Skip to content

bug(session-tab): shows 'failed to send' on return navigation while execution is still running #759

Closed

Description

@vybe

Summary

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

  1. Open an agent's Session tab
  2. Send a message that will take more than a few seconds to complete
  3. While the response is still in progress, navigate to a different page (e.g. Agents list, another agent)
  4. Navigate back to the original agent's Session tab
  5. Observe: UI shows "failed to send message"
  6. 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.

Environment

  • Trinity version: 7b95c46
  • Affected surface: Session tab (/agents/{name} → Session tab)

Activity

  1. webmixgamer commented on May 10, 2026

    @webmixgamer
    Contributor

    Updated analysis from API-level reproduction

    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:

    1. 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.
    2. 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).
    3. 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

    1. Move loading + the in-flight promise from local component state in SessionPanel.vue into stores/sessions.js, keyed by sessionId.
      • Touches: SessionPanel.vue:246, 418, sessions.js:158-213
    2. 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
    3. 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.

  2. webmixgamer commented on May 11, 2026

    @webmixgamer
    Contributor

    Filed the cold-turn lock-bypass edge case as #779 so it's tracked separately and not bundled into this PR.

  3. webmixgamer commented on May 11, 2026

    @webmixgamer
    Contributor

    /claim

  4. added
    status-in-progress
    on May 11, 2026
  5. github-actions commented on May 11, 2026

    @github-actions

    Claimed by @webmixgamer. Label status-in-progress added.

    Next steps:

    1. Create branch: feature/759-<short-slug>
    2. Implement the feature
    3. Open a PR with Fixes #759
  6. added
    status-in-dev
    and removed
    status-in-progress
    on May 11, 2026
  7. added a commit that references this issue on May 23, 2026
  8. vybe commented on Jun 1, 2026

    @vybe
    ContributorAuthor

    Shipped in v0.6.0 (released via #998).

  9. removed
    status-in-dev
    on Jun 1, 2026
  10. added
    status-in-dev
    on Jun 30, 2026
  11. removed
    status-in-dev
    on Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

priority-p2type-bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions