fix: add agent_end hook for per-turn observability #73
<!-- This is an auto-generated comment: summarize by coderabbit.ai -->
<!-- This is an auto-generated comment: rate limited by coderabbit.ai -->
[!WARNING]
## Rate limit exceeded
> @xDarkicex has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 53 minutes and 39 seconds before requesting another review.> To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.
> <details>
<summary>⌛ How to resolve this issue?</summary>
> After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.> We recommend that you space out your commits to avoid hitting the rate limit.
> </details>
>
<details>
<summary>🚦 How do rate limits work?</summary>
> CodeRabbit enforces hourly rate limits for each developer per organization.
> Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
> Please see our FAQ for further information.
> </details>
> <details>
<summary>ℹ️ Review info</summary>
> <details>
<summary>⚙️ Run configuration</summary>
> Configuration used: defaults
> Review profile: CHILL
> Plan: Pro
> Run ID: 474317b8-4376-4525-9dff-7cf59864b7f0> </details>
> <details>
<summary>📥 Commits</summary>
> Reviewing files that changed from the base of the PR and between eb1e0fcebbb4241c99745c42722017257b37e328 and 4dfd92715118d6f45858fbbc07c9378e10fd88de.
> </details>
> <details>
<summary>📒 Files selected for processing (1)</summary>
> * src/index.ts> </details>
> </details>
<!-- end of auto-generated comment: rate limited by coderabbit.ai -->
<!-- finishing_touch_checkbox_start -->
<details>
<summary>✨ Finishing Touches</summary>
<details>
<summary>🧪 Generate unit tests (beta)</summary>
fix/add-agent-end-hook</details>
</details>
<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->
---
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
<details>
<summary>❤️ Share</summary>
</details>
<!-- review_rate_limit_status_start -->
<sub>Review rate limit: 0/1 reviews remaining, refill in 53 minutes and 39 seconds.</sub>
<!-- review_rate_limit_status_end -->
<sub>Comment @coderabbitai help to get the list of available commands and usage tips.</sub>
<!-- tips_end -->
Minor concern: the fallback e.success ?? false means any agent_end event that omits the success field logs as success=false. If OpenClaw ever sends agent_end without that field (e.g., for a non-error completion), this would be misleading in logs. Consider e.success ?? true or logging the field only when present: success=${e.success ?? 'unknown'}.
Separately: this PR conflicts with #72 and #75 in src/index.ts around the api.on(...) registration block. Recommend rebasing after whichever of those merges first.
Reviewed the agent_end observability hook; no blocking issues found.
Minor concern: the fallbacke.success ?? falsemeans anyagent_endevent that omits thesuccessfield logs assuccess=false. If OpenClaw ever sendsagent_endwithout that field (e.g., for a non-error completion), this would be misleading in logs. Considere.success ?? trueor logging the field only when present:success=${e.success ?? 'unknown'}.
> Separately: this PR conflicts with #72 and #75 insrc/index.tsaround theapi.on(...)registration block. Recommend rebasing after whichever of those merges first.
Great find, Thank you @compoodment
fuller-stack-dev
xDarkicex
Summary
agent_endlifecycle hook that logs turn completion with success state, duration, and error detailssession_endhookConfiguration required
Non-bundled plugins must set in their OpenClaw config:
Test plan
npx tsc --noEmitpasses with zero errors