Repository navigation
perf(state): skip full agent scans on clean same-version restarts - #153463
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed September 20, 2026, 4:46 AM ET / 08:46 UTC (Revision 5). ClawSweeper reviewWhat this changesThe PR reuses persisted agent-database verification after clean same-version restarts, schedules background checks, and includes verification metadata in SQLite backups. Warning SQLite table change This PR modifies persisted SQLite tables in Merge readiness⛔ Blocked before merge - 5 items remain This remains useful work that current main does not implement. No concrete introduced correctness defect was found; the protected, maintainer-authored PR remains open with an unresolved upgrade-validation requirement. Priority: P2 Review scores
Verification
How this fits togetherAgent databases hold sessions, transcripts, memory indexes, and other agent state. Their admission and lifecycle owners validate storage before use, while the Gateway verifier checks databases in the background and quarantines confirmed corruption. flowchart TD
A[Agent database open] --> B[Lease owner consumes clean record]
B --> C{Matching version and file?}
C -->|No| D[Full integrity checks]
C -->|Yes| E[Schema and ownership checks]
D --> F[Agent database available]
E --> F
F --> G[Gateway background verification]
F --> H[Last graceful close records cleanliness]
Decision needed
Why: The applicable repository policy requires that transition, and the captured PR body explicitly says it was not run; the reviewer cannot waive it. Before merge
Agent review detailsSecurityNone. PR surfaceSource +761, Tests +986, Docs +22, Other +4. Total +1773 across 60 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep verification reuse under the existing lease owner, with a validated updater transition and actionable recovery for verification-metadata write failures. Do we have a high-confidence way to reproduce the issue? Not applicable as a correctness bug: current source confirms repeated full checks across process restarts, and the PR supplies an isolated benchmark; this read-only review executed no runtime tests. Is this the best way to solve the issue? Yes, the implementation fits the existing lease, verifier, and backup owners without creating competing policy owners; upgrade acceptance remains conditional on transition evidence or an explicit exception. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against f802444ee92c. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
7eb886a to
96e6194
Compare
96e6194 to
6e48837
Compare
Keep verification records in the quarantine store and let the existing lease owner consume clean proof and certify the last checkpointed close. Share gate eligibility with readiness, queue quick verification after listening, and invalidate proof across crashes, aliases, and maintenance. The warmed 899.5 MB fixture gate falls from 1094 ms to 17.8 ms (98.4%). Full checks remain for updates, migrations, unclean or replaced files, Doctor, shared state, snapshot fallback, and daily verification.
6e48837 to
0c0e3fb
Compare
|
Merged via squash.
|
…enclaw#153463) Keep verification records in the quarantine store and let the existing lease owner consume clean proof and certify the last checkpointed close. Share gate eligibility with readiness, queue quick verification after listening, and invalidate proof across crashes, aliases, and maintenance. The warmed 899.5 MB fixture gate falls from 1094 ms to 17.8 ms (98.4%). Full checks remain for updates, migrations, unclean or replaced files, Doctor, shared state, snapshot fallback, and daily verification.
What Problem This Solves
Large agent databases repeat full integrity scans during clean same-version restarts, delaying writable admission and Gateway readiness.
User Impact
A clean same-version agent reopen reuses its integrity verification and schedules
quick_checkplus foreign-key validation in the existing forked verifier after the Gateway is listening. Updates, pending migrations, missing or unclean verification, and replaced files retain full checks. Doctor’s full checks remain unchanged.Why This Change Was Made
This implements the maintainer-approved policy to gate full boot-time agent checks on updates and unclean or replaced state. The existing quarantine store owns an additive
agent_integrity_verificationstable withpath TEXT PRIMARY KEY,dev TEXT,ino TEXT,app_version TEXT,verified_at INTEGER, andclean_close INTEGER CHECK (clean_close IN (0,1)). Agent/shared-state schema versions remain unchanged; older builds ignore the table. The record is reconstructible, contains no content hashes, and ordinary writes do not change its eligibility.The existing lease owner consumes clean proof before admission and publishes clean close only after the last handle checkpoints and closes. Failed native cleanup, forced Worker exit, stale claims, and path aliases invalidate proof conservatively. A live lease may still lend identity-bound, revocable runtime proof to another handle, but only while matching durable metadata remains present. Missing, replaced, or version-mismatched metadata cannot be bypassed by remembered runtime validation.
Cached opens notify the existing host verifier, including late Worker opens. Quick-check success is logged and leaves full-check receipts unchanged; only the full-check lease owner publishes verification metadata. Gateways sharing a state directory in one process share serialized verification work and a daily deadline while retaining independent async contexts and shutdown ownership. Stopping one hands unfinished checks to surviving Gateways. Full scans also retain queued paths absent from the registered inventory. Clean consolidated WAL files use an immutable readiness read under the existing exclusive source-handle owner; uncertain or contended reads retain full snapshot verification.
The accepted tradeoff is that same-inode damage after a clean close may be detected after readiness. Background terminal failures retain live confirmation and quarantine; the next open fails through the existing terminal path. A failed durable dirty-marker write refuses admission, preserving the existing clean proof until the metadata-write problem is repaired. Shared-state boot checks, migrations and index repairs, explicit copied-file preflight, Doctor, and the existing full background scan (initially after five minutes, then daily) retain full checks. Independent Gateways must not share mutable agent databases across state roots.
Backup now includes the quarantine store in its existing verified SQLite snapshot path. The released quarantine schema remains version 2, with its existing rows preserved when the additive receipt table is first created.
Evidence
Six alternating-order warmed samples against the real agent schema with 4,428 synthetic sessions, 100,000 transcript rows, and 899,518,464 bytes, on Node 26.8.2 / SQLite 3.53.4:
quick_checkforeign_key_checkThe optimized gate saves 98.4%; all six samples report
integrityGateOutcome: "cached". This isolates the gate and excludes shared lease acquisition, whole-open cost, Gateway readiness, and shutdown. Host contention makes absolute times variable.The original 162 focused tests were supplemented during landing by passing suites covering 158 session/config cases, 15 auth-admission cases, 188 memory-plugin cases, 156 backup cases (two platform skips), 144 final integrity/admission/verifier cases, and eight real multi-Gateway lifecycle cases. Some suites overlap. The released v2026.9.5 quarantine-schema fixture proves additive receipt creation preserves existing rows and schema version; policy cases cover retained and borrowed runtime proof, version changes, missing receipts, file replacement, and failed dirty writes followed by recovery. Backup proof covers verified snapshot and restore of the receipt store.
Initial CI failures were reproduced or compared against pure main before attribution. Repairs preserve warm Worker proof, independent Gateway lifetimes, verified backup ownership, and all FIFO, authority, corruption, and cleanup assertions. Full-scan fixtures now explicitly invalidate receipts or replace their files. A separate cold-start timing failure reproduced on pure main and was left unchanged; the repaired startup suite passed its other 15 cases. Line-cap checks, formatting, docs checks, scoped lint, core and plugin-test typechecks passed. Independent review of the corrections is clean through P2, in addition to the completed review of the original change.
A Linux-only quick-check identity failure exposed a ctime-based replacement/restoration assumption and a fixture intercepting the coordinator open. The redundant quick-success timestamp writer and its identity certification were removed. A regression assertion fails on the old writer and passes after removal; 90 focused verifier, process, lease, policy, and shutdown cases pass, including the real cached-Worker relay. Scoped lint, core typechecking, docs checks, and fresh independent review through P2 pass. Pure main passes its 27 process cases but does not contain the new quick-check identity path.
Hosted CI run 35498498098 passed for head
0c0e3fbfc9a483879a9eb524e3da4c62734c3b39; the completed check set has 170 passing and 38 skipped checks. The dependency-review workflow briefly published its incomplete status before replacing it with success three seconds later; no dependency change required review.Limits: no production Gateway was modified or restarted, no live end-to-end restart timing or published-updater × candidate campaign was run, and no standalone local full build is claimed. Focused runs built their compiled Worker bundles; hosted CI owns the complete build/test gate. Updates retain version-mismatch full checks and the existing migration/Doctor owners.