Repository navigation
[PR] dsh: session identity rides the request object (llm/stream attribution, #4082) - #4101
Merged
ranxianglei merged 1 commit intoOct 21, 2026
Conversation
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.
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.
What
The positive fix for #4082 (companion to the negotiated recall bridge #4094, which stays as the last-resort rung).
dsh's
LlmRuntimestampsoptions.sessionIdon every dispatch — main loopbuildRequest, compaction (dsh-compaction-basicrunMaintenance), session-title — and re-stamps on every retry re-send. Thellm/streamwaterfall is the documented interception point (first-party plugins likedsh-session-checkpoint-policyuse exactly this shape).This PR wraps each stream's iteration in an
AsyncLocalStoragekeyed by that sid:next()runs in the scope;next/return/throw) re-enters the scope — generator bodies resume in the consumer's dynamic context, so each advance must re-enter (this is exactly the adapter-internal retry loop shape);attributionOfreads the scope first (the dispatch's own truth), ambientcurrentInitiator()second, the negotiated bridge ([PR] dsh: negotiated session recall for unattributed retries (#4082) #4094) last.Why this kills the class
Attribution now follows the request object, not the async chain, so the shapes that lost it are immune:
agent/request-errorretry chains (re-dispatch re-stamps the sid),currentInitiatorthrows when the service dies),Bonus: compaction dispatches are attributed → they reach the plugin lane natively and feed dsh-authored compaction (#3737).
Dispatches with no sid (auto-review) pass through untouched — the existing ladder decides.
Verification
tests/dsh-llm-stream-attribution.test.ts4/4: retry shape (lost ambient initiator) stays gated+stamped across yields; agentless no-sid passthrough; dispatch sid outranks ambient; compaction shape attributed.One-time visibility line:
bili-native-dsh: llm/stream attribution active — session id rides the request object (#4082).Stacked on #4094 — merge that first.