fix(agent): Request-limit-unrecoverable-thread#2078
Open
lost-particles wants to merge 3 commits intoPostHog:mainfrom
Open
fix(agent): Request-limit-unrecoverable-thread#2078lost-particles wants to merge 3 commits intoPostHog:mainfrom
lost-particles wants to merge 3 commits intoPostHog:mainfrom
Conversation
fix(agent): Request-limit-unrecoverable-thread Stop inlining workspace file bodies from ACP resources into Claude SDK user messages. For file:// on resource/resource_link, steer the model toward Read (offset/limit, PDF pages) and preserve attachment:// and other schemes. Update buildCloudPromptBlocks harness to use resource_link for text files. Add/adjust Vitest coverage for stripping inlined file text vs attachment parity.
Contributor
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #2048
Problem
Sometimes the prompt path was putting whole file bodies into the user message payload instead of only referencing paths:
resourcechunk used afile://URI, our conversion logic was takingresource.textand embedding it as a<context>...</context>block in the Claude Agent SDK user message. That meant a large (or mistakenly huge) attachment could blow the serialized HTTP request size before the agent could even behave “normally.”buildCloudPromptBlockstest/harness helper was also reading text off disk and emittingresourceblobs with inlined (truncated) content — structurally the same problem, and inconsistent with how production cloud flow stays path/artifact-centric.This is independent of
READ_TOOLS/ permission labels in our agent package: those only classify tool names likeRead(Claude Code tools reference — **Read). They don’t fetch files; the model invokesReadat runtime.Anthropic’s Request too large doc explains pressure from big payloads and recommends patterns like chunked reads and PDF
pagesrather than dumping everything into one turn (Request too large).Closes: #2048
Changes
promptToClaude(acp-to-sdk.ts)For
file://onresource_linkandresource, I only emit short path-first copy that aligns with Claude Code’sReadFileReadInput:file_path, optionaloffset/limitfor large text, and optionalpages(string ranges, e.g."1-5") for PDFs (Agent SDK TypeScript — Read).For
resource+file://, I stop forwardingresource.textinto<context>so workspace files can’t be inlined that way anymore.file://imageblocks without base64dataI map those to the same path + Read style text instead of dropping them or silently doing nothing useful.
Non filesystem schemes
Where we still rely on inlined payloads for tests/other flows (e.g.
attachment://), I keep link +<context>behavior so those cases don’t regress.buildCloudPromptBlocks(harness)Text attaches become
resource_linkwithfile://URIs (same idea as productioncloudPromptToBlocks), withoutreadAbsoluteFilefor TXT. Images in that harness stay embeddedimage(separate topic fromresource). Production cloud stays uploads +artifact_ids.Tests
I added/updated Vitest coverage so
file://+ hugeresource.textnever appears in the SDK message,attachment://inline behavior still works, and the cloud harness emitsresource_linkfor text.How did you test this?
pnpm testpnpm --filter @posthog/agent testpnpm --filter code testpnpm --filter @posthog/git test