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

Reaper: sticky blocked/waiting_input prevents termination on conclusive ProbeDead (Cursor)

Open LaibaFirdouse opened this issue 1 month ago • 1 comments

Summary

When a Cursor worker is in a sticky activity state (blocked, waiting_input), the reaper can report ProbeDead while isTerminated stays false indefinitely.

RCA status: Confirmed on upstream main at 038547a74 (2026-10-14).

Sticky states are treated as always having “recent” activity. runtimeClearlyDead requires both ProbeDead and !hasRecentActivity, so a conclusive dead probe never satisfies termination while activity remains sticky.

Stickiness is meant to block time-based demotion, not to override a conclusive runtime death fact from the reaper.

Evidence scope: This issue is code / unit-repro only.

Affected code (backend/internal/lifecycle/runtime.go on main)

func runtimeClearlyDead(f ports.RuntimeFacts, activity domain.Activity, now time.Time, window time.Duration) bool {
	observedAt := timeOr(f.ObservedAt, now)
	return f.Runtime == ports.ProbeDead && !hasRecentActivity(activity, observedAt, window)
}

func hasRecentActivity(a domain.Activity, now time.Time, window time.Duration) bool {
	switch {
	// ...
	case a.State.IsSticky():
		return true

ApplyRuntimeObservation (manager.go) only sets IsTerminated when runtimeClearlyDead is true (plus launch/mutation guards).

Expected behavior

If the runtime adapter returns ProbeDead (definitively gone—not ProbeFailed), the reaper should terminate even when activity is blocked or waiting_input (e.g. Cursor dies while paused on an AO permission hook).

Actual behavior

Session remains isTerminated: false while activity is sticky and runtime probes are conclusively dead.

Reproduction

Code / unit level

  1. Persist activity blocked or waiting_input (e.g. permission hook under default permission mode).
  2. Apply RuntimeFacts{Runtime: ProbeDead} via reaper or ApplyRuntimeObservation.
  3. Observe no termination on main.

Proposed fix direction

In runtimeClearlyDead: if f.Runtime == ProbeDead and activity.State.IsSticky(), return true; otherwise keep existing non-sticky logic. Unit tests; optional integration test: permission → blocked → dead probe → reaper tick → terminated.

Environment

  • Harness: cursor, worker.agentConfig.permissions: default
  • Runtime handles: ptyhost-v1:<session-id> (no tmux on machine)

Related

  • #6727

LaibaFirdouse avatar Oct 14 '26 18:10 LaibaFirdouse

I'd like to take this. Plan, following the fix direction above: in runtimeClearlyDead (backend/internal/lifecycle/runtime.go), treat a conclusive ProbeDead as death when the activity state is sticky (blocked / waiting_input). Stickiness keeps blocking the time-based demotion, and ProbeFailed / ProbeAlive still never count as death. Tests: a table test in internal/lifecycle covering sticky and non-sticky states against dead/failed/alive probes, plus an ApplyRuntimeObservation case where a blocked session with a dead probe gets terminated. @LaibaFirdouse, if you were planning to send this yourself, let me know and I'll step back.

pardeep-singh avatar Oct 22 '26 10:10 pardeep-singh