Repository navigation
perf(agent-runtime): bound inlined image history to prevent V8 sidecar heap exhaustion - #1105
Conversation
ce42e54 to
91486c0
Compare
…r heap exhaustion
91486c0 to
58c9f92
Compare
vastsa
left a comment
There was a problem hiding this comment.
Please address the two runtime correctness gaps noted inline. The targeted attachment-history tests pass, but they do not cover either case.
| } | ||
| } | ||
| const eligibleIndices = new Set( | ||
| userMessagesWithAttachmentsIndices.slice(-maxInlinedImageMessages) |
There was a problem hiding this comment.
[P1] Bound aggregate image bytes, not just the number of messages. A recent user message can contain multiple images, and the composer/main preparation paths iterate all imported attachments without a total count/byte cap. Since each eligible image up to MAX_INLINE_IMAGE_BYTES is still read and base64-encoded, five messages can still allocate an arbitrarily large aggregate payload and hit the same sidecar OOM. Please enforce a cumulative hydration byte budget (and cover many images in one message with a regression test).
| return { attachment }; | ||
| } | ||
| const shouldInline = attachment.kind === "image" && supportsVision; | ||
| const shouldInline = allowInlining && attachment.kind === "image" && supportsVision; |
There was a problem hiding this comment.
[P2] Preserve image context for replayed historical turns. Editing a user turn truncates the transcript at that turn and rebuilds runtime history from the kept prefix. For images outside this five-message window, historyToEntries() only emits image blocks when attachment.data exists; the @path fallback added here remains literal text, so those prior images silently disappear from the provider context. Please hydrate images that actually enter the replayed model context (or otherwise preserve their vision payload) and add an edit/regenerate regression test.
…yed image context
|
Thanks for the precise review! Addressed both points:
|
Summary
Bounds in-memory base64 image inlining in
hydrateAttachmentHistory(packages/agent-runtime/src/attachment-history.ts), addressing the root cause of V8 sidecar heap exhaustion and OOM crashes during historical message edits on large sessions (#1077).Motivation & Root Cause
In issue #1077, editing or regenerating an earlier message on a large session (e.g. 300+ messages, multi-megabyte context) reliably causes sidecar V8 heap exhaustion (
Reached heap limit Allocation failed - JavaScript heap out of memory, 2048 MB cap).While PR #1080 classified the resulting crash as
AGENT_SIDECAR_OOM, the underlying allocation problem remained:hydrateAttachmentHistoryindiscriminately read and base64-encoded every historical image attachment across the entire transcript into V8 memory viabytes.toString("base64").ref) and fallback file paths are already safely preserved and format-inserted.Key Changes
packages/agent-runtime/src/attachment-history.ts):maxInlinedImageMessages(default: 5) toAttachmentHistoryContext.packages/agent-runtime/src/attachment-history.test.ts):Verification
pnpm --filter @pi-desktop/agent-runtime test src/attachment-history.test.ts(2/2 passing).pnpm lint:biome(all files clean).pnpm run build:js(all workspace packages compiled successfully).