Skip to content

Key in-flight turn state by turn, not agent address (CL-7196) - #478

Merged
TheGreatAxios merged 2 commits into
mainfrom
cl-7196-turn-keyed-state
Aug 30, 2026
Merged

TheGreatAxios merged 2 commits into
mainfrom
cl-7196-turn-keyed-state

Conversation

@TheGreatAxios

Copy link
Copy Markdown
Contributor

Summary

  • resolveMemberWorkbenches deliberately returns workbench ids plural: one agent address can be mid-turn in several benches at once, each running its own sidecar session.
  • repliedAddresses, notifiedDropAddresses, and the reply-parts accumulator's partsByAddress all keyed in-flight turn state on the agent address alone, so two concurrent turns for the same agent shared one bucket — replyParts.take(agentAddress) could swallow the other turn's accumulated content, and either turn's bracket-close could steal the other's drop-notice guard.
  • Introduced turnKeyFor(agentAddress, sessionId) and re-keyed all three collections on it. sessionId is carried on every agent.event frame (SidecarEventMap["agent.event"]), scoped to the one sidecar connection that turn runs on.
  • Stale comments describing the old per-address limitation were removed rather than left describing behavior that no longer exists.

Out of scope (flagging, not fixing here)

  • postedApprovalIds (process-lifetime Set) and pendingDelegationThreads (a Map entry leaked per delegation whose specialist never replies) are both unbounded, but neither is part of the turn-keying bug and neither has a natural eviction point in this diff — bounding them needs its own design call (TTL vs. LRU vs. event-driven eviction). Left for a separate ticket.

Test plan

  • packages/chat test suite (723 pass, 0 fail), including the new overlapping-turns regression test already committed on this branch
  • WORKBENCH_CHECK_SINCE-scoped and full bun run typecheck — clean
  • bun run lint — 0 errors (pre-existing unrelated warnings only)
  • bun run check:structural — clean

resolveMemberWorkbenches returns workbench ids plural by design: an
agent can be mid-turn in two benches at once. Prove the orchestrator
doesn't let one turn's inference/tool events, reply, or bracket-close
observe or consume the other's in-flight state.
resolveMemberWorkbenches returns workbench ids plural: one agent address
can be mid-turn in several benches at once, each on its own sidecar
session. repliedAddresses, notifiedDropAddresses, and the reply-parts
accumulator's partsByAddress all keyed on the address alone, so two
concurrent turns for the same agent shared one bucket and could consume
or drop each other's state.

Key all three on agent address + sidecar sessionId instead.
@TheGreatAxios
TheGreatAxios force-pushed the cl-7196-turn-keyed-state branch from 8793ae1 to 8069b47 Compare August 30, 2026 13:07
@TheGreatAxios

Copy link
Copy Markdown
Contributor Author

Posting review summary for CL-7196 turn-keying fix.

@TheGreatAxios

Copy link
Copy Markdown
Contributor Author

Review notes (code review pass)

Re-keys in-flight turn state (repliedTurns, notifiedDropTurns, the reply-parts accumulator) on turnKeyFor(agentAddress, sessionId) instead of agent address alone.

sessionId coverage

SidecarEventMap["agent.event"] (vendor/intx/hub-sessions/src/ws/sidecar-events.ts) declares sessionId: string as a required field on every agent.event frame, not optional per inner event type. chat-orchestrator.ts has exactly one subscription to this stream and it is the only reader of the three re-keyed collections. Confirmed no orphaned references to the old address-only keys (repliedAddresses, notifiedDropAddresses, partsByAddress, toolTraceIndexByAddress) remain anywhere except a test comment describing pre-fix behavior. Coverage is complete for this module.

Findings (fixed)

Both commit subjects carried a trailing (CL-7196) ticket-ID suffix, which the project's commit style does not use (checked against the last 30 commits on origin/main - none carry a ticket ref in the subject). Reworded both subjects via a non-interactive rebase; diff against the pre-reword state is empty, and force-pushed.

Checks run (foreground)

  • prettier --check on both touched files: clean
  • WORKBENCH_CHECK_SINCE=origin/main bun run typecheck: exit 0
  • bun run lint: 0 errors, 8 pre-existing warnings unrelated to this diff
  • packages/chat test suite: 723 pass, 0 fail, including the new overlapping-turns regression test

No other issues found. Not merging.

@TheGreatAxios
TheGreatAxios merged commit 5ef58a2 into main Aug 30, 2026
5 checks passed
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