Skip to content

fix(#1729): refuse dsh native compaction calls at the proxy gate - #1835

Merged
ranxianglei merged 1 commit into
masterfrom
2026-10-01_dsh-compaction-guard
Oct 1, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-10-01_dsh-compaction-guard

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

Refs #1729 — kills the deadlock's second producer at the traffic level. Complementary to #1827 (source-layer preset): the preset makes dsh not even try; this gate refuses whatever still tries (manual /compact, native presets chosen explicitly, hosts without the plugin bundle).

What lands vs what refuses — the asymmetry that justifies the gate

Letting a dsh compaction call through is irreversible: a landed checkpoint durably shadows the replayed surface range (shadowedSeqs/shadowedRange, surface replacement generation) — the original messages never ride a future request again, and the proxy's compression substrate is destroyed alongside bili's own state anchors (the #1729 deadlock). Every cost of refusing is dsh-side, caught, and recoverable:

dsh path (source-verified) on refusal
pressure auto-compaction (agent/pre-step) warn "step compaction failed …; continuing the turn" — benign, turn proceeds
context-overflow recovery (request-error) original 400 surfaces; bili's nudge/truncate is the defense
manual /compact refused too — same envelope, trigger indistinguishable at traffic level

Identification — two-signal AND (claudeSubagentSplit #970 discipline)

  1. MARKER: final user message starts with the versioned COMPACTION_INSTRUCTION prefix (machine-appended by dsh-compaction-basic's summarizer; tracked per dsh release like MAIN_SYSTEM_PREFIXES);
  2. SHAPE: whole request ≤ 4 messages (observed live: 2 msgs @ ~152K tokens in the 升级新版本后一开始用的本地模型27B 不压缩,换模型后压缩 桌面版本 #1727 logs; a normal turn — even one quoting the template — carries its full history and cannot fit).

Both must agree; a reworded template degrades to today's behavior. openai + anthropic wire shapes in v1; google/responses out of scope. Not gated on the dsh plugin marker — a dsh host routed through a global bili without the bundle is covered too.

Wiring

Guard sits after identity resolution, before the #388 side-request lane (a compaction call is full-budget, only this gate catches it) and before any pipeline work: refused locally (403, non-retryable, protocol-shaped), kernel state untouched, one WARN per session. The refusal text rides into dsh's own warn line, so the host log self-explains.

Tests: 10 cases in tests/dsh-compaction-guard.test.ts (observed shapes, content-parts, anthropic, quoting/mid-history non-matches, count bar, protocol scope, refusal bodies, live-template prefix check). Typecheck green.

dsh-compaction-basic answers context pressure by replaying the whole
conversation prefix and appending its fixed COMPACTION_INSTRUCTION as
the final user message, under the SAME session id (KV prefix-cache
reuse). In the desktop lane those calls ride bili as a second producer
on the main conversation — the #1729 deadlock — and when one lands,
dsh durably shadows the replayed surface range: the original messages
never ride a future request again, destroying the proxy's compression
substrate. That loss is irreversible; every cost of refusing is
dsh-side, caught, and recoverable, so the guard is unconditional.

- src/server/dsh-compaction-guard.ts: two-signal AND identification
  (per the claudeSubagentSplit #970 discipline — both signals must
  agree, failure direction is "stop intercepting"):
  1. MARKER: final user message starts with the versioned instruction
     prefix (verbatim from @deepseek-ai/dsh-compaction-basic, tracked
     per dsh release like MAIN_SYSTEM_PREFIXES);
  2. SHAPE: whole request <= 4 messages (observed live: 2 msgs at
     ~152K tokens in the #1727 logs; a normal turn — even one quoting
     the template — carries its full history and cannot fit).
  openai + anthropic wire shapes; google/responses out of scope v1.
- src/server.ts: guard runs after identity resolution, BEFORE the #388
  side-request lane and any pipeline work — refused locally (403,
  non-retryable, protocol-shaped), kernel state untouched, WARN once
  per session. Not gated on the dsh plugin marker: a dsh host routed
  through a global bili without the plugin bundle is covered too.
  The refusal message rides into dsh's own warn line ("step
  compaction failed: <message>; continuing the turn").
- tests/dsh-compaction-guard.test.ts: 10 cases — observed production
  shapes, content-parts, anthropic shape, quoting/mid-history non-
  matches, count bar, protocol scope, refusal bodies, live-template
  prefix check.

Deliberate residual costs, on record: manual /compact is refused too
(same envelope — the traffic layer cannot tell the trigger), and
dsh's context-overflow recovery loses its compaction path (the
original 400 surfaces; bili's nudge/truncate is the defense). The
source-layer fix (preset auto:false, #1827) remains complementary:
it makes dsh not even try, so nothing reaches this gate.

Refs #1729 (deadlock producer), #1772/#1827 (source-layer preset),
#1206 ([conflict] name-scan), #394 (shared-session hazard class).
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-01_dsh-compaction-guard (56acf8f)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.1817-pr.1835.74f24ad

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr1835.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei
ranxianglei merged commit 97e7420 into master Oct 1, 2026
13 checks passed
LoveDoLove pushed a commit to LoveDoLove-Forked-Projects/billion-context that referenced this pull request Oct 10, 2026
…w ledger; fail fast doomed evidence probes

Root cause of the ranxianglei#2490 turn-37→40 death: the host's raw ledger (replayed
whole by every refused dsh native-compaction envelope) is invisible to bili's
folded view, so the output clamp planned against the small folded input while
the host re-sent the full raw history every turn — a 1M window with ~200K
folded input let max_tokens=384000 through and one 7.5MB assistant turn
landed un-folding. Two guards:

- ledger floor: the ranxianglei#1835 guard now records the refused replay size on the
  session (high-water bytes + count) and clampOutgoingOutput plans against
  max(folded estimate, ledger floor) on the openai/google/responses lanes.
  Only ever tightens; cap < floor surrenders to preflight as before.

- doomed probe: the ranxianglei#2313 forward-once-for-evidence bet assumes some
  tokenizer might fit the payload. Beyond window×7.5 BYTES of core text
  (densest live-route billing observed ~6.8 B/token, ranxianglei#2122) none can, so the
  probe is a guaranteed 400 with an 8MB body — fail fast 502 with the byte
  math instead of paying it.

tests/issue2490-ledger-floor-doomed-probe.test.ts: 6 pins (floor unit trio,
incident clamp 384K→55K, guard accounting e2e, doomed-probe e2e, ranxianglei#2313
control).
YunzhouLi-hub pushed a commit to YunzhouLi-hub/billion-context that referenced this pull request Oct 11, 2026
…t dsh native compaction

The ranxianglei#1117 passthrough lane relays byte-untouched with 'no session, no
injection, no guard' — which made it the one lane dsh's agentless
background compaction could still LAND through: the takeover gate
refuses attribution for agentless callers while the settings overlay
has already routed the URL to /bili/, so the native patch stamps
x-bili-passthrough and the call relays verbatim BELOW the ranxianglei#1835
pipeline guard (field report: 49 compaction starts, 45 refused through
the pipeline, 4 landed through this lane, each landing later tripping
ranxianglei#1001 as an 'unannounced' rewrite).

Same refusal applied at this lane too: marker-decisive detection
(ranxianglei#2193 — message count never gates), raw-ASCII sniff prefilter so
ordinary background traffic (title-gen, plugin calls) pays no
JSON.parse, bounded decode for content-encoded bodies (the relay still
forwards the ORIGINAL bytes), honors allowDshCompaction (ranxianglei#2028),
fail-open on undecodable bodies (the ranxianglei#1835 failure direction), and a
process-level refusal count since the lane has no session for the
ranxianglei#2490 ledger.
@ranxianglei
ranxianglei deleted the 2026-10-01_dsh-compaction-guard branch October 15, 2026 05:32
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.

1 participant