openclaw - 💡(How to fix) Fix Sub-agent reports 'completed successfully' when provider returns stopReason: error [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#60473Fetched 2026-04-08 02:50:42
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0

When a sub-agent session receives a provider-level error (stopReason: error, finish_reason: error, 0 tokens), the parent agent is notified with status: completed successfully and (no output). This masks the failure and prevents automatic retry/fallback logic.

Error Message

When a sub-agent session receives a provider-level error (stopReason: error, finish_reason: error, 0 tokens), the parent agent is notified with status: completed successfully and (no output). This masks the failure and prevents automatic retry/fallback logic. 2. If the upstream provider crashes or returns an error during processing, the sub-agent session ends with:

  • stopReason: error
  • errorMessage: Provider finish_reason: error When stopReason is error, the completion event should propagate the error state:
  • status: completed with error (or failed) status: completed successfully with empty result. The parent has no indication that an error occurred unless it independently verifies the sub-agent's output. "stopReason": "error", "errorMessage": "Provider finish_reason: error",
  • Parent agents cannot distinguish between "sub-agent completed with empty output" (legitimate) and "provider crashed before executing" (error)
  • stopReason: errorcompleted with error + forward errorMessage

Root Cause

When a sub-agent session receives a provider-level error (stopReason: error, finish_reason: error, 0 tokens), the parent agent is notified with status: completed successfully and (no output). This masks the failure and prevents automatic retry/fallback logic.

Code Example

{
  "stopReason": "error",
  "errorMessage": "Provider finish_reason: error",
  "usage": { "input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0, "totalTokens": 0 },
  "provider": "openrouter",
  "api": "openai-completions"
}

---

status: completed successfully
Result: (no output)
Stats: runtime 7s • tokens 0 (in 0 / out 0)
RAW_BUFFERClick to expand / collapse

Summary

When a sub-agent session receives a provider-level error (stopReason: error, finish_reason: error, 0 tokens), the parent agent is notified with status: completed successfully and (no output). This masks the failure and prevents automatic retry/fallback logic.

Steps to Reproduce

  1. Spawn a sub-agent via sessions_spawn (e.g. using openrouter/auto)
  2. If the upstream provider crashes or returns an error during processing, the sub-agent session ends with:
    • stopReason: error
    • errorMessage: Provider finish_reason: error
    • usage: { input: 0, output: 0 } (all zeros)
  3. The parent agent receives a completion event with:
    • status: completed successfully
    • Result: (no output)

Expected Behavior

When stopReason is error, the completion event should propagate the error state:

  • status: completed with error (or failed)
  • Include the errorMessage from the sub-agent session so the parent can decide to retry or fallback

Actual Behavior

status: completed successfully with empty result. The parent has no indication that an error occurred unless it independently verifies the sub-agent's output.

Evidence

Sub-agent session log entry (assistant response):

{
  "stopReason": "error",
  "errorMessage": "Provider finish_reason: error",
  "usage": { "input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0, "totalTokens": 0 },
  "provider": "openrouter",
  "api": "openai-completions"
}

Parent received:

status: completed successfully
Result: (no output)
Stats: runtime 7s • tokens 0 (in 0 / out 0)

Impact

  • Parent agents cannot distinguish between "sub-agent completed with empty output" (legitimate) and "provider crashed before executing" (error)
  • Automated retry/fallback rules based on completion status are bypassed
  • Silent data loss — parent proceeds as if the task was done

Environment

  • OpenClaw v2026.4.3-dev (main HEAD)
  • Provider: OpenRouter (openrouter/auto)
  • Sub-agent model: Gemini Flash via OpenRouter

Suggested Fix

In the sub-agent completion handler, check stopReason before reporting to parent:

  • stopReason: end_turn or tool_usecompleted successfully
  • stopReason: errorcompleted with error + forward errorMessage
  • stopReason: max_tokenscompleted (truncated) — also useful to surface

extent analysis

TL;DR

Modify the sub-agent completion handler to propagate error states to the parent agent based on the stopReason value.

Guidance

  • Check the stopReason in the sub-agent completion handler and update the status accordingly:
    • stopReason: error should return status: completed with error along with the errorMessage.
    • stopReason: end_turn or tool_use can return status: completed successfully.
    • Consider handling stopReason: max_tokens to return status: completed (truncated) for better error handling.
  • Verify the fix by reproducing the error scenario and checking if the parent agent receives the correct status and error message.
  • Review the sub-agent completion handler code to ensure it correctly handles different stopReason values and propagates the error state to the parent agent.

Example

if (stopReason === "error") {
  return {
    status: "completed with error",
    errorMessage: errorMessage
  };
} else if (stopReason === "end_turn" || stopReason === "tool_use") {
  return {
    status: "completed successfully"
  };
}

Notes

The suggested fix assumes that the sub-agent completion handler has access to the stopReason and errorMessage values. If this is not the case, additional modifications may be needed to pass these values to the completion handler.

Recommendation

Apply the workaround by modifying the sub-agent completion handler to correctly propagate error states to the parent agent, as this will allow for better error handling and automated retry/fallback logic.

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