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

Power-off: terminal ENDED and OSC flash while session stays idle/no_signal and not terminated (Cursor)

Open LaibaFirdouse opened this issue 1 month ago • 1 comments

Summary

On Linux, a Cursor worker can show TERMINAL ENDED / [process exited] and a brief OSC escape flash in the embedded terminal after full power-off, while the session remains isTerminated: false with activity idle and display status no_signal.

Upstream reference: 038547a74 on main.

Root cause: Not proven yet — needs reaper/reconcile logs (ProbeDead vs ProbeFailed, and whether boot Reconcile ran vs the daemon stayed up through sleep).

UI: terminal pane shows process ended; summary shows Idle / no signal; session still treated as live.

Screenshots

TERMINAL ENDED — terminal process ended, session not marked terminated (Permission repro, session 33):

Screenshot 2026-10-14 20-47-35

OSC escape sequences in the terminal pane (Referenced from Cursor hook audit session because Permission repro,session 33's couldn't be captured due to speed):

Screenshot 2026-10-14 20-57-21

Session loads and Activity Idle in the rail while the chat still shows permission / approval pause (Permission repro):

Screenshot 2026-10-14 20-47-55

What upstream main does (relevant paths)

Layer Behavior on 038547a74
Activity observer Cursor is not a continuous terminal reconciler (unlike Muse). Reconciliation mostly targets active + stale output, not blocked.
Sticky blocked applyToolPrecedence only clears blocked on turn boundaries or a correlated post-tool event — not generic terminal-idle.
Agent exited hook ActivityExited does not set IsTerminated; reaper or explicit kill/shutdown does.
Reaper ProbeDead → may terminate only if runtimeClearlyDead (#6726 if still blocked; if idle, must pass 60s defaultRecentActivityWindow since LastActivityAt).
Probe ambiguity (conpty) Dial refused → dead (false, nil); timeout/other → (false, err) → reaper ProbeFailed → no terminate (by design).
Boot Reconcile For live DB rows: if runtime is definitively dead → saveAndTeardownOne → MarkTerminated + restore marker. If probe errors → leave session live (reconcileLive returns error, logged).

Plausible RCA (needs log confirmation)

  1. idle + no_signal after relaunch: MarkSpawned seeds idle and clears FirstSignalAt; deriveStatus can show no_signal after the 90s grace even when the terminal looks empty — consistent with restore/relaunch, not necessarily the permission hook receipt.
  2. Runtime probe not conclusively dead: After reboot or flaky loopback, ProbeFailed (timeout) leaves the row live while the Electron terminal shows process exited (UI truth ≠ reaper fact).
  3. blocked → idle without terminate: Not explained by the terminal observer alone for Cursor+blocked. Candidates: turn-boundary hook during crash/teardown, activity API update, MarkSpawned after partial recovery, or stale ExpectedUpdatedAt reconciliation. Needs logs: reaper:, ApplyActivitySignal, reconcile, conpty probe outcome.

Evidence strength: API snapshots + UI are strong; a single root cause needs ProbeDead vs ProbeFailed at reaper time and whether Reconcile ran vs daemon stayed up through sleep.

Expected behavior

If the Cursor/PTY runtime is gone after power-off (terminal ENDED), the session should converge to terminated or a clear dead-runtime state while AO keeps running, not only on app/daemon shutdown.

Graceful shutdown SaveAndTeardownAll already MarkTerminated by design — “fixed when I quit AO” may be that path, not the reaper catching up.

What to capture for investigation

One session id and timestamps; grep daemon/Electron logs for that id across the power cycle:

  • Reaper facts per tick: ProbeDead vs ProbeFailed vs alive
  • Activity state at probe time
  • reconcile: adopt vs save-teardown vs probe error
  • Any MarkSpawned / RestoreAll on boot

Environment

  • Linux (kernel 7.x), AO data under ~/.ao/data, loopback daemon (port 3001 in testing)
  • Cursor runtime handles: ptyhost-v1:<session-id> (no tmux on this machine)
  • Logs often in the Electron Forge terminal, not a stable ~/.ao/daemon.log

Related

  • #6726 — separate confirmed logic bug: sticky blocked/waiting_input prevents runtimeClearlyDead when activity stays sticky with ProbeDead

LaibaFirdouse avatar Oct 14 '26 18:10 LaibaFirdouse

@codebanditssss any updates on this issue?

Vaibhaav-Tiwari avatar Oct 30 '26 13:10 Vaibhaav-Tiwari