Repository navigation
Description
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:
engine/agent/subagent.go:3209—handleChildEventreturnsev.Result.Textandev.Result.Stoponly.ev.Result.Erroris never read. This is where the cause is lost.engine/agent/subagent.go:2489-2495—renderSubagentResult. TheStopErrorbranch doesmsg := final, wherefinalis the child'slastText. 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.session.SubagentPayload(engine/session/event.go) carriesStopbut has no error/cause field — so thesubagent.endevent and the mecatui card are structurally incapable of showing more thanstop:error.- Persistence. The child snapshot stores
state:"failed"/stop_reason:"error"and no error field. And nosubagent-*.events.jsonlis ever written:EventLog.Appendhappens at the relay (internal/adapter/server), and child runs are not relayed, so the child'sEvResult.Errorreaches 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:
- Read
ev.Result.ErrorinhandleChildEventand thread it out ofdrainChildObserved/driveChild; prefer it overfinalinrenderSubagentResult'sStopErrorbranch (falling back tofinal, then to the existing placeholder). This makes the cause model-visible and puts it in the parent's event log via the ordinarytool.result, with no new port or storage seam. - Add a cause field to
SubagentPayload+Subagentproto (next free field is 14) so thesubagent.endcard 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). - 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:llmresilienceseesport.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
- A subagent that fails on a stream-idle stall produces a model-facing tool error naming the stall, not the child's last sentence.
- A child that fails with no assistant text still gets the honest placeholder — no regression of the issue Subagent exhausts max-turns fetching context and returns no summary (174K tokens wasted); salvage partial output + inline context #48/Subagent returns opaque "(subagent produced no summary)" on StopNoProgress / empty StopEndTurn, discarding its work #152 salvage/digest path, which must stay ahead of this on the non-error empty terminals.
- The cause is recoverable from the parent's
.events.jsonlalone, with no debug build. - No terminal stream failure ends a turn without at least one Info-level diagnostic.
- The clamped cause appears on the mecatui subagent card.
- No child-authored content crosses into the parent conversation (gauntlet ACP: accept client-provided streaming-HTTP MCP servers #7 behavioural sentinel still passes).
Companion to #318 — that issue makes these failures survivable; this one makes them explicable.
Activity
JAORMX commentedon Jul 29, 2026
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.fix(subagent,team): name the resume mode, fence the failure body, dro…
fix(llmresilience): log the breaker rejection; stop calling an operat…
docs: fold ADR 0077's amendment into its Decision; disclose the membe…
fix(subagent): enumerate the resume-note matrix; a writable resume is…
fix(agent): normalise before matching, cover every result arm, and ke…
fix(subagent,llmresilience): one EvSubagentEnd constructor, an unbrea…
fix(mecatui): restore the collapse the retained client-side bound cla…
docs: finish the ADR-0077 fold and correct four claims the code does …
fix(subagent): name a next action on the structured-output terminal, …
fix(agent): tag the framing markers by surface, and close the judge, …
fix(mecatui): strip the Cf class the engine's own fence normalises away
docs: correct the structured-output justification and the pre-#319 di…
fix(subagent): surface a failed delegation's real cause, not its last…
3 remaining items
fix(subagent,team): name the resume mode, fence the failure body, dro…
fix(llmresilience): log the breaker rejection; stop calling an operat…
docs: fold ADR 0077's amendment into its Decision; disclose the membe…
fix(subagent): enumerate the resume-note matrix; a writable resume is…
fix(agent): normalise before matching, cover every result arm, and ke…
fix(subagent,llmresilience): one EvSubagentEnd constructor, an unbrea…
fix(mecatui): restore the collapse the retained client-side bound cla…
docs: finish the ADR-0077 fold and correct four claims the code does …
fix(subagent): name a next action on the structured-output terminal, …
fix(agent): tag the framing markers by surface, and close the judge, …
fix(mecatui): strip the Cf class the engine's own fence normalises away
docs: correct the structured-output justification and the pre-#319 di…
fix(agent): synthesise a terminal cause for a text-bearing StopError …
feat(agent): surface team member StopError cause on team.* events (#331…