You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug(session-tab): shows 'failed to send' on return navigation while execution is still running #759
When a message is sent via the Session tab and the user navigates away to another page before the response completes, returning to the agent shows a "failed to send message" error. The execution is actually still running on the backend and will complete normally — the result may appear at the end — but the UI incorrectly surfaces a failure state mid-flight.
Component
Frontend / Session Tab
Priority
P2
Steps to Reproduce
Open an agent's Session tab
Send a message that will take more than a few seconds to complete
While the response is still in progress, navigate to a different page (e.g. Agents list, another agent)
Navigate back to the original agent's Session tab
Observe: UI shows "failed to send message"
Wait: execution completes on the backend and result may still appear
Expected Behavior
On return navigation, the Session tab should show the message as in-progress (e.g. a spinner or "running" indicator) and update to the completed result when the execution finishes. A "failed" state should only be shown if the backend actually returns an error.
Actual Behavior
The Session tab shows "failed to send message" immediately on re-render after navigation, even though the backend execution is still running. If left open, the result may appear when the execution eventually completes, contradicting the failure message.
Root Cause (suspected)
The Session tab likely tracks in-flight request state in local component state (e.g. a sending flag or a pending promise). When the component unmounts on navigation, that state is lost. On remount, the absence of a completed response is interpreted as a failure rather than as an in-progress execution. The fix likely requires checking execution status from the backend on mount (polling or the existing SSE stream) instead of relying solely on local component state.
Suggested Fix
On Session tab mount, check if there is an active execution for the agent (via /api/executions?status=running or the existing SSE stream). If one is found for the current session, resume the in-progress indicator and stream the result rather than rendering a failed state.
Workaround
Stay on the Session tab until the response completes. Do not navigate away while a message is being processed.
Reproduced this against dev (commit 9a57c6e2). Two notes that should land before any fix is written:
The suggested fix points at the wrong endpoint
The issue suggests GET /api/executions?status=running on mount. That endpoint queries schedule_executions. Session-tab turns go through POST /api/agents/{name}/sessions/{id}/message and write to agent_session_messages — a parallel table with no join to executions. Polling /api/executions will never show a session turn in flight. The right source of truth is the per-(agent, claude_uuid) Redis resume lock at routers/sessions.py:155-227.
Cases that need to be covered
Case
What happens today
What's needed
A — Vue Router navigate away & back
loading ref dies with component; remount shows enabled input; later optimistic rollback wipes the user message
Pinia store keeps inFlightBy[sessionId] + the action's promise; on remount, re-await
B — Browser refresh while turn in flight
JS state wiped; new POST contends with still-held _ResumeLock → 429 after 30s wait
Backend exposes lock status — new turn_in_progress: bool field on GET /api/agents/{name}/sessions/{id}, derived from EXISTS against trinity:session:lock:{cached_claude_session_id}
C — Tab close, return after completion
Already works (canonical messages via loadSession)
Nothing
D — Same-tab tab switch (Chat ↔ Session ↔ Tasks)
Already works (v-show keeps SessionPanel mounted in AgentDetail.vue:115)
Nothing
E — Multi-tab / two browser tabs same session
Tab B has stale view; no live update when Tab A submits
WebSocket broadcast on session turn start/end. Optional for v1, separate enhancement
Mechanism, confirmed via API
Direct calls against the turn endpoint:
Client disconnect mid-turn does NOT abort the backend.curl --max-time 1 returned 28 (timeout) but the user message + assistant reply both landed in agent_session_messages seconds later. This is the actual mechanism behind the "failed to send" toast — the frontend sees a rejected promise; the backend has already persisted everything.
Concurrent same-session warm turns serialize via _ResumeLock. Second POST waits up to _LOCK_WAIT_TOTAL_SECONDS (30s) — both succeed if the first completes within that window, otherwise the second gets 429 "Another turn on this session is in progress" (the user can already trigger this on browser refresh).
Different sessions on the same agent don't contend — locks are keyed on cached_claude_session_id, not agent name. Confirmed: A and B in parallel both ran without lock contention.
Minimum viable fix
Move loading + the in-flight promise from local component state in SessionPanel.vue into stores/sessions.js, keyed by sessionId.
Add turn_in_progress: bool to GET /api/agents/{name}/sessions/{id} — single Redis EXISTS against the lock key.
Touches: routers/sessions.py near the existing _ResumeLock definition
On mount, if the store reports in-flight OR backend reports turn_in_progress=true, render a "running" indicator and poll loadSession every 2s until either (a) backend reports no lock and latest message is assistant, or (b) the polled response signals an error.
(1) and (2) together close this issue. (E) is a separate enhancement and should not scope-creep this PR.
Adjacent defect — will file separately
routers/sessions.py:175-180 short-circuits the resume lock to key=None when cached_claude_session_id is null (the cold-turn path). Two concurrent first turns on a brand-new session both run in parallel and race on update_cached_claude_session_id — the loser's UUID is overwritten and its JSONL is orphaned. Both turns also see each other's user messages in context. Reproduced with two parallel POSTs against a fresh session: HTTP 200/200, 4 messages persisted, only one UUID survived. This matches the Anthropic #20992 / JSONL corruption window the architecture doc warns about, but the lock as currently written doesn't guard cold turns. Out of scope for #759 — will open a separate issue and link it here.
Activity
webmixgamer commentedon May 10, 2026
Updated analysis from API-level reproduction
Reproduced this against
dev(commit9a57c6e2). Two notes that should land before any fix is written:The suggested fix points at the wrong endpoint
The issue suggests
GET /api/executions?status=runningon mount. That endpoint queriesschedule_executions. Session-tab turns go throughPOST /api/agents/{name}/sessions/{id}/messageand write toagent_session_messages— a parallel table with no join to executions. Polling/api/executionswill never show a session turn in flight. The right source of truth is the per-(agent, claude_uuid)Redis resume lock atrouters/sessions.py:155-227.Cases that need to be covered
loadingref dies with component; remount shows enabled input; later optimistic rollback wipes the user messageinFlightBy[sessionId]+ the action's promise; on remount, re-await_ResumeLock→ 429 after 30s waitturn_in_progress: boolfield onGET /api/agents/{name}/sessions/{id}, derived fromEXISTSagainsttrinity:session:lock:{cached_claude_session_id}loadSession)v-showkeeps SessionPanel mounted inAgentDetail.vue:115)Mechanism, confirmed via API
Direct calls against the turn endpoint:
curl --max-time 1returned 28 (timeout) but the user message + assistant reply both landed inagent_session_messagesseconds later. This is the actual mechanism behind the "failed to send" toast — the frontend sees a rejected promise; the backend has already persisted everything._ResumeLock. Second POST waits up to_LOCK_WAIT_TOTAL_SECONDS(30s) — both succeed if the first completes within that window, otherwise the second gets 429"Another turn on this session is in progress"(the user can already trigger this on browser refresh).cached_claude_session_id, not agent name. Confirmed: A and B in parallel both ran without lock contention.Minimum viable fix
loading+ the in-flight promise from local component state inSessionPanel.vueintostores/sessions.js, keyed bysessionId.SessionPanel.vue:246, 418,sessions.js:158-213turn_in_progress: booltoGET /api/agents/{name}/sessions/{id}— single RedisEXISTSagainst the lock key.routers/sessions.pynear the existing_ResumeLockdefinitionturn_in_progress=true, render a "running" indicator and pollloadSessionevery 2s until either (a) backend reports no lock and latest message isassistant, or (b) the polled response signals an error.(1) and (2) together close this issue. (E) is a separate enhancement and should not scope-creep this PR.
Adjacent defect — will file separately
routers/sessions.py:175-180short-circuits the resume lock tokey=Nonewhencached_claude_session_idis null (the cold-turn path). Two concurrent first turns on a brand-new session both run in parallel and race onupdate_cached_claude_session_id— the loser's UUID is overwritten and its JSONL is orphaned. Both turns also see each other's user messages in context. Reproduced with two parallel POSTs against a fresh session: HTTP 200/200, 4 messages persisted, only one UUID survived. This matches the Anthropic #20992 / JSONL corruption window the architecture doc warns about, but the lock as currently written doesn't guard cold turns. Out of scope for #759 — will open a separate issue and link it here.webmixgamer commentedon May 11, 2026
Filed the cold-turn lock-bypass edge case as #779 so it's tracked separately and not bundled into this PR.
webmixgamer commentedon May 11, 2026
/claim
github-actions commentedon May 11, 2026
Claimed by @webmixgamer. Label
status-in-progressadded.Next steps:
feature/759-<short-slug>Fixes #759fix(session-tab): reattach to in-flight turn on KeepAlive activation (#…
fix(session-tab): capture agentName before await + restore optimistic…
test(#586) + test-suite recovery + doc backfill + CSO 2026-05-17 (#875)
vybe commentedon Jun 1, 2026
Shipped in v0.6.0 (released via #998).
fix(workspace): a mid-turn reload rejoins the turn (ent#286)
feat(workspace): absorb the Session surface, with continuity parity (…