fix: page sessions_history beyond truncated tails#97101
Conversation
|
Codex review: needs maintainer review before merge. Reviewed June 27, 2026, 6:17 PM ET / 22:17 UTC. Summary Reproducibility: yes. at source level: current main exposes no Review metrics: 1 noteworthy metric.
Stored data model Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Land the bounded offset-pagination subset after maintainer acceptance of the public API shape, while leaving readable full-history export tracked on #90981. Do we have a high-confidence way to reproduce the issue? Yes, at source level: current main exposes no Is this the best way to solve the issue? Mostly yes for the bounded pagination subset: adding pagination at the tool/Gateway layer preserves the sanitized history surface and avoids raw transcript export. The exact public API shape still needs maintainer acceptance, and readable full-history export remains separate. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 36722014efa3. Label changesLabel justifications:
Evidence reviewedWhat I checked:
Likely related people:
What the crustacean ranks mean
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. How this review workflow works
|
galiniliev
left a comment
There was a problem hiding this comment.
Manual review confirms the existing pagination blocker.
Finding:
- [P1]
sessions_historyforwards GatewaynextOffset/hasMoreafter applying its ownincludeToolsfiltering, sanitization, and 80 KiB cap (src/agents/tools/sessions-history-tool.ts:296,src/agents/tools/sessions-history-tool.ts:319). The PR correctly moves Gateway continuation metadata after Gateway byte budgeting, but the model-facing tool then returnshardened.items; if that tool cap drops older rows from the page, callers advance past rows they never received. Please recompute continuation from the final tool-visible messages or keep fetching until the tool can return a bounded page with accurate continuation metadata, and add a regression for a cappedsessions_historyoffset page.
Best-fix verdict: close, but not merge-ready. The Gateway-level pagination shape is plausible and well covered; the model-facing tool still needs to make its own pagination metadata match the exact payload it returns.
galiniliev
left a comment
There was a problem hiding this comment.
Manual follow-up review after 9800182da1:
Findings:
-
[P1] Regenerate protocol clients after adding
chat.history.offset—packages/gateway-protocol/src/schema/logs-chat.ts:35
The PR addsoffsettoChatHistoryParamsSchema, but the generated protocol artifacts were not committed. CI'schecks-fast-bundled-protocolrunspnpm protocol:gen && pnpm protocol:gen:swift && git diff --exit-code ...and now fails becauseapps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swiftstill lacksChatHistoryParams.offsetand its coding key. This leaves native/shared protocol clients out of sync with the Gateway schema. Regenerate and commit the protocol output. -
[P1] Fix lint errors in the new gateway pagination tests —
src/gateway/server.chat.gateway-server-chat-b.test.ts:3212
CIcheck-lintfails on the new directmessage.__openclaw?.seqassertions at lines 3212, 3230, and 3282 witheslint(no-underscore-dangle). These test assertions need to use a small helper or bracket access so the required lint lane passes.
The earlier pagination-metadata finding is addressed by 9800182da1: sessions_history now recomputes continuation from final tool-visible messages after filtering/capping and preserves seq metadata on the oversized placeholder path. I did not find another runtime correctness blocker in the pagination implementation after reading the Gateway reader/projection path, embedded stub parity path, tool wrapper, docs, and focused tests.
Proof checked: live CI logs for checks-fast-bundled-protocol and check-lint, PR diff against origin/main, scoped AGENTS docs, src/gateway/server-methods/chat.ts, src/gateway/session-utils.fs.ts, src/gateway/session-transcript-readers.ts, src/agents/tools/sessions-history-tool.ts, src/agents/tools/embedded-gateway-stub.ts, and adjacent tests/docs.
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@clawsweeper re-review |
0cab379 to
b4d4c26
Compare
|
Merged via squash.
|
Related: #90981
What Problem This Solves
Fixes an issue where parent agents using
sessions_historycould only inspect the newest bounded tail of long child sessions. When that tail was truncated or started inside late-session context, there was no supported way to page backward through older transcript windows without reading raw JSONL files.Why This Change Was Made
This adds explicit
offsetpagination tosessions_historyand Gatewaychat.history, returningoffset,nextOffset,hasMore, andtotalMessagesmetadata for explicit offset requests. The implementation keeps the existing no-offset newest-tail behavior, keeps display sanitization and byte caps, computes continuation from the final returned page boundary, overreads one context row for stale announce-pair filtering, and keeps offset pages scoped to OpenClaw transcript windows instead of merging whole external CLI fallback imports into every page.This does not add a readable full-history export surface; #90981 should remain open for that broader product/API decision if maintainers still want it.
User Impact
Agents and operators can now call
sessions_historywithoffset: 0, then follownextOffsetto page backward through long child-session transcripts. This makes recovery and audit workflows deterministic while preserving the bounded, redacted history view.Evidence
Before evidence:
Behavior addressed:
sessions_historyand Gatewaychat.historynow support explicit offset pagination for bounded, sanitized OpenClaw transcript windows.Real environment tested:
Local OpenClaw source checkout in a Codex worktree on Linux/WSL2, Node/pnpm dependencies already installed. Real live recovery logs from June 26, 2026 were used as before-fix evidence; no live provider replay was run after the patch because the bug is in local transcript pagination/schema handling before model generation.
Exact steps or command run after this patch:
Evidence after fix:
Observed result after fix:
Focused tests cover
offsetvalidation and forwarding, first-pagenextOffset, nonzero page reads, stale announce-pair boundary overread, final byte-budget cursor calculation, embedded gateway parity, protocol schema acceptance, and docs/tool metadata updates. The final autoreview found no accepted/actionable findings.Follow-up evidence for the P1 review finding:
Azure Crabbox real-history proof for the P1 review finding:
The behavior harness seeded an isolated OpenClaw state directory with a 64-row transcript, invoked the real
sessions_historytool through embedded Gatewaychat.history, followed returnednextOffsetvalues for five pages, and verified each page covered the expected older transcript window without skipping rows.What was not tested:
No live provider replay was run after the patch because this fix is local transcript pagination behavior before model generation. The requested real transcript pagination behavior was verified on Azure Crabbox with an isolated seeded OpenClaw state directory and the real sessions_history -> embedded Gateway chat.history path.