Rodrigo Uroz
9ceac415c5
fix: auto-compact on context overflow promptError before returning error ( #1627 )
...
* fix: detect Anthropic 'Request size exceeds model context window' as context overflow
Anthropic now returns 'Request size exceeds model context window' instead of
the previously detected 'prompt is too long' format. This new error message
was not recognized by isContextOverflowError(), causing auto-compaction to
NOT trigger. Users would see the raw error twice without any recovery attempt.
Changes:
- Add 'exceeds model context window' and 'request size exceeds' to
isContextOverflowError() detection patterns
- Add tests that fail without the fix, verifying both the raw error
string and the JSON-wrapped format from Anthropic's API
- Add test for formatAssistantErrorText to ensure the friendly
'Context overflow' message is shown instead of the raw error
Note: The upstream pi-ai package (@mariozechner/pi-ai) also needs a fix
in its OVERFLOW_PATTERNS regex: /exceeds the context window/i should be
changed to /exceeds.*context window/i to match both 'the' and 'model'
variants for triggering auto-compaction retry.
* fix(tests): remove unused imports and helper from test files
Remove WorkspaceBootstrapFile references and _makeFile helper that were
incorrectly copied from another test file. These caused type errors and
were unrelated to the context overflow detection tests.
* fix: trigger auto-compaction on context overflow promptError
When the LLM rejects a request with a context overflow error that surfaces
as a promptError (thrown exception rather than streamed error), the existing
auto-compaction in pi-coding-agent never triggers. This happens because the
error bypasses the agent's message_end → agent_end → _checkCompaction path.
This fix adds a fallback compaction attempt directly in the run loop:
- Detects context overflow in promptError (excluding compaction_failure)
- Calls compactEmbeddedPiSessionDirect (bypassing lane queues since already in-lane)
- Retries the prompt after successful compaction
- Limits to one compaction attempt per run to prevent infinite loops
Fixes: context overflow errors shown to user without auto-compaction attempt
* style: format compact.ts and run.ts with oxfmt
* fix: tighten context overflow match (#1627 ) (thanks @rodrigouroz)
---------
Co-authored-by: Claude <claude@anthropic.com >
Co-authored-by: Peter Steinberger <steipete@gmail.com >
2026-01-24 22:09:24 +00:00
..
2026-01-23 07:14:00 +00:00
2026-01-24 10:25:42 +00:00
2026-01-24 22:09:24 +00:00
2026-01-24 22:09:24 +00:00
2026-01-23 23:03:04 +00:00
2026-01-24 01:30:44 +00:00
2026-01-17 03:40:49 +00:00
2026-01-23 00:49:40 +00:00
2026-01-23 18:34:33 +00:00
2026-01-24 11:57:11 +00:00
2026-01-06 21:54:42 +00:00
2026-01-14 15:02:19 +00:00
2026-01-14 15:02:19 +00:00
2026-01-24 11:57:11 +00:00
2026-01-24 07:09:26 +00:00
2026-01-20 08:28:40 +00:00
2026-01-14 15:02:19 +00:00
2026-01-12 03:42:56 +00:00
2026-01-14 15:02:19 +00:00
2026-01-14 15:02:19 +00:00
2026-01-14 15:02:19 +00:00
2026-01-14 01:17:56 +00:00
2026-01-14 15:02:19 +00:00
2026-01-20 09:38:56 +00:00
2026-01-14 20:07:35 +00:00
2026-01-14 15:02:19 +00:00
2026-01-20 09:38:56 +00:00
2026-01-14 20:07:35 +00:00
2026-01-14 15:02:19 +00:00
2026-01-14 20:07:35 +00:00
2026-01-14 15:02:19 +00:00
2026-01-15 02:29:43 +00:00
2026-01-14 05:39:59 +00:00
2026-01-14 15:02:19 +00:00
2026-01-14 05:39:59 +00:00
2026-01-14 15:02:19 +00:00
2026-01-17 08:26:12 +00:00
2026-01-17 08:26:12 +00:00
2026-01-24 21:12:46 +00:00
2026-01-16 19:48:52 +00:00
2026-01-20 14:04:13 +00:00
2026-01-23 06:27:26 +00:00
2026-01-17 08:10:44 +00:00
2026-01-24 20:55:21 +00:00
2026-01-17 08:10:44 +00:00
2026-01-17 08:00:05 +00:00
2026-01-15 02:58:20 +00:00
2026-01-19 00:35:43 +00:00
2026-01-14 05:39:59 +00:00
2026-01-24 01:18:33 +00:00
2026-01-24 01:18:33 +00:00
2026-01-18 06:31:02 +00:00
2026-01-18 06:15:24 +00:00
2026-01-18 05:24:47 +00:00
2026-01-18 05:24:47 +00:00
2026-01-21 10:23:30 +00:00
2026-01-21 10:23:30 +00:00
2026-01-22 03:37:29 +00:00
2026-01-14 15:02:19 +00:00
2026-01-14 15:02:19 +00:00
2026-01-14 15:02:19 +00:00
2026-01-11 11:45:25 +00:00
2026-01-23 18:34:33 +00:00
2026-01-23 18:34:33 +00:00
2026-01-23 18:34:33 +00:00
2026-01-24 11:09:11 +00:00
2026-01-24 11:09:11 +00:00
2026-01-23 18:34:33 +00:00
2026-01-23 18:34:33 +00:00
2026-01-23 18:34:33 +00:00
2026-01-23 18:34:33 +00:00
2026-01-23 18:34:33 +00:00
2026-01-23 18:34:33 +00:00
2026-01-24 08:00:44 +00:00
2026-01-14 15:02:19 +00:00
2026-01-18 19:34:21 +00:00
2026-01-22 07:01:10 +00:00
2026-01-16 03:30:56 +00:00
2026-01-20 07:37:30 +00:00
2026-01-14 15:02:19 +00:00
2026-01-23 22:25:07 +00:00
2026-01-23 23:03:04 +00:00
2026-01-10 01:08:56 +01:00
2026-01-14 15:02:19 +00:00
2026-01-14 15:02:19 +00:00
2026-01-15 22:27:06 +00:00
2025-12-14 04:22:38 +00:00
2026-01-18 15:00:36 +00:00
2026-01-14 15:02:19 +00:00
2026-01-24 11:27:24 +00:00
2026-01-19 00:34:26 +00:00
2026-01-22 07:24:12 +00:00
2026-01-22 04:00:07 +00:00
2026-01-24 05:35:50 +00:00
2026-01-24 05:35:50 +00:00
2026-01-10 17:12:50 +01:00
2026-01-14 23:05:08 -05:00
2026-01-20 10:51:25 +00:00
2026-01-13 03:36:53 +00:00
2026-01-24 14:08:16 +00:00
2026-01-21 10:39:00 +00:00
2026-01-21 10:39:00 +00:00
2026-01-14 15:02:19 +00:00
2026-01-19 00:34:26 +00:00
2026-01-20 08:28:40 +00:00
2026-01-24 01:18:33 +00:00
2026-01-20 22:58:41 +00:00
2026-01-20 22:58:41 +00:00
2026-01-11 04:28:30 +01:00
2026-01-20 19:30:32 +00:00
2026-01-24 11:27:24 +00:00
2026-01-20 19:23:13 +00:00
2026-01-08 05:20:39 +01:00
2026-01-14 15:02:19 +00:00
2026-01-14 15:02:19 +00:00
2026-01-20 14:35:20 +00:00
2026-01-23 07:14:00 +00:00
2026-01-23 07:14:00 +00:00
2026-01-14 15:02:19 +00:00
2026-01-14 05:39:59 +00:00
2026-01-24 01:18:33 +00:00
2026-01-14 15:02:19 +00:00
2026-01-24 01:15:06 +00:00
2026-01-23 07:14:00 +00:00
2026-01-22 04:19:33 +00:00
2026-01-14 15:02:19 +00:00
2026-01-24 13:32:26 +00:00
2026-01-24 13:19:55 +00:00
2026-01-09 22:56:55 +00:00
2026-01-14 15:02:19 +00:00
2026-01-14 15:02:19 +00:00
2026-01-18 15:21:38 +00:00
2026-01-24 08:16:42 +00:00
2026-01-24 22:09:24 +00:00
2026-01-22 22:24:25 +00:00
2026-01-18 18:43:31 +00:00
2026-01-20 09:31:41 +00:00
2026-01-14 15:02:19 +00:00
2026-01-18 18:43:31 +00:00
2026-01-14 15:02:19 +00:00
2026-01-24 22:09:24 +00:00
2026-01-14 15:02:19 +00:00
2026-01-20 10:07:05 +00:00
2026-01-14 15:02:19 +00:00
2026-01-14 15:02:19 +00:00
2026-01-14 15:02:19 +00:00
2026-01-14 15:02:19 +00:00
2026-01-23 01:34:21 +00:00
2026-01-23 01:34:21 +00:00
2026-01-14 15:02:19 +00:00
2026-01-14 15:02:19 +00:00
2026-01-23 00:42:45 +00:00
2026-01-22 22:24:25 +00:00
2026-01-14 15:02:19 +00:00
2026-01-24 07:58:25 +00:00
2026-01-14 15:02:19 +00:00
2026-01-17 06:45:11 +00:00
2026-01-19 00:34:26 +00:00
2026-01-16 22:26:43 +00:00
2026-01-14 15:02:19 +00:00
2026-01-14 15:02:19 +00:00
2026-01-14 15:02:19 +00:00
2026-01-14 15:02:19 +00:00
2026-01-24 11:57:11 +00:00
2026-01-22 23:51:59 +00:00
2026-01-14 15:02:19 +00:00
2026-01-14 15:02:19 +00:00
2026-01-24 11:57:11 +00:00
2026-01-24 06:14:23 +00:00
2026-01-24 08:16:42 +00:00
2026-01-14 15:02:19 +00:00
2026-01-24 02:34:54 +00:00
2026-01-16 08:02:56 +00:00
2026-01-15 09:23:56 +00:00
2026-01-20 09:25:20 +00:00
2026-01-22 08:01:34 +00:00
2026-01-18 18:35:03 +05:30
2026-01-17 05:33:39 +00:00
2026-01-22 08:01:34 +00:00
2026-01-18 23:10:39 +00:00
2026-01-22 08:01:34 +00:00
2026-01-14 15:02:19 +00:00
2026-01-14 15:02:19 +00:00
2026-01-14 15:02:19 +00:00
2026-01-14 15:02:19 +00:00
2026-01-21 06:29:36 +00:00
2026-01-14 15:02:19 +00:00
2026-01-14 15:02:19 +00:00
2026-01-14 15:02:19 +00:00
2026-01-23 01:00:24 +00:00
2026-01-14 15:02:19 +00:00
2026-01-14 15:02:19 +00:00
2026-01-14 15:02:19 +00:00
2026-01-14 15:02:19 +00:00
2026-01-14 15:02:19 +00:00
2026-01-20 09:52:26 +00:00
2026-01-15 20:55:52 -08:00
2026-01-23 01:00:24 +00:00
2026-01-18 08:54:00 +00:00
2026-01-18 18:35:03 +05:30
2026-01-22 08:01:34 +00:00
2026-01-20 12:07:54 +00:00
2026-01-24 19:56:02 +00:00
2026-01-24 19:56:02 +00:00
2026-01-06 02:23:55 +01:00
2026-01-14 15:02:19 +00:00
2026-01-14 15:02:19 +00:00
2026-01-17 18:15:45 +00:00
2026-01-20 07:37:01 +00:00
2026-01-24 05:49:39 +00:00
2026-01-14 15:02:19 +00:00
2026-01-23 18:34:33 +00:00
2026-01-23 18:34:33 +00:00
2026-01-23 18:34:33 +00:00
2026-01-23 18:34:33 +00:00
2026-01-24 01:30:44 +00:00
2026-01-24 05:49:39 +00:00
2026-01-14 15:02:19 +00:00
2026-01-14 15:02:19 +00:00
2026-01-24 07:44:04 +00:00
2026-01-14 05:39:59 +00:00
2026-01-14 15:02:19 +00:00
2026-01-17 07:05:24 +00:00
2026-01-17 08:06:35 +00:00
2026-01-17 08:00:05 +00:00
2026-01-17 06:32:24 +00:00
2026-01-14 15:02:19 +00:00
2026-01-16 01:44:12 +00:00
2026-01-16 02:49:18 +00:00
2026-01-18 06:58:54 +00:00
2026-01-14 15:02:19 +00:00
2026-01-24 11:57:11 +00:00
2026-01-18 06:58:54 +00:00
2026-01-14 15:02:19 +00:00
2026-01-14 15:02:19 +00:00
2026-01-14 15:02:19 +00:00
2026-01-14 15:02:19 +00:00
2026-01-17 06:32:24 +00:00
2026-01-17 06:23:26 +00:00
2026-01-23 01:34:21 +00:00
2026-01-23 01:34:21 +00:00
2026-01-20 11:03:17 +00:00
2026-01-23 01:34:21 +00:00
2026-01-14 15:02:19 +00:00
2026-01-14 15:02:19 +00:00
2026-01-23 18:34:33 +00:00
2026-01-23 18:34:33 +00:00
2026-01-20 11:25:49 +00:00
2026-01-20 11:59:36 +00:00
2026-01-21 01:24:29 +00:00
2026-01-21 00:14:36 +00:00
2026-01-14 15:02:19 +00:00
2026-01-14 05:39:59 +00:00
2026-01-14 15:02:19 +00:00
2026-01-14 05:39:59 +00:00
2026-01-14 15:02:19 +00:00
2026-01-19 13:11:25 +01:00
2026-01-16 12:10:29 +00:00
2026-01-21 00:14:36 +00:00
2026-01-23 00:49:40 +00:00
2026-01-14 01:17:56 +00:00
2026-01-15 10:14:59 +00:00
2026-01-16 12:10:29 +00:00
2026-01-17 06:38:33 +00:00
2026-01-18 19:34:21 +00:00
2026-01-20 17:22:07 +00:00
2026-01-17 05:48:56 +00:00
2026-01-17 05:48:56 +00:00
2026-01-23 01:00:24 +00:00
2026-01-14 15:02:19 +00:00
2026-01-22 05:20:42 +00:00
2026-01-22 05:20:42 +00:00
2026-01-15 01:27:16 +00:00
2026-01-24 10:25:42 +00:00
2026-01-24 10:25:42 +00:00
2026-01-14 15:02:19 +00:00
2026-01-23 00:42:45 +00:00
2026-01-23 00:42:45 +00:00
2026-01-24 07:44:04 +00:00
2026-01-23 01:00:24 +00:00
2026-01-23 01:00:24 +00:00
2026-01-18 15:21:38 +00:00
2026-01-19 00:15:44 +00:00
2026-01-24 07:38:42 +00:00
2026-01-24 07:44:04 +00:00
2026-01-24 07:44:04 +00:00
2026-01-14 15:02:19 +00:00
2026-01-23 01:34:21 +00:00
2026-01-06 18:52:01 +00:00
2026-01-14 15:02:19 +00:00
2026-01-22 08:05:55 +00:00
2026-01-22 08:05:55 +00:00
2026-01-18 23:10:39 +00:00