← Back to Pull requests

fix: add agent_end hook for per-turn observability #73

Merged
xDarkicex merged 1 files (12 lines) on May 04, 2026 08:12 UTC
View on GitHub
xDarkicex xDarkicex commented on May 03, 2026 09:14 UTC
Author

Summary


  • Registers an agent_end lifecycle hook that logs turn completion with success state, duration, and error details

  • Observation-only — no blocking calls, no RPC, lightweight logging

  • Fires per-turn (not per-session), complementing the existing session_end hook
  • Configuration required


    Non-bundled plugins must set in their OpenClaw config:
    {
      "plugins": {
        "entries": {
          "libravdb-memory": {
            "hooks": {
              "allowConversationAccess": true
            }
          }
        }
      }
    }
    

    Test plan


  • npx tsc --noEmit passes with zero errors

  • Handler is fire-and-forget (no async RPC, just logger.info)

  • Uses structural typing on the event to avoid strict SDK type coupling
  • Diff: 12 lines (+12 / -0) across 1 files Reviewer: fuller-stack-dev Review duration: 1378m
    All Vouch review confidence checks passed
    Residual risk 0.02 = Change Risk (0.18) × (1 − Review Confidence (0.92)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.18 · 12 lines diff across 1 files
    0.18
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.97 · 3 substantive comment(s)
    0.97
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    92%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.153
    Real PR Conversation Timeline
    5 items
    coderabbitai[bot] coderabbitai[bot] commented on May 03, 2026 09:14 UTC
    Bot

    <!-- 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>

  • <!-- {"checkboxId": "f47ac10b-58cc-4372-a567-0e02b2c3d479", "radioGroupId": "utg-output-choice-group-unknown_comment_id"} --> Create PR with unit tests

  • <!-- {"checkboxId": "6ba7b810-9dad-11d1-80b4-00c04fd430c8", "radioGroupId": "utg-output-choice-group-unknown_comment_id"} --> Commit unit tests in branch 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>

  • X

  • Mastodon

  • Reddit

  • LinkedIn
  • </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 -->

    compoodment compoodment commented on May 03, 2026 13:00 UTC
    Contributor

    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.

    fuller-stack-dev fuller-stack-dev commented on May 04, 2026 03:28 UTC
    Reviewer

    Reviewed the agent_end observability hook; no blocking issues found.

    xDarkicex xDarkicex commented on May 04, 2026 08:12 UTC
    Author

    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.

    Great find, Thank you @compoodment

    Assignees
    xDarkicex xDarkicex
    Labels
    risk: low confidence: 92.4% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 18.3% (LOW) · Higher = larger blast radius
    18.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 92.4% · Lower = rushed or shallow review
    92.4%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 2% · Safe to merge
    2%