fix(agent): clamp provider context images#3232
Conversation
Dropped oldest outgoing image blocks above the active provider budget so umans requests honor the shipped 10-image cap even when snapcompact is disabled. Added regression coverage for preserving text and newest images.\n\nFixes #3230
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: eb88ecd7bb
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const content = clampContent(message.content, state); | ||
| return content ? { ...message, content } : message; |
There was a problem hiding this comment.
Preserve a placeholder for fully dropped tool-result images
When an older successful tool result contains only images, dropping all image parts here returns content: []. I checked the Anthropic/umans conversion path: buildToolResultBlock() only fills empty content for isError results, so once the provider budget is exceeded an image-only successful tool result is serialized as an empty tool_result rather than a textual omission marker. Add a placeholder text block when the clamp removes the last tool-result block so the request stays meaningful and protocol-safe.
Useful? React with 👍 / 👎.
Added a textual omission marker when provider image clamping removes every block from a successful tool result, keeping the serialized tool_result meaningful and protocol-safe.\n\nFixes #3230
|
Added a |
Repro
A focused regression test that imports
clampProviderContextImagesand builds a 31-imageumanscontext failed before the fix because@oh-my-pi/pi-coding-agent/session/provider-image-budgetdid not exist:bun test packages/coding-agent/test/session/provider-image-budget.test.tsexited 1 withCannot find module '@oh-my-pi/pi-coding-agent/session/provider-image-budget'.Cause
packages/snapcompact/src/snapcompact.tsshippedproviderImageBudget("umans") === 10, butpackages/coding-agent/src/sdk.tsonly installedtransformProviderContextwhen secret obfuscation or snapcompact inline imaging was enabled. No coding-agent request path clamped existing image blocks, so live contexts with more than 10 images could still be sent unchanged toumans.Fix
packages/coding-agent/src/session/provider-image-budget.tswithclampProviderContextImages(), which preserves text and the newest images while dropping oldest image blocks above the active provider cap.packages/coding-agent/src/sdk.tsto always run the provider-context transform and apply the clamp after obfuscation and snapcompact inline transforms.packages/coding-agent/test/session/provider-image-budget.test.tscoverage for the 31-imageumansregression and the below-budget no-op case.umans#3230.Verification
bun test packages/coding-agent/test/session/provider-image-budget.test.tspassed with 2 tests;bun run --cwd packages/coding-agent checkpassed. Fixes #3230