Skip to content

[ai][Bug][opencode/0.1.216] agy-cli 112 KiB replay clipping makes [acp-usage] report ~5% usage while outbound is 7.0 MiB, keeping nudge idle | agy-cli 112 KiB 重放裁剪使 [acp-usage] 仅报 ~5%,导致 outbound 7.0 MiB 仍维持 nudge idle #7444

Open

Description

@CaFeeling

Environment

  • OS: Windows
  • billion-context: 0.1.216 (lane: opencode, http://127.0.0.1:18787)
  • Upstream: Magpie 0.1.4623 + @magpie-community/opencode-agy-cli-auth 0.1.105 (agy-cli ACP 1.5.13)
  • Client: OpenCode 2.3.2 (compaction.auto = false)

Problem

When routing agy-cli models through billion-context, nudge judges context usage from the upstream [acp-usage] input token count. However, opencode-agy-cli-auth clips replayed history to 112 KiB (maxInitialPromptBytes due to agy.exe's 128 KiB ACP prompt limit) whenever replay occurs (no_live / drop_live / model switch).

As a result:

  • billion-context forwards 7.0 MiB (1287 msgs, ~2,034,181 est tok),
  • agy-cli clips it to 41 msgs / 44.5 KB (prompt_bytes=113,708) before sending to agy.exe,
  • agy.exe returns [acp-usage] input=50032,
  • billion-context sees usage=5% (50032/983040) and stays nudge idle (growth 0 < floor 22500), never compressing the 7.8 MiB session!

Similarly, in another active session (ses_e03a1f678ffeIFNmz1CeEv6390), acp_status shows:

  • Context (session accounting, host footer scale): 6% (61k / 1.0M) (from [acp-usage] input=60970)
  • Sent to LLM (after compression, est.): 452k (43% of limit) (from outbound=502.6KiB)

Logs (bili.log & app.log correlated)

# bili.log (10:38:15)
[ses_e06adb84effeu6Bg8VC1pz9aMN] request: 1287 msgs, inbound=7.8MiB, outbound=7.0MiB, local=12669ms
[ses_e06adb84effeu6Bg8VC1pz9aMN] slow-session: 1287 msgs / inbound=7.8MiB (~2034181 est tok)

# magpie app.log (10:38:24)
{"event":"agy_bridge_session","conv":"40919e565572","action":"replay","reason":"no_live","messages_before":1218,"messages_after":41,"bytes_before":2413101,"bytes_after":44499,"prompt_bytes":113708}

# bili.log (10:38:37 - 10:38:38)
[ses_e06adb84effeu6Bg8VC1pz9aMN] [plugin] [acp-usage] input=50032 cached=0 (cache hit 0%)
[ses_e06adb84effeu6Bg8VC1pz9aMN] nudge idle: usage=5% (50032/983040), growth=0/22500 (ref=50032, interval=50000), pendingT1=711791/50000 model=agy-cli/gemini-4-neon, reason="growth 0 < floor 22500, ready: T1 711791"

Suggested Fix

When outbound estimated tokens are vastly higher than the upstream [acp-usage] input tokens (e.g. outbound ~1.8M–2M est tokens vs input=50032, or outbound > 50% of effectiveWindow while acp-usage < 15%), nudge should fall back to billion-context's own outbound token estimate instead of staying nudge idle on the clipped upstream acp-usage.

Activity

  1. ranxianglei commented on Nov 21, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

    (ai: vllm-qwen/qwen3.8-27b)

    查重: 不重复 — no existing issue/PR covers the upstream-clipped usage report class. The anchorImpossible guard (#4805) handles side-lane pollution (producer sent a tiny payload), not upstream clipping (producer sent the full payload, upstream clipped it invisibly).

    Fix

    PR: #7446

    Root cause: effectiveTokenCount's anchorImpossible guard (condition B: payloadUpperNow >= lastUsagePayloadUpper * 8) cannot fire when bili sent the full history both times — the clip happens upstream (agy-cli's 112 KiB maxInitialPromptBytes), invisible to bili. The usage report (50032) describes the clipped payload, not the 2M-char payload bili forwarded. Result: nudge idle on a 7.8 MiB session.

    Fix: Added 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.

    Condition: localInputEstimate >= lastInputTokens * 16 AND localInputEstimate >= 500_000 (chars).

    The 16x ratio (vs the 8x SIDE_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):

    Tests: New tests/issue7444-agy-cli-clipping.test.ts (6 tests). All 52 tests in the related suite pass (issue4805, issue4383, issue5134, side-lane-invariants, issue1820).


    八问(中文,供 reviewer 参考):

    1. 是什么问题: agy-cli 在 replay 时把历史截断到 112 KiB,bili 转发 7.0 MiB 完整历史后上游只报告截断后的 50032 tokens,nudge 判断 usage=5% 保持 idle,7.8 MiB 会话永远不压缩。

    2. 什么原因导致的: anchorImpossible 守卫条件 B 要求当前 payload 比生产者快照大 8 倍以上,但 bili 两次都发送了完整历史(截断发生在上游,bili 不可见),条件 B 无法触发。usage report 描述的是截断后的 payload,不是完整 payload。

    3. 影响范围与严重程度: 影响所有使用 agy-cli(或任何有 byte cap 的上游)的 multi-MiB 会话。核心压缩承诺静默失败——7.8 MiB 会话永远不压缩。

    4. 怎么修复的: 在 effectiveTokenCount 中添加 reportClipped 条件(16x 比率 + 500K 字符下限),gate 两个 usage 返回分支,fall through 到 local estimate。

    5. 是否有回归问题: 审了 post-rebuild usage estimate inflates ~3.4x after a big fold, firing an EMERGENCY T1 nudge into an over-budget context #1820 B e2e(dense code 37x ratio,186K chars)——500K 下限保护了 fast path。审了 Bypass requests overwrite the main session's usage anchor, causing long sessions to permanently stop compressing. | 旁路请求覆盖主会话 usage 锚点,导致长会话永久停止压缩 #4805 anchor pollution——所有 52 个相关测试通过。无回归。

    6. 是否破坏缓存: 不涉及。

    7. 是否改了设计方向: 不涉及。修改在现有函数内,无架构变更。

    8. 是否引入了新的配置: 不涉及。

  2. changed the title [-][Bug][opencode/0.1.216] agy-cli 112 KiB replay clipping makes [acp-usage] report ~5% usage while outbound is 7.0 MiB, keeping nudge idle[/-] [+][ai][Bug][opencode/0.1.216] agy-cli 112 KiB replay clipping makes [acp-usage] report ~5% usage while outbound is 7.0 MiB, keeping nudge idle | agy-cli 112 KiB 重放裁剪使 [acp-usage] 仅报 ~5%,导致 outbound 7.0 MiB 仍维持 nudge idle[/+] on Nov 21, 2026
  3. added a commit that references this issue on Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions