Skip to content

feat(database): atomically reconcile expired startup runs - #320

Draft
sandersonstabo wants to merge 3 commits into
agent/database-startup-reconciliation-candidates-port-7a32019from
agent/database-startup-reconciliation-disposition-port-52642bf
Draft

feat(database): atomically reconcile expired startup runs#320
sandersonstabo wants to merge 3 commits into
agent/database-startup-reconciliation-candidates-port-7a32019from
agent/database-startup-reconciliation-disposition-port-52642bf

Conversation

@sandersonstabo

@sandersonstabo sandersonstabo commented Aug 29, 2026

Copy link
Copy Markdown
Collaborator

Depends on #318.

Atomically fences one expired startup-reconciliation candidate and records the honest unknown outcome: run interrupted with provider binding retained, dispatch failed, and turn/optional assistant item sealed with ordered lifecycle patches. Stale snapshots roll back as a typed skip; identical replay is harmless.

Checks: focused database build; 15 atomic disposition tests; fresh production/test Clippy aspects; root format; locked/offline Cargo metadata; exact hash/status guards; Bazel shutdown 0.

Excluded: storage opening, cross-process custody, provider contact, prompt retry, startup/backend wiring, requeue, and remote merging.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Summary by cubic

Atomically fences one expired startup-reconciliation candidate in a single transaction, recording the honest unknown outcome: run interrupted with provider binding retained, dispatch failed, and turn/optional assistant item sealed with ordered lifecycle patches. Stale snapshots roll back as a typed skip; an identical replay is harmless.

Included

  • Adds StartupReconciliationDisposition with typed outcome, receipt, and error types, registered in modules/database.
  • Adds 15 in-memory tests covering stale snapshots, idempotent replay, validation failures, and terminal/queued isolation.
  • Defers storage opening, cross-process custody, provider contact, prompt retry, startup wiring, requeue, and remote merging to later PRs.

Written for commit 1a5eff2. Summary will update on new commits.

Review in cubic

Adds fence-safe disposition for one expired E3 candidate: run->interrupted
(retains binding, clears owner/lease/claim, stores bounded error pair,
terminal_at NULL), dispatch->failed (clears lease, bounded reason),
turn/item ->interrupted with consecutive lifecycle patches and counter
advance. Full candidate-snapshot fences, SkippedMoved on zero-row,
idempotent replay detection, and typed validation for patch/item
agreement and counter/revision overflow. Single SeaORM transaction,
no storage/provider/requeue.

Includes in-memory tests for launching/no-item, running/with-item,
unexpired boundary, stale snapshots, idempotent replay, mismatched
input/duplicate patch/overflow, and terminal/queued isolation.

Owned paths: modules/database/src/repository/startup_reconciliation_disposition.rs,
tests/database/startup_reconciliation_disposition.rs

VP must register module and re-export + Cargo/Bazel entries.
- production: remove stored-but-never-read LoadedState fields
  next_renderer_ordinal/updated_at_ms and LoadedTurn fields
  thread_id/ordinal/lifecycle/created_at_ms/updated_at_ms; retain
  validation before context construction; fences unchanged.
- tests: remove unused OrdinalKind/RepositoryError, prefix unused
  claimed/receipt, combine identical bind arms, reduce
  commit_running_item to 4 args via RunningBatchFixtures, use
  sort_by_key, replace redundant closure with ItemId::as_str,
  replace len>=1 with !is_empty, add narrow allow for too_many_lines
  on two happy-path tests after helper extraction would obscure
  atomic assertions.

rustfmt 1.98, cargo test 15 passed, cargo clippy (test+lib) clean,
git diff --check clean. Owned paths only.
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