fix(agentlang): isolate stream fallback correlations by context - #85
Open
Linxiushen wants to merge 1 commit into
Open
fix(agentlang): isolate stream fallback correlations by context#85Linxiushen wants to merge 1 commit into
Linxiushen wants to merge 1 commit into
Conversation
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.
Summary
AgentContext.context_idProblem
The correlation manager already scopes paired Agent events by context, but streaming fallback still uses one process-wide mutable slot.
With concurrent Agent contexts, including independent sessions and parent/child Agents, the following interleaving is possible:
V2 streaming uses the request ID as its correlation ID. Reusing the wrong value can associate a final regular response with another Agent run, while a missing value makes partial chunks and the final response appear as separate replies.
Approach
Fallback correlations are now stored by the same
AgentContext.context_idscope already used for paired events.ProcessorManagersets and clears the marker in the current context, andRegularCallProcessoronly consumes that context's marker.The current Agent loop has one in-flight LLM call per context, while parallel sub-agents receive isolated contexts. This keeps the change aligned with the runtime's existing ownership boundary and avoids introducing another request-chain identifier.
Unconsumed markers are cleared at the end of a run and when an Agent closes. This covers cancellation, deterministic errors that skip fallback, and early termination. Callers that omit a context keep the previous single global-scope behavior.
Tests
run_main_agent()cancellation propagates while request-finally clears only the current scopeFixes #84