Repository navigation
Description
What
Prevent the deterministic expense parser from consuming multi-line free-form requests merely because later lines look like expenses. Only canonical expense-entry messages should enter the direct parser; mixed/natural-language requests must go to the AI agent. Persist recent relevant Telegram messages into shared chat history regardless of whether they were handled deterministically, so follow-ups such as 'Все суммы в евро' resolve against the immediately preceding plan.
Why (motivation)
Production on 2026-09-24 recorded 9 budget-plan lines as real expenses and then the agent lacked the preceding request when handling the follow-up.
User impact
Users can safely discuss or plan budgets in natural language without accidental writes, and follow-up messages keep conversational meaning.
Cost of inaction
The bot can corrupt expense data and make contradictory AI changes because it loses the immediate conversation context.
Acceptance criteria
- A message beginning with natural-language instructions followed by amount/category lines is not saved as expenses by the deterministic parser and is routed to AI intact. — forced: Backend routing/history acceptance is non-visual; verified by full pre-push suite (157/157 files, 3652/3652 tests), exact 2026-09-24 and 2026-09-30 budget regressions in message.handler.test.ts, and causal/concurrent history regressions in ask.history.test.ts.
- Recent relevant user messages handled outside the AI path are available to the next AI turn without duplicate history entries. — forced: Backend routing/history acceptance is non-visual; verified by full pre-push suite (157/157 files, 3652/3652 tests), exact 2026-09-24 and 2026-09-30 budget regressions in message.handler.test.ts, and causal/concurrent history regressions in ask.history.test.ts.
- Regression tests cover the exact 2026-09-24 budget-plan conversation and contextual follow-up. — forced: Backend routing/history acceptance is non-visual; verified by full pre-push suite (157/157 files, 3652/3652 tests), exact 2026-09-24 and 2026-09-30 budget regressions in message.handler.test.ts, and causal/concurrent history regressions in ask.history.test.ts.
Screenshots
(none)
Deploy
Deployed: no
Links
- PR: fix(routing): exclude budget intent from expense fastpath (Refs #121) #241
- Merge commit: f4d3530
Skipped gates
- links: Root cause and exact production evidence will be linked in implementation PR.
- msgref-quote: Original request is captured in production log and this working session; no stable external message URL is available.
- screenshots: Routing/history behavior is covered by deterministic tests and production logs; no visual proof is needed for this backend P0.
Activity
alex-mextner commentedon Sep 30, 2026
2026-09-30 production recurrence confirmed. User message 4239: 'Сформируй бюджет на грядущий октябрь' followed by €450 — квартира, €600 — еда, etc. Current production f0619bb ignored prose lines and created pending_expenses 1209–1218; each parsed category as literal em dash '—' and the intended category as comment. No final expenses were committed. Follow-up 'Бюджет надо а не траты / См сообщение выше' reached AI without the original request in history. Added exact regression for this message to PR #125 and rebased onto current main where old dependency-review vulnerabilities are already fixed.
fix(bot): route mixed plans atomically to AI (#121)
alex-mextner commentedon Sep 30, 2026
Review findings addressed before merge: (1) bounded chat history now prunes immediately on every stored user turn; (2) direct-AI current turn is carried by exact DB row id and causal history is queried with id < current, eliminating same-second/concurrency duplication and later-message leakage; (3) ordinary messages in forum groups without an active /topic binding are not added to AI history, preventing cross-topic disclosure. Added regression tests for unconfigured forums, immediate pruning/id handoff, deterministic id ordering, and causal history.
fix(bot): route mixed plans atomically to AI (#121)
alex-mextner commentedon Sep 30, 2026
Second review edge addressed: forum history remains stateless until /topic is bound; changing or clearing active_topic_id deletes prior group-scoped chat history, so context cannot cross old/new topic boundaries. Re-running /topic in the same thread preserves history. Added /topic regression tests.
fix(bot): route mixed plans atomically to AI (#121)
fix(bot): route mixed plans atomically to AI (#121)
2 remaining items
fix(bot): route mixed plans atomically to AI (#121)
fix(bot): route mixed plans atomically to AI (#121)
fix(bot): route mixed plans atomically to AI (#121)
alex-mextner commentedon Oct 1, 2026
Final queue review fix: optional maybeSmartAdvice now runs after the ordered primary conversation queue has been released, so a slow post-answer advice stream cannot block the next user turn. Added a regression that holds the first advice stream open and verifies the second primary AI turn still starts.
fix(bot): route mixed plans atomically to AI (#121)
fix(bot): route mixed plans atomically to AI (#121) (#125)
alex-mextner commentedon Oct 1, 2026
Shipped: merged via #125.
Merge commit: 5645969
This does NOT close the ticket — acceptance still needs proof. Run
task read #121for the outstanding criteria, thentask check/task done.alex-mextner commentedon Oct 1, 2026
✅ Deployed to production as merge commit 5645969 (PR #125) on 2026-10-01. Deploy workflow 36859415031 completed successfully: production pulled main, rebuilt the Mini App, reloaded PM2, and both
expensesyncbotandbank-synccame online. The exact Sep/Oct budget-planning regressions, causal recent-history ordering, forum topic scoping, retention bounds, and conversation-queue regression are covered by tests; final pre-push suite passed 157/157 test files and 3652/3652 tests.fix(routing): exclude budget intent from expense fastpath (#121)
fix(routing): exclude budget intent from expense fastpath (#121) (#241)
alex-mextner commentedon Nov 6, 2026
Shipped: merged via #241.
Merge commit: f4d3530
The ticket is already Done — recorded here for reference.
feat(budget): explainable setup prompts and compact overview (Refs #123…