openclaw-vainplex/src
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
..
acp fix: stabilize acp streams and tests 2026-01-18 08:54:00 +00:00
agents fix: auto-compact on context overflow promptError before returning error (#1627) 2026-01-24 22:09:24 +00:00
auto-reply feat(discord): add exec approval forwarding to DMs (#1621) 2026-01-24 20:56:40 +00:00
browser fix: handle extension relay session reuse 2026-01-24 04:41:28 +00:00
canvas-host chore: update a2ui bundle hash 2026-01-22 08:48:09 +00:00
channels Channels: add per-group tool policies 2026-01-24 05:49:39 +00:00
cli fix: clean docker onboarding warnings + preserve agentId casing 2026-01-24 19:07:01 +00:00
commands fix: normalize session keys and outbound mirroring 2026-01-24 11:57:11 +00:00
config feat(macos): add direct gateway transport 2026-01-24 21:02:13 +00:00
cron fix: clean docker onboarding warnings + preserve agentId casing 2026-01-24 19:07:01 +00:00
daemon test: stabilize service-env path tests on windows 2026-01-24 04:36:52 +00:00
discord feat(discord): add exec approval forwarding to DMs (#1621) 2026-01-24 20:56:40 +00:00
docs refactor: route channel runtime via plugin api 2026-01-18 11:01:16 +00:00
gateway feat(discord): add exec approval forwarding to DMs (#1621) 2026-01-24 20:56:40 +00:00
hooks refactor: centralize config update logging 2026-01-23 04:01:26 +00:00
imessage refactor: standardize channel logging 2026-01-23 23:34:30 +00:00
infra feat(discord): add exec approval forwarding to DMs (#1621) 2026-01-24 20:56:40 +00:00
logging fix: gate diagnostic logs behind verbose 2026-01-24 05:06:42 +00:00
macos fix: type gateway lock handle 2026-01-21 23:05:11 +00:00
markdown fix: add per-channel markdown table conversion (#1495) (thanks @odysseus0) 2026-01-23 18:39:25 +00:00
media fix: anchor MEDIA tag parsing 2026-01-24 03:46:27 +00:00
media-understanding test: add media auto-detect coverage 2026-01-23 05:47:13 +00:00
memory chore: filter noisy warnings 2026-01-24 10:48:33 +00:00
node-host fix: honor tools.exec ask/security in approvals 2026-01-24 04:53:44 +00:00
pairing feat: add /allowlist command 2026-01-21 05:34:53 +00:00
plugin-sdk Channels: add per-group tool policies 2026-01-24 05:49:39 +00:00
plugins fix: enforce explicit mention gating across channels 2026-01-24 11:09:33 +00:00
process fix: quiet auth probe diagnostics 2026-01-23 19:53:01 +00:00
providers fix: log config update in copilot auth 2026-01-23 07:23:52 +00:00
routing fix: unify reasoning tags + agent ids (#1613) (thanks @kyleok) (#1629) 2026-01-24 19:56:02 +00:00
security fix: honor gateway env token for doctor/security 2026-01-23 03:16:52 +00:00
sessions fix: inherit model overrides for thread sessions 2026-01-22 06:03:23 +00:00
shared/text fix: unify reasoning tags + agent ids (#1613) (thanks @kyleok) (#1629) 2026-01-24 19:56:02 +00:00
signal refactor: standardize channel logging 2026-01-23 23:34:30 +00:00
slack fix: normalize session keys and outbound mirroring 2026-01-24 11:57:11 +00:00
telegram fix: normalize telegram fetch for long-polling 2026-01-24 21:58:42 +00:00
terminal fix: clarify auth order exclusions 2026-01-24 01:18:03 +00:00
test-helpers refactor: add hook guards and test helpers 2026-01-18 06:15:24 +00:00
test-utils feat: add plugin command API for LLM-free auto-reply commands 2026-01-24 06:28:22 +00:00
tts feat: add TTS hint to system prompt 2026-01-24 10:25:42 +00:00
tui fix: gate TUI lifecycle updates to active run (#1567) (thanks @vignesh07) 2026-01-24 07:23:41 +00:00
types chore: fix lint/format 2026-01-20 13:52:59 +00:00
utils fix: harden Mattermost plugin gating (#1428) (thanks @damoahdominic) 2026-01-23 01:23:23 +00:00
web fix: normalize session keys and outbound mirroring 2026-01-24 11:57:11 +00:00
whatsapp refactor: prune legacy group prefixes 2026-01-17 08:47:25 +00:00
wizard fix: always offer TUI hatch 2026-01-23 09:07:43 +00:00
channel-web.barrel.test.ts refactor!: rename chat providers to channels 2026-01-13 08:40:39 +00:00
channel-web.ts refactor!: rename chat providers to channels 2026-01-13 08:40:39 +00:00
docker-setup.test.ts fix: update docker gateway command 2026-01-24 03:24:28 +00:00
entry.ts chore: filter noisy warnings 2026-01-24 10:48:33 +00:00
git-hooks.test.ts fix: add git hook setup and stable config hash sorting 2026-01-19 02:02:17 +00:00
globals.test.ts chore: format to 2-space and bump changelog 2025-11-26 00:53:53 +01:00
globals.ts CLI: streamline startup paths and env parsing 2026-01-18 23:10:39 +00:00
index.test.ts chore: migrate to oxlint and oxfmt 2026-01-14 15:02:19 +00:00
index.ts fix: tame invalid config logging 2026-01-21 01:58:47 +00:00
logger.test.ts fix: align rolling logs to local time 2026-01-22 07:02:52 +00:00
logger.ts refactor(logging): split config + subsystem imports 2026-01-19 00:15:44 +00:00
logging.ts fix: unblock bundled plugin load 2026-01-18 19:34:21 +00:00
polls.test.ts chore: migrate to oxlint and oxfmt 2026-01-14 15:02:19 +00:00
polls.ts chore: migrate to oxlint and oxfmt 2026-01-14 15:02:19 +00:00
postinstall-patcher.test.ts chore: migrate to oxlint and oxfmt 2026-01-14 15:02:19 +00:00
runtime.ts perf: speed up memory batch polling 2026-01-18 03:55:14 +00:00
utils.test.ts chore: migrate to oxlint and oxfmt 2026-01-14 15:02:19 +00:00
utils.ts refactor: centralize config update logging 2026-01-23 04:01:26 +00:00
version.ts chore: rename project to clawdbot 2026-01-04 14:38:51 +00:00