Skip to content

bug(session-tab): KeepAlive activation race + missing user-message echo (PR #782 follow-ups) #789

Closed

Description

@webmixgamer

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

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

  1. webmixgamer commented on May 11, 2026

    @webmixgamer
    ContributorAuthor

    /claim

  2. added
    status-in-progress
    on May 11, 2026
  3. github-actions commented on May 11, 2026

    @github-actions

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

    Next steps:

    1. Create branch: feature/789-<short-slug>
    2. Implement the feature
    3. Open a PR with Fixes #789
  4. added
    status-in-dev
    and removed
    status-in-progress
    on May 11, 2026
  5. vybe commented on Jun 1, 2026

    @vybe
    Contributor

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

  6. removed
    status-in-dev
    on Jun 1, 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