Skip to content

Keep a Claude Code turn open until the SDK has run every steer pushed into it - #7321

Merged
ymichael merged 2 commits into
mainfrom
bb/claude-code-keep-turn-open-for-queued-steer-thr_mrjgbn8x5q
Nov 10, 2026
Merged

ymichael merged 2 commits into
mainfrom
bb/claude-code-keep-turn-open-for-queued-steer-thr_mrjgbn8x5q

Conversation

@ymichael

@ymichael ymichael commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

The Claude Code bridge pushes every prompt (new turn or steer) into one long-lived SDK input stream, and it closed the bb turn on the SDK's first top-level result. Suppose a steer is pushed while the SDK is mid-turn and there is no tool boundary where the CLI can fold it in. The CLI then runs the steer as its next SDK turn, with its own replay and its own result. bb had already closed the turn, so the steer's answer arrived as a provider-initiated turn. Every later turn then answered the previous message: the next turn/start was answered with the steer's reply, and its own prompt came back as another provider-initiated turn. In the live trace (dev DB of thr_kskphedncm, thread thr_i7fdv3ia4f, events 477–516), the sdk/user replay inside each turn is the previous round's message, and turns t44/t49 open with no turn/input/accepted.

I confirmed the CLI behaviour directly against the Agent SDK with the installed CLI (2.1.319). Two prompts pushed before the first result produce two SDK turns, each with its own replay and result. A prompt pushed during a tool call is folded in: its replay arrives mid-turn and the single result's user_message_uuids lists both prompts. queued_turn_count on the result reports 0 for these pushes, so it can't be used.

What changed

  • plugins/provider-claude-code/src/delta-translation.ts: the translator keeps the pushed prompt ids per thread. A prompt counts as consumed when the SDK replays it (isReplay user message with that uuid) or lists it in a result's user_message_uuids. If a result carries user_message_uuids and a pushed prompt is still unconsumed, the result leaves the bb turn open, and the SDK turn that answers the steer continues in the same bb turn. Exceptions:
    • A result without user_message_uuids closes the turn as before. Older CLIs report neither replays nor user_message_uuids (the 2.1.238 parity recordings), so a folded steer would otherwise never look consumed.
    • A result that consumed no prompt (for example a stale-resume startup failure) settles the oldest pending prompt, so those turns still fail as before.
  • plugins/provider-claude-code/src/bridge/bridge.ts: pushPromptInput returns the prompt uuid it stamps, and the bridge registers it with the translator when it accepts the input.
  • plugins/provider-claude-code/src/schemas.ts: parse user_message_uuids on results.

Visible difference: a steer that lands just before the SDK finishes now appears in the turn it was accepted into, and that turn ends after the steer's answer. No wire or protocol change.

How you verified

  • New bridge.test.ts cases under "a steer the SDK has not consumed when its SDK turn ends", driven by the two SDK behaviours measured live:
    • the steer runs as the next SDK turn: one bb turn holds both answers, and the next turn/start gets its own turn. On origin/main this fails with expected [ { type: 'turn/completed', … } ] to deeply equal [];
    • the steer is folded into the running turn: the turn completes on the single result (guards against holding forever);
    • a CLI that reports no consumed prompts: the turn completes on the first result, as before.
  • npx vitest run in plugins/provider-claude-code: 29 files, 436 tests passed. @bb/provider-parity replays every recording through the bridge: 59 passed. The first CI run caught the older-CLI hang in claude-code/steer, and the second commit fixes it. @bb/provider-bridge-protocol: 312 passed. pnpm exec turbo run typecheck lint --filter=bb-plugin-provider-claude-code passed.
  • Live, pnpm start:worktree with a Claude Code (haiku) thread. 8 rounds, each starting a turn and steering into it at 0/300/600/900 ms; the check verifies every bb turn's sdk/user replays are inputs accepted into that turn:
    • origin/main: FAIL. Round 5's steer was accepted into t8 but answered in t9 (round 6's turn), and the next turns drifted one behind: t9 accepted=[round 6 turn] replays=[round 5 steer], t10 accepted=[round 6 steer] replays=[round 6 turn], t11 accepted=[] answers=[steer6], plus a replay outside any turn.
    • this branch: PASS: every turn answers only its own inputs. Steers that reached the SDK before its result (rounds 1, 2, 5, 6, 7) share a bb turn with their round's turn, for example t2 accepted=[round 1 turn,round 1 steer] answers=[turn1,steer1]. Later steers start their own turn.

The server-side sibling (the thread idling while a new-turn request is in flight) is a separate PR, since it happens without this drift too.

AGENT GENERATED

🤖 Generated with Claude Code

… into it

A steer pushed while the Claude SDK is mid-turn, without a tool boundary to
fold it in, runs as the SDK's next turn with its own result. The bridge
closed the bb turn on the first result, so the steer's answer arrived as a
provider-initiated turn and every later turn answered the previous message.

The translator now records each pushed prompt id and marks it consumed when
the SDK replays it or lists it in a result's user_message_uuids. A result
leaves the bb turn open while any pushed prompt is still unconsumed. A result
that consumed nothing (a startup failure) settles the oldest pending prompt.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Older Claude Code CLIs (the 2.1.238 parity recordings) neither replay plain
prompts nor put user_message_uuids on results, so a steer folded into the
running turn never looked consumed and the turn stayed open. A result without
user_message_uuids now keeps the previous behaviour and closes the turn. This
drops the fake-CLI replay edits the stricter rule needed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael added a commit that referenced this pull request Nov 10, 2026
## Human comments

## What was wrong

#7310 holds a root `turn/completed` while a **steer** is on its way to
the daemon. A new-turn request (`turn.submit` with `target: start`, or
`thread.start` for edits and forks) has the same window, but nothing
held it. The server applies `run.started` when the message is sent. If a
different root turn ends while the start is still on its way to the
daemon, `applyTurnCompletedEvent` applies `run.succeeded` and the thread
goes idle. The next message is then sent as a second start. The daemon
starts A's turn first and refuses the second with `competing_turn`, and
the user's message is lost.

The other root turn is any turn the provider opens by itself. For Claude
Code, that includes the turn the CLI runs when a background Bash command
finishes (bb doesn't hold the turn for background shells). In the
original trace it was the Claude Code drift fixed in #7321 (dev DB of
thr_kskphedncm, thread `thr_i7fdv3ia4f`, events 501–515). That drift is
one way to trigger it, not the cause: the server window exists without
it.

## What changed

- `apps/server/src/services/threads/thread-send.ts`: the start path
tracks its live command as in flight and settles it in `onSettled`. The
history-replacement `onCommandSettled` still runs first. A root
completion that arrives while a start is in flight is held, exactly as
for steers:
- if the start's turn is running when the request settles, the held
completion is dropped;
  - otherwise it is applied with its usual idle follow-ups.
- `apps/server/src/internal/turn-completed-events.ts`,
`thread-lifecycle.ts`: the in-flight counter now covers steers and
starts, so it is renamed from `trackInFlightSteer`/`settleInFlightSteer`
to `trackInFlightTurnRequest`/`settleInFlightTurnRequest`. Its behaviour
is unchanged.

Visible difference, as in #7310: if a turn ends before its own start
command settles, the thread stays "running" until the start settles,
usually one daemon round-trip. A start that fails still settles the
thread as `error` with later sends left queued, the same as without the
race. No wire change.

## How you verified

- Two new cases in
`apps/server/test/threads/thread-send-dispatch.test.ts`, in the #7310
describe (renamed to "a turn request in flight when a turn ends"). They
use a real migrated DB and the same fake daemon, which refuses `start`
with `competing_turn` while a turn is active:
- an idle thread sends A, a provider-initiated root turn starts and ends
before A reaches the daemon, then B is sent. A and B are both accepted,
with B steered into A's turn;
- the same race, but A's start fails: the thread ends in `error` with B
queued, which matches a failed start without the race.

On `origin/main` both fail with `AssertionError: expected 'idle' to be
'active'`. With the fix, all 52 tests in the file pass.
- `npx vitest run test/threads test/public test/internal test/system
test/routes`: 168 files, 1773 tests passed. The rest of the server suite
passed: 4024 tests; one shell-script test in
`install-machine-script.test.ts` timed out under load and passes on
rerun (54/54). `pnpm exec turbo run typecheck lint --filter=@bb/server`
passed.
- Live, `pnpm start:worktree` with a Claude Code (haiku) thread. Each
round asks Claude to run `sleep 8` in the background, so the CLI later
opens its own notification turn X. It then sends start A with 20–40 × 34
MB attachments, so the daemon stages A for seconds and X runs and ends
while A is in flight. B is sent the moment X ends:
- `origin/main`: `3 round(s) raced; 3 with a rejected message`, each `A
accepted(t18); B rejected:competing_turn`;
- this branch: `6 round(s) raced; 0 with a rejected message`, each `A
accepted(t15); B accepted(t15)`, with B steered into A's turn.

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael merged commit bb8c2af into main Nov 10, 2026
65 of 66 checks passed
@ymichael
ymichael deleted the bb/claude-code-keep-turn-open-for-queued-steer-thr_mrjgbn8x5q branch November 10, 2026 17:53
ymichael added a commit that referenced this pull request Nov 11, 2026
#7396)

## Human comments

## What was wrong

#7321 keeps a Claude Code turn open while a prompt pushed into it hasn't
been consumed yet, using the `user_message_uuids` each result reports. A
background task's notification turn (`origin: task-notification`) ends
with a result that has no `user_message_uuids` list at all. The
translator read that as a CLI that never reports consumed prompts, so it
cleared every pending steer and closed the bb turn. A message sent while
the notification turn was running was then answered in a turn bb had
already closed, and every following reply answered the previous message,
which is the drift #7321 fixed for ordinary steers. Found by #7321's
review; main behaves the same, so this was a gap in #7321 rather than a
regression.

## What changed

`plugins/provider-claude-code/src/delta-translation.ts`:
- A result whose origin isn't a person no longer touches the
pending-prompt bookkeeping.
- Such a result keeps the turn open while prompts are pending, but only
once this session's CLI has reported consumed prompts at least once
(`promptConsumptionReported`). With a CLI that never reports them,
behaviour is unchanged.
- The existing "human origin" check is shared through
`isHumanOriginResult`.

No server, wire or protocol change.

## How you verified

- New bridge test, "keeps the turn open through a task-notification
result that lands before the steer runs": fails on main (1 of 111 in
`bridge.test.ts`) and passes with the fix.
- `pnpm exec turbo run typecheck lint
--filter=bb-plugin-provider-claude-code` and the bridge test file pass
on this branch, which is the fix cherry-picked onto main after #7321
merged.
- Live, by #7321's review thread on a dev server with Claude Code
2.1.322 (before this was cherry-picked onto main): 6 rounds that each
start a background `sleep 4` and steer during the notification turn. On
#7321, rounds 3–5 drifted (the turn holding "ROUND 3 TURN" showed the
notification's answer and closed, and the real answer arrived as an
unprompted turn). With the fix, every message was answered inside the
turn that accepted it. The plain steer-race check also passed 6 of 6
rounds.

Not covered here: a turn that fails while a steer is pending still stays
open and can later end as `completed`. That was reproduced live
separately and is not fixed by this PR.

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
ymichael added a commit that referenced this pull request Nov 17, 2026
…; fix Pi turns after pi exits (#7551)

## Human comments

## What was wrong

The bridge conformance recordings had no case for settings changed
between turns or on a steer, for a steer that races the end of its turn,
or for the provider process dying mid-turn. Bridge fixes in exactly
those areas (#4789, #4794, #4922, #5141, #3299, #6939, #7319, #7321,
#4947) were each caught by hand, after users hit them. ACP was recorded
only for Cursor.

## What changed

Besides the suite, this fixes the bugs it found: Pi's crash handling,
two ACP permission bugs, where Pi keeps its session files, and a Windows
process-kill race. No protocol change. The plugin SDK is bumped to
0.6.150 because its bundled ACP bridge and replay kit changed; its
public surface did not.

- **Pi fixes (`plugins/provider-pi/src/bridge`).**
- **pi died, next message.** After the pi process died, the bridge kept
the thread's session registered with a dead child, so the next
`turn/start` failed with `No active Pi session` and the thread stayed in
error. `PiRpcSession.hasExited()` now lets `reconcileTurnOptions` treat
an exited pi like a settings change and rebuild the session from its
session file through the existing rebuild path. Users see the next
message continue the conversation. The `session/replaced` notice has
`contextLost: false` and isn't shown in the timeline.
- **Steer racing pi's death.** A steer that reached the bridge after pi
died got a generic error: the message was lost and the thread went to
error. It is now rejected with the stale-turn contract (`NO_ACTIVE_TURN`
+ `staleTurn`), as Codex and ACP do, so bb runs the message as a new
turn, which rebuilds the session.
- **Session file missing.** The rebuild silently started a blank
session. It now announces `contextLost: true`, so the timeline shows
"Provider session was replaced; provider-side context was lost. pi's
session file was missing…".
- **Session file corrupt.** pi refused to start, and every later message
failed the same way. Before rebuilding, the bridge now reads the session
file the way pi does. If it isn't a valid pi session, the bridge starts
a new pi session and announces `contextLost: true`, so the timeline
shows the context-loss note and the thread stays usable.
- **Other restart failures.** Any other failure to restart pi is
reported as an error. The thread keeps its session, and the next message
resumes it, so a one-off startup failure doesn't lose the conversation.
- New tests in `bridge.round2.test.ts` cover the steer, missing-file,
corrupt-file and failed-restart cases; each fails without its fix.
`session-cwd.test.ts` checks the session-file check against pi's own
rules (an empty file is valid, and a leading blank or unparseable line
is skipped). The fake pi now rejects an invalid session file the way
real pi does. The Pi `provider-exit` scenario cell was re-recorded
against the fixed bridge.
  - No protocol change.
- **ACP permission rule.** It used to check only that permission
requests the agent raised reached the user, so it was skipped whenever
the agent never asked. It now checks that every command an ACP agent ran
or asked to run after a change to a stricter mode went through the
user's approval. The Cursor and OpenCode `settings-steer` cells are
re-recorded with a command after the permission steer, and no rule is
skipped in any cell.
- The recording driver now answers approvals with allow-once. Cursor
turns bb's "allow for session" into `allow-always` and stores it in its
global allowlist. My earlier recordings had added
`Shell(printf|sleep|python3)` there, which made Cursor stop asking in
every thread; I removed those entries.
- **OpenCode 2 ran shell commands under Accept-edits without asking
(`packages/provider-bridge-acp`).** The bridge passed bb's policy in
`OPENCODE_PERMISSION`, which OpenCode 2.x no longer reads. When the
agent reports version 2 or later in `initialize`, the bridge now writes
bb's rules to the session with `opencode api PATCH /api/session/<id>`
before the first prompt: `edit` allow; `shell`, `webfetch` and
`external_directory` ask (all allow in Full), each on `*`. They go ahead
of the session's own rules, so additional-directory allows still apply.
OpenCode 1.x keeps the environment variable. A mode change already
restarts the session, which re-applies the rules. In Accept-edits, if
the launch command does not end in `acp` or OpenCode rejects the call,
the session fails to start instead of running unguarded. In Full Access
there is nothing to enforce, so a launch command that does not end in
`acp` logs once and the session starts. New bridge test for both modes.
New bridge test: OpenCode 2 gets the rules and keeps its directory rule,
and a switch to Full rewrites them; OpenCode 1.x gets no `api` call.
- **"Allow for session" was stored permanently by Cursor.** The bridge
answered it with the agent's `allow_always` option, which Cursor writes
to `~/.cursor/cli-config.json` for every future thread. It now answers
`allow_once` and keeps the grant in the bridge for that thread's ACP
session, including across the bridge's own rebuilds on a settings
change. Later requests with the same subject (same command, write scope
or tool) are approved without asking. `allow_always` is sent only if an
agent offers no allow-once option. New bridge test: the granted command
runs again without a prompt, a different command asks, and a new thread
asks for the granted command.
- **ACP restore after the agent dies (`packages/provider-bridge-acp`).**
- When a session rebuild failed because the agent exited during
`session/load` or `session/resume`, the bridge had already stopped the
old session and dropped the replacement. Every later message then got
"No active ACP session", and the provider session was never tried again.
The bridge now keeps the thread's settings and provider session after a
failed rebuild and restores them on the next `turn/start`, announcing
the replacement. A thread stop clears this. New bridge test: the agent
dies on its first `session/load`, the next turn resumes the same
session. It fails on the old code with "No active ACP session".
- An agent exit that landed while the bridge awaited the OpenCode 2
`opencode api` calls left a session whose agent was gone, reported as
started. The start now fails with "exited while its session was being
set up". New bridge test, which fails on the old code.
- **Pi sessions in the real `~/.bb` (`plugins/provider-pi`).** The Pi
bridge wrote session files to `~/.bb/pi-bridge-sessions` whatever bb's
data directory was, so source builds and second instances wrote into the
production data dir. Sessions now live in the plugin's
`bridge-data/sessions`. A thread whose file is still in the old place
gets a copy the first time the bridge resolves it; the old file is left
alone. New tests cover the new location, the copy, and that an existing
file is never overwritten.
- **Windows tree kills could hit an unrelated process
(`packages/process-utils`).** `stopWindowsProcessTree` checked that the
child was running, then launched `taskkill /pid <pid> /T /F`
asynchronously. If the child exited in that gap, Node handled the exit
and closed the handle, so Windows could give the PID to a new process
before taskkill ran. taskkill then killed that process and its children.
Forced Windows runs of this suite next to the Pi suite showed it:
provider processes in random cells, Codex included, died at startup with
exit code 1 and no output. With taskkill's output logged, 30 runs showed
9 kills of processes that were not the killer's children.
`stopWindowsProcessTree` now keeps the child's process handle open until
taskkill finishes. While taskkill runs, it holds back Node's internal
close of that handle (`ChildProcess._handle.close`), then makes that
close call once taskkill returns. Windows can't reuse a PID while a
handle to the process is open. The event loop isn't blocked. This
depends on Node's private `_handle`; if a child has none, the stop works
as before, without the guard. A new test checks that the handle stays
open through the child's exit until taskkill finishes, and is then
closed exactly once.
- **The recorder touched the real agent dirs.**
`scripts/provider-recordings/isolate-agent-state.mjs` runs each CLI
against temp config and state: Codex (`CODEX_HOME`), Pi
(`PI_CODING_AGENT_DIR`), Cursor (`CURSOR_CONFIG_DIR` +
`CURSOR_DATA_DIR`) and OpenCode (all four `XDG_*`, with its own service
port, a copy of its active credentials, and a warmed model catalog). A
refreshed `auth.json` is copied back. Two things can't be redirected, so
they are snapshot-and-restore or cleanup. Cursor syncs its built-in
skills into `$HOME/.cursor/skills-cursor` regardless, so that manifest
is restored. Claude Code keeps its sign-in in the keychain under its
config dir, so it can't be moved; instead the run's own `projects`,
`session-env`, `file-history`, `todos` and `debug` directories are
deleted afterwards. `~/.claude.json` is never rewritten, because other
Claude Code sessions write it concurrently.
-
`packages/provider-bridge-protocol/recordings/scenarios/<provider>/<cell>`:
20 new recordings made against the real CLIs (Codex 0.169.0, Claude Code
2.1.323, Pi 1.5.2, Cursor, and OpenCode 2.0.22 as a second ACP agent).
Four cells per provider:
- `settings-follow-up`: follow-ups that each change one setting (model,
env var, permission mode, reasoning level).
  - `settings-steer`: the same four changes, each sent with a steer.
  - `steer-race`: a steer sent as its turn ends, then a follow-up.
- `provider-exit`: the provider process killed mid-command, then a
follow-up.
- `src/testing/provider-probe-child.mjs` + `scenario-replay.ts` (new
`@bb/provider-bridge-protocol/scenarios` subpath, so the SDK bundle
stays unchanged): replay each cell through the current bridge with a
probe between the bridge and the existing replay child. The probe logs
the argv, env and stdin each provider process received, and kills the
provider where the recorded one died (`providerExit` in the manifest).
- `src/testing/recorded-scenarios.ts`: rules that hold for every bridge,
not snapshots:
- every cell: each message is accepted exactly once; every turn carries
the message that started it; every turn settles; a steer whose turn
already ended is rejected as stale.
- `settings-follow-up`: a changed model, reasoning level, env var or
permission mode reaches the provider before it gets that turn's prompt.
- `settings-steer`: a permission change sent with a steer reaches the
provider before it gets the steer. Applying a model, reasoning or env
var change mid-turn is deliberately not required: Codex, Claude Code and
Pi leave it for the next turn, ACP applies it, and both are allowed.
- `provider-exit`: the next message runs in a replacement process that
resumes the same session, or the bridge announces lost context.
- If a replay diverges from its recording, rules that depend on replayed
provider output are reported as skipped with a re-record note instead of
failing.
- `packages/provider-parity/src/scenarios.self.test.ts`: replays all 20
cells (about 15 s wall locally). It fails on any new rule failure, and
on any listed gap that now passes.
- `recordings/scenarios/known-gaps.json` is empty. It held the two
OpenCode Accept-edits gaps until the fix above; the OpenCode settings
cells are re-recorded against the fixed bridge and every rule in them
passes. The suite still fails on a new failure and on a listed gap that
starts passing.
- The replay kit answers `opencode api` calls the way it answers
`--version`, and keeps the agent's own launch args (`acp`) after the
replay args. The probe passes those calls straight through without
logging them as provider processes.
- Packaging normalizations, each noted in its manifest:
- Codex `config/read` responses trimmed to `config.model` (the rest was
the recording machine's config).
- Claude CLI 2.1.323's echoed hook-callback `control_response`s dropped.
The shared replay child would wait on them as answers to bridge
requests.
- Pi lines sent to a retiring child after its replacement spawned moved
ahead of the replacement.
- `scripts/provider-recordings/record-scenario-cell.mjs` records one
cell against the real CLI, through the gated agent-runtime harness
`src/integration.record-scenario-cells.test.ts`. It isn't run in CI.
- `scripts/provider-recordings/package-scenario-cells.mjs` redacts and
normalizes the raw recording and installs the cell. Re-packaging the raw
recordings with it reproduces every committed lane file byte-for-byte.
- The suite prints `<provider>/<cell> needs re-recording` when a replay
drifts.
- `docs/provider-bridge-protocol.md`: describes the scenario recordings,
the rules, and how to re-record.

Cut: a bb-shutdown-mid-turn cell was recorded too. Live, no provider
leaked the running command. But bridges legitimately differ: Codex sends
no interrupt and its app-server cleans up itself, while ACP, Claude and
Pi cancel. So no replay rule holds for every bridge, and the cell isn't
committed.

## Visible behaviour changes

- OpenCode 2 threads in Accept-edits now ask before shell commands, web
fetches and paths outside the workspace, as they did on OpenCode 1. A
custom OpenCode 2 agent whose launch command does not end in `acp` now
fails to start in Accept-edits with an error saying so; in Full Access
it starts as before.
- "Allow for session" on an ACP agent now lasts for that thread's
session only, and nothing is written to the agent's own config. It
covers the same command, write scope or tool. Cursor's own allow-always
covered a command prefix (`Shell(uname)`), so `uname -a` after granting
`uname -s` now asks again. After a server restart the thread asks again.
- Pi session files move under the data dir's
`plugins/provider-pi/bridge-data/sessions`. Existing threads are copied
over on first use. The old files stay in `~/.bb/pi-bridge-sessions` and
are not deleted.
- If an ACP agent dies while its session is being restored, the next
message restores the session instead of failing with "No active ACP
session".

## How you verified

- Pi, live on a source build (`pnpm start:worktree`, fresh dev data
dir). Each case plants a codeword first:
- **Killed mid-turn, then a message.** Before the fix it failed with `No
active Pi session`. After, it answers the codeword.
- **Killed while idle, then a message.** It answers the codeword, with
no context-loss note.
- **Steer racing the death** (bridge frozen with SIGSTOP, pi killed,
steer sent, then SIGCONT). Before the fix it showed "steer failed" and
the thread went to error. After, the steer runs as a new turn and
answers the codeword. The event order confirms the steer was sent while
the turn was still active.
- **Session file removed.** Before the fix it silently answered
`unknown`. After, the context-loss note shows, and the thread answers
the next message.
- **Session file corrupted.** Before the fix every message failed with
"Session file is not a valid pi session". After, the timeline shows
"pi's session file is not a valid pi session, so the conversation
continues in a new session without its earlier context." and the message
runs in a new session.
  - The `bb-plugin-provider-pi` tests, typecheck and lint pass.
- Platforms: pi's exit detection has no platform-specific branch: it
uses Node's `exit`/`close` events. The Linux and Windows CI replays run
the real Pi bridge (exit detection, rebuild, stale-steer reply) against
a replay child that the probe kills with SIGKILL, and the new unit tests
run the same bridge against the fake pi. On Windows the probe proxies
the Pi extension channel through a named pipe. The live runs above used
the real pi CLI on macOS.

- OpenCode 2 Accept-edits, live on a source build. Before the fix, a
thread ran `touch` with no approval. After, it shows "Waiting for
approval to run touch oc-accept.flag", and the file appears only once
the command is approved. The session's rules read back with `opencode
api GET` as bb's four, followed by the thread-storage directory allow. A
Full thread runs the command with no prompt.
- OpenCode 1.19.5 (installed in a temp prefix, run as a custom ACP agent
with temp `XDG_*` and `HOME`): an Accept-edits thread still asks before
`touch`, and the bridge makes no `api` call.
- "For session", verified where each part lives.
- On Cursor, the Cursor-specific part: before the fix, approving `uname
-s` for session added `Shell(uname)` to `~/.cursor/cli-config.json`, and
a new thread then ran `uname` without asking. After the fix, the same
approval leaves the file byte-identical (same sha1), and the command
runs.
- On OpenCode 2.0.22, live, the two steps that run in bridge code shared
by every ACP agent. Approving for session added no rule to OpenCode's
session. The same command in the same thread then ran with no new prompt
(one interaction in total), and a new thread asked again. The bridge
test covers them too: the granted command runs again without a prompt, a
different command asks, and a new thread asks.
- Pi sessions, live on a source build with its own data dir. A new
thread's session file is written to `<data
dir>/plugins/provider-pi/bridge-data/sessions`, and
`~/.bb/pi-bridge-sessions` is unchanged (325 files). After a server
restart the thread resumes from the new location and recalls its
codeword. Moving that file to the old location and restarting again
copies it back on resume, with the codeword kept.
- Isolation, live: one real cell each through the recorder for Codex,
Pi, Claude Code and Cursor, plus the two OpenCode settings cells.
Afterwards nothing tied to the run's workspace exists in `~/.codex`
(rollouts, `state_5.sqlite` threads), `~/.pi/agent`,
`~/.bb/pi-bridge-sessions`, `~/.claude`, `~/.cursor` (acp-sessions,
projects, `cli-config.json` sha), or OpenCode's real database. Config
and auth hashes are unchanged. Claude's own startup still rewrites
`plugins/known_marketplaces.json` (refresh timestamp) and adds one shell
snapshot, as any Claude start does; those are left.
- `@bb/provider-bridge-acp` (589 tests), `@bb/provider-bridge-protocol`
(312) and `@bb/provider-parity` (80) pass. The Pi session-file tests and
the typecheck and lint for all five touched packages pass too.
- Flakiness: a temporary workflow on a throwaway branch (this PR's head
plus only that workflow, same runners as CI) ran `turbo run test
--filter=@bb/provider-parity --filter=bb-plugin-provider-pi --force`. On
the final code: Linux 10/10; Windows 280/280 (20 runs, 20 more with
logging, and 240 looped runs). Every scenario suite was 21/21 with no
drift notices and no skipped rules, and every Pi suite passed. The
scenario suite takes about 21 s on Linux and 27 s on Windows (max 34 s).
Re-running CI jobs can't show this, because every re-run is a turbo
cache hit.
- Before the process-utils fix, Windows failed 6 of 40 runs: provider
processes in random cells died at startup and the replays stalled. The
Linux run that caught the probe-log cleanup race (`ENOTEMPTY`) was fixed
by retrying that removal.
- Windows sometimes failed `provider-exit` on `conversation-survives`:
twice on `acp-cursor` earlier, and once in 220 `acp-opencode` runs of a
loop. The loop's per-process log showed the cause. The bridge had
resumed the session correctly, but Windows had given the replacement
probe the dead probe's PID. The probe named its log after its PID, so
both processes' entries landed in one file, and the rule saw no
replacement. Logs are now named per process. Afterwards a cache-bypassed
Windows loop ran `acp-cursor/provider-exit` 1,100 times and every other
provider-exit cell 220 times. All passed, with no drift. Zero failures
in 1,100 puts the Cursor cell's failure rate below about 0.27% at 95%
confidence, and below about 1.4% for each of the others. The same run's
forced suite passed on Linux 10/10 and Windows 20/20.
- `vitest run src/scenarios.self.test.ts` in `@bb/provider-parity`:
21/21 pass, three runs, including two at load average ~40.
- Removing a known gap makes its cell fail with that rule.
- `turbo run typecheck lint lint:type-aware` for
`@bb/provider-bridge-protocol` and `@bb/provider-parity` passes.
- The existing parity fixture checks and the recordings redaction test
pass. The redaction sweep finds no survivors in the new cells.
- The scenarios were also run against the commits before and after the
past fixes listed above. Those proof runs are reported in the bb thread,
not committed.

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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