Repository navigation
fix(state): fence automatic agent database migrations - #133563
omarshahine merged 20 commits into
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
@clawsweeper review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. Reviewed August 31, 2026, 1:13 AM ET / 05:13 UTC. ClawSweeper reviewWhat this changesThe PR makes automatic historical transcript migration acquire and renew the existing stopped-writer lease only when a per-agent SQLite database needs mutation, with regression tests for no-op, expiry, and archive cases. Warning SQLite table change This PR modifies persisted SQLite tables in Regression provenancePossible regression — probable (reproduction; reviewed change). No predecessor PR is attributed. Merge readinessKeep this PR open: current main still has the unfenced synchronous migration path, while the introduced lease-bound path addresses the linked startup failure without a discrete correctness defect found in review. Its persistent-state authority change warrants the normal state-owner review before merge. Priority: P1 Review scores
Verification
How this fits togetherGateway startup scans per-agent SQLite databases for legacy transcript directives before reporting readiness. Mutating migrations use a shared-state maintenance lease so an active agent-database writer cannot race schema, transcript, archive, or cursor changes. flowchart LR
A[Gateway startup] --> B[Migration preflight]
B --> C{Database needs mutation?}
C -->|No| D[Leave writer and database untouched]
C -->|Yes| E[Acquire maintenance lease]
E --> F[Schema and transcript migration]
F --> G[Lease-checked commit or archive publish]
G --> H[Gateway readiness]
Decision needed
Why: The PR is a focused repair, but it changes the authority that protects persisted agent state across the shared-state and agent-database boundary. Before merge
Agent review detailsSecurityNone. PR surfaceSource +213, Tests +502. Total +715 across 7 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the conditional read-only preflight and single existing maintenance-lease path, with final ownership checks at every persistent mutation boundary. Do we have a high-confidence way to reproduce the issue? Yes, source-reproducible: fetched current main invokes the migration without the existing maintenance wrapper, and a supported v17 database reaches the guarded schema upgrade path. I did not execute the repository because this review is read-only. Is this the best way to solve the issue? Yes. Reusing the established maintenance lease, skipping it for proven no-op databases, and checking it at mutation boundaries is the narrowest maintainable repair; no parallel migration path or new setting is introduced. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against f3607b1963db. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (13 earlier review cycles; latest 8 shown)
|
|
@clawsweeper review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
🦞👀 Re-review progress:
|
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
Clarification on the automated SQLite warning: this PR does not add, remove, or redefine persisted SQLite tables. There is no delta to the agent schema SQL, schema version, or database contract. The Upgrade compatibility is exercised against an existing-format v17 database fixture: the focused regression advances beyond the original 60-second lease lifetime, renews authority between synchronous phases, upgrades to v19, and verifies success. A separate same-version fixture forces lease loss before commit and verifies the convergence transaction rolls back. No production database was modified for this proof. |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@clawsweeper automerge |
|
🦞👀 Approver: I left the PR open for the remaining gate instead of bypassing it. Automerge progress:
|
|
🦞✅ Source: Why human review is needed: What the maintainer can do as a next step: I added |
|
@clawsweeper approve |
|
Merged via squash.
|
* fix(state): fence automatic agent database migrations * fix(state): renew migration maintenance authority * fix(state): skip no-op transcript maintenance * test(state): prove maintenance loss fencing * fix(state): preserve no-op migration completion * style(state): format migration preflight * fix(state): fence archive publication rename * test(state): cover archive rename lease loss * test(state): isolate archive lease expiry proof * fix(state): use canonical writer lease preflight * fix(state): preserve migration preflight recovery * test(state): harden migration preflight proof * chore: keep release changelog generated * docs(changelog): record agent database startup fix * chore: keep release changelog generated * fix(state): surface migration preflight failures * fix(state): skip maintenance for canonical archives * fix(state): renew schema migration authority * fix(state): surface lease inspection failures --------- Co-authored-by: Omar Shahine <[email protected]>
Closes #133478
What Problem This Solves
Automatic historical transcript-directive migration can open a supported older per-agent SQLite database without first acquiring stopped-writer maintenance authority. The participant-identity schema migration correctly rejects that caller, so an otherwise isolated Gateway refuses readiness.
Why This Change Was Made
Automatic migration now performs a read-only need check first. A current database with no historical transcript or archive work returns without acquiring the maintenance lease, so an existing writer is neither interrupted nor warned. Databases that require mutation run under the existing agent-database maintenance lease.
Transcript and archive work yields after bounded batches so the timer-driven lease heartbeat can renew. Every transcript, archive, archive-file, and cursor mutation revalidates the shared-state maintenance authority immediately before writing. SQLite callbacks revalidate again after their final mutation and immediately before returning to the transaction owner, so an expired or replaced lease rolls the transaction back instead of committing stale-authority work. The maintenance guard itself remains strict.
The authority check uses the retained shared-state lease context rather than
assertOwnedInTransactionon the per-agent transaction because the lease row and transcript rows live in separate SQLite databases.User Impact
An isolated sole Gateway can upgrade copied older agent databases and become ready. A current database with no historical work remains read-only even when another process owns it. A database requiring migration remains fenced, including when a historical rewrite runs beyond the lease's original 60-second lifetime or loses authority during a synchronous mutation.
Evidence
Agent identity migration requires stopped-writer maintenance.node scripts/run-vitest.mjs src/infra/state-migrations.transcript-directives.test.tspassed 15/15, including same-version lease-loss rollback, a v17-to-v19 upgrade renewed past the original 60-second lease lifetime, and surfaced shared-state lease-inspection failures.extensions/qa-lab/src/suite-process-lifecycle.test.ts -t 'exits after the terminal summary and leaves no gateway listener'passed 1/1 in 30.91s.git diff --checkpassed.check:changedpassed in full, including core and core-test typechecks, changed-file formatting/lint, schema guards, and runtime-cycle checks.CHANGELOG.mddelta; release-note context is retained here because the repository owns changelog generation.Operational proof status
No production patch or restart was performed. An earlier isolated dev attempt removed the reported maintenance-authority refusal but encountered an independent copied-device-identity warning before readiness; production was restored immediately and subsequently placed under a hard no-touch gate. All post-finding proof is hermetic.
This PR is independently based and reviewable. It is not stacked on routing PR #133499 or Lobster proof-restore PR #339. Lobster #339 is only an operational proof-safety dependency for any future coordinated live exercise.
Exact-head CI and ClawSweeper review remain required before merge readiness. No autofix or automerge is enabled.