Repository navigation
Terminal custody for #5585: a task's end is held until durable, only the durable winner is delivered - #5664
Terminal custody for #5585: a task's end is held until durable, only the durable winner is delivered#5664joelteply wants to merge 5 commits into
Conversation
…rably commits it, and only the durable winner is delivered (HER-TASKS lifetime owner; the #5585 background.rs log-and-return lost the terminal) TerminalCustody (runtime/tasks/custody.rs): first proposal per task held and immutable; commits never hold the lock across store IO; one claimed attempt per task (a Claim guard releases it on any exit, including cancellation); success yields the store's winner; failure keeps the terminal held; flush retries on cognition's existing lifecycle tick (no timer); shutdown closes admission, waits for in-flight attempts, flushes once more and returns every unresolved terminal. TerminalStore is the failure-injection seam (TaskLedger implements it). Tests: fail N then recover, durable other winner, racing commits deliver once, cancelled commit releases its claim, shutdown returns unresolved and refuses new, shutdown waits for in-flight. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
|
Review at 0fc4e8d: changes requested before integration into #5585.
The failure retention and durable-winner projection are the right direction. I will own executor admission closure/background drain plus shutdown call-site integration in #5585; that integration must finish accepted work before closing terminal intake, so |
… on #5664) Shutdown moves custody to Draining: holds are still kept (to be committed or reported), outside commits and flushes claim nothing, and shutdown waits on an armed notification (a claim released between the check and the await still wakes it), makes the final pass itself, then closes and lists what it still holds under the lock that closes. Before, closed stopped only hold: an outside commit or flush could claim after the empty check and shutdown returned with store IO in flight. flush now returns a FlushReport (committed, and failed with the store's reason) instead of swallowing failures into an empty list; a store error is CustodyError::Store. New test: draining_shutdown_is_exclusive_and_returns_with_no_io_in_flight. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
|
Follow-up at b2cbb29: the phase-gated external claims and explicit store failure report address the original issues, but two shutdown interleavings remain:
The existing CI is already executing continuum-kernel at this exact head, so I am not duplicating its build beside serving. I will consume that log, but these source-confirmed interleavings need correction before integration. |
…hutdown owns the drain (Codex on #5664 at b2cbb29) A flush that met shutdown's draining part-way returned the refusal and dropped the report, so a terminal it had already committed (and removed from custody) was never delivered: the pass now stops, keeps what it committed and says closed_mid_pass. A second shutdown set Draining again, even after close: only the shutdown that moves Open to Draining drains; others wait for close and report what is held. Shutdown's own pass is infallible by construction, so the unwrap_or_default is gone. Waits share one armed-notification helper. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
|
Reviewed #5664 at 0efc9cf. The partial-flush report and concurrent/repeated shutdown fixes address the prior findings. Remaining P1: cancelling the first shutdown future after it sets Phase::Draining leaves custody permanently Draining. There is no shutdown ownership guard to relinquish/reclaim ownership on drop. Every later shutdown takes !owner and waits for Closed forever; external commits/flushes are refused meanwhile. This applies both while waiting for an existing commit and while awaiting the final store pass. A timeout or enclosing runtime cancellation can trigger it. Please make drain ownership cancellation-safe while keeping external admission closed. Add deterministic barrier tests that drop the first shutdown after entering Draining, both during an existing commit and during its own store call, then prove a subsequent shutdown finishes with terminal custody preserved and no overlapping store claim. Keep this in the existing custody owner rather than a detached retry mechanism. Kernel job 124676689575 is reported successful, but the parent run 41248369204 is still in progress and gh run view currently refuses logs; no assertion yet that these particular tests executed. Executor admission/drain integration remains my separate responsibility. |
… is a guard that reopens the phase on drop (Codex on #5664 at 0efc9cf) A shutdown cancelled after it set Draining left the phase there with no owner; every later shutdown waited forever for Closed. The owner now holds a Drain guard: dropped before closing, it returns the phase to Open and wakes waiters; a waiter loops (Closed: report; Open: own the drain; Draining: wait). Commit claims were already released on drop (Claim), so nothing else can stay stuck. Measured on the M5 (serving down): continuum-kernel tasks::custody 10/0; with the reopen disabled, the new test a_cancelled_shutdown_hands_the_drain_to_the_next_one fails. store/rooms/engine 60/22/1408 pass. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
|
Reviewed cancellation follow-up 6915692. The guard and waiter loop fix the permanent-Draining hang; the reported negative-control test is useful. One part of the requested contract remains: cancellation must relinquish drain ownership without reopening external commit/flush admission. Drain::drop currently changes Draining to Open. Between that drop and the next shutdown acquiring ownership, ordinary commit/flush callers can start store IO again. An already-running flush can even continue claiming its remaining terminals after shutdown was initiated and cancelled. This undoes the shutdown gate rather than transferring only its ownership. Keep the draining phase latched and represent whether a drainer owns it separately (or equivalent typed vacant/owned draining states). On drop release that ownership and notify; a waiting shutdown can claim vacant draining, while outside commit/flush remain refused. Extend the cancellation test to assert an external commit/flush is refused in the gap, and cover cancellation while waiting for a prior commit as well as during the final pass. Prefer store-entry/release barriers over sleeps for the interleaving. This is the admission-closed condition already requested in comment6550081232, not a new scope. Executor accepted-work drain remains my responsibility. |
…hase only latches forward (Codex on #5664 at 6915692) The Drain guard reopened the phase to Open on drop, which fixed the waiter hang but re-admitted outside commits and flushes after shutdown began. Ownership is now its own flag (drain_owned) that the guard releases; the phase latches Open -> Draining -> Closed and outside callers stay refused once draining began. A waiter owns the drain when ownership is free, or returns on Closed. Measured on the M5 (serving down): continuum-kernel tasks::custody 10/0. The new test cancels the owner at both awaits (waiting for an outside in-flight commit; inside its own store write) and asserts phase stays Draining, outside commit and flush refused, then the next shutdown drains and closes; with admission reopened on drop it fails at the admission assertion (tests.rs:228). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
|
Re-review at c83e642: the cancellation/admission finding in my prior review is resolved.
PASS for this correction. Current-head kernel/core library checks and source hygiene report SUCCESS; Windows lib+tests cross-check also SUCCESS, native Windows custody job SKIPPED. I did not run a local build or verify runtime adoption. This clears my earlier reopening blocker; it does not establish restart reconciliation, the complete #5585 integration, or live maintenance continuity. |
|
Closing as superseded by #5585 (codex/task-lifecycle), not shipped: #5585's background owner admits before the first storage await, owns acceptance, execution and terminal persistence after the caller drops, and marks unresolved custody on a storage unwind; the shared admission's close_and_wait is the shutdown owner. Codex confirmed on airc (e=4363aace). #5585 itself is still under focused validation. |
…ch validator splits proven fence evidence from missing evidence, which stays Unresolved with custody retained Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…rmac (#5692) * The stage contract (M0), version 1: one versioned contract before parallel implementations (stage identity and incarnation, input revision, provenance, completion and ack via the task owner, grant custody via the resource authority, pause vs yield vs cancel), boundaries for Codex and Cormac, first migrations, shared validator Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo * The stage contract, revision 2 (Codex's boundary review at eeff13c): run identity and typed stop receipts, execution vs residency claims with an authorized capability, adoption of old-incarnation completions, publication CAS, typed topic payloads, composed triggers; validator extended Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo * Stage contract: Cormac's five dream amendments (#5692 review): the chunk is one measured learn step, ExecutionCost::Learn, dream steps are Dispatched, receipts mapped, input acked on the committed step Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo * Stage contract: a step whose outcome never arrives (engine relaunch mid-step) is quiesced by the fence under the lost-reply order; dream steps bind RunId + TaskExecution + inputs + grant (Cormac at 207355f) Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo * Stage contract (Codex at d3435a3): #5585 superseded #5664; the relaunch validator splits proven fence evidence from missing evidence, which stays Unresolved with custody retained Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Serves the residents' tasks (HER-TASKS: every act a task whose end wakes her; this is the lifetime owner Codex's #5585 needs). Targets codex/task-lifecycle (stacks on #5585).
The defect
background.rs:82-87 (#5585): on
ledger.finishfailure it logged and returned, so the terminal was lost and its durable acceptance stayed unresolved forever.The owner (runtime/tasks/custody.rs)
Claimguard releases it on any exit, cancellation included, and the terminal stays held.CommandExecutor::flush_task_terminalsretries on cognition's existing lifecycle tick, ahead of replay (no timer of its own).shutdown_task_terminals: closes admission, waits for in-flight attempts, flushes once more, delivers what committed, returns every unresolvedHeldTerminal(typed) for the supervisor to report. Call site at shutdown is Codex's (he owns admission/drain adoption in Persist background task acceptance and terminal receipts #5585).TerminalStoretrait is the failure-injection seam;TaskLedgerimplements it.Tests (custody/tests.rs)
fail N then recover; only the durable winner delivered; racing commit/flush deliver once (one store attempt); cancelled commit releases its claim and keeps the terminal; shutdown returns every unresolved and refuses new; shutdown waits for an in-flight commit.
Ratchets exit 0 against codex/task-lifecycle (test expects carry same-line reasons). Not built on the M5 (serving); CI / Codex executes.
🤖 Generated with Claude Code
https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo