Skip to content

Session lane stays stuck indefinitely when orphaned task has no active embedded run handle #99847

Description

@ralf003

Problem

When a session lane has an orphaned task (active task whose promise will never settle) but no active embedded run handle, recoverStuckDiagnosticSession() unconditionally returns keep_lane on every heartbeat cycle. This creates an infinite recovery loop that blocks the session lane for up to 48 hours.

Symptoms

  • Diagnostic heartbeat repeatedly logs: stuck session recovery outcome: skipped/keep_lane/active_lane_task
  • The session lane's activeCount remains > 0 indefinitely
  • No new work can be processed on the affected session lane
  • The only recovery is a full Gateway restart

Affected Scenarios

  1. Dreaming cron (isolated + lightContext): Narrative session fails with EmbeddedAttemptSessionTakeoverError, the embedded run handle is cleaned up, but the parent cron run session's lane task promise remains pending for 48 hours
  2. Any embedded agent run timeout where the run handle is abandoned
  3. Session takeover errors in general

Root Cause

In the recovery decision tree at recoverStuckDiagnosticSession(), Step 6 (active_lane_task branch) has no time-based escape hatch. Steps 4-5 check isActiveRunProgressStale() against staleActiveProgressAbortMs before deciding to skip. Step 6 unconditionally returns keep_lane when activeCount > 0 and no active embedded run handle is found.

Proposed Fix

Add a time-based escape hatch: when the stuck session age exceeds staleActiveProgressAbortMs (~360s) or allowActiveAbort is true, force-reset the lane via resetCommandLane() and return release_lane/stale_lane_task.

The fix uses params.ageMs directly rather than isActiveRunProgressStale() because the orphaned task scenario typically has queueDepth === 0, which would cause isActiveRunProgressStale() to incorrectly return false.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority user-facing bug, regression, or broken workflow.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:crash-loopCrash, hang, restart loop, or process-level availability failure.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.maturity:stableIssue affects a taxonomy feature currently scored M4/M5.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions