Skip to content

[PR] dsh: session identity rides the request object (llm/stream attribution, #4082) - #4101

Merged
ranxianglei merged 1 commit into
2026-10-21_conversation-recallfrom
2026-10-21_llm-stream-attribution
Oct 21, 2026
Merged

ranxianglei merged 1 commit into
2026-10-21_conversation-recallfrom
2026-10-21_llm-stream-attribution

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

The positive fix for #4082 (companion to the negotiated recall bridge #4094, which stays as the last-resort rung).

dsh's LlmRuntime stamps options.sessionId on every dispatch — main loop buildRequest, compaction (dsh-compaction-basic runMaintenance), session-title — and re-stamps on every retry re-send. The llm/stream waterfall is the documented interception point (first-party plugins like dsh-session-checkpoint-policy use exactly this shape).

This PR wraps each stream's iteration in an AsyncLocalStorage keyed by that sid:

  • the adapter's eager work inside next() runs in the scope;
  • every iterator advance (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);
  • attributionOf reads the scope first (the dispatch's own truth), ambient currentInitiator() 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:

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

  • new tests/dsh-llm-stream-attribution.test.ts 4/4: retry shape (lost ambient initiator) stays gated+stamped across yields; agentless no-sid passthrough; dispatch sid outranks ambient; compaction shape attributed.
  • families green: dsh-conversation-recall 2/2, dsh-authored-compaction 16/16, fix-1117-passthrough 3/3, issue1158 5/5, issue2709 (compaction attribution) 7/7, issue3581 (attribution health) 1/1, native-intercept 64/64.
  • gates clean: unused-exports (5 waived), lifecycle-ledger (148/150), gen-config-docs coverage, tsc 0.

One-time visibility line: bili-native-dsh: llm/stream attribution active — session id rides the request object (#4082).

Stacked on #4094 — merge that first.

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.
@ranxianglei ranxianglei changed the title dsh: session identity rides the request object (llm/stream attribution, #4082) [PR] dsh: session identity rides the request object (llm/stream attribution, #4082) Oct 21, 2026
@ranxianglei
ranxianglei merged commit 797cacd into 2026-10-21_conversation-recall Oct 21, 2026
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant