Skip to content

fix(cli): queue remote prompts instead of dropping or overlapping turns - #226

Merged
BunsDev merged 1 commit into
mainfrom
fix/bridge-prompt-queue
Oct 15, 2026
Merged

BunsDev merged 1 commit into
mainfrom
fix/bridge-prompt-queue

Conversation

@BunsDev

@BunsDev BunsDev commented Oct 15, 2026

Copy link
Copy Markdown
Member

Summary

Remote-control prompts are no longer lost while a turn is streaming. Two prompts in one bridge poll no longer start overlapping model requests; they run as sequential turns.

Context

  • Related request: Coven Code surface-reduction goal, unit 17 ("Supplementary remote prompt queue retention" and "Remote prompt ownership: primary and supplementary FIFO" in the surface inventory ledger). Follows fix(bridge,cli): own and join bridge worker tasks through shutdown #222 (bridge task ownership), which owns supplementary cancellation and draining on disconnect.
  • Scope: crates/cli/src/main.rs remote prompt intake and turn start, plus a live fixture script.
  • Non-goals: no global server-time ordering or cross-transport deduplication; FIFO holds within each transport. No drop/truncation policy for a fast remote producer. No change to remote literals: they do not go through the local Enter or slash-command path.

Changes

  • Supplementary: the old while/if received before checking streaming, silently consuming every queued item while busy. A remote cancel could also clear is_streaming while current_query still owned the previous task, so the next prompt replaced that handle.
  • Primary: TuiBridgeEvent::InboundPrompt spawned a query for every message and replaced current_query/cancel. One poll batch started two concurrent API requests.
  • Now the primary handler appends the literal text to a local VecDeque and keeps processing control and permission events. take_remote_prompt returns at most one prompt per frame, only when !is_streaming && current_query.is_none(). Already-observed primary messages come first, then supplementary ones on the next idle frame. Both transports use the existing remote launch setup (goal baseline, effective model, token limit, message bookkeeping), and one duplicated query-launch block is removed. Primary prompts are cleared on disconnect.
  • Four unit tests cover each busy flag alone and together, supplementary backpressure, one dequeue per frame, primary/supplementary ordering, a late primary arrival, and literal /exit preservation.
  • New scripts/test_remote_prompt_queue.py runs the debug binary with isolated HOME/cwd, a dedicated tmux, dummy credentials and localhost bridge/SSE endpoints. It checks that:
    • two primary prompts become sequential completed turns;
    • the first response is in the second request's history;
    • /exit reaches the provider literally;
    • after a queued prompt plus Cancel, exactly one request is outstanding until headers are released.

Surface: main.rs production code before the test module is 5496 -> 5459 lines (-37), with one duplicate launch block removed.

Validation

  • RED (old base): with streaming active, 2 queued items were drained to zero, and an outstanding query returned a prompt instead of waiting. One poll batch started two concurrent API requests.
  • cargo test --locked -p claurst --bin coven-code: 103 passed, 0 failed (includes the 4 remote-prompt tests and fix(cli): deliver remote permission replies to the waiting tool #214's 3 bridge-permission tests).
  • cargo fmt --all -- --check, cargo check --workspace --locked, cargo clippy --workspace --all-targets --locked -- -D warnings: pass on this branch (current main, including fix(bridge,cli): own and join bridge worker tasks through shutdown #222).
  • python3 scripts/test_remote_prompt_queue.py <debug coven-code> on this branch: both cases pass, with 2 sequential provider turns, the literal /exit delivered, and the second reply rendered.
  • ... --expect-startup-cancellation on this branch (with fix(query): honor cancellation while a stream is starting #216): passes. The cancelled request closes before headers and the next turn starts. The first strict attempt passed its assertions, then hit a fixture teardown race (TemporaryDirectory cleanup while the engine still wrote sessions.db-journal); the rerun passed cleanly.
  • git diff --check: clean.
  • cargo test --workspace: hosted Rust CI. Source integration assembly: 2,018 passed, 0 failed, 8 ignored.
  • Independent specification/quality review accepted the production change and the tightened live fixture.
  • Port note: the disconnect path keeps fix(bridge,cli): own and join bridge worker tasks through shutdown #222's runtime shutdown and join; this unit only adds pending_remote_prompts.clear() ahead of it, matching the verified integration assembly.

PR Readiness

  • Diff is limited to the intended files.
  • Generated files were not edited by hand.
  • User-facing docs: not needed.
  • No secrets, credentials, local paths, or unrelated logs are included.
  • Remaining risks:
    • The primary backlog is unbounded if the remote producer outpaces turns.
    • The supplementary bounded channel can backpressure its poller while busy (preferable to silent loss).
    • Live evidence is macOS/tmux only.
    • The live fixture's temp-dir teardown can race the engine's final SQLite write.

The supplementary dequeue drained every queued remote prompt while a
turn was streaming, and a remote cancel could clear streaming while the
previous query still owned current_query, so the next prompt replaced
its handle. Primary-transport prompts skipped the queue entirely and
spawned a query per message, so one poll batch started two API requests.

Primary InboundPrompt now appends literal text to a local queue and
keeps processing controls and permissions. take_remote_prompt starts at
most one turn per frame, only when nothing is streaming and no query is
running, drawing primary messages first and then supplementary ones,
through the existing remote launch setup. One duplicated query-launch
block is removed. Primary prompts are cleared on disconnect.

Four unit tests plus scripts/test_remote_prompt_queue.py (live tmux
fixture with localhost bridge and SSE endpoints).

Coven-Harness: Claude Code / claude-opus-5-5
@vercel

vercel Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
docs Ready Ready Preview Oct 15, 2026 7:59am UTC

Request Review

@BunsDev
BunsDev merged commit 98f11e8 into main Oct 15, 2026
6 checks passed
BunsDev added a commit that referenced this pull request Oct 15, 2026
…ng (#272)

Goal-bearing commands lost their captured authority in the payload,
rate-limit and transport retries could re-send after the goal was
replaced, an unattempted turn's UUID stayed in the persisted session,
and old background children could mark a later turn. Track attempt
state per captured logical turn (retries and their child/housekeeping
work share it; each continuation gets fresh state), mark requests as
attempted at the transport, roll back a turn that never reached a
provider, and open rate-limit recovery only from the joined outcome,
retaining the abandoned owner until its outcome is gated. Interactive
launches go through InteractiveTurn/InteractiveQuery.

The remote-control launch keeps #226's queue ownership: remote prompts
stay in their own FIFO (never the local Enter path) and also wait while
a file-injection decision is pending.

Enhancement unit 8b.

Coven-Harness: Claude Code / claude-opus-5-5
@BunsDev
BunsDev deleted the fix/bridge-prompt-queue branch October 18, 2026 07:50

This branch was successfully deployed

1 active deployment
Preview — 1906ca1c Deployed Oct 15, 2026 by vercel[bot]
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