Repository navigation
Conversation
ymichael
marked this pull request as ready for review
November 14, 2026 01:05
ymichael
marked this pull request as draft
November 14, 2026 04:54
ymichael
marked this pull request as ready for review
November 14, 2026 06:11
ymichael
marked this pull request as draft
November 14, 2026 06:11
ymichael
force-pushed
the
bb/provider-session-contract-one-draft-pr-thr_y6mc8pqzcs
branch
from
November 14, 2026 06:48
79ed286 to
265fbb9
Compare
ymichael
marked this pull request as ready for review
November 14, 2026 06:52
ymichael
force-pushed
the
bb/provider-session-contract-one-draft-pr-thr_y6mc8pqzcs
branch
from
November 17, 2026 04:02
265fbb9 to
217bf14
Compare
ymichael
force-pushed
the
bb/provider-session-contract-one-draft-pr-thr_y6mc8pqzcs
branch
3 times, most recently
from
November 19, 2026 02:21
b331d11 to
49cce10
Compare
3 tasks done
ymichael
force-pushed
the
bb/provider-session-contract-one-draft-pr-thr_y6mc8pqzcs
branch
from
November 23, 2026 21:16
49cce10 to
be5a75c
Compare
…red settings Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ymichael
force-pushed
the
bb/provider-session-contract-one-draft-pr-thr_y6mc8pqzcs
branch
from
November 23, 2026 21:30
be5a75c to
ae0e734
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human comments
What was wrong
bb guessed what each agent was doing. Bridges inferred turn ends and busy agents from silence and grace timers (Codex 250 ms / 5 s zero-work grace, ACP 5 s quiet turns and 2 s busy waits, Pi 5 s extension-report timeouts), a
turn.boundarycould claim a turn nobody opened (claimIfIdle), and the server guessed compaction from the request text in two places (isManualCompactionActive). Each bridge diffed settings itself and restarted provider sessions whenever it decided to, with no check for running work (Claude per-setting restarts, CodexconstructionSignature, ACPreconcileExecutionSettings, Pi rebuilds), while the daemon evicted whole environments on any shell-env change and swapped the environment-wide skill catalog. Capabilities came from bb's catalog: per-agentsupportsManualCompactionoverrides, a fake "Agent default"/"medium" ACP model, and a hard-coded list of 1M-context Claude models. Plan:plans/provider-session-contract.mdin @thread:thr_hdhvdu78fj.Fixes #7040
Related, partly addressed but not fixed: #3636, #4942, #5359, #5843, #6301.
What changed
All three phases, one PR. Every mechanism on the plan's deletion list is deleted for bb's built-in bridges (
rgfor each name finds nothing); nothing old runs beside the new system. The one deliberate exception is main'sclaimIfIdleinference, kept only inside the protocol 2 compatibility path for third-party bridges (below), with a removal condition indocs/provider-bridge-protocol.md.Phase 1: one state machine, one gate, open work
packages/agent-runtime/src/runtime-session-state.tsreplaces the turn-state tracker, pending-start map and idle-since map with one per-thread machine: starting → idle → turnStarting → turnRunning → compacting / waitingOnUser → stopping → dead. It moves only on explicit reports (turn.open,turn.boundary, thecompactionitem lifecycle, interaction requests, request results). The turn-start watchdog stays as a backstop.turn/startonly from idle and a steer only into the turn it names, and answersbusyitself while starting, stopping or compacting.turn/startandturn/steernow return{admission: "accepted" | "busy" | "rejected"}from the bridge;acceptedcomes only afterinput.acceptedis on the wire.thread_busy/turn_rejected(COMPETING_TURN_ERROR_CODEandCompetingTurnErrorare gone). The server's lifecycle machine (lifecycle/machine.ts) answers them asbusyandrejectedturn-request answers: it records a busy request as refused and re-sends it behind the running turn, or after a backoff of 5, 10, 20, 40 and 80 s when no turn runs; after six busy answers in a row it stops and fails the run with aprovider_busyerror the user can retry. A rejected request settles the thread idle with the reason visible. Sends, steers, queued messages and parent notices all go through this one path.claimIfIdleis removed from the protocol 3 grammar and assembler; bridges open every turn explicitly. Output an agent sends with no prompt in flight is recorded on the last turn (attach: "currentOrLast"on text deltas and closes,item.openanditem.close) instead of opening a turn.thread/openWorkrequest (openWork: {list}capability). The runtime refuses to reap, restart (restartRecommended, now checking the thread itself as well as siblings) or resume a session while its phase, timeline background work, plugin tool calls or the bridge's list show open work. A failed or timed-out probe counts as busy for that attempt; after three failures in a row the thread gets a note saying bb can't confirm no work is running and that stopping the thread applies the change. Bridge-internal auth recovery stays ungated.claimIfIdle(protocol 3), CodexZERO_WORK_SETTLEMENT_GRACE_MS/GOAL_RESUME_TURN_GRACE_MS, ACPAGENT_TURN_QUIET_MS/SESSION_BUSY_QUIET_MSand the activity-based agent turn opening (startsAgentWork), PiAGENT_END_LEAF_TIMEOUT_MS, bothisManualCompactionActivechecks (plus the now-unusedisStoredTurnProviderCompactionRunningandgetStoredTurnRequestEventForTurnqueries).Phase 2: one settings reconciler
capabilities.sessionSettingsper setting and per value (live | resume | fresh), and may narrow it per session in thread start/resume/fork results.runtime-session-settings.tsdiffs the desired record (options, env, instructions, tools, skills, plugin build) against the applied one at eachturn/start, and only there: nothing is applied to idle threads in the background, and a turn causes at most one resume. Live changes go out inturn/start.apply; resume changes release and resume the session (new bridge process for skills/build changes) when no work is open, after a note that background processes bb does not track may stop; otherwise the turn runs on the old values and a thread note says what waits and why. Fresh changes never auto-apply.reconcileExecutionSettingsrestart predicate andrebuildAgentSession(a crash-onlyrecoverAgentSessionremains), CodexconstructionSignature/environmentHashand the steer interrupt-restart, Claudeapply{Chrome,Subagent,ContextWindow,Artifact}Setting, the bypass restart branch,applyTurnEnvironment/environmentSignature, the steer restart and the resume deep-equal, PireconcileTurnOptionsrebuild/rebuildThreadSession, daemonshellEnvGeneration,evictIdleRuntimeEntries,replaceEntryForSkillCatalog,SkillCatalogConflictError,retainedSkillCatalogHashes.effortper turn) live, memory/subagents/env/skills resume, instructions/tools fresh. Claude model/reasoning/tier/permission live exceptfull(resume; narrowed to live for sessions launched with bypass), chrome/subagents/1M/artifacts/env/tools/skills resume, instructions fresh. ACP native model/reasoning/permission live, narrowed to resume for launch-flag models and permission args; env/tools resume; instructions/skills fresh. Pi model and thinking live viaset_model/set_thinking_level; env/tools/skills/instructions resume.Phase 3: capabilities from the live session
supportsManualCompactionoverrides (old custom-agent entries are ignored). ACP no longer declares compaction: bb offers the built-in/compact(menu, compact-before-send offer,bb thread compact,--compact-first) when a provider declares it or the thread's livebb/provider-commandslistscompact, so ACP agents show it only once the agent advertises a compact command.ACP_DEFAULT_MODEL. An agent with no model list reports one entry from the live session'sagentInfo, with no invented effort;availableModelSchema.defaultReasoningEffortis now optional. Launch-flag (modelCli) agents only receive model ids their list contains; a storedacp-defaultor unlisted id is not passed and bb warns.LARGE_CLAUDE_CONTEXT_MODELS; the context window comes from the live session (getContextUsage,result.modelUsage).Third-party bridges: protocol 2 compatibility
capabilities.sessionSettings, runs on a compatibility path (packages/provider-bridge-protocol/src/protocol-v2.ts,assembler/protocol-v2.ts); the second case also logs one stderr line naming the missing field. This catches bridges such as NanoGPT and MoA that report the SDK'sPROVIDER_BRIDGE_PROTOCOL_VERSIONconstant: bumping their SDK would otherwise claim 3 without implementing it.claimIfIdleboundaries open and settle a turn as main's assembler did, anyturn/start/turn/steerresult counts as accepted, every turn carries the full options with noapply, steers carry their own options, env and instructions (including lowered permissions), and there is nothread/openWorkprobe, no settings note and no settings-driven resume. Env, skill, tool and build changes are applied by a resume at the next turn start, the equivalent of main's idle-bridge restart. The runtime's own busy gate, phases and watchdog are shared; none change the wire.handshake/session-contractfails a bridge that claims 3 withoutsessionSettings.Versions and docs
PROVIDER_BRIDGE_PROTOCOL_VERSION2 → 3 (grammar snapshot renamed to v3). Protocol 2 bridges keep working through the compatibility path.HOST_DAEMON_PROTOCOL_VERSION271 → 272 (new error codes and their meaning).@get-bb/plugin-sdk/provider-bridgeexports the new schemas and types.turn/admission-answered,openWork/list-declaredandhandshake/session-contract; the cross-provider permission contract now drives Codex and Claude through their own declarations.docs/provider-bridge-protocol.md(new "Session contract" and "Protocol 2 compatibility" sections; Sessions items rewritten),docs/provider-plugin-api.md,docs/configuration.md, the Plugin Guide provider-bridges card, the plugin-authoring providers reference, the thread-messaging guide, and the Claude, Codex, ACP and Pi plugin skills/readmes.agentSettledsettles turns on Pi's explicit settlement report; older Pi ends each turn onagent_endas before. The bridge chooses by the extension handshake, not a timer.Success measures (non-test source). Timing constants in the four bridges: 53 → 48. Runtime: 7 → 8 (the open-work probe timeout). Issue inflow can only be measured after release.
Rebased onto main (Nov 18)
Main's newer work is kept and moved onto this PR's model:
requeue-busy-requesteffect re-queues the message after the commit. Thecompeting_turnrefusal and its exception for a running root turn are gone from the machine.RuntimeSessionStates: the turn-start request joins the turn when it opens, and accepted steers join it.waitingOnUserphase end together when the agent withdraws a question.rebuildBeforeNextPrompt,restoreUnrestoredThread) runs throughrecoverAgentSessionat the nextturn/start. Show automatic compaction of ACP agents as a compaction row #7752's agent-started compaction opens an agent turn and settles it when the compaction ends (no quiet timer) and is listed as open work. Never report a failure as the user's answer to an agent #7723's answer-without-user warnings and Close approval cards the agent withdraws #7797's withdrawals settle interaction turns as before; a new prompt withdraws pending questions before it ends the agent's turn.turn/start(restoreExitedPiSession, reading the session file as before), and a steer after pi exits is rejected as stale. Settle Pi prompts that an extension command handled #7583's check that a "handled" or undisposed prompt really ran no turn is kept.bridge.session-settings.test.ts. The "routing changes during a turn" case now goes through the release and resume the runtime does for an env change.turn/startusessession.resolveModel, and session construction applies the selected model and thinking level as on main.pendingSteers) instead of rows. A busy-refused message bb is still re-sending stays a row at its request, whether its refusal is on the page or only in page context, so paging gives the same result as a full build.settings-follow-up/settings-steercells recorded main's in-bridge rebuilds, so their replays drifted. I re-recorded them against the real CLIs through this branch's runtime (Codex 0.169.0, Claude Code 2.1.325, Pi 1.5.2, cursor-agent 2026.06.19, OpenCode 2.0.22). The OpenCode cells now switch fromdeepseek-v4.1-flash-freetotidepool-alpha-free:glm-5.3-flash-freeis no longer listed, and the agent reports reasoning levels only for its current model. The scenario rules accept a turn with no reasoning level. All 80 scenario checks pass, andknown-gaps.jsonstays empty.Breaking changes
/compactonly when they advertise a compact command.Fix coverage
Each fix this PR replaces, the tests that covered it on main, and what covers it now.
runtime.pi-compaction-busy.test.ts: "the runtime answers busy while a Pi extension compacts, and the retried turn starts after compaction ends", "...relays Pi's busy refusal for a prompt that races the compaction start...", "...answers busy during bb's /compact and starts the next turn after it ends". Bridge: "answers busy while a Pi extension compacts after a run, and gives the compaction its own turn", "answers busy when Pi refuses a prompt for a compaction the bridge had not seen start", "answers busy to a steer and a new turn while bb's /compact runs...". Server: "re-queues a send the runtime refuses busy during compaction and delivers it after the compaction turn". "drops a prompt held behind compaction..." is obsolete: the bridge no longer holds prompts.bridge.turn-options.test.ts(6 tests)apply.settingsin the same file (model and thinking live, compaction model, unresolvable model keeps the session, steer applies nothing). "keeps serving the thread when the replacement child never starts" is obsolete (no child respawn). New: runtime "fails the turn when the settings resume fails and resumes cleanly afterwards".runPermissionChangeCase, native live, launch flag with and without load, opencode env); "never applies a permission change a steer carries, and applies it on the next turn/start that lists it" (native and launch flag, through the reconciler); "answers a second simultaneous start busy"; "delivers stacked steers on the same turn". The failed-replacement test is obsolete: steers no longer rebuild, and a failed resume is the runtime's (covered by the #2221 row).bridge.zero-work-turn.test.ts(11),translator.turn-response.test.ts(3)apply. Added "fails a turn/start answer that reports no turn instead of inventing one", "answers accepted only after the turn it opened is on the wire".it.each"preserves the session across CLI $setting changes (restorable=$restorable)"fresh, never applied): new runtime "keeps the old model on a session it cannot restore and says so once", plus "turns a resume into fresh for a session that cannot be restored".it.each"reports a runtime %s refusal of status %s with the %s error code" (start/steer × busy/rejected). Server "queues a busy refusal behind the running root turn instead of failing the run" (restored: root turn completes, the retry goes out, the queue empties); "returns the thread to idle and schedules the retry when no turn is running" replaces the run-failure case.bridge.interruption-recovery,rpc-session.settlement,run-settlement,delta-translationtestsclaimIfIdle)./goal resumebindingbridge.goal-controls.test.ts(7), server "clears a paused Goal"How you verified
Live, this round (dev instance built from this branch, driven with
pnpm bb:dev, plus bridges driven directly against real CLIs):sessionSettings, so it runs on the compatibility path and logs one stderr line). Each ran three turns and a mid-turn steer throughcreateAgentRuntimeagainst a local OpenAI-style server: all turns started and settled, the steer joined, model and API-key changes reached the server, and the runtime sent onlyinitialize,thread/start,turn/start×3 andturn/steer(noapply,thread/openWork,thread/stoporthread/resume)./goal(codex 0.169.0, through the bridge): a prompt that callscreate_goalset a Goal; Stop during the Goal turn paused the Goal before the interrupt and settled the turn interrupted;/goal resumeafter a thread resume set the Goal active and was accepted into the Goal turn Codex started, which ran tocompleteabout 33 s later;/goal pauseon the completed Goal was rejected with a reason;/goal clearsettled with an empty turn and no Codex turn. The no-turn case (a fork withdeferGoalContinuation) settled/goal resumein 22–333 ms with an empty turn.session_before_compactfor 6 s so the window was observable): during bb's/compacta steer, a new turn and a second/compactwere all answeredbusyand the compaction item stayed open; the next turn after compaction was accepted. The same for an extension-startedctx.compact()onagent_settled(Pi: a message sent during an extension-started compaction is steered, rejected, and lost #6379): busy during it, the retried turn accepted after. Pi's session file shows exactly the accepted messages, none of the refused ones./compactwith two messages sent during it: both were answered busy (client/turn/rejected thread_busy), then re-sent in order after compaction as their own turns and answered ("alpha-during-compact", "beta-during-compact"); the queue ended empty. This run found two bugs (risks 14 and 15), both fixed.host-daemonprocess with its own data dir, enrolled by join code; the Codex process ran under it): a turn completed; a message that raised reasoning to high while a new skill had been added restarted the session once ("Restarting the provider session to apply skills…", then "Applied skills, reasoning level; the provider session resumed with its history.") and answered; Stop during a foregroundsleep 60interrupted the turn, ended the command and released the session; the next message resumed the thread and answered.sleep 900,sleep 600) were still running; both processes kept running.sleep 600); it applies at the first turn after that."; a mid-turn message with a different model joined the turn and showed "Changed model applies from the next turn; this message joined the running turn on its current settings." (before this round it sat inside the turn's "Worked for" group). Messages refused busy during compaction show no "Steer failed" label after delivery./compactvisibility: opencode (3 commands) and omp (50) publishcompact, cursor-agent (80) does not; on opencode a turn then/compactproduced the compaction item,context.compactedand a completed turn.Live, earlier rounds: Claude model switch live and Full Access by resume with history; Full Access deferred behind a background
sleep 150and applied after; Codex mid-turn model change joined the turn and applied next turn, and lowering Full Access mid-turn ran as the next turn; Codex effort per turn; a skills change deferred behind a background terminal then applied by resume; cursor-agent/compactrefused with a reason; opencode live model switch; Pi model and thinking live in one session; Pi 0.83.0 (noagentSettled) ending turns onagent_end.Tests (targeted, via turbo): typecheck + lint for everything affected by the diff; tests for
@bb/agent-runtime(session state, reconciler, session contract, protocol 2, Pi end-to-end),@bb/host-daemon,@bb/provider-bridge-protocol(assembler, grammar, conformance for both protocols, permission contract), the four bridge plugins and echo,@bb/provider-bridge-acp,@bb/thread-view,@bb/dbquery plans, and the affected server suites. Parity recordings replay green. Full suites are left to CI.Busy retries and open-work checks
Decisions for Michael
Two behaviour changes this PR makes on purpose; each needs your call.
1. Plugin tool and provider build changes now restart the provider session (risk 4).
nohup … &(Changing a plugin's skills replaces every idle Codex thread's runtime at its next turn and kills the thread's background commands #6301); bridges report background terminals, tasks and sub-agents, so those defer the restart instead.2. Pi 0.84–0.98 extension commands that run no turn stay open (risk 12).
AGENT_END_LEAF_TIMEOUT_MS) closed the turn when Pi went quiet after an extension command that started no agent run.agentSettledends turns onagent_endas before.Risks
state_update running(settled byidle) or for a permission request, elicitation or tool call the agent raises with no prompt in flight (the runtime needs a turn to route it; it settles once the last one is answered). No timer. Verified with the fake agent only (no real agent emitted unprompted updates, see below).session-settings, which stays visible outside the completed turn's collapsed group (bridges cannot send it; the bridge warning delta keeps its four categories). Verified live: the note shows below the steer without expanding. Lowering permissions runs as the next turn./goal resumebinding (Codex thread showsidle(no spinner) while actively running commands #1646/Codex goal remains active after a turn ends but no next turn starts #6226 shape). Fixed: after setting the Goal active the bridge asks Codex which turn is active (aturn/steerwith an impossible expected id, which Codex runs in order after the goal set and refuses naming the active turn), then accepts the message into that Goal turn or settles it at once with an empty turn when Codex starts none. No timer. Verified live (below). No structured alternative exists in Codex 0.169 (checked againstcodex app-server generate-tsoutput, the rust-v0.169.0 source and the live app-server):thread/goal/setreply is sent before Codex decides whether to start a turn, has no turn field, and always saysactive;thread/goal/updatedfrom the set hasturnId: null; the first update naming the turn comes seconds later, and none comes when no turn starts;thread/status/changedandturn/startedarrive only if a turn starts, andTurnhas no goal or trigger field;thread/readsent right after the set returnedidle, turns: []in 4 of 4 runs while the goal turn started 10–60 ms later (it reads a cached status);thread/turns/listis explicitly concurrent and also cached;thread/goal/getreturns only the goal; noactiveTurn-style field exists in the 847 generated v2 types.turn/steerchecks the session's live active turn, but its refusals carry no structured data (CodexErrorInfocovers onlyactiveTurnNotSteerable), so the turn id is only in the message text. If that wording changes,/goal resumefails with a visible error and the Goal stays active; the bridge never guesses.thread/stopanswers a pendingturn/startat once, cancels, and settles the turn interrupted; tested ("answers a turn/start the agent never took as soon as the thread stops...")./compacton agents without a compact command. Fixed: offered only when the live commands listcompact. Verified live: listed by opencode and omp, not by cursor-agent.acp-defaultmodels on launch-flag agents. Fixed and tested: never passed through the launch flag; bb warns.Not verified
session/updates: OpenCode 2.0.22 resumed itself after a background job without telling the ACP client, cursor-agent never continued, omp had no credits. Covered by the fake agent only.session_busy: fake agent only.deferGoalContinuation, so it was driven through the bridge directly.🤖 Generated with Claude Code