Skip to content

fix: resolve audited defects from #1064 - #1072

Merged
ranxianglei merged 1 commit into
masterfrom
2026-09-20_fix-audited-defects-1064
Sep 22, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-09-20_fix-audited-defects-1064

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Sep 20, 2026 •

Copy link
Copy Markdown
Owner

Summary

Behavioral subset of the bug collection #1064 audit. Per maintainer decision, the four mechanical fixes were extracted into #1113 (merged as aba2bff): awaitDrain listener leak, codex config.toml block-end wipe, session-pool reload cap, drop-only echo re-injection — including their regression tests. This PR was rebased onto that master and the duplicated hunks dropped; what remains changes observable behavior/policy and is kept for standalone review.

Fixes retained here

Area File Fix
Upstream abort lifetime src/fetch-util.ts (+ degenerate-retry.ts, reasoning-guard.ts, forward() passthrough) stopIdleTimer split from clearTimer: splice/continue callers keep client-abort coverage while dropping the idle watchdog; event-ordering regression test (tests/fix-15-abort-lifetime.test.ts).
Image-token estimate src/server.ts (anthropic/openai/responses) Input estimates now pass imageBillingFor(), matching the output-clamp sites — pixel-tile billing hosts no longer inflated ~35× relative to the clamp.
Compress system note src/server.ts (forward()) withConversationIdNote in the compress-loop system rebuild (proxy-generated text, not user payload).
Context-window clamp (#12) src/server/context-window.ts MAX_ANTHROPIC_BETA_WINDOW = 10M — a hostile context-9999999m header can no longer drive every compression threshold toward infinity.
Tail-window trust (#13 interim) src/prefix-affinity.ts w === TAIL_WINDOW hard threshold replaces MIN_TAIL_MATCH = 3 — a crafted sub-8 window can no longer adopt an unrelated stored session. Design-level follow-up (suffix-anchoring / depth-scaled evidence / dropping mid-chain adoption) tracked in #1115.

Wire fidelity

No hunk touches tool-call arguments or wire message shape; all paths are mode-shared with behavior identical in plugin and proxy mode.

Pre-flight (head on master incl. #1113)

  • typecheck — pass
  • test — 2198 pass / 0 fail / 2 pre-existing skips
  • build — success

References #1064, #1113, #1115.

@github-actions

github-actions Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-20_fix-audited-defects-1064 (8ef6b8d)

Option A — Install from npm PR tag (recommended)

npm install -g billion-context@pr-1072

Each push to this PR publishes a new version under the pr-1072 npm tag.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr1072.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] 🏷 Reviewing this PR now — not re-doing the work. Initial state:

  • Branch 2026-09-20_fix-audited-defects-1064 is a single commit (9b1b1a7) on top of live master 2baef15 (v0.1.131) — matches the pre-flight claim.
  • Diff is small and scoped: src/plugin-install.ts, src/server.ts, src/server/stream-io.ts, src/session.ts, + one new test file (tests/backpressure-drain.test.ts). 5 files, +51/−14.
  • CI: 7/8 checks green so far; test (windows-latest, 22) still running. No reviews yet.

I'm now verifying each of the five fixes against the actual diff and re-running typecheck/test/build locally on the branch. Full conclusion to follow.

@ranxianglei ranxianglei mentioned this pull request Sep 20, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review complete — all five fixes verified against live master (2baef15, v0.1.131), pre-flight re-run locally, and I added the missing regression tests directly on the PR branch (commit 6c381f8).

Per-fix verification

# Fix Verdict
1 Echo summary loss (src/server.ts prepareResponses) ✅ Sound. replaceBiliCompactionItems (src/codex-compact.ts:72) replaces sentinel-blob items in place (replaced++) but drops id-prefix-only legacy markers (dropped++). Old code set echoReplaced on either, so a drop-only echo suppressed the codexForgedSummaries fallback at src/server.ts:2757 and silently lost the summaries. New code sets it only on a real replacement → drop-only still re-injects via the developer message. Residual edge (pre-existing, not a regression): a mixed replace+drop turn still suppresses the fallback for that turn.
2 Image-token estimate billing parity ✅ Sound. All three estimate sites now pass imageBillingFor(...): anthropic src/server.ts:2246, openai :2431, responses :2892 — matching the unchanged clamp sites :2401/:2839 exactly. resolveImageBilling (src/image-tokens.ts:44-58) classifies the pixel-tile hosts by suffix, so openai.com/api.anthropic.com estimates are no longer ~35× inflated vs the clamp. Minor non-blocking note: prepareAnthropic has no billingUpstream param, so its route lookup is origin-only; a path-prefixed provider key with a per-provider imageBilling override would be missed there (the sideRequestGuard at :1517 uses rewrittenUrl). Identical behavior under the default "auto" — not a regression from this PR.
3 config.toml wipe (src/plugin-install.ts codexInstall) ✅ Sound. Block-end detection is now byte-identical to codexRemove's next-table-header search (optional indent), fixing the indexOf("\n[") EOF-run when an indented [table] header follows. Refresh slice arithmetic verified; idempotency preserved via trimEnd compare.
4 Session cap bypass (src/session.ts getSession) ✅ Sound. Reload path now enforces MAX_SESSIONS with the same throw-if-exhausted shape as the new-session guard, before sessions.set. reloaded.lastSeen is refreshed first, so a reloaded session can never self-evict; evictOldest skips in-flight sessions and flushes to disk first.
5 Drain listener leak (src/server/stream-io.ts + src/server.ts) ✅ Sound. Single shared settle removes all three one-shot listeners (drain/close/error); the main compress-loop pipe (src/server.ts:4450-4453) now uses awaitDrain instead of a bare Promise.race that also never resolved on error. Audited every other drain-wait site (plugin.ts:1156,1637, reasoning-guard.ts:449, stream-io.ts:82) — all already use awaitDrain; the only remaining Promise.race is an unrelated timeout race in native-intercept.ts:134.

Diff is clean: 5 files, +51/−14, every line on-purpose, rebased onto current master, no lockfile/generated churn.

Regression tests added (pushed as 6c381f8, test-only commit)

The PR shipped a regression test only for the drain leak; the other four had none reproducing the actual bugs. Added per repo review norms:

  • Fix 1 — tests/codex-compact-e2e.test.ts: new e2e where codex echoes back a legacy id-prefix-only marker (no sentinel blob) → asserts the marker is dropped, no replacement handoff appears, and the forge-time summaries are still re-injected via the developer message.
  • Fix 4 — tests/fix-config-session.test.ts: evict-then-revisit with a real on-disk store → asserts the pool stays at MAX_SESSIONS on the reload path.
  • Fix 3 — new tests/codex-install-block-end.test.ts: refresh over a config whose next table header is indented (plus a column-0 control) → asserts trailing tables survive.

Proof they bite: with src/{server,session,plugin-install}.ts temporarily reverted to master, all three fail (indented-table codex, session-cap reload, drop-only e2e); with the PR code they pass. The column-0 control correctly passes on old code too (that case was never broken).

Pre-flight

Local on 6c381f8: npm run typecheck pass · npm test 2147 pass / 0 fail / 2 skipped (pre-existing skips; +4 = the new tests) · npm run build success. CI was fully green on 9b1b1a7 (all 4× platform test jobs + e2e-fake-codex + artifact); the new head triggers a fresh run — should be identical since the delta is tests only.

中文摘要:五个修复(#1064 的 echo 摘要丢失、图片 token 计费口径、config.toml 刷新误删、会话池上限绕过、drain 监听器泄漏)逐一核对代码路径均正确,本地 typecheck/全量测试/build 通过,CI 全绿;已在 PR 分支补了三个缺失的回归测试(均验证过在旧代码上会失败),测试提交 6c381f8 无源码改动,可以合并(等新一轮 CI 绿后由人工合并即可)。

Per system rules I won't merge — please do it yourself: #1072

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Update: my first test commit (6c381f8) broke the two Windows jobs — my bad, and my earlier "should be identical" was wrong. The codex block-end test asserted on a raw "dist/mcp.js" substring, but codexBlock() writes the args via JSON.stringify(path.join(...)), which on Windows escapes the separators (dist\\mcp.js), so the match failed there only. Fixed in 2780f9a + b8de83f: the assertion now matches the exact serialized form (JSON.stringify(join(selfPackageRoot(), "dist", "mcp.js"))) — byte-identical to what codexBlock() emits on any platform.

CI on b8de83f (current head): all 8 checks green — test ubuntu 22/24, windows 22/24, version-guard, build-artifact, e2e-fake-codex, codex CODEX_HOME overlay.

Local pre-flight unchanged: typecheck pass · full suite 2147 pass / 0 fail / 2 pre-existing skips · build success.

PR is at three commits: the original fix (9b1b1a7) + two test-only follow-ups (6c381f8, 2780f9a, b8de83f). Nothing in src/ changed since 9b1b1a7. Ready for human merge: #1072

中文摘要:我补的回归测试里有一处断言在 Windows 上因路径分隔符被 JSON.stringify 转义而失败(仅测试代码问题,非产品代码),已改为匹配序列化后的精确形式,当前头提交 b8de83f 全部 8 项 CI 检查通过,可以合并。

@ranxianglei
ranxianglei force-pushed the 2026-09-20_fix-audited-defects-1064 branch from b8de83f to de61ab1 Compare September 20, 2026 17:48
@ranxianglei ranxianglei changed the title fix: resolve audited defects from #1064 (echo summary, image tokens, config wipe, session cap, drain leak) fix: resolve audited defects from #1064 Sep 20, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

Independent review: MERGE (after rebase)

Reviewed both commits hunk-by-hunk on a rebase onto current master 9c01dbe:

All nine fixes are root-cause (疏 not 堵), each with a regression test:

  1. drop-only echo no longer suppresses forge-summary re-injection (replaced > 0 gate) — captured summaries survive marker-blob drops ✅
  2. imageTokensInParsedBody now takes imageBillingFor() at all three INPUT-estimate sites — pixel-tile hosts no longer ~35x inflated vs the output clamp ✅
  3. codexInstall block-end uses the same table-header regex as codexRemove — no more eating the rest of config.toml on refresh ✅
  4. getSession disk-reload path enforces the MAX_SESSIONS cap (was unreachable there) ✅
  5. awaitDrain shared-settle removes all three listeners — leak + MaxListenersExceededWarning gone; forward()'s compress-loop pipe uses it ✅
  6. anthropic-beta window clamped to MAX_ANTHROPIC_BETA_WINDOW = 10M — hostile header can't drive compression thresholds to infinity, future betas still generalize ✅
  7. tail-window reattach requires the FULL 8-item window (w === TAIL_WINDOW) — weak signals can't adopt an unrelated session ✅
  8. compress-loop system rebuild carries withConversationIdNote — loop re-requests share the conversation-id anchor ✅
  9. fetchWithTimeout splits stopIdleTimer (watchdog only) from clearTimer (full cleanup) — splice/continue callers keep client-abort cancellation ✅

Correctly excludes the two items already fixed upstream post-audit-base (#1068 fa18d6d, #1056 65cefd0).

Action needed: the branch is based on 36a7c56 (behind). @ework — please rebase onto current master (verified clean above) and push; CI should then go green on the updated head. No content changes requested.

@ranxianglei
ranxianglei force-pushed the 2026-09-20_fix-audited-defects-1064 branch from de61ab1 to 09b7b7e Compare September 22, 2026 01:13
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Rebase done and pushed — with one disclosure about restored test commits.

Rebase: onto current master 9c01dbe, clean, zero conflicts (verified independently, matches your check). Branch is now:

09b7b7e test: match codex block args in serialized form (JSON.stringify escapes Windows separators)
2fd9805 test: make codex block-end assertion path-separator neutral (Windows)
d9521ba test: add regression tests for #1064 fixes (echo drop-only, session-cap reload, codex toml block end)
5da01b4 fix: harden context window, prefix reattach, loop system block, upstream abort (#1064)
e6a83ef fix: resolve audited defects from #1064 (echo summary, image tokens, config wipe, session cap, drain leak)

Gates on the rebased tree (local): typecheck ✅ · 2171 pass / 0 fail / 2 pre-existing skips ✅ · build ✅
CI on 09b7b7e: all 8 checks green (ubuntu 22/24, windows 22/24, version-guard, build-artifact, e2e-fake-codex, codex overlay).

Disclosure — the +4 tests vs your 2167: when the branch was rewritten onto 36a7c56 (f6b69ba/de61ab1), the three regression-test commits I had pushed earlier (6c381f8, 2780f9a, b8de83f) were dropped from the branch — tests/codex-install-block-end.test.ts (fix 3), the evict-then-revisit session-cap test in tests/fix-config-session.test.ts (fix 4), and the drop-only legacy-marker e2e in tests/codex-compact-e2e.test.ts (fix 1) were no longer present at de61ab1. So "each fix has a regression test" held for fixes 5–9 but not 1/3/4 on that head. I cherry-picked my three test commits back on top of the rebase (the three test: commits above) — test files only, zero src/ changes, each previously proven to fail against the pre-fix code. That's exactly your 2167 + 4 = my 2171.

No content changes otherwise; nothing requested is outstanding. Ready for human merge: #1072

中文摘要:已按你的要求把 PR 分支 rebase 到当前 master 9c01dbe(零冲突)并推送,rebase 后本地 typecheck/全量测试(2171 通过)/build 全过,新头提交 09b7b7e 的 8 项 CI 检查全部绿色;另发现分支改写时把我之前补的三个回归测试(fix 1/3/4)弄丢了,已用 cherry-pick 恢复(仅测试文件,+4 条测试),可以合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

Independent review of all 7 src fixes + tests, plus a rebase/gate verification (the rebase mentioned in earlier comments was never pushed — remote head is still 09b7b7e, mergeable_state behind).

Gate verification on rebased head (independent)

Rebased 09b7b7e onto origin/master d3bb77d in a temp worktree: clean, no conflicts (the PR's server.ts hunks touch prepareResponses image-estimate / echoReplaced and forward() streaming — disjoint from #1107's identity-keying region).

  • npm run typecheck ✅
  • PR test files (7): 85 pass / 0 fail ✅
  • Full suite on rebased head: 2198 pass / 0 fail (2 skipped = ACP_TEST_E2E-gated) ✅

Per-fix verdicts

# Fix Verdict
15a awaitDrain one-shot shared settle (server/stream-io.ts) — removes all 3 listeners instead of leaking 2 per backpressure wait ✅ root cause; test asserts listenerCount drops to 0
15b stopIdleTimer split lifetime (fetch-util.ts; degenerate-retry.ts:93, reasoning-guard.ts:545 callers; forward() passthrough) — splice/continue callers keep client-abort coverage while dropping the idle watchdog ✅ semantics match the forward() wrapper pattern; event-ordering test, no wall-clock dependence
— codex config.toml block-end (plugin-install.ts:701) — ^[ \t]*\[ matches indented next tables; refresh no longer deletes everything after an indented header ✅ data-loss-class fix; indented + column-0 fixtures; args matched in serialized (JSON.stringify) form, path-separator neutral
12 MAX_ANTHROPIC_BETA_WINDOW = 10M clamp (server/context-window.ts) — hostile context-9999999m can no longer drive every compression threshold toward infinity ✅ cap sits far above shipping betas; pathological-header test
— echoReplaced drop-only (server.ts prepareResponses) — only a real replacement (summary actually injected) suppresses forge-time re-injection; a blob-less legacy drop re-injects via the developer message ✅ e2e asserts MAIN-SUMMARY-SETUP present on the drop-only turn
— session-pool reload cap (session.ts) — memory-miss reload evicts at MAX before insert; evict-then-revisit can no longer grow past MAX_SESSIONS ✅ test reloads a after eviction, pool stays at 1
— imageBillingFor threaded into all 3 localInputEstimate sites (anthropic/openai/responses) ✅ consistency fix; symbols pre-exist on master

One behavior note (not a blocker)

#13 prefix-affinity: w === TAIL_WINDOW now rejects sub-8 tail windows entirely (was MIN_TAIL_MATCH = 3). Correct security posture — a crafted 3-item window can no longer adopt an unrelated stored session — but note the legitimate side: a truncation whose retained suffix is shorter than 8 items now falls through to a new session instead of reattaching. That is rare in practice (truncation survivors keep the bulk of the tail) and the conservative direction is the right one, just flagging the trade-off consciously.

Wire fidelity

None of the hunks touch tool-call arguments or wire message shape; the toml fix is client-config side; the compress system-prompt note is proxy-generated text, not user payload. Both compression modes unaffected by every hunk (stream/billing/echo paths are mode-shared and behavior identical).

Verdict

MERGE — all fixes are root-cause level with real regression tests, gates green on the rebased head. Housekeeping before merge: push the rebased branch (or merge as-is — GitHub reports mergeable; the gates above are proven on the rebased tree).

@ranxianglei
ranxianglei force-pushed the 2026-09-20_fix-audited-defects-1064 branch from 09b7b7e to 205f1ee Compare September 22, 2026 04:50
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Rebase pushed — head is now 205f1ee on master d3bb77d.

Rebase: pr-1072-rebase rebased onto origin/master d3bb77d (post-#1107). All 5 commits reapplied cleanly, zero conflicts — matches your temp-worktree check exactly. New lineage:

205f1ee test: match codex block args in serialized form (JSON.stringify escapes Windows separators)
dd4fc67 test: make codex block-end assertion path-separator neutral (Windows)
ed7b245 test: add regression tests for #1064 fixes (echo drop-only, session-cap reload, codex toml block end)
c2aa5b3 fix: harden context window, prefix reattach, loop system block, upstream abort (#1064)
4b7bbfc fix: resolve audited defects from #1064 (echo summary, image tokens, config wipe, session cap, drain leak)
d3bb77d Merge pull request #1107 ...   ← current master

Gates on the rebased tree: local run = typecheck ✅ · 2198 pass / 0 fail / 2 skipped (the ACP_TEST_E2E-gated ones) · build ✅ — identical numbers to your independent run. CI on 205f1ee: all 8 checks green (ubuntu 22/24, windows 22/24, version-guard, build-artifact, e2e-fake-codex, codex CODEX_HOME overlay).

On the #13 trade-off note: acknowledged and no action taken — agree with your read. Sub-8 truncation survivors falling through to a new session instead of reattaching is the conservative direction; adoption of an unrelated stored session is the worse outcome, and survivors keeping the bulk of the tail makes the miss rare. If it ever bites in practice, loosening the floor back down (or making it configurable) is a one-line change.

Nothing else outstanding. Ready for human merge: #1072

中文摘要:已把 PR 分支 rebase 到最新 master d3bb77d(零冲突,与你独立验证一致)并推送,rebase 后本地与 CI(typecheck、全量 2198 通过/0 失败/2 跳过、build、8 项检查含双 Windows)全部绿色;关于 #13 前缀亲和窗口下限的行为取舍已确认无异议(保守方向正确),可以合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

Follow-up to my review (#1072 (comment)), per maintainer decision:

  1. The four mechanical fixes are extracted into fix: mechanical subset of #1064 (awaitDrain leak, codex toml block-end, session-pool reload cap, drop-only echo) #1113 (awaitDrain leak, codex toml block-end, session-pool reload cap, drop-only echo re-injection) — built on current master, gates green. Once fix: mechanical subset of #1064 (awaitDrain leak, codex toml block-end, session-pool reload cap, drop-only echo) #1113 merges, this PR should rebase and DROP the duplicated hunks to avoid double-merging.
  2. fix: cache health — remove condense, fix isTitleGen, preserve cache_control #13 (tail-window trust threshold) now has its own design-level issue: Design: prefix-affinity tail-window reattach adopts sessions on mid-chain evidence — ownership proof needs a redesign, not a bigger threshold #1115 — the w === TAIL_WINDOW hardening stays here as the interim mitigation, but mid-chain adoption itself needs a structural answer (suffix-anchoring / depth-scaled evidence / dropping mid-chain adoption / kernel-verified adoption).
  3. This PR retains the behavioral subset: stopIdleTimer lifetime split, imageBillingFor threading (compress triggers move earlier for image-heavy sessions), withConversationIdNote, and the refactor: reapOrphanBlocks should live in acp-kernel, not the proxy #12 beta-window cap — these change observable behavior/policy and should get their own conscious review rather than riding along with bug fixes.



#1113 (merged as aba2bff) carries the four mechanical fixes — awaitDrain
listener leak, codex config.toml block-end, session-pool reload cap,
drop-only echo re-injection — byte-identical to what this branch had,
including their regression tests. Dropped those duplicated hunks here.

Retained (observable behavior/policy, for standalone review):
- stopIdleTimer lifetime split (fetch-util.ts; degenerate-retry/reasoning-guard
  callers keep client-abort coverage while dropping the idle watchdog)
- imageBillingFor threaded into all three localInputEstimate sites
- withConversationIdNote in the compress-loop system rebuild
- MAX_ANTHROPIC_BETA_WINDOW 10M clamp (#12)
- prefix-affinity w === TAIL_WINDOW trust threshold (#13 interim mitigation;
  design-level follow-up tracked in #1115)

References #1064, #1113, #1115.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Done per the maintainer decision — rebased onto post-#1113 master and the duplicated hunks dropped. Head is now 8ef6b8d on master 14d06f1.

No-coverage-loss check first: I verified #1113's merged content (aba2bff) against this branch file-by-file before dropping anything — all four mechanical fixes AND their regression tests (drain listener-count test, codex block-end fixtures incl. the indented-header case, session-cap reload test, drop-only echo e2e) are byte-identical to what this branch carried. So nothing is lost by the drop; the two-dot diff after rebase reduces exactly to the behavioral subset you listed.

What remains (single commit, 9 files, +144/−19):

The PR body has been updated to match the new scope (split documented, table now covers only the retained fixes, references #1064/#1113/#1115).

Gates: local = typecheck ✅ · 2198 pass / 0 fail / 2 pre-existing skips · build ✅; CI on 8ef6b8d: all 8 checks green (ubuntu 22/24, windows 22/24, version-guard, build-artifact, e2e-fake-codex, codex CODEX_HOME overlay).

Ready for human review/merge of the behavioral subset: #1072

中文摘要:已按维护者决定执行——确认 #1113 合并内容与本分支逐字节一致(含全部回归测试,无覆盖丢失)后,把 PR rebase 到含 #1113 的 master 14d06f1 并删除重复的四个机械修复 hunk,现在只剩行为子集(stopIdleTimer 生命周期拆分、imageBillingFor 估算接线、压缩系统提示 note、#12 beta 窗口上限、#13 尾窗信任阈值临时缓解),本地与 CI(typecheck、2198 通过/0 失败、build、8 项检查双 Windows)全绿,PR 描述已同步更新,可以人工审查合并。

@ranxianglei
ranxianglei merged commit aeeed25 into master Sep 22, 2026
8 checks passed
antclt pushed a commit to antclt/billion-context that referenced this pull request Sep 22, 2026
…, codex toml block-end, session-pool reload cap, drop-only echo re-injection

Split from ranxianglei#1072 per review (issuecomment-5771332368): these four fixes are
pure mechanical repairs with no policy/behavior trade-offs, extracted so they
can merge independently of the behavioral changes that stay in ranxianglei#1072:

- awaitDrain one-shot shared settle (server/stream-io.ts) — removes all 3
  listeners per backpressure wait instead of leaking two; forward() call site
  now uses it
- codex config.toml block-end (plugin-install.ts) — block ends at the next
  table header (optional indent, matching codexRemove); a refresh no longer
  deletes everything after an indented table
- session pool reload cap (session.ts) — memory-miss reload evicts at
  MAX_SESSIONS before insert; evict-then-revisit can no longer grow the pool
- echoReplaced drop-only (server.ts prepareResponses) — only a real
  replacement suppresses forge-time summary re-injection; a blob-less legacy
  drop re-injects via the developer message

Gates: typecheck, full suite (0 fail), build.
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

Item #13 (require the full TAIL_WINDOW = 8 instead of MIN_TAIL_MATCH = 3) is superseded by PR #1163 (closes #1115): tail-window reattach — mid-chain adoption — is removed entirely from src/prefix-affinity.ts, so the gate item #13 tightened no longer exists. The crafted-window regression test added around it now passes structurally: no window size, sub-8 or full-8, can adopt a stored session mid-chain anymore. The other audited items in this PR (#2/#3/#10/#11/#12/#14/#15/#16) are unaffected by #1163.

ranxianglei pushed a commit that referenced this pull request Sep 23, 2026
Tail-window reattach (#316) adopted a stored session when the incoming's
leading 8 per-item hashes hit ANY mid-chain offset of a tracked chain. A
mid-chain contiguous match is symmetric evidence, not an ownership proof: it
cannot distinguish 'same conversation, truncated replay' from 'a different
conversation quoting shared content' (templated tool outputs, standard files,
stock errors - parallel agents on one codebase produce these naturally), and
adoption was bidirectionally harmful (folded-summary leak to the adopter,
context pollution of the victim). The #1072 interim mitigation (full-8 window
instead of 3) closed sub-8 crafted windows but not the symmetry.

Three days of production logs (~11.5k anonymous resolutions) showed zero
tail-window reattaches and zero near-misses, so mid-chain adoption is removed
entirely (direction 3 of #1115): truncated replays now fork into a fresh
session. The truncated-run scan survives as lineage attribution only (never
matching): leading TRUNCATION_LINEAGE_WINDOW=8 run strictly inside a tracked
chain records lineage.reason='truncated' with all hit parents; a shared
leading prefix (LCP >= MIN_FORK_PREFIX=3) records 'forked' and takes
precedence. via narrows to 'prefix' | 'new'; the server tail-window log
branch is deleted.

Cost accepted: one raw resend + ladder restart per truncation (same cost class
as instruction-drift forks, #1106); opt-in block adoption (#629) still carries
fully-present blocks, kernel reconcile stays sound (deactivate/revive pinned).

Tests: tail-window-reconcile.test.ts renamed truncation-fork.test.ts and
rewritten (reattach assertions -> fork assertions; ambiguous multi-parent case
asserts attribution with both parents). New design record SESSION-IDENTITY.md
(+ .zh-CN): identity principles, threat model, measurement, rejected
alternatives, three-layer framework, future client-side identity signal.
@ranxianglei
ranxianglei deleted the 2026-09-20_fix-audited-defects-1064 branch October 15, 2026 05:32
cskwork pushed a commit to cskwork/billion-context that referenced this pull request Oct 21, 2026
…lei#1115)

Tail-window reattach (ranxianglei#316) adopted a stored session when the incoming's
leading 8 per-item hashes hit ANY mid-chain offset of a tracked chain. A
mid-chain contiguous match is symmetric evidence, not an ownership proof: it
cannot distinguish 'same conversation, truncated replay' from 'a different
conversation quoting shared content' (templated tool outputs, standard files,
stock errors - parallel agents on one codebase produce these naturally), and
adoption was bidirectionally harmful (folded-summary leak to the adopter,
context pollution of the victim). The ranxianglei#1072 interim mitigation (full-8 window
instead of 3) closed sub-8 crafted windows but not the symmetry.

Three days of production logs (~11.5k anonymous resolutions) showed zero
tail-window reattaches and zero near-misses, so mid-chain adoption is removed
entirely (direction 3 of ranxianglei#1115): truncated replays now fork into a fresh
session. The truncated-run scan survives as lineage attribution only (never
matching): leading TRUNCATION_LINEAGE_WINDOW=8 run strictly inside a tracked
chain records lineage.reason='truncated' with all hit parents; a shared
leading prefix (LCP >= MIN_FORK_PREFIX=3) records 'forked' and takes
precedence. via narrows to 'prefix' | 'new'; the server tail-window log
branch is deleted.

Cost accepted: one raw resend + ladder restart per truncation (same cost class
as instruction-drift forks, ranxianglei#1106); opt-in block adoption (ranxianglei#629) still carries
fully-present blocks, kernel reconcile stays sound (deactivate/revive pinned).

Tests: tail-window-reconcile.test.ts renamed truncation-fork.test.ts and
rewritten (reattach assertions -> fork assertions; ambiguous multi-parent case
asserts attribution with both parents). New design record SESSION-IDENTITY.md
(+ .zh-CN): identity principles, threat model, measurement, rejected
alternatives, three-layer framework, future client-side identity signal.
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.

1 participant