#8360: Gateway: cap oversized transcript entries
app: web-ui
gateway
stale
## Problem
OpenClaw session transcripts (JSONL) can be bloated by very large message/tool-result payloads (e.g. data URLs / screenshots), which later causes oversized history/context payloads and request failures.
## Fix
Add a small gateway-side guard that caps a *single transcript JSONL entry* (default used here: 128KB). If an entry exceeds the cap, we:
- write the full JSON entry to an artifact file under `artifacts/transcript-blobs/<sha256>.json` adjacent to the transcript
- replace the transcript entry with a pointer + short preview
This preserves continuity (pointer + hash) while preventing session JSONL bloat.
## Scope
Wires the guard into gateway transcript append paths in `src/gateway/server-methods/chat.ts` (assistant transcript append helper + `chat.inject`).
## Tests
Adds `src/gateway/transcript-sanitize.test.ts` covering passthrough + elision + artifact write.
## Notes
- Artifact path is local-only and intended for operators/debugging.
- The cap is hardcoded in this PR; happy to move to a config knob if preferred.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR adds a gateway-side guard to cap the size of individual JSONL transcript entries (defaulting to 128KB). Oversized entries are written in full to a sidecar artifact file (keyed by sha256), and the transcript line is replaced with a small pointer/preview payload to prevent transcript bloat and downstream request failures. The guard is wired into both assistant transcript appends and `chat.inject`, and includes a new Vitest suite that verifies passthrough behavior and artifact creation for oversized message entries.
<h3>Confidence Score: 4/5</h3>
- This PR is reasonably safe to merge; changes are localized and covered by unit tests.
- Core behavior is additive and focused on transcript writing paths, and the sanitizer is small and deterministic. Main remaining concerns are operational (sync fs + repeated mkdir) and information leakage (embedding absolute artifact paths in transcript entries).
- src/gateway/transcript-sanitize.ts; src/gateway/server-methods/chat.ts
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#20394: feat(gateway): make chat history byte limit configurable via gatewa...
by mgratch · 2026-02-18
77.8%
#16015: fix(gateway): truncate oversized message content in chat.history re...
by fagemx · 2026-02-14
76.7%
#20381: feat(gateway): make chat history byte limit configurable via `gatew...
by mgratch · 2026-02-18
75.4%
#16006: fix(gateway): reduce chat.history byte cap from 6 MB to 2 MB
by fagemx · 2026-02-14
75.1%
#10915: fix: prevent session bloat from oversized tool results and improve ...
by DukeDeSouth · 2026-02-07
74.6%
#15050: fix: transcript corruption resilience — strip aborted tool_use bloc...
by yashchitneni · 2026-02-12
74.2%
#12296: security: persistence-only secret redaction for session transcripts
by akoscz · 2026-02-09
74.1%
#8713: feat: gateway memory monitor, install linger, docs and failover
by quratus · 2026-02-04
74.0%
#16330: fix(gateway): preserve conversation history on gateway restart
by openperf · 2026-02-14
73.7%
#12635: Gateway: add inbound webhook dispatch framework
by jhs129 · 2026-02-09
73.6%