← Back to library

Exec 大输出防上下文爆炸:落库前截断与摘要化保护

用于“单次 exec 输出过大导致会话超 token 上限并不可恢复”场景。前置:能修改工具结果写入链路。步骤:在写入 session 前执行长度截断/摘要→保留原始输出到文件路径→在 transcript 仅记录摘要+引用→用 100KB+ 输出做回归。关键点:截断必须发生在会话写入前,而非仅 UI 事件流。验证:超大输出不再触发 prompt too long。风险:过度截断可能丢失排障细节。

GITHUBDiscovered 2026-02-15Author QiushiWu95
Prerequisites
  • You can patch or configure tool-result persistence behavior in your OpenClaw deployment.
  • You have a reproducible large-output command for regression testing.
Steps
  1. Reproduce with a known large-output exec call and capture the token-overflow failure signature.
  2. Apply truncation/summarization before session transcript write, not only in stream rendering.
  3. Persist full raw output outside transcript (file artifact/path) and store only pointer + summary in session.
  4. Run stress tests with 100KB-1MB outputs and confirm session remains usable.
Commands
openclaw status
openclaw gateway status
Verify

Large exec output no longer corrupts session context; follow-up prompts still execute normally.

Caveats
  • If only UI stream is truncated while transcript stores full text, this issue still reproduces.
  • Retention policy for full raw artifacts should be reviewed for privacy/compliance(需验证).
Source attribution

This tip is aggregated from community/public sources and preserved with attribution.

Open original source ↗
Visit original post