Skip to content

test: exercise the EOWNERDEAD report and soak preemption for real - #27

Merged
lisachenko merged 3 commits into
mainfrom
claude/issue-20-eownerdead-and-preemption-soak
Aug 16, 2026
Merged

lisachenko merged 3 commits into
mainfrom
claude/issue-20-eownerdead-and-preemption-soak

Conversation

@lisachenko

Copy link
Copy Markdown
Owner

Closes #20.

1. The EOWNERDEAD reporting branch now runs

testAWorkerKilledHoldingAnArenaLockFailsItsWaiter kills a worker on a consumer stripe — a lock nothing in bury() ever takes, and stripe recovery is tracked nowhere SharedArena::lockRecovered() can consult — so the supervisor recovered nothing and the crash read "killed by signal 9". The issue's own framing ("the parent attempts the stripe before burying") cannot reach the branch either, for the same reason; the ordering in bury() was right all along, the lock was wrong.

The new testAWorkerKilledInsideACriticalSectionReportsTheRecoveredLock kills the worker inside the one critical section the supervisor itself enters on the way to the grave — the result-slot table's mutex, which every refresh() takes, and which is exactly the lock a worker dying mid-settle() would hand on. The parent's own refresh() inherits it as EOWNERDEAD and the waiter's WorkerCrashedException says the lock was recovered.

Sequencing is race-free, not timing-based: a non-blocking tryLock poll waits until the worker is demonstrably inside the section (blocking there would wedge the parent on a mutex a live worker holds), then SIGKILL, then no further touch of the mutex — so the first taker after the death is the supervisor. Branch-taken was proven by mutation: forcing the condition false in bury() flips the expected output back to "killed by signal 9".

No production change. The helper that locates the slot-table mutex lives in tests/Support, reads the header word the substrate documents (capacity | next slot | mutex address | reserved), and turns a future layout change into a named LogicException via an Arena::contains() guard rather than a lock taken on foreign bytes. A public accessor upstream would be the clean long-term shape — noted for the substrate.

2. tools/soak-preemption.php

The longest continuous preemptive run anywhere in the repo was ~4.3 s / ~430 preemptions. A local 30 s run of the new soak does 3022 preemptions with flat memory, every burner's arithmetic matching an uninterrupted reference of the same computation, and no fiber left parked in the interrupt callback. Workload mix: call-free arithmetic burners (the hard case — no cooperative point), channel/timer parkers, and socket-pair IO through the poller.

Every detector has been seen to fail: --self-test (one burner's sum off by one → arithmetic FAIL), --inject-leak (retained block per round → memory FAIL), a dropped fiber (fibers LEAKED), and a mid-run fatal (the shutdown guard fails the run before its own verdict). Exit codes match the other soaks — and a run that was never preempted exits 2 (inconclusive), so a runner where preemption silently stopped working cannot pass quietly.

3. CI gains a bounded preemption-soak job

20 s per minor (~26 s wall), timeout-minutes: 5, matrix 8.4/8.5. It is the one soak worth a runner: its subject needs thousands of slices and the suite only ever buys hundreds. AGENTS.md and README.md are updated so the "CI runs tests and static-analysis only" line stays truthful.

Acceptance criteria from #20

  • ☑ A worker killed inside an arena critical section produces a WorkerCrashedException whose message reflects lock recovery, with the EOWNERDEAD branch actually taken (mutation-verified).
  • ☑ A preemption soak runs sustained with many concurrent coroutines and real IO, asserting memory flat, no fatal, no fiber leak, arithmetic correct throughout.
  • ☑ It can produce its own failure on demand (--self-test / --inject-leak), both demonstrated.
  • ☑ Runs on both minors — via the new CI job.

Verification

PHP 8.4.19, -d ffi.enable=1 -d opcache.jit=off: full suite OK (99 tests, 99 assertions), PHPStan level max clean (the two level-max findings the new tool initially raised were fixed properly, no baseline), cs:check clean. PHP 8.5 is not verifiable locally (the vendor tree resolves the 8.4 z-engine line); CI covers it, including the new soak job.

🤖 Generated with Claude Code

https://claude.ai/code/session_01U5QRWPfmkZME7hDjU6i5EA


Generated by Claude Code

lisachenko and others added 3 commits August 16, 2026 09:02
…ot lock

testAWorkerKilledHoldingAnArenaLockFailsItsWaiter proves the waiter fails
rather than hangs, but the worker there dies on a consumer stripe — a lock
nothing in bury() ever takes. The supervisor therefore recovers nothing,
lockRecovered() answers false and the crash reads "killed by signal 9": the
EOWNERDEAD reporting branch has never run.

The lock the supervisor really depends on is the result-slot table's, which
every refresh() takes and which a worker dying mid-settle() would genuinely
hand on. HoldResultSlotLockTask dies inside exactly that critical section, so
the parent's own refresh() inherits the mutex as EOWNERDEAD and the waiter
receives the crash that says the lock was recovered.

The parent waits for the worker to be inside the section with a non-blocking
tryLock poll — blocking there would wedge the process on a mutex a live worker
holds — and then never touches the mutex again, so the first taker after the
kill is the supervisor. Proven branch-taken by mutation: forcing the condition
to false turns the expected message back into "killed by signal 9".

No production change: bury() already refreshes the slots before consulting
lockRecovered(), so the ordering was right all along; only the lock the test
chose was the wrong one.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5QRWPfmkZME7hDjU6i5EA
The longest continuous preemptive run anywhere in this repository was a few
hundred slices in a single fiber. The failures preemption is prone to do not
appear at that length: a resume that loses a partial result is arithmetic that
is quietly wrong, and a preempted fiber that is never drained is a fatal error
at request shutdown, which is not an exception anything can catch.

tools/soak-preemption.php runs one preemptive runtime for --seconds=N with a
mix that keeps the slice timer busy: call-free arithmetic burners (nothing in
them ever reaches a cooperative suspension point), parkers on the timer heap
and on a rendezvous channel, and real socket-pair IO through the poller. Every
burner result is compared, every round, against the same function run
uninterrupted before the run started, so a wrong answer is caught in the round
it happens in. Memory is judged by the warmup-then-trend rule the other soaks
use, coroutines are counted spawned against finished with the interrupt
callback drained at the end, and a shutdown guard makes a process that dies
before its own verdict say so instead of ending on a round line.

Both detectors have been seen to fail: --self-test corrupts one burner's sum by
a single unit and --inject-leak retains a block per round. A local 30 s run does
3022 preemptions with flat memory and no wrong answer.

CI gains a bounded preemption-soak job, 20 s on each minor — the one soak worth
a runner, because the property it checks needs thousands of slices and the
suite only ever buys hundreds.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5QRWPfmkZME7hDjU6i5EA
… surface

arena() and supervisor() are deliberately absent from TaskRuntime — the
surface guard test pins that — so the new critical-section test reads
them off the concrete Runtime captured by the closure, the same way the
panic-surface test does, instead of reaching through the interface-typed
parameter to methods it does not declare.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5QRWPfmkZME7hDjU6i5EA
@lisachenko
lisachenko marked this pull request as ready for review August 16, 2026 09:23
@lisachenko
lisachenko merged commit 28b7066 into main Aug 16, 2026
6 checks passed
@lisachenko
lisachenko deleted the claude/issue-20-eownerdead-and-preemption-soak branch August 16, 2026 09:24
lisachenko pushed a commit that referenced this pull request Aug 16, 2026
Unifies this branch's shared-record recycling with #29's local-view claim
counting, which landed while this was in flight and solved the other half of the
same lifecycle. #27 and #28 merged through with two expectation updates.

## One counter, two lifecycles

#29 counted claims to decide when to drop a slot's LOCAL VIEW; this branch counted
handles to decide when to give the SHARED RECORD back. Two mechanisms measuring the
same thing. They are now one - `ResultSlot::$claims`, #29's name kept - and
`forgetIfSettled()` is where the single decision fans out:

  claims == 0 && complete && no waiters
      -> the local view is dropped, ALWAYS, whatever this process's role
      -> the shared record goes back only if $owned && $sharedSettled

The distinction is the point. The view is per-process bookkeeping and its only cost
is memory; the record is family-wide state and giving it back is a claim that
nobody will read it through this ticket again. An adopter drops its view and
releases nothing. A slot whose worker died drops its view and keeps its record out
of circulation, because the record is still pending in shared memory where a zombie
may yet write to it.

`JoinHandle` now gives its one claim back at the FIRST of two moments - awaited, or
collected - guarded by `relinquish()` so the pair can never count as two. Awaiting
releases at once, which is stronger than #29's release-at-collection: a batch that
spawns N and awaits them in a loop is down to one live slot by the end of the loop
rather than N until the handles array dies. The destructor still carries the case
it was added for, a handle nobody awaits.

## The decision #29 could not have had to make

A settled, never-awaited handle now recycles its shared record and DISCARDS the
answer. The alternative - keep it until teardown - is the exhaustion bug itself for
fire-and-forget code, which is a real pattern. Nothing is silently misled by the
choice, because a sibling holding the id gets a generation refusal rather than the
next task's result. A handle dropped while its task is still PENDING keeps the slot
until it settles, so overrunning the table with in-flight work is still the same
typed refusal it always was. Verified: 300 paced fire-and-forget spawns run on a
one-record table, and 50 unpaced spawns on a four-slot table are refused cleanly.

## A real bug the merge produced, caught by main's suite

#29 made `settle()` end with `forgetIfSettled()`; this branch made `adopt()` settle
eagerly so a stale ticket is refused at attach time. Together, `adopt()` of an
already-settled slot forgot the view before the caller's claim was counted, and
`await()` then failed with OutOfBounds - `testAPanicWhoseDetailCannotBeAttached`
caught it. `adopt()` now claims BEFORE it settles, with the ordering written down.

## Conflicts

- `src/Parallel/SlotTable.php` - seven regions, resolved as above.
- `AGENTS.md` - both sides appended slot bullets and both edited the soak table.
  Kept both, rewritten around the two-lifetimes framing, and #27's preemption-soak
  row and self-test paragraph merged with this branch's `--leak-slots`.
- `JoinHandle`/`ResultSlot`/`README` auto-merged and were then reconciled by hand;
  the README's slot-budget table had claimed a never-awaited handle holds its slot
  for the rest of the run, which is no longer true.

`tools/soak-arena-watermark.php` did not conflict - main never touched it - and its
RSS verdict now passes for the two reasons #24 fixed plus this branch's own pruning.

## Expectation updates

- `testACompletedResultSlotIsNotRetainedByItsWaiter.phpt`: "views after await,
  handle still held" is 0 rather than 1, because awaiting now releases immediately.
  Its subject is untouched, and the destructor path it also covered moves to a new
  test rather than being dropped.
- `testAWorkerKilledInsideACriticalSectionReportsTheRecoveredLock.phpt`: a lost slot
  is named `#0/gen1`, since an arena slot id carries its generation now.
- New `testAnUnawaitedHandleGivesItsSlotBackWhenItIsCollected.phpt` pins the
  destructor path on a ONE-slot table, where a second spawn can only be allocated if
  the dropped handle's record really came back.

Suite: 108 tests OK on PHP 8.4, against substrate main merged into this branch's
substrate counterpart. phpstan level max clean, cs:check clean. All four soaks PASS
(arena-watermark, memory-flatness, no-leftover-children, preemption), and both
arena-watermark detectors still FAIL on demand.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U5QRWPfmkZME7hDjU6i5EA
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.

Coverage gaps: the EOWNERDEAD branch and preemption under long-run soak

1 participant