Skip to content

fix: stop false emergencies (real context window) + preserve compressed summaries - #110

Open
ranxianglei wants to merge 1 commit into
masterfrom
2026-08-10_nudge-real-window
Open

fix: stop false emergencies (real context window) + preserve compressed summaries#110
ranxianglei wants to merge 1 commit into
masterfrom
2026-08-10_nudge-real-window

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

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 from realUsage.percent). The nudge computes fullness as tokenCount / 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 as modelContextLimit for 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)
coreOutToAgentMessages previously continued past every acp_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)

  • emergencyNothingLeft adapter wiring: read 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).
  • biggest-reclaim-tier-first nudge arbitration: separate acp-kernel change.

Verification

typecheck clean, 156/156 tests pass (+3 new for resolveEffectiveContextLimit; updated the old "filters out summary" test to assert emission). Build 410 KB.

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

1 participant