fix(issue #2528): index active RuntimeContext by runId for concurrent multi-session support - #2531
Open
xzxiaoshan wants to merge 5 commits into
Conversation
…tive contexts with runId
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
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.
问题
ReActAgent.activeRc是一个private volatile RuntimeContext单字段。当同一 agent 实例上多个不同(userId, sessionId)会话并发调用时,后启动的调用会覆写前一个的 RuntimeContext,导致:getRuntimeContext()在并发下返回错误会话或 nullISSUE:#2528
方案
1. RuntimeContext 新增强制 runId
为 RuntimeContext 新增
runId字段,在Builder.build()中未显式设置时自动生成 UUID。getRunId()始终非空,作为 per-call 的权威 correlation id。2. activeRc 升级为 runId 索引的 ConcurrentHashMap
将
ReActAgent.activeRc(单 volatile 字段)替换为AgentBase.activeContexts(ConcurrentHashMap<String, RuntimeContext>),按 runId 索引:runLifecycle的Mono.deferContextual中,调用activeContexts.put(context.getRunId(), context)releaseExecution(Mono.usingcleanup)中调用activeContexts.remove(context.getRunId()),保证 complete / error / cancel 全路径覆盖getRuntimeContext(String runId)精确查找;getActiveRuntimeContexts()返回只读快照3. API 变更
RuntimeContext.getRunId()Agent.getRuntimeContext(String runId)Agent.getActiveRuntimeContexts()AgentBase.runLifecycle(msgs, context, doCallFn)AgentBase.afterAgentExecution(RuntimeContext context)ReActAgent.getRuntimeContext()(无参)HarnessAgent.promoteSkill(name, reviewerId, runId)