fix(streaming): pass agentId to resolveStorePath to fix non-default agent footer metrics#386
Closed
smallmj wants to merge 2 commits into
Closed
fix(streaming): pass agentId to resolveStorePath to fix non-default agent footer metrics#386smallmj wants to merge 2 commits into
smallmj wants to merge 2 commits into
Conversation
…gent footer metrics Footer metrics (tokens/cache/context/model) were always missing for non-default agents because resolveStorePath() was called without passing the agentId, causing the SDK to default to 'main' and look up the wrong per-agent session store file. Fix: extract agentId from sessionKey (format: 'agent:<agentId>:...') and pass it to resolveStorePath() in both the runtime.agent.session and channel.session code paths. Fixes larksuite#347
…agents The fallback mechanism was wrong because: 1. It tried to read from the default agent's session file when the correct agent's file didn't have the entry 2. This resulted in all non-default agents showing the same metrics (from the main agent's session), which is incorrect The agentId-based routing via resolveStorePath is sufficient to correctly read metrics from each agent's own session file.
Author
为什么删除 fallback 逻辑PR #386 原本包含了 fallback 机制:当在当前 agent 的 session 文件中找不到 metrics 时,尝试去 default agent (main) 的 session 文件中查找。 问题在于: 这个 fallback 找到了错误的数据。 经过本地验证:
结论: fallback 是冗余且有害的。 路由机制已经能正确将读操作定向到对应 agent 的 session 文件,不需要 fallback 来读取其他 agent 的数据。 删除 fallback 后,每个 agent 现在显示的是自己真实的 metrics 值。 |
Author
|
This PR has been replaced by the new PR #422 which is based on the latest main branch with a cleaner history. The fix in #422 has been locally verified to work correctly - each non-default agent now shows its own metrics instead of all showing the same values from the main agent. Please close this PR in favor of #422. Thanks! |
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
Footer metrics (tokens/cache/context/model) were always missing for non-default agents because
resolveStorePath()was called without passing theagentId, causing the SDK to default to 'main' and look up the wrong per-agent session store file.Root Cause
The SDK's
resolveStorePath(store, opts?: { agentId?: string })was being called as:resolveStorePath(sessionStorePath)— missing theagentIdargument.This means regardless of which agent handled the request, the metrics lookup always went to
~/.openclaw/agents/main/sessions/sessions.jsoninstead of the correct agent's session file.Fix
Extract
agentIdfromsessionKey(format:'agent:<agentId>:feishu:...') and pass it to bothresolveStorePath()calls (runtime.agent.session path and channel.session path).Change Type
Scope
Compatibility
agentIdis undefined (malformed sessionKey), it falls back to the default behavior, exactly as before.Linked Issue
Testing
agentIdis undefined (non-standard sessionKey), it gracefully degrades to the old behavior