Skip to content

fix(runner): record a run for the life of its engine - #355

Merged
T-Crypt merged 1 commit into
mainfrom
T-Crypt/run-record-covers-the-run
Nov 20, 2026
Merged

T-Crypt merged 1 commit into
mainfrom
T-Crypt/run-record-covers-the-run

Conversation

@T-Crypt

@T-Crypt T-Crypt commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Addresses the overlapping whole-card grant in #354.

What changed

berth run and berth train write their record when the engine starts and keep it for the life of the engine, instead of writing it only after the wrapper notices the lost daemon.

  • The record drops its reason when the run re-attaches, and is removed when the child exits.
  • berthd treats every live record with no matching lease as due back during the restart window, so a wrapper that is stopped or slow to read EOF cannot hide a live engine.
  • A training record still holds with no timer. A keep-up record holds nothing, because that drain freed the card on purpose.
  • berth status still lists only records whose engine is unleased.

Why

In #354 the first runner was stopped, so it never read EOF and never wrote a record. The new daemon saw nothing, granted a second whole-card lease, and the first runner re-attached successfully afterwards, leaving two live leases on the card.

Proof

Four checks fail on the parent commit and pass here:

  • TestLiveRunHoldsTheCardUntilItReattaches
  • TestRecordForALeasedRunHoldsNothing
  • TestTrainingLocksTheCardUntilItReattaches, for a record with and without the lost reason
  • TestReattachAfterDaemonRestart, which now asserts the record exists before the daemon stops and is cleared after the re-attach

The full proof is green except the runner park tests, which this host also fails on the untouched base: memory pressure on aphotic is around 60 percent and the broker evicts parked engines above 10. With the pressure gate raised for the test daemon, the runner package passes.

Still open

A daemon that dies between the grant and the child start still has no durable trace, because no process exists yet. Closing that needs a grant record written by berthd, which is a separate change.

Refs #354.

A berthd that restarted while a pinned or training engine was alive could
grant a second whole-card lease. The runner wrote its record only after it
noticed the lost socket, so a run that was stopped, or slow to read EOF,
left the new daemon nothing to see, and it granted at once. #354 has the
reproducer.

The record now covers the whole life of the engine. It is written when the
child starts, rewritten with the reason when the daemon goes away, cleared
when the run re-attaches, and removed when the child exits. berthd counts
every live record it has no lease for as due back, so the card stays held
until the run re-attaches or the window closes. A training still holds with
no timer, and a keep-up record holds nothing because that drain freed the
card on purpose.

The new tests failed before the change: TestLiveRunHoldsTheCardUntilItReattaches,
TestRecordForALeasedRunHoldsNothing, the two-record table in
TestTrainingLocksTheCardUntilItReattaches, and the reattach e2e, which now
asserts the record before the daemon stops and its cleared state after the
re-attach.

One interval remains: a daemon that dies between the grant and the child
start. No process exists there for a runner record to describe, so closing
it needs a durable grant record in berthd.
@T-Crypt
T-Crypt force-pushed the T-Crypt/run-record-covers-the-run branch from f37bfc8 to 54425cd Compare November 20, 2026 20:55
@T-Crypt
T-Crypt merged commit 5ab7466 into main Nov 20, 2026
4 checks passed
@T-Crypt
T-Crypt deleted the T-Crypt/run-record-covers-the-run branch November 20, 2026 20:59
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