Skip to content

[PR] fix: recover retained compression blocks against fork replay - #5970

Merged
ranxianglei merged 2 commits into
ranxianglei:masterfrom
zouzh22:2026-11-08_fork-retained-folds
Nov 9, 2026
Merged

ranxianglei merged 2 commits into
ranxianglei:masterfrom
zouzh22:2026-11-08_fork-retained-folds

Conversation

@zouzh22

@zouzh22 zouzh22 commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Fixes #5968

A short source request can deactivate retained compression blocks even though the complete original span returns in a fork. Ordinary replay through kernel syncBlocks reactivates that span, but planForkAdoption skips every inactive source block before checking the child, producing refs-only inheritance.

Judge retained blocks against the child's complete id set. Preserve explicit expansion and consumed-tier exclusions, activate independently copied eligible blocks, and carry tier descendants as inactive records. No source-session mutation, kernel change, config field, schema migration or DSH parentSession change.

Validation

  • Before the fix, the new short-view planning regression and retained-tier regression fail; after it they pass.
  • Rebased independently onto upstream 82e2d53. All 49 selected fork/resume/adoption/CCR/DSH-protocol regressions pass on this head.
  • Coverage includes the new real compression/original-content retrieval fixture whose source is first deactivated by syncBlocks.
  • Typecheck, build and diff whitespace checks pass on this rebased head.
  • On this rebased head, a real DSH headless process using isolated DSH_HOME and a fake upstream passed bootstrap, request interception, status and compression-tool smoke checks: 2 passed; the external Docker attach case was skipped by its existing gate.
  • The combined local hotfix archive was installed successfully through DSH's own CLI into a separate temporary profile. This smoke verifies artifact loadability; it is not proof of a real production fork reply.

Review scope

Create this PR as DRAFT initially. This changes fork block eligibility and needs human review. Synthetic regression proves this specific planner gap; neither the issue nor PR claims it is the sole cause of every reported fork overflow. Actual recovery of the original failing production branch has not been verified. Existing branch state is not migrated by this patch.

Source data remains independent. Explicitly expanded blocks and incomplete/cross-boundary spans are not reactivated. No raw user sessions, logs, paths or credentials are part of the submission.

Related overflow-format parsing fix is #5967 / #5969; the branches are independently reviewable. After one lands, update the other's nearby bilingual documentation hunk as needed.

@ranxianglei ranxianglei changed the title fix: recover retained compression blocks against fork replay [PR] fix: recover retained compression blocks against fork replay Nov 8, 2026
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

查重: 不重复。Searched open+closed mirror issues/PRs and GitHub for the same mechanism (planForkAdoption eligibility vs kernel syncBlocks resurrection). Related-but-distinct threads: #5964 (DSH opaque fork snapshots adopted by raw ids — different mechanism) and #5971 (LiteLLM overflow-count parsing — the sibling overflow-format fix your body references as #5967/#5969). No other PR targets this thread.

标签: bug + p1 + scope/kernel — defect fix; fork inheritance losing retained folds is the "fork 继承被放弃" class (owner revision 2026-10-19 category ① → p1); the mechanism lives in host-side session core logic and is client-agnostic — the DSH lane has its own copy path and this change does not touch it, so no client tag.

Review verdict

I read the diff against current master and verified it against the kernel's own resurrection rule. The fix is correct, minimal, well-tested, and honest about its scope. Two pre-merge conditions remain: a fresh full-matrix green on a rebased head, and human review per your own draft intent.

① Issue direction — root cause, not symptom

Issue #5968's diagnosis holds and the patch targets the producer, not a downstream symptom. Cross-checked against kernel/src/sync.ts:141-172: syncBlocks deactivates three distinct classes — (a) consumed-by-tier blocks, (b) explicitly expanded blocks, (c) blocks merely absent from the last short view — and resurrects exactly class (c) when the span returns on the next full resend. The old planner gated roots on active, collapsing all three into "ineligible". The new eligibility !expanded && !consumed reproduces the kernel's distinction precisely, and adoption keeps the stricter every-id-present criterion (correct for forks: the child must hold the complete span before a fold can be trusted there).

② Regression inventory (existing behaviors on touched paths)

  • Explicit expansion: still excluded (expanded checked first). The only host stamp site is src/plugin.ts:1616 (DSH snapshot crossing) — behavior unchanged.
  • Consumed tiers: excluded; descendants are now copied as INACTIVE records instead of inheriting stale flags — safer than before (no false-active leaves).
  • Restored-inline blocks (markBlockRestoredInline, decompress.ts): keep active=true → unchanged.
  • Orphan-GC'd blocks (src/orphan-gc.ts:43-68, deactivated after 3 turns AND blockContents deleted): now re-adoptable without content — but the parent's own syncBlocks resurrection already has this exact property today, so this is parity with existing behavior, not a new exposure. Worth knowing, not a blocker.
  • All four consumers get the rule consistently: handle.ts:1704 maybeAdoptForkBlocks, handle.ts:1836/1964 maybeAdoptDerivedFork, handle.ts:1912 maybeAdoptResume, server.ts:583 reconcileDerivedLineage boot sweep. DSH lane (plugin.ts:1609-1616) does not call planForkAdoption — your "no DSH parentSession change" claim holds.
  • One honest drift: the straddled counter now also counts eligible-but-partially-present blocks (previously only active ones). Comment updated accordingly; observability-only.

③ Code quality

Meets the bar — no rework needed. Comments explain why (short-view vs consumed), naming is clear, no dead code, en+zh doc section added in the right place. One micro-nit I am NOT asking you to fix: consumed is built even when includeBlocks is false (one wasted flatMap over a small array per planning call) — negligible, and your pending rebase supersedes any nit-push anyway.

④ Test quality

Real teeth, both directions (#3617 discipline): the short-view fixture uses a genuine syncBlocks deactivation (not a hand-set flag), asserts no source mutation via deepEqual, independent ownership, and an exclusion matrix covering expanded / partial-span / unrelated / blocks-disabled / tier-descendant; the CCR e2e is parameterized over shortView∈{false,true} with a JSON stateBefore compare. I proved the bite locally: swapping origin/master's src/fork-adoption.ts into the PR branch makes exactly the 3 new tests fail and nothing else (9 pass / 3 fail); the PR head passes 12/12 on both files; typecheck clean.

⑤ CI status (live-verified just before this reply)

⑥ Scope honesty

Your review-scope caveats are appropriate and I concur: the synthetic regression proves this specific planner gap; neither issue nor PR claims it is the sole cause of every reported fork overflow; recovery of the original failing production branch is not verified; existing branch state is not migrated by this patch. Behavior-change disclosure is present (docs, both languages). No config surface, no kernel/ change, no schema migration — confirmed against the diff.

结构化八问(中文,供人工评审)

  1. 是什么问题:源会话最后一轮只发了短视图时,kernel 的 syncBlocks 会把「内容还在、只是这轮没出现」的压缩块标记为 inactive;fork 收养(planForkAdoption)却把 inactive 一律跳过,导致子会话丢掉本可继承的折叠记录(refs-only 继承),上下文在 fork 后重新膨胀甚至溢出。
  2. 什么原因导致的:planForkAdoption 用单一的 active 标志做资格判定,混淆了三种不同的失活原因——被上层折叠消费(consumed)、宿主显式展开(expanded)、仅因短视图缺席(view-deactivated)。只有第三种应当像父会话自己的 syncBlocks 复活逻辑一样允许恢复;修法是让收养资格与 kernel 复活条件同构。
  3. 影响范围与严重程度:任何走匿名 fork 收养路径(pluginMode 宿主,含 DSH 无 parentSession 场景)且源会话末轮为短视图的 fork。p1——折叠继承被放弃,子会话失去已完成的压缩工作,是生产报告的 fork 溢出场景之一(PR 自己也声明非唯一原因)。
  4. 怎么修复的:资格判定改为 !expanded && !consumed(与 kernel/src/sync.ts 复活规则对齐);闭包拷贝时按「子会话消息是否完整覆盖该块全部 id」逐块决定 active 标志,tier 后代强制 inactive;采纳根块后置 active=true。不改源会话、不动 kernel、不加配置、无 schema 迁移。
  5. 是否有回归问题:逐项审过——显式展开仍排除;消费层排除且后代改为强制 inactive(比继承旧标志更安全);restored-inline 不受影响(本就保持 active);孤儿 GC 块(内容已被删)现在可再收养,与父会话自身 syncBlocks 复活的既有行为对等,非新暴露面;四个消费点统一获得新规则;唯一口径漂移:straddled 计数器变宽(仅观测面,注释已同步更新)。
  6. 是否破坏缓存:不涉及——不改出站字节、不改前缀渲染、不动 cache ref 机制;只改 fork 时刻的块元数据继承。
  7. 是否改了设计方向:不涉及——把收养判定对齐到既有的 kernel 复活语义,不是新机制面。
  8. 是否引入了新的配置:无。

判定:代码与测试质量达标(外部提交从严清单全项通过,无需对齐重构),方向正确,修法打到根因,测试有牙且双向。可进入人工评审。合并前置条件两条:(a) rebase 到当前 master(848f59b)后拿到一次完整矩阵绿——当前 head 有 9 个 shard 被触发风暴取消,尚无全量绿判定;(b) 按 §7.4,fork 块资格属 session-binding 域,保持 draft→人工合并,我不代合。

…-carry regressions

Ported from parallel PR ranxianglei#5979 (same fix for ranxianglei#5968; being consolidated into this PR): three unit cases not covered by this branch - applyForkAdoption deep-copy isolation (mutating the adopted child never leaks into the source session), the straddled counter for partial spans while the block is transiently inactive in the source, and covered-ref carry into the child numbering.
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

审核协调说明(与平行 PR #5979 的合并处理):

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

CI 状态更新(18:29Z 直读核实):新 head b44e4711d5fa 全部检查完成——37 success / 13 skipped / 0 failed。合并前置条件已齐:undraft → owner 人工合并即可(本 PR body 带 Fixes #5968,squash 后会自动关 issue)。

@ranxianglei
ranxianglei marked this pull request as ready for review November 9, 2026 01:31
@ranxianglei
ranxianglei merged commit 2405f46 into ranxianglei:master Nov 9, 2026
50 checks passed
Louie0806 added a commit to Louie0806/billion-context that referenced this pull request Nov 9, 2026
…anxianglei#5970 retained folds, ranxianglei#5978 anthropic egress tail, ranxianglei#5981 truncated compress receipt

Advances the base from 33d4951 to 7d18b7a (15 commits, 35 files). Four
files overlap with this lane: src/plugin.ts, src/server/relay.ts and the two
generated docs. All four auto-merged; upstream added `noteTruncatedUpstream`
calls inside the plugin pipelines it already touches, while the lane's strip
gates live elsewhere in the same files.

Notable upstream commits adopted:
 - 0f93793 feat(pi): pi.commands — configurable slash-command registration surface
 - 4f80702 fix: recover retained compression blocks against fork replay
 - 8c98898 fix(anthropic): never send an outbound body that ends on an assistant turn
 - adc863a fix: tell the model to re-issue a compress whose args were cut in transit
 - 38e6b07 fix: bound the lost-in-transit re-issue advice with the session breaker
 - d1b2d8f fix: 会话历史按真实维度拦死 — count gate + 32MiB ingest cost band
 - fa447f9 fix: exempt image-bearing bodies from the ingest cost band
 - 33bec44 fix(launcher): force-takeover the wedged same-lane proxy holding the canonical port
 - 2826c51 fix(launcher): field-tune wedged-takeover timings + quiet win32 ESRCH alarm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working p1 scope/kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Fork adoption drops retained folds deactivated by the source's last short view

2 participants