fix: make removeClineFromStack() delegation-aware to prevent orphaned parent tasks#11302
Draft
roomote[bot] wants to merge 2 commits intomainfrom
Draft
fix: make removeClineFromStack() delegation-aware to prevent orphaned parent tasks#11302roomote[bot] wants to merge 2 commits intomainfrom
roomote[bot] wants to merge 2 commits intomainfrom
Conversation
Contributor
Author
Re-reviewed the incremental changes (45d756e). The previously flagged nested delegation issue is resolved via the
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
… parent tasks When a delegated child task is removed via removeClineFromStack() (e.g., Clear Task, navigate to history, start new task), the parent task was left orphaned in "delegated" status with a stale awaitingChildId. This made the parent unresumable without manual history repair. This fix captures parentTaskId and childTaskId before abort/dispose, then repairs the parent metadata (status -> active, clear awaitingChildId) when the popped task is a delegated child and awaitingChildId matches. Parent lookup + updateTaskHistory are wrapped in try/catch so failures are non-fatal (logged but do not block the pop). Closes #11301
241c0a2 to
45d756e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related GitHub Issue
Closes: #11301
Description
This PR attempts to address Issue #11301 where parent tasks become orphaned in a
delegatedstate when a child task is removed viaremoveClineFromStack().Root cause:
removeClineFromStack()is a pure pop-and-dispose operation with no delegation awareness. When a delegated child task is removed (via Clear Task, navigate to history, or start new task), the parent'sHistoryItemremains stuck withstatus: "delegated"and a staleawaitingChildId.Fix: Makes
removeClineFromStack()the delegation-aware chokepoint. After popping and disposing the child task, it now:parentTaskIdandchildTaskIdbefore abort/dispose (sinceabortTask(true)is async and the task reference is cleared later)HistoryItemviagetTaskWithId(parentTaskId)status === "delegated"andawaitingChildId === childTaskId, updates parent metadata:status->"active",awaitingChildId->undefinedupdateTaskHistory()This is a lightweight metadata repair (~20 lines), not a full delegation return. The parent simply becomes resumable from the task history list. All three affected paths (and any future callers) go through
removeClineFromStack(), so this single fix covers everything.Test Procedure
src/__tests__/removeClineFromStack-delegation.spec.ts:provider-delegation.spec.ts,history-resume-delegation.spec.ts,nested-delegation-resume.spec.ts,single-open-invariant.spec.ts)ClineProvider.spec.ts(88 tests) continues to passPre-Submission Checklist
Documentation Updates
Additional Notes
Feedback and guidance are welcome.
Important
Enhance
removeClineFromStack()inClineProvider.tsto update parent task metadata when a delegated child is removed, preventing orphaned parent tasks.removeClineFromStack()inClineProvider.tsnow updates parent task metadata when a delegated child is removed, changingstatusfromdelegatedtoactiveand clearingawaitingChildId.skipDelegationRepairoption is true.removeClineFromStack-delegation.spec.tswith tests for parent metadata repair, non-delegated task removal, mismatchedawaitingChildId, non-delegated parent status, error handling, empty stack, and nested delegation transitions.provider-delegation.spec.ts,history-resume-delegation.spec.ts, and others continue to pass.This description was created by
for 241c0a2. You can customize this summary. It will automatically update as commits are pushed.