Repository navigation
fix(floor): skip the provider-usage floor while the anchor predates a successful compress - #259
Merged
Merged
Conversation
… successful compress pi's getContextUsage() anchors on the last assistant message with valid provider usage. A successful compress lands AFTER that anchor, so the next LLM call floors the meter at the pre-compress request size and re-runs the emergency decision (nudge + mechanical tool-result truncation) on context that was just shrunk; the panel keeps showing the old large number too. - new src/floor-stale.ts: usageAnchorPredatesCompression(entries) scans the branch for the last valid assistant usage anchor (same validity rule as pi's getAssistantUsage) vs the last successful compress toolResult (panel >0 blocks; failed/no-op compresses don't count) - skip the floor while stale at all three processTurn sites (context transform, acp_status, /acp panel; the panel's sessionTokens number too) - mirrors pi's own post-compaction check: "usage source must be post-compaction" (agent-session.js) - fixes the floor comment in src/index.ts that claimed "can't cause a false emergency" (not true for usage-less providers' tree-sum fallback — now documented as the accepted omp #18 trade-off) - docs: token-calibration-plan.md banner marks the density system removed in #258 and records the current design + accepted trade-offs - tests: 8 unit cases + extension-level regression (97% usage anchor predating a successful compress -> no emergency nudge); 422 pass
Contributor
📦 Built Extension ArtifactBranch: Option A — Install from npm PR tag (recommended)pi install npm:billion-context-pi@pr-259Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pi-pr259.tgz
pi install ./packageThis comment is automatically updated on each push. |
HangxiangMa
pushed a commit
to HangxiangMa/billion-context-pi
that referenced
this pull request
Sep 21, 2026
…stale-anchor fix(floor): skip the provider-usage floor while the anchor predates a successful compress
HangxiangMa
pushed a commit
to HangxiangMa/billion-context-pi
that referenced
this pull request
Sep 21, 2026
…acks Fixes ranxianglei#401 - src/packs/* deleted (229 lines): types/sanitize/lean/builtin/dir all live in the kernel now (acp-kernel ranxianglei#259/ranxianglei#260, v0.0.66) - src/prompt-pack.ts rewritten on kernel exports; external surface (packResolver/resolveActivePack/mergeSurface/readToolSurfaceWithPacks) unchanged - pi-specific surface (PiPromptSections tri-state, tool extras, delegatePrompt) read from surface.adapters.pi and sanitized adapter-side; kernel treats it as opaque data - lean assertions moved to kernel leanPack.adapters.pi (aligned recall rules from ranxianglei#399/ranxianglei#400) - acp-kernel pinned 0.0.65 -> 0.0.66 (exact) - 792 tests: 789 pass / 0 fail / 3 skipped (pre-existing); typecheck+build green
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.
fix(floor): skip the provider-usage floor while the anchor predates a successful compress
问题(#258 评审发现)
getContextUsage()锚定最后一条带有效 usage 的 assistant 消息。#258 引入的 floor(tokenCount = max(sentTokens, realUsage.tokens))在压缩成功后的一轮会出问题:后果(压缩后的一个请求窗口内):
emergencyTruncateNode在 ≥95% 时无条件执行,把刚通过压缩保留下来的工具结果截成 2K+2K+marker(数据丢失);acp_status永久显示压缩前的大数字 直到下一条 usage 到达。下一条 assistant usage 到达即自愈,但窗口内的截断是不可逆的。
pi 自身的 compaction 有同样的检查(
agent-session.js:"Verify the usage source is post-compaction"),本 PR 把对齐检查带到扩展的 floor 上。修复
新增
src/floor-stale.ts:usageAnchorPredatesCompression(entries)getAssistantUsage规则的 assistant(role=assistant、stopReason 非 aborted/error、totalTokens 或分项之和 > 0);isError/0-block no-op 不算 — 它们没有改变上下文);三个调用点一致接入,保证决策与显示不分裂:
src/index.tscontext transformstale-anchor-skip),nudge/truncate 仲裁用 sentTokenssrc/status-tool.tsacp_statussrc/commands.ts/acp面板sessionTokens不再取 stale usage同时修正
src/index.ts的 floor 注释:原文声称 realUsage "can't cause a false emergency",对不上报 usage 的 provider(tree-sum 回退)不成立 — 现如实记录为已接受取舍。测试(+9,413 → 422 pass / 0 fail)
tests/floor-stale.test.ts(8 个单元用例):fresh anchor / stale anchor / 无 compress / 失败 compress 不算 / 0-block no-op 不算 / error·aborted·全零 usage 不算锚点 / 仅 totalTokens / 非 compress 工具结果忽略;tests/sent-view-arbitration.test.ts(扩展级回归):19 条消息流 +usage: 175k锚点 + 成功 compress toolResult +fakeCtx(175_000)→ 0 nudge(对照组:无 usage → 0;floor 生效组:无 compress → nudge ≥1)。验证:
npm run typecheck✅ ·npm test422/0 ✅ ·npm run build✅(518.85KB)版本
0.1.52 → 0.1.53,CHANGELOG 已在 Unreleased 段记录。已知取舍(评审记录,不在本 PR 范围)
countTokens回到未校准估算(密度系统已随 fix: run nudge/emergency decision on provider-reported prompt size (#257) #258 移除),CJK 低估 2–5×;决策层由 floor 兜底,/status以 Provider-reported 为准。关联