Skip to content

[PR] fix: a covered tool-result id held by another tool call is missing - #6919

Open
MohammadErfan-Jabbari wants to merge 1 commit into
ranxianglei:masterfrom
MohammadErfan-Jabbari:2026-11-16_displaced-tool-result-ids
Open

MohammadErfan-Jabbari wants to merge 1 commit into
ranxianglei:masterfrom
MohammadErfan-Jabbari:2026-11-16_displaced-tool-result-ids

Conversation

@MohammadErfan-Jabbari

Copy link
Copy Markdown
Contributor

Fixes #6916

Problem

Near the request-size limit, Claude Code replaces older screenshots with one placeholder text. A tool result's id hashes its tool name and text only (#3642), so screenshots that share a caption share one base id and are told apart by position. When the oldest ones become placeholder text, every later screenshot inherits a covered id, the fold hides those later screenshots, and the evicted ones go out unfolded. The drift line counts only the ids that vanished, so it understates the leak.

Fix (host side, no kernel change)

In src/fold-reconcile.ts:

  • planReconciliation: a covered id whose current message carries a different non-empty toolCallId than its anchor (anchors[id].t) counts as missing (displaced). It is claimed back only by the existing exact-toolCallId rung, never by similarity, and the message that wrongly held the id is a candidate for that rung only. A displaced id already claimed is skipped.
  • rewriteBlocks: a replacement target that is itself a claimed id may leave its slot in the same pass, so ids handed along a chain of duplicates survive.

Identity stays exact: the change only uses the protocol's own tool-call id, which bili already stores per folded tool result.

Both compression modes

Fold reconcile runs on the resent history in both modes, and the change acts only when a covered id's message carries a different tool-call id than its anchor. A history with unique or unshifted tool results takes the same path as before.

Tests

  • tests/issue6916-media-eviction-displaced-ids.test.ts (new) replays the shape scrubbed from the real session: 30 screenshot turns with one shared caption, a fold over screenshots 0 to 8, then the first 15 screenshots evicted to one placeholder. On master the fold ends up on screenshots 15 to 23; with the fix it stays on 0 to 8, and the next pass claims nothing. The negative case (duplicates that keep their tool-call id are not moved) passes on both.
  • With the fix, every test file that touches fold reconcile (33 files) plus verif-subset-guard passes: 349 pass, 2 skipped. npm run typecheck is clean.
  • Live: a 26-turn Claude Code session (Haiku) on the fix logged 0 drift lines and 0 rejected requests, the same as the baseline. That session had no eviction, so it shows only that the fix causes no regression.

Review tier

This changes message-identity logic in fold reconcile (KDD #11), so per §7.4 it stays with a human reviewer. No config, persistence-format, wire-shape or kernel change.

🤖 Generated with Claude Code

Claude Code replaces older screenshots with one placeholder text near the
request-size limit. Tool results that share a caption share a base id
(ranxianglei#3642 hashes tool name and text only), so later results inherit the
covered ordinals and the fold hides them instead of the evicted ones.

A covered id whose current message carries a different tool_use_id than
its anchor is now treated as missing and re-claimed by exact toolCallId;
the message holding it may be claimed only by that rung. rewriteBlocks
keeps a target that is itself a claimed id, so ids handed along a chain
of duplicates survive.

Fixes ranxianglei#6916

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ranxianglei ranxianglei changed the title fix: a covered tool-result id held by another tool call is missing [PR] fix: a covered tool-result id held by another tool call is missing Nov 16, 2026
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

查重: 不重复。 #6919 is the only PR addressing #6916. Nearest neighbors checked and distinct: #5360/#5196 (post-restart ref reuse — kernel ref-space mechanism, different failure domain), #5398 (retiring persistently-unmatched coverage — the opposite direction: coverage that never re-matches, vs. this PR's coverage that re-matched onto the wrong duplicate), #5836 (test-only repro of legacy coverage loss). No parallel fix in flight.

Review in progress — local verification so far:

  • New regression test tests/issue6916-media-eviction-displaced-ids.test.ts passes on the PR head (2/2) and fails on the PR base with the fold drifting onto the later screenshots exactly as Claude Code's screenshot eviction shifts duplicate tool-result ids, so a fold hides later screenshots and the evicted ones go out unfolded #6916 describes — genuine repro, not a tautology.
  • All 33 test files touching fold reconcile: 349 pass / 0 fail locally; tests/verif-subset-guard.test.ts green (fold-reconcile.ts is not in the verif guard list).
  • CI at time of check: 13 lanes green, 0 red, 6 still running — will confirm the final state.
  • Diff is clean: 2 files (src/fold-reconcile.ts +30/−8, new test +71), no lockfile/version/config/wire changes, commit message clean.

Full review with regression analysis follows shortly.

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

Review — fix: covered tool-result id held by another tool call is missing (#6916)

Verdict: mergeable (human merge — §7.4 identity tier, correctly self-assessed in the PR body). All completed CI lanes green (13/13, 0 failed); 6 guard lanes still queued at review time (mysql-contract, kernel-guard, unused-exports, config-surface-guard, lifecycle-ledger-guard, docs-sync) — the diff touches none of those domains, expected to pass. Branch is 18 commits behind master at review time; trial merge shows 0 conflicts and master has not touched src/fold-reconcile.ts.

What I verified

Behavior changes (disclosed, both intended)

  1. A covered tool result whose toolCallId no longer matches its anchor is now visible. Previously: id present → silent. Now: counted displaced → missing → one drift WARN per pass. This hits a tool re-run with identical content, or a host that re-mints toolCallId while keeping the msgid (a [Bug][Prime/Responses] provider switch rewrites composite tool IDs and reintroduces compressed history #2396 contract violation the system was previously blind to). No repair happens (the anchor's bucket is empty), no escalation, no reap — visibility only. The real [Bug][Prime/Responses] provider switch rewrites composite tool IDs and reintroduces compressed history #2396/公告:release v0.1.193 修复dsh 切模型导致上下文暴涨问题,修复fork问题,修复claude codex dsh等自动压缩导致会话破坏问题 . 另外修复几十个bug. 我本地场景有限,未必都测全,麻烦大家小场景先测试下是否有问题.任何问题及时反馈. #2821 shape (both re-minted) is unaffected (point 1 above).
  2. Pass 1 no longer overwrites a Pass 0 positional claim (new plan.claims.has(oldId) guard, src/fold-reconcile.ts:1109). Aligns Pass 1 with passes 1.5/2/3, which already had the guard. Observable only in a contrived corner (same-content occupant at the same index with a rewritten toolCallId, true original elsewhere with different content); the new ordering (position first) matches the 顺序为中心 rule (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. rewriteBlocks chain clause (src/fold-reconcile.ts:1685, || claims.has(target)): a replacement target that is itself a claimed id now leaves its slot in the same pass, so ids handed along a chain of duplicates survive. The old code could silently drop such a target when it was already present in the list, shrinking block coverage. I hand-traced both orderings — the clause is correct. One gap: no test pins this clause. The Claude Code's screenshot eviction shifts duplicate tool-result ids, so a fold hides later screenshots and the evicted ones go out unfolded #6916 test's claims are single-level (targets are placeholder ids, never sources), so the clause never fires in the suite. Constructing the pinning fixture (two-level displacement + a covered merge target) is non-trivial; recommend the author or a follow-up add it. Non-blocking: the clause is defensive and the primary fix is pinned.

Suggested labels (not applied — source PR is author-owned)

bug · p2 (usable, clearly wrong under specific conditions: Claude Code + many same-caption screenshot results + media eviction near the size limit) · claude-code · scope/kernel (fold reconcile = context-management core)


结构化八问

  1. 是什么问题:Claude Code 在请求体积接近上限时把旧截图替换成占位文本。工具结果 id 只按工具名+文本哈希(The intermediate message (core) is not protocol-agnostic: switching protocols/models causes identity churn; cross-protoc | 中间消息(core)没有做到协议无关:切协议/切模型制造身份 churn,补齐跨协议映射 #3642),同标题截图共享基础 id、靠序号区分;旧截图变占位后,后续截图继承了被折叠覆盖的 id → 折叠盖住的是后面的截图,被驱逐的内容反而未折叠外发,且 drift 行只统计消失的 id、低估泄漏。
  2. 什么原因导致的:planReconciliation 的 missing 判定只看 id 是否在场(byId),不看持有者是不是锚点对应的那个 tool call。id 在场但持有者的 toolCallId 与锚点不符(被同标题的后续截图顶替)时被当作"在场"→ 不修复,折叠持续盖错消息。
  3. 影响范围与严重程度:触发条件窄——做媒体驱逐的宿主(Claude Code)+ 大量同标题截图工具结果 + 已存在折叠。满足时:折叠摘要锚定到错误消息(后续截图被隐藏)、被驱逐内容未折叠外发(压缩承诺失效,请求持续贴近体积上限)。能用但有明显问题 → p2。
  4. 怎么修复的:判定层加一个精确判据——被覆盖 id 的当前消息携带与锚点不同的非空 toolCallId 时判为 missing(displaced),且只允许走既有 exact-toolCallId 档认领回真正的原件(占位消息保留原 tool_use_id),不走任何相似度;rewriteBlocks 放行"认领目标本身也是被认领 id"的链式移交。身份判定只用协议自带的 tool-call id,零模糊匹配,host 侧改动、无 kernel 变更。
  5. 是否有回归问题:审过 fold-reconcile 全部既有行为面——[Bug][Prime/Responses] provider switch rewrites composite tool IDs and reintroduces compressed history #2396/公告:release v0.1.193 修复dsh 切模型导致上下文暴涨问题,修复fork问题,修复claude codex dsh等自动压缩导致会话破坏问题 . 另外修复几十个bug. 我本地场景有限,未必都测全,麻烦大家小场景先测试下是否有问题.任何问题及时反馈. #2821 provider 切换(id 与 toolCallId 双重铸)走既有 positional/twin 档,不受影响;[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 N→1 档(Pass 3,目标为 assistant 消息,无 toolCallId,不可能 displaced)不受影响;覆盖账本按 byId 在场计数 → 不触发 [Bug][proxy] unframed host-side history deletion leaves zombie fold blocks rendering carriers forever — one carrier flaps in/out every turn (persistent prefix-cache churn) #2695 僵尸收割;升级路径需 !hardDirectMajority → 不升级。两处有意行为变更已在上方披露(同内容重跑/宿主重铸 toolCallId 现在每轮出一条 drift WARN,原先静默;Pass 1 不再覆盖 Pass 0 位置认领,与 1.5/2/3 档对齐)。33 个 fold-reconcile 测试文件 349 全绿、typecheck 干净、CI 已完成车道全绿。
  6. 是否破坏缓存:不涉及。不改缓存键/前缀/重试策略;折叠覆盖集合的变化只决定出站历史中哪些消息由摘要代表,被覆盖消息本来就不逐字外发,前缀缓存字节稳定性不受影响。
  7. 是否改了设计方向:不涉及。仍按 KDD feat: self-update (auto + manual) #11 三层裁决(msgid > 顺序 > hash),hash 仍是逐格硬门、无全局否决;只是把"在场"判据从"id 存在"收紧为"id 存在且持有者 toolCallId 与锚点一致"。
  8. 是否引入了新的配置:不涉及。无新 env/config/默认值。

判定:可合并(待 6 个排队中的 guard 车道转绿,预期通过;按 §7.4 身份逻辑档由人工合并)。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

CI update: all 30 lanes now completed — 18 success, 12 skipped (gated e2e), 0 failed. The 6 previously-queued guard lanes (mysql-contract, kernel-guard, unused-exports, config-surface-guard, lifecycle-ledger-guard, docs-sync) all passed. Nothing outstanding on the review side; ready for a human merge whenever.

This branch has not been deployed

No deployments
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.

Claude Code's screenshot eviction shifts duplicate tool-result ids, so a fold hides later screenshots and the evicted ones go out unfolded

2 participants