t3code icon indicating copy to clipboard operation
t3code copied to clipboard

[Bug]: task_cancel leaves the parent's queued t3_thread_send follow-ups held, and "Turn into project" then reports the stopped child as "still working"

Open loosekite opened this issue 4 days ago • 0 comments

What happened

"Turn into project" on a No project thread failed with this server error (ScratchThreadPromotion):

"<child thread title>" is still working. Finish or stop it first.

Nothing was working. The named thread was a delegated child of this thread that a parent agent had stopped with task_cancel 11 days earlier. Three follow-ups that the parent had sent with t3_thread_send (mode: "queue") while the child was running were still queued with queueHeld: true. They had never started.

Every status surface treats those runs as idle. t3_thread_list reported the child as interrupted, it had no pending background work, and child threads are not in the main list. Only t3_thread_read showed status: "queued". As a result, the error named a thread that looked finished, and there was no visible way to find what was blocking.

Cancelling the three runs with t3_queue cancel cleared the block. A second child of the same parent was stuck the same way and would have blocked the next attempt.

Root cause

task_cancel does not cancel follow-ups that the parent queued into the child; it only holds them.

  1. cancelTask → stopChild dispatches thread.stop on the child. dispatchThreadStop interrupts with holdQueue: true, so holdStoppedThread marks every queued run queueHeld: true.
  2. The loop that follows cancels only queued runs where run.delegatedTaskId === input.taskId || run.id === current.childRunId (OrchestratorMcpService.ts#L3220-L3243).
  3. A t3_thread_send follow-up never matches that condition. In the projection, the three stuck runs had delegatedTaskId set to their own thread-send: task nodes, not to the cancelled delegate-task: node. On 0.1.13, a fresh repro's follow-up run has no delegatedTaskId at all. In both cases the run's message has senderThreadId equal to the parent thread.
  4. The tool contract says the opposite: "Stops its running and queued turns … including later runs in its child thread" (tools.ts#L120).

The leftover held runs then hit an inconsistency:

  • threadHasUnfinishedWork (Orchestrator.ts#L629-L644) counts any queued run, held or not, as unfinished. ScratchThreadPromotion reports that as "is still working" (ScratchThreadPromotion.ts#L106-L108).
  • latestUnheldRun, hasPendingChildRuns, and the active-work SQL queries all exclude held queued runs. That is why the list says interrupted.

Related: #39511 covers the same hold-on-task_cancel path, from the angle of the owner never being told and settlement cancelling silently. #26119 documented the narrow cancel loop. This issue covers the follow-ups the parent itself sent, which the tool description says task_cancel cancels, and the misleading "Turn into project" error they cause.

Steps to reproduce (0.1.13, server on Linux)

  1. From a No project thread, delegate_task a child that runs sleep 150.
  2. While it runs, t3_thread_send to the child thread with mode: "queue".
  3. task_cancel the task from step 1. It returns cancel_requested.
  4. Check the child's runs. Run 1 is interrupted. Run 2 is queued with queueHeld: true. t3_thread_list shows the child as interrupted; t3_thread_read shows it as queued.
  5. "Turn into project" on the parent now fails with "<child>" is still working. Finish or stop it first. This step was observed in the original incident. In the repro I checked the state only and did not retry the promotion.

Expected

  • task_cancel cancels queued runs in the child thread that the parent sent, as its description says, not just the task's own run.
  • If held queued runs are still meant to block promotion, the error says so and is actionable. For example: "<child>" has 3 paused queued messages. Send or cancel them first., with a link to the thread.

Suggested fix

In stopChild, also cancel queued runs whose message senderThreadId is the caller (scope.thread.threadId), alongside the existing delegatedTaskId / childRunId match. This covers both run shapes seen above.

Separately, have ScratchThreadPromotion distinguish held queued runs from active work in its error.

These fixes are proposals; I have not built or tested them against the repo.

loosekite avatar Nov 28 '26 00:11 loosekite