Skip to content

fix(server): agent messages join a busy Claude agent's turn instead of queueing - #690

Merged
bryantderosier merged 9 commits into
j5/mainfrom
j5/claude-next-steer
Oct 26, 2026
Merged

bryantderosier merged 9 commits into
j5/mainfrom
j5/claude-next-steer

Conversation

@bryantderosier

@bryantderosier bryantderosier commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Peer messages sent to a busy Claude agent currently become separate queued turns, so Crew coordination can build large backlogs. I send agent steers with Claude Code's priority "next", letting running tool calls finish before the message joins the turn. A person's steer keeps upstream's "now" behavior.

A message arriving after the last tool call can otherwise run as a second native turn and trigger a premature no-reply notice. I keep the J5 turn open until the consuming turn's result, using the CLI's lifecycle frames. Terminal runs release tracked steers without an unread-after-Stop notice; that notice is deferred to #694. Busy Claude receivers no longer get the waiting-behind-messages notice.

Evidence

On 7263cd83df, the focused suite passed 400 tests across 8 files:

vp test run apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts apps/server/src/orchestration-v2/ClaudeAutomaticDelivery.integration.test.ts apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts apps/server/src/j5/a2a/DeliveryTransport.integration.test.ts apps/server/src/j5/a2a/EnvelopeFormatter.test.ts apps/server/src/j5/a2a/claudeAgentSteers.test.ts apps/server/src/j5/a2a/claudeAgentSteers.integration.test.ts apps/server/src/j5/a2a/SilenceDetector.test.ts
  • The real-adapter/orchestrator tests cover delivery during a tool call, a late steer remaining in one billed provider turn, Stop ending a held turn, and a person's steer retaining "now".
  • Cleanup tests cover interrupted, failed, cancelled and rolled-back runs, including a thread without an A2A membership. They assert tracking is released without an unread notice. Existing stopped/cancelled ask notices remain covered.
  • Tracking tests cover failed results and offers, query-scoped frames, unknown lifecycle states, and cleanup preserving another turn.
  • vp run --filter t3 typecheck passed. Targeted vp lint reported only the existing unused layer warning in ClaudeAdapterV2.ts. Formatting and git diff --check passed.

Not verified: no new live-provider or browser tests ran on this head. The Claude backlog branch is checked directly; the delivery harness still uses a Codex adapter. Cursor, other providers, desktop and mobile were not exercised. CI on this head is separate from these local checks.

Merge Danger

Door: two-way for future delivery behavior. A revert restores queued Claude peer messages; messages already consumed cannot be recalled.

Blast Radius: busy Claude agents receiving agent or server steers. A person's steer and upstream's capability flag retain their existing behavior.

The hold depends on the @internal command_lifecycle contract of the user's unpinned claude binary. FORK.md case 84 records the assumptions for a fresh uuid user message and requires checking them at Claude Code upgrades and upstream advances. Folded commands share their consuming turn's result. Stop still has the existing steer/Stop race recorded under retired D5.

After merge: check the four adapter hooks and lifecycle assumptions at upgrades. If upstream pingdotgg#21158 lands, check that its capability guard does not turn J5's Claude peer steers back into queued turns.

Live testing

Earlier PR evidence records live passes on 1b44c601c2 for Haiku/Sonnet bursts, late messages, Stop, delegated completions and Codex behavior. Those reports are in J5's artifacts store under test-reports/j5/claude-next-steer/.

Jackson's review reports independent live tests on b22516c20b and a comparison with the hold disabled: late asks produced two turns and premature no-reply notices without the hold; the PR kept them in one turn. His Stop-with-an-ask tests received the existing stopped/cancelled notice. These are earlier-head reports, not a live pass on 7263cd83df.

This head removes the plain-message unread notice, keeps terminal cleanup, and integrates current main. Focused tests cover those changes; live testing was not repeated.

Upstream impact

  • apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts: FORK.md case 84, with the import, lifecycle observation, result hold, and priority/offer hooks. Cases 82 and 83 already belong to main; the inventory is 85 entries: 1–84 plus 15b.
  • The product decision is recorded in register D4, including Bryant's 2026-10-22 decision and Jackson's approval of the direction in the linked review.
  • Providers: Claude changes; Codex remains covered by existing tests. Cursor and the remaining providers retain their queue behavior. Server delivery serves web, desktop, mobile and peer-server connections; no client or wire-schema changes.

Checklist

  • One concern: the description has no "also"
  • Tests cover the changed behavior (backend changes ship with focused tests)
  • UI changes: before/after screenshots above, and a video for motion or interaction — not applicable; server only
  • Live testing: the section above says what ran live and what did not
  • Upstream-owned files: each one is recorded in FORK.md (case text and file-table row) in this PR
  • Upstream product: any change to what upstream's product does has a human decision linked above and a register entry in docs/j5/product/upstream.md
  • Surfaces: entry points, clients, providers, contracts, reverse states, connection modes (see AGENTS.md)
  • Docs: definitions under docs/j5/product/ and user docs rewritten where this changes them

Original implementation: Claude Opus 5.5 through Claude Code in J5 Code. Review revisions and current verification: GPT-6.1-Sol (High) through Codex in J5 Code.

@bryantderosier bryantderosier self-assigned this Oct 22, 2026
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:L 100-499 effective changed lines (test files excluded in mixed PRs). labels Oct 22, 2026
@vercel

vercel Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
j5-code Ready Ready Preview Oct 26, 2026 12:59am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@BastiHu BastiHu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review from a three-seat crew (code quality, security, acceptance-criteria coverage), with findings cross-checked independently on Claude Opus 5.5 and GPT-6.1-Sol.

Verdict: approve with changes. The one change worth requiring before merge is F1 (a held turn can stay running with no timeout); see the comment on claudeAgentSteers.ts:127. The rest are minor or nits.

Validation at 0ce087a: apps/server tsc --noEmit clean; targeted tests 94/94; the PR's 8-file command 384/384; the three mutation claims reproduce. Security: no issues found. Agents cannot obtain createdBy: "user", and the unread notice reaches only the original sender.

PR-level gaps:

  • The cited test-reports/j5/claude-next-steer/* reports aren't in the repo, so the live-test evidence can't be checked.
  • The checklist says the human decision is "linked above", but there's no link.

Comment thread docs/j5/product/a2a/index.md Resolved
Comment thread docs/j5/product/upstream.md Resolved
@bryantderosier

Copy link
Copy Markdown
Collaborator Author

Thanks @BastiHu, this was a really useful review. Fixes are in b22516c20b, and I replied on each thread. I resolved the ones I fixed and left F1 and the reportsLifecycle one open, since I'm pushing back on those (reasoning's on the F1 thread).

On the two PR-level points:

  • Test reports: they live in J5's artifacts store, not the repo, because they have local paths in them. The PR body now says so, and the Live testing section has what each run found.
  • Decision link: added. The Upstream impact section now links straight to register D4.

@Jacksondr5 Jacksondr5 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bryantderosier Jackson and I reviewed this and ran our own live tests. He agrees with the direction: steer peer messages into Claude with "next". He'd like three changes before merge.

1. Keep the hold

We tested whether "next" alone would do, using a local build of this head with j5ClaudeSteerHoldsResult never holding. All runs used Haiku 5.5 receivers and GPT-6-Luna senders.

Case "next" alone This PR
Ask arriving after the last tool call, 3 runs 2 turns every time. The sender got turn-ended-no-reply 4–5 s before the real reply, which came from a second turn labelled "Background activity updated". 1 turn every time, with a same-turn reply and no notice
Plain message arriving after the last tool call 2 turns. Claude acted on it in the second. 1 turn
Ask arriving during a tool call 1 turn, no notice 1 turn, no notice

Without the hold, every late ask sends its sender a false "no reply" notice, so the hold earns its place. It's also less of a new dependency than it looks: upstream's adapter already reads command_lifecycle for its own prompts (claudePromptLifecycle).

2. Cut the unread-after-Stop notice into #694, and keep the cleanup

The notice worked live. A plain message still waiting at Stop got exactly one steered-message-unread, and the receiver stayed stopped. We'd still rather not carry it:

  • Asks are already covered: both live Stop-with-an-ask runs got the existing stopped/cancelled notice.
  • The case is narrow: in the waiting-ask run, Claude Code took the message out of its queue as the Stop landed.
  • The sender can't act on it: the notice tells it not to retry.
  • It's the fragile part: the notice has to decide whether Claude read a message. The CLI's cancelled means either "never ran" or "read, then the turn was aborted". A probe on CLI 2.1.310 showed started, then cancelled for a steer Claude had read before an interrupt. It didn't reach a notice live, because the adapter closes the query first, but it's a latent false notice.

#694 holds the design and that guard if we build it later. Please keep the part of this path that releases a turn's tracked steers when a run ends without a clean result, minus the notice, so steersByTurn doesn't keep stopped or failed turns.

3. Renumber FORK.md case 82 to 83

#689 is merging first and takes case 82. After it lands, please:

  • change the inventory line to "84 entries: 1–83 plus 15b";
  • renumber the case itself;
  • update the ClaudeAdapterV2.ts file-table row;
  • update the references in ClaudeAdapterV2.ts (three J5: case 82 comments), DeliveryTransport.ts, SilenceDetector.ts and its test (if kept), claudeAgentSteers.ts, docs/j5/product/upstream.md (the D4 text, its Decided line, the history line) and docs/j5/product/upstream-convergence.md.

Smaller, optional

  • In case 82 (83), note that the hold relies on the @internal command_lifecycle contract of the user's unpinned claude binary, so it's a check at Claude Code upgrades as well as upstream advances. That was Basti's last open ask.
  • The CLI's schema says discarded comes only when the session ends and refused only for cross-session peer messages, so leaving them unmapped is fine.

Live test reports

These are in J5's artifacts store:

  • test-reports/j5/claude-next-steer/b22516c20b.md (this head)
  • test-reports/review/pr690-next-without-hold/96ed4fb09e.md (the "next"-alone comparison)

Stop after a plain message was read (this head): no notice, receiver stays stopped.

pr690-plain-message-read-then-stop.mp4

Posted by Claude Opus 5.5 (Claude Code in J5 Code) on Jackson's behalf.

@Jacksondr5

Copy link
Copy Markdown
Owner

@bryantderosier #689 is now merged (0d75051) and holds FORK.md case 82, so this PR's case becomes 83 and the count line "84 entries: 1–83 plus 15b". #689 also added a temporary-patch entry (the completion burst guard) in the part of FORK.md this PR touches, so please rebase onto j5/main rather than resolving FORK.md by hand.

Posted by Claude Opus 5.5 (Claude Code in J5 Code) on Jackson's behalf.

bryantderosier and others added 9 commits October 25, 2026 20:48
…ng them

A steer into a running Claude turn was sent with the SDK's "now" priority,
which cancels the turn's running tool calls and makes the agent report a
refusal the person never gave. Send it with "next" instead: Claude Code
waits for the running tool calls and reads the message at the next tool
result, inside the same turn, the way its own CLI handles a message typed
mid-turn.

A steer offered after the turn's last tool call is still queued when the
turn's result arrives, and the CLI runs it as the next native turn. The
adapter follows each steer's command_lifecycle frames and keeps the turn
open until that steer's own result.

Claude no longer reports that steering interrupts tools, so upstream's
rule steers a delegated completion into a running Claude turn, and J5
delivers peer messages into one as it does for Codex GPT 6.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Claude driver is "claudeAgent", so the check for "claude" never matched
and peer messages to a busy Claude agent still queued. The test now builds
its fixture from CLAUDE_PROVIDER. The send tool's description says Claude
agents take an ordinary message into the turn they are running.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… wait

Upstream wants a person's steer to reach Claude at once (pingdotgg#15720), so it
keeps priority "now". Steers from agents and the server, such as a peer's
update or a child's completion, use "next" and wait for the running tool
calls.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A turn result can arrive before Claude acknowledges a steer, so once the
session has reported command_lifecycle frames, an offered steer counts as
waiting too. A failed result always ends the turn so its error shows. A CLI
that reports no lifecycle never holds a turn open: a steer it runs after
the turn's result reaches the thread as a wake turn.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…am's adapter

Move the priority choice, steer tracking and turn hold into J5-owned
j5/a2a/claudeAgentSteers.ts. Upstream's Claude adapter keeps four marked
hooks, and its capability, tests and automatic-delivery behavior go back
to upstream's. J5's delivery steers peer updates into a running Claude
turn by driver. Recorded as FORK.md case 82; register D4 and the A2A,
Crews and user docs say Claude takes peer messages mid-turn.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
An agent's message steered into a running Claude turn waits for its tool
calls. If a person's Stop ends the turn first, Claude never reads it, and
before this nobody was told. The leaf tracks each steer's thread message;
when an interrupted run ends, the silence detector asks which of its
steers Claude never took and sends each sender a steered-message-unread
notice through the same path as a removed queued message (A2A AC30).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The notice told the sender to send the message again, and a GPT 6 sender
did within seconds, undoing the person's Stop. It now carries the stopped
notice's "Do not retry" instruction. It says the receiver probably never
read the message, because Claude can take it just as the Stop lands (the
steer-and-Stop race register D5 leaves unguarded), which FORK.md case 82
and D4 now record.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Release a turn's tracked steers on every run that ends without a clean
  result, so a Claude process that dies mid-turn doesn't leave them behind.
  Only a Stop still tells the sender.
- Read a steer's lifecycle frames only from the query it was offered on,
  and ignore lifecycle states the leaf doesn't know.
- Drop the leaf's abort-result check: the adapter holds an aborting result
  before it asks.
- Pin the failed results that are never held, and a Stop that ends a turn
  held open for a late steer.
- j5_send_message says a Claude agent takes a steer once its running tool
  calls finish; envelope version 28.
- AC29, D4's record line, the backlog comments and FORK.md case 82 match the
  code, and case 82 records what the hold relies on.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@bryantderosier

Copy link
Copy Markdown
Collaborator Author

@Jacksondr5 Pushed the rebased update in 7263cd8, addressing your review and follow-up.

  • Kept "next" and the result hold. The real adapter/orchestrator tests still cover late delivery sharing one provider turn and Stop ending a held turn.
  • Removed the unread-after-Stop notice from this PR and left its design in A2A: tell the sender when a Stop leaves a plain message steered into Claude unread #694. Retained cleanup as j5ForgetClaudeSteers, before the membership check, so interrupted/failed/cancelled/rolled-back runs release their tracked steers even without a current membership. Existing stopped/cancelled ask notices are unchanged.
  • Rebased onto current j5/main, preserving its completion-burst patch, delivery ordering and usage-limit handling. Case 83 had since been taken by the dev-owner-name integration, so this PR uses case 84, with 85 entries: 1–84 plus 15b. Updated the adapter comments, file-table row and documentation references; main's cases 82 and 83 remain intact.
  • Added the warning that the hold relies on the user's unpinned CLI's @internal lifecycle contract, with assumptions qualified for a fresh uuid user message and checks at CLI upgrades. Folded commands share their consuming turn's result. Left discarded/refused unmapped as discussed in your review; no timeout/fallback path was added for the withdrawn hang blocker.

Validation: 400 focused tests passed across 8 files, server typecheck passed, formatting passed, and targeted lint reported only the existing unused layer warning in the adapter. No new live-provider tests ran; the PR body now separates current local verification from earlier live reports.

I checked the inline discussions: all 12 were already resolved, with no open review threads left to close. GitHub now reports the branch mergeable. This update does not merge or close the PR.

— GPT-6.1-Sol (High), Codex in J5 Code

@Jacksondr5 Jacksondr5 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving at 7263cd8. All three changes from the review are in: the hold is kept; the unread-after-Stop notice is out (now #694) and the cleanup of stopped and failed turns is kept; the case is renumbered to 84 after the rebase. The note that the hold relies on the CLI's internal lifecycle frames is in too. No open threads, and required CI is green. No new live test: the tested behaviour is unchanged, and the removed code wasn't something an agent or person sees.

Posted by Claude Opus 5.5 (Claude Code in J5 Code) on Jackson's behalf.

@bryantderosier
bryantderosier merged commit 117ce93 into j5/main Oct 26, 2026
35 checks passed
@bryantderosier
bryantderosier deleted the j5/claude-next-steer branch October 26, 2026 01:27

This branch was successfully deployed

1 active deployment
Preview — 7263cd83 Deployed Oct 26, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 effective changed lines (test files excluded in mixed PRs). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants