fix(chat): sync currentChatRef when prefill creates a new chat session #153

Merged
chihlasm merged 4 commits from fix/tasklane-prefill-ref into main 2026-04-26 05:05:54 +00:00
Owner

Summary

The dashboard prefill flow in AssistantChatPage set activeChatId after creating a new session but never updated currentChatRef.current. Every later handleSend / handleTaskSubmit then tripped the currentChatRef.current !== sentForChatId guard that was meant to discard responses for stale chats — and silently dropped the AI's follow-up. The user saw their submitted message but no assistant reply, no toast, no task-lane update.

Reported symptom: in a troubleshooting session, after answering 3 of the 7 questions in the task lane and submitting, there was no response from the AI.

Fix

Add currentChatRef.current = session.session_id immediately after setActiveChatId(session.session_id) in the prefill effect, mirroring what handleNewChat and handleResumeNew already do.

Verification

  • New e2e regression test: frontend/e2e/assistant-chat-prefill.spec.ts. Drives the real dashboard prefill flow against the real backend and stubs /ai-sessions/*/chat so turn 1 returns deterministic questions and turn 2 returns a deterministic follow-up. Asserts the second AI message renders and the task lane clears.
  • Confirmed the test fails on unfixed code at the exact assertion (Got it — based on your answer… never appears) and passes once the fix is restored.
  • tsc -b clean. No new lint errors.

Test plan

  • CI: backend, frontend, e2e all green on this branch.
  • Manual: from dashboard, type a prefill, answer some questions in the task lane, click Send N of M Responses → AI follow-up appears.

Follow-up tracked separately

The currentChatRef.current !== sentForChatId guard is a silent return — same pattern can mask other bugs. Tracked in .ai/TODO.md.

## Summary The dashboard prefill flow in `AssistantChatPage` set `activeChatId` after creating a new session but never updated `currentChatRef.current`. Every later `handleSend` / `handleTaskSubmit` then tripped the `currentChatRef.current !== sentForChatId` guard that was meant to discard responses for stale chats — and silently dropped the AI's follow-up. The user saw their submitted message but no assistant reply, no toast, no task-lane update. Reported symptom: in a troubleshooting session, after answering 3 of the 7 questions in the task lane and submitting, there was no response from the AI. ## Fix Add `currentChatRef.current = session.session_id` immediately after `setActiveChatId(session.session_id)` in the prefill effect, mirroring what `handleNewChat` and `handleResumeNew` already do. ## Verification - New e2e regression test: `frontend/e2e/assistant-chat-prefill.spec.ts`. Drives the real dashboard prefill flow against the real backend and stubs `/ai-sessions/*/chat` so turn 1 returns deterministic questions and turn 2 returns a deterministic follow-up. Asserts the second AI message renders and the task lane clears. - Confirmed the test fails on unfixed code at the exact assertion (`Got it — based on your answer…` never appears) and passes once the fix is restored. - `tsc -b` clean. No new lint errors. ## Test plan - [ ] CI: backend, frontend, e2e all green on this branch. - [ ] Manual: from dashboard, type a prefill, answer some questions in the task lane, click Send N of M Responses → AI follow-up appears. ## Follow-up tracked separately The `currentChatRef.current !== sentForChatId` guard is a silent return — same pattern can mask other bugs. Tracked in `.ai/TODO.md`.
chihlasm added 1 commit 2026-04-26 03:43:42 +00:00
fix(chat): sync currentChatRef when prefill creates a new chat session
Some checks failed
Mirror to GitHub / mirror (push) Successful in 12s
CI / frontend (pull_request) Failing after 2m50s
CI / e2e (pull_request) Has been skipped
CI / backend (pull_request) Failing after 10m27s
e983607c88
The dashboard prefill flow in AssistantChatPage set activeChatId after
creating a new session but never updated currentChatRef.current. Every
later handleSend / handleTaskSubmit then tripped the
`currentChatRef.current !== sentForChatId` guard that was supposed to
discard responses for stale chats — and silently dropped the AI's
follow-up. The user saw their submitted message but no assistant
reply, no toast, no task-lane update.

Mirrors what handleNewChat and handleResumeNew already do. Adds an
e2e regression test that drives the dashboard prefill, submits a
partial task-lane response, and asserts the second AI turn renders.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
chihlasm added 1 commit 2026-04-26 03:44:13 +00:00
docs(ai): track currentChatRef silent-swallow follow-up in TODO
Some checks failed
Mirror to GitHub / mirror (push) Successful in 14s
CI / backend (pull_request) Failing after 2s
CI / frontend (pull_request) Failing after 2m40s
CI / e2e (pull_request) Has been skipped
1a8cb0604f
The guard pattern that masked the prefill-ref bug fixed in PR #153 is
applied across handleSend, handleTaskSubmit, selectChat, refreshFacts,
refreshActiveFix, and refreshPreview. Worth either logging the
mismatch path or distinguishing expected-stale from unexpected-stale
so the next instance of this class of bug surfaces instead of hiding.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
chihlasm force-pushed fix/tasklane-prefill-ref from 1a8cb0604f to 1559feb759 2026-04-26 04:24:31 +00:00 Compare
chihlasm added 1 commit 2026-04-26 04:30:53 +00:00
docs(ai): close out PR #150, set PR #153 as active task
Some checks failed
Mirror to GitHub / mirror (push) Successful in 13s
CI / frontend (pull_request) Successful in 5m50s
CI / e2e (pull_request) Failing after 6m50s
CI / backend (pull_request) Successful in 10m40s
43eed720d9
- CURRENT_TASK.md rolled forward — the CI-recovery task is complete
  (PR #150 merged as 87bb20b; backend gate is in required checks).
  Active task is now landing PR #153.
- HANDOFF.md rewritten — new resume point is watching CI on the
  rebased SHA 1559feb and merging when all three checks are green.
- SESSION_LOG.md gains a 2026-04-26 entry covering the prefill bug
  diagnosis, fix, regression test, and the rebase off post-#150 main.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
chihlasm added 1 commit 2026-04-26 04:51:40 +00:00
fix(ci): set stub ANTHROPIC_API_KEY for e2e job so AI-gated endpoints respond
All checks were successful
Mirror to GitHub / mirror (push) Successful in 11s
CI / frontend (pull_request) Successful in 5m39s
CI / backend (pull_request) Successful in 10m24s
CI / e2e (pull_request) Successful in 12m14s
11fe32f4c6
POST /api/v1/ai-sessions and friends call _require_ai_enabled(), which
returns 503 when no provider key is set. The new prefill-handoff
regression test (e2e/assistant-chat-prefill.spec.ts) drives the
dashboard prefill flow, which has to create a chat session before its
page.route stub on /chat can fire — so without a key, session
creation 503s and the test never sees the task lane.

The Playwright stub intercepts /chat in the browser, so the backend
never actually contacts Anthropic — but the AI-enabled gate still
needs to pass. A stub value is enough.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
chihlasm merged commit 68fcdc6122 into main 2026-04-26 05:05:54 +00:00
chihlasm deleted branch fix/tasklane-prefill-ref 2026-04-26 05:05:55 +00:00
Sign in to join this conversation.