Skip to content

fix(chat): recover history reads across resets and rebuilds - #159163

Merged
steipete merged 6 commits into
mainfrom
steipete/perf-micro-chat-history-rebuilding-refusals-20260919
Sep 26, 2026
Merged

steipete merged 6 commits into
mainfrom
steipete/perf-micro-chat-history-rebuilding-refusals-20260919

Conversation

@steipete

@steipete steipete commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes repeated chat.history refusals when a transcript reset or replacement invalidates an in-progress read window, and immediate refusals while a scheduled projection rebuild can still finish.

User Impact

History returns a coherent page from the current window and a fresh continuation token. A lost anchor falls back to the tail with windowReset; Control UI replaces obsolete rows and adopts the returned deltaCursor. Missing active projections get one cancellable wait of up to three seconds before a refusal. Embedded sessions_history also receives the recovered offset, continuation, and reset marker.

Why This Change Was Made

SQLite readWindow is internal continuity state across snapshots within one request. The browser's separate cursor/reset contract is in packages/gateway-protocol/src/schema/logs-chat.ts; ui/src/pages/chat/chat-history-hydration.ts clears reset cursors and adopts returned deltaCursor values.

The accessor resolves stale windows against current history. Page assembly discards old chunks and restarts once; UI, SSE, and embedded-tool owners retire obsolete continuation state. Remaining window-change failures have a distinct message. Image pagination retains its invalid-cursor/restart contract because its cursors also address images within a message. The async history-worker owner waits after a failed snapshot unwinds, retaining its authority and cancellation checks; read-only catalogs do not initiate writes.

No configuration, cache, database-schema, retention, or permission changes. Net production growth is 182 lines: the 150-line guideline is exceeded to carry the result through all affected continuation owners without leaving competing behavior.

Evidence

Fixture Original Candidate
Retained-anchor reset, lost-anchor reset, replacement 3 refusals 0 refusals; returned token continues successfully
Multi-read branch/reset continuity 2 refusals 0 refusals; no mixed-window page
Real SQLite missing-projection request Immediate refusal Original request returns recovered history
UI tail/backscroll replacement 2 failing cases Both pass; next request uses new cursor
Embedded tool recovery Old offset 2, false exhaustion, no marker Offset 0, continuation 1, reset marker; valid output schema
Rebuild deadline/cancellation Immediate refusal Pending at 2,999 ms, bounded at 3,000 ms; cancellation preserved

All heavy validation used blacksmith-testbox, profile openclaw-check. No local test suites, builds, typechecks, browser automation, or live Gateway changes.

  • Original readers were restored temporarily on Testbox for negative controls; candidates were restored before positive checks.
  • node scripts/run-vitest.mjs passed the focused history/window/projection, worker/error/readiness, readonly/SSE, public chat-cursor, and artifact-image suites. The refreshed broad focused run passed 258 tests, with one existing opt-in benchmark skipped, on tbx_01m3fq6kqzc8pdqeemj0cn3zfs.
  • Embedded adapter/tool coverage passed 64 tests, plus core/agent-tool typechecks and targeted lint, on tbx_01m3ftjaw9mkygv2tvt46kq276.
  • Published head 7a233c5dfaf960f11fd6ae1f3b04c0a1fe2160bf passed another 79 lifecycle/source/worker tests and 64 adapter/tool tests, core typechecking, and targeted lint on tbx_01m3fw49wwgh4r82psbhd4vgr7 (180.9 s including sync/setup).
  • The initial node scripts/check-changed.mjs --base 8d8bd43120f3acd7e9e596e4d12774c442000703 passed production/UI types, all 25 test typecheck groups, dead-export scans, and preceding guards. Five lint findings were fixed; affected types were rechecked and the existing planner resumed from lint through all remaining gates successfully. Main refreshes received fresh affected proof and review.
  • Independent Codex reviews through P2 are scoped-clean. Completed Testbox leases are stopped.

Per-file measured cost (pnpm test <file> --maxWorkers=1, initial validation lease tbx_01m3fm4tcy8et8zbhd18g4vbe3):

Test file CLI wall
session-accessor.sqlite-history-window.test.ts 24 s (0.229 s tests; cold worker preparation)
session-history-reads.test.ts 13 s
session-history-state.test.ts 7 s
session-history-worker-runtime.test.ts 8 s
session-history-worker.integration.test.ts 36 s
session-history-worker-errors.test.ts 8 s

The integration file's real SQLite/worker lifecycle scenarios account for its cost; the new recovery case requires the real worker/reconcile boundary. UI pagination/cursor suites measured 4.53 s / 2.98 s Vitest wall. The three adapter/tool files measured 22.82 s Vitest / 24.56 s wrapper wall together; the new composition case took 173 ms.

CI and limits

CI exposed an initial registry-discovery race. The canonical repair subsequently landed in main commit 3d903819c564; this PR adopts it and has no separate registry production/test delta. The preceding CI run 36273244444 passed. The subsequent run 36275157554 then exposed a test teardown race: session-group-mutation-targets.test.ts closed shared state before asynchronous agent cleanup settled. The test-only ordered-await repair passed 3/3 original-shard runs and 20/20 standalone file runs on tbx_01m3fx56gqddzp8c2xx6r6g8rg, plus focused typechecking, lint, and independent review. Unchanged-code shard/file replays both passed, so those replays did not reproduce the intermittent failure; the source lifecycle shows the missing settlement ordering. Production identity guards and assertions remain unchanged. The lease is stopped. The fixture measured 18.31 s Vitest / 20.18 s wrapper wall, with 4.199 s test time.

An existing branch-continuation test had masked an unfinished projection before reaching stale-window validation. On the initial base, diagnostics showed indexed sequence 7/raw sequence 8 with needs_rebuild=1, with or without a session entry. The continuity fixture now explicitly completes that synthetic branch through the canonical reconcile function; this PR does not claim to fix that separate deferred-reconcile observation or demonstrate a live production CPU/latency improvement.

Testbox setup required frozen dependency installation and replacement leases after native checksum-sync timeouts. The first unpinned changed-check used stale remote origin/main; pinned-base proof owns validation. Final head 20ead5da8c3c659c12f28e47f1d5f7e4bd27d20c passed CI run 36277843970: all 164 jobs succeeded in 880 seconds (14m40s), including both required openclaw/ci-gate results. All owned Testbox leases are stopped. The requested auto-merge attempt was rejected by the installed gh shim with string rewrite protection blocked unsafe input; no second merge request was issued from this lane. GitHub subsequently recorded the PR merged by steipete at 2026-09-26 23:11:16 UTC as d9fd43d6cf4286e1734e4a6ff91b962cb3e35e82; ancestry against current main is verified.

@clawsweeper

clawsweeper Bot commented Sep 26, 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 app: web-ui App: web-ui gateway Gateway runtime size: L labels Sep 26, 2026
@clawsweeper clawsweeper Bot added 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. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 26, 2026
@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 26, 2026, 7:07 PM ET / 23:07 UTC (Revision 6).

ClawSweeper review

What this changes

The branch recovers chat-history pages after transcript resets or projection rebuilds and carries replacement-page cursors through the Gateway, embedded history tool, and Control UI.

Merge readiness

⛔ Blocked before merge - 2 items remain

Current main still refuses history reads when a transcript window changes. This PR provides a coherent recovery path, and no introduced code defect was established. The Control UI reset state still needs the repository-required before/after screenshots before merge.

Priority: P1
Reviewed head: 20ead5da8c3c659c12f28e47f1d5f7e4bd27d20c

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The owner-level repair has focused integration coverage, while the changed visible chat state still lacks its required before/after demonstration.
Proof confidence 🦐 gold shrimp (3/6) Not applicable: Repository State identifies the author as a member, so the external-contributor proof gate does not apply. The PR reports Testbox before/after checks and adds a real SQLite-to-Gateway-reader integration case; Control UI coverage uses a mocked browser client, and the separate repository screenshot gate remains outstanding. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Repository State identifies the author as a member, so the external-contributor proof gate does not apply. The PR reports Testbox before/after checks and adds a real SQLite-to-Gateway-reader integration case; Control UI coverage uses a mocked browser client, and the separate repository screenshot gate remains outstanding. No stored-data contract changes.
Evidence reviewed 8 items Current main still refuses stale windows: The fetched main revision retains the assertion that rejects an invalidated history read window; the branch's recovery path is absent.
Recovery at the storage owner: The introduced page reader detects a changed window, rebases a retained anchor when possible, and returns a reset marker with a new read window.
Gateway page coherence: The Gateway discards a page assembled across different windows and retries once from the current tail.
Findings None None.
Security None None.

How this fits together

The Gateway reads per-agent SQLite transcript projections and serves history to chat clients and the embedded history tool. The Control UI turns those pages into a visible conversation and uses returned cursors to continue reading.

flowchart LR
  A[Stored transcript] --> B[SQLite history projection]
  B --> C{Window still current?}
  C -->|Yes| D[History page]
  C -->|No| E[Recovered page and cursor]
  D --> F[Gateway and embedded tool]
  E --> F
  F --> G[Control UI conversation]
Loading

Before merge

  • Resolve merge risk (P1) - The changed Control UI reset state has no inspected before/after screenshots in the originating chat and linked PR body, as required for UI changes by repository policy.
  • Complete next step (P2) - Provide inspected, sanitized before/after Control UI screenshots in the originating chat and in the PR body or a linked PR comment, showing history replacement after reset.
Agent review details

Security

None.

PR surface

Source +182, Tests +349, Docs +1. Total +532 across 33 files.

View PR surface stats
Area Files Added Removed Net
Source 22 253 71 +182
Tests 10 374 25 +349
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 33 628 96 +532

Review metrics

Metric Value Why it matters
Production and test growth production +182, tests +349 The PR body explains the production growth as carrying one recovery contract through the affected continuation owners.

Mantis proof suggestion

A before/after web UI chat capture could show whether a reset during backscroll replaces obsolete messages and preserves continued history loading. A maintainer can ask Mantis to capture proof by posting this exact PR comment:

@openclaw-mantis verify Control UI chat history after a reset during backscroll; capture redacted before/after transcript screenshots showing replacement and continued loading.

Merge-risk options

Maintainer options:

  1. Demonstrate the reset state (recommended)
    Capture inspected, sanitized before/after Control UI chat screenshots showing obsolete history replaced after a reset, and link the PR evidence from its body.

Technical review

Best possible solution:

Keep the storage reader as the continuity owner and have the UI replace obsolete history from the Gateway's recovered page; complete the visible reset demonstration before landing.

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

Yes. Current-main source rejects changed read windows, and the PR reports baseline refusals in focused Testbox negative controls; this read-only review did not rerun them.

Is this the best way to solve the issue?

Yes. The patch resolves continuity at the SQLite reader, retries mixed-window Gateway assembly once, and lets clients adopt the replacement cursor. Visible UI evidence remains required.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add merge-risk: 🚨 session-state: The PR changes how a stale history page replaces the visible conversation and its continuation cursor.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • remove proof: sufficient: Current real behavior proof status is not_applicable, not sufficient.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.

Label justifications:

  • P1: Repeated history refusals interrupt a current chat and backscroll workflow.
  • merge-risk: 🚨 session-state: The PR changes how a stale history page replaces the visible conversation and its continuation cursor.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Repository State identifies the author as a member, so the external-contributor proof gate does not apply. The PR reports Testbox before/after checks and adds a real SQLite-to-Gateway-reader integration case; Control UI coverage uses a mocked browser client, and the separate repository screenshot gate remains outstanding. No stored-data contract changes.

Evidence

What I checked:

Likely related people:

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

Rank-up moves

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

  • Add sanitized before/after Control UI screenshots showing reset recovery and continued history loading; redact private messages, endpoints, and credentials.

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 (5 earlier review cycles)
  • reviewed 2026-09-26T20:58:02.575Z sha aaeaf91 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-26T21:19:52.816Z sha aaeaf91 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-26T21:38:08.634Z sha d10b3bc :: needs maintainer review before merge. :: none
  • reviewed 2026-09-26T21:59:30.191Z sha c0ea473 :: blocked before merge. :: none
  • reviewed 2026-09-26T22:13:07.452Z sha 7a233c5 :: needs maintainer review before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Sep 26, 2026
@steipete
steipete enabled auto-merge (squash) September 26, 2026 21:52
@clawsweeper clawsweeper Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 26, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 26, 2026
@steipete

steipete commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor Author

The HTTP ingress stack hit the same session-group-mutation-targets.test.ts teardown failure in CI run 36275987134, job 108499434753, after its assertions passed. Three exact-job replays at CI's measured machine shape, toolchains, original groups, and effective two-worker overrides passed; those are non-reproductions, not proof of a fix.

Coordination update: your canonical ordered cleanup repair is now on main in d9fd43d6cf4286e1734e4a6ff91b962cb3e35e82. I inspected the explicit awaited agent/state finalizers and am adopting this version in the HTTP ingress stack. The separate extraction from dependency PR #158298 was not opened as a PR; its rebase was aborted and committed work is preserved. Verification now follows the landed owner repair, avoiding a duplicate cleanup implementation.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Sep 26, 2026
@steipete
steipete merged commit d9fd43d into main Sep 26, 2026
244 checks passed
@steipete
steipete deleted the steipete/perf-micro-chat-history-rebuilding-refusals-20260919 branch September 26, 2026 23:11
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 27, 2026
…#159163)

* fix(chat): recover history reads across resets and rebuilds

* fix(gateway): retry registry churn during history discovery

* fix(agents): preserve recovered history pagination

* test(gateway): await session group fixture cleanup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L 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