Skip to content

fix(doctor): keep repaired session rows readable - #117207

Merged
vincentkoc merged 2 commits into
openclaw:mainfrom
VACInc:fix/doctor-delivery-validity
Aug 1, 2026
Merged

vincentkoc merged 2 commits into
openclaw:mainfrom
VACInc:fix/doctor-delivery-validity

Conversation

@VACInc

@VACInc VACInc commented Aug 1, 2026 •

Copy link
Copy Markdown
Member

Summary

openclaw doctor --fix could rewrite canonical SQLite session JSON and leave the same row marked invalid. The next strict session read then rejected doctor's own output, which could abort doctor or update finalization.

This PR now repairs the shared doctor write invariant for both direct session_nodes.entry_json writers:

  • delivery-state normalization
  • reserved incognito-key repair

Both paths validate the prospective canonical row before writing, then restore entry_valid = 1 after the schema trigger resets it.

What Problem This Solves

Doctor repair could report success and then make its own repaired session rows unreadable. Affected operators could see doctor or openclaw update finalization fail immediately after legacy session metadata was normalized.

The original patch fixed only delivery-state repair. Deep review found the same defect in reserved incognito-key repair, which runs earlier in the same doctor sequence and could still leave a row unreadable.

Root Cause

session_nodes has an AFTER UPDATE OF entry_json trigger that sets entry_valid = 0. Canonical runtime writers follow their JSON update with a separate validity update. The two doctor repair paths bypassed that owner boundary and updated entry_json directly without settling validity.

The strict validity projection landed on main in #116703 after v2026.7.2-beta.6 was cut. Neither v2026.7.2-beta.5 nor v2026.7.2-beta.6 contains that projection, so this is a current-main release blocker rather than a regression shipped in those beta tags.

Canonical Fix

A doctor-owned rewrite helper now:

  1. parses the prospective JSON through the canonical SQLite session-entry parser,
  2. refuses structurally invalid rewrites,
  3. updates entry_json, and
  4. marks the row valid in a second statement after the trigger fires.

Strict readers remain strict. There is no runtime fallback, retry, schema-version bump, or configuration change.

Evidence

Baseline reproduction against current main with the regression tests retained:

Test Files  1 failed | 1 passed
Tests       3 failed | 9 passed

The failures proved:

  • delivery repair persisted entry_valid = 0
  • incognito-key repair persisted entry_valid = 0
  • delivery repair accepted an invalid object row as a candidate

Exact repaired head:

node scripts/run-vitest.mjs \
  src/commands/doctor-session-delivery-state.test.ts \
  src/commands/doctor-session-incognito-key-repair.test.ts

Test Files  2 passed
Tests       12 passed

Coverage includes:

  • real schema-trigger behavior
  • copied-store close/reopen through strict listSessionEntries
  • repeated repair idempotence
  • malformed-row fail-closed behavior
  • delivery and incognito sibling writers

Also passed:

  • targeted oxlint
  • targeted oxfmt --check
  • git diff --check
  • fresh local autoreview with no accepted or actionable findings

Blacksmith Testbox was attempted for the changed gate, but checkout sync timed out before any repository command ran. The permitted local fallback then stopped at the dependency-status guard because this Codex GWT must not reconcile its shared node_modules. Clean exact-head GitHub CI is therefore the heavy proof lane.

Scope

Production delta: +59/-26 across the two repair paths and one shared helper. Tests: +95/-6.

The positive production delta establishes one canonical validation/write boundary and removes duplicate trigger-settlement policy from both doctor writers.

AI-assisted: yes. Maintainer review traced the producer, trigger, strict reader, sibling writer, doctor order, update finalization path, tag provenance, and focused failure/reopen behavior.

@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations size: S labels Aug 1, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P1 High-priority user-facing bug, regression, or broken workflow. labels Aug 1, 2026
@clawsweeper

clawsweeper Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 1, 2026, 2:10 AM ET / 06:10 UTC.

ClawSweeper review

What this changes

The PR adds a shared Doctor helper that validates rewritten SQLite session JSON and restores its validity projection for delivery-state and reserved-incognito-key repairs.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

This PR is still necessary: current main has two doctor-owned session JSON rewrite paths that can leave the row invalid after the schema trigger runs. The proposed shared validation-and-settlement boundary covers both paths without weakening strict reads, and no discrete patch defect was found; retain it for normal exact-head CI and maintainer merge review.

Priority: P1
Reviewed head: daa1b8d8bb6f07d8e80b3e03283647c0fa0df1a6

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, source-aligned repair with strong persisted-state boundary coverage; exact-head CI completion remains before merge.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The PR body includes after-fix terminal evidence for focused tests exercising the real SQLite trigger, close/reopen, and strict session reads, and the PR is labeled proof: sufficient.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body includes after-fix terminal evidence for focused tests exercising the real SQLite trigger, close/reopen, and strict session reads, and the PR is labeled proof: sufficient.
Evidence reviewed 6 items Current defect owner: Current main delivery repair updates session_nodes.entry_json but does not restore entry_valid; the schema trigger resets validity after every JSON update.
Shared invariant: The session migration schema defines an AFTER UPDATE OF entry_json trigger that sets entry_valid = 0, so a JSON rewrite needs a later validity settlement before the next strict read.
PR repair boundary: The proposed helper validates the prospective entry with the canonical parser, writes JSON, then sets entry_valid = 1; both affected writers call it inside existing synchronous agent-database write transactions.
Findings None None.
Security None None.

How this fits together

OpenClaw Doctor repairs persisted SQLite session records before runtime reads them through strict session accessors. These two Doctor rewrite paths change row JSON; the schema trigger marks that JSON pending validation, and a later strict reader either accepts a settled row or rejects it.

flowchart LR
  A[Legacy session row] --> B[Doctor repair]
  B --> C[Validate rewritten entry]
  C --> D[Update session JSON]
  D --> E[Schema validity trigger]
  E --> F[Settle row validity]
  F --> G[Strict session reader]
Loading

Before merge

  • Resolve merge risk (P1) - Exact-head CI is still in progress; merge only after required checks complete green for daa1b8d8bb6f07d8e80b3e03283647c0fa0df1a6.
Agent review details

Security

None.

PR surface

Source +33, Tests +89. Total +122 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 59 26 +33
Tests 2 95 6 +89
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 154 32 +122

Review metrics

None.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/commands/doctor-session-delivery-state.test.ts, migration/backfill/repair: src/commands/doctor-session-delivery-state.ts, migration/backfill/repair: src/commands/doctor-session-entry-rewrite.ts, migration/backfill/repair: src/commands/doctor-session-incognito-key-repair.test.ts, migration/backfill/repair: src/commands/doctor-session-incognito-key-repair.ts, serialized state: src/commands/doctor-session-delivery-state.ts, and 4 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep one Doctor-owned validation-and-settlement helper for direct session JSON rewrites, preserve strict runtime reads, and merge after current-head CI confirms the repair.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep one Doctor-owned validation-and-settlement helper for direct session JSON rewrites, preserve strict runtime reads, and merge after current-head CI confirms the repair.

Do we have a high-confidence way to reproduce the issue?

Yes. Current source shows either direct Doctor writer can update entry_json, the schema trigger then sets entry_valid = 0, and a strict later read rejects the unsettled row; the PR body also provides focused real-SQLite trigger and reopen coverage.

Is this the best way to solve the issue?

Yes. Validating the prospective row through the canonical parser and settling the schema-owned validity projection inside the existing Doctor transactions fixes both sibling writers without a runtime fallback, configuration change, or schema bump.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 1b8411958b4d.

Labels

Label justifications:

  • P1: The current-main Doctor repair can make persisted session rows unreadable and abort a repair or update-finalization workflow.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes after-fix terminal evidence for focused tests exercising the real SQLite trigger, close/reopen, and strict session reads, and the PR is labeled proof: sufficient.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes after-fix terminal evidence for focused tests exercising the real SQLite trigger, close/reopen, and strict session reads, and the PR is labeled proof: sufficient.

Evidence

What I checked:

Likely related people:

  • steipete: Current blame attributes the strict validity projection and both direct Doctor JSON writers to the canonical-session repair work merged as PR 116703. (role: feature author and recent area contributor; confidence: high; commits: d8ba00f8a262, cd8a96491e26; files: src/commands/doctor-session-delivery-state.ts, src/commands/doctor-session-incognito-key-repair.ts, src/config/sessions/session-entry-json.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Wait for required checks on daa1b8d8bb6f07d8e80b3e03283647c0fa0df1a6 to finish green, then complete normal maintainer merge review.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-01T05:10:51.684Z sha 185bd74e6e73fd26933400c203aaba196f53aafd :: needs maintainer review before merge. :: none

@vincentkoc vincentkoc self-assigned this Aug 1, 2026
@vincentkoc
vincentkoc force-pushed the fix/doctor-delivery-validity branch from 185bd74 to daa1b8d Compare August 1, 2026 06:02
@vincentkoc vincentkoc changed the title fix: prevent doctor repair from blocking update finalization fix(doctor): keep repaired session rows readable Aug 1, 2026
@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. and removed triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Aug 1, 2026
@vincentkoc

Copy link
Copy Markdown
Member

Final maintainer landing gate for exact head daa1b8d8bb6f07d8e80b3e03283647c0fa0df1a6:

  • exact-head CI: 80 green, 0 failed/pending, including openclaw/ci-gate and all QA/compact shards
  • ClawSweeper: exact-head no defect; its sole rank-up move (wait for green checks) is satisfied
  • autoreview: clean
  • regression proof: main 3/12 failed; repaired 12/12 across delivery and incognito doctor writers
  • review threads: 0 unresolved
  • live main: ad3e36ef33148ea5b341ebbbc8f5b0fcd84b0596
  • touched-path drift: 0
  • clean synthetic merge tree: a8136f9696b0eb76fa0adeaea6dbcb67c4ba2f77

Landing via squash with contributor authorship preserved.

@vincentkoc
vincentkoc merged commit fe790ab into openclaw:main Aug 1, 2026
133 of 138 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 1, 2026
* fix: keep repaired session delivery rows readable

* fix(doctor): settle session entry rewrites

---------

Co-authored-by: VACInc <[email protected]>
Co-authored-by: Vincent Koc <[email protected]>
vincentkoc added a commit to a-tokyo/openclaw that referenced this pull request Aug 1, 2026
…in-4caff51-20260801

* origin/main:
  fix(agents): surface /new guidance for thinking-signature replay errors (openclaw#116967) (openclaw#116987)
  fix(doctor): keep repaired session rows readable (openclaw#117207)
  fix(feishu): unify outbound delivery lifecycle (openclaw#117223)
  docs(gateway): document llamacpp toolSchemaProfile for custom llama.cpp endpoints (openclaw#117120)
  fix(clickclack): thread replies stop being answered past the 100-reply thread window (openclaw#117225)
  fix(talk): retain bounded relay close owners
  fix(talk): bound relay transcript persistence
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants