@@ -252,7 +252,8 @@ export async function recoverStuckDiagnosticSession(
252252 }
253253 }
254254
255- const queuedCount = sessionLane ? getCommandLaneSnapshot ( sessionLane ) . queuedCount : 0 ;
255+ const postAbortLaneSnapshot = sessionLane ? getCommandLaneSnapshot ( sessionLane ) : undefined ;
256+ const queuedCount = postAbortLaneSnapshot ?. queuedCount ?? 0 ;
256257 // A task id active now but not before the abort means the lane already
257258 // unwedged and pumped fresh work; resetting it would double-run the lane.
258259 const laneStartedFreshTask =
@@ -261,10 +262,23 @@ export async function recoverStuckDiagnosticSession(
261262 // Queued turns ride the session queue (params.queueDepth), not only the lane
262263 // queue; without this signal a cleanly aborted wedged lane never resets.
263264 const hasQueuedSessionWork = ( params . queueDepth ?? 0 ) > 0 ;
265+ // A run may have been aborted+drained from the embedded-run registry while its
266+ // underlying command-lane task is still executing (e.g. waitForCompactionRetry
267+ // or in-flight tool execution). If the lane is still blocked by pre-existing
268+ // active tasks we must reset it so queued work can drain.
269+ const laneStillBlockedByPreExistingTask =
270+ ! laneStartedFreshTask &&
271+ postAbortLaneSnapshot !== undefined &&
272+ postAbortLaneSnapshot . activeCount > 0 ;
264273 const released =
265274 sessionLane &&
266275 ! laneStartedFreshTask &&
267- ( queuedCount > 0 || hasQueuedSessionWork || ! activeSessionId || ! aborted || ! drained )
276+ ( queuedCount > 0 ||
277+ hasQueuedSessionWork ||
278+ ! activeSessionId ||
279+ ! aborted ||
280+ ! drained ||
281+ laneStillBlockedByPreExistingTask )
268282 ? resetCommandLane ( sessionLane )
269283 : 0 ;
270284
0 commit comments