Skip to content

test(ui-server): close three test races: partial JSON lines, a slow cap fixture, shared temp listings (#4247, #4249, #4252) - #4254

Merged
schlessera merged 6 commits into
mainfrom
test/4247-4249-4252-test-races
Nov 18, 2026
Merged

schlessera merged 6 commits into
mainfrom
test/4247-4249-4252-test-races

Conversation

@schlessera

@schlessera schlessera commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

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 throws JSON Parse error: Unexpected EOF (#4247). The files_changed workspaces 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 private TMPDIR, so another process's brain-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 TMPDIR follows 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. Its fixture (packages/ui-server/tests/turn-data-tree.test.ts:60-63) gives every test its own TMPDIR. The contention runs below confirm it, so that file is unchanged.
    • server-host-relay-probe.ts only ever runs under bwrap with --tmpfs /tmp (native-route-qualification.test.ts), or inside a one-step-at-a-time docker run --rm container (scripts/prove-worker-identity.ts). Its /tmp is private by construction. A comment now records that. I did not move its TMPDIR: 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/*/tests and tests/ is private (autonomous-envelope, hygiene-fixture-cleanup), pid-scoped (private-index-cache) or inside a sandboxed /tmp (worker-turn-temp).

Proof

bun run check:pr --base origin/main
{"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

  • Focused local preflight/behavioral receipts and complete selected hosted proof passed; actual head/base/job checkout evidence is in Proof.
  • Acceptance criteria from the issue are all met, or the gap is named below.
  • A PR touching packages/ui-react/, packages/ui-kit/, packages/ui-server/ or packages/core/ carries a recorded independent review of its head (bun scripts/review-receipt.ts check <pr>), or it touches none of them.
  • The PR and completed/advanced issues have verified release milestones under docs/process/github.md.
  • A changeset is included, or this changes nothing a consumer can see.
  • No personal data anywhere in the diff — the leakage gate covers the whole tree.
  • The integration contract index or relevant component is updated in this same commit, or nothing in the machine surface moved.
  • Docs under docs/ reflect the change, or nothing documented moved.
  • A fail-closed guard added or changed answers the proportionate-containment checklist in this body, or no guard changed.
  • Provider history stays append-only (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). Repeating turn-scope.test.ts under 4 CPU burners, "workspace writes still count toward turn_bytes" failed its second repetition with "Worker process tree did not confirm its frozen state". The files_changed case from this PR passed both repetitions (5.7 s, 3.5 s).

That case and four others start a while :; do sleep 1; done worker 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 the files_changed case 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 a sleep runs 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

schlessera and others added 3 commits November 18, 2026 09:01
…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>
@schlessera schlessera added type: test Coverage, harness or proof work with no behaviour change. area: ui-server Hono app factory: turn coordinator, auth, session catalog, routes, cron. labels Nov 18, 2026
@schlessera schlessera added this to the 0.45.0 milestone Nov 18, 2026
@schlessera

Copy link
Copy Markdown
Owner Author

Independent review

Reviewed 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>
@schlessera

Copy link
Copy Markdown
Owner Author

Independent review

Reviewed 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"
    }
  ]
}

@schlessera

Copy link
Copy Markdown
Owner Author

Independent review

Reviewed 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

Copy link
Copy Markdown
Owner Author

Collisions at head 25bef50 (bun scripts/collisions.ts --json --pr 4254): closure-level only, with #3056, #3059, #3069, #3581, #3622, #4151, #4234 and #4238. No path collision.

@schlessera
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>
@schlessera

Copy link
Copy Markdown
Owner Author

Independent review

Reviewed 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": []
}

@schlessera

Copy link
Copy Markdown
Owner Author

Collisions at head 98a882b (bun scripts/collisions.ts --json --pr 4254): closure-level only, with #3056, #3059, #3069, #3581, #3622, #4151 and #4234. No path collision.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ui-server Hono app factory: turn coordinator, auth, session catalog, routes, cron. type: test Coverage, harness or proof work with no behaviour change.

Projects

None yet

1 participant