Repository navigation
fix(session-tab): KeepAlive race capture + optimistic user-message echo (#789) - #790
Merged
Merged
Conversation
… user-message echo Two follow-up fixes for #782's KeepAlive reattach work, both on the same SessionPanel code path. Filed and tested as #789. 1. TOCTOU race in onActivated (SessionPanel.vue) AgentDetail's route watcher calls loadAgent() async, so `agent.value` (and therefore `SessionPanel.props.agentName`) can update mid-await. Reading `props.agentName` after `await sessionsStore.loadSession(...)` paired the previous agent's session id with the new agent's name; startPolling captured the cross-agent pair and 404'd ~60 times per incident against `GET /api/agents/<new>/sessions/<old-sid>` until MAX_ATTEMPTS hit ~22 min later. Surface: stuck spinner + blocked input on the original agent after switching away and back. Fix: capture `agentName` and `sid` into locals before the await; pass the captured pair to startPolling. 2. Missing optimistic user-message insert (stores/sessions.js) PR #782 dropped the optimistic insert from sendMessage on the assumption that turns are fast ("~100-300 ms perceived latency"). For a 30s+ Bash/sleep prompt the user stares at a bare spinner for the full turn duration. The Chat tab does this correctly at ChatPanel.vue:612. Fix: optimistic insert at the start of sendMessage without rollback on error. Backend persists the user row at turn start so loadSession on success overwrites the optimistic row with the canonical one (same content, no flicker). On error the row is intentionally kept in view — server-side failures occur after the user row is persisted, and for the rare network failure where the POST never reaches the server, keeping the row visible is still better than silent disappearance. Tests: tests/unit/test_session_panel_race_capture.py — 4 AST/regex guards pinning (a) `const agentName = props.agentName` captured before first await in onActivated, (b) no re-read of props.agentName after the capture, (c) `messagesBySession[sessionId] = [...]` precedes the axios.post in sendMessage, (d) the optimistic insert spreads existing messages rather than replacing. Same convention as test_session_inflight_sentinel.py. Docs: feature-flows/session-tab.md line 51 corrected — "optimistic insert + rollback on failure" was wrong both before #782 (which removed it entirely) and after #789 (which restores it without rollback). Verified live against testfix + testfix-2: - 404 polling errors gone. - Cross-agent stuck-spinner repro gone. - User message echoes immediately on send. - #759 cross-agent bleed scenario still works end-to-end. Fixes #789 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two follow-up fixes for #782's KeepAlive reattach work, both on the same SessionPanel code path.
agentNameandsidbefore theawaitinonActivated— fixes the TOCTOU race against Vue prop reactivity. Without it, polling captured the new agent's name with the previous session's id and 404'd ~60 times per incident againstGET /api/agents/<new>/sessions/<old-sid>until MAX_ATTEMPTS hit ~22 min later. User-visible symptom: stuck spinner + blocked input after navigating away from a mid-turn session and back.loadSessionon success overwrites with the same content (no flicker), and on error the row is intentionally kept (server-side failures occur after persist; network failures keep the user's text in view rather than silently disappearing).Changes
src/frontend/src/components/SessionPanel.vue— capture pattern inonActivated.src/frontend/src/stores/sessions.js— optimistic-insert insendMessage; comment updated to describe the no-rollback rationale.docs/memory/feature-flows/session-tab.md— line 51 corrected (the doc previously claimed "optimistic insert + rollback on failure" which was wrong both before and after fix(session-tab): reattach to in-flight turn on KeepAlive activation (#759) #782).tests/unit/test_session_panel_race_capture.py— 4 new AST/regex guards (capture-before-await; no re-read ofprops.agentNameafter capture; optimistic-mutation-before-axios-post;[...existing, ...]spread pattern). Same convention astest_session_inflight_sentinel.py.Test plan
pytest tests/unit/test_session_panel_race_capture.py -v— 4 passed locally.testfix+ temporarytestfix-2, withconsole.loginstrumentation that capturedagentNameflipping fromtestfixtotestfix-2across theawaitboundary in the broken code.Fixes #789
🤖 Generated with Claude Code