Skip to content

[Bug] compress reports 'no compressible ranges remain' while mid-history spans sit outside every block #4331

Closed

Description

@sorasoras

Summary

compress (and the acp_status nudge text) can report "No compressible ranges remain — the context is already at its minimum" while large contiguous mid-history spans sit outside every active block. Those messages keep going to the upstream raw, and nothing in the tool surfaces them.

Observed on 0.1.204 (c87185a0) in a live ZCode session, and earlier at a larger scale on 0.1.197.

Environment

  • billion-context 0.1.204, commit c87185a0 (Windows 10.0.26200, node:sqlite, storage.unified=full)
  • lane: ZCode (pluginAgent: zcode), Anthropic wire
  • Session A (0.1.204): session_0f487119cdd1fbc6aaa15d9d59e892d9
  • Session B (0.1.197, for scale): 79900b32-a7bb-400c-8fcc-ebd7d281dd6e

Evidence — session A (0.1.204)

  • 864 messages, 13 active blocks, highest covered ref m01046.
  • 138 mid-history refs are in no active block: 262,160 bytes ≈ 65K tokens, ≈16% of the 404,342-token live context.
  • They form 23 runs; the largest is m00312–m00411 — 100 consecutive messages (50 tool-call / 50 tool-result pairs, 201,159 bytes). Next: m00416–m00429 (14 msgs), then 21 single/short gaps.
  • 30 of the 138 are compression-machinery messages (compress calls/results), 141,264 bytes.
  • After folding around them, compress returned, three times in a row:
    No compressible ranges remain — the context is already at its minimum; continue the task without compressing.

Evidence — session B (0.1.197, for scale)

  • 161 mid-history messages (489,298 bytes ≈ 122K tokens, ≈20% of a 596,267-token context) plus a 50-message tail were outside every active block.
  • Composition: 91 assistant reasoning, 21 tool-result, 20 tool-call (mostly mcp__bili__compress), 19 user, 10 assistant text.

This is not the coverageLostFolds accounting (9 folds, 33.9M tokens) — that counts refs the client stopped resending. These refs are still in the session and still raw on the wire.

Mechanism (hypothesis)

Coverage is tracked per block (metadata.foldCoverageByBlock, {p,r,t,e,z}) and reconciled only against that block's own range. Nothing compares the union of active-block ranges with the session's ref set, so:

  • disjoint ranges nominated by an agent leave permanent holes;
  • a fold that begins after an uncovered run never revisits it;
  • the "no compressible ranges" verdict comes from the fold scanner's own view, not from a global coverage audit.

state.hiddenOrphanRefs exists but is empty in both sessions.

Repro

-- active block ranges; T2 blocks have NULL refs, follow payload_json.directBlockIds
SELECT block_id, start_ref, end_ref, tier, active
  FROM blocks WHERE session_id='<sid>' AND active=1 ORDER BY ord;

Diff those ranges against messages.ref_num. Session A returns m00312–m00411 as the largest gap. Summing p over active T1 blocks in metadata.foldCoverageByBlock and adding the gap count reproduces the same accounting.

Proposed fix (any one, increasing scope)

  1. Report it — add an "uncovered history" section to acp_status and the nudge: contiguous runs of refs in no active block, older than preserveRecentMessages, with ref span and a token estimate. Cheap, no behaviour change.
  2. Allow a sweep — compress with no ranges (or sweep: true) folds the largest uncovered run(s), respecting the same protected window and min/max range limits.
  3. Absorb at fold boundaries — when a fold resolves a range, extend its start/end across contiguous uncovered messages older than the protected window, capped by a token budget.

Notes

  • Checked against master 94f75cc: the coverage bookkeeping lives in the fold path; nothing enumerates unowned spans.
  • This session reproduces reliably, so I can test a patch or send a PR for option 1 if that shape is preferred.

Activity

  1. ranxianglei commented on Oct 22, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

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

    查重: 不重复。 Closest candidate is #4227 ("viable ranges" vs "no ranges remain" contradiction) — different mechanism: its false stop-report came from a reporting-layer baseline mismatch (the preflight internal lane's RewriteCtx lacked lastNudge, so postCompressTail fell to live recompute against a usage-level baseline and mis-claimed "no pressure" while 102 viable ranges existed in the same turn); fixed by PR #4229. In #4331 the spans are genuinely outside every active block AND outside the prepare-time offer, so even a correctly-wired receipt could not list them. Related-but-distinct: #4307 (stuck compress calls never reclaimed), #4289/#4293 (failed exchanges exempt from folding), #4240 (atomic batch rejection).

    标签: bug, zcode, scope/kernel, p2 — compression-tooling-surface defect on the ZCode lane; p2 because sessions stay usable and there's a partial workaround (acp_status(scope:"uncompressed") still shows those rows as visible mass) — but the terminal verdict is wrong and the leak is invisible by default.

    Verification so far (master aa198fe61; between your c87185a0/v0.1.204 and master only #4252's diagnostic wording touched these paths):

    1. Your architectural hypothesis is confirmed in code: the stop verdict derives purely from pre-fold-offer exhaustion (postCompressTail, src/stream.ts:546-609 — remaining = prepare-time offer minus submitted overlaps; empty ⇒ "already at its minimum"). Nothing anywhere — host or kernel — compares the union of active-block coverage against the session's ref set. The default acp_status overview doesn't enumerate uncovered runs either.
    2. I reproduced the offer path on master with synthetic sessions (fold around a 99-message mid-history hole; plus a variant where fold boundaries split a turn): the kernel DOES advertise mid-history holes in both shapes — including turn-fragment residue merged into adjacent batches. So the scanner isn't blind to mid-history holes per se; something session-specific kept yours off every offer (candidates: dead-ref window exclusion The compress failure receipt is self-contradictory: the same message first declares the ref permanently DEAD, then lists the range containing that DEAD ref as the "current compressible range." | compress 失败回执自相矛盾:同一条消息先宣告 ref 永久 DEAD,再把含该 DEAD ref 的区间列为「当前可压缩范围」 #3192/kernel: buildCompressibleRanges 应围绕 DEAD ref 切分区间,而不是让 DEAD ref 落进已宣告 span 的内部 #3205, [Bug][preflight] range selector re-nominates a fully-folded span every turn — permanent "no new compressible messages" rejection loop + nudge churn #2638 structural-dead span memory, or id-set-vs-ref-window divergence). The reporting feature is exactly the diagnostic that pins which one from real traffic.
    3. One honesty gap independent of (2): even in clean sessions, "the context is already at its minimum" is an unverifiable global claim — the verdict can only know "nothing left in this call's offer"; sub-viable (<200 tok/run) and sub-minChar residue are structurally invisible to it.

    Plan (your option 1 + honest verdict; host-side only, no kernel change):

    • Shared audit helper: contiguous runs of messages outside every active block, tokens>0, older than the protected recent window. Window membership is computed empirically as the diff between the normal-config and relaxed-config kernel offers (the same relaxation preflight already uses, src/preflight.ts:1381) rather than re-implementing the zone rules host-side.
    • acp_status: additive UNCOVERED HISTORY section (ref span, msg count, token estimate per run) when non-trivial. No behaviour change.
    • Compress receipt: when the offer is exhausted but the audit finds significant uncovered runs, the "minimum" claim is replaced by an honest text listing the top runs. The verbatim contract string stays byte-stable for genuinely-drained sessions (existing tests pin it). This is the one behavior change — old: unconditional minimum claim on offer exhaustion; new: claim only when the audit verifies it — disclosed in the PR.
    • Options 2/3 (sweep / absorb-at-fold-boundaries) change behavior (autonomous folding of un-nominated ranges) — I'm leaving those as decision items for you rather than implementing them unilaterally.
    • The nudge text itself is kernel-owned prompt territory; receipts + acp_status cover the surface without a kernel change this pass.

    Implementing now; PR will reference this issue. If you want different wording for the section, say so before I ship it.

  2. added
    bugSomething isn't working
    zcode改动范围:内核之外的主机侧接线(src/agent 适配器、server 路由、注入拦截)/范围兜底/客户端标签
    on Oct 22, 2026
  3. ranxianglei commented on Oct 22, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

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

    **PR: #4340 #4331)。按你提的 option 1(报告)落地,外加把「minimum」判定改成可验证的;option 2/3(sweep/absorb)是行为变更,留给你拍板,没动。

    1. 是什么问题:compress 回执(acp_status nudge 同源)在「本轮 offer 全部折完」时就宣告「上下文已到最小值」,但此时中段历史里可能还有大块消息不在任何活跃块里、仍逐字发往上游——你的 session A 就是 138 个 refs(~65K tok,≈16% 上下文)完全裸露,而回执连说三次「already at its minimum」。

    2. 什么原因导致的:停止信号只来自 offer 耗尽(postCompressTail 的 #2404 预折叠基线纪律),整条链路没有任何一处做全局覆盖审计——从不比较「活跃块范围并集 vs 会话 ref 集」。我在 master 上复现确认:内核 recommend 路径其实能找到这类洞(干净边界和拆轮两种形状都正常上报到 nudge.compressibleRanges),所以生产假停还叠加了会话内因素(死 ref 窗口、#2638 结构死区间记忆、offer 批次整体移除等);但无论哪种因素,「minimum」这句话本身都是拿局部观察断言全局事实——这是结构性缺陷,独立于具体触发因素成立。

    3. 影响范围与严重程度:所有 plugin/proxy 车道,只要折叠后在保护窗口之外留下未覆盖质量(不相交的提名范围、拆轮残留、死 ref 切段)就会中招。p2:能用、无数据丢失、无缓存投毒,但回执误导 + 裸 token 持续计费/占压,且此前任何回执面都发现不了这个泄漏。

    4. 怎么修复的:纯 host 侧、不动 kernel。新增 src/uncovered.ts 审计:枚举所有活跃块覆盖之外的连续 run,用「两次 processTurn 过克隆状态(正常配置 vs preserve-0/0 宽松配置)」的经验差集判定保护窗隐藏(直接复用内核自己的 zone 规则,不复制实现,规则演进时自维护);被当前 offer 覆盖的跳过;<200 tok(VIABLE_RANGE_MIN_TOKENS)的保持沉默;任何异常降级为「无」,绝不破坏回执。两个面:① acp_status 默认视图新增 UNCOVERED HISTORY 段落(top-5 run + 计数,与上方实时 ranges 列表互斥过滤);② postCompressTail 在宣告 minimum 前先跑审计——有洞就报诚实文案+点名 span,没有才发原 #1387 契约字符串(逐字保留)。

    5. 是否有回归问题:逐项审过触碰路径的既有行为:#2404 offer 钉选(子集折叠仍继续广告剩余;nudge 时受保护的 range 仍不会作为 offer 泄漏——更新后的钉住测试改断言新形态)、#1387 逐字契约(真排空会话负向测试保字节稳定)、tier 蒸馏优先级(有 tier 时既不发停也不发洞报告)、#2029 状态基线溯源(审计自己的两次调用同样喂 provenance 基线)、#847 失败守卫的 offer 门控不变、viable 地板不变。typecheck 干净 + 定向 43 测试全绿(9 新门禁 + 4 个更新的钉住文件);全量以 CI 为准。

    6. 是否破坏缓存:不涉及——不改任何出站 wire/前缀/摘要内容,只加诊断文本(回执尾部 + status 输出),折叠行为零变更。

    7. 是否改了设计方向:不转向。加了一个 advisory 审计模块 + 两个报告面。行为变更披露(旧→新):① 旧 = offer 耗尽即无条件宣告 minimum;新 = 仅当全局审计验证通过才宣告,否则点名未覆盖 run。② 旧 = sub-gate 残留(低于 minCompressRange 的孤立 run)在所有面上不可见;新 = acp_status 诊断里可见(仍永不被 offer/折叠,#847 门控纪律保留)。已知遗留(未修,单独观察项):receipt 的 remaining 计算在任一提交 span 重叠整个 offer 批次时会整批移除,部分折叠的合并批次会少报(安全方向);若证明用户可见再单开。

    8. 是否引入新配置:无。不加 env/config/CLI 字段,地板复用 VIABLE_RANGE_MIN_TOKENS。

    请 review PR #4340;option 2(sweep)/3(fold 边界吸收)若要做,建议在你确认本 PR 的观测面够用之后再单开讨论。

  4. sorasoras commented on Oct 22, 2026

    @sorasoras
    ContributorAuthor

    Coordinating with #4340 (ework): that PR implements option 1 and supersedes my #4339, which I am closing.

    Where #4340 is stronger than my version:

    • Zone exclusion comes from a normal-vs-preserve-0 offer diff on cloned state, instead of re-implementing the kernel's #2886 / neverPreserveRecentTools rules host-side.
    • It uses kernel coveredMessageIds / refForRaw instead of a hand-rolled coverage walk, and it subtracts the live offer so the audit does not duplicate the Compressible-ranges list.
    • It changes the verdict itself ("The context is not at its minimum") instead of appending a note. That is the more honest fix; keeping the verbatim string only for genuinely drained sessions is the right split.

    Two review notes from my implementation:

    1. Coverage must expand tier-2 parents. In the CED-T session, b249 (tier 2) has children b246-b248; the parent's stored effective list is empty while its children cover the spans. If coveredMessageIds(state) already expands children this is a non-issue, but it deserves an explicit test either way (my [PR] feat: audit uncovered history behind the "no ranges remain" verdict (#4331) #4339 had directBlockIds recursion because the DB-side walk showed the parent as empty).

    2. Sub-threshold residue. My version gated the note at >= 10k uncovered tokens to keep the #1387 / pi #521 rule ("declined leftovers must not re-nag"). [PR] fix(#4331): report uncovered mid-history spans instead of claiming "at its minimum" #4340 updates that pin instead, reinterpreting it as "never leaks AS AN OFFER". That is defensible, but it is a behavior change for any session with small gaps, so it deserves a maintainer ack rather than riding along with the bug fix.

    Cost note: the audit runs two extra kernel processTurn passes on a structuredClone per receipt (exhaustion path only) and per acp_status. Probably fine, since acp_status is explicit and receipts happen once per fold, but it is 2x O(session) on a hot path in long sessions.

    The measurements stand regardless of which implementation lands: 138 refs / ~65k tok / 16% of a 404k context (864 msgs) and 161 refs / ~122k tok / 20% of 596k (12k-ref session); largest run m00312-m00411 = 100 msgs (50 tool-call/result pairs); ~30 of the 138 are compression-turn machinery messages.

    One CI note: #4340's red checks (2 failures) are the same master-side issues as #4339 — #4334 (tests/storage-durability.test.ts missing from scripts/live-files.mjs) and #4330 (kernel/dist never built in the mysql-contract lane) — not its diff.

  5. added a commit that references this issue on Oct 22, 2026
  6. ranxianglei commented on Oct 22, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

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

    Thanks for coordinating — all three review notes are addressed in a new commit on the PR branch (dda94a452, pushed).

    1. Tier-2 coverage — verified independently: not affected in this implementation; explicit test added anyway.
    Checked the state model end-to-end: coveredMessageIds is the union of ACTIVE blocks' effectiveMessageIds with no child recursion (kernel/src/state.ts:57-64) — and that is safe because every block-creation path unions the consumed children's effective ids into the new parent (kernel/src/unit-projection.ts:178-183) and deactivates the children (kernel/src/compress.ts:1578-1581); host hydration preserves the whole state JSON (src/persist.ts:2781). A T2/T3 parent therefore carries its full distilled span in the state model. Your "parent's stored list is empty" observation is what a DB-side SQL walk shows (payload_json doesn't carry that property) — which is exactly why #4339 needed directBlockIds recursion; the state-model walk does not. New regression test P4 pins it regardless: fold three adjacent T1 blocks, distill into one T2 through the real host path (same bN-range shape as src/preflight.ts:1819), then assert parent active + children deactivated + covered ids span the distilled region + the audit reports nothing inside it.

    2. Sub-threshold nagging — accepted, floor added.
    The receipt verdict now fires only when TOTAL uncovered mass ≥ 10K tokens (UNCOVERED_RECEIPT_FLOOR_TOKENS, receipt-only). Below the floor the legacy #1387 wording fires byte-identical to master — so I reverted tests/compress-success-tail.test.ts fully to master bytes (zero diff vs master), and its two sub-floor residue fixtures (#2404-leak ≈3.75K tok, #1387-shouldInject ≈5K tok) now pin the floor directly. The acp_status section stays ungated deliberately: an explicit inspection surface is not a nag surface, and option 1 specified no size gate there. The 10K total is a product value — flagging for owner ack (it matches your independent pick).

    3. Cost — halved on acp_status, kept where it matters.
    uncoveredHistoryRuns now accepts optional normalRanges: a caller that already ran the normal-config offer pass may pass it in (array = trust-and-reuse, even empty; undefined = self-run). acp_status passes its live Compressible-ranges list → net +1 processTurn instead of +2 there. The receipt path keeps both passes because at stop time the pre-fold offer is stale by definition (the fresh post-fold offer is exactly what the audit classifies against), but it runs only on exhaustion folds. The structuredClone stays: the nudge-inject node stamps cadence low-water marks, so running the live state through twice would corrupt them.

    4. CI note — confirmed, plus one that was mine.
    Check-run data: the mysql-contract failure matches #4330 (master-side, kernel/dist never built in that lane). The second red was actually my diff — unused-exports flagged the two newly exported interfaces; fixed by unexporting them (the small 7981fee05 commit already on the branch; gate is clean locally now). Master's own test lanes are also red at base (windows-latest 22 shards 1&2, ubuntu 24 shard 1, ubuntu 22 shard 3), consistent with #4334-class issues.

    Local verification on the pushed tree: typecheck clean, unused-exports gate clean, 42/42 across the five touched suites (incl. the new P4). Options 2/3 (sweep / absorb-at-boundary) remain open owner decisions — this PR is option 1 + honest verdict only. Ready for merge verdict once CI confirms.

  7. pkuqiuning commented on Oct 23, 2026

    @pkuqiuning

    Second data point on the same debris class, from two sessions on two lanes — offered as input to the option 2 / 3 decision, not as a new defect.

    Environment: opencode lane and omp lane through the proxy, OpenAI-compatible wire, build 0.1.204 (plus a brief pass on the #4354 master build).

    session compress exchanges debris no fold reaches cost
    A (opencode lane) 52 calls + 52 receipts = 104 store messages, all ref='BLOCKED' call text 228K characters, 295K including receipts (store measure) ≈30% of the outbound request, on a 222K-token request
    B (omp lane) 111 calls (client count; 109 in store) ≈0.4M characters of call arguments + receipts in store ~29% of the request surface is the compress category (wire measure)

    Measurement basis, per row: A's counts and sizes from the proxy's session store; A's tokens from [acp-usage] lines — input=210774 cached=0 (cache hit 0%) before the reclamation below, input=130168 cached=130048 (cache hit 100%) after; B's call count from the client session file, share from the outbound dump. Coverage side, before the write below: none of A's 104 ref-BLOCKED compress messages appears in any active block's covered set (0/104 in the dumps we kept); the reclamation adds one block — ours; the kernel's own fold count did not change.

    On builds: the age exemption exists only on the #4354 master build, where the newest three exchanges stay protected (COMPRESS_EXCHANGE_KEEP_RECENT = 3); on 0.1.204 the protection has no age dimension at all, so every receipt is debris from the start.

    This is not an edge case: the compress exchanges are the largest single reclaimable category we can identify on our side, in every session that has run long enough to accumulate them — the tool's own receipts are the debris.

    Two properties make it a scope question rather than a diagnostic:

    1. It grows with the number of successful compress calls, not with the volume of content involved — and nothing in the current picker path removes it, so it accumulates for the lifetime of the session. The one exception we saw: a single span we named explicitly absorbed 24 exchanges at once.
    2. A verifiable verdict still leaves the user without an action. [PR] fix(#4331): report uncovered mid-history spans instead of claiming "at its minimum" #4340's verifiable-verdict split is the right first step — but visible mass is not an offerable range, so the user cannot act on what they are being shown.

    What we did instead: on a disposable copy, we wrote the proxy's own state store by hand — a synthetic block for the aged exchanges in the engine's block format, then a lane restart. As an equivalence check of the mechanism it moved session A's input from 210,774 back to 130,168, cached= from 0% to 100%, and the outbound message count from 272 to 165. That is not a supported path, and not something we want to depend on.

    Note on the two-sided observation: our own attempt was the absorbing one. The rejecting half — ranges that straddle refs recorded as DEAD — is described in the #4354 thread by another reporter, not something we reproduced; in neither of our two attempts did the tool nominate those exchanges by itself.

    Both parked options would reclaim this mass if they run through the fold filter — absorb-at-boundaries does it across the span, while a sweep would need the aged set to reach the picker gates too (the same two gates the #4354 follow-up reports) — so the open question is whether either is wanted.

    One structural link: the same asymmetry appears on the recommend side, logged as F-B in the #4354 review — the aged exemption reaches the apply path but not recommend (and by extension absorb/ccr). F-B is a pending decision in that review with no durable item of its own, so if the lean toward declaring it deliberate stands, the decision has no surface to be revisited on.

    Two asks, both within decisions already on the table:

    1. When you weigh options 2/3, please count this token cost — on our side it is roughly a third of every request on the worst session.
    2. If the F-B lean toward "deliberate conservatism" stands, give it an open tracking item (or fold it into option 2/3) — and if the machinery stays as-is, a documented user-side recovery path for aged exchanges would answer this observation.
  8. added 2 commits that reference this issue on Oct 23, 2026
  9. ranxianglei commented on Oct 23, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

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

    Thanks for the second data point — it pins down the population my #4331 audit can't see. Everything checkable was checked against current master (970bd4d40, which includes today's #4354 merge):

    Verified claims

    Your asks

    1. Cost counted. All four measurements (both your sessions, [Bug] compress reports 'no compressible ranges remain' while mid-history spans sit outside every block #4331 session A's 30 machinery refs inside its 16%, and floor 17's pi-session −15% round) are recorded in the new tracking issue below, including your reclamation A/B (210,774→130,168 input, cache 0%→100%) as proof the mass is fully reclaimable once coverage attaches. This materially strengthens the case against leaving the mechanism as-is.
    2. Tracking item filed: #4398 — "Aged compress receipts are foldable but unselectable by any tool", labelled bug · p1 · scope/kernel · opencode · pi · omp (p1 per the cache-leak criterion: grows monotonically, unreclaimable by any tool, billed every round). It carries the five-gate checklist (M1 ref layer, M2 recommend layer = F-B, M3 apply works, M4 DEAD straddles, M5 observability blind spot), the cost table, and the three open decisions: D1 F-B disposition (document-as-deliberate vs age both gates together per floor 17), D2 [Bug] compress reports 'no compressible ranges remain' while mid-history spans sit outside every block #4331 options 2/3 weighed with D1 (if D1(b) lands, nudge-driven folds already reclaim this class and a dedicated sweep loses most of its value), D3 interim documentation of the only supported recovery (post-[PR] kernel: fold aged compress receipts (#4348) #4354 explicit ranges over aged exchanges; pre-[PR] kernel: fold aged compress receipts (#4348) #4354 releases have none; the synthetic-store-write path is explicitly NOT to be documented).

    Housekeeping: PR #4340 is rebased onto current master (now includes #4354) — head 94819f4a2, typecheck + unused-exports gate clean, 42/42 across the touched suites. Composition note for D1: if the aged set ever enters the offer, #4340's audit automatically stops listing those spans (they become actionable), so the two land cleanly together.

  10. sorasoras commented on Oct 23, 2026

    @sorasoras
    ContributorAuthor

    Two additions for the option 2 / 3 decision, both from the two sessions in the report.

    1. There are two distinct debris classes, and only one of them is foldable.

    class what it is my sessions pkuqiuning's sessions what fixes it
    A ref-bearing messages (mNNNNN) that are in no active block 30 of the 138 in session A; 20 tool-call msgs (mostly mcp__bili__compress) in session B — option 2/3 can absorb these
    B messages the exemption marks ref='BLOCKED' none observed 104/104 compress exchanges not fixable by a sweep; needs the #4348/#4354 line

    The distinction matters because a sweep that only walks ref-bearing messages will look healthy on a session like mine and still leave the opencode/omp debris untouched, while a sweep that also unblocks BLOCKED exchanges is a policy change, not a cleanup. Worth stating which class option 2 is allowed to touch.

    2. Option 3 must snap boundaries to turn/tool-pair edges, not just contiguity.

    The largest gap in session A is 100 messages = exactly 50 tool-call / 50 tool-result pairs, so "extend the fold across contiguous uncovered messages" happens to be safe there, but contiguity is not the constraint that matters. The fold already has a guard that withdraws messages "to keep N turn(s) intact" (visible tool-call would lose its reasoning run or its results). If option 3 extends a range by message adjacency without reusing that guard, it can cut a reasoning/tool pair and produce the exact 400 we already hit in this lineage ("content[].thinking in the thinking mode must be passed back"). Concretely: reuse the existing turn-integrity withdrawal, then trim the appended run to the last complete boundary inside the token cap.

    Same applies to the protected window: the run should be clipped by the block-boundary rule the audit uses (empirical offer diff), not by re-deriving preserveRecentMessages host-side.

    One more constraint: refs renumber across session generations (in session B a naive DB range-diff produced scattered refs 14797/12541/17115 mix). Any bookkeeping for a sweep or a persisted "already reported" marker must key on effectiveMessageIds/hashes, not on mNNNNN, or the second generation will silently mis-scope.

    Prioritization note. After option 1 lands, this is an occupancy issue, not a cache-miss one. The uncovered spans sit in the stable prefix; my acp_cache sample for session B was 98.9% hit over 3,734 requests, and the misses were TTL/rewrite-shaped, not coverage-shaped. So the number to optimize is "tokens of window wasted", which in my sessions was 16% and 20% of a 404k/596k context, and ~30% in pkuqiuning's 222k case. It becomes urgent only near the window limit, which is exactly where the false "minimum" verdict used to stop the agent from caring.

  11. ranxianglei commented on Oct 23, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

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

    Both additions checked against the code and logged as D2 design constraints in the tracking issue — #4398 (comment, so they sit with the decisions they constrain). Direct answers:

    1. Which class option 2 may touch: class A only. The class split is correct and it's already structural in what shipped: #4340's audit skips BLOCKED_REF by predicate (src/uncovered.ts:100, same predicate as the acp_status visible list), so a sweep built on that offer surface is class-A-only by construction. Unblocking BLOCKED exchanges is not cleanup — it's the M1/M2 gate change in #4398 (your F-B / their floor-17 line), and I've recorded it there as belonging to decision D1, explicitly separated from the sweep spec. A class-A-only sweep looking healthy on your sessions while opencode/omp debris rides on is now a stated expectation, not an accident.

    2. Option 3 snapping — agreed, and the guard already exists to be reused. The turn-integrity withdrawal you describe is kernel/src/turn-integrity.ts (reasoning/call split → withdraw whole turn; call/result split → withdraw both), and since the shared unit projection (#3236, kernel/src/unit-projection.ts) it runs on BOTH the apply side and the recommend side. So the constraint lands as: any extended candidate range must pass through that projection (which includes the withdrawal), then trim to the last complete boundary inside the cap — raw adjacency extension is off the table. Your thinking-mode 400 lineage is exactly the failure those invariants exist for (#1960). Same for the window clip: the empirical normal-vs-preserve-0 offer diff is precisely the mechanism #4340 uses, and reusing it for the sweep keeps kernel zone-rule evolution from desyncing it — no host-side preserveRecentMessages re-derivation. The renumbering constraint is recorded too (key on effectiveMessageIds/hashes, never mNNNNN); one clarifier: #4340 persists nothing — the audit is stateless per call — so that rule binds future sweep bookkeeping, not anything already merged.

    Prioritization: accepted and logged with the occupancy framing (stable-prefix spans → cache hits fine; the cost is window occupancy, urgent near the limit — which is exactly where the false minimum verdict used to stop the agent caring). That's now part of the D2-vs-D1 weighting in #4398.

    Nothing here changes what's in PR #4340 (option 1 + honest verdict); all four constraints apply to the not-yet-decided options 2/3 work.

  12. ranxianglei commented on Oct 23, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

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

    CI update: PR #4340 head 94819f4a2 is now fully green — 23/23 checks passed, zero failures (the master-side reds seen earlier didn't reproduce on this run). Nothing outstanding from my side; ready for merge verdict whenever you are. Open items remain only the owner decisions logged in #4398 (D1 F-B disposition / D2 options 2-3 with the four design constraints / D3 interim docs) and the ack on the 10K receipt-floor value.

  13. added 2 commits that reference this issue on Oct 24, 2026
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

    bugSomething isn't workingp2scope/kernelzcode改动范围:内核之外的主机侧接线(src/agent 适配器、server 路由、注入拦截)/范围兜底/客户端标签

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions