Skip to content

fix(ai): keep the work log when a write tool ran before an unclassified error (Refs #182) - #247

Merged
alex-mextner merged 1 commit into
mainfrom
fix-agent-worklog-unclassified
Nov 7, 2026
Merged

alex-mextner merged 1 commit into
mainfrom
fix-agent-worklog-unclassified

Conversation

@alex-mextner

@alex-mextner alex-mextner commented Nov 7, 2026 •

Copy link
Copy Markdown
Owner

Что было

failRun в src/services/ai/agent.ts на любой неклассифицированной ошибке (баг/не-AI сбой посреди диалога) вызывал writer.deleteSentMessage() — удалял стримящийся «журнал работы» бота. Если до ошибки уже отработал write-инструмент (add_expense / set_budget), пользователь терял единственную запись о том, что расход записан, добавлял его повторно — и получал дубль (issue #182).

Фикс

  • failRun: при writeToolRan журнал сохраняется, сообщение об ошибке рендерится под ним (writer.fail(UNCLASSIFIED_FAILURE_MESSAGE)), наружу летит AgentError — его userMessage уже на экране, вызывающий (ask.ts) не шлёт дубль.
  • AgentError теперь принимает cause — оригинальная ошибка сохраняется для логов, а не маскируется.
  • Тексты ошибки объединены в UNCLASSIFIED_FAILURE_MESSAGE (agent.ts + ask.ts — один источник).

Без write-инструментов поведение прежнее: плейсхолдер удаляется, оригинальная ошибка пробрасывается.

Тесты

  • agent.errors.test.ts: «a write tool, then an unclassified non-AI error: the work log stays, failure under it» — AgentError брошен, deleteMessage не вызывался, журнал «Записываю расход: 5 EUR, Еда» виден, под ним текст ошибки (red-verified на старом коде).
  • ask.history.test.ts: мок обновлён под экспорт константы.

Gates: server-run -- bun run test — 253 файла / 6071 тест, 0 fail; type-check ✅; lint ✅. Машинное ревью: чисто, в т.ч. регрессионные ветки (no-write-tools, classified AI errors).

Refs #182

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

🔁 PR closed. Stage bot switched back to main.

@alex-mextner alex-mextner changed the title fix(ai): keep the work log when a write tool ran before an unclassified error (Fixes #182) fix(ai): keep the work log when a write tool ran before an unclassified error (Refs #182) Nov 7, 2026
@alex-mextner
alex-mextner force-pushed the fix-agent-worklog-unclassified branch from 71f9851 to 4c1123b Compare November 7, 2026 09:47
…ed error (Refs #182)

failRun deleted the streamed work log on any unclassified (non-AI) error.
When a write tool (add_expense, set_budget) had already run, the user lost
the only record of what was done, re-added the expense and got a duplicate.
Now: writeToolRan keeps the log, renders the failure message under it and
throws AgentError (message already sent — the caller sends no duplicate);
AgentError carries the original error as cause for the logs.
@alex-mextner
alex-mextner force-pushed the fix-agent-worklog-unclassified branch from 4c1123b to 93e7a36 Compare November 7, 2026 09:59
@alex-mextner
alex-mextner merged commit d60d5f1 into main Nov 7, 2026
16 checks passed
@alex-mextner
alex-mextner deleted the fix-agent-worklog-unclassified branch November 7, 2026 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant