Skip to content

fix(cli): keep driven agents receiving relay messages - #1368

Merged
willwashburn merged 2 commits into
mainfrom
fix/drive-live-delivery
Jul 30, 2026
Merged

fix(cli): keep driven agents receiving relay messages#1368
willwashburn merged 2 commits into
mainfrom
fix/drive-live-delivery

Conversation

@willwashburn

@willwashburn willwashburn commented Jul 27, 2026

Copy link
Copy Markdown
Member

Behavior

node agent attach --mode drive asserts auto_inject, so a driven agent goes on receiving relay messages while you watch it. Ctrl+] holds delivery for when the screen must stay still while typing; a second press drains the parked queue and returns to live delivery. Detach still restores an explicit pre-attach hold via the same compare-and-set.

The status line's pending counter reports only messages the inbound hold actually parked.

Why

drive previously flipped the agent into manual_flush for the whole session, so every inbound relay message parked until Ctrl+] or detach. Watching a team therefore stopped it: three PTY agents playing tic-tac-toe with a drive session attached to each exchanged 8 messages in seven minutes and never finished, where the same unattended run exchanged 21 and finished in three. Agents made progress only by polling check_inbox — the push path was frozen for the session's lifetime.

Two layers emit delivery_queued: the inbound hold, which means "parked", and the harness runtimes, which emit it for every delivery they queue for injection — ordinary traffic on its way to the agent. The counter added both. Under manual_flush that was mostly hidden; with live delivery it would climb on every message and never come back down, since nothing drains a queue the message was never in. It now counts only frames carrying the hold's reason.

Verification

  • vitest run packages/cli — 782 passed, 9 skipped
  • tsc --noEmit — clean
  • Live: three PTY agents spawned with agent new --mode drive, each attached in a real PTY, played a full tic-tac-toe game to a draw in 3m15s over 21 relay messages, with every status line reading delivery=auto_inject | pending=0.

Relationship to #1364 and #1366

Those fix the status line tearing the pane and are independent of this change. This one is the delivery half: #1364 attributed the "agents never used the relay protocol" symptom to operator error, and the measurements above show the session-long manual_flush was starving them. This PR does not touch renderStatusLine, so it composes with either rendering fix.

Review in cubic

@willwashburn
willwashburn requested a review from khaliqgant as a code owner July 27, 2026 16:20
@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2681d22e-d9cd-422a-aa57-012a38f5de00

📥 Commits

Reviewing files that changed from the base of the PR and between 3b9e9b7 and 3d12838.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • packages/cli/src/cli/lib/attach-drive.test.ts
  • packages/cli/src/cli/lib/attach-drive.ts
  • packages/cli/src/cli/lib/attach.ts

📝 Walkthrough

Walkthrough

drive now attaches workers in auto_inject mode, updates Ctrl+] toggling and cleanup restoration, filters pending deliveries by cause, validates broker transitions, and expands terminal status handling and tests.

Changes

Drive delivery behavior

Layer / File(s) Summary
Filter held delivery events
packages/cli/src/cli/lib/attach-drive.ts, packages/cli/src/cli/lib/attach-drive.test.ts
Only inbound manual-flush delivery_queued frames affect pending counts, with replay, drain, and harness-injection cases covered.
Adopt auto-inject attach state
packages/cli/src/cli/lib/attach-drive.ts, packages/cli/src/cli/lib/attach.ts, packages/cli/src/cli/lib/attach-drive.test.ts
Attach, toggling, broker transition validation, interruption cleanup, and guarded restoration now use the auto_inject baseline.
Validate terminal status rendering
packages/cli/src/cli/lib/attach-drive.ts, packages/cli/src/cli/lib/attach-drive.test.ts
Status rendering tests cover terminal width, truncation, ANSI output, repaint holding, predictive echo, and row restoration.
Record release behavior
CHANGELOG.md
The unreleased minor entry documents delivery-mode behavior, build changes, and pending-counter corrections.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant DriveCommand
  participant runDriveSession
  participant DeliveryModeAPI
  participant WorkerWebSocket
  DriveCommand->>runDriveSession: start drive attach
  runDriveSession->>DeliveryModeAPI: set auto_inject
  runDriveSession->>WorkerWebSocket: receive delivery events
  runDriveSession->>DeliveryModeAPI: toggle mode on Ctrl+]
  runDriveSession->>DeliveryModeAPI: restore mode with CAS guard
Loading

Possibly related PRs

Suggested reviewers: khaliqgant, claude

Poem

I’m a rabbit guarding queues tonight,
Auto-inject keeps the burrow bright.
Ctrl+] makes held hops wait,
Then drains them through the gate.
Pending counts now tell what’s true.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: drive mode keeps agents on live relay delivery.
Description check ✅ Passed The description is detailed and covers behavior, rationale, and verification, though it doesn't follow the template headings exactly.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/drive-live-delivery

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3b9e9b7652

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/cli/src/cli/lib/attach-drive.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@CHANGELOG.md`:
- Line 8: Update the unreleased changelog heading from “## [Unreleased - Minor]”
to the standard “## [Unreleased]” format, leaving the release classification for
the eventual versioned entry.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 83f142e3-0f01-4068-b5ed-6c67a54a746d

📥 Commits

Reviewing files that changed from the base of the PR and between af898f7 and 3b9e9b7.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • packages/cli/src/cli/lib/attach-drive.test.ts
  • packages/cli/src/cli/lib/attach-drive.ts

Comment thread CHANGELOG.md
willwashburn and others added 2 commits July 29, 2026 21:01
Attaching with `drive` put the agent in `manual_flush` for the whole session,
so every inbound relay message parked until Ctrl+] or detach. Watching a team
coordinate therefore stopped it: three driven agents exchanged 8 messages in
seven minutes where the same unattended run exchanged 21 in three.

`drive` now asserts `auto_inject` on attach. Ctrl+] holds delivery for when the
screen must stay still while typing, and a second press drains the queue and
returns to live delivery. Detach still restores an explicit pre-attach hold.

The status line also counted every `delivery_queued` frame, including the ones
harness runtimes emit for their own injection queues. With live delivery that
count climbed on ordinary traffic and never came back down, so it now counts
only the frames the inbound hold actually parked.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@willwashburn
willwashburn force-pushed the fix/drive-live-delivery branch from 3b9e9b7 to 3d12838 Compare July 30, 2026 01:07
@willwashburn
willwashburn merged commit fbc8c27 into main Jul 30, 2026
41 checks passed
@willwashburn
willwashburn deleted the fix/drive-live-delivery branch July 30, 2026 01:16
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