bug(lifecycle): orchestrator terminated mid-turn by a stale-activity/probe race, then silently replaced with no linkage or notification
Bug
A long-running orchestrator session (pledg-turbo-monolith-4) was marked IsTerminated=true / activity.state=exited / status=terminated while it was still genuinely alive and mid-turn — its own Claude Code transcript shows real activity (a turn_duration/stop_hook_summary event, then an away_summary event) after the daemon's recorded termination timestamp. A brand-new orchestrator session was then spawned in its place 3 seconds after the old session's last transcript event, with zero linkage back to the original session and no notification to the user. The user only discovered the swap by asking "what happened to the orchestrator that was already working here?" and had to manually recover context by grepping raw .jsonl transcripts.
Source: reported directly in chat by the project owner | Analyzed against: a54003e7 (origin/main HEAD)
Confidence: High — traced the exact code paths below and cross-checked them against live session records, the session's own transcript, and the daemon's hook-delivery log.
Priority: high — core reliability of long-running orchestrator sessions; loses conversation continuity for the primary supervising agent with zero user-facing signal, no workaround other than manually diffing transcripts (no priority:* label applied automatically since I can't independently confirm "many users affected" — flagging severity in the body instead).
Timeline (UTC, all directly confirmed)
pledg-turbo-monolith-4(kind: orchestrator) created2026-07-04T06:47:24Z, ran ~3 days across several Claude Code session UUIDs in the same transcript directory (normal compaction/resume behavior).09cccbfd-e7de-413f-a3bb-efdcd4f86583.jsonl(that orchestrator's transcript):2026-07-07T18:35:35.238Zlast assistant message,18:35:35.422Zsystem stop_hook_summary,18:35:35.428Zsystem turn_duration, then18:38:38.674Zsystem away_summary— all confirming the session was alive and had just finished a turn well past 18:30.ao session get pledg-turbo-monolith-4 --jsonreportsactivity.state: "exited",isTerminated: true,updatedAt: "2026-07-07T18:30:46.569Z"— ~5 minutes before the transcript'sstop_hook_summary/turn_durationand ~8 minutes before itsaway_summary.pledg-turbo-monolith-19, a newkind: orchestratorsession for the same project, was created2026-07-07T18:38:41.164Z— 3 seconds after the old transcript's last event — with no reference topledg-turbo-monolith-4anywhere in its record.~/.ao/data/hooks.loghas zero entries forpledg-turbo-monolith-4anywhere near this window (its only entries are from2026-07-05T00:49:24Z, an unrelated "daemon not running" failure) — ruling out a failedSessionEndhook delivery as the trigger; no hook of any kind is logged as attempted around 18:30:46Z.
Root Cause
Two independent, compounding defects, both confirmed by code trace:
1. A stale-activity gate + non-sticky idle state lets a single probe reading kill a live session
lifecycle.Manager.ApplyRuntimeObservation(backend/internal/lifecycle/manager.go:100-110) setsIsTerminated=trueandActivity.State=ActivityExitedwheneverruntimeClearlyDead(...)is true.runtimeClearlyDead(backend/internal/lifecycle/runtime.go:25-28) requiresf.Probe == ports.ProbeDead(from the reaper's 5-second-intervaltmux has-sessioncheck,backend/internal/observe/reaper/reaper.go:20,backend/internal/adapters/runtime/tmux/tmux.go:176-190) AND!hasRecentActivity(activity, observedAt, window), wherewindow = defaultRecentActivityWindow = 60 * time.Second(backend/internal/lifecycle/runtime.go:10,12-23).- Critically,
ActivityIdleis not sticky (onlyActivityWaitingInputis —backend/internal/domain/activity.go:19-21). Between aStophook (turn-end → idle) and the nextuser-prompt-submit(→ active), or whenever a hook delivery is dropped (hook delivery is explicitly documented as best-effort,manager.go:140-141), the recorded activity can go stale past 60s while the agent is still genuinely working (e.g. a long tool call, or Claude Code's own idle/away bookkeeping producing no AO-visible signal). If a singleProbeDeadsample lands from the reaper during that window — for any transient reason (tmux server hiccup, a race in probe timing, anything that isn't cleanlyProbeFailed) — the session is killed immediately and irreversibly. There is no retry, no requirement for multiple consecutive dead readings, and no reconciliation if the pane turns out to still be there. - The adapter code is explicit that this exact race is expected by design:
backend/internal/adapters/agent/claudecode/activity.go:57-59— "SessionEnd is not guaranteed on crash/SIGKILL, so the reaper remains the backstop; both paths guard on IsTerminated, so whichever lands first wins." No safeguard exists for the case where the reaper wins incorrectly. - Given the transcript shows no
SessionEndevent before 18:30:46Z andhooks.logshows no hook activity for this session in that window, the reaper/probe path is the far more likely trigger here, not a genuineSessionEndhook.
2. The idempotent orchestrator-respawn path blindly spawns a replacement with no linkage, no clean-exit check, and no notification
SpawnOrchestrator(ctx, projectID, clean=false)(backend/internal/service/session/service.go:269-307) is the sole "ensure a live orchestrator exists" path. It checks only!IsTerminatedacross existing orchestrator sessions (service.go:279,291); if none are active, it callsSpawn(...)with no reference to the prior session's id, no reason code, and no check for whether the prior termination was "clean."verifyOrchestratorReplacement(service.go:318-333) only validates the new session's own fields (harness, branch) — it never looks at the old session at all.- The retire-notice mechanism (
sendRetireNotice/orchestratorRetireNotice,service.go:284,309-316) — the only user-facing "your old orchestrator was replaced" messaging that exists in this codebase — only fires on the explicitclean=trueuser-initiated replacement flow, not on this idempotentclean=falserespawn. - No autonomous backend loop spawns orchestrators (confirmed: nothing in
backend/internal/daemon, the reaper, or any observer creates akind=orchestratorsession). Everyclean=falsecall site is a user-facing "open orchestrator" UI action (ShellTopbar.tsx,SessionsBoard.tsx,Sidebar.tsx) that finds nothing active in cache — consistent with the user clicking into the project a few seconds after the reaper had already (incorrectly) flipped the old session to terminated, and getting a cold, unlinked, unexplained new session instead of any indication something had gone wrong.
Suggested Fix
- Require the runtime-probe kill path to see multiple consecutive
ProbeDeadreadings (or a longer confirmation window) before flippingIsTerminated, rather than acting on one sample — especially forkind=orchestratorsessions, which are long-lived and higher-value than a typical worker. - Consider making the
hasRecentActivitystaleness window adaptive to whether a turn is actually in flight, or treat a session's own harness-reported "actively producing output" signal (if obtainable) as an override that suppressesProbeDeadverdicts. - On the
SpawnOrchestrator(clean=false)respawn path: pass the terminated predecessor's session id into the new session's record, and extend the existingorchestratorRetireNoticemechanism (already built for theclean=truepath) to also fire here, so the new session's first turn (and the user, via a UI toast/notification) is told "the previous orchestrator session ended unexpectedly at<time>; here's a link to its transcript" instead of starting cold with no explanation.
Impact
Loss of orchestrator continuity mid-task with zero notification anywhere (neither the dying session nor the replacement says anything) — for a background-running supervising agent, this is a real trust problem: work and context can silently vanish, discoverable only by the user manually grepping raw .jsonl transcript files. This is exactly the kind of incident that erodes confidence in leaving an orchestrator unattended.
Related
Two closed issues from the pre-rewrite TypeScript codebase describe the same class of failure (process-liveness probe false-positive → premature "killed"/"exited" verdict), though neither is this Go rewrite's code and neither is an exact duplicate — citing as precedent that this failure mode has recurred across rewrites:
- "Orchestrator session immediately marked as 'killed' despite running fine" (closed, TS-era
lifecycle-manager.ts/agent-claude-coderace between session creation and first liveness poll) - "
pstimeout conflated with 'process not found' — bulk-terminates all sessions whenpsexceeds 5s" (closed, TS-era, same probe-failure-collapsed-to-dead pattern this issue's root-cause section describes for the current Go reaper)
Also potentially related in the current Go codebase (not independently verified against this issue's mechanism, flagging for triage cross-reference):
Thanks for contributing to Agent Orchestrator.
This issue is being picked up by the current external contributor on-call pair:
- @neversettle17-101
- @somewherelostt
If someone is already working on this, please continue as usual. The on-call pair is added for visibility, tracking, and support, not to take over the work. If you need help with review, direction, reproduction, or next steps, please tag @neversettle17-101 and @somewherelostt here. You can also join the AO Discord if you want faster context, want to ask questions live, or just want to follow what the community is building.
You are also welcome to join the AO Discord community.
We do daily Discord calls at 10 PM IST, except Saturday.
Join the session here: https://discord.gg/H6ZDcUXmq
Come by if you want to see what is being built, ask questions, or just hang around with the community.
Assigned to @shankywho