Skip to content

A failed subagent's actual cause is dropped four times — the error shown is the child's last chat line #319

Closed

Description

@JAORMX

Summary

When a subagent fails, the reason is captured correctly by the loop and then dropped at four independent points. The result is a model-facing "error" that is actually the child's last piece of running commentary:

✗ Subagent
  subagent · 14m 47s · ↑5M ↓10.3K · 83 tools · stop:error
  [the subagent edited your workspace directly but did NOT finish cleanly — its edits may be PARTIAL; …]

  Subagent: Now let me check the ListPluginsRow structure and the InsertPluginVersionParams / UpsertPluginVersionForSyncParams.

  agentId: subagent-Subagent_10

"Now let me check the ListPluginsRow structure…" is not an error. It is lastText. Diagnosing what actually happened required reading the persisted session snapshots by hand, and even then the cause was unrecoverable — no field, log line, or event retains it.

The four drop points

engine/agent/loop.go:2151-2156 does the right thing: terminate() sets errMsg = cause.Error() and passes it to emitResult, landing in session.RunResult.Error (engine/session/event.go:433). Then:

  1. engine/agent/subagent.go:3209 — handleChildEvent returns ev.Result.Text and ev.Result.Stop only. ev.Result.Error is never read. This is where the cause is lost.
  2. engine/agent/subagent.go:2489-2495 — renderSubagentResult. The StopError branch does msg := final, where final is the child's lastText. Because the child had spoken, the "subagent failed without producing a summary" fallback never fires and the child's chatter is presented as the error.
  3. session.SubagentPayload (engine/session/event.go) carries Stop but has no error/cause field — so the subagent.end event and the mecatui card are structurally incapable of showing more than stop:error.
  4. Persistence. The child snapshot stores state:"failed" / stop_reason:"error" and no error field. And no subagent-*.events.jsonl is ever written: EventLog.Append happens at the relay (internal/adapter/server), and child runs are not relayed, so the child's EvResult.Error reaches no durable log.

And the terminal paths log nothing. The loop deliberately emits no diagnostic for a failed run (the "exactly THREE lines" contract — correct, leave it). llmresilience logs its recoverable lifecycle at Info: breaker open/half-open/closed, "llm stream not established after all attempts" (llmresilience.go:426), and "llm stream stalled (idle timeout); ending turn" (llmresilience.go:701). But the two paths that actually end a turn terminally log at no level at all:

  • A permanent, non-retryable establishment error — if !p.cfg.Classifier(err) { return nil, err } (llmresilience.go:~399) returns verbatim, silently. A 400/403/404 from the provider exits here with no record.
  • A mid-stream error chunk — if r.e != nil { return } (llmresilience.go:~684), i.e. the stream yielded an error after the first chunk. Terminal, no record.

The retry/per-attempt-timeout lines that would narrow it down are at LevelDebug (llmresilience.go:404,416), and cmd/mecatui hardcodes slog.LevelInfo in three places (main.go:266, main.go:278, diaglog.go:37) with no override flag.

This eliminates most candidates for the two failures behind #318. mecatui.log's last line for the affected session is 09:00:22 … subagent routed … z-ai/glm-5.2, then silence through the 14m47s failure. Since a stall, a retry exhaustion, and a breaker trip all log at Info and none appeared, the cause was none of those — it was one of the two silent terminal paths above (a permanent 4xx on the next request, or a mid-stream error frame). That is precisely the gap this issue closes.

Consequence

For the two failures behind #318 we can establish that no limit was hit, the history was well-formed, and each died on the next provider call at loop.go:1114 — but not which error. Stream-idle stall vs. exhausted retries on a 429/5xx vs. a permanent 4xx are indistinguishable after the fact, despite each implying a different operator response.

Proposed fix

In leverage order — the first item alone recovers the cause:

  1. Read ev.Result.Error in handleChildEvent and thread it out of drainChildObserved/driveChild; prefer it over final in renderSubagentResult's StopError branch (falling back to final, then to the existing placeholder). This makes the cause model-visible and puts it in the parent's event log via the ordinary tool.result, with no new port or storage seam.
  2. Add a cause field to SubagentPayload + Subagent proto (next free field is 14) so the subagent.end card can show it. Gauntlet-ACP: accept client-provided streaming-HTTP MCP servers #7 safe: a harness/provider error string is not child-authored content — but clamp it, and keep it out of the parent conversation (event stream only).
  3. Log the two terminal paths. Add an Info-level diagnostic to the permanent-error return and the mid-stream-error return, so a turn can never end terminally with no record — matching the Info treatment the stall and retry-exhaustion paths already get. Also promote (or make reachable via a mecatui --log-level) the Debug retry/per-attempt-timeout lines. All of this is metadata-only by construction: llmresilience sees port.LLMRequest + errors, never prompt text.

Gates: (2) touches the engine public surface (task api:update + engine/CHANGELOG.md, Added = minor) and the proto (task generate).

Acceptance

Companion to #318 — that issue makes these failures survivable; this one makes them explicable.

Activity

  1. added
    bug
    on Jul 29, 2026
  2. JAORMX commented on Jul 29, 2026

    @JAORMX
    ContributorAuthor

    Correcting my own framing in the original body: the stream-idle stall already logs at Info (llmresilience.go:701), as do retry-exhaustion (:426) and the breaker transitions. So "promote the stall line" was wrong.

    The real gap is sharper, and it changes the diagnosis: the two paths that end a turn terminally — a permanent non-retryable establishment error (:~399) and a mid-stream error chunk (:~684) — log at no level. The recoverable lifecycle is observable; the fatal one is not.

    That inverts the elimination for the failures behind #318: because none of the Info lines appeared in mecatui.log, those children did not die on a stall, a retry exhaustion, or a breaker trip. It was one of the two silent paths. Body updated.

  3. 3 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions