Skip to content

fix(testing): make the fuzz CI guards satisfiable and de-flake the JS cancel test - #3023

Merged
chaliy merged 6 commits into
mainfrom
eve/clever-mccarthy-aa6pkb
Nov 27, 2026
Merged

chaliy merged 6 commits into
mainfrom
eve/clever-mccarthy-aa6pkb

Conversation

@chaliy

@chaliy chaliy commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

What changed

Three CI-side guards stop reporting their own setup as a defect. No product
behavior changes: the only library file touched is bashkit::testing, the
#[doc(hidden)] test-only module, and the rest is tests and knowledge.

  • Fuzz canary attribution now sees through characters a parser deletes.
    carries_through_expansion strips DROPPED_BY_PARSERS — NUL from shell word
    expansion, and "/'/\ from shell quote removal or the csv field parser
    — so a needle spliced with one of those is attributed to the script that
    spelled it.
  • The fuzz path got its own stderr budget. MAX_FUZZ_STDERR_BYTES (4 KiB)
    matches the largest ExecutionLimits::max_stderr_bytes any fuzz target
    configures, while MAX_STDERR_BYTES stays 1 KiB for the strict per-builtin
    path (assert_no_leak). A const assertion makes a future mismatch a compile
    error. The 1 KiB per-diagnostic bound is a third, separate budget and stays
    in diagnostic_prefix_tests.rs (L-ARITH-002).
  • The ctx.fetch cancellation test waits for its request to arrive before
    cancelling it, instead of sleeping 200ms and assuming so.

Why

Fuzz Testing run 45932089002 and the windows-latest lane of JS run
45816668178 were red on main (and the JS one recurred on this PR at ab7a1db). All three failures were guards misfiring, not
bugs in bashkit.

csv_fuzz reported the host canary in stdout from the input
BASHKIT_FUZZ_HOST_CANARY_47a83bcf_D"O_NOT_LEAK. echo passed the bytes
through verbatim and csv headers then removed the " as its CSV quote
character, printing the canary whole — so the output carried a token the script
text never spelled. This is the run-272 forgery one parser further down the
pipeline: libFuzzer harvests the canary from the detector's own contains, and
a spliced quote survived the comparison a spliced NUL already did not.

printf_fuzz tripped the stderr byte cap with 1,283 bytes, which was not a
flood. printf '%d %o %x' cycles its format over every operand, so 34
non-numeric operands drew 34 invalid number diagnostics — output linear in
the input and well inside the max_stderr_bytes(4096) the target itself
configures. The harness was holding a whole-execution budget to a single
diagnostic's
size, so any script landing in 1024..=4096 failed by
construction: the cap was unsatisfiable rather than strict.

The JS failure is not a product fault either, but my first explanation of it
was wrong and is worth recording. I read it as slow disconnect delivery on
Windows and replaced the 2s poll with a 20s event-based wait; it failed again
on ab7a1db, same assertion, which ruled that out — when it fails the
disconnect never arrives at all.

The cause is upstream. The test cancels an in-flight request but only assumed
the request was in flight, after sleeping 200ms. bash.execute has to reach
the native interpreter, dispatch the builtin and let undici open the connection
inside that window, and sibling tests in the same file show builtin dispatch
taking 1.3–1.5s on windows-latest. When 200ms ran out first, cancel()
landed before the builtin ran: no request was ever sent, the server handler
never ran, so no listener existed to report a disconnect and no later wait
could help. The assertion was failing on a request that did not exist — which
is also why the two Windows lanes disagreed run to run while macos and ubuntu
stayed green.

Before / After

Both crash units are replayed in fuzz_crash_regressions.rs. Against the old
harness they reproduce the CI failures exactly:

csv_crash_quote_forged_canary_is_an_echo_not_a_leak ... FAILED
  [csv_fuzz] FUZZ canary leaked into stdout (TM-INF-013 regression ...)

printf_crash_per_operand_diagnostics_are_not_a_flood ... FAILED
  [printf_fuzz] stderr exceeds 1024 bytes (1283 bytes)

— the same 1,283 bytes the nightly reported. After, all 11 replays pass.

The JS mechanism is reproducible on Linux: cancelling before dispatch rather
than sleeping gives the exact Windows signature.

exitCode=130 requests=0 closes=0

Exit 130 (the assertion that passed in CI), no request at the server, and no
disconnect even after the original 2s budget — matching serverAborted: false.
With the fix the cancel waits on the server actually holding the request, so it
cannot precede dispatch; the elapsed bound is timed from the cancel so it no
longer folds in dispatch and connection setup; and a request that never arrives
now fails at that point with a clear message instead of as a mystery disconnect
timeout.

Also fixed on the same reporting path, found in review: truncate sliced
arbitrary fuzz output at a fixed 512 bytes and panicked whenever that offset
landed inside a multi-byte character, replacing a canary-leak message with an
unrelated backtrace. It now floors the cut to a character boundary
(truncate_cuts_on_a_char_boundary).

Risk

  • Low
  • Attribution gets wider, and it over-approximates: the strip is unconditional
    and context-free, while a real parser drops those characters only in certain
    positions, and attribution is whole-script/whole-stderr. So it can excuse an
    occurrence no parser would have produced. This is the same residual false
    negative script_explains already documents, accepted for the same reasons,
    and erring this way is the right direction — under-approximating is what
    turns the nightly red on the detector's own dictionary.
  • Only the fuzz cap is looser, in 1024..=4096. The strict per-builtin path
    keeps 1 KiB, pinned by
    loosening_the_fuzz_cap_did_not_loosen_the_strict_path. Both remain absolute
    against attribution (attribution_does_not_relax_the_stderr_cap, sized off
    the constant so a future raise cannot quietly turn it into a no-op), and
    10 MB of library spam still fails.
  • The guard does not make the cap satisfiable for every target: eight of the
    26 configure no limit and take the 1 MiB default, so for them 4 KiB is a
    deliberate flood bound and this class of false positive can recur. Documented
    at the constant and in the threat model, with the fix named (give that target
    an explicit max_stderr_bytes).
  • MAX_STDERR_BYTES is pub but #[doc(hidden)] and documented as
    unsupported; its value is unchanged in any case.
  • The JS change is test-only and strengthens what it asserts: it now requires
    the request to reach the server and the abort to be observed, where before
    a lost race could skip the first silently.
  • The JS fix is reasoned plus reproduced in the failing direction on Linux, but
    not yet observed green on windows-latest; this PR's run is the first real
    test of it.

Checklist

  • Tests added or updated
  • Backward compatibility considered

Validation

cargo test --features http_client (7607 passed), failpoints slice (19),
cargo clippy --all-targets --all-features -- -D warnings, cargo fmt --check, scripts/tests (282), capability/workflow parity, check-okf,
check-doc-links, and the full ava suite (695 passed). cargo vet is
unaffected — no dependency or lockfile change — and CI runs it. No benchmarks
apply: no product code changed.


Generated by Claude Code

…opped quotes

Nightly Fuzz Testing run 45932089002 went red on csv_fuzz and printf_fuzz.
Neither was a product bug; both were harness guards reporting inputs they
had armed the fuzzer to build.

csv_fuzz flagged the host canary in stdout from the input
BASHKIT_FUZZ_HOST_CANARY_47a83bcf_D"O_NOT_LEAK. echo passed the bytes through
verbatim and csv headers then removed the `"` as its CSV quote character,
printing the canary whole, so the output carried a token the script text never
spelled and attribution could not account for it. That is the run-272 forgery
one parser further down the pipeline: libFuzzer harvests the canary from the
detector's own `contains`, and a spliced quote survived the comparison a
spliced NUL already did not. carries_through_expansion now strips
DROPPED_BY_PARSERS -- NUL from word expansion, and `"`/`'`/`\` from shell
quote removal or the csv field parser -- as well as NUL. Stripping can only add
matches, and no banned shape and no part of the canary contains any of those
characters, so every match it adds is a parser dropping punctuation out of
script text, which is an echo by definition.

printf_fuzz tripped the stderr byte cap with 1,283 bytes, which was not a
flood: printf '%d %o %x' cycles its format over every operand, so 34
non-numeric operands drew 34 `invalid number` diagnostics -- output linear in
the input and well inside the max_stderr_bytes(4096) the target itself
configures. The harness was holding a whole-execution budget to a single
diagnostic's size, so any script landing in 1024..=4096 failed by construction;
the cap was unsatisfiable rather than strict. MAX_STDERR_BYTES now matches the
largest limit any target configures, which keeps what the assertion was written
for: for those targets it says the engine honored the limit it was given, and
10 MB of library spam still fails. A const assertion makes a future mismatch a
compile error instead of a nightly-only failure, and the 1 KiB per-diagnostic
bound stays where it belongs, in diagnostic_prefix_tests.rs (L-ARITH-002).

Both crash units are replayed in fuzz_crash_regressions.rs and reproduce the
exact CI failures against the old harness, including the same 1,283 bytes.
attribution_does_not_relax_the_stderr_cap had hard-coded a 2,200-byte fixture
and would have silently become a no-op, so it is now sized off the constant.
The windows-latest lane of JS run 45816668178 failed on
"Ctrl+C aborts a held server connection via ctx.fetch: exit 130" at its
`server saw the connection abort` assertion, taking the JS Check gate and main
with it. Every other lane passed, and the seven preceding runs on main were
green.

The product path is not at fault: bash.cancel() aborts the builtin controller
synchronously before it calls native.cancel(), and abort() dispatches to undici
in the same tick, so the request is already aborted by the time execute()
resolves -- which the test confirms independently via exit 130 and its elapsed
bound. What remained was the kernel and the server's event loop noticing the
socket go away, and the test gave that a fixed 2s of 20ms polling rounds on a
single event, `req` 'close'. Neither the delay nor which event lands first is
uniform across platforms, so the assertion was timing out on the slowest runner
in the matrix rather than catching anything.

The test now resolves a promise from `req` 'close'/'aborted' and the socket's
'close'/'error' and races it against one generous timeout. The usual case
passes as soon as the event arrives instead of after a fixed wait, a slow
delivery no longer reads as a failure, and a genuine failure to propagate still
fails because the timeout resolves false. Recorded as a maintenance rule for
the ava suite, which runs on windows-latest as well as ubuntu.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
bashkit 136ced9 Commit Preview URL

Branch Preview URL
Nov 27 2026, 11:02 AM

@bashkit-pr-reviewer

bashkit-pr-reviewer Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Re-review after push 136ced9 — last P2 resolved, no findings

This push addresses the one open item from last round and touches nothing else:

  • js-cancel-cascade-after-arrival-failure (was P2) → resolved. The test now returns early (if (!arrived) return;, spec line 233) with a comment explaining exactly the cascade the finding described — cancelling nothing, waiting out the disconnect timeout, reporting a second failure pointing away from the cause. t.teardown/finally still close the server on that path.
  • Re-verified the Rust side is untouched since 070150d (split caps at testing.rs:72/103, char-boundary truncate, clap-chrome anchoring all intact) and the PR body now records the recurrence history honestly (JS flake recurred on this PR at ab7a1db).

All findings across the lifetime of this review are now resolved. No inline review submitted (nothing to flag). The PR still reports mergeable_state: blocked — flagging once more in case it needs author action rather than just pending checks.

…fuzz one

Review of the previous commit caught that raising the single shared
MAX_STDERR_BYTES also moved assert_no_leak, the strict per-builtin path the
threat model calls absolute, from 1 KiB to 4 KiB -- so a builtin emitting
kilobytes of Debug spam would have passed a gate that previously failed it.
Only the fuzz path needed the looser figure, because only a fuzz target inlines
bytes it did not choose and runs under a limit it declared itself.

The two budgets are now separate constants: MAX_STDERR_BYTES stays 1 KiB for
assert_no_leak, and the new MAX_FUZZ_STDERR_BYTES is 4 KiB for
assert_fuzz_invariants, with the const assertion moved onto it.
loosening_the_fuzz_cap_did_not_loosen_the_strict_path pins the split and fails
if they are ever collapsed back into one.

Two documentation claims were also too strong, and are now qualified where they
are made:

- The guard does not make the cap satisfiable for every target. Eight of the 26
  configure no limit and so take the 1 MiB default, 256x the harness figure, so
  for them 4 KiB is a deliberate flood bound rather than a satisfiable one and
  this class of false positive can recur. The fix when it does is an explicit
  max_stderr_bytes on that target, not a blind raise.
- Stripping DROPPED_BY_PARSERS over-approximates: it is unconditional and
  context-free, while a real parser drops those characters only in particular
  positions, and attribution is whole-script and whole-stderr. So it can excuse
  an occurrence no parser would have produced. That is the same residual false
  negative script_explains already documents, accepted for the same reasons,
  and erring this direction is right -- under-approximating is what turns the
  nightly red on the detector's own dictionary.

Fixed in passing on the same reporting path: truncate sliced arbitrary fuzz
output at a fixed 512 bytes, panicking whenever that offset landed inside a
multi-byte character and replacing a canary-leak message with an unrelated
backtrace. It now floors the cut to a character boundary.

chaliy commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

All three findings were real. Fixed in ab7a1db.

[P1] stderr-cap-shared-with-strict-path — fixed. This was the significant
one: both paths read the same constant, so raising it for the fuzz targets
silently moved assert_no_leak from 1 KiB to 4 KiB, and the threat model calls
that path absolute. Split into two constants — MAX_STDERR_BYTES stays 1 KiB
for the strict path, MAX_FUZZ_STDERR_BYTES is 4 KiB for
assert_fuzz_invariants, with the const assertion moved onto the latter. Only
the fuzz path needed the looser figure, since only a fuzz target inlines bytes
it did not choose and runs under a limit it declared itself.
loosening_the_fuzz_cap_did_not_loosen_the_strict_path now fails if they are
ever collapsed back into one.

[P1] fuzz-stderr-guard-misses-default-targets — documented, not closed.
Correct that the guard only covers targets configuring an explicit limit; the
other eight take the 1 MiB default, so for them 4 KiB is a deliberate flood
bound rather than a satisfiable-by-construction one, and this class can recur
there. The constant's docs, the threat model and security-testing.md now say
so plainly, and name the fix for when it happens: give that target an explicit
max_stderr_bytes declaring its real budget, rather than raising the harness
cap. I did not make explicit caps mandatory across all 26 targets here — that
is a wider change than this CI fix should carry, and none of the eight drives a
per-operand diagnostic loop the way printf does.

[P2] quote-strip-overapproximates-parsers — fixed. The "echo by
definition" claim was too strong, exactly as described: the strip is
unconditional and context-free while a real parser drops those characters only
in particular positions, and attribution is whole-script/whole-stderr. The
paragraph now states the over-approximation and the residual false negative,
cross-referencing the one script_explains already documents, and says why
erring this direction is still right — under-approximating is what turns the
nightly red on the detector's own dictionary.

Pre-existing truncate observation — fixed too. Confirmed: with
s.len() > max it sliced at a fixed 512 bytes, which panics whenever that
offset lands inside a multi-byte character, so a canary-leak report could
surface as an unrelated backtrace instead of the assertion message. It now
floors the cut to a character boundary, covered by
truncate_cuts_on_a_char_boundary. Small and on the same reporting path this
change already touches, so I took it rather than leaving it.

On the JS note: agreed that a genuine abort-delivery failure now costs 20s
instead of 2s. That trade seemed right — the 2s bound was producing false reds
on the Windows lane, and a real failure is rare and still detected.

Re-validated after the change: cargo test --features http_client (7607
passed), failpoints slice (19), cargo clippy --all-targets --all-features -- -D warnings, cargo fmt --check, check-okf, check-doc-links, and the 11
crash replays.


Generated by Claude Code

The csv_fuzz paragraph still read 'an echo by definition', which overstates an
unconditional context-free strip and contradicts the qualified wording the same
change put on carries_through_expansion. State the over-approximation and the
residual it shares with script_explains, as the code comment does.
My previous commit on this test was wrong about the cause and did not fix it:
`Runtime callbacks (windows-latest)` failed again on ab7a1db, same assertion,
despite a 20s budget and four disconnect listeners. That ruled out slow
delivery -- when it fails, the disconnect never arrives at all.

The real cause is upstream of the disconnect. The test cancels an in-flight
request, but it only assumed the request was in flight, after sleeping 200ms.
`bash.execute` has to reach the native interpreter, dispatch the builtin and
let undici open the connection within that window, and sibling tests in this
file show builtin dispatch taking 1.3-1.5s on windows-latest. When 200ms ran
out first, `cancel()` landed before the builtin ran: no request was ever sent,
the server handler never ran, so no listener existed to report a disconnect and
no later wait could help. The assertion was failing on a request that did not
exist.

Reproduced on Linux by cancelling before dispatch instead of sleeping, which
gives the exact Windows signature -- exit 130, zero requests at the server,
zero closes after the original 2s budget. So this needs no platform-specific
explanation: Windows just loses the race more often, which is also why the two
Windows lanes disagreed run to run while macos and ubuntu stayed green.

The cancel now waits on `requestArrived` from the server handler, so it aborts
something that exists, and that wait is bounded so a request that never arrives
fails where the cause is visible. The elapsed bound is timed from the cancel
rather than from `execute`, since it is about how fast cancellation unwinds and
would otherwise fold in dispatch and connection setup on a slow runner. The
event-based disconnect wait is kept and factored into `raceWithTimeout`.

chaliy commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Correction on the JS failure: my first diagnosis was wrong

Recording this because the CI failure above is on this PR and my earlier
explanation of it does not hold.

Runtime callbacks (windows-latest) (execution-plan) failed on ab7a1db with
the same assertion the PR set out to fix, despite the 20s budget and four
disconnect listeners I had added. That rules out the slow-delivery theory:
when it fails, the disconnect never arrives at all. Only serverAborted failed
— exit 130 and the elapsed bound both passed.

The cause is upstream of the disconnect. The test cancels an in-flight request
but only assumed it was in flight, after sleeping 200ms. bash.execute has
to reach the native interpreter, dispatch the builtin and let undici open the
connection inside that window, and sibling tests in this same file show builtin
dispatch taking 1.3–1.5s on windows-latest. When 200ms ran out first,
cancel() landed before the builtin ran: no request was sent, the server
handler never ran, so no listener existed to report a disconnect and no later
wait could help. The assertion was failing on a request that did not exist.

That also explains what the platform theory could not: the two Windows lanes
disagreed run to run (interpreter red on main, execution-plan red here, the
other green each time) while macos and ubuntu stayed green throughout.

Reproduced on Linux by cancelling before dispatch instead of sleeping:

exitCode=130 requests=0 closes=0

Exit 130, zero requests at the server, zero closes after the original 2s
budget — the exact Windows signature.

Fixed in 070150d: the cancel waits on requestArrived from the server handler,
so it aborts something that exists, bounded so a request that never arrives
fails where the cause is visible rather than as a mystery disconnect timeout.
The elapsed bound is now timed from the cancel rather than from execute,
since it is about how fast cancellation unwinds and would otherwise fold in
dispatch and connection setup on a slow runner — that would have been a fresh
flake of my own making. The event-based disconnect wait is kept, factored into
raceWithTimeout.

Verified: full ava suite 695 passed, oxlint clean. The honest caveat is that
this is reasoned and reproduced in the failing direction on Linux, but has
not yet been observed green on windows-latest — this PR's run is the first
real test of it.


Generated by Claude Code

@bashkit-pr-reviewer bashkit-pr-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review of the JS rework.

Review follow-up. A false `arrived` recorded the failure and then fell through
into cancelling a request that was never sent, waiting out the full disconnect
timeout and reporting a second failure that points away from the cause -- the
opposite of what the arrival assertion's message promises. Return there
instead; the server still closes via t.teardown and the finally block.

The windows-latest lanes both passed on 070150d, including the execution-plan
one that failed on ab7a1db, so the dispatch-race diagnosis holds.
@chaliy
chaliy merged commit 8573f55 into main Nov 27, 2026
112 checks passed
@chaliy
chaliy deleted the eve/clever-mccarthy-aa6pkb branch November 27, 2026 11:32
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