Repository navigation
test(ui-server): close three test races: partial JSON lines, a slow cap fixture, shared temp listings (#4247, #4249, #4252) - #4254
Merged
Conversation
…lete (#4247) The calls.jsonl readers parsed the whole trimmed file, so a poll that landed after appendFileSync created the file but before it wrote the line parsed "" and threw "JSON Parse error: Unexpected EOF". A partial line threw the same way. completeJsonLines parses only lines ended by a newline, and every polled JSON-lines reader in the ui-server tests uses it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…4249) The case wrote 2,500 files to prove a 1,000-path cap and outran the 30 s hang limit on a loaded unit worker. A 20-path cap keeps every assertion (a clone far past the cap does not pause, a workspaces-old/ sibling and brain paths do) with 170 files; locally the file drops from 3.3 s to 0.5 s. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… own (#4252) The placement fixture proved "no temporary copy" by diffing the shared temp directory for brain-turn-data-*, so a tree another test process created at the same time counted as this one's. The fixture now runs with a private TMPDIR and asserts it is listing it. The relay probe's diff is already isolated by its launchers; a comment records why. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
Author
Independent reviewReviewed head a596a6d against base 80a16d2. Reviewer: agent. 1 finding: 0 fixed, 0 filed, 0 rejected, 1 without a disposition. {
"version": 1,
"kind": "brain-review-receipt",
"pr": 4254,
"head": "a596a6d680f4c7e1c108e1229812936ff8c7256a",
"base": "80a16d2b724cd3d6f979ad5c1313073d418bf987",
"reviewer": "agent",
"outcome": "findings",
"findings": [
{
"summary": "packages/ui-server/tests/json-lines.test.ts:10 overwrites the sole cleanup path on each file() call. The test creates five temporary directories, but afterEach removes only the last, leaking four directories on every run. Track all created directories or create one directory per test."
}
]
} |
…ves (#4247) The cleanup kept only the last directory file() made, so four of the five leaked on every run. Each test now gets one directory, created before it and removed after it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
Author
Independent reviewReviewed head a596a6d against base 80a16d2. Reviewer: agent. 1 finding: 1 fixed, 0 filed, 0 rejected, 0 without a disposition. {
"version": 1,
"kind": "brain-review-receipt",
"pr": 4254,
"head": "a596a6d680f4c7e1c108e1229812936ff8c7256a",
"base": "80a16d2b724cd3d6f979ad5c1313073d418bf987",
"reviewer": "agent",
"outcome": "findings",
"findings": [
{
"summary": "packages/ui-server/tests/json-lines.test.ts:10 overwrites the sole cleanup path on each file() call. The test creates five temporary directories, but afterEach removes only the last, leaking four directories on every run. Track all created directories or create one directory per test.",
"disposition": "fixed",
"commit": "25bef5026a89587349376aae9a5165519dfc8f50"
}
]
} |
Owner
Author
Independent reviewReviewed head 25bef50 against base 80a16d2. Reviewer: agent. No findings. {
"version": 1,
"kind": "brain-review-receipt",
"pr": 4254,
"head": "25bef5026a89587349376aae9a5165519dfc8f50",
"base": "80a16d2b724cd3d6f979ad5c1313073d418bf987",
"reviewer": "agent",
"outcome": "no-findings",
"findings": []
} |
schlessera
marked this pull request as ready for review
November 18, 2026 09:24
Five turn-scope cases start a `while :; do sleep 1; done` worker and observe straight away. The observation freezes the worker tree, and the freezer cannot confirm a stopped tree until the sandbox's PID 1 has forked the shell. On a loaded hosted runner (determinism, 4 CPU burners) the first observation outran that fork and failed "Worker process tree did not confirm its frozen state". Each case now waits until a sleep process runs below the worker before it observes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
Author
Independent reviewReviewed head 98a882b against base c156dc2. Reviewer: agent. No findings. {
"version": 1,
"kind": "brain-review-receipt",
"pr": 4254,
"head": "98a882b2ea9b41e5ee5171365adc1b5d53312a84",
"base": "c156dc2b278692980115f0db6c3294f553b2ebb8",
"reviewer": "agent",
"outcome": "no-findings",
"findings": []
} |
Owner
Author
schlessera
marked this pull request as draft
November 18, 2026 09:48
schlessera
marked this pull request as ready for review
November 18, 2026 09:48
This was referenced Nov 18, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #4247
Closes #4249
Closes #4252
What changed
Three test-only races in the ui-server tests are fixed. The JSON-lines readers that poll a file another process appends to now parse only newline-terminated lines (
completeJsonLines,packages/ui-server/tests/helpers/json-lines.ts). A poll that lands between file creation and the write no longer throwsJSON Parse error: Unexpected EOF(#4247). Thefiles_changedworkspaces case proves the same exclusion with a 20-path cap and 170 files, instead of a 1,000-path cap and 2,500 files, so it no longer outruns the 30 s hang limit (#4249). The turn-tree placement fixture lists its temporary trees in a privateTMPDIR, so another process'sbrain-turn-data-*directory no longer counts as a temporary copy (#4252).Why this shape
test(ui-server): the web broker's calls() helper reads calls.jsonl mid-write and throws #4247. One shared helper rather than per-file patches, because the same
trim().split().map(JSON.parse)shape appears in every reader of a file another process appends to (broker, pi worker, version-requirements, hygiene, HTTP CLI logs, capture). All of them now use it.test(ui-server): the files_changed workspaces/ case outruns the 30 s test limit on a loaded unit worker #4249. I cut the volume instead of raising the timeout. The issue allows either, and a smaller cap keeps every assertion while removing the load sensitivity, rather than budgeting for it.
test: temp-directory diffs count other processes' directories (turn-data-tree, relay probe) #4252. The private
TMPDIRfollows the ci: main red at c2870f8ce44b: browser #4250 pattern (usePrivateTmpdir, which asserts it is the directory being listed). Two of the listed sites did not need it:turn-data-tree.test.ts(bases(),left()) is already isolated. Itsfixture(packages/ui-server/tests/turn-data-tree.test.ts:60-63) gives every test its ownTMPDIR. The contention runs below confirm it, so that file is unchanged.server-host-relay-probe.tsonly ever runs under bwrap with--tmpfs /tmp(native-route-qualification.test.ts), or inside a one-step-at-a-timedocker run --rmcontainer (scripts/prove-worker-identity.ts). Its/tmpis private by construction. A comment now records that. I did not move itsTMPDIR: in the managed identity mode the relay directory must stay reachable by the worker uid, and only the Docker identity proof could show that a change keeps it reachable.Audit for the third criterion: every other listing of the shared temp directory in
packages/*/testsandtests/is private (autonomous-envelope,hygiene-fixture-cleanup), pid-scoped (private-index-cache) or inside a sandboxed/tmp(worker-turn-temp).Proof
trim().split("\n")logic,json-lines.test.tsfails withSyntaxError: JSON Parse error: Unexpected EOFat the empty-file case (CREATED_BUT_UNWRITTEN_FILE_HAS_NO_RECORDS), the CI error from test(ui-server): the web broker's calls() helper reads calls.jsonl mid-write and throws #4247. Restored, it passes.turn.filesChangedchanged to count workspace paths (packages/ui-server/src/brain/turn-scope.ts), the reduced case fails onWORKSPACE_CLONE_DOES_NOT_PAUSE_FILES_CHANGED. Restored, it passes. The single-case file run drops from 3.31/3.20/3.28 s on main to 0.53/0.55/0.54 s.brain-turn-data-*,brain-private-index-*,brain-private-index-base-<live pid>-*andbrain-inference-*in/tmp:turn-data-tree-placement.test.tson main: 3 of 3 runs fail onNO_TEMPORARY_COPY, with 2 to 4 tests failing per run.turn-data-tree.test.ts"reusable private index base" and "aborted admission" on main: 3 of 3 runs pass, which shows the existing fixture isolation.80a16d2b7). Those failures all need an unprivileged user namespace, a tmpfs or a strict mount, which this host's AppArmor userns restriction refuses. The files whose changed cases run here pass: json-lines, web-tools-broker 12/12, web-pi-worker 2/2, turn-data-tree-placement 6/6, and the changed cases in turn-scope and turn-data-tree. Hosted unit proof covers the rest.{"version":1,"kind":"brain-check-pr-receipt","head":"98a882b2ea9b41e5ee5171365adc1b5d53312a84","base":"origin/main","mode":"focused","startedAt":"2026-11-18T09:46:50.909Z","finishedAt":"2026-11-18T09:47:16.652Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":12936.143485000002},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":103.86262999999963},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":66.7135789999993},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":18.171086999998806},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":12597.770993000002}]}Checklist
packages/ui-react/,packages/ui-kit/,packages/ui-server/orpackages/core/carries a recorded independent review of its head (bun scripts/review-receipt.ts check <pr>), or it touches none of them.docs/reflect the change, or nothing documented moved.docs/decisions/provider-history.md): the provider-history guard passes, or nothing on a turn's path changed.Review round 1 found a temp-directory leak in
json-lines.test.ts, fixed in 25bef50 (each case now owns one directory).Candidate run 44275585611 (head 6ad9d62) failed
determinism (2). Repeatingturn-scope.test.tsunder 4 CPU burners, "workspace writes still count toward turn_bytes" failed its second repetition with "Worker process tree did not confirm its frozen state". Thefiles_changedcase from this PR passed both repetitions (5.7 s, 3.5 s).That case and four others start a
while :; do sleep 1; doneworker and observe at once. The freezer (freeze,packages/ui-sdk/src/server/worker-freezer.ts:39-52) cannot confirm a stopped tree until the sandbox's PID 1 has forked the shell, and its 5 s deadline is a product timing, so it stays. Cutting thefiles_changedcase from 1,500 writes to 150 also shortened the head start that hid this race. So 98a882b makes each of the five cases wait until asleepruns below the worker (sleeping, read from the host's /proc) before it observes.This cause is inferred from the code. A local load run did not reproduce the failure: with the case pinned to 2 cores under 8 burners, 10 reruns passed on both main and the branch. The file's local failures are identical to main's.
Anything left open
Nothing. The #4252 contention criterion is met for the placement fixture. The two turn-data-tree sites and the relay probe were already isolated, as Proof shows.
🤖 Generated with Claude Code