You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Abandoned background subagent loses its failure cause to the post-seal emit race #332
Found during the fix-verification audit of PR #320 (issue #319). A narrow race lets a background subagent's failure cause die before it reaches the parent's durable .events.jsonl.
The race
At run end, drainChildren (engine/agent/loop.go) cancels + joins live background children in two phases (childDrainCap ~10s, then abortEmits() + childDrainGrace ~1s), then SEALS the child registry — after which every child emit routes through safeEmit and a post-seal emit is a no-op.
The lossy shape: a background child determines StopError (a terminal provider error) at roughly the same instant the parent's drain cap expires. driveChild returns the cause, but the child's subagentEndEvent emit (engine/agent/subagent.go ~2605) fires AFTER the seal — so the cause never reaches the parent's event stream or its .events.jsonl.
The child IS persisted by persistChild (SessionStore.Save) — but only its snapshot (state: failed, stop_reason: error). session.Session has no cause field, and child runs are never relayed (EventLog.Append happens at the relay; children are not), so the child's own EvResult.Error is not durable either. The cause is unrecoverable from any durable log.
Why it's narrow
In the common flow cancelLiveBackground cancels the child's ctx first, so the child ends StopCancelled — no cause by design (a cancellation). The lossy case only arises when the child ALREADY determined StopError but its end-emit lands post-seal. This is a genuine shape (a provider error concurrent with the drain cap expiring) but outside #319's synchronous evidence.
Possible directions
Widen drainChildren's grace for a child that has ALREADY reached its terminal result (its doneCh is about to close) vs one still mid-turn — a terminal child needs only to flush one end event, not finish a turn.
Or persist the terminal cause onto the child snapshot itself (a last_error field on Session), so persistChild captures it independent of the emit race — this also fixes the "child runs are never relayed" gap for the terminal cause specifically.
Activity
feat(session): persist the terminal failure cause on the session snap…
fix(server): repair TeamPayload.Cause on the wire (#402)