Skip to content

fix(client): per-thread agent status so concurrent threads each render their own stop button#47

Closed
yourbuddyconner wants to merge 1 commit into
mainfrom
fix/per-thread-agent-status
Closed

fix(client): per-thread agent status so concurrent threads each render their own stop button#47
yourbuddyconner wants to merge 1 commit into
mainfrom
fix/per-thread-agent-status

Conversation

@yourbuddyconner

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #46. After scoping the runner abort to the active thread, the Stop button still disappeared when the user switched to a still-running parallel thread. Two layers of session-wide front-end state were leaking across threads.

What was wrong

  1. ChatState.agentStatus is a single value — whichever thread emitted the most recent agentStatus WS message overwrote every other thread's status. So if thread B's thinking arrived a beat earlier than thread A's tool_calling, switching to A would show the wrong (or no) state.
  2. abort() optimistically cleared that global field session-wide — even when scoped to a specific thread, the client set isAgentThinking=false, agentStatus=idle everywhere. The Stop button keys off isAgentActive (derived from agentStatus), so it disappeared on every thread until the runner happened to emit a status update for the still-running thread.

Fix shape

  • New ChatState.threadStatuses: Record<threadId, { status, detail }>. The agentStatus WS handler updates threadStatuses[msg.threadId] alongside the existing global fields (kept for back-compat).
  • abort('thread', threadId) only mutates that thread's slot; other threads' status entries stay intact. Session-wide abort() (no scope) still clears the global indicator.
  • chat-container derives activeThreadStatus from threadStatuses[activeThreadId] (with a fallback to the legacy global value for sessions whose first event predates this map), and computes isAgentActive / isAgentThinkingInThread from that. MessageList receives the thread-scoped status instead of the global one.

Test plan

  • `pnpm typecheck` at workspace root.
  • `cd packages/client && pnpm build` (production build).
  • Manual: open two concurrent thread turns on one orchestrator session. Click Stop on thread A — confirm A aborts and its Stop button disappears. Switch to thread B — confirm its Stop button is still visible while it's running.

…r their own stop button

After PR #46 the stop button correctly aborted only the active thread, but
switching to a still-running parallel thread showed no stop button. Root
cause: the chat state stored a single global agentStatus, so whichever
thread emitted the most recent agentStatus event clobbered every other
thread's busy indicator — and the abort handler optimistically cleared
that single field session-wide.

Track agent status per-thread:
- ChatState now carries threadStatuses: Record<threadId, {status, detail}>.
- The agentStatus WebSocket handler updates threadStatuses[msg.threadId]
  alongside the legacy global fields.
- The abort handler clears only the targeted thread's slot when scoped to
  ('thread', channelId); other threads' busy indicators stay intact.
- chat-container derives activeThreadStatus from threadStatuses[
  activeThreadId] (with a fallback to the legacy agentStatus for sessions
  whose first event predates this map), and computes isAgentActive /
  isAgentThinkingInThread from that. MessageList now receives the thread-
  scoped status rather than the global one.

Net effect: clicking Stop on thread A leaves thread B's stop button visible
while thread B is still running.
@github-actions

Copy link
Copy Markdown

Preview deployment: https://pr-47.dev-valet-turnkey-client.pages.dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant