Repository navigation
fix(gateway): honor requested session preview length - #125201
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Codex review: needs maintainer review before merge. Reviewed August 23, 2026, 1:36 AM ET / 05:36 UTC. ClawSweeper reviewWhat this changesThe PR changes shared session-preview truncation so explicit caller budgets can reach a bounded 800 characters while omitted budgets retain the 240-character default. Regression provenancePossible regression — probable (reviewed change; failure trace). No predecessor PR is attributed. Merge readinessNo blocking findings. Current main still unconditionally caps explicit preview budgets at 240, while the PR repairs that at the shared projection owner and preserves the default; refresh the clean merge result and required checks against current main before landing. Priority: P2 Review scores
Verification
Live VerificationCommand: Result: FAIL (partial) — step 2 Assertions:
How this fits togetherGateway converts persisted session transcripts into filtered, UTF-16-safe snippets for session-preview RPC calls and Browser Talk startup context. Callers supply a per-item budget, and the shared projection returns bounded visible text to those consumers. flowchart LR
A[Persisted session transcript] --> B[Transcript reader]
C[RPC or Browser Talk budget] --> B
B --> D[Shared display projection]
D --> E[Visibility filtering]
E --> F[UTF-16-safe bounded text]
F --> G[Session preview RPC]
F --> H[Browser Talk context]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +2, Tests +48. Total +50 across 3 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Land the shared-owner repair after a current-main merge and exact-head gate refresh, keeping the 240 default, the 800 per-item ceiling, and Browser Talk’s independent total-byte ceiling. Do we have a high-confidence way to reproduce the issue? Yes. Current main forwards explicit maxChars through sessions.preview and Browser Talk but the shared projection caps it at 240; the PR also supplies after-fix Gateway proof. Is this the best way to solve the issue? Yes. Repairing the shared projection is the narrow canonical fix because both RPC and Browser Talk reach it; changing either consumer would duplicate truncation policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against f5553a8fee0e. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (8 earlier review cycles)
|
|
Nudge: This PR has been awaiting review for over 3 hours. |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review Exact head: |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
Maintainer landing verification for exact contributor head
Contributor credit remains with @Alix-007. |
* fix(gateway): honor session preview length * fix(gateway): cap session preview budgets
Refs #124997
What Problem This Solves
Fixes an issue where
sessions.previewcallers requesting more than 240 characters would still receive only 240 after the shared display projection landed in #124997. Browser Talk also requests 800 characters per initial context item, so the same cap silently discarded context there.Why This Change Was Made
The shared projection treated 240 as an unconditional ceiling even though its
maxCharsoption represents a caller-owned budget. The projection now uses 240 only when the option is omitted and honors an explicit valid budget at the canonical owner.This deliberately does not address the separate first-user title-source finding from #124997. Alternatives rejected: raising the global default, compensating in the RPC handler, or creating a second preview projection would change unrelated consumers or duplicate policy.
Credit to @steipete for #124997 and to its exact-head ClawSweeper review for identifying the remaining preview-budget regression.
User Impact
Session preview consumers can request the amount of visible context they need. Existing callers that omit
maxCharskeep the 240-character default, while Talk and RPC callers using an explicit larger budget receive it without losing UTF-16 safety or visibility filtering.Evidence
node scripts/run-vitest.mjs src/gateway/session-display-projection.test.ts src/gateway/server.sessions.preview-resolve.test.tsran 15 tests; the new unit and real SQLite RPC regressions were the only two failures, each receiving 240 instead of 800.076a8cc616366: the projection unit, SQLite RPC, and Talk sibling suites pass together, 3 files and 81 tests.git diff --check, dirty autoreview, and an independent read-only Codex review are clean with no actionable P0/P1 findings.packages/terminal-core/src/ansi.tsand the missing local@openclaw/session-url-contract/parselink); exact-head CI is the authoritative full type gate.Real SQLite and Gateway preview proof
bd69181013ac983d934da5945825cf0b9335be3ein proof run 32030179825, which completed successfully on Node 24 in 8m09s.operator.readWebSocket client forsessions.preview.{ maxChars: 800 }returned one visible assistant item with exactly 800 UTF-16 code units; omittingmaxCharsretained the 240-unit default; the surrogate-boundary fixture returned 239 units without an unpaired surrogate. The seeded tool-result rows remained excluded.pr125201-session-preview-real-gateway-proof-32030179825-1, archive digestsha256:c7c89446013f9428cfd8ac507bbfd0ae2fedb5c716214ad2240e1e444d0b4573. Downloaded hashes independently revalidated:result.json543d573525f2f2682358137f0dce256ef86eb581b957df1f02f8cd589e68f1ed; fullrpc-responses.json34c44ea8c464f3ca10cc87cbeeb7f430a0bd723a063ff45ec8717d9eb79429cc;run.log008c2cf66761915a3bde0c54ed97c97e5ec72164cdfd176f0b318b6320547984.alix/proof-125201; the PR code/head was not changed.Oversized preview-budget exact-head proof
Exact repair head:
218fd13185c3945cf8c371a6c6ed4a81a7de5053(unchanged).On 2026-08-21, the exact head passed a clean, isolated direct-local-Docker fallback run on Node 24.19.0. The container used the default seccomp profile, had no host mounts, and received no credential-bearing environment variables. This is local Docker evidence, not AWS/Testbox remote proof.
The one-shot harness used production
upsertSessionEntryCoreandpersistSessionTranscriptTurnwriters to create the real per-agent SQLite database, verified theSQLite format 3\0header atagents/main/agent/openclaw-agent.sqlite, started a real child Gateway, completed token-authenticated WebSocket hello asoperatorwithoperator.read, and invokedsessions.previewthrough the public RPC path.Observed result:
maxChars: 50000: exactly 800 UTF-16 code units, one visible assistant item, tool-result row excluded, no unpaired surrogate.maxChars: 800: exactly 800 code units.6782691da61336d6e876477dd50c3412da4e5fd9e0b767607168c1138a514d95.Sanitized exact-head
result.json{ "schemaVersion": 1, "verdict": "PASS", "head": "218fd13185c3945cf8c371a6c6ed4a81a7de5053", "runtime": { "node": "v24.19.0", "platform": "linux" }, "storage": { "engine": "SQLite", "agentId": "main", "databaseRelativePath": "agents/main/agent/openclaw-agent.sqlite", "sqliteHeader": "SQLite format 3\\0", "seededSessionEntries": 1, "seededTranscriptRows": 2 }, "gateway": { "childProcess": true, "bind": "loopback", "transport": "WebSocket", "authMode": "token", "authenticatedHello": true, "clientRole": "operator", "scopes": [ "operator.read" ], "method": "sessions.preview" }, "oversizedRequest": { "requestedMaxChars": 50000, "sourceCodeUnits": 1600, "returnedCodeUnits": 800, "expectedCap": 800, "visibleItems": 1, "excludedToolRows": 1, "utf16Safe": true, "returnedTextSha256": "cc1d624a46c2851322146c60f5260b4feae912d4716daae54512d4065cfa1fda", "response": { "key": "agent:main:proof:preview-cap", "status": "ok", "items": [ { "role": "assistant", "text": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa..." } ] } }, "controls": { "explicit800ReturnedCodeUnits": 800, "omittedBudgetReturnedCodeUnits": 240 }, "redaction": { "omitted": [ "gateway token", "port", "pid", "hostname", "absolute paths" ] } }