Repository navigation
[PR] dsh: negotiated session recall for unattributed retries (#4082) - #4094
Merged
Merged
Conversation
Host-driven retries, model switches and post-resume resends run outside the agent execution chain, so the AsyncLocalStorage initiator is missing and the takeover gate refused them into raw DIRECT sends — compression off, guards off, permanently for the session (#3918, #2975). While attribution works, the shim learns lane -> (sid, boundary fingerprint of the request's last message). When attribution is later missing on the same lane, a dispatch whose history CONTAINS a remembered boundary (uniquely) is provably that session's continuation: the gate claims it and beforeSend stamps the negotiated conversation header atomically with the body (#3370 discipline). Fork divergence lacks the boundary — never claimed; no evidence or ambiguity keeps today's direct behavior byte-for-byte. Every proxied 2xx now carries x-bili-session (protocol surface for cooperating clients, PLUGIN.md).
Contributor
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.4893-pr.4094.8d371f5This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr4094.tgz
npm install -g packageInstall instructions are refreshed on each push. |
Tokens rotate (bearer refresh, key swap) — an auth-keyed lane orphans the table on the exact retry it exists to rescue. The lane is only the search namespace; identity evidence stays the boundary fingerprint + uniqueness, so widening the lane trades a rare cross-account ambiguity (refused, safe) for a bridge that survives credential rotation.
The LlmRuntime stamps options.sessionId on every dispatch and documents the llm/stream waterfall as the interception point. Wrap each stream's iteration in an AsyncLocalStorage keyed by that sid so adapter fetches read attribution that follows the request, not the async chain — retry chains, agentless side-calls (compaction, session-title), disposed initiator scopes, and host runtime gaps all stay attributed (#2975, #3918, #4082). Attribution order: llm/stream sid first, ambient currentInitiator fallback, the negotiated recall bridge (#4094) stays as the last resort. Agentless dispatches without a sid pass through untouched.
…ite, stamp rebuild (#4082) Four non-behavioral fixes from the independent #4082 review of this PR: - recallLaneKey JSDoc still described the pre-c8960a0e auth-keyed lane; rewritten to match the implemented origin+pathname-only key. - maybeNegotiatedClaim now probes lane existence before parsing/hashing the body: agentless sidecars (title-gen etc.) hit the none path constantly, and multi-MB quota-retry bodies must not pay full JSON.parse plus per-message sha256 when no session was ever learned on that lane. - learn+stamp moved before fork-adopt/incremental in beforeSend: the boundary fingerprint must come from the ORIGINAL full history, not from bodies those two steps rewrite (the incremental delta happens to end with the newest message today; learning must not rest on that shape). - The negotiated re-stamp rebuilds init.headers via new Headers(...) instead of mutating the host-provided headers object in place (#3370 discipline): an in-place stamp could leak the negotiated identity into later unclaimed requests if the host reuses its headers across retries. Observable behavior unchanged on every path; wiring test assertions read through a Headers view to match the rebuilt stamp.
…bution [PR] dsh: session identity rides the request object (llm/stream attribution, #4082)
Contributor
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.709-master.496f05e # this exact build
npm install -g billion-context@master # always the newest merged build
|
This was referenced Oct 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4082 (the bili-side half; the host-side ALS gap itself stays tracked in #2975).
What this does
dsh retries and model switches re-send model traffic from execution chains that never entered an agent turn, so our AsyncLocalStorage attribution reads
noneand the interceptor falls todirectSendOrRefuse— the session loses compression, guardrails, and fold state (#3918, #4068, #2975). dsh cannot accept PRs for the host-side fix, so this adds a negotiated identity recall that needs zero host changes:(lane key → session id, boundary fingerprint)in a small LRU/TTL table. The lane key is origin+path+authorization-hash — deliberately without model, because a model switch on the same history is exactly the shape we must recognize. The boundary fingerprint is the sha of the last message of that dispatch.beforeSendseam.x-bili-session: <sid>. Cooperating clients can carry the id themselves (fetch response → later fetches), adopting stable identity without any bridge. The dsh recall does not depend on this header.Limits
Verification
tests/conversation-recall.test.ts5/5 — continuation claim, model-switch + fork shapes, ambiguity rejection, TTL expiry, LRU eviction.tests/dsh-conversation-recall.test.ts2/2 — end-to-end wiring: attributed turn learns; unattributed retry with the same history is claimed and stamped; fork history never stamps.tests/dsh-native.test.tscannot run in this sandbox (attach-registration timeouts — reproducible on clean master; CI runs it green).