Skip to content

fix(sessions): cancel revoked restores and bound rebuild checks - #149333

Merged
steipete merged 1 commit into
mainfrom
codex/session-loader-audit-20260915
Sep 15, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/session-loader-audit-20260915

Conversation

@steipete

@steipete steipete commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Related: #148972, #148918

What Problem This Solves

A history read could restore cold transcript rows after its database closed and then reject the result as revoked. Rebuild checks also scanned entire oversized transcripts before deciding to defer the rebuild.

User Impact

Revoked history reads leave replacement database contents intact. Large transcripts spend less synchronous work on rebuild preflight. Existing row/byte thresholds, transcript contents, reader snapshots, and native mutation settlement remain unchanged; no schema or configuration migration is needed.

Why This Change Was Made

Carry the existing history owner's live authority through cold-restoration queue waits and into the existing native commit guard. Bound stored-event sizing to the remaining 4,000-row budget plus one, preserving SQLite's ability to read byte lengths without loading overflow payloads. Reconciliation reuses its newest-sequence observation, and both entry points share the same query and comparison helpers.

Evidence

Three regression paths failed before the repair: a history read paused before restoration or inside its cold queue restored rows into a replacement database despite rejecting as revoked; a native commit-boundary test also ignored caller revocation. All now preserve the cold descriptor and canonical rows. Two row-budget cases failed with 8,000 size evaluations rather than their 4,001/4,000 bounds and now pass.

The five focused session/history files passed 75 cases. After the final query-helper cleanup, all 40 affected index/search cases passed again. Complete changed-file checks and independent P0–P2 review passed.

Warm, alternating measurements use the actual exported owners with synthetic in-memory SQLite on Node 26.8.2 / SQLite 3.53.4. The measured source is hashed before and after the run. These are component timings, not end-to-end Gateway latency.

Operation Before wall After wall
Rebuild sizing, 100,000 events 6.503 ms 0.340 ms
Rebuild sizing, 1,000,000 events 63.543 ms 0.360 ms
Rebuild sizing, 4,000 events 0.255 ms 0.310 ms
Clean synchronous reconciliation 0.02425 ms 0.01829 ms

The million-event check sizes 4,001 rows instead of 1,000,000. The bounded subquery adds about 0.06 ms at the existing 4,000-row threshold. Clean reconciliation executes three selections instead of four. All measured decisions match the original implementation, and the UTF-8/overflow-page regression coverage remains passing.

Required hosted CI passed for 3b2ab0884f33d4a52724169cce5f3c2b5cba5987: run 35008571258. ClawSweeper also reviewed that exact head without findings. The run waited for larger runners but completed without a CI rerun or cancellation request.

@steipete steipete self-assigned this Sep 15, 2026
@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: M maintainer Maintainer-authored PR labels Sep 15, 2026
@steipete
steipete marked this pull request as ready for review September 15, 2026 18:36
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Sep 15, 2026
@clawsweeper

clawsweeper Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 15, 2026, 2:48 PM ET / 18:48 UTC.

ClawSweeper review

What this changes

The PR prevents revoked history reads from restoring archived transcripts and bounds the synchronous work used to decide whether transcript indexes need rebuilding.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused repair: inspected main still lacks both changes, and the related merged PRs do not supersede them. No blocking correctness defect was found.

Priority: P2
Reviewed head: 3b2ab0884f33d4a52724169cce5f3c2b5cba5987

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful regression coverage and no identified blocking defect.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer-authored PR is exempt from ordinary contributor proof. The inspected native-worker and Gateway tests cover revoked restoration effects; reported SQLite timings cover only preflight performance. The authority-chain review found no unresolved introduced violation requiring additional final-effect proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer-authored PR is exempt from ordinary contributor proof. The inspected native-worker and Gateway tests cover revoked restoration effects; reported SQLite timings cover only preflight performance. The authority-chain review found no unresolved introduced violation requiring additional final-effect proof.
Evidence reviewed 8 items Current main still needs the repair: At fetched main, the history reader does not pass its database owner's assertion into restoration, and rebuild preflight aggregates every stored event before checking the row threshold. Neither related merged PR implements these remaining changes.
Restoration preserves the existing authority owner: Restoration checks the supplied assertion before database access, after its queue wait, and through runColdMutation. That existing mutation owner composes caller authority with database-claim and mutation-lifetime checks at write admission and native commit authorization.
Native commit settlement closes the authorization gap: The existing commit owner checks current authority before approving the shared commit gate, rejects failed authorization, and synchronously joins transaction settlement before releasing authority. The patch reuses this mechanism without changing its protocol.
Findings None None.
Security None None.

How this fits together

OpenClaw’s history reader restores archived transcripts before returning conversation history from SQLite. Database lifecycle ownership governs restoration, while the transcript index owner decides whether rebuilding can run synchronously.

flowchart TD
  A[History request] --> B[Database lifecycle owner]
  B --> C[Queued archive restoration]
  C --> D{Authority still current?}
  D -->|Yes| E[Commit restoration and read history]
  D -->|No| F[Reject and preserve stored rows]
  G[Transcript changes] --> H[Bounded index rebuild check]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +21, Tests +173, Docs +2. Total +196 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 5 54 33 +21
Tests 4 176 3 +173
Docs 1 4 2 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 234 38 +196

Review metrics

Metric Value Why it matters
Rebuild sizing bound At most 4,001 stored rows; fewer with incoming rows Oversized transcripts can be rejected without scanning their entire event history, while the existing thresholds remain unchanged.
Production versus test growth Production +21 lines; tests +173 lines Production growth carries existing authority through restoration; most added code verifies cancellation and bounded work.

Technical review

Best possible solution:

Keep restoration under the existing database lifecycle and native commit owners, with bounded preflight queries that preserve transcript bytes and rebuild thresholds.

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

Yes: source and the added regression scenarios identify how a paused history read can restore after database retirement and how oversized transcripts trigger unbounded sizing. This review did not execute those scenarios.

Is this the best way to solve the issue?

Yes: threading the existing owner assertion into the established commit guard fixes the missing check without creating another authority owner, and the limited subquery preserves existing rebuild decisions.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against e7dde047904e.

Labels

Label changes:

  • add P2: This repairs a bounded database-retirement race and excessive transcript preflight work without evidence of a widespread urgent outage.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The maintainer-authored PR is exempt from ordinary contributor proof. The inspected native-worker and Gateway tests cover revoked restoration effects; reported SQLite timings cover only preflight performance. The authority-chain review found no unresolved introduced violation requiring additional final-effect proof.

Label justifications:

  • P2: This repairs a bounded database-retirement race and excessive transcript preflight work without evidence of a widespread urgent outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The maintainer-authored PR is exempt from ordinary contributor proof. The inspected native-worker and Gateway tests cover revoked restoration effects; reported SQLite timings cover only preflight performance. The authority-chain review found no unresolved introduced violation requiring additional final-effect proof.

Evidence

What I checked:

  • Current main still needs the repair: At fetched main, the history reader does not pass its database owner's assertion into restoration, and rebuild preflight aggregates every stored event before checking the row threshold. Neither related merged PR implements these remaining changes. (src/config/sessions/session-history-worker-runtime.ts:123, e7dde047904e)
  • Restoration preserves the existing authority owner: Restoration checks the supplied assertion before database access, after its queue wait, and through runColdMutation. That existing mutation owner composes caller authority with database-claim and mutation-lifetime checks at write admission and native commit authorization. (src/config/sessions/session-cold-storage.ts:358, 3b2ab0884f33)
  • Native commit settlement closes the authorization gap: The existing commit owner checks current authority before approving the shared commit gate, rejects failed authorization, and synchronously joins transaction settlement before releasing authority. The patch reuses this mechanism without changing its protocol. (src/config/sessions/session-accessor.sqlite-reclamation-commit.ts:108, 3b2ab0884f33)
  • Regression coverage checks final stored effects: The added Gateway cases invoke readChatHistoryPage, pause before restoration or inside the queue, close and replace the database, then assert rejection and unchanged cold descriptors/events. The cold-storage test injects revocation at the real worker commit callback and verifies rollback. Existing tests cover successful file-backed and embedded-archive restoration after reopening. (src/gateway/session-history-worker-lifecycle.test.ts:187, 3b2ab0884f33)
  • Bounded query preserves rebuild decisions: The subquery examines the remaining 4,000-row budget plus one sentinel row. Oversized transcripts still defer; transcripts within the row budget retain complete byte sizing against the unchanged 4 MiB threshold. Reconciliation reuses its latest-sequence observation within the existing transaction. (src/config/sessions/session-transcript-index.ts:91, 3b2ab0884f33)
  • Captured validation and its limits: The supplied PR body reports three restoration regressions failing before repair, 75 focused cases passing afterward, and 40 index/search cases passing after final cleanup. It also reports real SQLite component measurements on Node 26.8.2, including 1,000,000-event preflight decreasing from 63.543 ms to 0.360 ms. These are contributor-reported component results, not independently executed Gateway latency measurements. Review execution remained read-only; git diff --check passed and final git status was clean. (3b2ab0884f33)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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.

@steipete
steipete merged commit 35a7167 into main Sep 15, 2026
269 checks passed
@steipete
steipete deleted the codex/session-loader-audit-20260915 branch September 15, 2026 20:04
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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.

1 participant