Skip to content

fix: codex lane — keep the proactive compression channel alive (#3008) - #3018

Merged
ranxianglei merged 1 commit into
masterfrom
2026-10-13_codex-proactive-channel
Oct 13, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-10-13_codex-proactive-channel

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Closes #3008

What

Session CODEX-01A130C1 forensics proved bili's proactive compression channel was dead for over an hour while usage sat at ~75%: the advisory nudge was suppressed by self-heal with no possible recovery (the recovery evidence can never arrive while context grows monotonically), the decide side-calls kept coming back empty (inheriting reasoning_effort=max against a 200-token budget), and the codex compact safety valve had self-disabled on an uncalibrated estimate-grade token count. This PR fixes all three mechanisms plus the misleading docs that made the issue get filed as "the intercept branch never entered".

Verification against the forensics

  • The intercept branch is not dead code in the sense of the issue title: it fires only for codex's EXPLICIT compaction requests (trailing compaction_trigger item from /compact, or POST /responses/compact). codex-tui 0.162.1's auto-compaction is purely client-side — byte-verified from the rollout: the compacted event at 02:19:53.351Z carries summary = fixed template header + final assistant message VERBATIM, zero wire traffic. There is no request to intercept.
  • The request bili saw 260 ms before codex's compaction was a normal continuation whose upstream response took 2 m 16 s to complete (relay cache TTL expiry → cached=0); total 725,892 crossed codex's internal point client-side.
  • Therefore this PR deliberately does NOT add an interception predicate on cold-cache continuation requests — that would forge over ordinary requests whose relay cache expired (catastrophic false positive). It documents the boundary instead.

Behavior changes (old → new)

  1. suppress-nudge now exits on time (src/session-self-heal.ts): old = suppression lasts until a compression reduction or bili tool use occurs — with monotonic context growth that is forever (observed 1 h 23 m 49 s in bili 对 Codex 原生压缩的拦截分支在本会话没进入(貌似自己截断自己了) #3008); new = it also lifts after SELF_HEAL_SUPPRESS_MAX_MS = 30 min without either, re-arming the advisory nudge; it re-suppresses after another 5 idle rounds. Evidence-based lift unchanged and still wins. No new config knob (会话卡死自愈机制:卡死模式检测与代理侧主动补救 #2155 convention: constant).
  2. The decide side-call no longer inherits reasoning knobs (all four wire lanes): old = the side body copied the main request's reasoning/reasoning_effort/thinking/thinkingConfig, so a reasoning_effort=max main request burned the entire 200-token decide budget on thinking and came back empty (14/31 empty responses in the forensics); new = those keys are stripped from the side body before dispatch. Previously-empty decides can now return verdicts; sessions previously cycling through the failure ladder may inject model-decided nudges where they previously fell back to legacy advisory.
  3. codex compact safety-valve baseline (src/codex-compact.ts): old = raw stats.lastInputTokens (can be an estimate-grade phantom — 970,475 uncalibrated in bili 对 Codex 原生压缩的拦截分支在本会话没进入(貌似自己截断自己了) #3008 — which closed the valve above 829,800 while real usage was far below); new = statusInputBaseline() (usage/overflow-arm grade reads lastInputTokens, else the retained real usage anchor, else 0). Usage-grade and overflow-arm values still close the valve identically; only estimate-grade phantoms stop self-disabling it.
  4. Docs/copy (CONFIGURATION.md/.zh-CN, TECHNICAL-NOTES.md/.zh-CN, conflict-watch.ts): codexCompact/BILI_CODEX_COMPACT were described as covering "codex native compaction" generally; now scoped to explicit compaction requests only, with the client-side auto-compaction → detect+rebase ([bug] Codex local auto-compaction can destroy existing bili fold substrate instead of rebasing #2372) boundary stated. User-facing text only, no behavior change.

Config surface

No new env vars, config fields, or CLI flags. SELF_HEAL_SUPPRESS_MAX_MS is an internal constant per the #2155 no-knobs convention.

Tests

  • tests/issue2155-self-heal.test.ts: +2 unit tests (time-cap re-arm incl. log line; sub-cap stays suppressed).
  • tests/nudge-decide.test.ts: +1 unit test (strip removes exactly the four reasoning knobs, nothing else).
  • tests/codex-compact.test.ts: existing gate matrix pinned to usage-grade source; +1 test (estimate phantom doesn't close the valve; usage/overflow-arm do; no anchor → open).
  • Targeted runs green locally: typecheck, build, the three files above + tests/nudge-model-decided.test.ts e2e lane (39 + 4 pass). Full suite left to CI per local-testing discipline.

Out of scope (checklist items left in #3008)

  • L1 trigger-line arithmetic: the headroom-shrunk 80% forced line (737,600) vs the client's unobservable auto-compact point (725,892 observed) — structural; honoring the user's literal modelContextLimit would make THIS race worse (840K >> 725,892), so neither denominator wins deterministically. Product decision needed (learned-point cap vs explicit-limit precedence).
  • L3 ledger rebuild after native compaction: resetSessionCompression zeros all baseline stats, so post-rebase nudge state starts from scratch ("max compressible 0"). Days of engineering; tracked as a checklist item in the issue.

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-13_codex-proactive-channel (98e4cf4)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.3456-pr.3018.696e3ec

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr3018.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review 完成——已 rebase 到当前 master(96f2f38,Merge #3010)逐项核验,零冲突。结论先行:代码本身可合(质量门全过),但与 #3019 存在机制级重叠,两个 PR 不能按现状都合并。查重:非重复立项(#3008 CODEX 取证 vs #3004 dsh-tui 取证,不同会话),但同机制族、同文件族,需排序去重(见下)。

结构化八问

1. 是什么问题:codex lane 的主动压缩通道被双重夹死——advisory nudge 被 self-heal 以 "injected but nothing ever compressed" 判死后永久锁存(上下文单调增长永远产生不了恢复证据,证据式解除自锁,实测静默 83 分钟);同时 decide side call 继承 host reasoning 旋钮,reasoning_effort=max 把 200-token 判决预算全部烧完 → 空响应(取证 31 次中 14 次空);另有 codex compact 安全阀基线用 estimate-grade 幻值误关阀门。

2. 什么原因导致的:三个独立根因,各修各的源头——① D1 抑制锁存的解除条件与唯一恢复来源(nudge→压缩)构成循环等待;② side call 以 {...parsed} 全量继承主请求旋钮,小输出预算先于判决被 reasoning 质量吃掉;③ codexCompactGatePre 用裸 stats.lastInputTokens 当压力基线,uncalibrated 的 estimate(取证幻值 970,475 ≥ 90%×922,000)把阀门关掉,而真实 usage 远低于。

3. 影响范围与严重程度:任何 nudge 通道被误判死的会话(上下文单调增长 + 模型/客户端不配合压缩时触发,不限 codex lane);codex 显式压缩路径(forge dispatch)在幻值压力下退化为 passthrough。特定条件下有问题而非完全不可用——事后 detect+rebase 兜底(#2372)仍工作,数据不丢,但主动压缩实质停摆(本会话最终由 codex 自己压掉 725,892→11,037,bili 只认账)。

4. 怎么修复的:三机制均修产生侧而非遮症状——① suppress-nudge 锁存加时限分支(SELF_HEAL_SUPPRESS_MAX_MS=30min):证据式解除仍优先,到时一次释放,再空转 5 轮重新抑制——有界循环替代永久静默;② 新增 stripClientReasoning(),四条 wire lane 的 sideBody 统一剥 reasoning/reasoning_effort/thinking/thinkingConfig(主请求不动,side call ephemeral 从不进客户端历史);③ 安全阀基线改用 statusInputBaseline()(usage/overflow-arm grade 读 lastInputTokens,否则回退最后真实 usage anchor,否则 0)——与展示面同口径(#2117 纪律);④ conflict-watch codex remediation 措辞 + CONFIGURATION/TECHNICAL-NOTES en/zh 把 codexCompact/BILI_CODEX_COMPACT 范围澄清为「仅显式压缩请求」,边界写明(客户端自动压缩从不经过代理,detect+rebase #2372)。

5. 是否有回归问题:逐条审过既有行为——

  • self-heal 状态机:zombie degrade、D2 fallback 抑制、证据式解除、streak 只在 nudge 轮推进、持久化 shape {detected,action,since}(since 为既有字段,无持久化版本变更)——全部保持。一处有意扩展需点名:D2 fallback 抑制(plugin-lane-gone + injectTool=false)同样吃到 30min cap → 永久坏 lane 从「永久静默」变为约每 30min+5 轮发一波有界 nudge burst;严格增加恢复机会、噪声有界,判定可接受;
  • 安全阀:usage-grade / overflow-arm 读数改前后基线字节级相同(该两 source 下 statusInputBaseline 即返回 lastInputTokens),门矩阵测试已钉住;无 anchor/stale anchor 方向 fail-open 到 forge(主设计路径),transformOk 仍是完整 gate 硬条件,残余风险有限;
  • side call wire shape = ephemeral 请求参数剥离,不碰主请求、不碰 thinking-family 签名块,KDD#10 不受影响;两种压缩模式(proxy/plugin)下 strip 一致适用;
  • 日志格式仅新增一行 time-capped log,不改既有行;
  • auto-merge 判定:wire shape 变更 + 默认行为变更 + 跨多模块 → 不满足 §7.4,作者正确自评 human-review tier ✓。

6. 是否破坏缓存:不涉及(未触碰缓存/重试/增量游标/去重键失效策略;prefix cache 无关)。

7. 是否改了设计方向:无。三机制全部骑在既有 self-heal 状态机 / decide ladder / codex compact gate 上,无新架构面;「不给冷缓存 continuation request 加拦截谓词」的边界处理正确(会伪造拦截普通 relay-cache 过期请求,灾难性假阳性)。

8. 是否引入新配置:无。SELF_HEAL_SUPPRESS_MAX_MS、stripClientReasoning()、statusInputBaseline() 均为内部面;常量沿用 #2155 惯例(代码常量非配置)。

验证证据(rebased head 实测)

  • rebase 到当前 master 零冲突;master 侧对本 PR 触碰文件的改动已逐一比对(conflict-watch [Bug] ACP 接駁套件名稱誤報 / False positive for @openma/deepseek-harness-acp in compression scanner #2969 措辞重构、prepare lanes marker-strip 重构)——与本 diff 无函数级交叠;
  • 定向测试 39/39 绿(codex-compact + issue2155-self-heal + nudge-decide);typecheck clean;
  • mutation check:src 回退到修复前版本,三组新测试全红(gatePre baseline 断言直接失败;另两文件 import 缺失失败)→ 回归测试真复现 bug,非假测试;
  • zh/en 文档同步核对通过(ZH D1 bullet 含 30min 时限;CONFIGURATION zh/en 范围措辞对齐)。

⚠️ 阻塞项:与 #3019 的机制重叠(合并前必须定序)

#3019(Closes #3004,dsh-tui 取证,创建于本 PR 后 15 秒)修同一机制族、取值不同:

机制 本 PR #3019
抑制锁存寿命封顶 SELF_HEAL_SUPPRESS_MAX_MS = 30 min SELF_HEAL_SUPPRESS_CAP_MS = 10 min
side call 剥 reasoning 旋钮 stripClientReasoning()(四 lane 内联调用) stripDecisionReasoningFields()(导出)
抑制期内 ladder punch-through —(到时才放行) consumeFallback,每 3 连败一次
post-gate 投递台账(nudgeOutcome) — 修 pre-gate willInjectNudge 为模型否决轮虚报投递

两者都改 evaluateSelfHealRound 同一恢复分支 + 四条 prepare lane + tests/issue2155-self-heal.test.ts → 先后合并必然语义冲突。建议:先合本 PR(rebase 干净已证、体量小、独有 codex compact 基线修复 + 措辞更正),随后 rebase #3019:删其重复常量与 strip 函数,保留独有部分(punch-through + nudgeOutcome 台账 + INJECT-PENDING 日志)——二者互补:punch-through 在 30min 窗口内即生效,台账减少虚假武装使 cap 更少触发。cap 取值(10 vs 30 min)请你拍板:30min 封顶最坏静默 ≈30min+5 轮;若要更紧可在后续统一为 10min。

范围外项(作者明确留在 #3008 checklist,同意留置)

  • L1 trigger line 算术(强制线 737,600 vs 客户端不可观测的 725,892;字面尊重 modelContextLimit 反而更糟 840K≫725,892)——需产品决策;
  • L3 native compaction 后台账重建(resetSessionCompression 清零 baseline stats,rebase 后 nudge 状态从零起步)——独立机制域。

判定

代码质量:可合(diff 小而净、每行 on-topic、测试有牙、文档中英同步)。流程:待 #3019 协调定序后再合——请确认合并顺序与 cap 取值,我可以随即将 #3019 做去重 rebase。分支当前 behind master,我本地已验证 rebase 干净;定序后我可推 rebased head 刷新 CI。

@ranxianglei
ranxianglei force-pushed the 2026-10-13_codex-proactive-channel branch from 04c737b to 841a938 Compare October 13, 2026 13:37
…pe docs (#3008)

Delta-only rebase onto master (#3019 merged the shared mechanisms):
- dropped from this PR (covered by #3019): stripClientReasoning (master has
  per-protocol stripDecisionReasoningFields incl. google nested
  generationConfig), SELF_HEAL_SUPPRESS_MAX_MS 30min cap (master has
  SELF_HEAL_SUPPRESS_CAP_MS 10min at top-of-evaluate + fallback punch-through
  + re-arm guard), TECHNICAL-NOTES D1 English hunks.
- kept, unique: codexCompactGatePre now reads the evidence-grade input
  baseline (statusInputBaseline) instead of raw stats.lastInputTokens — an
  estimate-grade phantom reading self-disabled the safety valve at >=0.9x
  limit (#1492/#1839 discipline); comment corrected (90% is bili's backstop
  line, not codex's own point — 78.7% observed, client point unobservable).
- kept: docs honesty — codexCompact interception covers explicit requests
  only; codex-tui auto-compaction is pure client-side and never transits the
  proxy (detect/rebase path #2372); conflict-watch remediation no longer
  claims 'intercepts native compaction by default'; zh D1 aligned with the
  merged 10-min cap.

Closes #3008
@ranxianglei
ranxianglei force-pushed the 2026-10-13_codex-proactive-channel branch from 841a938 to 98e4cf4 Compare October 13, 2026 13:55
@ranxianglei
ranxianglei merged commit 1928981 into master Oct 13, 2026
15 of 19 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.380-master.1928981 (rolling master tag).

npm install -g billion-context@0.0.380-master.1928981  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

YunzhouLi-hub pushed a commit to YunzhouLi-hub/billion-context that referenced this pull request Oct 13, 2026
)

Codex's local inline auto-compact (compact.rs run_inline_auto_compact_task,
observed rust-v0.162.1) transits the proxy as an ORDINARY turn: full history
plus the SUMMARIZATION_PROMPT template as the last user message. No
compaction_trigger item, no /responses/compact call — the only wire signature
is the prompt text itself, so the existing interception never fired and the
request re-cached the full unfolded history (720,706 tokens in the ranxianglei#3008
incident). If the summarization call returned no assistant content, codex
fell back to a placeholder summary (template header + last conversation
message).

- hasCompactionPrompt(): scan input[] backwards; the last message item must
  be a user message opening with the built-in template anchor. A
  user-overridden compact_prompt falls out of detection (documented) and
  transits verbatim. Mid-history quotes cannot match (only the final user
  message is tested).
- buildPromptForgeBody(): one assistant message item + response.completed —
  exactly what codex's drain_to_completed records item-by-item; its
  summary_suffix = this text, so the compacted payload becomes codex's own
  SUMMARY_PREFIX + bili's fold summaries. Forge reuses the same safety gate
  (active block + <90% usage-grade baseline + transform ok) and the same
  captured-summaries ledger as the trigger form.
- handle.ts: skip preflight when a forge is about to be served locally.
- Docs: codexCompact scope copy updated in the config reference (EN/ZH),
  website, and conflict remediation — 'auto-compaction never transits the
  proxy' was false and is now corrected everywhere (ranxianglei#3018 follow-up).

Tests: detector matrix (anchor-last/quotes/assistant-last/overridden
template), forge shapes (SSE + JSON), e2e forge (upstream untouched,
summaries captured) + gate-fail/pass-mode/non-codex passthrough.
@ranxianglei
ranxianglei deleted the 2026-10-13_codex-proactive-channel branch October 15, 2026 05:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bili 对 Codex 原生压缩的拦截分支在本会话没进入(貌似自己截断自己了)

1 participant