fix: martwe Assistants API nie może wyłączać całego coga AI #27

Merged
gitea merged 1 commits from fix-ai-cog-load-crash into main 2026-08-27 14:15:03 +00:00
Owner

To jest przyczyna "Command modele_ai is not found"

Nie chodziło o Ollamę. Cały cog ai_commands nie ładował się, więc nie istniała ŻADNA komenda AI.

ai_commands.py:129 in cog_load
    thread = await OPENAICLIENT.beta.threads.create()
openai.NotFoundError: Error code: 404
-> ExtensionFailed: Extension 'ai_commands' raised an error

Bootstrap osobistych asystentów woła OpenAI Assistants API (beta threads/runs) — to legacy, które teraz odpowiada 404. Wyjątek wychodził z cog_load, więc discord.py wywalał całe rozszerzenie, a z nim: $gadaj_teraz, $modele_ai i obsługę rozmów. Bot działał dalej (bot.py ładuje rozszerzenia defensywnie) — po prostu nie miał AI w ogóle.

Dlaczego istniejące zabezpieczenie nie złapało

cog_load miał już właściwy odruch — pomija bootstrap, gdy OPENAICLIENT is None (żeby wdrożenie Claude-only działało). Ale zabezpieczał się przed brakiem klienta, nie przed błędem wywołania.

Poprawka

Bootstrap wydzielony do _start_personal_assistants(), a jego awaria jest nieśmiertelna: logujemy co przepadło i lecimy dalej. Osobiści asystenci to jedna opcjonalna funkcja — reszta coga działa na Claude i Ollamie i nie ma powodu, żeby szła z nimi na dno.

Czego świadomie nie zrobiłem

Nie ma testu jednostkowego: sterowanie cog_load wymaga atrap openai, tiktoken i tasks.loop na tyle kompletnej, by odpowiadała na is_running() — wtedy test sprawdza moje atrapy, nie kod. Zamiast tego zweryfikuję na działającym klastrze po wdrożeniu.

Suite: 72 unit + 71 integration zielone.

⚠️ Produkcja

deploy-bot chodzi na fbd1ec9f i ma ten sam błąd. Żeby go naprawić, potrzebny jest commit z [deploy] — sam tego nie promuję.

🤖 Generated with Claude Code

## To jest przyczyna "Command modele_ai is not found" Nie chodziło o Ollamę. **Cały cog `ai_commands` nie ładował się**, więc nie istniała ŻADNA komenda AI. ``` ai_commands.py:129 in cog_load thread = await OPENAICLIENT.beta.threads.create() openai.NotFoundError: Error code: 404 -> ExtensionFailed: Extension 'ai_commands' raised an error ``` Bootstrap osobistych asystentów woła **OpenAI Assistants API** (beta threads/runs) — to legacy, które teraz odpowiada **404**. Wyjątek wychodził z `cog_load`, więc discord.py wywalał całe rozszerzenie, a z nim: `$gadaj_teraz`, `$modele_ai` i obsługę rozmów. Bot działał dalej (`bot.py` ładuje rozszerzenia defensywnie) — po prostu **nie miał AI w ogóle**. ## Dlaczego istniejące zabezpieczenie nie złapało `cog_load` miał już właściwy odruch — pomija bootstrap, gdy `OPENAICLIENT is None` (żeby wdrożenie Claude-only działało). Ale zabezpieczał się przed **brakiem klienta**, nie przed **błędem wywołania**. ## Poprawka Bootstrap wydzielony do `_start_personal_assistants()`, a jego awaria jest **nieśmiertelna**: logujemy co przepadło i lecimy dalej. Osobiści asystenci to jedna opcjonalna funkcja — reszta coga działa na Claude i Ollamie i nie ma powodu, żeby szła z nimi na dno. ## Czego świadomie nie zrobiłem Nie ma testu jednostkowego: sterowanie `cog_load` wymaga atrap `openai`, `tiktoken` i `tasks.loop` na tyle kompletnej, by odpowiadała na `is_running()` — wtedy test sprawdza moje atrapy, nie kod. Zamiast tego zweryfikuję na działającym klastrze po wdrożeniu. Suite: **72 unit + 71 integration** zielone. ## ⚠️ Produkcja `deploy-bot` chodzi na `fbd1ec9f` i **ma ten sam błąd**. Żeby go naprawić, potrzebny jest commit z `[deploy]` — sam tego nie promuję. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
gitea self-assigned this 2026-08-27 14:12:25 +00:00
gitea added 1 commit 2026-08-27 14:12:25 +00:00
AI: a dead Assistants API must not disable the whole AI cog
CI / compile (pull_request) Successful in 8s
CI / unit (pull_request) Successful in 29s
CI / integration (pull_request) Successful in 39s
build / build (push) Successful in 4m29s
CI / compile (push) Successful in 5s
CI / unit (push) Successful in 22s
CI / integration (push) Successful in 27s
9b6666dc9c
Field report from both instances: "Command modele_ai is not found", and on
restart the extension fails outright:

  ai_commands.py:129 in cog_load
    thread = await OPENAICLIENT.beta.threads.create()
  openai.NotFoundError: Error code: 404
  -> ExtensionFailed: Extension 'ai_commands' raised an error

The personal-assistants bootstrap calls the OpenAI Assistants API (beta
threads/runs), a legacy surface that now answers 404. That exception
propagated out of cog_load, so discord.py failed the whole extension - and
with it EVERY AI command: $gadaj_teraz, $modele_ai and the conversation
handler. The bot kept running (bot.py loads each extension defensively), it
simply had no AI at all.

cog_load already had the right instinct - it skips the bootstrap cleanly
when OPENAICLIENT is None, so a Claude-only deployment works - but it
guarded against the client being ABSENT, not against the call FAILING.

Move the bootstrap into _start_personal_assistants() and treat any failure
there as non-fatal: log what was lost and carry on. Personal assistants are
one optional feature; the rest of the cog works fine on Claude and Ollama
and must not go down with them.

Not unit-tested on purpose: exercising cog_load needs stubs for openai,
tiktoken and a tasks.loop complete enough to answer is_running(), at which
point the test exercises the stubs rather than the code. Verified against
the running cluster instead.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
gitea merged commit 9b6666dc9c into main 2026-08-27 14:15:03 +00:00
gitea deleted branch fix-ai-cog-load-crash 2026-08-27 14:15:03 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: gitea/conjurer#27