agent-orchestrator icon indicating copy to clipboard operation
agent-orchestrator copied to clipboard

bug(runtime/tmux): IsAlive reports pane-exists as agent-alive, masking crashed agents behind the keep-alive shell

Open anmol0b opened this issue 4 months ago • 2 comments

Problem

tmux.Runtime.IsAlive (backend/internal/adapters/runtime/tmux/tmux.go) only checks whether the tmux session exists (tmux has-session). It has no way to tell whether the agent process inside the pane is still running.

The launch command built by buildLaunchCommand always appends a keep-alive shell after the agent's argv:

b.WriteString(strings.Join(parts, " "))
// Keep the tmux session alive after the agent exits so the operator can
// inspect the terminal.
b.WriteString(`; exec "${SHELL:-/bin/sh}" -i`)

; runs unconditionally regardless of exit status, so a crash, an OOM kill, or a clean exit all leave the pane alive on an interactive shell. From that point on, has-session returns true forever, IsAlive reports true forever, and the reaper (backend/internal/observe/reaper/reaper.go, probeOne) only ever reports ProbeAlive to the lifecycle manager — it has no signal that the agent itself is gone.

Impact

  • A session whose agent crashes while in a sticky state (blocked / waiting_input) never gets a ProbeDead fact, so the lifecycle fix in #2749 (for #2745) can't trigger for the tmux runtime — the sticky-state reducer fix is correct, but the fact it depends on is never produced for most real crashes. See @neversettle17-101's review comment on #2749.
  • Same architectural gap as #2089 (filed against the old TypeScript implementation's isAlive()); it was never fixed for the Go rewrite's tmux adapter.
  • Any other automation that trusts IsAlive/ProbeAlive (session restore, dashboard status) is misled the same way.

Repro

  1. Spawn a session on the tmux runtime.
  2. Find the agent's PID inside the pane and kill -9 it (or let it crash), leaving the pane's shell alive.
  3. Call IsAlive (or wait for the reaper's next tick) — it still reports true / ProbeAlive, even though the agent is gone.

Proposed fix

Keep the fix contained to the tmux adapter — no changes needed to ports.ProbeResult, RuntimeFacts, the reaper, or lifecycle.

  1. In buildLaunchCommand, mark the pane via tmux's own per-pane user option right before the keep-alive exec:

    <agent argv...>; tmux set-option -p -t "$TMUX_PANE" @ao_agent_exited 1 2>/dev/null; exec "${SHELL:-/bin/sh}" -i
    
  2. In IsAlive, after has-session succeeds, additionally query that pane option (tmux show-options -v -p -t <id> @ao_agent_exited). If it reads 1, the agent has exited even though the pane survives — return false, not true.

This makes a confirmed agent exit surface as ProbeDead through the existing reaper/lifecycle path unchanged, so #2749's reducer fix actually fires for the case it was written for.

Test plan (TDD)

In backend/internal/adapters/runtime/tmux/tmux_test.go:

  1. TestRuntime_IsAlive_ReportsDeadWhenAgentExitedBehindSurvivingPane — has-session succeeds, pane option reads 1 → IsAlive returns false, nil. Currently fails (returns true).
  2. TestRuntime_IsAlive_ReportsAliveWhenAgentStillRunning — has-session succeeds, pane option unset/empty → IsAlive returns true, nil. Should pass (regression guard).
  3. TestRuntime_IsAlive_SessionMissingStillReportsDead — existing has-session-missing path unchanged.
  4. TestRuntime_IsAlive_PaneOptionProbeErrorReportsFailedProbe — the show-options call itself errors (not "option unset") → surfaced as a probe error, never collapsed to alive or dead.

Related issues

  • #2745 (sticky-state zombie sessions) / #2749 (its fix, pending review)
  • #2089 (same gap, old TS implementation)

anmol0b avatar Jul 18 '26 20:07 anmol0b

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.

For faster context or live questions, you can also join the AO Discord.

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.

somewherelostt avatar Jul 19 '26 15:07 somewherelostt

Triage validation

Analyzed against: 5f018b9ca3992815a0d4b62d74644ffc1b302a0c (upstream/main, 2026-07-20) AO version: dev (locally built Go rewrite) Environment: macOS arm64, Go 1.26.4, tmux 3.6a Confidence: High Priority: P1 — runtime liveness is a core lifecycle input, and a crashed agent can remain indefinitely classified as alive.

The reported root cause is confirmed in the Go rewrite: tmux.Runtime.IsAlive only probes has-session, while buildLaunchCommand unconditionally enters the keep-alive shell after the agent command exits. This prevents the reaper from producing a confirmed dead-runtime fact.

Duplicate/related search confirms:

  • #2089 describes the same architectural gap in the old TypeScript implementation.
  • #2745 is the downstream sticky-state lifecycle symptom.
  • PR #2831 is the active Go adapter fix.

I tested PR #2831 in an isolated worktree. Its tmux adapter tests pass, but the current fallback is too broad: every show-options error is converted to alive=true. On tmux 3.6a, an unset @ao_agent_exited returns exit 1 with invalid option, while show-options -qv returns exit 0 with empty output. The fix should use quiet lookup so unset means alive, marker 1 means dead, and genuine command failures remain probe errors. This preserves the adapter's existing rule that failed probes are never collapsed into alive/dead facts.

nikhilachale avatar Jul 20 '26 16:07 nikhilachale