Repository navigation
[PR] fix(dsh): DSH Remote long sessions skip compression due to stale fetch-chain re-entry state - #5616
Conversation
A new DSH model operation whose transport callbacks were minted during an earlier fetch inherits a stale dispatchDepth/chainHop AsyncLocalStorage context. Its first request then lands in the fetch-chain depth-1 / depth>=2 re-entry branches and skips dispatchBody (the compression entry), so the long session's full history goes straight to the model uncompressed. On Windows + DSH Desktop + ds-harness-remote (Go client) a 2-char turn still sent ~1.44M input tokens and tripped CONTEXT_WINDOW_EXCEEDED (HTTP 400), while the same session on desktop compressed normally. Add runOutsideFetchChain (fetch-chain): runs an operation with BOTH re-entry stores cleared via .exit(), for the operation's own subtree only, so #1662's foreign-wrapper cutoff still fires inside each single-fetch descent and resumes on return. Wrap every dsh llm/stream boundary (iterator factory, next, return, throw, and the hook entry) in runLlmDispatch = runOutsideFetchChain + dispatchScope.run, preserving session attribution (sid/msgIds) and host ALS. Regression tests: tests/issue5616-dsh-remote-fetch-boundary.test.ts (primitive reset semantics; integration stale-context op still compresses at all five boundaries with #1662 cutoff preserved and parent context restored; concurrent ops keep their own scope). Negative control: integration test fails without the dsh-native change. Closes #5614
📦 Built Package ArtifactBranch: Latest build — install this exact versionnpm install -g billion-context@0.0.8027-pr.5616.ec07082This exact version is immutable and reproducible. The rolling Recent builds (commit → version)
Download artifact
tar xzf billion-context-pr5616.tgz
npm install -g packageInstall instructions are refreshed on each push. |
… fix markers The fix comments and regression test referenced #5616, which is this PR; the bug report is upstream issue #5614. Repo convention (issueNNNN test names, #NNNN comment markers) cites the GitHub ISSUE the marker documents. Rename tests/issue5616-* to tests/issue5614-* and re-point the three comment sites. Comment/provenance only — no behavior change.
(ai: vllm-qwen/qwen3.8-27b) PR 独立审核结论:可合并(等 CI 在新 head 上全绿;合并按惯例由人执行)。 我没有照搬原 issue 线程的结论——把 base(9dc4c94) 与 head 两侧的 我独立验证过的事:
顺手修了一个小问题(已作为独立标注 commit 推到 PR 分支):代码注释与测试文件名引用的 结构化八问:
判定:方向对(修的是根因层的不变量,不是症状掩码)、实现层次正确、测试有牙且双向、diff 干净、无回归发现。等 CI 在 |
|
(ai: vllm-qwen/qwen3.8-27b) Review verdict: ✅ APPROVE / recommend merge (posted as a comment — GitHub blocks a formal self-approval of the author's own PR). Verified end-to-end against the PR head What it does. A new DSH model op whose transport callbacks were minted during an earlier fetch inherits a stale Correctness. Traced the Tests. Ran the new suite on the PR head: 3/3 pass. Proved the negative control — disabling the clearing (runLlmDispatch → plain dispatchScope.run) flips the integration test red while the primitive + concurrency tests stay green, so the test pins exactly this regression. Both directions asserted (dispatch-when-should AND cutoff-when-should-not), plus concurrency no-cross-talk and host-ALS non-clearing. Meets the gate-discipline bar. Regression surface. None: DSH-lane only; no config schema / env / CLI change, no Conventions. Clean 3-file diff (+378/−6); comments explain WHY with #5614 refs; no dead code / Non-blocking scope note: verification exercised the reported full-resend ( |
(ai: vllm-qwen/qwen3.8-27b) PR #5616 reviewed end-to-end → APPROVE / recommend merge (head Ran the new suite directly on the PR head: 3/3 pass. Proved the negative control — disabling the fetch-boundary clearing ( Verdict posted as a GitHub review comment on the PR (GitHub blocks a formal self-approval of the author's own PR, so it's recorded as a comment rather than an APPROVE event). |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.1054-master.6db0e84 # this exact build
npm install -g billion-context@master # always the newest merged build
|
…-gate, ranxianglei#5616 dsh remote compression bypass, ranxianglei#5378 release-notes fix
…4241 teeth at the byte-promised tail CI red on this PR had three causes: 1. storage-render + wire-contract goldens were regenerated against a kernel WITHOUT this PR's config (the committed metadata digest matches what master produces, not this branch): effectiveConfig in the persisted metadata now carries nudge.requireUsageSampleForPressure + nudge. maxEstimateHoldRounds, so every metadata digest moved again. Regenerated both golden sets with the local 0.0.185 kernel. 2. #4241 teeth: the fault dropped outbound[length-2] on the assumption the engine appends a trailing nudge as the final wire message. Since #5772 the snapshot render covers the previous turn's tail too (tailStart advanced), so length-2 lands INSIDE the exempt rendered prefix and the teeth never fire. The fault now drops the client's newest tail row (located by content) — the part the render lane actually owns byte-intact. Verified the same fix also passes on current master, where this test is broken since #5772. Note: storage-render/#4241/wire-contract/storage-engine-proofs also fail on master HEAD (run 42358603178) — #5772/#5616-era fallout, not this PR; the nudge e2e subset that master broke (#728A/C, #1119, #1137, zero-baseline) is fixed by this PR's backstop.
Problem
On Windows + DSH Desktop + ds-harness-remote (Go client), a long session skips compression: a 2-character turn still sends ~1.44M input tokens to the model and trips
CONTEXT_WINDOW_EXCEEDED(HTTP 400). The same session on desktop compresses normally (~139K input tokens). Reported by @dongyun-666 with local repro metadata and a candidate patch.Root cause
src/agent/fetch-chain/index.tsroutes each request throughdispatchBody(the compression entry) only when it sees a fresh top-level dispatch or a legit same-stack descent (chainHop.getStore() === patched). It tracks re-entry depth with twoAsyncLocalStoragestores (dispatchDepth,chainHop).AsyncLocalStorage values persist in ANY callback minted inside a
.run()scope even after that fetch has settled. A NEW dsh model operation whose transport callbacks were created during an earlier fetch therefore inherits a stale non-undefineddispatchDepth(with a non-matchingchainHop). Its first request lands in the depth-1 / depth>=2 branches and bypassesdispatchBody, so the full history goes straight to the model uncompressed. This matches the reporter's log signature (thellm/streamevent fired but no fetch-entry ran insidedispatchBody).The desktop path didn't hit it because its transport callbacks are minted by the client event loop as fresh top-level dispatches; the remote/harness path reuses callbacks across operations.
Fix
Add
runOutsideFetchChaininfetch-chain/index.ts: run an operation with BOTH re-entry stores cleared via.exit(), scoped to the operation's own subtree. Because.exit()only affects the operation's subtree, #1662's foreign-wrapper cutoff still fires INSIDE each single-fetch descent and resumes on return — the anti-loop protection is preserved, not defeated.Wrap every dsh
llm/streamboundary (iterator factory,next,return,throw, and the hook entry) inrunLlmDispatch = runOutsideFetchChain(() => dispatchScope.run(scope, op)). This enforces the invariant "a new model operation starts outside any transport fetch's re-entry scope" while keeping session attribution (sid/msgIds) and host ALS intact.This fixes the invariant at its source (the boundary where a new operation begins), not a payload mask — robust to whichever wrapper leaks the stale context, since every operation boundary resets.
Scope
DSH lane only. pi/opencode/omp intercept each model request as a passive fresh top-level fetch from the client event loop and have no bili-controlled "new operation" boundary hook; resetting at their raw-fetch level would break the legitimate nested-descent mechanism the two stores exist for. Not changed.
Tests
tests/issue5616-dsh-remote-fetch-boundary.test.ts:runOutsideFetchChainturns a stale-context fetch back into a fresh dispatch; parent cutoff restored after;llm/streamwaterfall driven from a stale transport context still compresses at all five boundaries (creation/iterator-factory/next/return/throw), DSH0.1.7-rc.2中billion-context与dsh-codex-subscription的冲突? #1662 cutoff preserved on ordinary re-entry, parent context restored, session attribution + host ALS intact;Negative control: test 2 fails when the dsh-native change is reverted (verified locally).
Behavior change
None. Pure availability fix — restores the compression entry that was being skipped. No threshold/default/timing/wire-format/output change.
Closes #5614