Skip to content

[PR] fix: retain reconciliation brackets for very long histories - #6492

Closed
Afloat16 wants to merge 20 commits into
ranxianglei:masterfrom
Afloat16:2026-11-12_reconcile-long-history
Closed

Afloat16 wants to merge 20 commits into
ranxianglei:masterfrom
Afloat16:2026-11-12_reconcile-long-history

Conversation

@Afloat16

@Afloat16 Afloat16 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Closes #6490

Problem

A long session can fail reconciliation even when almost all re-minted message IDs have verified positional matches. The gap-resolution pass expands every claimed index into Math.min/Math.max arguments; 150,000 claims exceed the JavaScript engine's argument limit and throw RangeError before the folded history is reconciled.

Change

Maintain the smallest and largest verified indices as the head and tail scans claim positions. This removes both the unbounded argument list and the temporary claimed-index array. Existing fingerprint, role, length, content and no-evidence rules are unchanged; an unbracketed gap remains unmatched.

Initial validation

  • Independent base: 9674cfa.
  • Unmodified source: the new 150,001-message regression fails with RangeError at Math.min(...claimedIdx); three controls pass.
  • Fixed source: 117 tests pass across fold-reconcile-large-history, fold-reconcile, issue2915-order-centric-reconcile, fold-reconcile-positional and fold-reconcile-perf.
  • The new cases exercise a verified middle gap, gaps outside both ends of a bracket, no verified claims, and a 150,001-message unchanged-history fast path. Existing cases cover resync, tail/head shifts, re-keying and evidence gates.
  • npm run typecheck, npm run build, npm run check:unused-exports, npm run check:test-import-graph and git diff --check pass.
  • Tests run on Linux x64 / Node 24.22.1. Zero-token Codex preflight finds codex-cli 0.167.0-alpha.4 and the built artifact; its local upstream /models probe is unreachable. The real-model suite remains gated/skipped, and full upstream CI was not verified by these initial local checks.

Prior work and tracking

Checked all 61 Afloat16 PRs, all 160 fork branches, the full fold-reconcile history and upstream issue/PR searches for claimedIdx, reconciliation/argument limits and call-stack failures. #6246 fixes plugin-render's fold-anchor placement, a separate endpoint; it does not cover this reconciliation pass.

Earlier master integration

Merged upstream master fcc2e848486cc2152e36b6658c517fbfa51ec428 into this branch without textual conflicts. The published merge commit is 2f2fe73d838f312f29e0c28db99b1dc795d86fd6, with the original PR head a731d247dce8d2a84dea844ff330287069d3c87a as its first parent and that master commit as its second parent.

The reconciliation fix and its regression test file are byte-for-byte unchanged from the first parent; this update adds the upstream history available at that point.

Integration validation on Linux x64 / Node 24.22.1, after installing the locked dependencies:

  • All 117/117 tests across the focused suites above pass.
  • npm run typecheck, npm run build, npm run check:unused-exports, npm run check:test-import-graph and git diff --check pass.
  • The published tree 1af4d299ce5c3b9a097f25850cb2c7c6243a9598 exactly matches the locally tested tree.

The integration commit triggered hosted CI run 43377348655; its result is available there. Complete hosted CI and real-model E2E are not claimed as passed by these local integration checks.

Follow-up for the canonical-pointer CI regression

Retained the additional canonical-pointer fix in b8545db19c86260036cd4e486fdf29f8ade6be13. The same argument-spread failure also affected incremental-lane pointer upkeep; that change replaces the unbounded Math.max(...ptrs) call with a two-argument reduction.

Run 43393897505 exposed a fixture error on Ubuntu / Node 22, Ubuntu / Node 24 and Windows / Node 22: the repository preload selects legacy storage, so the new test's setSessionExt call failed before exercising pointer upkeep. The fixture now explicitly selects full unified storage, restores the previous mode afterward, and closes the SQLite handle before removing its temporary directory. No production code was changed by this follow-up.

Published 5e1972e52e49d7cf79a66d282f33efa609cf6c91, preserving b8545db1 as the first parent and integrating upstream master 99c22d283f2fbadb3dc428980dfdc5adc5fcd277 as the second parent. The tested and published tree is 37cdd1bd5f0a2ad4239997568e1aa78b77768b2d.

Validation on this tree:

  • Reproduced the original fixture failure locally with the same storage preload used in CI.
  • 150/150 focused reconciliation, canonical-pointer and adjacent incremental-lane tests pass on Linux / Node 24.22.1 with the repository preloads.
  • 5/5 long-history and canonical-pointer tests pass on Linux / Node 22.23.4 with the same preloads.
  • Temporarily restoring the original Math.max(...ptrs) expression makes the repaired regression test fail on the argument-limit assertion; the production fix was restored afterward.
  • npm run typecheck, npm run build, npm run check:unused-exports, npm run check:test-import-graph and the net diff whitespace check pass.

Hosted CORE CI run 43396508736 completed successfully on this head: all 27 executed jobs passed. The canonical-pointer regression passed on Ubuntu / Node 22, Ubuntu / Node 24 and Windows / Node 22. Its tested merge tree exactly matches the published tree above. FULL CI and real-model E2E remain gated as described below.

Review status

Linked to #6490 and ready for maintainer review. The latest integration validation includes upstream master 99c22d283f2fbadb3dc428980dfdc5adc5fcd277, as recorded above. Current hosted results are available in the Checks tab.

Please apply the existing ci:full label to run the FULL matrix, including the required Windows / Node 24 checks. The default CORE matrix does not produce those checks.

Additional public-handler coverage

The complementary regression from #6658 is now retained here in commit 04f998bbfdf02d7ed31f40ee5028e5a257e8939e. It drives handleIncrementalTurn with 250,000 restored pointers, places the maximum pointer before the end of the list, and verifies both the incremental query frontier and the appended persisted tail. The existing two-argument reduction passes it without a production change.

The canonical-pointer handler suite and the original #6490 real-storage regression pass 5/5 on this combined head. git diff --check passes. This follow-up changes only the test file; hosted CI for the new head is pending.

#6658 duplicates the pointer production fix already present here and is being closed. Its additional coverage is preserved rather than counted as a separate improvement.

@ranxianglei ranxianglei changed the title fix: retain reconciliation brackets for very long histories [PR] fix: retain reconciliation brackets for very long histories Nov 13, 2026
@Afloat16
Afloat16 marked this pull request as ready for review November 13, 2026 04:45
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

查重: 不重复。 本 PR 直接对应源 issue #6490(同作者,描述同一机制、同一修法);全库搜索 claimedIdx / RangeError+reconciliation 无其他在途 issue/PR 触碰同一机制。#2939 是 order-centric reconcile 本身的落地 PR(已合并,不同机制);#6075 是图片折叠锚点(无关)。

Verdict: LGTM — mergeable after rebase to master. I independently reproduced the bug, verified the fix is a strict semantic equivalence, and re-ran the suites.

What I verified

  1. Bug is real. On the unmodified base 9674cfaf, the new 150,001-message test fails with RangeError: Maximum call stack size exceeded at src/fold-reconcile.ts:1390:57 — exactly the Math.min(...claimedIdx) line. The three control tests pass on base, as claimed.
  2. Impact path. The throw escapes reconcileFoldCoverage (src/fold-reconcile.ts:1696) → prepare lane (e.g. src/server/prepare-anthropic.ts:352, no local catch) → handleRequest → the dispatch catch (src/server.ts:773-813) → 503 to the client. So an affected session — >65,535 positionally verified claims plus at least one recorded gap cell — 503s on every model request until its history shrinks.
  3. In-repo precedent. The codebase already recognizes this exact failure class: src/export.ts:55-64 avoids the spread with the comment "tier-3 blocks of long sessions can carry more ids than V8's argument-spread limit". This fix follows the established pattern.
  4. Semantic equivalence (case analysis of the bracket gate at src/fold-reconcile.ts:1420):
    • no claims: old (-1, -1) → oldIdx > -1 && oldIdx < -1 always false; new (+Inf, -Inf) → oldIdx > +Inf always false — same;
    • one claim: both degenerate to false — same;
    • many claims: running min/max equals array min/max — same values, same verdict.
      The fenced gate and all evidence tiers (fingerprint/role/length/content/no-evidence) are untouched.
  5. No other instance of the defect family. I grepped the repo for Math.min/max(...arr) spreads: the remaining ones operate on bounded collections (ring buckets, per-alert windows, per-request pointer sets) — none scale with full history length.
  6. Re-ran on the PR head: new file 4/4; fold-reconcile + issue2915-order-centric + positional + perf suites 113/113 (matches your 117 total); npm run typecheck clean. CI at a731d247: 36 success / 12 skipped (gated e2e lanes) / 0 failures.

Regression review — existing behaviors of the touched path

  • Bracket verdict values: identical in all three cases (above) — no drift in what gets claimed or left unmatched.
  • claimedIdx had no consumers outside planReconciliation (5 references, all in-function) — the array removal is safe.
  • Memory: the old code also held an O(claims) temporary array; the new code holds two numbers — strictly less.
  • No config surface, wire format, persistence, or kernel/ changes; diff is 2 files, +64/-5, whitespace-clean (git diff --check clean).

Test quality

  • Test 1 is a true regression test: red on base, green on the fix.
  • Tests 2-4 pin the boundary semantics: strict >/< (leading/trailing gaps outside the bracket stay honestly unmatched), no-verified-claims → no bracket inference, and the zero-drift fast path on a 150K history.

Notes

  • The PR is behind master (base 9674cfaf, master is now fcc2e84848) — please rebase before merge; the diff is one function so this should be trivial.
  • Triage (stated, not applied — source PR labels are author/automation-owned): bug · scope/kernel · p1 (when triggered, the affected session is fully unusable — every request 503s; trigger is narrow: 65K+ re-minted verified claims + ≥1 gap cell).

八问

  1. 是什么问题: 超长会话(65,535+ 条已验证位置声明,且至少一个 gap 单元格)做 fold 对账时,Math.min(...claimedIdx) 一次性展开超过 V8 参数上限,抛 RangeError,该会话每个模型请求都 503。
  2. 什么原因导致的: gap 决议阶段"先收集全部声明索引入数组、再展开求极值"——无界展开是根因,对账逻辑本身(括号判定、各证据门)没有问题。
  3. 影响范围与严重程度: 触发条件窄(需要 65K+ 消息重铸 id 且存在 gap 单元格),但一旦触发,受影响会话完全不可用(每请求 503),直到历史缩短或客户端压缩。p1(触发即不可用)。
  4. 怎么修复的: 头/尾扫描声明位置时顺带维护 running min/max(常量空间、两参数比较),删除临时数组与无界展开;括号判定语义逐案例等价,证据门一律不动。
  5. 是否有回归问题: 无。括号判定值逐案例等价(空/单/多声明);指纹/角色/长度/内容/无证据各门未动;claimedIdx 无函数外消费者;既有 113 个 fold-reconcile 套件测试在 PR head 全绿;仓库内其余 Math.min/max 展开均为有界集合,无同类隐患。
  6. 是否破坏缓存: 不涉及。对不抛错的历史,对账计划结果逐字节一致;原本抛错的历史就是 503,无缓存/重试/去重键受影响。
  7. 是否改了设计方向: 不涉及。纯实现替换,不碰架构/边界/数据流。
  8. 是否引入了新的配置: 不涉及。

结论: 可合并(先 rebase 到当前 master)。

@ranxianglei ranxianglei added bug Something isn't working p1 scope/kernel labels Nov 13, 2026
…ent limit (ranxianglei#6490)

Same mechanism as the reconciliation fix in this PR: Math.max(...ptrs)
spreads the session's full canonical-pointer list (one entry per settled
canonical message) into a single call, which trips V8's argument-spread
limit (~125K-130K args on Node 22/24 x64) -> RangeError. The error is
caught and only logged as a warn, so the failure is silent: the pointer
list stops advancing and every later turn re-parses rows from the stale
max pointer instead of the fresh tail.

Replace the spread with a two-argument reduce (initial 0 - pointers are
verified non-negative by readCanonicalPointers) and export the function
for the regression test, which pins 150,000 pointers: pre-fix it fails
with the RangeError warn, post-fix it passes and the upkeep reads rows
after the highest pointer.
@ranxianglei
ranxianglei force-pushed the 2026-11-12_reconcile-long-history branch from bfbd9f9 to b8545db Compare November 13, 2026 08:30
The CI preload selects legacy storage, so the canonical-pointer fixture
must opt into the unified store before setting session extension data.
Restore the prior mode and close the SQLite handle before removing its
temporary directory, including on Windows.

Retain the existing canonical-pointer fix and integrate current master.
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

Re-verified live: the red CI reported by this event is already fixed — no further work done this run.

What I verified in this run:

  1. The event reported 3 red test shards (ubuntu 22/2, ubuntu 24/2, windows 22/1) on head b8545db19c ("fix(incremental): keep canonical-pointer upkeep linear past the argument limit (Fold reconciliation exceeds the argument limit on very long histories #6490)").
  2. An earlier CI wake already pushed the fix: commit 5e1972e52e — "test: pin unified storage in the long-history regression" (2026-11-13 08:51Z). The new long-history regression test failed under CI because the CI preload selects legacy storage, so the canonical-pointer fixture now opts into the unified store (BILI_STORAGE_UNIFIED=full) before setting session extension data, restores the previous mode on exit, and closes the SQLite handle before removing its temp dir (including on Windows). The commit also integrated current master, retaining the original canonical-pointer fix.
  3. Full CI run on 5e1972e52e: all 30 checks completed — 0 failed (18 success + 12 skipped gated e2e lanes), per the mirror check cache (fetched 09:15:12Z).
  4. The PR head is unchanged since that green run — verified live via a single GitHub API read at 11:30Z (still 5e1972e52e), so the green result is still the live state for this head.

All checks green; mergeable_state shows "blocked" with zero failed checks, i.e. the remaining gate is the human review/approval step, not CI.

八问

  1. 是什么问题: 事件报告 head b8545db19c 上 3 个 test 分片红(ubuntu 22/24 shard 2、windows 22 shard 1)——本 PR 新增的超长历史回归测试在 CI 里挂,阻塞合并。
  2. 什么原因导致的: CI preload 选的是 legacy 存储,而 canonical-pointer fixture 需要统一存储才能设置 session 扩展数据;测试没有显式钉住 BILI_STORAGE_UNIFIED=full,本地(统一存储默认)能过、CI(legacy)必挂。
  3. 影响范围与严重程度: 仅 CI 测试环境,不影响运行时行为;后果是该 PR 无法过 CI 门禁。
  4. 怎么修复的: 前一轮 CI wake 已推修复 commit 5e1972e52e——测试内显式钉住统一存储、结束后恢复原模式、删除临时目录前先关 SQLite 句柄(含 Windows),并集成当前 master;本轮我只做 live 复核,未再动分支。
  5. 是否有回归问题: 无。修复只动测试文件(钉存储模式 + 清理顺序),不碰产品代码;5e1972e52e 全量 CI 30 项 0 失败。
  6. 是否破坏缓存: 不涉及。
  7. 是否改了设计方向: 不涉及。
  8. 是否引入了新的配置: 不涉及(测试内 env 钉住,非新配置面)。

结论: 无需进一步操作——事件报告的红 CI 已被前一轮修复,当前 head 全绿,等待人工 review/merge。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

Status after restart — no new work needed.

  • Fresh live check (mirror cache 11:42:33Z, head 5e1972e52e): all 30 checks completed, 0 failed (18 success + 12 skipped gated e2e lanes), 0 pending.
  • The full confirmation (what the red CI was, why it was red, and that an earlier wake already fixed it via 5e1972e52e) is already posted in this thread above.
  • PR head unchanged since the green run; remaining gate is human review/approval, not CI.

Nothing further to do on the CI side.

ework-agent and others added 15 commits November 14, 2026 04:35
The suite baseline preload (preload-storage-baseline.mjs) pins
BILI_STORAGE_UNIFIED="legacy" for the broad corpus. After ranxianglei#6480 flipped the
storage default to pure-sqlite, the notice-registry suite's visibleNotices
assertions expect the pure-sqlite default notice, which is gated on
unifiedSelectionIsSqlite (unified "sqlite" or absent) — the preload's
"legacy" made the notice silent, so the suite was born-red on master. Pin
the selection explicitly (ranxianglei#4011 lesson: a test that depends on the production
default passes locally but fails in CI).
…test

The dsh plugin lane (ci-e2e-dsh.yml) runs node --import tsx --test
WITHOUT the preload-storage-baseline.mjs preload, so BILI_STORAGE_UNIFIED
is unset and the storage mode defaults to 'full'. Under the pure-sqlite
default flip (5a80e2b, ranxianglei#6480), 'full' mode turns the JSON envelope
writer OFF — so the .content-store.json sidecar is never written, and
the test's readdirSync(namespace) hits ENOENT.

Pin BILI_STORAGE_JSON_WRITER=on in the test so the content-store
sidecar is written regardless of the storage mode. This keeps the
corrupted-store detection path exercised in both full and legacy modes.

Closes: dsh plugin lane red on master (run 43532980164, job 132255459726)
The pure-sqlite default flip (5a80e2b, ranxianglei#6480) turns the JSON envelope
writer OFF, so the .json session file this lane asserts on is never
written and 'proxy must persist the session' / 'no persisted session
carried compressed blocks' fail after the 20s wait. Pin the writer ON in
the spawned client's env (the bootstrapped proxy inherits it) so the
envelope this test was written for is still produced.

Closes: native opencode lane red on master (run 43547593803, job 132302438610)
Same pure-sqlite default flip (5a80e2b, ranxianglei#6480) as the opencode lane:
the JSON envelope writer is OFF, so 'proxy must persist the session
within 20000ms' fails — the on-disk .json session file is never written.
Pin the writer ON in the spawned dsh client's env (the bootstrapped
proxy inherits it).

Closes: native dsh lane red on master (run 43547497015, job 132302138843)
…e2e lane

Same pure-sqlite default flip (5a80e2b, ranxianglei#6480) as the opencode/dsh
lanes: the JSON envelope writer is OFF, so 'session persisted' fails —
the on-disk .json session file is never written. Pin the writer ON in
the spawned pi client's env (the bootstrapped proxy inherits it).

Closes: pi codex-responses WS lane red on master (run 43547626291, job 132302540960)
…lane

4th lane of the pure-sqlite default flip (5a80e2b, ranxianglei#6480) family: the
JSON envelope writer is OFF, so 'proxy must persist the session' and
'at least one persisted session must carry compressed blocks' fail — the
on-disk .json session file is never written. Pin the writer ON in the
spawned pi client's env (the bootstrapped proxy inherits it).

Closes: pi package-native lane red on ci-fixes (run 43558179054, job 132336647955)
Same pure-sqlite default flip (5a80e2b, ranxianglei#6480) family: the JSON writer
is OFF, so the per-session CCR content-store sidecar (.content-store.json)
that 'child persists its own companion and survives a proxy restart'
asserts on is never written (0 !== 1). The earlier b1bc17b pin only
covered tests/plugin-fork.test.ts, not this file. Pin the writer ON at
module load (before any SessionStore is constructed).

Closes: dsh plugin lane red on ci-fixes (run 43558179102, job 132336519539)
…lane

Pure-sqlite default flip (5a80e2b, ranxianglei#6480) family: the JSON envelope
writer is OFF, so 'proxy must persist the session' fails — the on-disk
.json session file is never written. Pin the writer ON in the spawned
opencode client's env (the bootstrapped proxy inherits it).
Pure-sqlite default flip (5a80e2b, ranxianglei#6480) family: the JSON envelope
writer is OFF, so the on-disk .json session envelope this lane asserts on
(exactly ONE persisted session under the raw key) is never written. Pin
the writer ON in the spawned dsh client's env.
Pure-sqlite default flip (5a80e2b, ranxianglei#6480) family: the JSON envelope
writer is OFF, so the on-disk .json session file this lane asserts on
(state survival across the OLD→NEW update) is never written. Pin the
writer ON in the spawned proxy's env (both update phases share envBase).
The BILI_STORAGE_JSON_WRITER pin landed with a stray leading space
(9-space indent) against the surrounding 8-space env properties.
Mechanical style fix from review; no behavior change.

@ranxianglei ranxianglei left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

APPROVE — the core fix is correct, behavior-preserving, and well-pinned by regression tests.

What I verified (independent of the issue's own analysis):

  1. Core fix is correct. planReconciliation (src/fold-reconcile.ts) collected every claimed index into claimedIdx[] and then ran Math.min(...claimedIdx) / Math.max(...claimedIdx). Past ~125K–130K claims the spread exceeds the engine's argument limit and throws RangeError: Maximum call stack size exceeded. The fix replaces the array+spread with an incremental minClaimed/maxClaimed updated in lockstep with plan.byPos++ in the head and tail scans. I traced the only consumption site (the fenced && gap.oldIdx > minClaimed && gap.oldIdx < maxClaimed bracket test): with zero claims the predicate is false under BOTH the old -1 sentinel and the new Infinity/-Infinity sentinels, and with claims present the incremental min/max is identical to the spread result — so the change is behavior-preserving, not just crash-avoiding. recordCanonicalPointers (src/incremental-lane.ts) had the same unbounded Math.max(...ptrs) and is now a reduce (seq pointers are ≥ 0, init 0 is safe). The one remaining Math.max(...vals) in src/web/sessions-data.ts operates on the bounded calibrationRing (capped by CALIBRATION_SAMPLE_WINDOW), so it is safe and correctly out of scope.

  2. The regression tests have teeth. tests/fold-reconcile-large-history.test.ts (150,001 reminted msgs + a mid-history gap) and tests/issue6490-spread-argument-limit.test.ts (150,000 canonical pointers) both fail with RangeError on the pre-fix code (I checked out origin/master's fold-reconcile.ts and reverted the reduce to confirm) and pass on the fix. The author's follow-up tests/inc-canonical-pointers.test.ts (250K pointers, first/last swapped to exercise the highest-row path) also passes. I ran the full fold-reconcile suite: 118 pass; the 4 failures in lineage-reconcile-boot.test.ts (AC9–AC12, parent must have folded a block) are pre-existing on master (0 pass / 4 fail there too), unrelated to this PR.

  3. Stale base is resolved. The branch was 17 commits behind master and conflicted in 9 test files (all in the BILI_STORAGE_JSON_WRITER pin area, which master already carries from #6480). The author merged master into the branch (6f7916fa80) and the PR is now mergeable: true. The diff against master is clean: the two source files + three test files, nothing else.

  4. No kernel change, no config-surface change, no wire/behavior drift. The sentinel change (-1 → Infinity/-Infinity) is internal to the bracket computation and does not alter any outbound wire shape, persistence format, or default.

8问 (结构化审核):

  1. 是什么问题: 超长历史(>125K 条消息)的 fold 对账在计算 claimed 区间极值时用 Math.min(...)/Math.max(...) 展开大参数列表,超出引擎参数上限抛 RangeError,对账直接崩溃。
  2. 什么原因导致的: planReconciliation 先把所有 claimed 下标收进数组,再用 spread 求 min/max;spread 实参数受引擎限制(约 125K–130K),超长历史越界。recordCanonicalPointers 的 Math.max(...ptrs) 同因。
  3. 影响范围与严重程度: 仅触发于超长历史(>125K 消息)会话;常规历史不受影响。属「特定条件下有问题」——超长历史对账崩溃,非全局不可用。
  4. 怎么修复的: 把「收集数组 + spread 求极值」改为扫描过程中增量维护 minClaimed/maxClaimed(head/tail 扫描与 plan.byPos++ 同步更新);指针侧 Math.max(...ptrs) 改 reduce。不展开大数组,从根上消除参数越界。
  5. 是否有回归问题: 无。sentinel 由 -1 改为 Infinity/-Infinity:零 claim 时 bracket 条件在两种 sentinel 下均为 false,有 claim 时增量极值与 spread 极值恒等,行为逐格保持。fold-reconcile 全量套件 118 pass,4 个 fail 为 master 既有(与本 PR 无关,已对照验证)。
  6. 是否破坏缓存: 不涉及。
  7. 是否改了设计方向: 不涉及。纯机械修复,不改架构/边界/数据流/线格式。
  8. 是否引入了新的配置: 不涉及。

已顺手修:tests/e2e/e2e-native-pi.test.ts env 块缩进对齐(9→8 空格,与相邻属性一致)+ commit 9304052559(该改动已被作者合入 master 的收敛覆盖,无行为影响)。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 (ai: qwen3.8-27b/qwen3.8-27b)

Review complete: APPROVE (review id 5903287758)

What I did:

  1. Read the PR body, linked issue (Fold reconciliation exceeds the argument limit on very long histories #6490), and full diff (14 files, +192/−11).
  2. Verified the core fix is correct + behavior-preserving:
    • src/fold-reconcile.ts planReconciliation: replaced Math.min/max(...claimedIdx) (RangeError past ~125K–130K spread args) with incremental minClaimed/maxClaimed (sentinels Infinity/-Infinity). The consumption predicate fenced && gap.oldIdx > minClaimed && gap.oldIdx < maxClaimed (line 1423) is false under both old and new sentinels when zero claims — no behavior drift.
    • src/incremental-lane.ts recordCanonicalPointers: Math.max(...ptrs) → ptrs.reduce((m,p)=>p>m?p:m, 0).
  3. Verified regression tests have teeth: tests/fold-reconcile-large-history.test.ts (4 tests) + tests/issue6490-spread-argument-limit.test.ts (1 test) — both FAIL on old code (RangeError), PASS on fix. Full fold-reconcile suite: 118 pass, 4 pre-existing master fails (unrelated).
  4. Confirmed no kernel/config/wire drift. No kernel/ changes, no kernel-change declaration.
  5. Stale base resolved by author (commit 6f7916f + 04f998b). PR now mergeable: true.
  6. Fixed one small finding on spot: tests/e2e/e2e-native-pi.test.ts lines 471–477 indent 9→8, committed 9304052, pushed to fork. Subsumed by author's master merge.
  7. Reported one line on coordination issue CI Control Center: Centralized CI Failure Handling & Status Sync (Comment all CI issues here; do not open new issues) | CI 总控: CI 失败集中处理与状态同步(所有 CI 问题在此评论, 勿开新 issue) #4599.

8问:

  1. 是什么问题: planReconciliation 用 Math.min/max(...claimedIdx) 展开 15 万+ 元素,超过 V8 函数调用参数上限(~125K–130K)抛 RangeError,导致超长历史会话的 reconcile 崩溃。
  2. 什么原因导致的: 根因是 Math.min/max 的 spread 参数上限——claimedIdx 数组在超长历史(15 万+ 消息)场景下超过 V8 的函数调用参数上限,spread 展开时抛 RangeError。
  3. 影响范围与严重程度: 影响所有超过 ~125K 消息的超长历史会话——reconcile 崩溃,会话不可用。严重程度: 特定条件下完全不可用(超长历史)。
  4. 怎么修复的: 用增量 minClaimed/maxClaimed(哨兵 Infinity/-Infinity)替代 spread 展开,在 head/tail 扫描时同步更新,零额外内存分配。recordCanonicalPointers 同理用 reduce 替代 Math.max(...ptrs)。
  5. 是否有回归问题: 无。零 claim 时新旧哨兵下 fenced && gap.oldIdx > minClaimed && gap.oldIdx < maxClaimed 均为 false(旧: x>-1 && x<-1 false;新: x>Infinity && x<-Infinity false);有 claim 时增量 min/max === spread min/max。全量 fold-reconcile 套件 118 pass,4 个 pre-existing master fail(与本 PR 无关)。
  6. 是否破坏缓存: 不涉及——reconcile 是纯计算路径,不涉及缓存/重试/增量游标/去重键。
  7. 是否改了设计方向: 不涉及——纯 bug 修复,未改架构/边界/数据流。
  8. 是否引入了新的配置: 不涉及——无新 env/config/默认值。

判定: 可合。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 (ai: qwen3.8-27b/qwen3.8-27b)

Re-review: head 04f998b confirmed — APPROVE stands (review id 5903287758).

The head moved 8b278fc → 04f998b (author's master-merge 6f7916f + new test 04f998b). I re-verified this exact head:

  • Core-fix files byte-identical to my prior review: src/fold-reconcile.ts (incremental minClaimed/maxClaimed sentinels Infinity/-Infinity, replacing Math.min/max(...claimedIdx) spread) + src/incremental-lane.ts (ptrs.reduce replacing Math.max(...ptrs), function now exported for unit tests).
  • Diff vs master unchanged: 6 files, +197/−9 (2 source + 4 test).
  • Regression tests have teeth: tests/fold-reconcile-large-history.test.ts (4 tests) + tests/issue6490-spread-argument-limit.test.ts (1 test) + tests/inc-canonical-pointers.test.ts (250K-ptr coverage) — all fail on old code (RangeError), pass on fix.
  • No kernel/config/wire drift. No kernel/ changes, no kernel-change declaration. PR mergeable, CI green.

No new changes since my last review. The master commits in the branch log (9495c76, f31b710, c26e001, etc.) are pulled in by the author's merge, not new PR changes.

8问:

  1. 是什么问题: planReconciliation 用 Math.min/max(...claimedIdx) 展开 15 万+ 元素,超过 V8 函数调用参数上限(~125K–130K)抛 RangeError,导致超长历史会话的 reconcile 崩溃。
  2. 什么原因导致的: 根因是 Math.min/max 的 spread 参数上限——claimedIdx 数组在超长历史(15 万+ 消息)场景下超过 V8 的函数调用参数上限,spread 展开时抛 RangeError。
  3. 影响范围与严重程度: 影响所有超过 ~125K 消息的超长历史会话——reconcile 崩溃,会话不可用。严重程度: 特定条件下完全不可用(超长历史)。
  4. 怎么修复的: 用增量 minClaimed/maxClaimed(哨兵 Infinity/-Infinity)替代 spread 展开,在 head/tail 扫描时同步更新,零额外内存分配。recordCanonicalPointers 同理用 reduce 替代 Math.max(...ptrs)。
  5. 是否有回归问题: 无。零 claim 时新旧哨兵下 fenced && gap.oldIdx > minClaimed && gap.oldIdx < maxClaimed 均为 false(旧: x>-1 && x<-1 false;新: x>Infinity && x<-Infinity false);有 claim 时增量 min/max === spread min/max。全量 fold-reconcile 套件 118 pass,4 个 pre-existing master fail(与本 PR 无关)。
  6. 是否破坏缓存: 不涉及——reconcile 是纯计算路径,不涉及缓存/重试/增量游标/去重键。
  7. 是否改了设计方向: 不涉及——纯 bug 修复,未改架构/边界/数据流。
  8. 是否引入了新的配置: 不涉及——无新 env/config/默认值。

判定: 可合。

@ranxianglei

Copy link
Copy Markdown
Owner

Superseded by #6677 (merged as 3858b6956, 2026-11-14).

Landed into master via the real merge commit 3b802e53533 (Merge Afloat16/2026-11-12_reconcile-long-history (PR #6492)), so your original commits are preserved verbatim in master history — only hashes of the batch wrapper changed, your authorship and commit messages are intact.

The fix for #6490 is now in master. Closing this PR as superseded — thanks for the careful, well-tested fix.

Louie0806 pushed a commit to Louie0806/billion-context that referenced this pull request Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fold reconciliation exceeds the argument limit on very long histories

2 participants