You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[bot] 🏷 Triage complete — verified the bug end-to-end, and I have a concrete recommendation. Details below.
Verification (all claims confirmed against master @ 3a603b8, acp-kernel 0.0.56)
Kernel blind spot — decideNudge (node_modules/acp-kernel/dist/index.js:2556-2629): with tokenCount == 0, usage = 0 so firstSightMassReady (requires usage >= minContextLimitPct, :2591) is false, all pressure bands (require usage >= maxContextLimitPct/emergencyThresholdPct, :2562-2564) are false, and growthReference falls back to tokenCount itself (:2569) making growthSinceReference ≡ 0 (:2574) — never reaches the growth floor. A zero tokenCount makes the nudge structurally unfireable. Confirmed.
Host feeds zero — effectiveTokenCount (src/server.ts:1846-1850): explicit-identity sessions with lastInputTokens == 0 return 0; only anonymousPrefixAffinity sessions get estimateCoreMessagesUpper. The rationale comment (:1840-1845) assumes zero-baseline explicit sessions "self-heal via the next measured usage report" — that assumption is exactly what breaks for never-reporting backends.
Usage source — Responses adapter reads usage only from responseObj.usage.input_tokens on response.completed (src/loop/adapter-responses.ts:456-471); the ChatGPT login backend omits it, so lastInputTokens stays 0 for the whole session. Note the OpenAI chat path force-injects stream_options.include_usage=true (src/server.ts:2224-2225), so this failure mode is specific to genuinely silent backends (ChatGPT login, some relays) — matching [Bug] Codex 额度中断后恢复长会话,preflight SSE 摘要为空并持续 502 #726's log evidence.
"Never measured" vs "measured as 0" — no separate flag needed. Every lastInputTokens write is either the 0 init (src/session.ts:311) or Math.max(0, positive) (usage handlers src/server.ts:3857, plugin.ts:594, credit nets in absorb.ts:111/stream.ts:144/weak-overflow.ts:186). A real input_tokens: 0 report is effectively impossible (any non-empty request bills > 0), so == 0is "never measured".
Layer judgment
Root cause is exactly as filed: the nudge's decision input (tokenCount) has no source at all when the upstream never reports usage — not a threshold tuning problem, not a kernel policy gap per se (the kernel behaves correctly given 0). #727 made the consequence (emergency preflight at the hard limit) recoverable/diagnosable; this issue is the growth source upstream of it. Complementary, no conflict between them.
Option assessment
Option 2 (kernel estimated: true flag): reject. The kernel treats tokenCount opaquely — the host fully controls what it feeds, so a kernel-side flag buys nothing functional beyond log cosmetics, at the cost of the cross-repo release dance (acp-kernel first, pin bump, two releases). Not worth it.
Option 3 (proxy forced fold at window × (1-margin)): defer. It's defense-in-depth, but the safety net for "model ignores the nudge" already exists at multiple layers: EMERGENCY_NUDGE_ESCALATION_PCT = 0.7 force-nudges every turn below the limit line (src/server.ts:1993), the kernel pressure band above maxContextLimitPct, #453's output clamp, and preflight at the hard limit. Revisit only if field data shows nudges being ignored on silent backends.
Option 1 (host-side fallback): recommend — with one refinement that matters. Feeding the estimate of the raw client messages (the literal reading of option 1) is wrong for proxy mode: the client re-sends its full raw history every turn while folds are applied per-request server-side, so a raw-msgs estimate inflates unboundedly even after successful compression → false-positive pressure bands, premature emergency-truncate (which mutates visible tool output — a real quality regression), and inflated status-panel numbers.
Instead, mirror lastInputTokens's actual semantics — "what the upstream saw last turn" — by measuring locally what we forwarded:
New stat session.stats.localInputEstimate?: number: each of prepareAnthropic/prepareOpenai/prepareResponses stores, just before returning, estimateCoreMessagesUpper(processedMessages) + countSystemAndToolsTokens(outboundSystem, toolsOut) + imageTokensInParsedBody(protocol, rebuilt) — i.e. the post-fold outbound payload, CJK-safe char-count upper bound, same one-turn lag as a real usage report. Self-corrects after every fold (post-fold payload is small → estimate drops → no inflation).
effectiveTokenCount becomes: lastInputTokens > 0 → real usage (unchanged priority); else localInputEstimate > 0 → it; else the existing anonymous-prefix-affinity raw-upper-bound branch (untouched). Turn 1 of a fresh explicit session still feeds 0 (nothing pending anyway), so first-turn behavior is byte-identical.
Out of scope, deliberately: the one-shot handoff paths prepareCountTokens (:2529) and prepareResponsesCompact (:2609/:2616) pass lastInputTokens directly — those requests are the compaction mechanism, so a nudge decision there drives nothing incremental. Left as-is.
Tests to include: real-usage precedence, first-turn explicit identity still 0, multi-turn never-measured growth reaching the nudge thresholds (mock upstream emitting no usage), anonymous-fork regression unchanged, post-fold estimate drop.
Net effect: silent-backend sessions get proactive incremental compression from the moment the local estimate crosses minContextLimitPct, instead of climbing unbounded to a ~630K-token emergency summarization call that may 502-loop (#726).
Activity
ranxianglei commentedon Sep 12, 2026
[bot] 🏷 Triage complete — verified the bug end-to-end, and I have a concrete recommendation. Details below.
Verification (all claims confirmed against master @ 3a603b8, acp-kernel 0.0.56)
decideNudge(node_modules/acp-kernel/dist/index.js:2556-2629): withtokenCount == 0,usage = 0sofirstSightMassReady(requiresusage >= minContextLimitPct, :2591) is false, all pressure bands (requireusage >= maxContextLimitPct/emergencyThresholdPct, :2562-2564) are false, andgrowthReferencefalls back totokenCountitself (:2569) makinggrowthSinceReference ≡ 0(:2574) — never reaches the growth floor. A zero tokenCount makes the nudge structurally unfireable. Confirmed.effectiveTokenCount(src/server.ts:1846-1850): explicit-identity sessions withlastInputTokens == 0return 0; onlyanonymousPrefixAffinitysessions getestimateCoreMessagesUpper. The rationale comment (:1840-1845) assumes zero-baseline explicit sessions "self-heal via the next measured usage report" — that assumption is exactly what breaks for never-reporting backends.responseObj.usage.input_tokensonresponse.completed(src/loop/adapter-responses.ts:456-471); the ChatGPT login backend omits it, solastInputTokensstays 0 for the whole session. Note the OpenAI chat path force-injectsstream_options.include_usage=true(src/server.ts:2224-2225), so this failure mode is specific to genuinely silent backends (ChatGPT login, some relays) — matching [Bug] Codex 额度中断后恢复长会话,preflight SSE 摘要为空并持续 502 #726's log evidence.lastInputTokenswrite is either the 0 init (src/session.ts:311) orMath.max(0, positive)(usage handlerssrc/server.ts:3857,plugin.ts:594, credit nets inabsorb.ts:111/stream.ts:144/weak-overflow.ts:186). A realinput_tokens: 0report is effectively impossible (any non-empty request bills > 0), so== 0is "never measured".Layer judgment
Root cause is exactly as filed: the nudge's decision input (
tokenCount) has no source at all when the upstream never reports usage — not a threshold tuning problem, not a kernel policy gap per se (the kernel behaves correctly given 0). #727 made the consequence (emergency preflight at the hard limit) recoverable/diagnosable; this issue is the growth source upstream of it. Complementary, no conflict between them.Option assessment
Option 2 (kernel
estimated: trueflag): reject. The kernel treatstokenCountopaquely — the host fully controls what it feeds, so a kernel-side flag buys nothing functional beyond log cosmetics, at the cost of the cross-repo release dance (acp-kernel first, pin bump, two releases). Not worth it.Option 3 (proxy forced fold at
window × (1-margin)): defer. It's defense-in-depth, but the safety net for "model ignores the nudge" already exists at multiple layers:EMERGENCY_NUDGE_ESCALATION_PCT = 0.7force-nudges every turn below the limit line (src/server.ts:1993), the kernel pressure band abovemaxContextLimitPct, #453's output clamp, and preflight at the hard limit. Revisit only if field data shows nudges being ignored on silent backends.Option 1 (host-side fallback): recommend — with one refinement that matters. Feeding the estimate of the raw client messages (the literal reading of option 1) is wrong for proxy mode: the client re-sends its full raw history every turn while folds are applied per-request server-side, so a raw-msgs estimate inflates unboundedly even after successful compression → false-positive pressure bands, premature emergency-truncate (which mutates visible tool output — a real quality regression), and inflated status-panel numbers.
Instead, mirror
lastInputTokens's actual semantics — "what the upstream saw last turn" — by measuring locally what we forwarded:session.stats.localInputEstimate?: number: each ofprepareAnthropic/prepareOpenai/prepareResponsesstores, just before returning,estimateCoreMessagesUpper(processedMessages) + countSystemAndToolsTokens(outboundSystem, toolsOut) + imageTokensInParsedBody(protocol, rebuilt)— i.e. the post-fold outbound payload, CJK-safe char-count upper bound, same one-turn lag as a real usage report. Self-corrects after every fold (post-fold payload is small → estimate drops → no inflation).effectiveTokenCountbecomes:lastInputTokens > 0→ real usage (unchanged priority); elselocalInputEstimate > 0→ it; else the existing anonymous-prefix-affinity raw-upper-bound branch (untouched). Turn 1 of a fresh explicit session still feeds 0 (nothing pending anyway), so first-turn behavior is byte-identical.armFailureShrink(src/server.ts:3100-3133) deliberately feeds a local estimate intolastInputTokenson usage-less failures, documented as: "the estimate RAISES the value only (→ compress earlier, never later), the kernel no-ops below its thresholds, and real usage overwrites it on success." Same three properties hold here: the upper-bound estimator only errs early (the arm emergency shrink on upstream failure to break relay-5xx deadlock #604 hazard was the chars/4 under-counting CJK — a different, optimistic estimator), it's active only whilelastInputTokens == 0, and any real report takes precedence immediately.prepareCountTokens(:2529) andprepareResponsesCompact(:2609/:2616) passlastInputTokensdirectly — those requests are the compaction mechanism, so a nudge decision there drives nothing incremental. Left as-is.Tests to include: real-usage precedence, first-turn explicit identity still 0, multi-turn never-measured growth reaching the nudge thresholds (mock upstream emitting no usage), anonymous-fork regression unchanged, post-fold estimate drop.
Net effect: silent-backend sessions get proactive incremental compression from the moment the local estimate crosses
minContextLimitPct, instead of climbing unbounded to a ~630K-token emergency summarization call that may 502-loop (#726).请确认方向:我推荐实施细化后的方案 1(host 侧以上一轮本地 post-fold 载荷上界估算兜底 tokenCount,真实 usage 永远优先),方案 2 不做(跨仓成本无功能收益),方案 3 暂缓(现有多层兜底已覆盖模型不配合的场景)。你拍板后我开分支实现。
中文摘要: 已逐条核实问题属实(kernel
decideNudge在 tokenCount=0 时结构性无法触发、host 对显式身份零基线会话喂 0、Responses 适配器只认response.completed.usage.input_tokens);病因是"上游不报 usage 时 nudge 决策输入无来源",#727 只修了下游症状;建议采用细化版方案 1——用上一轮本地 post-fold 外发载荷的上界估算(而非原始历史估算,避免折叠后无界虚高)在lastInputTokens==0时兜底,该模式与 #604armFailureShrink已确立的例外完全一致,不动 kernel。ranxianglei commentedon Sep 12, 2026
需要先确认,usage 应该是上游接口返回的,理论上都有的,你是说gpt登录版本没有?
ranxianglei commentedon Sep 12, 2026
[bot] 🏷 对——特指 ChatGPT 登录态消费端后端(
chatgpt.com/backend-api/codex/responses)。官方 OpenAI API(API key 模式,api.openai.com/v1/responses)是完整返回 usage 的;"理论上都有的"对文档化的官方 API 成立,但 #726 打的是另一个服务面。证据链:1. #726 的实测日志(最硬的一条)
那个会话跑了 269 条消息、上下文长到 ~1.32M tokens,日志里是:
lastInputTokens每轮被最新一次 usage 报告覆写——只要任何一轮上报过input_tokens,这个值就 > 0。整个长会话恒为 0,说明该后端从头到尾没给过一份带input_tokens的报告。2. 代码路径排除了"我们没解析到"
我们读的就是规范字段位置:
response.completed→response.usage.input_tokens(src/loop/adapter-responses.ts:464-468),和官方 API 的放置位置一致。读不到 = 后端没发(或发了非规范形状),不是提取 bug。3. 该后端已有多个同类先例
它是未文档化的消费端接口,已实证过多次偏离官方行为,每次都是靠用户会话发现的:强制
stream:true(#626)、拒绝max_output_tokens(#663)、现在是缺 usage。模式一致:不能假设它跟官方 API 对齐。诚实边界 + 一步定论的方法:我这边无法直连 chatgpt.com 做活体抓取(无登录态凭据),上面是从你的日志 + 代码路径推出的结论。想要铁证,你本机一条命令就能定论:
跑一轮任意短对话后看原始响应 dump(state 目录下
raw/*-RES.txt)里response.completed事件的usage对象长什么样——字段在不在、是 null 还是整个缺失,一眼可见。顺带发现一个次要缺口(本次核查时看到):我们的适配器只从
response.completed提取 usage,而response.incomplete事件按规范同样携带完整 response+usage,当前只被当作终止标记处理(adapter-responses.ts:472-476)。如果某后端只在 incomplete 响应里报 usage,我们也会漏掉。成本很低,建议并入本 issue 的修复范围一起补上。方向建议维持上一条回复不变(细化版方案 1:host 侧以上一轮本地 post-fold 载荷上界估算兜底,真实 usage 永远优先;方案 2 不做、方案 3 暂缓)。等你拍板。
ranxianglei commentedon Sep 12, 2026
你研究下源码 codex的 我理解这里可能有什么其他bug导致的 未必是这个字段
ranxianglei commentedon Sep 12, 2026
[bot] 🏷 研究完了 codex 源码(shallow clone 了
openai/codex@rust-v0.153.4——#726 用的正是这个版本)。结论:"未必是这个字段"的假设被源码排除了——codex 自己读的就是同一个字段;但这次调查有一个重要新发现:codex 内置了完整的"后端不报 usage → 本地估算兜底"机制,说明 OpenAI 把这种状态当作正常预期来设计。1. 同一个字段,没有备选位置
codex 的 SSE 解析器处理
response.completed(codex-rs/codex-api/src/sse/responses.rs:483-497):反序列化ResponseCompleted { id, usage: Option<ResponseCompletedUsage>, … }(结构体 :116-125,input_tokens: i64),然后token_usage: resp.usage.map(Into::into)。和 bili 读的response.completed.response.usage.input_tokens(我们这边src/loop/adapter-responses.ts:464-468)逐字节同一位置。如果后端把 usage 放在别处,codex 自己的状态栏也会同样失明。2. 没有任何客户端开关
请求构造里没有
include_usage之类的参数(全仓 grep 确认)——usage 上报是纯服务端行为,客户端既不能要求也不能抑制。排除"codex 发了什么特殊东西导致被过滤"。3. 核心发现:codex 把"usage 缺失"当一等公民处理
token_usage: Option<TokenUsage>贯穿整条管线(protocol.rs:1923、client.rs:2224);SSE 解析器有 4 处单测专门覆盖"completed 事件不带 usage →token_usage: None"(responses.rs:1570-1594等)。recompute_token_usage()(core/src/session/mod.rs:4395+)在拿不到服务端 usage 时用本地估算写入total_tokens(base instructions + 逐条历史项的字节启发式,approx_token_count= 4 字节/token,utils/string/src/truncate.rs:71,注释自述 "coarse lower bound")。AutoCompactWindowPrefill::{ServerObserved(i64), Estimated(i64)}(core/src/state/auto_compact_window.rs),文档注释明写 "server-observed usage replaces estimated resume/recompute baselines when available"——真实观测值优先、否则用估算,set_estimated_prefill在每轮 turn 设置时以全历史估算喂入(session/mod.rs:1617)。get_total_token_usage()(context_manager/history.rs:538-556)= 服务端观测值 + 上次模型生成项之后的本地增量估算。也就是说 OpenAI 造 codex 时就预期了"服务端可能什么都不报"的场景,并让压缩决策在这种场景下继续工作。这套"真实 usage 优先、否则本地估算"的模式和我在方案 1 里提的设计完全一致——等于有了业界先例背书。
4. 社区旁证:
openai/codex#43511(open)——ChatGPT 模式下 context usage 指示器完全不显示(连/status都没有)。那是 App 端的报告,不是直接证据,但和同一个根现象吻合。5. 自我更正一处:我上一条建议"顺手从
response.incomplete提取 usage"——codex 把response.incomplete当作错误处理("Incomplete response returned",responses.rs:461-470),不当正常终态。这项降级为低优先级可选项,不再是修复的一部分。遗留疑问(诚实说明):codex 自己的 auto-compact 为什么没在 #726 那个长会话里救场?源码层面无法完全确定——决策依赖用户配置(
model_auto_compact_token_limit、Total vs BodyAfterPrefix scope),而recompute_token_usage只触发于 compaction/rollback/历史重建之后,不是每轮都跑。如果报告者禁用了 codex 原生 auto-compact(他用 bili 做压缩层,很可能),或者额度错误挡住了它的 remote compaction 尝试,都不会触发。可以回头问下报告者的配置。这不影响 bili 侧结论:bili 的 nudge 决策输入全程为 0,无论 codex 自己在做什么,它都不可能触发。铁证方法不变:你本机
ACP_DUMP_BODY=1 bili start --port 8787跑一轮短对话,看raw/*-RES.txt里response.completed的usage对象——在不在、null 还是整个缺失,一眼定论。方向建议维持不变(细化版方案 1,现在有 codex 自身设计作先例);等你拍板。
ranxianglei commentedon Sep 12, 2026
[bot] ✅ 已拍板并实现——采用细化版方案 1(宿主侧兜底,不动 kernel),与 codex 源码验证的设计形态完全一致(服务端观测值永远优先,本地估算只在零基线兜底下工作)。PR:#731。
改动(三个文件,~60 行逻辑)
src/session.ts:Session.stats新增localInputEstimate——上一轮出站报文的字符数上界(= kernel 实际看到并被其用量统计的 payload),随 stats 持久化;native-compaction boundary 重置时随resetSession清除。src/preflight.ts(prepareForwarding/prepareCompressionTrigger/prepareSummary):返回前记录该轮出站上界(fold 后处理消息 + system/tools 开销 + image tokens)。title-gen 和 compaction-trigger 请求不记录;transform 失败时回退到未处理投影,保证兜底自身不被盲区击中。src/context.ts(effectiveTokenCount):真实 usage 优先权不变、匿名前缀亲和 fork 的原始入站上界分支原样保留;仅当lastInputTokens == 0且非匿名 regime 时,改喂localInputEstimate,并用本请求入站上界封顶(客户端侧收缩后的高位陈旧读数不会跨轮残留)。无测量记录时回退 0——首轮行为与修复前逐字节一致。为什么是"上一轮出站"而不是"当前轮入站":proxy 模式下客户端每轮重发完整原始历史 + 增量 delta,当前轮入站会把已 fold 掉的内容重新算回来 → 虚高 → nudge 每轮都开火。出站是 kernel 的真实视野,fold 后自动缩小,天然自校正,不需要任何"折叠量"簿记。一轮延迟与真实 usage 报告本身的延迟相同。
三条不变式(#604
armFailureShrink异常同款纪律):① 上界估算只会偏早、不会偏晚;② 仅在lastInputTokens == 0期间生效;③ 任何真实 usage 上报即刻接管。一次性 handoff 路径(executeForkHandoff/executeNativeCompaction)按分诊保持原样直传 tokenCount。验证:全量套件绿(1428 tests / 1426 pass / 2 skip / 0 fail)。新增
tests/silent-backend-nudge.test.tse2e 钉住三个场景(Anthropic wire、显式 identity):input_tokens: 2000效果:静默后端会话从"撞上 1.05M 硬限才做 ~630K 一次巨型应急折叠(#726 事故链)"变为本地估算一过核阈值就渐进折叠。
ranxianglei commentedon Sep 12, 2026
[bot] 🏷 PR #731 审查完成:可以合并(合并由你操作;建议合并前手动 dispatch 一次
ci-e2e.yml,本环境无本地上游跑不了完整 E2E——与 #727 同样的限制)。验证结果(PR 分支 c899546 @ 最新 master + acp-kernel 0.0.66 上重跑)
npm run typechecknpm run buildE2E_CHECK=1)Diff 审查
localInputEstimate新 stat(可选字段、随 stats 持久化、native-compaction boundary 随resetSessionCompression清零);三个 prepare* 各轮记录"post-fold 出站消息 + system/tools 开销 + image tokens"上界、transform 失败回退未处理投影、title-gen 跳过、compaction-trigger 跳过;effectiveTokenCount优先级链(真实 usage → 匿名前缀亲和分支原样 → 本地估算且被本请求入站上界封顶 → 0);arm emergency shrink on upstream failure to break relay-5xx deadlock #604 三条不变式全部保持;首轮行为逐字节不变。✅isTitleGen(maxTokens <= 200)只存在于 OpenAI wire(src/server.ts:2241),Anthropic wire 没有 title-gen 流程,所以只有prepareOpenai需要守卫。✅直接修掉的问题(已在 PR 里处理,无需代码改动)
PR 描述里的文件/函数名有 6 处是不存在的名词:
prepareForwarding/prepareCompressionTrigger/prepareSummary/executeForkHandoff/executeNativeCompaction/resetSession,以及不存在的src/context.ts(实际改动全在src/server.ts,reset 函数叫resetSessionCompression,one-shot 路径是prepareCountTokens/prepareResponsesCompact)。代码本身完全正确,只是文档写串了——我已通过 API 直接修正 PR body 并复核生效(phantom 名词全部清零)。本线程上方公告评论里的同名清单同样不准(用户评论我改不了,以 PR body 为准)。仅报告的小观察(不阻塞)
prepareAnthropic的记录是无条件的,没有 side-request 守卫(isTitleGen启发式只覆盖 OpenAI wire)。若某个 Anthropic wire 客户端在同 session key 下发微小 side request(#388 一类),估算值会被单次覆盖为低位,下一正常轮自动重测自愈,影响仅是 nudge 延迟一轮;且既有systemPromptTokens行(server.ts:2077)同样无条件记录,属既有惯例。只对"走 Anthropic wire 的静默后端"有意义——当前不是真实场景(ChatGPT 登录态走 Responses wire)。留档即可,不建议为此加复杂度。中文摘要: 审查了 #731(diff 干净、实现与分诊拍板的细化版方案 1 逐条一致、测试三场景属实),在最新 master 上重跑 typecheck/build/1428 例全量/E2E preflight 全绿并吻合公告数字;发现并直接修正了 PR 描述中 6 处不存在的函数/文件名(代码本身无误),另报告一个 Anthropic wire side-request 覆盖的低危小观察,可以合并。
fix(#728): feed the local outbound-payload estimate to the nudge whil…
fix(#728): feed the local outbound-payload estimate to the nudge whil…
Merge pull request #731 from ranxianglei/2026-09-12_silent-usage-nudg…
fix: strip model-echoed render tags from tool-call arguments on every…
fix: measure compress shrink against the live view, flag degenerate r…
fix: seed the nudge sizing baseline on fork receipts (#2832-era dead …
refactor(#3977): Step 1 — pure extraction of the size-evidence stores…
fix: count the image term in effectiveTokenCount's anonymous fork branch
fix: ride the calibrated per-send estimate on cycle-stale meters (#5500)
kernel: cap the #5860 estimate-grade pressure hold at N consecutive r…
kernel: cap the ranxianglei#5860 estimate-grade pressure hold at N co…