Skip to content

fix: recognize Codex context-overflow errors and learn conservative window when unparseable - #281

Merged
ranxianglei merged 1 commit into
masterfrom
2026-08-27_codex-overflow-selfheal
Aug 27, 2026
Merged

fix: recognize Codex context-overflow errors and learn conservative window when unparseable#281
ranxianglei merged 1 commit into
masterfrom
2026-08-27_codex-overflow-selfheal

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #280

Background

After a macOS sleep/wake (or any rebind), a restored session starts with lastInputTokens=0. The nudge is blind at tokenCount=0, so only the preflight fit check can catch an oversized raw-history replay. The preflight safety net (shipped in v0.1.57 via #247) already covers the main path — but two gaps left Codex sessions stuck:

  1. Codex's overflow error was never recognized. Codex returns context_window_exceeded / "ran out of room in the model's context window" — neither matched CONTEXT_OVERFLOW_PATTERNS, so no self-heal ever armed and the same oversized payload was re-sent forever.
  2. No window number in the body. Even when recognized, Codex's error carries no parseable window, so parseOverflowWindow found nothing and the armed floor stayed 0.

Changes

  • src/util.ts: recognize context_window_exceeded and the "ran out of room in the model's context window" phrasing as context overflow.
  • src/server.ts: when an overflow is recognized but no window is parseable, learn a conservative window from the rejected payload's own size (only-shrink-never-grow). The next turn's self-heal re-centers the limit and preflight compresses the history below it before forward.

Tests

  • 2 unit tests: Codex error recognition (API code + client phrasing), window stays undefined.
  • Codex e2e self-heal: 400 without window number → conservative window learned → preflight folds the history on the retry → 200.
  • New Responses-protocol e2e (the scenario suggested in Codex 长会话在 macOS 休眠唤醒后 Bili 未触发压缩,导致上下文窗口超限 #280): a long session compressed once, then a fresh restored session (lastInputTokens=0) replays the full raw history over the window → preflight compresses before forward; the oversized history is never replayed verbatim.

Full suite: 661/661 pass.

🤖 ework agent

…indow when unparseable

closes #280

After a macOS sleep/wake (or any rebind), a restored session starts with
lastInputTokens=0, so the nudge is blind and only the preflight fit check
can catch an oversized replay. Two gaps left the Codex path stuck:

- Codex's overflow error (code context_window_exceeded / "ran out of room
  in the model's context window") matched none of CONTEXT_OVERFLOW_PATTERNS,
  so no self-heal ever armed and the same oversized payload was re-sent
  forever.
- Even when the error is recognized, Codex's body carries no window number,
  so parseOverflowWindow found nothing and the floor stayed 0.

Now: both Codex markers are recognized, and when no window is parseable the
proxy learns a conservative window from the rejected payload's own size
(only-shrink-never-grow). The next turn's self-heal re-centers the limit
and preflight compresses the history below it before forward.

Tests: 2 unit (Codex error recognition) + Codex e2e self-heal (400 without
window number -> learned window -> preflight fold on the retry) + new
Responses-protocol e2e for the issue's suggested restore scenario (fresh
session, lastInputTokens=0, raw history over the window -> preflight
compresses before forward). Full suite: 661/661 pass.
@github-actions

Copy link
Copy Markdown

📦 Built Package Artifact

Branch: 2026-08-27_codex-overflow-selfheal (169cf12)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-281

Each push to this PR publishes a new version under the pr-281 npm tag.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr281.tgz
npm install -g package

This comment is automatically updated on each push.

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.

Codex 长会话在 macOS 休眠唤醒后 Bili 未触发压缩,导致上下文窗口超限

1 participant