Skip to content

fix: cascade-remove inactive descendants when deleting archived workspaces - #3982

Open
ethanndickson wants to merge 5 commits into
mainfrom
fix/archived-workspace-shift-delete
Open

fix: cascade-remove inactive descendants when deleting archived workspaces#3982
ethanndickson wants to merge 5 commits into
mainfrom
fix/archived-workspace-shift-delete

Conversation

@ethanndickson

Copy link
Copy Markdown
Member

Summary

Shift+click to bypass the force-delete modal on archived workspaces stopped working after the persistent sub-agent lifecycle change (PR #3825).

Root Cause

removeUnlocked had a guard using hasDescendantAgentTasks() that checks for any descendants (active or inactive) and fires before the force flag is even evaluated. Since PR #3825 made completed sub-agents persist as inactive children in config, any workspace that ever spawned a sub-agent could never be deleted — shift+click bypass, force delete, and normal delete all hit this guard.

Fix

  • Guard: Changed from hasDescendantAgentTaskshasActiveDescendantAgentTasksForWorkspace — only blocks deletion when children are actively running (queued/starting/running)
  • Cascade removal: Before removing the parent, cascade-remove all inactive descendants deepest-first via removeUnlocked(childId, true). This mirrors what task_remove requires users to do manually but happens automatically during workspace deletion
  • New method: Added listDescendantAgentTaskIdsDeepestFirst() to TaskService for the cascade ordering

What this fixes

  • Shift+click delete on archived workspaces works again (skips force-confirm modal)
  • Regular and bulk delete on archived workspaces with finished sub-agents works again
  • Active sub-agents still correctly block parent deletion

Risks

Low — the safe default (block on active descendants) is preserved. Only inactive (reported/interrupted) descendants are cascade-removed, and each child removal goes through the full removeUnlocked path including all cleanup steps.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3eeef7a926

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/node/services/workspaceService.ts Outdated
Comment thread src/node/services/workspaceService.ts
Comment thread src/node/services/workspaceService.ts Outdated
Comment thread src/node/services/workspaceService.ts
Comment thread src/node/services/workspaceService.ts
Comment thread src/node/services/workspaceService.ts Outdated
@ethanndickson

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 5bda4fa207

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

This comment has been minimized.

…paces

The persistent sub-agent lifecycle change (PR #3825) made completed
sub-agents persist in config as inactive children. But removeUnlocked's
guard used hasDescendantAgentTasks() which checks for ANY descendants
(active or inactive), and fires before the force flag is checked. This
meant any workspace that ever spawned a sub-agent could never be deleted
— shift+click bypass, force delete, and normal delete all failed.

Fix:
- Change the guard to hasActiveDescendantAgentTasksForWorkspace so only
  running/queued children block deletion
- Cascade-remove inactive descendants deepest-first before removing the
  parent, mirroring what task_remove requires users to do manually
- Add listDescendantAgentTaskIdsDeepestFirst() to TaskService for the
  cascade ordering
Address Codex review comments by replacing the inline cascade loop in
WorkspaceService.removeUnlocked() with a dedicated TaskService method
(cascadeRemoveInactiveDescendantsWhileTaskTreeLocked) that includes:

- Git-patch-artifact lock + wait before removal (comment #3)
- Ownership tombstone persistence (comment #6)
- Force-flag passthrough from parent instead of hardcoding true (comment #1)
- Active/streaming safety checks per descendant

The new method is designed to run inside an already-held task-tree lifecycle
lock, avoiding deadlock by calling removeWhileTaskTreeLocked directly.
@ethanndickson
ethanndickson force-pushed the fix/archived-workspace-shift-delete branch from 5bda4fa to 7da5387 Compare August 27, 2026 09:21

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7da5387e1b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/node/services/taskService.ts Outdated
@ethanndickson

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@ethanndickson

Copy link
Copy Markdown
Member Author

@codex review

@ethanndickson

Copy link
Copy Markdown
Member Author

@codex review

@ethanndickson

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 8111f648a5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: 8111f648a5

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant