fix: 多 Agent 路由场景下按当前 agent 读取 footer metrics#504
Conversation
…ed agents
The footer metrics lookup (getFooterSessionMetrics) called
resolveStorePath without { agentId }, causing it to always read from
the default/main agent's session store. In multi-agent setups where a
Feishu chat is routed to a non-main agent, the metrics entry exists in
the routed agent's store but not the main store, so footer model/runtime
info was silently missing.
Thread agentId through StreamingCardDeps and pass it to both
resolveStorePath calls (runtime.agent.session and channel.session paths).
Fixes larksuite#502
Co-Authored-By: Claude Opus 4.7 <[email protected]>
evandance
left a comment
There was a problem hiding this comment.
Thanks for the well-scoped bug report in #502 and this targeted fix — root cause analysis was spot on, and the implementation follows the same pattern already used in src/card/tool-use-config.ts:60, which keeps it consistent with how the codebase handles routed agentId in session-store lookups. Verified the SDK supports passing { agentId } to resolveStorePath (plugin-sdk/src/config/sessions/paths.d.ts:19), all call sites of createFeishuReplyDispatcher are updated (dispatch.ts:256, dispatch-commands.ts:67, the test setups), and pnpm test passes 214/214.
One non-blocking suggestion: there's no regression test pinned to the new opts-passing behavior. A test that mocks runtime.agent.session.resolveStorePath and asserts the opts argument carries { agentId: <routed-agent-id> } would prevent a future refactor from silently dropping it.
LGTM, approving.
Extract agentId from session key (format: 'agent:<agentId>:feishu:...') to route the store lookup to the correct per-agent session file. The fallback mechanism from larksuite#504 is incorrect because it reads from the default agent's session file when the correct agent's file doesn't have the entry, causing all non-default agents to show the same metrics values (from main). This approach avoids that by using the correct key directly without any fallback. Fixes larksuite#347
背景
修复 #502。
Fixes #502.
在 OpenClaw 多 Agent 路由场景下,飞书/Lark 消息已经能正确路由到非 main agent,例如
coder,但 streaming/card footer 里的模型/运行时指标可能不显示。根因是 footer metrics 查询 session store 时,没有把当前路由到的
agentId传给resolveStorePath(...),导致它默认去读 main/default agent 的 session store。对于被路由到非 main agent 的会话,模型和 token metrics 实际写在对应 agent 的 store 里,因此 footer lookup 读不到metrics.model,最终 model footer 被跳过。修改内容
本 PR 将当前路由的
agentId传入StreamingCardController,并在 footer metrics 的两条 session store 解析路径里使用它:runtime.agent.session.resolveStorePath(...)runtime.channel.session.resolveStorePath(...)涉及文件:
src/card/reply-dispatcher-types.tsStreamingCardDeps增加agentIdsrc/card/reply-dispatcher.tsStreamingCardController时传入当前agentIdsrc/card/streaming-card-controller.tsresolveStorePath(sessionStorePath, { agentId: this.deps.agentId })验证
本地已验证:
npx pnpm typecheck npx pnpm test npx pnpm build结果:
另外也已把相同修复临时覆盖到本地运行中的
@larksuite/openclaw-larkruntime 包进行验证,确认 footer/model 显示功能正常。