Skip to content
This repository was archived by the owner on Aug 6, 2026. It is now read-only.

fix(agent): treat gateway 413 as prompt-too-long - #3793

Merged
trunk-io[bot] merged 3 commits into
mainfrom
brandon/glm-413-prompt-too-long
Jul 24, 2026
Merged

fix(agent): treat gateway 413 as prompt-too-long#3793
trunk-io[bot] merged 3 commits into
mainfrom
brandon/glm-413-prompt-too-long

Conversation

@brandonleung

@brandonleung brandonleung commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Problem

Cloud tasks running Cloudflare-hosted models (e.g. @cf/zai-org/glm-5.2) through the LLM gateway fail permanently once a resumed transcript outgrows the model's context window: the gateway rejects every attempt with HTTP 413, the run ends in error, and each orchestrator restart replays the same oversized transcript indefinitely.

Changes

The oversized-resume recovery already exists (retryOversizedResumeOnFreshSession restarts the run on a fresh session with summarized history) but only triggered on Anthropic's "prompt is too long" phrasing.

  • isPromptTooLongError now also matches the gateway's 413 shapes ("exceeded this model context window limit" and any API Error: 413), so the recovery fires instead of the restart loop.
  • 413 stays a non-retryable agent_error, pinned by test, so transient-retry paths never burn attempts on it.

How did you test this?

Each matcher has a unit case only it matches (deleting any one pattern fails a test), and the agent-server fresh-session-retry test drives the full wrapped gateway 413 message through the recovery end-to-end. vitest, tsc, and biome pass.

Automatic notifications

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

@trunk-io

trunk-io Bot commented Jul 24, 2026

Copy link
Copy Markdown

😎 Merged directly without going through the merge queue, as the queue was empty and the PR was up to date with the target branch - details.

@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit c445055.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RA68K3mgc4P3X9jwPWVaFM
@brandonleung
brandonleung force-pushed the brandon/glm-413-prompt-too-long branch from ca678e6 to 191d03b Compare July 24, 2026 17:42
@brandonleung
brandonleung marked this pull request as ready for review July 24, 2026 17:45
@brandonleung
brandonleung requested a review from a team July 24, 2026 17:45
@posthog

posthog Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

👋 Visual changes detected for this PR.

Review and approve in PostHog Visual Review

If these changes are unexpected, they may be caused by a flaky test or a broken snapshot on master. Don't approve — rerun the job or wait for a fix.

@greptile-apps

greptile-apps Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "fix(agent): treat gateway 413 as prompt-..." | Re-trigger Greptile

@brandonleung

Copy link
Copy Markdown
Contributor Author

/trunk merge

@trunk-io
trunk-io Bot merged commit 88bebde into main Jul 24, 2026
33 checks passed
@trunk-io
trunk-io Bot deleted the brandon/glm-413-prompt-too-long branch July 24, 2026 18:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants