openclaw - 💡(How to fix) Fix [Feature Request] Add agent:error event hook support for auto-recovery mechanisms [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#44458Fetched 2026-04-08 00:46:43
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
1
Participants

Error Message

Add gent:error event type to the hooks system: if (event.type !== "agent" || event.action !== "error") { const error = event.context.error; console.log([error-hook] Agent error: ); if (error.code === 401) { The error event could include:

  • error.code - HTTP status code or error type
  • error.message - Error message
  • error.retryable - Whether the error is retryable
  • sessionKey - Which session encountered the error
  • imestamp - When the error occurred
  1. Monitor command-logger output for error patterns
  2. Parse gateway logs for error detection
  • Documentation mentions gent:error as a "future event" but not yet implemented
RAW_BUFFERClick to expand / collapse

Problem

Currently, OpenClaw hooks system supports events like command:new, command:reset, gateway:startup, etc. However, there's no event for when the agent encounters errors (like API errors, 401 authentication failures, timeouts, etc.).

Use Case

Users want to implement auto-recovery mechanisms that:

  1. Detect when the agent encounters errors (e.g., 401 Unauthorized, API rate limits, network failures)
  2. Automatically trigger recovery actions (e.g., refresh tokens, retry, run diagnostic scripts)
  3. Resume normal operation without manual intervention

Proposed Solution

Add gent:error event type to the hooks system:

` ypescript // Example handler const errorHandler: HookHandler = async (event) => { if (event.type !== "agent" || event.action !== "error") { return; }

const error = event.context.error; console.log([error-hook] Agent error: );

// Auto-recovery logic if (error.code === 401) { // Refresh token or notify user } }; `

Event Context

The error event could include:

  • error.code - HTTP status code or error type
  • error.message - Error message
  • error.retryable - Whether the error is retryable
  • sessionKey - Which session encountered the error
  • imestamp - When the error occurred

Alternative

Until this is implemented, users can:

  1. Use cron jobs to periodically check for errors
  2. Monitor command-logger output for error patterns
  3. Parse gateway logs for error detection

Related

  • Documentation mentions gent:error as a "future event" but not yet implemented
  • Would enable powerful auto-recovery and self-healing capabilities

Environment

  • OpenClaw version: 2026.3.8
  • Node.js: v24.12.0
  • Platform: Windows 10

extent analysis

Fix Plan

To implement the agent:error event type, follow these steps:

  • Update the hooks system to include the new event type
  • Modify the error handling mechanism to trigger the agent:error event
  • Create a handler function to process the agent:error event

Example Code

// Define the agent:error event type
enum EventType {
  // ...
  AGENT_ERROR = 'agent:error',
}

// Update the error handling mechanism to trigger the agent:error event
const errorHandler = async (error: Error) => {
  const event: HookEvent = {
    type: EventType.AGENT_ERROR,
    action: 'error',
    context: {
      error: {
        code: error.statusCode,
        message: error.message,
        retryable: error.retryable,
      },
      sessionKey: 'current-session-key',
      timestamp: new Date().toISOString(),
    },
  };

  // Trigger the agent:error event
  await triggerHookEvent(event);
};

// Create a handler function to process the agent:error event
const agentErrorHandler: HookHandler = async (event: HookEvent) => {
  if (event.type !== EventType.AGENT_ERROR) {
    return;
  }

  const error = event.context.error;
  console.log(`[error-hook] Agent error: ${error.message}`);

  // Auto-recovery logic
  if (error.code === 401) {
    // Refresh token or notify user
  }
};

Verification

To verify that the fix worked, test the agent:error event by simulating an error and checking if the auto-recovery logic is triggered. You can do this by:

  • Intentionally causing an error (e.g., by making an API request with an invalid token)
  • Checking the console logs for the [error-hook] Agent error: message
  • Verifying that the auto-recovery logic is executed correctly (e.g., by checking if the token is refreshed)

Extra Tips

  • Make sure to update the documentation to reflect the implementation of the agent:error event type.
  • Consider adding more error codes and retryable flags to the agent:error event context to handle different types of errors.
  • You can also use this event to trigger diagnostic scripts or notify users of errors.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING