Skip to content

test(clazel): accept 'cannot write' for a truncated hostile renderer - #20

Merged
atiernan merged 1 commit into
mainfrom
fix/adversarial-flake
Oct 27, 2026
Merged

atiernan merged 1 commit into
mainfrom
fix/adversarial-flake

Conversation

@atiernan

Copy link
Copy Markdown
Member

Fixes a flaky test that failed Verify (base, macOS) on #10. That PR only adds clazel-der, which this test doesn't touch.

hostile_renderers_are_killed_and_well_behaved_ones_are_unaffected (crates/clazel/tests/adversarial.rs) expected every hostile renderer to end with "closed its socket". The test sent renderer 32 a Truncated frame, and that renderer ended with "cannot write":

renderer 32 (Truncated, seed 539365443) did not end with "closed its socket": [
    "<- commit \"https://evil32.test/\" and a script of 0 bytes",
    "exited: cannot write; exit status: 0; stderr: hostile: seed=539365443 kind=Truncated bytes=8 head=0000000b82096831",
]

Cause

  • hostile::attack (crates/clazel-renderer/src/hostile.rs:296-305) writes the frame and returns at once for Kind::Truncated, so that renderer exits immediately. Every other kind waits to be cut off.
  • The host spawns the renderer and writes its Commit in the same step (crates/clazel/src/lib.rs:157-163), which races that exit:
    • if the host reads the closed socket first, it logs "closed its socket";
    • if the process has already exited when the host writes, the write fails, and it logs "cannot write".
  • Either way the host reaps the renderer and reports RendererExited to the kernel.
  • crates/clazel/tests/host.rs:108-116 already accepts both outcomes for a stub that exits immediately, for the same reason.

Fix

For the Truncated kind only, the test now accepts either wording, with a comment explaining the race. Every other kind keeps its single expected outcome. Every other assertion is unchanged:

  • the renderer was sent only its Commit;
  • exactly one exited line carries the right seed and kind;
  • the kernel forgot the renderer;
  • the well-behaved renderers match their baseline.

So a hostile renderer that wasn't cut off, or was sent more, still fails the test.

Results

  • I couldn't reproduce the race locally on macOS: 0 failures in 60 idle runs and 40 under CPU load. The diagnosis comes from the code and the CI log.
  • After the fix: 0 failures in 50 runs.
  • cargo test -p clazel, strict clippy, cargo fmt --all --check and cargo xtask check pass.
  • This changes one test file and nothing under clazel-sys, so no audit is needed.

Needs Alex's OK to merge.

🤖 Generated with Claude Code

…r a truncated frame

A truncated-frame renderer exits at once, so the host races it: reading the
closed socket logs 'closed its socket'; a Commit write to the already-exited
process fails and logs 'cannot write'. Both reap the renderer and tell the
kernel; the Commit-only and kernel-forgot checks still apply. Other kinds
keep their single expected outcome.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@atiernan
atiernan merged commit ad07787 into main Oct 27, 2026
23 checks passed
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