Repository navigation
Description
Context
scripts/contract.sh exits 4 when the server under test never comes up: "target did not become healthy" or "target process exited early" (contract.sh:221 and :226). Contract cells and the mutants job then fail intermittently. Because gate requires every job, one of these turns the required check red, on main and on pull requests, for a reason that says nothing about the code.
scripts/mutants.sh runs each mutant as contract.sh ... > "$OUT/$name.out" 2>&1 (:53), so the server log that contract.sh prints on exit 4 goes into a file the job log does not show. Its summary then labels any non-kill SURVIVED or did not run (exit=..) (:33), so a server that never started reads like a surviving mutant, which is the finding the job exists to make.
Evidence
| Where | Job | What was seen |
|---|---|---|
push to main, b1c9d1f (run 40258128717) |
mutants |
native-memory engine + case-sensitive-search SURVIVED or did not run (exit=4, failed tests=) |
| #86, first run (42158481836) | mutants |
native-memory main + ignore-revoked ... (exit=4, failed tests=) |
| #86, first run | contract (worker-cf, bindings) |
Address already in use (127.0.0.1:34322), then target process exited early, exit 4 |
| #88, a throwaway pull request (42164639829) | mutants |
ignore-revoked again, exit=4; the other ten mutants were killed |
| #88 | contract (worker-cf, main) |
Address already in use (127.0.0.1:43896), exit 4 |
Of the nine pushes to main from ad07a79 to a206319, four failed (ae7dfa6, c0736a0, 7e4e858, b1c9d1f). For c0736a0, 7e4e858 and b1c9d1f the failing job was mutants ("Every mutant must be KILLED"); I did not inspect ae7dfa6. The last three pushes passed.
It is not a real surviving mutant: rerunning the failed jobs of #86 passed, #87's own run was green, and running the ignore-revoked mutant locally on the same tree gave a healthy server and a kill (49 passed, 5 failed, exit 101).
What is not known
- Why
mutantsfails: its log does not show the server's. Theworker-cfcells areAddress already in use. - Two hypotheses, neither tested. (1)
pick_port(contract.sh:72-85) picks a random port in 20000-49999 and checks only that nothing is listening on it, at the start of the script. The server binds long afterwards, after a build, so there is a window. (2) That range overlaps Linux's default ephemeral range (32768-60999), where a port can be held as the source port of an outgoing connection, whichlsof -sTCP:LISTENdoes not see but abindrefuses. macOS's ephemeral range starts at 49152, which would explain why it is never seen locally. ignore-revoked(the fourth mutant to start) has been the failing one on both pull-request runs wheremutantsfailed. That may be chance.
Proposal
- Make it diagnosable first: when a mutant is not killed, print the tail of
$OUT/$name.out(the server log) into the job log, and uploadtarget/mutantson failure. - Fix the port choice: take it from below the ephemeral range, or bind port 0 and read the port back, or retry the server start once on
address already in usewith a fresh port. That is a retry of the start, not of a test; AGENTS.md rule 2 forbids retrying tests, and this must not weaken it. - Separate "did not run" from "survived" in the
mutantssummary. An exit-4 mutant is not evidence that an assertion is vacuous, and a real survivor must stay unmistakable.
Acceptance criteria
- A mutant that is not killed shows its server log in the CI job log.
- The
mutantssummary reports a mutant whose server never started differently from one that survived, and a planted unkillable mutant still reportsSURVIVED(rule 8's control). -
flake-hunt.ymlon the affected cells (worker-cf main,worker-cf bindings), and a repeated run ofmutants, show no exit-4 failures over a number of runs agreed in this issue (30, say). - If hypothesis 1 or 2 is confirmed or ruled out, the finding is recorded here.
References
#86 (first run), #87, #88; scripts/contract.sh, scripts/mutants.sh; .github/workflows/flake-hunt.yml, contract-cell.yml; AGENTS.md rules 2 and 8.
Activity
aRustyDev commentedon Nov 10, 2026
One more occurrence, and this one is the guard line, not a mutant row.
#99, first run (run 42670075647, attempt 1, head
45bf3d0, 2026-11-09):mutantsfailed withAll ten mutants before it were
KILLED. That guard runs the main pass against a server started with the CSRF switch off, and expectscontract.shto refuse it (exit 5, the target guard); exit 4 is the server never coming up, so there was nothing to refuse and the line reads as a guard that does not work.gatewas red with it. Re-running the failed jobs passed (mutantsin 3m16s) on the same tree.Same observation as above: CI uploads no server log for
mutants, so the cause of this one is unseen too. It also shows the issue's point about labels from another side: a server that never started reads as a surviving mutant in the other rows, and here as a guard that did not refuse.fix(contract): draw test ports from below the kernel's outgoing-conne…
aRustyDev commentedon Nov 16, 2026
Hypothesis 2 is confirmed, and #224 (merged as a243dcf) fixes it.
What the failures were
mutantsfailed on 3 of the 4 fullciruns onmainbefore the fix:It also failed on pull requests, for example 43814088649 on #216. In every one of those jobs, the
show_whyoutput of the row that was not killed shows the target's own bind being refused:The scheduled run also had
could not start the mail server, which fits the same cause: adocker run -pon a port taken the same way.The mechanism, reproduced
pick_portdrew from 20000-49999. It accepted a port whenlsof -sTCP:LISTENshowed nothing on it. 57% of that range is inside Linux's outgoing-connection range,ip_local_port_range, which is 32768-60999 by default.A client connection that closes first keeps its local port in TIME_WAIT for 60 s.
lsof -sTCP:LISTENdoes not list that socket. The client did not set SO_REUSEADDR, so a later bind to that port fails with EADDRINUSE even with SO_REUSEADDR set, which is what tokio'sTcpListener::binddoes. Nothing is listening on the port at that point.I reproduced this in
ubuntu:24.04(range 32768-60999). The harness opened and closed 3000 client connections against a local listener, closing from the client side, then:lsof -sTCP:LISTENcalls them freepick_port, 1000 draws under repeated churn, then a bindpick_port, 1000 draws interleaved with those, then a bindA
mutantsjob starts the server about 45 times, alongside thousands of short connections from the suite, the health-check curls and cargo, so it builds up exactly this state. The build that runs between the pick and the bind widens the window. macOS starts its range at 49152, which is why local runs almost never collided.Hypothesis 1, the window between the pick and the bind, is part of the same story. It is only harmful because the drawn port can be held by a client socket that
lsofcannot see.The fix (#224)
scripts/lib/ports.shdraws from 20000 up to just below the kernel's outgoing range: 20000-32767 on Linux and 20000-49151 on macOS.readgets a single byte from procfs.contract.shuses it for every port: the target, the mock IdP, Postgres, Mailpit and the delay proxy. It also:ssfor the port;docker run, prints Docker's own error..github/scripts/tests/test-ports.shruns inci-scripts. 13 hand mutants of the library and 3 of the wiring each fail it under dash.docs/src/testing/status.md.On the runner, the
native-memory maincell now printsports drawn from 20000-32767 (the kernel's outgoing range starts at 32768).Runs after the fix
On #224's run 43944208486, I reran only the
mutantsjob, 8 times in a row:That is 9 clean jobs and about 400 server starts. At the rate before the fix, roughly 1 start in 90, a run that long with no failure would happen by chance about 1 time in 100.
Against the acceptance criteria
show_why(feat(email): an SMTP adapter, and the native server sends the reset mail when it has a relay #176). fix(contract): draw test ports from below the kernel's outgoing-connection range #224 addsssfor the refused port and Docker's error for the containers.mutantssummary still reports a row whose server never started asSURVIVED or did not run. fix(contract): draw test ports from below the kernel's outgoing-connection range #224 does not change that.flake-huntonworker-cf mainandworker-cf bindingshas not been run since the fix. It is the next step.🤖 Generated with Claude Code
aRustyDev commentedon Nov 16, 2026
Both flake-hunt runs were clean after #224: 30 iterations each, on
mainat 3beb018, which contains a243dcf.ports drawn from 20000-32767Address already in useworker-cf main, 43968248519failures: 0 / 30worker-cf bindings, 43968253482failures: 0 / 30The counts come from each run's artifact (
flake-hunt-worker-cf-<pass>, all 30 iteration logs), not from the job's status alone, so every iteration reached its tests. All iterations of a hunt share one runner, which makes the hunt harder on ports than a fresh CI cell: closed connections pile up in TIME_WAIT across iterations, as they did inmutants.Acceptance criteria now:
show_why; fix(contract): draw test ports from below the kernel's outgoing-connection range #224 addsssand Docker's error).mutantssummary still reports a row whose server never started asSURVIVED or did not run. This is the one item left open.flake-huntonworker-cf mainandworker-cf bindings(above), and repeatedmutantsruns (9 clean jobs, earlier comment): no exit-4 failures.🤖 Generated with Claude Code
fix(mutants): tell a row that did not run from one that survived (#248)
aRustyDev commentedon Nov 17, 2026
Closing: every acceptance criterion is met. The port collisions are fixed by #224 (cause shown and recorded as D-20, then 9 clean mutants jobs and two clean 30-iteration flake hunts), and #248 (57f06d4) reports a row that did not run as DID NOT RUN, separately from a real SURVIVED (D-21).
test: run the adapter suites on nextest, so only the doctests stay on…
fix(contract): a run never draws the same port twice, and a refused b…