Repository navigation
fix: nudge injection loop — 3 defects from issue #216 - #218
Merged
Merged
Conversation
Defect 1: applyAnchoredNudges ran before nothingToCompress was computed,
injecting full nudge text even when filter said nothing to compress.
Fix: moved recommendation filter computation before applyAnchoredNudges,
gated with shouldInjectNudge.
Defect 2: messageHasCompress only counted status=completed, so failed
compress calls never reset lastNudgeShownTokens → threshold permanently
halved → nudge frequency accelerated instead of backing off.
Fix: new messageHasCompressAttempt counts any compress tool call
regardless of status.
Defect 3: HOW_TO_COMPRESS_RULES (~1.5K tokens) sent on every nudge.
Fix: compressRulesShown flag — rules sent only once per session.
Files: lib/messages/{inject/inject,query}.ts, lib/state/{types,state,
persistence,utils}.ts, tests/nudge-loop-fix.test.ts (7 new).
936 tests pass, typecheck clean.
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)
Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Defect 2: failed compress now clears halved-threshold state (anchors, lastNudgeShownTokens) but does NOT run proportional baseline adjustment. Baseline stays unchanged — growth accumulates until there's genuinely more to compress. Previously treated failed compress identically to success, eating growth. Defect 3 (HOW_TO_COMPRESS_RULES dedup): reverted. Rules are needed every time for compression quality. Fixes 1+2 break the loop that caused rules to repeat every ~10s — without the loop, per-nudge rules overhead is acceptable. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
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.
Summary
Fixes the self-reinforcing nudge injection loop described in issue #216.
Defect 1: applyAnchoredNudges before nothingToCompress check
applyAnchoredNudgesran BEFOREnothingToCompresswas computed, injecting full nudge text (with HOW_TO_COMPRESS rules ~1.5K tokens) even when the filter determined there was nothing to compress.Fix: Moved
buildCompressibleRanges+filterRecommendedRanges+nothingToCompresscomputation BEFOREapplyAnchoredNudges. Changed gate fromif (nudgeAllowed)toif (shouldInjectNudge).Defect 2: Failed compress calls never reset pending-nudge state
messageHasCompressonly countedstatus === "completed". Failed/rejected compress calls didn't resetlastNudgeShownTokens, keeping the threshold permanently halved → nudge frequency accelerated instead of backing off.Fix: New
messageHasCompressAttempt()counts ANY compress tool call regardless of status. Used atcurrentTurnHasCompresscall site.messageHasCompress(completed-only) retained for priority classification.Defect 3: Heavy nudge payload self-inflates
Every nudge carried full HOW_TO_COMPRESS rules (~1.5K tokens). Loop from 1+2 caused injection every turn → nudges themselves inflated context.
Fix:
compressRulesShownflag in session state — rules sent only once per session.Test plan
messageHasCompressAttemptdetects failed compress (status=error, invalid_request_error), distinguishes frommessageHasCompressCloses #216.