Skip to content

test: make release integration tests deterministic - #325

Merged
nixuuu merged 8 commits into
devfrom
test/release-flakes
Nov 7, 2026
Merged

nixuuu merged 8 commits into
devfrom
test/release-flakes

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 7, 2026

Copy link
Copy Markdown
Member

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)

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.

nixuuu added a commit that referenced this pull request Nov 7, 2026
ssh2's ed25519 key generation drops a leading zero byte of the public
key about once in 256 keys (83 of 20,000) and writes a private key that
neither ssh2 nor OpenSSH can read (`Malformed OpenSSH private key`). The
gateway uses it for each owner's SSH install key, so an affected owner's
SSH worker installs fail until the key is rotated.

A generated pair that doesn't parse is now generated again
(`apps/gateway/src/core/ssh-keys.ts`); 0 of 20,000 bad afterwards.
Owners who already have a bad stored key still need to rotate it once.

Split out of the release flake PR (#325), where the SSH installer test's
own host key hit the same bug.

Copy audit: no UI text changed.

Fixes: #5
spawn_thread answers once the side thread is stored; the gateway delivers its createThread command to the worker afterwards. Five assertions read the scripted worker's created list right after the tool result and failed on a slow runner (Expected: 4, Received: undefined). ScriptedWorker.createdThread waits for that command.
The old gateway's 250 ms queue tick could claim the turn whose lease the test expired before the competitor ticked. The old gateway then ran the held model again and the turn never settled (10 s timeout, last message 'take over'). The old gateway now drains like one handing over: it keeps its running turn and claims nothing.
After enrollment the installer runs 'npm prefix -g'. The test ran the runner's real npm, which cold-starts Node: 0.3-4.1 s on CI and over the 5 s test timeout once. A stub in $HOME/.local/bin, which the installer searches before the system paths, keeps the host toolchain out of the test.
The announcement test left B's withdrawn loopback address in A's routes. Loopback still reaches B there, so the takeover test's dial could succeed through it; B's next advertisement then withdrew it and the stale 127.0.0.1 route came first (lastSuccessMs exactly one hour old). The announcement test now waits for the withdrawal and removes the route.
The test waited for the plugin only. A skill record is applied as waiting until its version's content is fetched, one blob at a time, so B could list the skill without its artifact (Expected: aeb81c…, Received: undefined). The wait now covers the document, the skill version and the plugin artifact.
A watch snapshot reads items before steers. When the provider's user message item is ingested between the two reads, the snapshot shows the steer delivered without the item (Expected: true, Received: false; 2 of 15 runs on one CPU). The test now waits for a snapshot with both.
A test that closes a scripted worker's link can do so while a command is on its way. The worker loop then replied on the closed link, the ConnectError escaped as an unhandled rejection and failed whichever test was running ('offline pools retry the same occurrence', 92 ms). Closing a link right after createThread reproduced it in 10 of 20 runs; the loop now ends quietly on an unavailable link.
The test's SSH server key came from ssh2's ed25519 keygen, which writes an unreadable key for one key in 256; the whole file then failed at startup (Cannot parse privateKey: Malformed OpenSSH private key).
@nixuuu
nixuuu force-pushed the test/release-flakes branch from 13dcf8d to e5bbcc9 Compare November 7, 2026 09:41
@nixuuu
nixuuu merged commit 7cb6ef4 into dev Nov 7, 2026
9 checks passed
@nixuuu
nixuuu deleted the test/release-flakes branch November 7, 2026 09:45
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