Repository navigation
perf(sessions): remove per-commit canonical validation bookkeeping - #167932
Conversation
Checkpoint schema 25 and canonical writer cutover after a clean P2 review. Full campaign proof and the autocommit-policy and prior-schema recovery follow-ups remain pending before publication.
Revoke canonical proof before policy publication, preserve backed-up schema-24 orphan repair, and reuse historical schema definitions for older media and session migrations. Update import fixtures to use explicit admission invalidation. Final staged-tree P2 review is clean; focused regressions, typechecks, cycles, Knip, and the T1 ratchet pass. Full changed checks have only reproduced inherited max-lines failures in untouched files.
|
🦞👀 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. What this changesThe session store validates serialized records before writing them, removes repeated database bookkeeping, and migrates existing agent databases from schema 24 to 25. Review scores
ProductKind: Performance · Worth it: Yes Merge readiness⛔ Blocked before merge - 1 item remains This PR provides a distinct, measured optimization that current main still lacks. No concrete introduced correctness defect was found. Priority: P2 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherOpenClaw stores session metadata and conversation history in per-agent SQLite databases. Session writers preserve record identity, while admission workers validate imported or repaired records before runtime use. flowchart TD
A[Session metadata update] --> B[Validate serialized record]
B --> C[Session writer]
C --> D[Agent SQLite database]
E[Offline imports and Doctor repairs] --> F[Pending validation queue]
F --> G[Admission worker]
G --> D
D --> H[Session readers]
Technical reviewBest possible solution: Keep serialized validation with the existing writer and historical-state validation with migration and admission, preserving explicit offline invalidation and backup-based recovery. Do we have a high-confidence way to reproduce the issue? Not applicable to a functional bug: current-main source and the submitted alternating Gateway workload establish the repeated bookkeeping this optimization removes. Is this the best way to solve the issue? Yes: the existing writer validates its serialized inputs before mutation, while the existing migration and admission owners handle historical or unvalidated records without a competing runtime path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against e69931d6e6a2. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +37, Tests +1181, Docs +71, Config 0, Other +2. Total +1291 across 64 files. Added test files: 2. View PR surface stats
Review metrics
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed October 9, 2026, 4:38 PM ET / 20:38 UTC (Revision 2). |
Include the schema-25 migration in extracted PR wrappers and the existing raw SQLite schema/migration allowlist. Focused import-closure and process-build graph tests, Kysely guardrails, and scoped P2 review pass.
Preserve corruption, retained-reader, label-authority, and admission failure coverage after retiring canonical validation triggers. All 113 focused cases pass on the integrated tree; production, core-test, and tooling types and Madge pass.
Explicitly publish pending state in raw repair fixtures, retain transaction snapshot boundaries, and remove the obsolete per-write validity UPDATE assertion. All 123 focused late-fixture tests pass after the targeted schema fixture correction; selected type graphs and final P2 review pass.
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
…uard writes Since 6a8b0dc (#167932) the canonical writer persists native session patches with insert into "session_nodes" (upsert) instead of update ... set, so the opaque commit-guard case still mutated natively but the SQL detector missed it. Accept both native write shapes; the prepared-guard case still asserts no native write.
…penclaw#167932) * perf(sessions): validate canonical rows before writing Checkpoint schema 25 and canonical writer cutover after a clean P2 review. Full campaign proof and the autocommit-policy and prior-schema recovery follow-ups remain pending before publication. * fix(sessions): preserve offline validation and historical repairs Revoke canonical proof before policy publication, preserve backed-up schema-24 orphan repair, and reuse historical schema definitions for older media and session migrations. Update import fixtures to use explicit admission invalidation. Final staged-tree P2 review is clean; focused regressions, typechecks, cycles, Knip, and the T1 ratchet pass. Full changed checks have only reproduced inherited max-lines failures in untouched files. * fix(tooling): register canonical validation migration dependencies Include the schema-25 migration in extracted PR wrappers and the existing raw SQLite schema/migration allowlist. Focused import-closure and process-build graph tests, Kysely guardrails, and scoped P2 review pass. * test(sessions): explicitly seed imported validation fixtures Preserve corruption, retained-reader, label-authority, and admission failure coverage after retiring canonical validation triggers. All 113 focused cases pass on the integrated tree; production, core-test, and tooling types and Madge pass. * test(sessions): complete canonical writer fixture cutover Explicitly publish pending state in raw repair fixtures, retain transaction snapshot boundaries, and remove the obsolete per-write validity UPDATE assertion. All 123 focused late-fixture tests pass after the targeted schema fixture correction; selected type graphs and final P2 review pass.
…uard writes Since e6f6e17 (openclaw#167932) the canonical writer persists native session patches with insert into "session_nodes" (upsert) instead of update ... set, so the opaque commit-guard case still mutated natively but the SQL detector missed it. Accept both native write shapes; the prepared-guard case still asserts no native write.
…#167932): schema 25 -> 26 bridge Upstream openclaw#167932 takes agent schema 25 for canonical writer validation (retires the entry_valid / canonical-pending triggers). Our recipient authority was also schema 25 and is live on the fleet. Decision (🌊 + 🕯, option A): keep upstream's numbering; recipient authority becomes schema 26. - OPENCLAW_AGENT_SCHEMA_VERSION = 26; CANONICAL_SESSION_WRITER_VALIDATION = 25; AGENT_RECIPIENT_AUTHORITY_SCHEMA_VERSION = 26. - readAgentSchema25Shape classifies a schema-25 file by its physical shape: authority table + legacy entry_valid trigger = the fleet's schema 25; neither = upstream's; any other shape throws ("unrecognized schema-25 shape ... restore its pre-upgrade backup") before anything is written. - The fleet shape validates against current SQL + legacy triggers, then runs upstream's trigger retirement and the idempotent recipient-authority step in the one schema transaction; markers advance to 26 only on commit. - getOpenClawAgentMigrationSchema composes both historical representations; schema.sql keeps the authority table without the retired triggers. - agent-schema-history: upstream's 25 row, our 26 row, and the fleet-25 bridge; rollback is the pre-migration backup with its matching build. Fossils (openclaw-agent-db.schema25-bridge.test.ts, 7): fleet 25->26 keeps the authority row and drops the legacy triggers; upstream 25->26; 24->26; idempotent reopen; mixed shape refused unchanged; a denied user_version=26 publication rolls back to the exact fleet-25 shape. Causal: with shape detection stubbed out 4/7 RED, restored 7/7 GREEN. The recipient-authority migration test moves to 26 and its schema-24 fixture now carries the legacy triggers schema 24 really had. Checks: tsgo x4 clean; 106-file schema/canonical-validation/doctor sweep green except openclaw-agent-execution.creation-witness (7 fail), which fails identically on plain upstream 6a8b0dc (upstream baseline on this host; not touched). Deploy is blocked past step 13 until bootstrap#1703 (a post-migration rollback must restore the pre-migration snapshot) lands. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Jhynq2GVpzuVQQieebEubg
What Problem This Solves
Canonical session commits queued their already-known row for validation, restored a validity flag cleared by a trigger, reread the row, and deleted its pending marker. This removes 55 SQLite statements per warmed chat turn, with no replacement worker requests.
User Impact
Chat turns execute less SQLite work. The paired all-thread median is 1,135.0 → 1,060.7 statements/turn; 55 of the observed 74.3 reduction are the verified removed bookkeeping classes. Remaining differences are unchanged admission/background work and timing, not additional savings claimed here. The overall campaign still has work remaining toward 500 statements/turn.
Agent schema 24 → 25 is a forward migration. Older binaries refuse schema 25; binary rollback requires the verified pre-upgrade database backup with its matching build. Session/transcript payloads, durability, retention, permissions, FIFO, effect-boundary live authority, and released SDK contracts are preserved. Low-level autocommit writers now reject invalid serialization/native-text projections before writing, closing the previous transaction-only validation gap.
Why This Change Was Made
The canonical writer validates its serialized UTF-8 row projection before side effects and writes final validity once. Schema 25 retires three validity-reset triggers and nine pending-validation triggers. No new cache, worker request, runtime format check, or foreign-commit probe is introduced.
Under the approved single-owner contract, the Gateway owns runtime SQLite writes. Other processes use the Gateway or operate offline while it is stopped. Imports and Doctor repairs that deliberately stage aliases or unvalidated rows explicitly queue those keys and revoke canonical receipts. Main-key policy changes invalidate before publication, including autocommit failure paths. Existing provenance/owner reads retain their separate contracts.
Migration validates the historical schema, seeds every existing node, clears prior canonical proof, and publishes both version markers atomically. Admission retains its bounded validation worker and exact-input settlement. The migration supports older databases missing the lazy receipt column. Backed-up schema-24 orphan-window repair remains available before upgrade or the full migration backup; only unreachable windows are removed, with original history preserved in the backup. V14 and intermediate media schemas use the same historical schema owner. Current construction never reinstalls the retired triggers.
Evidence
Base
432ade6f500de6cdb0bcd4b0948a07bf466672f1; candidate01f857c6b37056bd47df1eae9f546bc0e8efbb2c. Six same-host runs in M,C,M,C,M,C order used the shared workload, privately copied only to add the existing transport observer. All 13 top-level turns, the native child, control RPCs, cron, compaction, and shutdown succeeded in every run. SQL/census joins conserve every successful statement; no missing SQL contexts or duplicate sends. Calibration on MAIN and a worker: 8 native calls, 2 prepares, 7 successful statements, 0 failures.Values are median [min–max] across three runs. Warmed values are each run’s ten-turn mean; other rows are phase totals. MAIN is Gateway thread 0; all-thread totals also include workers and helper processes. Instrumentation and background work stay counted. These are execution-count observations, not unloaded-host latency measurements.
Requests are logical transport requests, including resource closes; continuation/control frames are recorded separately. The warmed 200.2 → 199.7 change is observed variation, not an RPC reduction attributed to this patch. Two boot-only transport targets were unresolved; their sends remain counted, and all warmed requests completed.
Statement attribution and gates
The certification stack itself loses all 42 pending/readback/delete executions, and the writer loses 13 validity updates. Nothing moves to MAIN or another worker. Retired trigger DDL also disappears from current-schema construction/comparison: median reductions are 60 boot, 48 connect, and 60 first-turn statements; its warmed median is zero on both sides. The direct bookkeeping class sums removed in first-turn/second-session/cron/compaction are 77/179/59/9. Other observed decreases are not credited as new optimization: unchanged schema/handle admission, resource lifetime, and background timing account for their variable work.
All per-phase median duration ratios are ≤1.5 (maximum 1.458). First-turn and warmed totals decrease. Control’s +3 statements/+1 request are an existing
deliveryQueue.outboundrecovery read (version observation, config-machine state, queue selection), present in baseline run 3 and candidate runs 1/3. Shutdown’s +6 statements come from existing integrity clean-close/lease-release and WAL owners. Every positive SQL/normalized-stack group appears in the baseline. Both increases pass the ≤10-statement non-turn tolerance, with no PR-created request path. For context, compaction+shutdown sums are M=[709,613,610], C=[612,621,658], median 613→621 (+1.3%).Native failed attempts are retained separately: base [0,0,0]; candidate [1,0,2], all boot/connect
BEGIN IMMEDIATElock attempts in unchanged state-lease release/operator-approval cleanup. None occur in first/warmed turns; all full workloads finish successfully. They are excluded from successful-statement counts by the shared counting contract.Correctness and static proof
check:changedpassed all guards, formatting, package/schema baselines, SDK surface checks, all typecheck lanes, and unused-export scans. Its sole failure is 15 inheritedmax-lineslint errors in untouched files. All 15 reproduce, and their source/config/lock/wrapper inputs are byte-identical toorigin/mainata799f4a42891eb875c7c238c22c2fa881027209f. They do not block this lane under the inherited-failure rule. The final fixture edit separately passes its selected type graph and lint.657de9cb.Materially expanded test owners were measured individually with
pnpm test <file> --maxWorkers=1: canonical validation 25.4 s, canonical schema/migration 20.9 s, validation-cache receipts 20.5 s wall time. These exercise actual SQLite serialization, physical admission, worker handoff, and migration/rollback contracts. Final-attempt CI timing and incomplete coverage are recorded below. A timing-only attempt aborted before tests because a concurrent build changed workspace artifact topology; its sequential rerun passed. No timeout increase or weakened assertion was used.Published-driver × candidate update cell passed in this lane: installed
2026.9.8updater → candidate2026.9.9at01f857c6b37056bd47df1eae9f546bc0e8efbb2c. The run finished/succeeded,/readyzreturned 200, running version/build matched, and durable/incognito post-update checks passed. The isolated service stopped and the container/volume cleanup completed. Candidate tarball SHA-256:2b0593c93fd7ff07946277e8ee9f1f2ab50241e821353545c9bc2b1250f9bb01.Scope and remaining limits
Production/metadata/tooling LOC: +343/−304 (net +39). Tests/support: +1529/−348 (net +1181), dominated by the 1,039-line frozen schema-24 migration fixture. Docs: +80/−9. Historical trigger definitions remain only with migration; current writers and DDL have no competing path.
The published artifact build reported a startup-JS budget warning (364.8 KiB gzip versus 364.7 KiB); tarball integrity passed. This is backend work with no UI source changes. The shared host and background admissions explain wide run spreads; only the 55 repeated statement removals are claimed as warmed-turn savings. The landing validation below covers the integrated candidate and CI repairs.
Landing validation
Final candidate:
881ea03585a2167dabbf23393dc7468f26912e15. Main was merged without conflicts in1bd8206d9ad3to incorporate the already-landed recovery-fixture fix. No rebase or SQL-path conflict resolution was needed; the valid alternating SQL proof above is reused. Agent schema 25 was still free on main7cf743ec145a(which declares 24).The lander fixed two tooling omissions in
cd88c380b583: the migration module belongs in the extracted-wrapper dependency inventory and in the existing raw-SQL schema/migration allowlist. CI also exposed raw-write test fixtures that relied on the retired triggers. Commitsad8d86fb3452and881ea03585a2explicitly establish pending/validity fixture state, preserve concurrent-writer transaction boundaries, and retain refusal, snapshot, authority, and persistence assertions. The companion test's assertion for the retired validity UPDATE was removed; its persisted-label and authority checks remain.All 236 focused tests across 18 repaired fixture files now pass, plus 31 wrapper/import/process-graph tests. Post-integration production, all 27 core-test typecheck lanes, scripts typechecking, Kysely guardrails, and Madge (zero cycles) passed. Subsequent fixture edits passed their selected type graphs. Three scoped lander Codex P2 review rounds are clean; the original lane's final P2 review remains valid for unchanged production code. Released SDK review against
v2026.9.9andv2026.10.1-beta.2confirms the changed helpers are internal and no released callable signature was removed.Focused proof used
--maxWorkers=1. The first eight-file repair batch took 632.786 s (97 tests); ACP startup took 279.875 s, including a cold worker build, and canonical reads 188.579 s. The late eight-file batch took 314.74 s (122 passed, one fixture precondition corrected); the final schema-probes file passed all 14 tests in 67.96 s. The final late batch's Gateway suites passed 34 tests in 147.13 s. No timeout increases, sleeps, retries, or weaker behavior assertions were added.ClawSweeper completed its review of
01f857c6b370with zero code findings and requested latest-stable upgrade evidence beyond the lane's earlier 2026.9.8 run. That gap is now closed: the published 2026.9.9 driver → candidate 2026.9.9 at 881ea03 cell passed. The updater finished in 646.391 s;/readyzreturned 200, running version/build identity matched, and both durable and incognito post-update checks passed. The isolated service stopped successfully and container/volume cleanup completed.Command (artifact paths abbreviated):
bash scripts/e2e/published-driver-update-docker.sh <candidate.tgz> <artifacts> 2026.9.9.The full package build and tarball integrity check passed. Candidate SHA-256:
7dcd9bae4e3d99d61e43669ad17295a904aed6ad709f0658bf132c01d8ae0b9b. The build retained the same startup-JS budget warning already recorded above (364.8 KiB versus 364.7 KiB); this PR changes no UI source.CI infrastructure exception
CI attempt 37986402968 executed merge
c97064b345f20fc3c37f5e960d6bcf9096279556, whose parents are main7cf743ec145aand candidate881ea03585a2. Two unchanged pinned-Bun setup downloads returned HTTP 500 on the initial request and all three built-in retries, before their Node test steps ran:The successful fail-fast monitor cancelled 131 collateral jobs; none of those jobs has a failed step. The complete attempt has two infrastructure roots, one downstream CI-gate failure, 131 cancelled jobs, 20 skipped jobs, and six successful jobs including security-fast. Cancelled coverage remains unrun. This attempt recorded 17,490 elapsed job-seconds including cancelled jobs; that is execution timing, not a claim of complete coverage. The Bun action, installer, pin, and workflow blobs are identical to the tested main baseline, and the failure precedes this PR's code. Native admin admission is explicitly authorized for this independently inherited infrastructure failure; it must still verify current security, reviews, head identity, and the complete retained evidence. No CI rerun was requested merely to obtain green.