Skip to content

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

Merged
tatoalo merged 1 commit into
mainfrom
posthog-code/resume-prompt-too-long-fallback
Jul 10, 2026
Merged

fix(agent): retry oversized resume on a fresh session with summarized history#3334
tatoalo merged 1 commit 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.

@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 df83f0d.

@tatoalo tatoalo self-assigned this Jul 10, 2026
@tatoalo tatoalo marked this pull request as ready for review July 10, 2026 14:17
@greptile-apps

greptile-apps Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "refactor(agent): simplify oversized-resu..." | Re-trigger Greptile

Comment thread packages/agent/src/server/agent-server.ts Outdated
@tatoalo tatoalo force-pushed the posthog-code/resume-prompt-too-long-fallback branch from dbe76da to df83f0d Compare July 10, 2026 14:37
@tatoalo tatoalo added the Stamphog This will request an autostamp by stamphog on small changes label Jul 10, 2026
@tatoalo tatoalo requested a review from a team July 10, 2026 14:40
@tatoalo tatoalo enabled auto-merge (squash) July 10, 2026 14:42

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No showstoppers. The retry mechanism is well-guarded with a one-shot flag, state is cleaned up in a finally block on both success and failure paths, and the previously raised concern about stale resume state on failed retries is demonstrably fixed in the current diff.

@tatoalo tatoalo merged commit 4a16670 into main Jul 10, 2026
30 of 31 checks passed
@tatoalo tatoalo deleted the posthog-code/resume-prompt-too-long-fallback branch July 10, 2026 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Stamphog This will request an autostamp by stamphog on small changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant