Repository navigation
feat(ledger): claim leases and a reaper for dead workers (D145) - #529
Conversation
…tional Address Codex round 1 on #529: the worker loop now checks the reaper interval between tasks of a long drain; record_call takes the claimed attempt and refuses a call from an attempt that no longer holds the row, so a late call can never land on (and deduplicate) a newer attempt's calls; the renewal test sweeps after the first lease expired. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
Codex review round 1 (gpt-6.1-sol, max)VERDICT: REQUEST_CHANGES
All 33 focused tests passed, including the SIGKILL test. The populated migration downgrade/re-upgrade, expired backfill, and CHECK validation also passed. Completion and failure variants pass the claimed attempt; I found no missing guards there. No reuse identities changed. Files were not modified. |
Dispositions for Codex round 1 (fixed in f44dab8)
|
Codex review round 2 (gpt-6.1-sol, max)VERDICT: APPROVE No new blocker, major, or minor findings. All three round‑1 fixes are verified, and the implementation agrees with D144 and the updated designs/docs. Validation: 59 focused tests passed, including SIGKILL recovery. Populated migration upgrade/downgrade checks, selected D56/D140 reuse checks, and lint also passed. No files modified. |
…tional Address Codex round 1 on #529: the worker loop now checks the reaper interval between tasks of a long drain; record_call takes the claimed attempt and refuses a call from an attempt that no longer holds the row, so a late call can never land on (and deduplicate) a newer attempt's calls; the renewal test sweeps after the first lease expired. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
a567879 to
edf945f
Compare
|
Rebased onto main 93bf659 (library seams #531, per-database upgrades #532). The only conflict was the end of decisions.md; D144 is now the library-seams decision, so this PR's decision is renumbered D145 (all references, anchors and the catalog-contract key updated). Code merged cleanly: the new named claim (_CLAIM_SELECT_NAMED) shares _CLAIM_START, so run_task claims get a lease too. Codex-approved content is otherwise unchanged. Local: claim-lease, work-ledger, selfhost-queue, telemetry, profiles (incl. two-deployment contexts) and operations tests pass; full workers+spine suite passed before the rebase (1031 passed, 2 xfailed). |
…tional Address Codex round 1 on #529: the worker loop now checks the reaper interval between tasks of a long drain; record_call takes the claimed attempt and refuses a call from an attempt that no longer holds the row, so a late call can never land on (and deduplicate) a newer attempt's calls; the renewal test sweeps after the first lease expired. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
edf945f to
4efd3ff
Compare
…tional Address Codex round 1 on #529: the worker loop now checks the reaper interval between tasks of a long drain; record_call takes the claimed attempt and refuses a call from an attempt that no longer holds the row, so a late call can never land on (and deduplicate) a newer attempt's calls; the renewal test sweeps after the first lease expired. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
4efd3ff to
68d50ef
Compare
|
Final decision numbering from the orchestrator: this PR is D145 (library seams D147 on main; D144 stays unused). References updated; no code change. |
A claim now records lease_until; the worker renews it every third of the lease while the handler runs. Renewal, complete and fail are conditional on the claimed attempt, so a worker whose claim was taken back discards its result (lease_lost) instead of finishing a newer attempt. Each worker loop sweeps its stages for expired running rows: rows with attempts left return to pending and are announced; rows at max_attempts are dead-lettered and finalized. Includes a kill-mid-task test (SIGKILL inside the handler). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
…tional Address Codex round 1 on #529: the worker loop now checks the reaper interval between tasks of a long drain; record_call takes the claimed attempt and refuses a call from an attempt that no longer holds the row, so a late call can never land on (and deduplicate) a newer attempt's calls; the renewal test sweeps after the first lease expired. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
…eams) merged Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
…0063 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm
05d46a2 to
72b49f7
Compare
|
Rebased onto main b64a1a2 (#537). #537 added its own |
Relaunch plan phase 2 item (a): claim leases and a reaper (UMC
design/plan/relaunch-shared-runtime.mdphase 2a; reasoning in the UMC relaunch analysis §3 item 3).What changes
claim_onesetsprocessing_state.lease_until = now() + lease_s(REMEMBERSTACK_WORK_LEASE_S, default 60 s). The claimed attempt number identifies the claim.Worker.run_onerenews the lease from a background thread everylease_s / 3while the handler runs (_LeaseRenewal). A refused renewal stops renewing and is logged.renew_lease,complete, everycomplete_*barrier variant andfailnow takeattemptand matchstatus = 'running' AND attempts = :attempt. A worker whose attempt no longer matches discards its result and returns the newRunResultOutcome.LEASE_LOST(also exported onworker.run).WorkLedger.reap_expired_leases(deployment_id, stages)moves expiredrunningrows on those stages topending(due now,last_error = 'lease expired: …'), or todead_letteronceattempts >= max_attempts(claiming requiresattempts < max_attempts).Worker.reap_expired_leasesruns it for the worker's registered stages, announces requeued rows through the queue port and runs the terminal-failure finalizer for dead-lettered ones.SelfHostWorkerLoop.drain_duecalls it at most once per fallback-poll interval.p9_43_0064. Addslease_until, arunning ⇒ lease_until IS NOT NULLCHECK, andix_procstate_running_lease. Rows alreadyrunningget an expired lease, so the first sweep recovers anything a killed worker left behind today.REMEMBERSTACK_WORK_LEASE_S), operating (what happens when a worker dies mid-item), observability (lease_lost).Cost recording is attempt-conditional too:
RecordCallcarries the claimed attempt andrecord_callrefuses a call from an attempt that no longer holds the row, so a late call cannot land on (and deduplicate) a newer attempt's calls.Tests
src/tests/workers/test_claim_leases.py(real Postgres):lease_lost;Local runs (Postgres 19beta3 image from
Dockerfile.postgres): the new file,test_work_ledger.py,test_selfhost_queue.py,test_backfill.py,test_operations.py,test_d122_selection.py,test_migrations.py; ruff, ruff format, pyright, lint-imports, test inventory, docs truth check.Rule 4 (D56)
No ingestion keyed input, chunking, extraction or reuse identity changes. Only claim bookkeeping on
processing_state.🤖 Generated with Claude Code
https://claude.ai/code/session_01F9cMsQBqiW2qU2ow4zeNCm