[GH-ISSUE #1615] [Feature]: let harnesses recognize the context-overflow 400 (include a phrase they already match) #648

Closed
opened 2026-11-04 01:44:46 +07:00 by bsakaguchi · 3 comments
Owner

Originally created by @donnielrt on GitHub (Oct 8, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/1615

Filed by an AI agent (Claude, running in Claude Code) on behalf of the repository operator, who reviewed and approved this submission.

What do you want to do?

Let agent harnesses recognize Strata's context-overflow 400 as an overflow, so they run their own compaction-and-retry instead of showing a dead error.

What happens today. serve/server.py (main, fb58e0d) refuses an oversized request with one of two messages:

prompt (N tokens) leaves no room to answer in the context (C); requests are never truncated
prompt (N tokens) + max tokens (M) exceeds the context (C); requests are never truncated. Send a smaller max_tokens (at most R here), or add "fit_max_tokens": true to ...

as HTTP 400 with "type": "invalid_request_error".

Harnesses detect overflow by matching the error text against the phrases servers already use. Pi (pi-coding-agent, pi-ai/utils/overflow.js, isContextOverflow) matches, among others:

  • llama.cpp server: exceeds the available context size
  • OpenAI: exceeds the context window
  • generic: context_length_exceeded / context length exceeded, too many tokens, token limit exceeded

Strata's wording matches none of them, so Pi treats the 400 as an ordinary provider error: no compaction, the turn fails, and the session is stuck until the user shrinks it by hand. We hit this on 0.1.40.1 with a 150,722-token prompt on a 131,072 context (one large tool result pushed the prompt past the limit in a single turn). fit_max_tokens cannot help in that case because the prompt alone exceeds the context (the room < 1 branch).

For comparison, llama.cpp's server returns request (N tokens) exceeds the available context size (C tokens), try increasing it with "type": "exceed_context_size_error" plus n_prompt_tokens and n_ctx fields, and Pi recovers from that automatically.

Suggestion. Keep the current message and guidance, and add a phrase harnesses already match. The smallest change is appending llama.cpp's wording to both messages, e.g.

prompt (N tokens) + max tokens (M) exceeds the context (C); the request exceeds the available context size. Requests are never truncated. Send a smaller max_tokens ...

Optionally also return "type": "exceed_context_size_error" with n_prompt_tokens and n_ctx, matching llama.cpp, for clients that check the type instead of the text.

Workaround we use today. Our Pi extension rewrites the error text on the client side to include "the request exceeds the available context size" when it matches Strata's two messages, which makes Pi's compact-and-retry fire. We'd rather delete that adapter once the server says it itself.

Originally created by @donnielrt on GitHub (Oct 8, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/1615 *Filed by an AI agent (Claude, running in Claude Code) on behalf of the repository operator, who reviewed and approved this submission.* ### What do you want to do? Let agent harnesses recognize Strata's context-overflow 400 as an overflow, so they run their own compaction-and-retry instead of showing a dead error. **What happens today.** `serve/server.py` (main, fb58e0d) refuses an oversized request with one of two messages: ``` prompt (N tokens) leaves no room to answer in the context (C); requests are never truncated prompt (N tokens) + max tokens (M) exceeds the context (C); requests are never truncated. Send a smaller max_tokens (at most R here), or add "fit_max_tokens": true to ... ``` as HTTP 400 with `"type": "invalid_request_error"`. Harnesses detect overflow by matching the error text against the phrases servers already use. Pi (pi-coding-agent, `pi-ai/utils/overflow.js`, `isContextOverflow`) matches, among others: - llama.cpp server: `exceeds the available context size` - OpenAI: `exceeds the context window` - generic: `context_length_exceeded` / `context length exceeded`, `too many tokens`, `token limit exceeded` Strata's wording matches none of them, so Pi treats the 400 as an ordinary provider error: no compaction, the turn fails, and the session is stuck until the user shrinks it by hand. We hit this on 0.1.40.1 with a 150,722-token prompt on a 131,072 context (one large tool result pushed the prompt past the limit in a single turn). `fit_max_tokens` cannot help in that case because the prompt alone exceeds the context (the `room < 1` branch). For comparison, llama.cpp's server returns `request (N tokens) exceeds the available context size (C tokens), try increasing it` with `"type": "exceed_context_size_error"` plus `n_prompt_tokens` and `n_ctx` fields, and Pi recovers from that automatically. **Suggestion.** Keep the current message and guidance, and add a phrase harnesses already match. The smallest change is appending llama.cpp's wording to both messages, e.g. ``` prompt (N tokens) + max tokens (M) exceeds the context (C); the request exceeds the available context size. Requests are never truncated. Send a smaller max_tokens ... ``` Optionally also return `"type": "exceed_context_size_error"` with `n_prompt_tokens` and `n_ctx`, matching llama.cpp, for clients that check the type instead of the text. **Workaround we use today.** Our Pi extension rewrites the error text on the client side to include "the request exceeds the available context size" when it matches Strata's two messages, which makes Pi's compact-and-retry fire. We'd rather delete that adapter once the server says it itself.
Author
Owner

@Niko1221 commented on GitHub (Oct 10, 2026):

Done in v0.1.42 through #1623: the overflow 400 now opens with "request exceeds the context window:", followed by the previous text. The error type stays invalid_request_error. If a harness you use matches a different phrase, tell us which and we will check it against the message.

<!-- gh-comment-id:6099635079 --> @Niko1221 commented on GitHub (Oct 10, 2026): Done in v0.1.42 through #1623: the overflow 400 now opens with "request exceeds the context window:", followed by the previous text. The error type stays invalid_request_error. If a harness you use matches a different phrase, tell us which and we will check it against the message.
Author
Owner

@donnielrt commented on GitHub (Oct 10, 2026):

(Posted by an AI agent on behalf of the reporter, with their approval.) Thank you — confirmed: our harness (Pi, via pi-ai's overflow detector) matches /exceeds the context window/i, so the v0.1.42 prefix "request exceeds the context window:" is recognized natively and no other phrase is needed. We will drop our relabel adapter once we pin v0.1.42. This can be closed from our side.

<!-- gh-comment-id:6101175251 --> @donnielrt commented on GitHub (Oct 10, 2026): (Posted by an AI agent on behalf of the reporter, with their approval.) Thank you — confirmed: our harness (Pi, via pi-ai's overflow detector) matches `/exceeds the context window/i`, so the v0.1.42 prefix "request exceeds the context window:" is recognized natively and no other phrase is needed. We will drop our relabel adapter once we pin v0.1.42. This can be closed from our side.
Author
Owner

@Niko1221 commented on GitHub (Oct 13, 2026):

Thanks for the report. To keep the tracker current we are closing issues older than three days: 0.1.44 is out with a long list of fixes, and many older reports are covered by it or by 0.1.43.1.

If this still happens on 0.1.44, please leave a comment here with your engine log (and the version line it prints), and we will reopen it. A new issue that links this one works too.

<!-- gh-comment-id:6156156197 --> @Niko1221 commented on GitHub (Oct 13, 2026): Thanks for the report. To keep the tracker current we are closing issues older than three days: [0.1.44](https://github.com/Niko1221/Strata/releases/tag/v0.1.44) is out with a long list of fixes, and many older reports are covered by it or by 0.1.43.1. If this still happens on 0.1.44, please leave a comment here with your engine log (and the version line it prints), and we will reopen it. A new issue that links this one works too.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#648
No description provided.