Skip to content

Do not retry a context overflow reported as a server error - #207

Open
Will Walker (willswire) wants to merge 1 commit into
microsoft:mainfrom
willswire:fix/overflow-not-retried
Open

Will Walker (willswire) wants to merge 1 commit into
microsoft:mainfrom
willswire:fix/overflow-not-retried

Conversation

@willswire

@willswire Will Walker (willswire) commented Dec 6, 2026 •

Copy link
Copy Markdown

Linked issue

Fixes #205

What changed (Before / After)

  • Before: a server that reports a context overflow as a server error (Apple's fm serve answers HTTP 500 with "The
    session's transcript exceeded the model's context size.", or sends that error inside the stream after HTTP 200)
    was retried like a temporary failure. Each retry resent the whole conversation, and the turn finally failed as
    "the server is failing".
  • After: that wording is recognised as an overflow, neither the request retry nor the stream retry resends it, and
    the turn ends once as context full, with the window when it is known. Nothing is trimmed or compacted unless
    compaction is turned on. The change applies only to errors whose text already says the context overflowed.

Visual proof (UI / TUI / Web / Desktop / export changes)

N/A (runtime only).

How you verified it

  • New test test_apple_fm_overflow_is_context_full_and_not_retried in tests/test_context_window.py: a fake Chat
    server replays both shapes fm serve produced on macOS 27.2.1 (HTTP 500 JSON, and an in-stream event: error)
    and checks the turn ends as context_full after exactly one request.
  • uv run pyflakes src tests .github/scripts; tests/test_context_window.py and tests/test_compaction.py pass;
    the Python 3.9 import check for src/freehand/runtime/ passes.
  • The sharded core suite passed apart from test_snapshots. I believe that failure comes from my local git
    commit-signing setup, not from this change; the rerun with signing off was interrupted, so this is not
    confirmed yet.
  • Against a real fm serve, the overflow error was confirmed for both shapes before the fix was written.

AI disclosure & checklist

  • AI disclosure: AI-assisted (personally tested and verified)
  • uv run pyflakes src tests .github/scripts prints nothing and relevant tests pass locally (full suite runs in CI)
  • Left CHANGELOG.md untouched (maintainers update it at release time)
  • No change to what the model sees (prompt, tool descriptions, status line, notes), or benchmark evidence attached
  • src/freehand/runtime/ still uses only the standard library and imports on Python 3.9

🤖 Generated with Claude Code

Some Chat Completions servers report an overflow as a server error:
Apple's `fm serve` answers HTTP 500 ("The session's transcript exceeded
the model's context size."), or sends that error inside the stream after
HTTP 200. Both were retried, resending the whole conversation each time
(against a daily quota on fm's PCC model), and the turn then failed as
a generic server error.

The message is now recognised as an overflow, both retry paths stop on
an overflow, and the turn ends once as context_full. Nothing is trimmed
or compacted unless compaction is turned on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Dec 6, 2026

Copy link
Copy Markdown

Thanks for the pull request! A few friendly reminders based on the files changed:

  • Model-facing / runtime core: This PR touches benchmark-sensitive or Python 3.9 stdlib runtime files (src/freehand/runtime/agent.py, src/freehand/runtime/compaction.py). Please make sure Python 3.9 stdlib imports still pass and attach benchmark evidence if model-visible behaviour changed.

(This comment updates automatically when you edit the PR description or push new commits.)

@willswire

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

This branch has not been deployed

No deployments
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.

Don't retry a context overflow reported as a server error

1 participant