Skip to content

fix: capture agent end_time before emitting agent_stats - #9597

Merged
Soulter merged 1 commit into
AstrBotDevs:masterfrom
wcqqq1214:fix/webchat-stats-duration
Aug 8, 2026
Merged

fix: capture agent end_time before emitting agent_stats#9597
Soulter merged 1 commit into
AstrBotDevs:masterfrom
wcqqq1214:fix/webchat-stats-duration

Conversation

@wcqqq1214

@wcqqq1214 wcqqq1214 commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Modifications / 改动点

  • In tool_loop_agent_runner.py, capture end_time right before the agent_stats snapshot is serialized via to_dict(). Previously end_time was only set after the yield (inside _complete_with_assistant_response), so the frontend received end_time=0 and the per-message elapsed duration (耗时) in the webchat detail panel always displayed as "-". Token counts and time-to-first-token were unaffected.

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Verification Steps / 验证步骤

  1. Start AstrBot and open the webchat.
  2. Send a message and wait for the reply.
  3. Click the detail (info) button on the assistant message and check the 耗时 (duration) row.

Screenshots or Test Results / 运行截图或测试结果

Before / 修复前

Screenshot 2026-08-08 at 11 08 27

After / 修复后

Screenshot 2026-08-08 at 11 09 19

Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。(本 PR 无新功能)

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了"验证步骤"和"运行截图"。(截图待补充)

  • 🤓 I have ensured that no new dependencies are introduced.
    / 我确保没有引入新依赖库。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

Bug Fixes:

  • Fix agent_stats snapshots reporting an end_time of 0, which caused the frontend message duration to display as '-' instead of the actual elapsed time.

Summary by Sourcery

Bug Fixes:

  • Fix agent_stats responses reporting an end_time of 0 that caused the webchat message duration field to show '-' instead of the elapsed time.

@wcqqq1214
wcqqq1214 marked this pull request as ready for review August 8, 2026 03:48
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. area:core The bug / feature is about astrbot's core, backend feature:chatui The bug / feature is about astrbot's chatui, webchat labels Aug 8, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Aug 8, 2026
@Soulter
Soulter merged commit 40c8d1a into AstrBotDevs:master Aug 8, 2026
21 checks passed
@wcqqq1214
wcqqq1214 deleted the fix/webchat-stats-duration branch August 8, 2026 04:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core The bug / feature is about astrbot's core, backend feature:chatui The bug / feature is about astrbot's chatui, webchat lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants