(fix) cap emergency nudge injections per user turn (closes #108) - #119
Open
ranxianglei wants to merge 2 commits into
Open
(fix) cap emergency nudge injections per user turn (closes #108)#119ranxianglei wants to merge 2 commits into
ranxianglei wants to merge 2 commits into
Conversation
Contributor
Author
|
我来协助看一下这个问题,请分析并回复处理结果。 |
added 2 commits
September 8, 2026 20:20
…66666#108) An unrelieved >= emergencyThreshold pressure re-injected a durable emergency nudge on EVERY agent/pre-step (each appended as a user/message event), and the nudge's own tokens pushed usage higher -> a runaway positive-feedback loop that never stops because no-op compress calls are not terminal. Cap emergency nudges at EMERGENCY_NUDGE_MAX_PER_TURN (3) per user turn; normal- pressure nudges remain once-per-turn (behavior unchanged). Mirrors billion-context-pi commit 414acd1. Adds a regression test asserting the cap bounds re-injection (an uncapped kernel emits an emergency nudge on every step). Note: the new per-session emergencyNudges map follows the existing lastNudgeTurn pattern; broader per-session Map cleanup is tracked in Tyan66666#113. <!-- ework-agent-pr -->
…ap-hit log, docs sync - Rewrite the cap regression test with explicit per-call assertions: calls 1-3 inject, the 4th returns null, later calls stay null; assert the cap-hit hook fires for every suppressed call - New tests: the cap resets on a new user turn; a normal nudge does not consume the emergency budget (same-turn mixed pressure) - buildNudge takes an optional onEmergencyCapHit callback; the engine logs a warn when the per-turn emergency budget is spent, so operators can see why the model stops receiving nudges (issue Tyan66666#108 review) - Docs sync: README zh/en config table, config comments, AGENTS.md module map - Cap stays hardcoded at 3 (a safety mechanism, not a tuning knob — per review)
ranxianglei
force-pushed
the
2026-09-06_issue108-emergency-nudge-cap
branch
from
September 8, 2026 12:32
eecbd76 to
52438ce
Compare
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.
Closes #108.
Problem
When context pressure stays above the emergency threshold (engine default
0.85), every agent step re-injects a full emergency nudge, and each nudge is appended as a durableuser/messageevent. If the pressure does not come down (the model no-ops, picks the wrong range, or the content is protected), the nudge's own tokens push usage even higher — a positive feedback loop that never stops. billion-context-pi hit the same failure mode (#223: retry prompt re-injected ~400×/hour, eventually removed) and fixed it with a per-user-turn cap (commit414acd1).Cause
src/nudge.tsdedups only normal nudges per user turn (lastNudgeTurn); the emergency path bypassed the dedup entirely (!emergency && …). No attempt counter, cap, or cooldown existed anywhere in the repo.Fix
EMERGENCY_NUDGE_MAX_PER_TURN = 3(hardcoded — a safety mechanism, not a tuning knob): emergency nudges are capped at 3 injections per user turn, tracked in a per-sessionemergencyNudgesmap ({ turn, count }). The budget resets when the user turn advances (same semantics as the normal dedup).warn(emergency nudge suppressed — per-turn budget of 3 spent …) so operators can see WHY the model stops receiving nudges (issue [compression] emergency nudge 无上限逐 step 重注入,且缺少 compress attempt 断路器 #108 review).Scope note: this PR implements proposal #1 from the issue (the per-turn cap), which bounds the unbounded re-injection loop — the token-leak part. The compress-attempt circuit breaker (proposals #2/#3) is a follow-up; the kernel-side
minPressureBenefitgate lands with the acp-kernel ≥0.0.54 bump planned in #116.Review follow-up (2026-09-08)
Applied from the review on #108:
logger.warnon cap hit (in theagent/pre-stephandler,src/index.ts).main(v0.2.21 + e2e harness); nodist/changes carried — per the current policy the dist-bot refreshesmainafter the merge.(fix) …form required by the pr-title CI check (the oldfix(nudge): …form failsscripts/check-pr-title.mjs).Verification
npm run typecheck— cleannpm test— 216/216 pass (including the three [compression] emergency nudge 无上限逐 step 重注入,且缺少 compress attempt 断路器 #108 tests above)npm run build— clean (local check only;dist/not committed)