Skip to content

fix(agent): retry oversized resume on a fresh session with summarized history#3334

Draft
tatoalo wants to merge 2 commits into
mainfrom
posthog-code/resume-prompt-too-long-fallback
Draft

fix(agent): retry oversized resume on a fresh session with summarized history#3334
tatoalo wants to merge 2 commits into
mainfrom
posthog-code/resume-prompt-too-long-fallback

Conversation

@tatoalo

@tatoalo tatoalo commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Problem

When a resumed session's transcript no longer fits the model's context window, the API rejects every request — including the SDK's own auto-compaction — so the resume continuation fails with Internal error: Prompt is too long. That is classified as a non-recoverable agent_error, the run dies before doing any work, and every subsequent resume of the task hits the same wall: the task is permanently stuck.

Follow-up to #3331 (which makes hydration unlikely to produce an oversized transcript in the first place); this adds the safety net for any remaining path to an oversized resume.

Changes

  • When the resume continuation fails with a prompt-too-long error, start a fresh session (same session meta) and re-send the pending user message with the summarized conversation history that the non-native resume path already uses (capped at 50k estimated tokens), instead of failing the run.
  • One retry per run, gated to the native-resume continuation turn; any other failure keeps the existing handleTurnFailure behavior.
  • New isPromptTooLongError predicate in error-classification.ts.

How did you test this?

  • New test: a resume continuation whose first prompt rejects with "Prompt is too long" creates a fresh session, swaps the active ACP session id, and re-prompts with the summarized history.
  • pnpm exec vitest run src/server/agent-server.test.ts — 101 passed.
  • tsc --noEmit on the agent package.

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Created with PostHog Code

… history

When a resumed transcript no longer fits the context window, the API
rejects every request including auto-compaction, so the resume
continuation fails with "Prompt is too long" as a non-recoverable
agent_error and the task can never be resumed again. Catch that
specific failure, start a fresh session, and re-send the pending user
message with the summarized history the non-native resume path already
uses, instead of failing the run.

Generated-By: PostHog Code
Task-Id: c6065620-5694-4478-a20a-fec4ccde8f1a
@trunk-io

trunk-io Bot commented Jul 10, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit dbe76da.

Move sessionMeta onto the active session, keep resumeState until the
turn succeeds so the retry reuses the already-loaded conversation
instead of re-downloading the run log, and reuse getErrorMessage from
shared.

Generated-By: PostHog Code
Task-Id: c6065620-5694-4478-a20a-fec4ccde8f1a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant