Repository navigation
[PR] fix: detect upstream-clipped usage reports so nudge fires on multi-MiB sessions - #7446
Open
ranxianglei wants to merge 1 commit into
Open
ranxianglei wants to merge 1 commit into
ranxianglei wants to merge 1 commit into
Conversation
…B sessions (#7444) agy-cli (opencode-agy-cli-auth) clips replayed history to 112 KiB (maxInitialPromptBytes, agy.exe's 128 KiB ACP prompt limit) on every replay. bili forwards the full 7.0 MiB history, agy-cli clips it to 41 msgs / 44.5 KB, agy.exe reports [acp-usage] input=50032. The existing anchorImpossible guard cannot catch this: condition B requires the current payload to tower 8x over the producer's snapshot, but both are ~2M chars (bili sent the full history both times). The distinguishing fact: the outbound char-bound (localInputEstimate) towers 16x+ over the report AND is itself multi-megabyte (>= 500K chars). An honest report of a small-to-medium payload can legitimately under-report by 16x+ on dense code (#1820 B e2e: 186K chars over a 5k report = 37x), but the clipped-payload class only manifests on multi-MiB sessions where the upstream's byte cap is far below the forwarded history. The fix adds a reportClipped condition to effectiveTokenCount that gates both usage-returning branches (main usage + grade), falling through to the local estimate so the nudge sees the true payload size and fires. Closes #7444
Contributor
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.11176-pr.7446.f47f8c6This exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr7446.tgz
npm install -g packageInstall instructions are refreshed on each push. |
This branch has not been deployed
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.
Problem
agy-cli (opencode-agy-cli-auth) clips replayed history to 112 KiB (
maxInitialPromptBytes, agy.exe's 128 KiB ACP prompt limit) on every replay (no_live/drop_live/ model switch). bili forwards the full 7.0 MiB history (1287 msgs, ~2M chars), agy-cli clips it to 41 msgs / 44.5 KB, agy.exe reports[acp-usage] input=50032. The existinganchorImpossibleguard cannot catch this: condition B requires the current payload to tower 8x over the producer's snapshot, but both are ~2M chars (bili sent the full history both times).Result:
nudge idleon a 7.8 MiB session — the core compression promise silently fails.Root cause
The usage report (50032) describes the CLIPPED payload, not the full payload bili sent. The
anchorImpossibleguard's condition B (payloadUpperNow >= lastUsagePayloadUpper * 8) cannot fire when bili sent the full history both times — the clip happens upstream, invisible to bili.Fix
Add a
reportClippedcondition toeffectiveTokenCountthat gates both usage-returning branches (main usage + grade), falling through to the local estimate so the nudge sees the true payload size and fires.The condition:
localInputEstimate >= lastInputTokens * 16ANDlocalInputEstimate >= 500_000(chars). The 16x ratio (vs the 8xSIDE_LANE_ANCHOR_IMPOSSIBLE_RATIO) and the 500K-char floor together distinguish true clipping (agy-cli: 2M chars / 50032 tokens = 40x) from honest under-reports on dense code (#1820 B e2e: 186K chars / 5000 tokens = 37x, below the 500K floor).Behavior change (old → new)
effectiveTokenCountreturns the clipped report (e.g. 50032) assource: "usage"→ nudge idle.effectiveTokenCountreturns the local estimate (e.g. 2M chars) assource: "estimate"→ nudge fires (EMERGENCY tier if over window).Tests
tests/issue7444-agy-cli-clipping.test.ts(6 tests: T1 agy-cli clipping, T2 post-rebuild usage estimate inflates ~3.4x after a big fold, firing an EMERGENCY T1 nudge into an over-budget context #1820 B honesty, T3 small-session guard, T3b post-rebuild usage estimate inflates ~3.4x after a big fold, firing an EMERGENCY T1 nudge into an over-budget context #1820 B e2e margin, T4 grade branch gated, T5 honest large-session report)Closes #7444