fix: stop false emergencies (real context window) + preserve compressed summaries - #110
Open
ranxianglei wants to merge 1 commit into
Open
fix: stop false emergencies (real context window) + preserve compressed summaries#110ranxianglei wants to merge 1 commit into
ranxianglei wants to merge 1 commit into
Conversation
- index.ts: derive the real context window from the provider's usage percent (percent = tokens/realWindow) and prefer it over the configured modelContextLimit. A limit set smaller than the actual model window (e.g. 80K vs a real 272K) no longer traps the session in permanent emergency / death-loop nudging at 24% real fullness. - config.ts: resolveEffectiveContextLimit helper, trustworthy 5-100% band. - messages.ts: emit kernel acp_summary_* placeholders as user text instead of dropping them. Dropping gave the model total amnesia for compressed sections, driving re-fetch feedback loops that inflated context.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root cause of the death-loop (from acp.log analysis)
The configured
modelContextLimit(80K) was ~3.4× smaller than the model's real window (272K, derived fromrealUsage.percent). The nudge computes fullness astokenCount / modelContextLimit, so it entered emergency at 64K tokens — only 23.5% of the real window — and stayed in emergency continuously, thrashing the model with compression nudges it could not satisfy (protected zone / too-small ranges). At peak the nudge's own pct hit 270% while the provider showed 81%.Fixes
1. Derive the real window from the provider's usage percent (
src/index.ts,src/config.ts)realUsage.percent = tokens / realWindow ⇒ realWindow = tokens / percent. When the reading is in a trustworthy 5–100% band, use it asmodelContextLimitfor the nudge decision. The nudge now matches the footer the user sees; a misconfigured limit no longer causes false emergencies.2. Stop dropping compressed summaries (
src/messages.ts)coreOutToAgentMessagespreviouslycontinued past everyacp_summary_*message — the kernel's prune node replaces covered messages with these placeholders, and dropping them gave the model total amnesia for compressed sections, driving re-fetch feedback loops that inflated context. Now emitted as user-role text.Not in this PR (blocked)
nudge.breakdown.emergencyNothingLeft(from acp-kernel release v0.1.16 #53) to withhold the urgent nudge when nothing is legally compressible. Blocked on acp-kernel release v0.1.16 #53 merge + a version bump (field absent in bundled 0.0.17).Verification
typecheck clean, 156/156 tests pass (+3 new for
resolveEffectiveContextLimit; updated the old "filters out summary" test to assert emission). Build 410 KB.