[PR #12874] fix(session): avoid retry doom loop on context overflow #14415

Closed
opened 2026-02-16 18:19:12 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/12874

State: closed
Merged: No


What does this PR do?

Screenshot 2026-02-08 at 8 47 04 AM

Fixes a retry-doom-loop where context overflow errors (e.g. OpenAI context_length_exceeded) can be delivered as JSON in Error.message, get misclassified, and then be retried indefinitely instead of triggering compaction.

This has been hitting me on GPT-5.3 Codex via the ChatGPT Pro provider. The UI context meter can be misleading here because GPT-5.3 Codex has separate limits (context 400k, input 272k), so you can be ~68% of context while effectively at the input ceiling.

All this to say I was a bit skpetical of the AI fix that seemed to think that this was just a mistake in interpreting the error message and triggering the compact flow correctly.
Neither the less this has been running pretty stable for me and I hope you guys can validate if this seems like the right approach to the problem or if I'm just patching a weird symptom.

Changes:

  • Parse stream-style JSON errors even when wrapped in Error.message so context_length_exceeded becomes ContextOverflowError
  • Treat JSON error strings containing context_length_exceeded as non-retryable
  • Prefer compaction over retry when we hit ContextOverflowError (and avoid looping if the compaction agent itself overflows)

Most likely related to #8089

How did you verify your code works?

  • cd packages/opencode && bun test test/session/retry.test.ts test/session/message-v2.test.ts
  • Built a local opencode binary and used it as my daily driver for a bit
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/12874 **State:** closed **Merged:** No --- ### What does this PR do? <img width="1796" height="976" alt="Screenshot 2026-02-08 at 8 47 04 AM" src="https://github.com/user-attachments/assets/1005c8a6-3c9e-4a81-b301-3a422f261fa5" /> Fixes a retry-doom-loop where context overflow errors (e.g. OpenAI `context_length_exceeded`) can be delivered as JSON in `Error.message`, get misclassified, and then be retried indefinitely instead of triggering compaction. This has been hitting me on GPT-5.3 Codex via the ChatGPT Pro provider. The UI context meter can be misleading here because GPT-5.3 Codex has separate limits (context 400k, input 272k), so you can be ~68% of context while effectively at the input ceiling. All this to say I was a bit skpetical of the AI fix that seemed to think that this was just a mistake in interpreting the error message and triggering the compact flow correctly. Neither the less this has been running pretty stable for me and I hope you guys can validate if this seems like the right approach to the problem or if I'm just patching a weird symptom. Changes: - Parse stream-style JSON errors even when wrapped in `Error.message` so `context_length_exceeded` becomes `ContextOverflowError` - Treat JSON error strings containing `context_length_exceeded` as non-retryable - Prefer compaction over retry when we hit `ContextOverflowError` (and avoid looping if the compaction agent itself overflows) Most likely related to #8089 ### How did you verify your code works? - `cd packages/opencode && bun test test/session/retry.test.ts test/session/message-v2.test.ts` - Built a local `opencode` binary and used it as my daily driver for a bit
yindo added the pull-request label 2026-02-16 18:19:12 -05:00
yindo closed this issue 2026-02-16 18:19:12 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14415