Repository navigation
[PR] fix: bound the codex forged-summary handoff ledger (part 1 of #4600) - #4629
ranxianglei wants to merge 14 commits into
Conversation
The session-level ledger of forge-time captured block summaries was append-only with exact-text dedup, and every request without an echoed bili compaction item re-injected the ENTIRE accumulated list into the developer message (#1064 fallback). Over a long session that grows without bound: field data shows 1,421 entries / ~1.21M tokens in a 46-day session failing preflight 413 against a 375K window. Changes (host-side only, no kernel/ touched): - Ledger entries now carry provenance ({text, blockId}); legacy persisted string lists keep working via normalizeForgedEntries. - pruneForgedEntries drops an entry only when provably redundant: its block is inactive AND a newer block folded the message carrying its summary (summaryMessageId in the consumer's effectiveMessageIds) AND that consumer is itself represented (still active or holding its own ledger entry). Truncation debt stays — it is load-bearing fallback. Applied at both the forge-time capture (persisted ledger stops accumulating) and injection time (self-heals older persisted state). - carriesConversationTurns gate: requests replaying no conversation (context-only probes/sidecars/prewarms) get no re-injection at all; view-only, the persisted ledger is untouched. - Observability: warn when the fallback re-injection eats >=10% of the model window (FORGED_SUMMARY_INJECT_WARN_PCT); info/debug logs for prunes and skips.
Small in-pass fix found while working #4600: the import was already dead on master (only this import line referenced the symbol after the forge-capture logic moved into prepare-responses).
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.10930-pr.4629.db7c2c5This exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr4629.tgz
npm install -g packageInstall instructions are refreshed on each push. |
…by this PR) The entry-shape interface is referenced only inside codex-compact.ts (normalize/merge/prune signatures); no file imports it. INTERNAL_ONLY per scripts/check-unused-exports.mjs.
(ai: vllm-qwen/qwen3.8-27b) 查重:本 head( 八问
CI 状态(新 head
|
(ai: vllm-qwen/qwen3.8-27b) 判定:继承性失败,分支侧不动手,等 #4606 合入后 rebase。 证据(run 40143511023,head 八问
收工判定:auto-fix 车道 2/2 用完。本 PR 侧能修的红(unused-exports ×2)已在 attempt 1 修掉并转绿;剩余 11 片红全部继承自 master,唯一解锁动作 = owner 合并 #4606,之后本分支 rebase 重触发即绿(届时若 born-red 集群仍红,按 #4599 清单逐机制 triage,不在本 PR 范围)。 |
(ai: vllm-qwen/qwen3.8-27b) 查重: 不重复。 检索 open+closed issue/PR 无同机制条目(forged-summary ledger 有界化);相关项已互链:父 issue #4600(本 PR 为其 part 1)、#1064(回注 fallback 出处)、#2372(codex 本地 auto-compaction 路径)、#4594(context-only 辅助流量形状)。一个 issue(#4600)→ 一个 PR,符合 loop guard。 标签: bug / codex / scope/wiring / p1(handoff ledger 只增不减属缓存泄露类,按 owner 修订 2026-10-19 一律 p1) 审核进行中,先报一个关键发现(完整八问结论随后): 本 PR 的核心机制——provenance + lineage pruning——在真实 kernel 状态下不会触发,是死机制。 证据链:
后果:
确实有效的部分: 此发现强化 #4600 待决策的必要性:option 2(budget cap)使 413 结构性不可能,与 prune 是否有效无关;option 1(边界核销)覆盖主导模式。part 1 的核心贡献低于正文所述。 进行中:定向测试已过(codex-compact.test.ts 20/20、codex-compact-e2e.test.ts 22/22)→ 正在分支内修 CI 两处 unused-exports 红(本 PR 引入 1 处 + master 继承 1 处)→ push → CI → 八问终局结论。 |
(ai: vllm-qwen/qwen3.8-27b) PR 审核终局结论(独立重审,不复述 issue 侧结论)总判定:hold,暂不合并。 代码质量达到合并标准、CI 红已处置(floors 5/8),但核心机制(provenance + lineage pruning)在真实 kernel 状态下不触发(floor 10 证据链)——本 PR 现状合入后,#4600 的用户可见问题(长会话 ledger 无界增长 → 413)依然存在。需要 #4600 政策决策先行,同分支收口。 ① 方向关(原 issue)#4600 要修的是「debt without lifecycle」:append-only capture + 对每个无 echo 请求全量回注 → 无界增长。方向判断正确(根因不是表面现象)。Part 1 三机制实测:(a) lineage pruning = 死机制(kernel/src/unit-projection.ts:135-137 把所有 summary id 剔出 fold 范围,effectiveMessageIds 结构上永远干净,prune 的触发条件永不成立);(b) ② 回归审查(既有行为逐项清点)
高危模式逐项过:语义漂移无、fail-fast 变吞错无、阈值/时序漂移无( ③ 代码审查(主关)纯函数组(normalize/merge/prune/carriesConversationTurns)本身整洁:命名达意、注释讲为什么带 #NNNN 引用、guarded cast、具名常量、风格与仓库一致。问题不在代码质量,在机制所依赖的数据关系不存在——约 100 行当前不可达代码路径 + 依赖它的测试。 ④ 测试有效性
⑤/⑤b diff 整洁度与代码硬标准干净:每一行服务本 PR 目的,无关文件/生成物/空白 churn 为零,外部提交硬标准全项通过。唯一不符项在正文表述而非 diff(见①)。 八问
CI 状态(head
|
…n codex-compact/server/prepare-responses) Merging origin/master (99c22d2) into the PR head to clear the merge-conflict blocker. Three import-line conflicts resolved by union: - src/codex-compact.ts: keep master's createHash (nativeCompactionKey) + PR's baseIdOf/summaryMessageId (forged-ledger provenance). - src/server.ts: keep master's CommandcodeEnvelopeMeta import; drop the dead mergeForgedSummaries import (unused in server.ts body, PR's own intent per af47e02). - src/server/prepare-responses.ts: union of PR's carriesConversationTurns/ normalizeForgedEntries/pruneForgedEntries/FORGED_SUMMARY_INJECT_WARN_PCT + master's nativeCompactionKey. All symbols verified used + exported. Typecheck (tsc --noEmit) green; targeted codex-compact tests 42/42 pass.
…state Master advanced 3 commits (pure-SQLite default #6480 + notice gate test) after the initial conflict merge; re-syncing so the PR head is clean against current master. No conflicts.
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b) CI red triage — PR #4629 (4 failing test shards) What's failing: 2 tests in Root cause analysis:
Verdict: This is a master-level CI-specific failure, not introduced by this PR. The PR's own code is clean — typecheck + targeted tests (42/42 codex-compact) pass locally. Action taken:
Remaining: The 4 test shards will stay red until the notices test is fixed on master/ci-fixes. All other checks (GATE workflow: 4 success, 12 queued, 14 skipped, 0 failures) are clean. |
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b) CI red triage — PR #4629 (2 failing test shards, head ce46c44) What's failing: 13 tests across 2 Windows shards, all with the same error:
Root cause: Windows CI-environment file locking — the SQLite Not a code bug: The PR diff (5 files: codex-compact, server, prepare-responses, 2 test files) does not touch persist/storage paths. The notices-test fix from the previous wake (c6369fb) is in this head and the notices failures are gone. Action taken:
Remaining: Waiting for the re-run to complete. If the EBUSY reproduces on fresh runners too, the leaked-handle hypothesis (#4347) becomes primary and needs a persistent fix in the test teardown (close SQLite handles before |
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b) CI red triage — PR #4629 (re-run completed, same 2 shards still red) The CI's own diagnostic (from the job logs):
Root cause: Windows CI runners have an external AV/indexer that holds freshly-written SQLite Not a code bug / not this PR's fault:
Why I'm not fixing it in this PR branch:
Status: All 28 other checks are green (ubuntu × 22/24, windows × 22 shards 2/4/5, all static gates, kernel-guard, docs, lock-sync, etc.). Only the 2 Windows EBUSY shards remain red, pending a ci-fixes retry-ladder widening. |
[ework] auto-fix stalled: test (windows-latest, 22, 3), test (windows-latest, 22, 1) — stopping for human review |
2 similar comments
[ework] auto-fix stalled: test (windows-latest, 22, 3), test (windows-latest, 22, 1) — stopping for human review |
[ework] auto-fix stalled: test (windows-latest, 22, 3), test (windows-latest, 22, 1) — stopping for human review |
# Conflicts: # src/codex-compact.ts
[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b) Conflict resolved & pushed — PR #4629 Merged
Verified: typecheck clean, 46/46 targeted tests pass (codex-compact + codex-compact-e2e). Pushed as merge commit 7292abb (no force-push). 八问
判定: 冲突已解决,PR 分支已推送到 7292abb,等待 CI 在新 head 上重跑。 |
ranxianglei
left a comment
There was a problem hiding this comment.
(ai: opencode/qwen3.8-27b)
REQUEST_CHANGES — the core "bound the ledger" mechanism (lineage pruning) is dead code against real kernel state: the predicate it relies on is never true, so the persisted ledger still grows unboundedly for the main #4600 scenario. The conversation-evidence gate works and is correct, but it only removes the 413 for context-only probes/sidecars — it does not bound the ledger or fix the 413 for real conversation requests.
Blocking: pruneForgedEntries never fires (src/codex-compact.ts:401)
The pruning drops an entry only when some consumer block's effectiveMessageIds contains the entry's block summary id:
src/codex-compact.ts:411registers the lookup keysummaryMessageId(e.blockId)(=acp_summary_<blockId>);src/codex-compact.ts:414-425scans each block'seffectiveMessageIdsfor that key;src/codex-compact.ts:427prunes when a represented consumer is found.
But the kernel never puts an acp_summary_* id into any block's effectiveMessageIds:
kernel/src/unit-projection.ts:181:const rangeMessageIds = adjustedIds.filter((id) => !isSummaryMessageId(id) && !liveCarrierIds.has(id));— summary ids are explicitly excluded from the fold range, andeffectiveMessageIdsis seeded fromrangeMessageIds(line 237) plus the consumed blocks' raw ids (lines 240-242).kernel/src/prune.ts:17documentssummaryMessageIdas "VIEW-ONLY ... must never be persisted intoeffectiveMessageIds/directMessageIds".kernel/tests/regression-promote-after-prune.test.ts:465pins the invariant:assert.ok(!isSummaryMessageId(id), 'synthetic id leaked into block: ' + id).
The kernel records block lineage in directBlockIds, not in effectiveMessageIds with summary ids. I verified this empirically against the PR's exact kernel (0.0.199, built at the PR head): folding a range that consumes block b2 produces a new block with directBlockIds = [b2] and effectiveMessageIds = [raw-3, raw-4] — no acp_summary_b2. Running the PR's predicate against that real state finds zero consumers, so the b2 ledger entry is never pruned.
Consequence: the persisted codexForgedSummaries ledger still accumulates forever for the #4600 field scenario (blocks nested into newer blocks across a long-running conversation — the 1,421-entry / 1.21M-token case). Both pruning sites (injection-time and forge-time in src/server/prepare-responses.ts) call this dead predicate. The e2e test tests/codex-compact-e2e.test.ts ("forge-time capture prunes superseded ledger entries") fabricates the state the kernel forbids — liveBlock.effectiveMessageIds.push("acp_summary_b_stale_1", ...) — so it passes while the real behavior is broken. The PR's "safety property" note (a block's effectiveMessageIds never contains its own summary id) is true but proves only no-self-pruning; it does not establish that a consumer carries the old block's summary id.
Suggested fix: key supersession on the kernel's actual lineage record — an entry for block X is redundant iff X is inactive AND some block Y is represented (Y.active, or Y holds its own ledger entry) AND X is reachable from Y via the transitive directBlockIds chain (that is how the kernel records "Y consumed X"). Truncation debt (a block deactivated by the post-forge history cut with no consumer) then stays, exactly as the PR intends. Re-verify against a real applyCompression-produced state (not a hand-built block) so the regression test pins real kernel behavior.
What works (no change needed)
carriesConversationTurnsgate (src/codex-compact.ts:451) — correct; context-only requests pay nothing, and it errs toward injecting (lenient by design, matching the comment). The e2e probe test is valid.normalizeForgedEntries/mergeForgedSummariesshape change (string[]→{text, blockId?}[]) with legacy read-compat — correct; the only reader of the ledger issrc/server/prepare-responses.ts, and the shape change is disclosed.- Observability warn log (
FORGED_SUMMARY_INJECT_WARN_PCT, a code-internal named constant, not a config key) — fine.
结构化八问
- 是什么问题:PR 声称"bound the codex forged-summary handoff ledger",但核心谱系剪枝(
pruneForgedEntries)在真实 kernel 状态下永不触发——它依赖的谓词(consumer 的effectiveMessageIds含acp_summary_<blockId>)在 kernel 中恒为假。 - 什么原因导致的:kernel 从不把
acp_summary_*写进任何 block 的effectiveMessageIds(unit-projection.ts:181显式过滤;prune.ts标注 VIEW-ONLY;kernel 自身回归测试钉死"synthetic id never leaks into block")。kernel 用directBlockIds记录谱系。PR 把"block 的effectiveMessageIds不含自己的 summary id"(真,仅防自剪枝)误当成了"consumer 含旧 block 的 summary id"(假)。 - 影响范围与严重程度:持久化账本在 #4600 主场景(长会话嵌套 block)下仍无界增长——p1 未修复;注入时与 forge 时两个剪枝点都调用死谓词。e2e 测试伪造了 kernel 禁止的状态故通过,真实行为是坏的。会话证据门有效,但只消除 context-only probe/sidecar 的 413,不消除增长,也不消除真实会话请求的 413。
- 怎么修复的:把取代判定键到 kernel 真实谱系记录上——entry X 冗余当且仅当 X inactive 且存在被代表的 Y(Y.active 或 Y 有自己的账本 entry)使 X 可从 Y 经 transitive
directBlockIds链到达;用真实applyCompression状态(非手搓 block)重验并让回归测试钉住真实 kernel 行为。 - 是否有回归问题:本 PR 未合入,无既有行为被破坏。按建议修复后剪枝语义与 PR 原意一致(truncation debt 保留、被取代 entry 剪除),仅换正确信号,无额外回归。
- 是否破坏缓存:不涉及——账本是
session.metadata内部键,非缓存/重试/增量游标。 - 是否改了设计方向:不涉及(#1064 handoff 契约不变;token 预算上限仍待 owner 在 issue 线程决策)。
- 是否引入了新的配置:无新配置(
FORGED_SUMMARY_INJECT_WARN_PCT是代码内命名常量,非 env/config 键)。
判定:REQUEST_CHANGES — 核心机制是死代码,PR 未达成其声称的目标(bound the ledger);按 directBlockIds 谱系重写剪枝谓词、补真实 kernel 状态的回归测试后再审。
[bot] 🏷 Review of PR #4629 (bound the codex forged-summary handoff ledger, part 1 of #4600) is complete. Verdict: REQUEST_CHANGES (blocking). Posted as a comment review (GitHub blocks request-changes on my own account's PR): #4629 (review) The core "bound the ledger" mechanism (lineage pruning) is dead code against real kernel state:
What works (no change needed): the 结构化八问:
判定:REQUEST_CHANGES — 核心机制是死代码,PR 未达成其声称的目标(bound the ledger);按 |
[ework] CI fix verified green ✓ |
Part 1 of #4600 — the bounded-handoff mechanics. The injection-policy decision requested in the issue thread (native-compaction boundary write-off / token-budget cap / both) lands in this same branch after the call is made; per the one-issue-one-PR rule there is no separate PR for that part.
What was wrong
Every intercepted codex compaction appends the rendered summaries of all active blocks to
session.metadata.codexForgedSummaries(append-only, exact-text dedup), and every request without an echoed bili compaction item re-injects the ENTIRE accumulated list into the developer message (#1064 fallback contract). Blocks nested into newer blocks keep their old entries forever, so the list grows for the life of the session. Field data from #4600: 1,421 entries ≈ 1.21M tokens in a 46-day session →preflight fail-fast 413against a 375K window; 36 entries grew a 67 KiB request to 422 KiB.What changed (host-side only, no kernel/ files touched)
src/codex-compact.ts): ledger entries now carry the block they were captured from ({text, blockId}); legacy persisted string lists keep reading throughnormalizeForgedEntries.pruneForgedEntriesdrops an entry only when provably redundant: its block is inactive AND a newer block folded the message carrying its summary (summaryMessageId(blockId)∈ the consumer'seffectiveMessageIds) AND that consumer is itself represented (still active — its summary renders live — or holds its own ledger entry). Truncation debt (blocks deactivated only by the post-forge history cut, with nothing consuming them) ALWAYS stays — that is the load-bearing 发现一些bug #1064 fallback. Pruning runs at BOTH sites: forge-time capture (the persisted ledger stops accumulating) and injection time (self-heals state persisted before this fix).effectiveMessageIdsnever contains its OWNacp_summary_<id>(the set is built inunit-projection.tsbefore block-id allocation; refolds rewrite only summary/topic/runId), so an entry can never be pruned by its own block.carriesConversationTurns): requests that replay no conversation (no assistant/tool/reasoning items — context-only prewarms/sidecars/probes) get NO re-injection at all. They have no replayed history to protect, and previously paid the full accumulated tax, which failed them outright once the list outgrew the window. The gate is view-only: the persisted ledger is untouched.FORGED_SUMMARY_INJECT_WARN_PCT, named constant); info/debug logs for prune/skip events.Behavior changes (disclosed)
session.metadata.codexForgedSummariespersisted shapestring[]{text, blockId?}[]No wire-format change beyond what the developer-message injection already did; no config surface added (a budget knob belongs to the pending policy decision); no persistence version bump (internal metadata key).
Tests
tests/codex-compact.test.ts: entry-shape merge test + normalize/prune/conversation-predicate matrices (both directions per gate discipline) — 20 pass.tests/codex-compact-e2e.test.ts: two new real-pipeline regressions — a conversation-less probe gets no re-injection with the persisted ledger untouched, and forge-time capture prunes seeded stale entries before persisting; plus the three existing ledger assertions updated to the entry shape. 22 pass, including all pre-existing echo/fallback/发现一些bug #1064/bili 对 Codex 原生压缩的拦截分支在本会话没进入(貌似自己截断自己了) #3008 contracts.Out of scope here (awaiting the owner's call in the issue thread)
The #4600 policy options: (1) write off the ledger at native-compaction boundaries, (2) token-budget cap on the injected set (suggested default 25% × window), (3) both (recommended). Lands in this branch after the decision.