Expand description
Phase 4.D decay job runner.
§Contract
- Atomic: the
Pending -> InProgressclaim and theInProgress -> Completed | Failedsettle happen viaDecayJobRepo::update_statecalls. The substrate refuses no-op updates (no matching row → hard error), so a stale claim surfaces rather than silently dropping. The substrate does NOT today CAS on prior state; the runner protects against double-claim by only proceeding when it has just observedPending(loaded then immediately transitioned). - Idempotent: re-running a terminal (
Completed,Failed,Cancelled) job is a no-op (run_specific_jobreturns Ok without re-dispatching). The Pending surface (run_next_pending_job) returnsOk(None)when the queue is empty. - Fail-closed: any error inside the dispatched method transitions
the job to
Failedwith the error’s stable invariant (when one exists) or itsDisplaytext otherwise. The runner never leaves a job stuck inInProgresson a normal error path. - Observable: every stage emits a diagnostic line on stderr under
a stable prefix (
cortex_memory::decay::runner) so operators can tail logs without parsing JSON envelopes.
§Why “now” is a parameter
The runner takes an explicit now: DateTime<Utc> for the scheduling
window. The CLI and dispatcher both pass Utc::now() in production;
tests pass a frozen timestamp so the pending-pickup query is
deterministic.
Functions§
- run_
next_ pending_ job - Run the next pending decay job whose
scheduled_for <= now, if any. - run_
next_ pending_ job_ with_ attestation - Variant of
run_next_pending_jobthat allows the caller to supply an operator-attestation path for the next-pending LLM-summary job. The dequeue path itself does not select on summary method, so the attestation is only consumed if the next picked job turns out to be an LLM-summary job; deterministic jobs ignore it. - run_
specific_ job - Run a specific decay job by id.
- run_
specific_ job_ with_ attestation - Variant of
run_specific_jobthat allows the caller to supply an operator-attestation path for the dispatched job. Required when the resolved job is an LLM-summary job; deterministic jobs ignore it.