Skip to content

fix(contract_test): restore supervised children unconditionally - #688

Merged
hyperpolymath merged 4 commits into
mainfrom
fix/contract-test-supervisor-restore
Aug 7, 2026
Merged

hyperpolymath merged 4 commits into
mainfrom
fix/contract-test-supervisor-restore

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

take_supervised/1 registered its on_exit restore after start_supervised!/1. If that raised, the child had already been terminated and deleted from Hypatia.Supervisor and was never restored — and there is no restart_child call anywhere in the repo. Every later test needing that module then failed with "no process: the process is not alive".

This exact bug was already diagnosed and fixed — in one file

test/reflexive_test.exs carries the correction and a comment describing the same cascade:

"the child was deleted from Hypatia.Supervisor and NEVER restored. Every later test needing that module then failed too, which is why one root failure cascaded into ~20 and why the failing set changed with the seed."

contract_test.exs was missed. This applies the same pattern, plus an idempotent restore_supervised/1 that raises on an unexpected result rather than discarding it — a silent restore failure is what made the original cascade invisible.

⚠ This is a partial fix, and the number barely moves

75 failures before, 74 after. More importantly, the suite is not deterministic even at a fixed seed — three runs at --seed 0 gave 75, 82 and 74, with different failing sets each time.

Seed control cannot help, because the variance isn't from test ordering: these tests manipulate the live application supervisor, so they share globally-named processes and their outcome depends on process state and timing.

That is the foundational problem and it is architectural — tests should start isolated instances rather than taking children away from the running Application. Until then this repo's CI cannot distinguish a good PR from a bad one: it currently fails on every PR, including ones touching no Elixir at all.

🤖 Generated with Claude Code

`take_supervised/1` registered its `on_exit` restore AFTER calling
`start_supervised!/1`. If that call raised — or anything between the delete and
the registration failed — the child had already been terminated and deleted
from Hypatia.Supervisor and was NEVER restored.

`Supervisor.terminate_child/2` keeps a child dead until something explicitly
restarts it, and there is no `restart_child` call anywhere in this repository.
So every later test needing that module also failed, with

    ** (exit) exited in: GenServer.call(Hypatia.Neural.Blackboard, :clear, 5000)
        ** (EXIT) no process: the process is not alive

⚠ THIS EXACT BUG WAS ALREADY DIAGNOSED AND FIXED — IN ONE FILE.
test/reflexive_test.exs carries the correction and a comment describing the
same cascade: "the child was deleted from Hypatia.Supervisor and NEVER
restored. Every later test needing that module then failed too, which is why
one root failure cascaded into ~20 and why the failing set changed with the
seed." contract_test.exs was missed.

on_exit callbacks still run when setup raises, so registering first makes the
restore unconditional. `restore_supervised/1` is idempotent and RAISES on an
unexpected result rather than discarding it — a silent restore failure is what
made the original cascade invisible.

⚠ THIS IS A PARTIAL FIX, AND THE HEADLINE NUMBER BARELY MOVES: 75 failures
before, 74 after. The suite is NOT DETERMINISTIC EVEN AT A FIXED SEED — three
runs at `--seed 0` gave 75, 82 and 74, with different failing SETS each time.
Seed control cannot help, because the variance does not come from test ordering:
these tests manipulate the LIVE application supervisor, so they share global
named processes and their outcome depends on process state and timing.

That is the foundational problem, and it is architectural: tests should start
isolated instances rather than taking children away from the running
Application. Until then hypatia's CI cannot distinguish a good pull request
from a bad one — it currently fails on every PR, including ones that touch no
Elixir at all.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Jonathan D.A. Jewell <[email protected]>
@gitar-bot

This comment has been minimized.

@gitar-bot
gitar-bot Bot enabled auto-merge (squash) August 7, 2026 08:12
@gitar-bot gitar-bot Bot added the gitar-approved Added by Gitar label Aug 7, 2026
gitar-bot[bot]
gitar-bot Bot previously approved these changes Aug 7, 2026

@gitar-bot gitar-bot 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.

Gitar has auto-approved this PR and enabled auto-merge (configure)

This file tore GenServers out of Hypatia.Supervisor via a `take_supervised/1`
helper — `terminate_child/2` + `delete_child/2`, then a private instance.

It was never necessary. Every test here already isolates by KEY, not by
process: bot names, quarantine subjects and query keys are all built with
`unique_id()`, and the GenServers store state keyed by exactly those. The file
passes 19/19 with the helper removed entirely.

It was also actively harmful. `terminate_child/2` keeps a child dead until
something explicitly restarts it, and there is NO `restart_child` call anywhere
in this repository — so any failure between the delete and the restore left the
singleton dead for the rest of the run, and every later test touching it failed
with "no process: the process is not alive".

⚠ NO IMPROVEMENT FIGURE IS CLAIMED, DELIBERATELY. The full suite returns a
different failure count on IDENTICAL input: three consecutive runs at
`--seed 0` on this exact tree gave 77, 79 and 16. A before/after number from it
would be noise dressed as evidence. What is verifiable is that this file passes
on its own and that the helper's failure mode is gone by construction.

⚠ WHY THE PATTERN EXISTED, so it is not reintroduced. RateLimiter, Quarantine,
VCL.Client, Blackboard and SelfDiagnostics all hardcode

    GenServer.start_link(__MODULE__, opts, name: __MODULE__)

and IGNORE `opts[:name]`. A second instance therefore cannot coexist with the
supervised one, so taking the child away was the only way to get a fresh
process. If a future test genuinely needs a clean process rather than a clean
key, fix it there first — honour `opts[:name]` — and start an isolated instance
under the test supervisor. Do not mutate the application supervisor.

Supersedes #688, which made the same helper safer rather than removing it.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Jonathan D.A. Jewell <[email protected]>
…ile blind spot

OSSF Scorecard's Pinned-Dependencies check reads workflows for inline SHA refs
and cannot see .github/workflows/actions.lock, which is what actually pins this
repository's actions — resolving each symbolic ref to a verified commit plus the
transitive dependencies of composite actions.

Satisfying the check inline would reduce coverage rather than raise it:
gh actions-lock rejects a ref that no tag or branch contains, so inline pinning
drops actions from the lockfile. Measured 2026-08-07 on this repository — it put
14 workflows into startup_failure and removed dtolnay/rust-toolchain from 7
lockfile entries.

Recorded with the reasoning rather than fixed, because the finding is a
limitation of the external tool, not a defect here.
@hyperpolymath
hyperpolymath merged commit 8d6a52d into main Aug 7, 2026
61 of 87 checks passed
@hyperpolymath
hyperpolymath deleted the fix/contract-test-supervisor-restore branch August 7, 2026 09:45
hyperpolymath added a commit that referenced this pull request Aug 7, 2026
…ervision)

watcher.ex: supervisor child ids like Bandit's {module, make_ref()} were
inspect/1-ed into the Prometheus queue-depth label — a fresh
broke the exposition test's label parsing once the 30s queue poll had
fired (why it only failed in-suite). Ids now collapse to the module.

metrics_test.exs: byte-equality of two renders raced uptime_seconds'
1s granularity; the claim under test is that the plug serves render/0's
output, so the comparison now strips each line's sample value.

diagnostics/monitor.ex + config/test.exs: the monitor's 30s tick is now
config-gated and off in the test env — its recovery path GenServer.stops
supervised children mid-suite, the invisible order-dependence source
flagged in #643. check_now/0 still drives checks explicitly.

(The contract_test.exs half of this work was dropped on rebase: #688
landed a better fix upstream — it deleted take_supervised/1 outright,
since those tests already isolate by unique key rather than by process.)

Co-Authored-By: Claude Opus 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gitar-approved Added by Gitar

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant