Skip to content

fix(runtime): resolve shutdown races blocking nightly releases - #262

Merged
nixuuu merged 4 commits into
devfrom
test/flaky-nightly
Nov 6, 2026
Merged

nixuuu merged 4 commits into
devfrom
test/flaky-nightly

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 6, 2026

Copy link
Copy Markdown
Member

Nightly releases were cancelled by assertions that observed an earlier asynchronous event, plus three product lifecycle bugs. This change waits for the state each assertion actually needs and fixes the product bugs in separate commits. It adds no test retries, skips, blanket timeout increases or workflow cancellation changes.

Product fixes

  • Bot shutdown releases the turn lease without replying “interrupted” to a worker's pending tool call. Old handlers reject instead of continuing to poll; the worker resends the same call after reconnect, preserving the pending approval and running inference once. The restart test now asserts these shutdown outcomes explicitly.
  • LAN discovery shutdown drains outstanding certificate checks and route writes. A handshake that finishes after discovery is disabled or shutdown starts cannot add a route. The silence test drains old discovery before deleting routes and observes actual query cycles instead of sleeping.
  • CLI discovery discards results captured before an overlapping install completed. A successful install can no longer be published alongside the previous executable/version. A controlled overlap reproduces the original stale-version report deterministically using the real discovery and installer code.

Reproduction and results

Rates below are failed executions / attempted executions, not historical workflow frequency. Gateway suites ran one file at a time, pinned to one CPU (taskset -c 10); process tests used --rerun-each 100. Skill-source checks also ran with two bounded CPU burners on that CPU. Temp data stayed on disk outside the repository. All repetitions execute the assertions normally; no retry wrapper is committed.

Test / suite Cause and fix Before After
Governor: timeout kills an owned descendant /proc exists/read races with reaping (including ESRCH); parent completion also precedes descendant signal delivery. Read once, catch only process disappearance, wait until the owned process cannot execute, retain the no-delayed-write assertion. 9/100 0/100
Bots harness: restart preserves pending approval Product shutdown returned an interruption or kept polling a released lease. Reject the old handler and preserve the unanswered call for replay. 4/30 0/30
Composer: timeout and Stop kill the process group Stop competed with a global 1.5 s fixture timeout; a local PID marker can precede gateway turnStarted; file creation can precede PID contents; immediate PID existence counts zombies as running. Give only the timeout case its short deadline, await gateway running state for Stop, publish PID atomically and await process termination. 1/1 full suite 0/10 full suites
Composer: Stop during shell steer Same PID publication and termination races. Keep interrupted-result and failed-delivery assertions. Empty PID reproduced during verification 0/10 full suites
Linked-home unreachable/read-only Re-enabling sharing reconnects before worker-record bootstrap arrives. Await the expected replicated settings before disconnecting. 1/10 0/10
Remote thread creation/live stream UI creation response precedes worker command delivery. Await delivery and explicitly verify the echo; settle its turn before enabling the next test's held-turn fixture. 0/10 locally; 2 historical runs 0/10
Remote attached file Earlier shared-turn state can cascade into attachment waits. Finish held turns and restore fixture state in finally; preserve byte/content checks. No independent message-loss bug reproduced. 0/10 locally; 2 historical runs 0/10
Remote inline file / older peer Same shared-turn sequencing; explicitly assert the received input exists before inspecting it. Preserve placement and old-peer fallback assertions. 0/10 locally; 2 historical runs 0/10
Relay: reciprocal sharing Route withdrawal precedes asynchronous mirror purge. Await purge and retain the late-subscription rejection assertion. 0/5 locally; 2 historical runs 0/10
LAN: discovery disabled Pending handshakes/writes survived socket closure and could recreate deleted routes. Drain discovery and recheck enablement after TLS. 1/5 0/10
CLI: native update / discovery overlap Product report combined a pre-install version with a post-install success status. Discard discovery across an install revision. Controlled overlap 1/1; original suite 0/1 Controlled overlap 0/100; original suite 0/10
Grok process cleanup (disposal and ignored cancellation) Immediate PID check assumes signal delivery/reaping is synchronous. Use the shared bounded process-state condition; a zombie cannot execute. The reported flake did not reproduce locally. 0/600 tests (100 complete runs) 0/600 tests (100 complete runs)
Agent skill sources No verified current cause found; left assertions and product code unchanged. 0/5 full suites plus 0/1 with two CPU burners Passed in the full gate

The new process wait retains a five-second failure bound and accepts only a missing or non-executable process. Unexpected OS errors still fail the test. Stop still has to terminate its child and persist a user interruption; the timeout case still has to fail without launching a harness.

Historical inventory

Audit snapshot: 189 dev Release runs, 2026-11-03 08:39 UTC through 2026-11-06 08:52 UTC, and 9 failed CI runs. Read failed job logs, including first-attempt logs for the successful rerun of Release 42072916585. Counts are distinct failed workflow runs per test, deduplicating run IDs across both listings and Bun's repeated summary lines. They are not a failure percentage: cancelled jobs did not all execute every test. Superseded cancellations with no failed job are excluded from test counts.

Full test name Failed runs Disposition
bots, schedules and worker settings at their linked home > an unreachable home fails immediately, keeps records read-only and queues nothing 7 Bootstrap barrier in this PR
bot platform tools through the UI core > discover a worker without roots, add any absolute workspace, validate paths, start a thread and search its title 5 Already fixed by #107: wait for the returned initial turn to finish
bots through official worker harnesses > gateway restart preserves a pending approval and never reruns inference 4 Product fix in this PR
process governor with owned subprocesses > a timeout kills an owned descendant that would otherwise survive its parent 3 Process-state condition in this PR
Share onward: three real gateways and independent databases > explicit reciprocal sharing permits both directions without a routing loop 2 Mirror-purge barrier in this PR
bundled stack: local enrollment, gRPC online, remote enrollment, restart durability and complete shutdown 2 Already fixed by #44 (missing desktop reflect polyfill/startup) and #103 (initial pairing racing secure-route migration; preserves identity/data and separately verifies unchanged saves)
migration 0077: connector configuration bootstrap > (unnamed) 2 Deterministic historical schema/fixture failure, not classified as a flake
moving things between linked computers > interrupted after the decision: the move rolls forward through restarts and link drops, idempotently 2 Already fixed by #44: stop source work and await target's own record
remote threads across two linked gateways > a file attached on A travels with the message to B 2 Shared-turn sequencing in this PR; no independent message loss reproduced
remote threads across two linked gateways > a file placed in the text on A keeps its place on B; an older B gets the text without the badge 2 Shared-turn sequencing in this PR; no independent message loss reproduced
remote threads across two linked gateways > a thread created from A on B's worker lives on B and streams back live 2 Worker-delivery / turn-completion barriers in this PR
Bun worker -> grpc-js (Node) gateway over TLS > handshake, command, 100 events, ack, worker half-close 1 Already fixed by #107: await the client-end output event
a postmaster orphaned by a killed guardian is stopped on the next start, so only one runs 1 Already fixed by #44: await orphaned sidecars during recovery
actionable errors across gateway APIs > Grok bot with native id and Proxy connection uses the gateway API without a reasoning-starving cap 1 Obsolete API expectation; Grok execution now uses worker harnesses
attachments > access to bytes > a preview the worker uploaded is readable through its thread (and its tree), nothing else 1 Historical 5 s timeout; current reproduction not established; #44 fixed scripted provider-ID collisions that could close links, but attribution of this timeout is unproven
automation worktrees over gRPC > settled scheduled threads can be cleaned up and linked worktree schedules are refused 1 Deterministic historical expectation/refusal mismatch
durable read-only thread mirrors across two gateways > a stale cursor or a journal gap fully resynchronizes, removing deleted threads and preserving archivals 1 Historical 60 s timeout; current cause not established; no speculative change
guardian closes its owned process groups when the Electron pipe disappears 1 Already fixed by #44: stop during startup / desktop sidecar initialization
managing the queue (gateway + scripted worker) > races with the head starting: the scheduler starts the head as it stands, with its current text 1 Historical closed worker link; #44 fixed colliding scripted provider thread IDs, but the log does not prove this particular link's closure cause
managing the queue (gateway + scripted worker) > the scheduler starts a head only as it read it (whileHead) 1 Same historical closed worker link; exact attribution unproven
owner-scoped SSH enrollment trust boundary > (unnamed) 1 Deterministic malformed OpenSSH fixture failure in beforeAll
provider CLIs (gateway + real worker + fake CLIs and registry) > native Claude updates with claude install; output is redacted and secrets never reach the installer 1 Product report-consistency fix in this PR; regression forces the overlap
remote threads across two linked gateways > only thread actions cross the link; requests that point elsewhere are refused 1 Deterministic historical allowed-method expectation
routes and local network discovery between two linked gateways > with discovery off a computer announces nothing, answers nothing and forgets LAN routes 1 Product discovery-lifecycle fix in this PR
worker enrollment and credential lifecycle over gRPC > CLI spends a token once, writes a private config, connects; rotation and revoke invalidate the live link 1 Already fixed by #45: enrollment token beginning with a dash was parsed as a CLI option

An additional failed CI run (41914149735) failed migration-ID/lint checks without a test failure; it is not a per-test row. Composer, Grok cleanup and skill sources were also investigated because they were reported in the task, although those names did not appear in this audit's failed-job inventory.

Validation and limits

  • bun install, bun run gen:check, bun run typecheck, bun run lint, bun run format:check and bun scripts/build-web.ts passed after rebasing onto current origin/dev.
  • Full bun run check:tmp: 1,448 passed, 159 existing skips, 0 failed, 258 files / 1,607 tests, 462.49 s. No test temp directories left behind; tool-owned runtime caches were removed by the runner's private-directory cleanup.
  • Additional unchanged suites: thread mirrors, attachments and queue management each passed 5/5 complete runs pinned to one CPU.
  • The exact historical attachment-preview, mirror-resync and queue-link failures have no proven current root cause. The reported skill-source and Grok flakes did not reproduce in the bounded local runs. Passing repetitions reduce uncertainty; they do not prove every historical failure has been eliminated.
  • No live-provider tests, packaged macOS runtime tests or browser/E2E tests were enabled. Existing opt-in skips remain unchanged. No UI copy changed; the new gateway shutdown rejection is an internal worker replay signal.

Fixes: #97
Fixes: #35
Fixes: #26

Leave pending worker tool calls unanswered during shutdown so reconnect can resume the same approval and inference. Reject old handlers instead of sending an interruption or polling after lease release.

The restart regression failed 4/30 loaded runs before and passed 30/30 after, including pending-call and approval assertions.

Fixes: #97
Closing discovery now waits for pinned handshakes and route writes, and a handshake finishing after discovery is disabled cannot add a route. Replace the silence check sleep with observed query cycles after draining old work.

Fixes: #35
Discard discovery results when an overlapping installation completes. This prevents publishing a successful installation alongside the previous executable and version.

A controlled discovery/install overlap reproduced the stale report before the fix; the regression passes 100/100 runs after it.

Fixes: #26
Wait for worker bootstrap, command delivery, terminal turns and mirror purge instead of observing earlier routing or stream events. Publish PID markers atomically and distinguish killed zombies from running descendants without a procfs exists/read race.

Give only the shell timeout case a short deadline; Stop waits for the gateway running state and retains process-group and no-harness assertions.
@nixuuu
nixuuu merged commit fd92dc5 into dev Nov 6, 2026
9 checks passed
@nixuuu
nixuuu deleted the test/flaky-nightly branch November 6, 2026 09:27
nixuuu added a commit that referenced this pull request Nov 7, 2026
No beta or stable has ever been cut: `next` and `main` are still at
57b87e5 while `dev` is ~290 commits ahead.

The dev → next plan shows why. Besides a temporary explicit hold (#262
`Fixes: #26`, released once #262 soaks), the fallback blame of web fix
#115 attributes its two adjacent lines in `AGENTS.md` to b7845036 `docs:
add AGENTS.md…`, the second commit after `next`. A hold on that commit
holds the entire suffix, permanently, because #115 is re-checked every
run.

A docs/test/ci/chore/style commit changes no shipped behaviour, so it
can't be the change a fix corrects. Blame now never attributes to those
commit types, and root `AGENTS.md`, `CLAUDE.md`, `README.md` and
`CONTRIBUTING.md` join the shared files blame ignores. Explicit
`Fixes:`/`Refs:` links and reverts still hold as before.
`docs/release.md` describes the rule.

Verified: new policy test (types, root files, refactor still holdable,
explicit link to a docs commit still holds); `promotion-policy`,
`promotion-attribution` and `promote` tests pass (38); typecheck, lint,
format clean.

Copy audit: no UI text changed.
nixuuu added a commit that referenced this pull request Nov 7, 2026
Scheduled Release runs on dev were cancelled when one flaky integration
test failed in a test shard. This PR collects every test failure from
the Release runs and PR CI runs of 2026-11-05 to 2026-11-07, finds the
cause of each, and fixes it deterministically. It adds no retries,
skips, global timeout increases or workflow changes.

Evidence was collected locally: gateway suites ran one file at a time,
mostly pinned to one CPU (`taskset -c 3`). Where a race could not be
forced naturally, a temporary delay was injected at the racing point,
and the same test was run with and without the fix. No injected delay is
committed.

### Fixed here

| Test | Cause | Fix | Before → after |
| --- | --- | --- | --- |
| `worker-ssh-command` › fixed SSH stdin … preserves the gateway and TLS
pin (nightly 42352444980) | After enrollment the installer runs `npm
prefix -g`. The test ran the runner's real npm, which cold-starts Node:
the success path took 0.3–4.1 s on CI (the tampering path, which exits
earlier, takes ~10 ms) and once went over the 5 s test timeout ("killed
1 dangling process"). | A stub `npm` in `$HOME/.local/bin`, which the
installer searches before the system paths. | 20 reruns with 6 busy
loops on the same CPU: mean 211 → 133 ms, max 662 → 314 ms; unloaded
mean 62 → 20 ms. |
| `full-access-mode` › an agent's side thread never gets Full access;
plus `agent-bus` › spawn options (PR CI) and the same race in 3 more
`agent-bus`/`agent-bus-cross` assertions | `spawn_thread` answers once
the side thread is stored. The gateway delivers the `createThread`
command to the worker afterwards, and the tests read `worker.created`
right away (Expected: 4, Received: undefined). |
`ScriptedWorker.createdThread(id)` waits for that command. | With the
worker's `createThread` handling delayed 200 ms: full-access 1 fail → 0;
agent-bus 3 relevant fails → 0; agent-bus-cross 2 fails → 0.
full-access-mode with 10 reruns on one CPU: 30/30. |
| `bots` › an expired lease cannot commit an old model answer (PR #318
CI) | The old gateway's 250 ms queue tick could re-claim the turn whose
lease the test expired before the competitor ticked. The held model then
ran again and the turn never settled (10 s timeout, last message "take
over"). | The old gateway drains, like one handing over: it keeps its
running turn but claims nothing. | With a 300 ms gap before the
competitor's tick: fail (identical error) → 3/3 pass. 10/10 on one CPU.
|
| `lan-routes` › routes are tried in order of last success (PR CI) | The
announcement test left B's withdrawn loopback route `127.0.5.2` in A's
routes. It is the newest route, so A's dial after the dead route
succeeded through it (dumped locally). B's next 1 s advertisement then
withdrew it, and the stale `127.0.0.1` route came first. On CI
`lastSuccessMs` was exactly one hour old, the value the test writes. |
The announcement test waits for the withdrawal and removes the route. |
The CI interleaving was not forced locally; the route dumps show each
step. After: 8/8 file runs on one CPU. |
| `config-sync-environment` › a document, a skill and a plugin arrive on
B (PR CI) | The test waited for the plugin only. A skill stays `WAITING`
until its version blob is fetched, one blob at a time (Expected:
`aeb81c…`, Received: undefined). | Wait for the document, the skill
version and the plugin artifact. | With B's blob fetches delayed 400 ms:
1 pass / 7 fail, the first with the exact CI error → 8/8. 5 runs on one
CPU: 8/8 each. |
| `composer-shell` › Codex steer executes at delivery (PR CI) | A watch
snapshot reads items before steers (`core-watch.ts`). When the
provider's user message item is ingested between the two reads, the
steer shows as delivered without its item. The stream sends the event
right after, so clients converge; the test only reads the first
snapshot. | Wait for a snapshot that has both. | 15 reruns on one CPU:
2/15 and 4/15 failed (the debug dump showed an empty item list) → 15/15.
|
| `schedules-new-thread` › offline pools retry the same occurrence (PR
CI) | A test closed a scripted worker's link while a command was on its
way. The worker loop replied on the closed link, and the `ConnectError`
escaped as an unhandled rejection that failed whichever test was
running. | The scripted worker's loop ends quietly on an unavailable
link. | Throwaway repro (close right after `createThread`, 20
iterations): 10/20 fail → 20/20 pass in 7 consecutive runs. The file
with 3 reruns: 21/21. |
| `worker-ssh` › owner-scoped SSH enrollment trust boundary (PR CI) |
ssh2's ed25519 keygen drops a leading zero byte of the public key (1 key
in 256). It writes a 31-byte public and 63-byte private key that neither
ssh2 nor OpenSSH (`ssh-keygen -y`) can read. The test's server host key
failed with "Malformed OpenSSH private key". | Product fix below; the
test uses the same helper. | `generateKeyPairSync`: 60/20000 and
83/20000 unreadable; `ed25519KeyPair`: 0/20000. worker-ssh 6/6. |

### Product fix (separate commit `fix(gateway): never store an
unreadable ssh install key`)

The gateway generates each owner's SSH install key with the same ssh2
call (`apps/gateway/src/core/worker-ssh.ts`, introduced in #5) and keeps
it until rotation. About 1 owner in 256 got a truncated public key and a
private key that can never be parsed, so every SSH install failed until
they rotated the key. `ed25519KeyPair` generates the pair again when it
does not parse. Keys already stored in that state still need Rotate. The
commit body carries `Fixes: #5`. This PR squashes under a `test:` title,
so that link and the patch release only apply if the fix is split out or
the PR is retitled.

### Already fixed by #262 (no change here)

- `config-sync-execution` › an unreachable home fails immediately…: all
6 failures were before #262 merged (last one 2026-11-06 09:01; #262
merged 10:27), and none since. 8/8 runs on one CPU.
- `remote-threads` › a file attached on A… / a file placed in the text
on A…: a cascade from the first test (worker `created` read without
waiting, thread not settled before the next test held turns). #262 fixed
exactly that, and none have recurred since.
- `computer-relay` › Share onward, `process-governor`, `bots-harness` ›
gateway restart: fixed by #262, and none have recurred since.

### Not flakes

Failures from in-progress feature-branch pushes, not on dev: the CLI
import suites on `feat/cli-import-*`, and the migration list and
error-text failures on `feat/linked-shared-config-7`.

### Gates

`bun install`, `bun run gen:check`, `bun run typecheck`, `bun run lint`,
`bun run format:check`, the web build and `bun run check:tmp` (1671
pass, 0 fail, 162 skip; nothing left in the temp dir) are all clean.

One thing to know: if TMPDIR is inside a Git checkout, `add-project` and
`linked-projects` fail locally, because their "folder without Git"
fixtures inherit the checkout's origin. `check:tmp` above ran with
TMPDIR on disk outside any repository.

Copy audit: no UI text changed.
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