Repository navigation
fix: repair canonical session keys with doctor - #116703
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed July 31, 2026, 12:51 PM ET / 16:51 UTC. ClawSweeper reviewWhat this changesThis PR moves session-key alias repair into Merge readiness⛔ Blocked until stronger real behavior proof is added - 7 items remain Keep this PR open, but do not merge it yet: the new additive Priority: P1 Review scores
Verification
How this fits togetherOpenClaw stores each agent’s session identity, transcript links, and delivery state in SQLite. Gateway, agent, CLI, and doctor flows resolve those rows; this PR moves alias cleanup out of runtime and into the doctor-owned migration boundary. flowchart LR
A[Existing SQLite session rows] --> B[Doctor migration]
B --> C[Canonical session-key rows]
C --> D[Gateway and agent runtime]
D --> E[Session reads, writes, and transcripts]
Before merge
Findings
Agent review detailsSecurityNone. Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Run the new idempotent session-key contract and entry-validity setup on both steady-state and legacy-version migration paths, then add a regression test opening a pre-change SQLite database and attach redacted exact-head file-backed doctor output. Do we have a high-confidence way to reproduce the issue? Yes: create an agent SQLite database at a schema version below the current target, then open it with this branch. The version-migration branch does not call the new Is this the best way to solve the issue? No: making doctor the sole alias-repair owner is the right boundary, but the additive SQLite projection must also be installed during legacy-version upgrades rather than only on already-current databases. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 5332641ed3ba. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles) |
4718232 to
760e4c7
Compare
|
Merged via squash.
|
* origin/main: (42 commits) fix(auto-reply): avoid false overload attribution on stalled replies (#116959) fix(auth-profiles): scope model_not_found cooldown to the failing model (#116768) fix(agents): expose embedded preparation latency (#116936) fix(macos): preserve localized setup fallback fix: repair canonical session keys with doctor (#116703) fix(gateway): preserve plugin-only session change events (#116948) fix(media): recognize AIFF attachments across audio workflows (#116907) fix(openai): recover missing terminal response output (#116910) fix(telegram): preserve outbound media metadata and rejected photos (#116886) fix(agents): preserve bounded truthful subagent outcomes (#116932) improve(setup): clarify local provider actions fix(cron): preserve scheduler truth across edits and delivery (#116923) fix(openai): finalize Chat tool calls from authoritative terminals (#116922) fix(ui): recover session observers across reconnects (#116887) fix(qa): verify requested scenarios and reject silent character runs (#116912) fix: agent turns survive unavailable optional web credentials (#112522) fix(sessions): preserve transcript and child ownership (#116897) fix(ui): preserve chat stream ownership and accessible rendering (#116929) fix(media): preserve display metadata and attachment formats (#116928) fix(together): preserve immediate video outcomes and image references (#116913) ...
* fix: repair canonical session keys with doctor * test: align canonical validation with reopen boundary * test: align session fixtures with canonical keys * fix: copy only canonical session repair winners * fix: cover canonical repair edge cases * test: remove retired preview helper import * test: align canonical repair delivery scope * fix: close canonical repair validation gaps * fix: preserve destination-only repair generations * fix: preserve canonical repair window projections * style: format canonical repair imports * fix: preserve canonical repair delivery ownership * fix: preserve winner-owned cross-store state * fix: guard canonical delivery rehoming * fix: align canonical session contracts after rebase * test: accept internal canonical repair fixtures * test: move sharing alias coverage to doctor
* origin/main: (42 commits) fix(auto-reply): avoid false overload attribution on stalled replies (openclaw#116959) fix(auth-profiles): scope model_not_found cooldown to the failing model (openclaw#116768) fix(agents): expose embedded preparation latency (openclaw#116936) fix(macos): preserve localized setup fallback fix: repair canonical session keys with doctor (openclaw#116703) fix(gateway): preserve plugin-only session change events (openclaw#116948) fix(media): recognize AIFF attachments across audio workflows (openclaw#116907) fix(openai): recover missing terminal response output (openclaw#116910) fix(telegram): preserve outbound media metadata and rejected photos (openclaw#116886) fix(agents): preserve bounded truthful subagent outcomes (openclaw#116932) improve(setup): clarify local provider actions fix(cron): preserve scheduler truth across edits and delivery (openclaw#116923) fix(openai): finalize Chat tool calls from authoritative terminals (openclaw#116922) fix(ui): recover session observers across reconnects (openclaw#116887) fix(qa): verify requested scenarios and reject silent character runs (openclaw#116912) fix: agent turns survive unavailable optional web credentials (openclaw#112522) fix(sessions): preserve transcript and child ownership (openclaw#116897) fix(ui): preserve chat stream ownership and accessible rendering (openclaw#116929) fix(media): preserve display metadata and attachment formats (openclaw#116928) fix(together): preserve immediate video outcomes and image references (openclaw#116913) ...
What Problem This Solves
Canonical and alias-form session keys could coexist across SQLite stores, forcing runtime readers to reconcile duplicates by freshness and making indexed session reads unsafe. Operators had no single durable repair owner, and a duplicate encountered after migration could silently select a different row.
Why This Change Was Made
openclaw doctor --fixis now the one migration owner. It inventories configured, discovered/retired, and fixed-collision stores; groups delivery-proven aliases under one canonical key; selects the freshestupdatedAtwinner with the canonical destination winning ties; archives losing transcripts before deletion; and leaves the persisted canonical key authoritative. Process-held incognito databases are excluded because doctor cannot reach their process-local handles.Runtime writes enforce canonical row and lineage keys. Reads no longer perform freshest-winner alias reconciliation; impossible post-doctor duplicates fail with
SESSION_CANONICAL_KEY_MIGRATION_REQUIREDand point operators toopenclaw doctor --fix. Whole-database validation runs once perDatabaseSyncopen. A deliberate same-process main-key contract update invalidates that connection's result; external direct-SQLite edits otherwise surface on the next process open, not a topology change.Retention rule: only the selected winner store is copied. Rows actually deleted have their user-visible transcript archived first. A superseded row already at the canonical destination keeps its
session_windowsandtranscript_eventsattached to the canonical node chain. A generation merely referenced by the winner is not replaced unless the winner store actually owns a window or generation rows, preserving destination-only history. Stale loser-only trajectory/ACP supplemental state is not merged; that is the approved ambiguity tradeoff. Copied delivery/idempotency records follow the exact winner key and are removed from the retired source store after the destination commit.No schema-version bump is required.
entry_valid, its triggers/index, andsession_key_contractare additive/idempotent surfaces.LOC accounting and trims
The rebuild deletes the ordered-event loser merge and supplemental fill semantics, the
session_key_revisionstable/triggers and token/TOCTOU retries, the per-write full scan, the duplicate-key JSON lexer, duplicate diagnostic factories, runtime freshest-winner alias mutation, andcanonicalizeSpawnedByForAgent. Those cuts are safe because doctor is the sole migration owner, runtime assumes canonical persistence, and loser user-visible history is archived or remains on the canonical node chain.User Impact
After
openclaw doctor --fix, session identity is durable and deterministic across restarts and stores. Operators keep accessible or archived transcript history, while runtime duplicate corruption fails loudly with an actionable repair command instead of silently choosing a winner.There are no gateway-protocol changes and no new config surface.
Evidence
Exact head:
69090643229.tbx_01kyw06a3smn5fy95mp0cpmv49:acpthroughweb-search, then the Testbox process was system-killed with exit 137 when startingwizard; the second run usedNODE_OPTIONS=--max-old-space-size=3072and skipped the already-green dead-code phase but reproduced the same infrastructure boundary;wizard,worker, root-source, UI, and packages lint shards serially with zero warnings/errors. The union covers the complete changed gate.failure; main Testbox dispatches were active or cancelled as leases ended, with no evidence of another hostedwizard-shard failure.origin/main(9922ea02e96):global:heartbeatand in-flight main-recovery ownership into canonical keys;pnpm buildgreen; noINEFFECTIVE_DYNAMIC_IMPORToutput.session_windows, exactly matching the documented retention rule rather than becoming orphaned.packages/gateway-protocolis untouched.ClawSweeper rank-up moves: the requested upgrade proof is the redacted file-backed Testbox migration above, which uses real SQLite files and the production doctor path rather than a mocked store. The old compact-shard failures were against
41e4dad84d6; the final exact head is covered by the fresh changed gate and exact-head CI listed here.Latest ClawSweeper P1 skipped as factually inapplicable: the ordinary legacy-version branch already calls
ensureSessionEntryValidityProjection(db)immediately aftermigrateSessionNodesAndWindows(db, previousVersion)and beforedb.exec(OPENCLAW_AGENT_SCHEMA_SQL)and final schema assertion insrc/state/openclaw-agent-db-schema.ts. The exact-head schema baseline, core/test typechecks, focused pre-change doctor fixtures, and hosted CI are green. The reviewer also requested inspectable proof that its context could not fetch; the redacted commands and durable Testbox/CI run IDs above identify that proof, so the documented reviewer wedge does not block landing.Follow-ups
Goal 3 remains deferred exactly as ruled: either persist the current runtime controller into canonical lineage, changing today’s runtime-only ownership design, or redesign multi-store federation so indexed per-store queries compose without a materialized combined store.