Skip to content

fix: 多 Agent 路由场景下按当前 agent 读取 footer metrics#504

Merged
evandance merged 1 commit into
larksuite:mainfrom
babobi-bo:fix/footer-metrics-routed-agent-v2
May 13, 2026
Merged

fix: 多 Agent 路由场景下按当前 agent 读取 footer metrics#504
evandance merged 1 commit into
larksuite:mainfrom
babobi-bo:fix/footer-metrics-routed-agent-v2

Conversation

@babobi-bo
Copy link
Copy Markdown
Contributor

@babobi-bo babobi-bo commented May 12, 2026

背景

修复 #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.ts
    • StreamingCardDeps 增加 agentId
  • src/card/reply-dispatcher.ts
    • 创建 StreamingCardController 时传入当前 agentId
  • src/card/streaming-card-controller.ts
    • 调用 resolveStorePath(sessionStorePath, { agentId: this.deps.agentId })

验证

本地已验证:

npx pnpm typecheck
npx pnpm test
npx pnpm build

结果:

  • TypeScript typecheck 通过
  • 测试通过:27 个 test files / 214 个 tests
  • build 通过

另外也已把相同修复临时覆盖到本地运行中的 @larksuite/openclaw-lark runtime 包进行验证,确认 footer/model 显示功能正常。

…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]>
Copy link
Copy Markdown
Collaborator

@evandance evandance left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@evandance evandance added bug Something isn't working messaging src/messaging/ + src/card/ — message rendering, cards, streaming labels May 13, 2026
@evandance evandance merged commit 06977aa into larksuite:main May 13, 2026
2 checks passed
smallmj added a commit to smallmj/openclaw-lark that referenced this pull request May 13, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working messaging src/messaging/ + src/card/ — message rendering, cards, streaming

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Footer model metrics use default session store for routed agents

2 participants