Skip to content

Fold reconciliation exceeds the argument limit on very long histories #6490

Closed

Description

@Afloat16

Problem

At master 9674cfa, planReconciliation gathers every verified positional claim in claimedIdx and expands that array into Math.min and Math.max when resolving a gap. A valid history with 150,000 verified claims and one reformatted middle cell throws RangeError: Maximum call stack size exceeded before reconciliation can finish.

Reproduction

Construct 150,001 assistant text messages and the stored positional fingerprints, then re-mint all message IDs without changing their order or content except one middle cell. Cover the old IDs and give the gap its role/type/length anchor. planReconciliation throws at Math.min(...claimedIdx). The committed fold-reconcile-large-history regression reproduces this on unchanged master.

Proposed correction

Track the minimum and maximum positional-claim indices while the head and tail scans run. This uses constant auxiliary space and two-argument comparisons, preserves existing bracket semantics, and leaves content/role/length evidence gates intact.

Evidence and limits

Baseline: one new large-history case fails and three controls pass. Fixed: all 117 focused reconciliation, positional, order-centric and performance tests pass. Typecheck, build, unused-export and import-graph gates pass. Real-model Codex E2E and full upstream CI remain unverified; the zero-token preflight finds the CLI/build, but the local model endpoint is unreachable.

This is distinct from #6246, which removes the argument limit in plugin-render anchor placement and does not touch reconciliation.

The patch is prepared on Afloat16:2026-11-12_reconcile-long-history. This issue requests maintainer discussion; it does not claim prior agreement. The linked draft PR will retain the validation limits.

Activity

  1. Afloat16 commented on Nov 13, 2026

    @Afloat16
    ContributorAuthor

    (ai: OpenAI/GPT-6 Astra Pro)

    The prepared fix is submitted in #6492 as a draft for maintainer discussion. The PR records the baseline reproduction, focused validation results and remaining validation limits.

  2. ranxianglei commented on Nov 13, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

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

    Duplicate screening: not a duplicate — searched open+closed issues/PRs for the argument-limit/spread mechanism:

    Triage (three steps)

    1. Reproduced. On master the committed 150,001-message regression fails with RangeError: Maximum call stack size exceeded at src/fold-reconcile.ts:1390 (Math.min(...claimedIdx)); the three controls pass. Matches your baseline exactly.
    2. Root-cause layer. The defect is not "reconciliation is slow" — it is that an unbounded array is spread into function arguments: V8's argument-spread limit is ~125K–130K args on Node 22/24 x64 (measured 125,000 ok / 130,000 throws here), so any session with that many verified positional claims plus one mass ID re-mint (codec/protocol switch — exactly the [Bug] pi lane: switching models mid-session replays the full history and drops fold state — cross-model re-serialization churn defeats fold-reconcile anchors #2636/fix(dsh): model switch drops all folds — fold-reconcile #2396 detect-only cannot re-anchor rewritten tool-call ids → doom-probe 502 session death #2915 scenario this pass exists for) crashes.
    3. Fix evaluation. Your running-min/max fix is the correct root-cause fix: constant auxiliary space, two-argument comparisons, and the bracket semantics are preserved (the empty-claims case still yields no bracket, so no gap is ever bracketed without evidence). Content/role/length evidence gates are untouched.

    Severity: p1 availability. reconcileFoldCoverage has no try/catch, and its callers (prepare-openai.ts:310, prepare-responses.ts:352, prepare-anthropic.ts:352) don't wrap it — once triggered, the RangeError propagates out of prepare and the session fails every request.

    What I added to PR #6492 (commit bfbd9f99d0) — a same-mechanism sweep of src/ found one more unbounded site with no tracker:

    • src/incremental-lane.ts:433 — Math.max(...ptrs) in canonical-pointer upkeep spreads the session's full pointer list (one entry per settled canonical message). Its failure is silent: the RangeError is caught and only warn-logged, so the pointer list stops advancing and every later turn re-parses rows from the stale max pointer instead of the fresh tail (performance degradation, not a crash). Fixed with a two-argument reduce; regression test pins 150,000 pointers (fails with the RangeError warn pre-fix, passes post-fix, and asserts the upkeep reads rows after the highest pointer).
    • The third src/ site (src/cache-ledger.ts:2279) is [Bug][cache] Long-session cache reports crash when a size bucket exceeds the argument limit #6256's territory — left to that thread so the two PRs don't fix the same line.
    • Kernel sites (checklist, separate package, human-gated): kernel/src/refold.ts:43 (Math.min(...nums)) and kernel/src/recommend.ts:559-560 (Math.min(...batch.map(...))). Same mechanism, but a kernel change needs the kernel-change: declaration + owner approval — not included here.

    Verification on the new head bfbd9f99d0: 172/172 targeted tests pass (fold-reconcile / -large-history / -positional / -perf, issue2915 order-centric, issue3301 shape-flip, incremental-lane, issue5155, new issue6490 case); typecheck, check:unused-exports, check:test-import-graph all clean. CI: 30 checks, 0 failures so far (shards still running). PR labels set: bug, p1, scope/kernel.

    8问(中文,供人工评审)

    1. 是什么问题:超长会话(12.5万+条已验证位置指纹)在消息 ID 批量重铸时,对账把全部声明下标展开进 Math.min/Math.max 参数,超过 V8 参数展开上限抛 RangeError。
    2. 什么原因导致的:根本原因是无界数组被展开为函数参数(参数个数越界),不是对账算法慢;触发条件 = 长会话 + 大规模 ID 重铸(codec/协议切换,[Bug] pi lane: switching models mid-session replays the full history and drops fold state — cross-model re-serialization churn defeats fold-reconcile anchors #2636/fix(dsh): model switch drops all folds — fold-reconcile #2396 detect-only cannot re-anchor rewritten tool-call ids → doom-probe 502 session death #2915 场景)。
    3. 影响范围与严重程度:p1 可用性——对账路径无 try/catch,触发后会话每个请求都失败;触发面 = 12.5万+消息长会话且发生批量 ID 重铸。同机制另两处较轻:incremental-lane 指针维护(静默降级,指针游标停更、后续每轮从陈旧游标重解析,性能退化);cache-ledger 报表(仅打挂诊断报表,[Bug][cache] Long-session cache reports crash when a size bucket exceeds the argument limit #6256 跟踪)。
    4. 怎么修复的:head/tail 扫描中用运行最小/最大值替代数组展开(常量辅助空间、两参比较),括号语义完整保留(空集仍不触发括号);incremental-lane 用 reduce 替代 Math.max 展开。
    5. 是否有回归问题:审过既有行为——括号语义(空/非空)、内容/角色/长度证据门、resync/头尾偏移/重键控路径全部保持(172/172 定向测试覆盖 fold-reconcile 全家 + incremental-lane + The incremental lane re-renders the entire conversation history and synchronously flushes it to disk each turn; large co | 增量车道每轮把整段会话历史重新渲染并同步落盘,大对话每轮多花约100毫秒 #5155);无阈值/时序/输出格式漂移;唯一可见行为变化是超长会话对账从崩溃变为正常完成(即修复目的本身)。
    6. 是否破坏缓存:不涉及——不触碰缓存键/重试/增量游标语义;incremental-lane 修复反而恢复了长会话指针游标的推进。
    7. 是否改了设计方向:不涉及——纯实现层替换(展开→线性归约),设计不变。
    8. 是否引入了新的配置:不涉及。

    Verdict: PR #6492 is ready from my side — the reconciliation fix is verified against the issue's own repro, the PR now covers the complete same-mechanism set for src/ (reconciliation + incremental lane), #6256 covers the cache-ledger site, and the two kernel sites are tracked as checklist items above. Merge is yours per the rules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions