

























@@ -44,6 +44,10 @@ function resolveMaxToolResultChars(opts?: { maxToolResultChars?: number }): numb
4444return Math.max(1, opts?.maxToolResultChars ?? DEFAULT_MAX_LIVE_TOOL_RESULT_CHARS);
4545}
464647+// `details` is runtime/UI metadata, not model-visible tool output. Keep the
48+// session JSONL useful for debugging without letting metadata blobs dominate
49+// disk, replay repair, transcript broadcasts, or future tooling that reads raw
50+// sessions. Model-visible text belongs in tool result `content`.
4751const MAX_PERSISTED_TOOL_RESULT_DETAILS_BYTES = 8_192;
4852const MAX_PERSISTED_DETAIL_STRING_CHARS = 2_000;
4953const MAX_PERSISTED_DETAIL_SESSION_COUNT = 10;
@@ -102,6 +106,9 @@ function buildPersistedDetailsFallback(
102106originalSize: BoundedJsonUtf8Bytes,
103107sanitizedBytes?: number,
104108): Record<string, unknown> {
109+// If even the structured summary is too large, keep only shape and stable
110+// status fields. This preserves "what happened?" without persisting the raw
111+// diagnostics payload that caused the cap to trip.
105112const fallback: Record<string, unknown> = {
106113persistedDetailsTruncated: true,
107114finalDetailsTruncated: true,
@@ -150,6 +157,8 @@ function sanitizeToolResultDetailsForPersistence(details: unknown): unknown {
150157if (details === undefined || details === null) {
151158return details;
152159}
160+// Measure with an early-exit walker so hostile or enormous details do not
161+// need to be fully stringified just to learn they exceed the persistence cap.
153162const originalSize = boundedJsonUtf8Bytes(details, MAX_PERSISTED_TOOL_RESULT_DETAILS_BYTES);
154163if (originalSize.complete && originalSize.bytes <= MAX_PERSISTED_TOOL_RESULT_DETAILS_BYTES) {
155164return details;
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。