Repository navigation
fix(gateway): prevent large history from blocking chat startup - #124994
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 17, 2026, 2:37 AM ET / 06:37 UTC. ClawSweeper reviewWhat this changesThe PR bounds SQLite transcript-history reads and adds a shared asynchronous Claude CLI snapshot so large local histories do not stall concurrent Gateway chat startup. Merge readinessNo blocking correctness finding. This maintainer-owned PR remains necessary: current main still synchronously reads and parses bound Claude CLI history and materializes SQLite boundary payloads before recent-history byte selection. Priority: P1 Review scores
Verification
How this fits togetherGateway chat history combines the local SQLite transcript with an optional bound Claude CLI transcript before returning startup and history pages to connected clients. The changed code selects the local page, imports external history once, merges both sources, and projects the response. flowchart LR
A[Connected chat clients] --> B[Gateway history reader]
B --> C[SQLite active transcript]
B --> D[Claude CLI snapshot]
C --> E[Bounded history selection]
D --> F[Redacted imported messages]
E --> G[Merged chat history]
F --> G
G --> H[Startup or history response]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +405, Tests +601, Docs 0, Other 0. Total +1006 across 11 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the server-owned asynchronous snapshot as the single external-history path, retain the embedded stub's synchronous contract, and land after exact-head validation confirms the bounded SQLite and concurrent Gateway regressions. Do we have a high-confidence way to reproduce the issue? Yes, from source: current main synchronously reads, splits, and parses the complete bound Claude JSONL transcript on the Gateway history path; this read-only review did not execute the reproduction. Is this the best way to solve the issue? Yes. Moving external-history work to a server-owned prepared snapshot fixes the blocking owner while retaining the synchronous embedded-runtime contract and avoiding duplicate reads during a request. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against ac5c8be00196. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (7 earlier review cycles)
|
8007c16 to
3e88261
Compare
3295073 to
4ea8062
Compare
4ea8062 to
f77d4cd
Compare
f77d4cd to
470729d
Compare
Apply SQLite byte limits before loading history payloads and share a yielded, fingerprinted Claude CLI snapshot across concurrent startup clients. Preserve marker, cursor, redaction, and external identity semantics, and clarify that shrink-only ratchet updates need no separate approval.
470729d to
a9d3056
Compare
|
Merged via squash.
|
Refreshes the merge head after main's chat-history read-path changes (openclaw#124994, openclaw#125123). Conflict resolution: - cli-session-history.ts: take main's async snapshot/augment helpers. This PR originally deleted them as embedded-only duplicates; main's canonical page reader (chat-history-pages.ts) is now their consumer. - embedded-gateway-stub.ts: keep the canonical readChatHistoryPage delegation and its pagination/budget handling; drop main's inlined offsetPage arithmetic, which belonged to the reader this PR removes. - embedded-gateway-stub.test.ts: drop main's new offset-continuation case, which mocks readRecentSessionMessagesWithStatsAsync (removed from the embedded runtime facade here). The equivalent assertion runs through the canonical reader in the retained budgeted-page test.
…law#124994) * fix(gateway): bound startup history materialization Apply SQLite byte limits before loading history payloads and share a yielded, fingerprinted Claude CLI snapshot across concurrent startup clients. Preserve marker, cursor, redaction, and external identity semantics, and clarify that shrink-only ratchet updates need no separate approval. * test(browser): await all lazy command groups * fix(gateway): bound history snapshot state * fix(gateway): preserve oversized history responsiveness
What Problem This Solves
Fixes an issue where opening chat with a large SQLite transcript or a bound Claude CLI history could block Gateway startup/history responses. Multiple clients connecting together multiplied the Claude JSONL read and parse work, while SQLite could parse large
event_jsonpayloads before applying the response byte limit.Why This Change Was Made
SQLite history now selects a contiguous suffix from metadata and serialized byte lengths before materializing message or reset/compaction payloads. The recent-tail metadata query reads only the newest
maxMessagescandidates, whose public cap remains below SQLite's bind-variable limit. Reset/compaction payloads are fetched through one event-sequence range joined back to the active-event projection, avoiding both unbounded bindings and abandoned-branch payloads.Claude CLI history is streamed through a process-owned, strong-fingerprint single-slot snapshot with event-loop yields and cross-client singleflight. Oversized records are parsed in a worker: supported user/assistant records retain their role, external ID, timestamp, and bounded metadata through a visible placeholder, while unsupported external record types remain ignored. Messages are coalesced and redacted before the shared snapshot is frozen; each caller receives isolated clones. A request reuses the same snapshot for both the recent-tail and full-local merge.
The synchronous import API is intentionally retained for
embedded-gateway-stub, whose injected runtime contract is synchronous. The server Gateway path never performs the external read through that API: it supplies the prepared async snapshot. Both paths share the same parser, tool-call coalescing, reseed, and redaction helpers so their semantics cannot drift independently.The existing external IDs, reseed handling, redaction, marker ordering, cursor behavior, and terminal imported-snapshot contract remain unchanged. The assertion-safety ratchet is lowered for two removed assertions, and the contributor guidance now records that exact shrink-only ratchet maintenance needs no separate approval.
The PR also repairs a current-main browser test failure exposed by the broad exact-head matrix: eager lazy-registration coverage left two newer command groups real and tore down while their OAuth imports were loading. The test now mocks and awaits every declared group.
User Impact
Chat startup remains responsive with large histories and concurrent clients instead of serially blocking the Gateway event loop. History content and pagination behavior are unchanged.
Release note: Prevent large local or Claude CLI histories from blocking chat startup.
Evidence
SyntaxErrorthroughreadVisibleHistoryRange).too many SQL variables: the widened recent-tail metadata query and the boundary payload query.JSON.parse; the fixed path parses it in a worker and preserves supported record identity through a bounded placeholder.src/agents/tools/embedded-gateway-stub.ts; server history passespreparedImportedMessagesfrom the async snapshot owner.check:changed: green across formatting, production/test types, lint, dead exports, import cycles, database guards, extension tests, and ratchets. Remote delegation was unavailable (Blacksmith readiness failure and Daytona memory quota), so trusted-source fallback ran on the prepared local checkout.AI-assisted; implementation and proof reviewed by the maintainer.