Skip to content

Prune low-value @bb/agent-runtime tests and require providerThreadId on resume - #6936

Merged
ymichael merged 4 commits into
mainfrom
bb/test-audit-packages-agent-runtime-thr_5nrkrkx5b8
Nov 3, 2026
Merged

ymichael merged 4 commits into
mainfrom
bb/test-audit-packages-agent-runtime-thr_5nrkrkx5b8

Conversation

@ymichael

@ymichael ymichael commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

@bb/agent-runtime carried about 1,300 lines of tests that couldn't catch a regression:

  • Duplicates of a stronger test. The same scenario was replayed in a second file, or a unit case was already covered at the runtime boundary.
  • Assertions that couldn't fail:
    • a key-order check that compared identical objects;
    • a background-work filter test using an item that is never counted as open;
    • "no input-accepted event" checks that only exercised the fake bridge.
  • Inventories that copied constants and checked them against themselves.
  • Tests whose names promised more than they checked. In particular:
    • Commit 94988c3 changed the three provider exit-race regressions from Fix provider process exit lifecycle races #1402 to a fixture that never answers initialize. Since then they run against an empty process map, so all three pass with each Fix provider process exit lifecycle races #1402 fix reverted.
    • Three live permission tests passed without reaching the path they name. The Claude deny-escalation test passes even if the model never runs Bash. The two "automatic review" tests write inside the workspace, where no review happens.
  • A test-only production path. ResumeThreadArgs.providerThreadId was optional only so tests could register a thread with no provider identity. Every production caller already passes it.

What changed

All changes are in packages/agent-runtime: tests +328 / −1,487, production +12 / −17. No wire, protocol, CLI or docs changes, so HOST_DAEMON_PROTOCOL_VERSION is unchanged.

Production

  • ResumeThreadArgs.providerThreadId is required.
  • resumeThread drops the ?? requireProviderThreadId(threadId) fallback and the undefined branches around it.
  • @bb/host-daemon (the only production caller) already checks the id before calling.

Deleted or merged tests, each one's unique assertions moved into its keeper first:

  • Lifecycle and command-contract duplicates:
    • changed settings on later turns (merged into the next-turn settings test);
    • stop, retire and resume (merged into the stop/resume contract test);
    • "does not start a turn until input is sent";
    • the launch-spec process-cache test (the process-key unit test and the declaration-change lifecycle test cover it).
  • Process lifecycle: the non-Codex reap duplicate. The cold-resume reap test still covers non-Codex providers.
  • Multi-thread: "resumes across runtime instances", which the fake provider makes the same as a plain resume.
  • Interactive requests:
    • The provider-filtered approval case is already cell auto/deny × provider of the permission matrix.
    • Three undecodable-request tests are merged into one it.each that pins the real -32601 Unsupported provider request reply.
  • Unit tests:
    • four bridge-adapter tests covered at the runtime boundary;
    • a thread-identity stamping case;
    • a waiter-timeout case;
    • a bridge-bundle argv case;
    • the permission-matrix inventory and predicate tests. Compile-time SameUnion checks against the domain types already fail typecheck when a new mode, escalation or enforcer appears.
  • Live CLI suites:
    • "starts a thread and runs a single turn" (merged into the follow-up turn test);
    • "recovers from a bad request", which is rejected before any provider I/O;
    • "uses multiple providers in a single runtime";
    • two Codex resume tests that are strict subsets of "preserves memory and dynamic tools across runtime restart";
    • the Pi permission-modes constant check.
  • Removed fixtures and setups: test/bridges/unsolicited-turn-bridge.ts, and request-record setups that were never written to.

Repaired tests

  • Process key: the key-order case now uses different insertion orders.
  • Background work: the filter test uses a pending commandExecution item.
  • Stale steer: adds a "no-active-turn code alone" case for a branch no test covered before.
  • Skill configure: the failure test now checks that the next start relaunches the provider on the same runtime.
  • Guard tests: the missing-provider-thread-id guards for runTurn and renameThread now run during a real in-flight startThread.
  • Exit races: the three Fix provider process exit lifecycle races #1402 tests use a fixture that answers initialize, starts a grandchild holding stderr open, then exits. Each test acts between the child's exit and close events:
    • shutdown of an exited provider;
    • replacement waiting for exitFinalized;
    • a single replacement for concurrent callers.
  • Live permission tests:
    • The Claude deny-escalation test asserts a completed Bash item for the target that failed or was denied.
    • The Codex and Claude automatic-review tests write outside the workspace, so the reviewer must approve an escalated command. I confirmed in the Codex rollout that the call carried require_escalated and went through auto_review.
  • Renames: three tests whose names promised more than they assert.

How you verified

Turbo runs on the rebased branch (base 7130d9692b), with --force:

  • pnpm exec turbo run lint typecheck --filter=@bb/agent-runtime --filter=@bb/host-daemon --filter=@bb/server: green.
  • pnpm exec turbo run test --filter=@bb/agent-runtime --force: 297/297. The baseline was 314/314; the difference is the deleted tests.
  • pnpm exec turbo run test:integration --filter=@bb/agent-runtime --force: 54/55. The baseline was 64/65.
    • The one failure is the existing Codex env-rotation failure described below.
    • The rewritten Codex and Claude permission tests passed live in this run and in a separate targeted run.
  • runtime.process-lifecycle.test.ts: 5 consecutive uncached runs, all 31/31.

Mutation checks. Each bug is introduced into production code and the before/after tests are run. All mutations were reverted byte for byte.

  • An independent agent ran 20 mutations against 51d8ddc75a and the first commit, in separate worktrees. Every bug caught by a removed test is still caught by a kept test.
  • Rows 4–6 and 12 show the repaired assertions failing where the old ones passed.
  • That review found the in-flight-start guard was still reachable, so it is covered again. Replacing the runTurn guard with getProviderThreadId(...) ?? "" fails the restored test.
  • New exit-race tests, against RuntimeProviderProcessManager:
Mutation Old test New test
ensureProvider doesn't await exitFinalized or re-check pass "waits for an exited provider…" and "starts a single replacement…" fail
only the post-finalize re-check removed pass "starts a single replacement…" fails (4 starts)
shutdown() waits for an exit event that already fired (the pre-#1402 bug) pass "does not wait for an already-exited provider…" fails (5.1 s)

Existing failure: integration.env-isolation.test.ts "codex provider applies rotated and removed contributions on the next turn". It is not caused by this change.

  • It fails the same way on a clean origin/main worktree (cbde50f2d9) and on the pre-change baseline 51d8ddc75a: the turn with the rotated value reads FAIL. Reproduced on every run with codex-cli 0.166.0.
  • Cause:
    • Codex receives contributed env only as shell_environment_policy.set.* config when the session is built.
    • The bridge's turn/start carries no env.
    • The bridge rebuilds a session only when constructionSignature (plugins/provider-codex/src/bridge/bridge.ts) changes, and that signature takes only CODEX_HOME and the pool route from envVars. So a rotated or removed contribution never reaches the live session.
  • Control: adding envVars to constructionSignature on the same main worktree makes the test pass. That edit was reverted and is not part of this PR.
  • CI only runs one test:integration case, so nothing in CI catches this. It should be fixed in its own PR.

🤖 Generated with Claude Code

AGENT GENERATED

ymichael and others added 4 commits November 3, 2026 12:51
…on resume

Delete duplicate, vacuous, and inventory tests across the runtime unit and
live-CLI suites, merge their unique assertions into the keeper tests, and
repair assertions that could not fail. ResumeThreadArgs.providerThreadId is
now required: every production caller already supplies it, and the fallback
only existed for the tests that relied on it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The three provider exit-race tests now answer initialize and then exit while
a grandchild holds stderr open, so they act between the child's exit and
close events; each fails when its fix in RuntimeProviderProcessManager is
reverted. The Claude deny-escalation test asserts the blocked Bash attempt,
and both automatic-review tests write outside the workspace so the reviewer
actually runs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
On Windows the stderr holder can take longer to start than the one-second
close grace, so the provider's exit was already finalized before the test
observed the window. The provider now exits when the test writes a signal
file, after the holder is running and the exit listener is attached.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Windows locks a directory that a live process uses as its cwd, so cleanup
failed with EBUSY while the holder was still being torn down.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael merged commit e837c18 into main Nov 3, 2026
32 checks passed
@ymichael
ymichael deleted the bb/test-audit-packages-agent-runtime-thr_5nrkrkx5b8 branch November 3, 2026 21:18
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