# Agent-hub 0.12.6 verification

Implementation and candidate verification for issue #115 (follow-ups of the 0.12.5 review), performed on 2026-10-03. Native CLIs: Codex 0.160.0, Claude Code 2.1.288, Kimi Code 2.1.1. Production application is verified separately after publication.

## The macOS CI hang of 0.12.5

On 0.12.5's CI, `test/daemon.test.ts` once hung until the job limit; no test reached its own timeout, so the event loop was blocked. It reproduced locally twice under heavy machine load (load average about 12), once on the 0.12.5 checkout and once on this branch. Each time `bun test` sat at 100% CPU for minutes, with nothing but the banner in its output in one case.

The stacks were sampled with macOS `sample` and symbolized with Bun's own profile build of 1.3.14, whose UUID matches the installed binary (`C7E7A979-F99B-3466-9AD6-E56A63373A35`). The hung main thread shows this chain:

1. An async continuation, resumed from a timer, calls `Bun.spawnSync` (`BunObject_callback_spawnSync`, `spawnMaybeSync`).
2. Inside spawnSync's own event loop, the test runner's timeout callback fires (`BunTest.bunTestTimeoutCallback`). Through `BunTest.run` and `runTestCallback`, it runs the next test's JavaScript.
3. That JavaScript calls `Bun.spawnSync` again, and the inner call spins in `SpawnSyncEventLoop.tickWithTimeout` for good.

So a test timeout that fires while a `Bun.spawnSync` runs can hang the whole run. Minimal attempts to reproduce it outside the suite did not hang: when a test times out, Bun kills the child that test's own spawnSync started. The precise trigger therefore also needs a spawnSync that Bun does not attribute to the timed-out test.

Mitigation, since the fix belongs in Bun:

- `scripts/check.sh` runs `bun test --timeout 20000`, so a timeout, which is the trigger, is much rarer under load.
- It runs the suite under `scripts/hang-watch.sh`. If the run is still going after 600 s, the watchdog prints a stack sample (macOS) or the thread states (Linux) and stops it, so a hang fails fast with evidence.
- The process-heavy stop tests carry timeouts of their own.
- Upgrading Bun (1.4.2 is current) is left for a separate change.

The permission-test flake of 0.12.5 had a different cause: the test rig's 200 ms permission timeout is shorter than a loaded runner takes to connect a peer and make two tool calls. That test now has its own 30 s window.

## Automated gate

`scripts/check.sh` at the head of the pull request, after the eleventh review round and the merge of main (#118): 754 tests passed, 0 failed, 3,807 expectations across 68 files in 135 s (macOS CI counts one expectation fewer) (the 68th file is #118's); `check: OK` (with the fourth round's fixes: 739 passed, 3,723 expectations; at `b03b035`: 739 passed, 3,710 expectations; at `fdc884e`: 738; at `4b98d2d`: 737 passed in 116 s at a load average of about 5). Mutation checks (each test fails with its fix removed; the last four are 0.12.5 tests checked again against this release's stop change): split availability under the 0.12.5 rule, the ACP launcher test without `detached`, pipes in the non-group stop, the fallback's newcomer freeze, the kill-only-stopped rule, the reused-pid stop, and the grace-period SIGTERM to own-group descendants.

CI on `4b98d2d`: macOS passed; Ubuntu failed the new ACP launcher test, because dash points a background job's stdin at `/dev/null` before the explicit `0<&0`, so the fake agent never got its handshake. The test now passes stdin through fd 3 (`bef35ab`); CI passed on both platforms there, at `fdc884e`, `5bfaf53`, `70b1daf` and `b03b035`.

Cost of the group stops: each ACP or Pi stop now reads the process table twice (a `ps` of about 1,300 processes takes about 60 ms here). `test/acp.test.ts` and `test/pi-daemon.test.ts` together take 8.1 s against 3.1 s on 0.12.5. The group stop now finishes as soon as the leader has exited and a read shows nothing left.

## Live checks

- Upgrade, on `4b98d2d`: `scripts/smoke-recovery-09-10.ts` recovered the published 0.12.5 package (protocol 13, integrity from the registry) into the candidate (protocol 13): operation `31f206a6-6dbc-4f42-adfb-40eac841417a`, queue and task identity and state digest preserved.
- Kimi through ACP, on `4b98d2d`, real `kimi acp` 2.1.1, in a disposable project with its own `AGENTHUB_HOME`: started by the hub as the daemon's child, it led its own process group; `ahub kill` said "hub stopped", nothing of that group was left, and the daemon was gone.
- Interrupted benchmark arms with real agents, on `4b98d2d` (A, B) and `bef35ab` (C, E, V, S2; it differs only in the ACP test):

| Run | Arm | Stopped at | Signal | Cleanup | Left running | Restoration |
|---|---|---|---|---|---|---|
| A | solo Codex | 31.1 s into the work | SIGTERM to the runner | `clean` (298 ms) | nothing | inputs, sibling locks |
| B | advisory | 40.3 s into the work | SIGINT to the group | `clean` (463 ms) | nothing | inputs, locks, trust |
| C1 | solo Claude | completed (57.7 s); turn end after 0.75 s, tree unchanged | none | `clean` (340 ms) | nothing | inputs, locks, trust |
| C2 | advisory | setup | SIGTERM to the runner | `clean` (424 ms) | nothing | inputs, locks, trust |
| E | turn-free | 31.2 s into the work, and again during teardown | SIGINT to the group, twice | `clean` (422 ms) | nothing | inputs, locks, trust |
| V | solo Codex with a visitor in the fixture | 31.0 s into the work | SIGTERM to the runner | `incomplete_or_unknown`, the visitor left alone and recorded as `program: sleep` | the visitor | withheld; `restore.ts` refused while it ran, restored once it left |
| S2 | advisory | native readiness | SIGINT to the group | `clean` (452 ms) | nothing | inputs, locks, trust |

Runs A, V and S2 were repeated on `fdc884e` with the same outcomes. Every one of these runs registered its fixtures with Orca, since the runner still added them then. The user has since directed that no fixture is added to Orca without an explicit registration (#117), and the registrations these runs left are removed under #117. Since `70b1daf` the runner only looks registrations up, and since `b03b035` it refuses an unregistered selection up front. A live check of the latter registered nothing. A run prepared afresh (`/private/tmp/ahub-0126-refusal`, 40 fixtures, none registered) was started with the runner of `b03b035`. It refused the whole run before anything was locked or recorded, naming every unregistered fixture. That lookup was later replaced by #118's read-only helper (`scripts/benchmarks/orca-workspace.ts`, merged into this branch from main), which refuses at the first fixture missing and checks each arm's identity against the preflight; #118 records its own checks, and this refusal check was not repeated on it. Orca's repository list was the same before and after (15 repositories), the upstream checkout kept its mode, and no attempt record was written. Before the release, no arm had run on the lookup-only runner, which needs fixtures registered explicitly first: the live arms above ran on the runner that still added them. Every record carries `platform: darwin`. The Codex skills condition was 177 user and 5 system skills in every arm above with Codex. Arms on the released runner follow.

After the release, with the user's authorization for the Orca registrations, three of these arms ran on the released runner (`44e04e5`, Bun 1.3.14, which 0.12.6's CI used). Each run's four case-0 fixtures were registered by hand before the run and removed after it, and Orca's repository list ended as it began (16 repositories, the same ids; the one more than at the refusal check is an unrelated project added meanwhile). Every record carries `platform: darwin`; the Codex skills condition was 177 user and 4 system skills in each.

| Run | Arm | Stopped | Cleanup | Left running | Restoration |
|---|---|---|---|---|---|
| A | solo Codex | SIGTERM to the runner, 30.8 s into the work | `clean` (313 ms) | nothing | inputs, sibling locks |
| B | advisory | SIGINT to the group, 40.7 s into the work | `clean` (447 ms) | nothing | inputs, locks, trust |
| V | solo Codex with a visitor in the fixture | SIGTERM to the runner, 30.6 s into the work | `incomplete_or_unknown`, the visitor left alone and recorded as `program: sleep` | the visitor | withheld; `restore.ts` refused while it ran, restored once it left |

## Review

Independent read-only reviews (Claude Code OCR delegation, with the OCR rule groups, `REVIEW.md`, the `AGENTS.md` invariants and issue #115), each on the head of the time. The first round, on `4b98d2d`, found one Important gap: this record and the spec amendment for the Bun cause were missing. The spec was amended (#115, Decisions of 2026-10-03), and this record was written. Its Minor findings were fixed:

- Hand-overs in the split prediction are keyed by owner generation: a task handed back to a peer that had it is a new hand-over.
- A failed Pi start reports its own error, and Pi's stop finishes its teardown when the group stop fails.
- Pi has a launcher test, as ACP does.
- The spawn-heavy stop tests' own timeouts are at least the suite's 20 s.
- The runner removes the trust write's temp file on every path, the recovery's included.
- `hang-watch.sh` signals only the process it began watching (pid and start time), escalates to SIGKILL, and is stopped once the tests end.
- Run records and the restoration ledger are written atomically.
- `programOf` looks at a bounded number of argv words.
- Several doc and comment fixes.

Deferred: the Codex start-failure test does not exercise a stop that fails, since no fake can make the group stop fail there without mocking. The second round, on `5bfaf53`, found no Critical or Important defect. Its Minor findings were fixed:

- The program name comes from `ps`'s name for the executable, not from stats that can hang on a dead mount.
- A failed restore keeps the trust write `pending` for the recovery.
- The trust temp files are named in one place, and removed when a write or a restore fails.
- The recovery's pending-trust path is tested.
- The Bun mechanism is worded as what the stacks show, not as a general rule.

The runtime review of that round also found Minor gaps. Fixed: a claimed task now counts as handed over for the split prediction; Claude's version is cached when the transcript has none yet; the watchdog test waits for its trap and always cleans up; `sample` writes its report to a temp file it removes. Deferred and listed in a comment on the pull request: a task steered into a turn about other work counts as taken (shadow only); the start-failure tests do not exercise a failing stop. The same commit makes the runner lookup-only in Orca (#117).

The third round, on `70b1daf`, found two Important defects; both are fixed.

- **Arguments recorded as a program name.** The program name read from `ps -o comm=` is, on macOS, a process's own argv[0], so a process that sets its title (Node's `process.title`, perl's `$0`) put its arguments into the record. It now reads `ps -o ucomm=`, the executable's name as the kernel recorded it, only while the pid has the start time recorded, and records nothing when it cannot be read. A test with a self-titled perl fails with `comm`.
- **A steered task counted as taken.** A task steered into a busy Codex turn counted as taken by it. Only a task that starts the owner's turn counts now (idle with nothing queued when it is sent, or claimed), and a test with a steering peer covers it.

Its Minor findings were fixed:

- The runner, whose own trust write threw, no longer touches the trust file.
- An unregistered fixture refuses the run up front instead of failing every arm, and the documented procedure has the registration step.
- The operator note on refused Kimi and Pi restarts was added.
- Several wording fixes.

Deferred, as before: the start-failure tests do not exercise a failing stop.

The fourth round, on `b03b035`, found two Important defects in the split prediction; both are fixed.

- **A hand-over outlived its turn.** A task that started its owner's turn stayed marked as taken after that turn ended, so a later turn about something else counted as taking it. The mark now lasts as long as that turn: the peer leaving busy drops it. It is set only once the task envelope was delivered at once (idle before, busy after, not queued), so a held delivery is not taken; a claim counts only in a turn the hub sees.
- **The queue was checked again at prediction time.** A peer still in the turn its task started, with a status message queued behind it, read as not available, and so did a claimant with one queued. Only the turn decides now.

Tests cover a turn that ended, a message queued behind the turn, a claim with one queued, a held delivery and the daemon's journal, and each fails with its part of the fix removed. Its Minor findings were fixed:

- The ledger counts a record caught in the middle of the recovery's move once, as withheld (also raised by the Codex review on the pull request), and refuses a run whose `runs/` is still locked instead of reporting its attempts missing.
- The Orca refusal names why each lookup failed, and each arm looks its fixture up before touching it.
- The recovery removes the temp file a runner left when it died in its own trust restore, and a temp file it cannot remove keeps the recovery open instead of aborting it.
- The tail permission test has the 30 s permission window too.
- The docs name the hub's project registration where they meant it, and the availability rule names the claim and the turn.
- Several nits: a nested ternary, the version cache stamped only after a read that worked, a failed `sample` said so.

Deferred, as before: the start-failure tests do not exercise a failing stop (a fake cannot end the launcher between the health check and the failure that follows it).

The fifth round, on `56585ea`, found no Critical or Important defect in the change. It found that main had moved: #118 (#117's Orca change) had been merged, so the pull request conflicted and no CI had run on its head. Main was merged in. The Orca lookup is #118's: its helper, its preflight and its per-arm identity check replace this branch's own preflight and lookup move. This branch keeps the guard that asks for a hub shutdown only once an arm got past its locks, which the merged code needs (its `orcaProject` is now always set). The docs keep #118's text on explicit authorization for Orca registrations. Its Minor findings were fixed:

- A pause no longer drops a hand-over: the turn's end is read from the adapter's own state.
- A temp file the recovery cannot remove keeps the trust entry unrestored, so the next recovery tries again; it had been marked restored and never retried. A test covers it.
- The ledger no longer refuses a run whose `runs/` is locked: the attempts it cannot read there are listed as `unreadable`, never as missing, and the withheld ones are rows as before.
- #115's Design and #109's Decisions were amended to the turn rule; test assertions that could pass without a routing record now require one.

CI on the merge (`46e22e0`): macOS passed; Ubuntu failed two of #118's tests. They run the runner's entrypoint, which on Linux stops at this release's macOS-only refusal before the Orca checks. The helper-pin test now expects that refusal off macOS, with the same checks that nothing was written or run, and the preflight test runs on macOS only, where the runner does. CI passed on both platforms at `e2d66ea`.

The sixth round, on `46e22e0`, found the Ubuntu failure above (fixed in `e2d66ea`) and checked the merge: #118's helper, its pin, its preflight before any change and its per-arm identity check are intact, and nothing of either side was lost or duplicated. Its Minor findings were fixed:

- The runner's own pending trust write whose temp file cannot be removed keeps the trust entry open for the recovery, as the recovery already did for its own; it had been marked settled.
- The ledger's per-arm summary lists the attempts a locked `runs/` hides (`unreadable`), so the summary a record quotes accounts for them.
- An interrupt right after the locks no longer asks a hub that never started to stop.
- A claim reads the claimant's own adapter state, as the turn's end does.

CI passed on both platforms at `e9137dd` and `5440086`. The seventh round, on `e9137dd`, found no Critical or Important defect. Its Minor findings were fixed:

- When the runner's own temp file could not be removed, the recovery treated the write as possibly landed and could take back an entry someone else had set meanwhile. The runner now records the write as `not_written`, and the recovery removes the copy without touching any entry. A test with someone else's entry covers the recovery's side and fails without its fix.
- An arm with no record at all appears in the ledger's summary with what it owes (`missing`, `unreadable`).

The claim's change was left untested in that round, on the premise that only the cohort record at the claim reads its mark; `route explain` reads it too (round 8).

The eighth round, on `5440086`, found no Critical or Important defect. It found the same class a fourth time: with an incomplete cleanup, a trust write the runner knew never landed was left `pending`, so the recovery could take back an entry someone else set meanwhile. Following `REVIEW.md`, the rule went into `AGENTS.md`. A write still `pending` in the runner's own process is `not_written` on every path, and neither the runner nor the recovery then touches an entry. Its other Minor findings were fixed:

- The recovery re-settled a `changed_concurrently` entry (the user's) when the run was unrestored for another reason, and could take it back. It now leaves it. This was older than this release (0.12.5). A test covers it and fails without the fix.
- The summary seeds an arm with no record into its full shape, so its common medians count it.
- A claim made while paused, then resumed in the same turn, is read as taken by `route explain`. A test covers it and fails with the bus's `paused` state.
- `restoration.json` names a temp file left behind, rather than a trust entry, when that is what is left; the summary's units and the docs describe `unreadable`.

CI passed on both platforms at `e5940e0`. The ninth round, on `e5940e0`, enumerated every state the trust entry can be left in by the runner, a runner that dies at any point, and the recovery. It found no Critical or Important defect, and every path the runner settles itself correct. Its Minor findings were fixed:

- A runner that died between its trust write and the rename leaves `pending`, and the recovery took back any entry set meanwhile. It now takes back only an entry exactly as the runner would have written it, and none while the runner's temp file is still there (the rename never happened). This was older than this release. A test covers the three cases and fails without either check.
- The recovery's own restore named its temp file by its own pid, which no later recovery looks for. It now uses the runner's.
- The runner's settlement is a function (`settleTrust`), tested as a table of stage, containment and temp removal; the `AGENTS.md` rule points to it. The table test fails with the earlier order (containment before `pending`).
- The common medians' change has a test: an arm with no record leaves no common pair. It fails without the change.

CI passed on both platforms at `bbf59d9`. The tenth round, on `bbf59d9`, found no Critical or Important defect. It compared `settleTrust` with the inline code it replaced, field by field, and found them equal. It walked every point at which a runner can die, every stage on disk, and the 0.12.3 to 0.12.5 ledgers, and found no path where the recovery changes an entry the runner never wrote or the user changed. Fixed:

- A test now checks that the recovery names its restore's temp file by the runner's pid. It fails when the recovery's own pid is used.
- The `TrustLease` comment now says that every ledger since 0.12.3 records `written`.
- The `AGENTS.md` rule no longer gives a count of rounds.

Deferred, older than this release and listed in the pull request:

- A recovery of a 0.12.3 or 0.12.4 ledger (no runner identity) killed mid restore leaves a temp file that no later recovery looks for.
- A 0.12.5 runner whose rename threw left its temp file behind a `restored: true` run.
- A run directory whose earlier invocation stopped before any arm keeps its `restoration.json` (`restored: true`). A recovery after a crashed re-run there reports the run restored and exits 0 while the re-run's locks and trust entry stay; it changes no entry.

CI passed on both platforms at `e0b71a0`. The eleventh round, on `e0b71a0`, found no Critical or Important defect. The new test now runs the recovery as this process (`self` is its pid), so a temp file named by either the recovery's pid or `self` fails it; the record's third deferred item says what the recovery reports.

Deferred: the start-failure tests, as before.

## Known limits

- The Bun 1.3.14 hang is mitigated, not fixed. A test that times out during a spawnSync can still hang a run, which the watchdog then stops after 600 s.
- Group stops cost about two process-table reads per stop.
- The limits recorded for 0.12.5 stand.
