Skip to content

Reconcile provider session tools and skills in one place, declared per bridge - #6479

Closed
ymichael wants to merge 11 commits into
mainfrom
bb/swing-2-provider-contract-thr_a5ummscns7
Closed

ymichael wants to merge 11 commits into
mainfrom
bb/swing-2-provider-contract-thr_a5ummscns7

Conversation

@ymichael

@ymichael ymichael commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

When a plugin's tools or a thread's skills changed between turns, whether a running provider session picked up the change depended on which provider it was. Each bridge had its own "did the config change, apply it or rebuild?" logic, and they drifted: a tool added after a Claude session started was never callable (#5843), ACP/omp kept the old tool schema after a plugin reload (#5359), a skill change shut down the whole environment's runtime and killed running work (#6301), and tool changes were silently dropped on Codex (#2384). Each previous fix patched one provider.

What changed

One place decides, bridges declare how. Each provider bridge now declares in its handshake how a running session takes a changed tool set or skill set (sessionConfig): live (applied in place), resume (the session is resumed with the new config before the next turn), or fixed (kept as started, with one warning in the thread). The agent runtime is the only place that compares a session's recorded config with the new one before each turn; the per-bridge diff code is deleted.

Provider Tools Skills
Claude Code live (setMcpServers, remove-then-add because the SDK ignores a same-name replace) per session, resume
Codex fixed (app-server 0.164 thread/resume has no dynamicTools) per session, live
Pi resume per session, resume
ACP resume (session/load with the new MCP servers) fixed (ACP drops pending instructions on load)

Skills are per thread. Skill roots left the process key: bridges that declare skills.perSession get each session's own roots at start/resume/fork and on a live turn, so a skill change no longer restarts the runtime and one thread's selection never reaches a sibling. Bridges that don't declare it keep main's behaviour (one process per skill catalog). Staged skill catalogs are retained while any running session uses them.

Codex app-server runs with the thread's environment (BB_THREAD_ID, project env), so MCP servers it launches see the thread identity (#4960).

Conformance table. runBridgeConformance gains session-config checks (env reaches the agent, tools at start, tools added/changed/removed, per-session skill isolation) run against all four first-party bridges through their fakes. A bridge with no declaration is checked against the documented resume default, so third-party provider plugins keep passing on SDK upgrade.

No server/daemon wire change, so no HOST_DAEMON_PROTOCOL_VERSION bump: the new bridge fields are optional and capability-gated. Plugin SDK bumped to 0.6.100.

Visible behaviour changes

  • Plugin tool and skill changes reach running threads at their next turn (the fix).
  • Codex threads and ACP skill changes show "This thread keeps the tools/skills it started with" instead of silently keeping them. A skill change on a session its provider can't restore also warns instead of resuming it.
  • A failed Claude tool update restarts the session before the turn (history kept) instead of silently missing the tools.
  • Idle provider processes for other skill catalogs are no longer shut down when another catalog's process starts (main killed a sibling catalog's freshly spawned process before its thread arrived); they are released on thread move/stop as before, including when moving a thread to a new catalog's process fails.

How you verified

  • Every new test was run against the old code first and failed, then passed.
  • Real providers (packages/agent-runtime/src/integration.session-config.test.ts, Claude Code 2.1.312, codex-cli 0.164.0): a tool added between turns is called on Claude (main: NO_SUCH_TOOL); Codex shows the warning; a Codex MCP server sees BB_THREAD_ID and the project CODEX_HOME (main: never launched); a skill added between turns is used on real Codex and Claude while a sibling thread in the same runtime does not get it. omp verified at the protocol level (session/load and session/resume mount the new MCP server); omp/opencode/Pi model turns couldn't run on this machine (no credits / 401 on main too).
  • Typecheck, lint and tests pass for @bb/agent-runtime, @bb/host-daemon, @bb/provider-bridge-protocol, the Codex, Claude Code, Pi and ACP bridges, scripted-echo and the echo example.
  • Two independent review rounds; all findings fixed with failing-first tests.

Fixes #5843
Fixes #5359
Fixes #6301
Partly addresses #2384 (fixed for Claude Code, Pi and ACP; Codex now warns because its app-server cannot take new tools on resume).

Related: #5479 (a changed tool definition now reaches a running Claude session; the stop-then-resume path still depends on the Claude CLI's transcript cache).

🤖 Generated with Claude Code

AGENT GENERATED

ymichael and others added 11 commits October 28, 2026 14:59
The server resolves a thread's plugin tools and skill catalog for every
turn, but the daemon dropped the fresh tool set for live threads,
turn/start had no tools field, and a skill catalog change shut down the
environment's whole runtime (killing Codex shell watchers).

Bridges now declare in their handshake how each session-config field is
applied (sessionConfig.dynamicTools / skills: live, resume or fixed), and
the agent runtime is the only place that diffs: it sends a changed tool
set on turn/start to live bridges, resumes the session with it on resume
bridges, and keeps the start-time tools with one warning on fixed ones.
Skill roots leave the provider process key; a catalog change is sent to
running bridges with skills/configure instead of replacing the runtime.

Claude Code applies tools live (setMcpServers), ACP and Pi resume, and
Codex is fixed because app-server thread/resume ignores dynamicTools.
The Codex app-server now runs with the session's env, so MCP servers and
hooks it launches see BB_THREAD_ID and the project's environment.

The bridge conformance kit gains a session-config table run against all
four first-party bridges through per-fake probes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Against the real CLI (2.1.312, SDK 0.3.245), setMcpServers with an
existing server name is a no-op: it reports nothing added or removed
and the session keeps the old tool list, so a thread asked to call a
newly added plugin tool answered that it had none. Removing the server
and adding the new one makes the new tools appear and get called;
tools/list_changed is ignored.

The conformance fake now behaves the same way, and it no longer reads
the context-usage probe's forked query as the thread's session. A
real-provider integration test covers tools added between turns
(Claude applies them, Codex keeps its start-time tools and warns once)
and the env Codex launches MCP servers with.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Adds a real-provider case to integration.session-config.test.ts: a skill
added to the environment between two turns must be usable on the next
turn, through skills/configure on Codex (live) and a session resume on
Claude Code (resume), without restarting the provider process.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A thread's selected skill catalog was sent to every provider process in
its environment with skills/configure, and the Codex bridge then applied
it to every session it served, so one thread's selection replaced the
skills of a sibling still running. The daemon also kept only the
previous and the requested staged catalogs, so a long-running Claude
session lost the files its injected plugin links to.

Skill roots are now per session. Bridges that declare
skills: { configure, perSession } receive each thread's skillRoots on
thread/start, thread/resume and thread/fork, and changed roots on a live
turn/start; skills/configure only sets the default for sessions built
without roots. Codex, Claude Code, Pi and ACP declare it. The runtime
keeps one process per skill catalog for bridges that do not. The daemon
stages each command's catalog for its own thread and passes it through,
and keeps every catalog a live session or an in-flight command uses.

The new conformance checks config/skills-per-session and
config/skills-change-isolated run against all four bridges. They showed
that ACP cannot change a session's skills on resume (the list rides the
first prompt, and session/load drops it), so ACP now declares
sessionConfig.skills "fixed" and the runtime warns instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The bridge recorded a thread's new dynamic tools before replacing its
MCP servers and ignored the errors map setMcpServers returns, so a
server that failed to connect was treated as applied and never retried.

A rejected update now throws, and the bridge restarts the session with
the new tools before the turn instead of keeping the failed state.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A third-party bridge that never declared sessionConfig failed the
config/session-config-declared rule as soon as its author upgraded the
SDK, although the runtime treats a missing declaration as "resume".

The rule is gone. The config/* checks run with the declared mode or the
resume default, so an undeclared bridge is held to the behaviour the
runtime will actually use. The echo example no longer declares it, and
Pi's suite runs once with its declaration stripped.

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

For bridges that do not declare skills.perSession, the runtime gave the
first catalog's process the base key, so a later thread with no skills
(or a different catalog started concurrently, before the handshake was
known) ran with that catalog's skills. A catalog change on such a bridge
also resumed the session without checking sessionRestorable, which can
lose the conversation. And a fixed skills declaration (ACP) kept the old
roots with no warning.

Process keys follow main again: a non-empty catalog gets its own key,
an empty one the base key. A bridge that declares perSession reuses the
first process that told us so for every catalog. Retirement after an
ensure now only shuts down processes from another bridge launch, not a
sibling catalog's process that has no thread yet. A skill change on a
session that is not restorable is treated as fixed, and a fixed skill
change warns once, as tool changes already do.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
resumeThreadFromConfig stopped forwarding the thread's recorded skill
roots, so a restartRecommended recovery resumed the thread, and the
siblings moved with it, with the runtime's empty default roots.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
For a bridge without per-session skills, a catalog change detaches the
thread from its old process and resumes it on the new catalog's process.
When that resume failed, the old process was never released: retirement
keeps processes of the same bridge launch and idle reaping only looks at
processes with threads, so each failed move left a live threadless
bridge until runtime shutdown.

The old process is now released on failure too. A process that still
hosts a thread, including one whose session is being constructed, is
kept as before.

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

The runtime chose a thread's process key before it knew whether the bridge
takes skills per session, then aliased later keys after the first spawn. Two
first starts with different catalogs could each spawn a process, sessionless
calls looked up a different key than they started, archive respawned a
catalog process without its skills, and a bridge that cannot configure
skills still resumed or warned on every skill change. ensureProviderProcess
now serializes a bridge's first start, records its skill scope, and returns
the process it started; skill changes are ignored when the bridge does not
configure skills.

The daemon kept every thread's staged catalog on the environment entry
forever and swept the staging directory on every turn. Staged catalogs now
live on the runtime manager from staging until the thread's last in-flight
command finishes, and the sweep runs only when a command stages a catalog no
session or command already uses. Catalog hashes come from a root's first path
segment under the staging root.

Restores the optional disallowedTools field on session construction params,
which docs/api_to_audit.md keeps until the next major.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael force-pushed the bb/swing-2-provider-contract-thr_a5ummscns7 branch from b2286cd to f7b4ba0 Compare October 28, 2026 22:11
ymichael pushed a commit that referenced this pull request Nov 5, 2026
…7117)

## Human comments

## What was wrong

When two threads of one provider whose injected skill catalogs differ
start or resume their sessions at the same time in one environment
runtime, each one's `ensureProvider` retires the other's freshly spawned
bridge, and both commands fail. Skill roots are part of the process key
(`packages/agent-runtime/src/runtime.ts:365-380`), so the two threads
get two bridge processes. `ensureProvider` ends with
`retireStaleBridgeProcesses`
(`packages/agent-runtime/src/runtime-provider-process.ts:254-273`),
which shuts down every other process of the same provider with no
registered thread. A thread is registered only after `ensureProvider`
returns (`packages/agent-runtime/src/runtime.ts:1549-1574`), and that
return waits for the sweep's own shutdowns, so each sweep sees the
other's new bridge with zero threads. The victim either dies from
SIGTERM while still initializing (`exited unexpectedly (signal
SIGTERM)`) or exits gracefully once initialized (`exited unexpectedly
(code 0)`, or `has exited (code 0)` when the lookup lands between exit
and close); the other command then reports `is not running`.

In practice this hits Claude Code threads with Composer Predictions
installed: its hidden helper gets `skills: []`, every other thread gets
its skill, and the helper starts about a second after a watched thread
goes idle. A message sent to that thread, or to another idle thread in
the same environment, about 0.5 to 4 s after the idle is rejected. On
one server this lost 7 sends on long-lived threads in four days, and 6
of 10 sends in a controlled repro.

The sweep exists to retire bridges superseded by a plugin update (a new
artifact hash). Bridges for another skill catalog of the same bridge
launch are not superseded; they are released when their last thread
ends. #6479 makes the same change to this filter as part of its larger
session-config rework ("main killed a sibling catalog's freshly spawned
process before its thread arrived"). This PR takes only that filter, so
the crash can be fixed while #6479 is open; it applies to `main` on its
own and the hunk matches #6479's, so either can rebase over the other.

## What changed

- `packages/agent-runtime/src/runtime-provider-process.ts`: each process
records its bridge launch key (`bridgeLaunchProcessKey`: artifact
digest, capabilities, bridge options) when it is spawned.
`retireStaleBridgeProcesses` retires only a threadless process of the
same provider whose bridge launch key differs from the one being
ensured. Processes of the same launch with another skill catalog are
left to the existing release-after-last-thread path.
- `packages/agent-runtime/src/runtime.process-lifecycle.test.ts`:
- "retires a threadless bridge process superseded by a new artifact
hash" now ensures the fresh key with a launch whose digest differs
(`SUPERSEDING_BRIDGE_LAUNCH`, as in #6479). Before, it only changed the
process key string while reusing the same launch, which no longer counts
as superseded.
- New "starts threads of two skill catalogs at once without retiring
either bridge": two concurrent `startThread` calls on one runtime with
different `skillRoots`; both must be hosted afterwards.
- No daemon wire change, no `HOST_DAEMON_PROTOCOL_VERSION` change.

## How you verified

- New test without the production change (`main`'s
`runtime-provider-process.ts`): fails with `ProviderProcessExitedError:
Provider "scripted" exited unexpectedly (signal SIGTERM)`; the other 35
tests in the file pass. With the change: 36/36.
- `pnpm exec turbo run test --filter=@bb/agent-runtime --force`: 23
files, 307 tests passed.
- `pnpm exec turbo run typecheck lint --filter=@bb/agent-runtime
--filter=@bb/host-daemon --force`: 7/7 tasks passed.
- `oxfmt --check` on the test file reports the existing `oom_score_adj`
test from #7039, unchanged on `main`; the new code is formatter output
and that hunk is left alone.
- Standalone reproduction at the same code path, ten fresh runtimes per
run, on `main` at `fa30b0a7d`: 0/10 without the change (every run lost
one or both threads with `exited unexpectedly (code 0)`, `(signal
SIGTERM)` or `is not running`), 10/10 with it.

  ```sh
  pnpm exec turbo run generate:test-bridges --filter=@bb/agent-runtime
  cd packages/agent-runtime
../../node_modules/.bin/tsx /tmp/sibling-start-race.mts "$PWD/../.." 10
  ```

  <details><summary>/tmp/sibling-start-race.mts</summary>

  ```ts
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
  import { tmpdir } from "node:os";
  import { join } from "node:path";

  const root = process.argv[2]!;
  const trials = Number(process.argv[3] ?? 10);
const { createAgentRuntime } = await
import(`${root}/packages/agent-runtime/src/runtime.ts`);
const harness = await
import(`${root}/packages/agent-runtime/src/test/runtime-test-harness.ts`);

  function stage(dir: string, name: string) {
    const path = join(dir, name);
    mkdirSync(join(path, name), { recursive: true });
writeFileSync(join(path, name, "SKILL.md"), `---\nname:
${name}\n---\n`);
return [{ id: `skills:${name}`, path, skills: [{ name, description: name
}] }];
  }

  let passed = 0;
  for (let trial = 1; trial <= trials; trial++) {
    const dir = mkdtempSync(join(tmpdir(), "sibling-start-race-"));
    const runtime = createAgentRuntime({
      workspacePath: dir,
      onEvent: () => {},
      onToolCall: async () => ({ contentItems: [], success: true }),
    });
    const bridgeLaunch = harness.createScriptedEchoLaunch();
    const start = (threadId: string, skillRoots: unknown) =>
      runtime.startThread({
        bridgeLaunch,
        skillRoots,
        environmentId: "env-1",
        threadId,
        projectId: "p1",
        providerId: "scripted",
        options: harness.fullRuntimeOptions,
      });
    const results = await Promise.allSettled([
      start("coordinator", stage(dir, "with-predictions-skill")),
      start("prediction-helper", stage(dir, "no-skills")),
    ]);
const errors = results.flatMap((r) => (r.status === "rejected" ?
[String((r.reason as Error).message ?? r.reason).split("\n")[0]] : []));
const hosted = ["coordinator", "prediction-helper"].filter((t) =>
runtime.hasThread(t));
    const ok = errors.length === 0 && hosted.length === 2;
    if (ok) passed++;
console.log(`trial ${trial}: ${ok ? "PASS" : "FAIL"}
hosted=${hosted.join(",") || "none"}${errors.length ? `
errors=${JSON.stringify(errors)}` : ""}`);
    await runtime.shutdown();
    rmSync(dir, { recursive: true, force: true });
  }
  console.log(`${passed}/${trials} passed`);
  process.exit(0);
  ```

  </details>

- Live, on a bb-app 0.48.2 nightly (upstream `298e5d0`): the daemon
bundle built from `298e5d0` without the change is byte-identical to the
shipped `host-daemon/dist/daemon-bundle.mjs`; with the change it differs
only by this filter. The live reproduction (send to a watched Claude
Code thread the moment it goes idle, Composer Predictions installed)
failed 6 of 10 sends before. The patched daemon has not been deployed
there yet.

Fixes #7116

> AGENT GENERATED

Co-authored-by: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot closed this Nov 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This is an automated message. We have closed this pull request because it has been open for more than two weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment