Repository navigation
Description
Summary
Two distinct regressions in the Session tab after #782 merged. Both surfaced during manual verification of the original fix and are in the same component path (SessionPanel.vue + stores/sessions.js).
Issue 1 — TOCTOU race in onActivated causes wrong-URL polling
Surface: switch agents while a Session-tab turn is in flight (testfix mid-turn → NavBar → Agents → testfix-2 → wait → back to testfix). Result: stuck spinner + blocked input on testfix even after the turn completes; Console shows ~60 404 (Not Found) errors against GET /api/agents/testfix-2/sessions/<testfix-session-id> before MAX_ATTEMPTS hits.
Root cause: src/frontend/src/components/SessionPanel.vue:515 onActivated reads props.agentName after await sessionsStore.loadSession(...). AgentDetail's route watcher (AgentDetail.vue:884) calls loadAgent() asynchronously, which updates agent.value (and therefore SessionPanel.props.agentName) mid-flight. The post-await read pairs the previous agent's session id with the new agent's name. startPolling captures the cross-agent pair; every tick fires GET /api/agents/<new>/sessions/<old-sid> → 404 → caught and ignored. The polling loop never observes a terminal condition and runs for ~22 min before giving up.
Console evidence (live capture with temporary instrumentation):
[SP] onActivated ENTER {agentName: 'testfix', sid: 'Uc4A...', status: 'running'}
[SP] onActivated AFTER await {agentName: 'testfix-2', sid: 'Uc4A...', turnInProgress: true}
[SP] startPolling CALL {agentName: 'testfix-2', sid: 'Uc4A...'}
[store.poll tick] loadSession {agentName: 'testfix-2', sessionId: 'Uc4A...', attempts: 0..59+}
GET http://localhost/api/agents/testfix-2/sessions/Uc4A... 404 (Not Found) (x59+)
props.agentName flips from testfix to testfix-2 across the await boundary. Same flip in reverse on the return navigation.
Issue 2 — Missing optimistic user-message insert
Surface: in the Session tab, the user's typed message doesn't appear in the conversation until the assistant's response lands. For a 30 s+ turn the user stares at a bare spinner with no echo of what they typed. (The Chat tab does this correctly at ChatPanel.vue:612 — message appears immediately.)
Root cause: #782 intentionally dropped the optimistic insert from sendMessage in src/frontend/src/stores/sessions.js. The store comment claimed: "Trades ~100-300 ms perceived latency for correctness across navigation." The ~100-300 ms estimate is wrong for slow turns — perceived latency equals the entire turn duration.
The mid-flight failure case the PR was avoiding is real (an optimistic insert with rollback on error would delete the user's row from view even though the backend persisted it). The correct fix is optimistic insert without rollback — same as Chat tab's pattern.
Proposed fix (tested locally)
SessionPanel.vue — capture agentName and sid before the await
onActivated(async () => {
const agentName = props.agentName // capture before await
const sid = currentSessionId.value
if (!sid || props.agentStatus !== 'running') return
try {
const data = await sessionsStore.loadSession(agentName, sid)
if (data?.session?.turn_in_progress) {
sessionsStore.startPolling(agentName, sid)
}
} catch { /* non-fatal */ }
})stores/sessions.js — optimistic insert without rollback in sendMessage
const existing = this.messagesBySession[sessionId] || []
this.messagesBySession[sessionId] = [
...existing,
{ id: \`optimistic-\${Date.now()}\`, role: 'user', content: text, timestamp: new Date().toISOString() },
]loadSession after the successful turn overwrites with the canonical row from the DB — same content, no flicker. On error the optimistic row is intentionally kept (server-side failures occur after the user row is persisted; network failures keeping the row in view is still better than silent disappearance).
Verified
- Cross-agent stuck-spinner repro → gone.
- 404 polling errors → gone.
- User message echoes immediately on send.
- Cross-agent bleed flow (bug(session-tab): shows 'failed to send' on return navigation while execution is still running #759 scenario) still works end-to-end.
Scope
~40 net lines across SessionPanel.vue + stores/sessions.js. No backend changes. No schema changes. No new tests required beyond what #782 already shipped (those pin lock-key naming and TTL formulae, not the JS race).
Activity
webmixgamer commentedon May 11, 2026
/claim
github-actions commentedon May 11, 2026
Claimed by @webmixgamer. Label
status-in-progressadded.Next steps:
feature/789-<short-slug>Fixes #789fix(session-tab): capture agentName before await + restore optimistic…
vybe commentedon Jun 1, 2026
Shipped in v0.6.0 (released via #998).