Skip to content

🤖 feat(tasks): let task_remove force-remove a sub-agent with unsaved work - #8153

Merged
ThomasK33 merged 10 commits into
mainfrom
feat/task-remove-force
Nov 12, 2026
Merged

ThomasK33 merged 10 commits into
mainfrom
feat/task-remove-force

Conversation

@ThomasK33

@ThomasK33 ThomasK33 commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Why

The goal, in the maintainer's words: "allow xum to force remove sub-agents and workspaces with a flag. I'm not interested in cleaning up after you."

Today task_remove refuses to remove a sub-agent that holds unsaved work. It then tells the agent that the user must remove the child by hand from the command palette. An agent that owns 13 finished children cannot clean up after itself, and the user must do it.

This PR gives task_remove a force flag. Workspace archive is a separate PR (see Scope).

What changed

  • task_remove takes force: boolean | null (src/common/utils/tools/toolDefinitions.ts). Only force: true forces. false, null and an omitted flag keep the refusal.
  • TaskService models the choice as one typed value: lossyWorkPolicy: "refuse" | "force" (src/node/services/taskService.ts). A model-driven removal always sets it. The palette and automatic cleanup still omit it.
  • Under "force", the removal skips only the unsaved-work refusal. Under both policies these refusals stay: a running background bash process, an external editor or native terminal the user opened, a pending patch artifact, an active sub-agent, and remaining descendants.
  • A forced removal still computes the same description of the lost work, under the same locks, right before the removal. When the removal succeeds, the removed result carries deletedWork (what was deleted, past tense, plus the checkout path and the branch) and paths (the file list). A checkout that could not be checked is removed anyway, and deletedWork says it could not be checked.
  • The branch in deletedWork is the workspace name. I verified that each runtime forks the sub-agent checkout with newWorkspaceName: plan.workspaceName and that removal deletes the branch by that name.
  • The refusal text now tells the agent that force: true exists and when to use it: the user asked for cleanup, or the work is provably saved (pushed, merged, or in an applied patch). It keeps "you must not delete that work yourself to get around it". It no longer sends the user to the command palette.
  • A forced removal that fails after it deleted the checkout (for example when the config write fails) returns the report on the error result too, worded "may have deleted". A retry finds no unsaved work, so the failure is the only place to report it.
  • When the runtime leaves part of the checkout behind (a forced removal then succeeds with warnings), the report says some of the work may remain and lists what was left. It never claims a full deletion that did not happen.
  • WorkspaceService now returns a warning when a forced removal could not delete the checkout, even if the runtime named no leftover (single runtime and multi-project). Before, it logged the failure, removed the row and returned nothing, so no caller could tell that the checkout might still exist. The palette and parent-delete paths still succeed as before and only gain that warning.
  • The task_remove card shows deletedWork and paths on removed and failed rows.
  • Generated docs (docs/hooks/tools.mdx, the docs skill snapshot) follow the schema.

Scope

  • This PR covers sub-agents (task_remove) only. task_workspace_lifecycle (workspace archive) is the sibling PR, and its behavior is unchanged here. The one shared piece is a type: TaskService returns the shared WorkspaceLifecycleResult, so this PR adds the optional deletedWork field to TaskWorkspaceLifecycleBaseResultSchema. The archive tool does not set it.
  • No partial fix for "commits reachable from a remote ref or patch-equivalent to origin/main do not count" (decision D5 below).
  • No new IPC field and no change to the palette (D2).

Tradeoffs

  • The guard against misuse is a prompt rule, not enforcement. The tool description and the refusal text say to set force only when the user asked for cleanup or the work is provably saved. The maintainer accepted this.
  • force is all or nothing for the unsaved-work check. It does not take a list of paths to keep.
  • A forced removal that fails before it deletes anything (mutation gate, a new attempt, a stream stop timeout) still says "may have deleted". Those failures share one error result with the ones that fail after the deletion, and telling them apart would mean matching error text. The wording is hedged and nothing is lost, so I left it.
  • deletedWork is one string, not several fields. The model and the card both read prose, and one field keeps the result small.
  • I renamed the private characterization probe refuseLossySubagentRemoval to settleLossySubagentRemoval in taskService.removeInactiveDescendant.test.ts. The step now returns a refusal or a forced report, so the old name was wrong.

Blast Radius

  • Anyone who can call task_remove on their own descendants can now delete their unsaved work. Scope checks are unchanged, so an agent cannot force-remove another tree's children or a user's workspace.
  • The default call behaves as before, except for the refusal wording.
  • Automatic cleanup, the command palette, and the parent-deletion cascade do not change.

Decisions (root, 2026-11-12)

  • D1. Flag shape: force: z.boolean().nullish(). The handler tests args.force === true.
  • D2. Agent tools only. The palette and IPC removal already delete without this check, after the user confirms.
  • D3 (task_remove half). Force skips only the unsaved-work refusal: uncommitted and untracked files, commits without a ready patch artifact, commits on other branches or the stash, and "cannot verify" failures. It keeps the checks for someone still working in the checkout.
  • D4. A forced removal reports what it deleted: the summary, the checkout path, the branch, and paths. The card shows it.
  • D5. No partial fix. It does not meet the request (a flag), and squash merges are not patch-equivalent per commit, so the flag covers those cases.
  • Threat model, short form:
    • Who can set the flag: any agent that owns the target sub-agent.
    • What can be lost: uncommitted and untracked files, commits not captured by a patch artifact, commits on other local branches or the stash in self-owned repositories.
    • Audit: every forced deletion is reported in the tool result and on the card.
    • Not changed: what removal deletes, scope checks, and the user-mediated paths.

Question for @ThomasK33

force skips only the unsaved-work refusal. A running background bash process and an editor you opened still refuse. Do you want force to skip those too?

  • Option A (current): keep those refusals. The agent can stop its own background bash with task_stop. An editor you opened has no agent-side fix, so those children still need you.
  • Option B: skip them too. The agent never needs you, but it can delete files while a process or editor still writes to them.
  • My recommendation is Option A, because those refusals protect work that is still changing, not saved work.

Screenshots

Dark theme, from the TaskRemoveForcedNarrow story, cropped to the card.

375px:

task_remove card at 375px

Wider card:

task_remove card, wide

Verification

  • taskService*.test.ts plus the cascade and multi-project removal suites: 1810 pass, 0 fail (58 files). All workspaceService*.test.ts: 1248 pass, 0 fail (52 files). Tool, common, browser Tools, workspaceService.pendingRemoval and subagentRemovalWorkCheck suites: 2570 pass, 0 fail (136 files).
  • New tests: a real git checkout with an uncommitted file and an uncaptured commit (refuse refuses, force removes and reports the path, the commit count, the checkout and the branch), an unverifiable checkout, a clean checkout, a removal that leaves files behind, a removal that fails, a runtime that fails to delete the checkout (real worktrees: parent cascade warning and the task_remove report), the same for a multi-project workspace, removal warnings, both policies keep the live-writer guards, force keeps the scope, descendant, active-child and pending-patch refusals, the tool passes force only for true, and the card shows deletedWork.
  • Hand mutants, each turned red by the named test: force skipped, report dropped, live-writer guard dropped (background bash and editor), force skips the scope, descendant, active or pending-patch refusal, refusal dropped, failed-removal report dropped or worded "Deleted", leftover caveat dropped or always added, tool ignores force, tool always forces, tool drops deletedWork, card hides deletedWork.
  • make typecheck, oxlint, ESLint on the 11 changed files, Prettier, docs sync check, make crap-check, make dry-check: pass.
  • make mutate-check for taskService.ts runs only the 10 nearest test files, and they do not include taskService.lifecycle.test.ts. Its survivors are a test-selection artifact. I ran each survivor by hand against the lifecycle suite, and each is now killed.
  • Story play test TaskRemoveForcedNarrow passes (the story sets no Pixel snapshot, because the snapshot budget is at its cap).
  • Not run on my host: hadolint (not installed, and I changed no Dockerfile).

Generated with xum • Model: anthropic:claude-sonnet-5-5 • Thinking: xhigh • Cost: $4.57

@mintlify

mintlify Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
Mux 🟢 Ready View Preview Nov 12, 2026, 3:54 PM

💡 Tip: Enable Automations to automatically generate PRs for you.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T16:04:26.444642Z fdb41a1 Manual request
🔒 Security Review ✅ Completed 2026-11-12T15:58:47.223596Z fdb41a1 Manual request

Security findings

Advisory findings (1)

ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@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: 4769afe202

ℹ️ 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 Resolved
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

🟢 e2e stories (Haiku): 14 passed

22 agent steps · 7 replayed from cache · 15 model calls · 47.1k tokens (27% cached)
Spend: $0.09 of the $1.00 cap (proxy ledger)

All 14 tests in 9 files
Test Agent Time
🟢 chatRestart.e2e.ts · 1 passed 1 step · 1 call 6.0s
🟢 a chat survives a restart of the server 1 step · 1 call 6.0s
🟢 compaction.e2e.ts · 1 passed 1 step · 1 call 4.6s
🟢 /compact replaces the old chat with a summary 1 step · 1 call 4.6s
🟢 pluginTrustRestart.e2e.ts · 1 passed 4 steps · 2 calls 10.7s
🟢 a trusted plugin hook stays trusted after the server restarts 4 steps · 2 calls 10.7s
🟢 settingsRoundTrip.e2e.ts · 1 passed 2 steps · 1 call 9.2s
🟢 a chat survives trips through Settings 2 steps · 1 call 9.2s
🟢 sidebarPerWorkspace.e2e.ts · 1 passed 4 steps · 1 call 4.2s
🟢 a new workspace starts with its right sidebar collapsed while another keeps it open 4 steps · 1 call 4.2s
🟢 smoke.e2e.ts · 1 passed 2 steps · 1 call 2.8s
🟢 the agent opens the playground workspace 2 steps · 1 call 2.8s
🟢 streamErrors.e2e.ts · 1 passed 1 step · 1 call 7.0s
🟢 stream errors show in the chat, and the chat recovers 1 step · 1 call 7.0s
🟢 todoNudge.e2e.ts · 1 passed 1 step · 1 call 3.3s
🟢 the agent finishes open TODO items after the turn-end nudge 1 step · 1 call 3.3s
🟢 touchAlignment.e2e.ts · 6 passed 6 steps · 6 calls 26.8s
🟢 the Settings close button is level with the title on a touch screen 390px wide 1 step · 1 call 3.8s
🟢 the Settings close button is level with the title on a touch screen 768px wide 1 step · 1 call 4.4s
🟢 Backup settings checkboxes are small and level with their labels on a touch phone 1 step · 1 call 4.9s
🟢 the heartbeat checkbox is small and level with its label on a touch phone 1 step · 1 call 3.8s
🟢 a reply's model and time stay on one line on a touch phone 1 step · 1 call 6.7s
🟢 the workspace actions menu stays on the title row on a touch phone 1 step · 1 call 3.2s

e2e 0.20.0 · 1m 18s · web · run artifacts

🟢 e2e Electron stories (Haiku): 3 passed

3 agent steps · 3 model calls · 7.9k tokens (33% cached)
Spend: $0.01 of the $1.00 cap (proxy ledger)

All 3 tests in 3 files
Test Agent Time
🟢 electron/deepLink.e2e.ts · 1 passed 1 step · 1 call 7.0s
🟢 a deep link of a second launch starts a chat in the running app 1 step · 1 call 7.0s
🟢 electron/menuBar.e2e.ts · 1 passed 1 step · 1 call 9.4s
🟢 the workspace menu bar is the desktop title bar 1 step · 1 call 9.4s
🟢 electron/smoke.e2e.ts · 1 passed 1 step · 1 call 5.3s
🟢 Xum Electron opens the playground workspace 1 step · 1 call 5.3s

e2e 0.20.0 · 24.3s · electron · run artifacts

🟢 e2e agent repros (Haiku): no tests selected

Spend: $0.00 of the $1.00 cap (proxy ledger)

e2e 0.20.0 · 6.5s · 2 targets (web, phone) · run artifacts

@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 Security Review · Automatically triggered

Here are some automated security review suggestions for this pull request.

Reviewed commit: 4769afe202

ℹ️ 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.

Comment thread src/node/services/tools/task_remove.ts Resolved
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

Round 2: head 84537a7 fixes the leftover finding (and a failed removal now reports what it may have deleted) and pins the guards that force keeps. The security finding is answered on its thread: it is the intended design.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 84537a7541

ℹ️ 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

🛡️ Codex Security Review · Automatically triggered

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

Reviewed commit: 84537a7541

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.

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

Round 3: head fdb41a1 makes a forced removal return a warning when the runtime could not delete the checkout (so the deleted-work report no longer claims a deletion that did not happen), and gives the real-git tests a longer timeout.

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

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

Reviewed commit: fdb41a1a27

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.

@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: fdb41a1a27

ℹ️ 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 Resolved
Comment thread src/node/services/workspaceService.ts Resolved
@ThomasK33

Copy link
Copy Markdown
Member Author

Merge decision for head fdb41a1: ready, with the remaining items left open.

  • The maintainer asked to land only the major pains, leave the rest open and stop spending. I am treating that as the waiver for the two Codex P2s on this head. Both are report wording, and no work is lost. 🤖 fix(tasks): forced task_remove report wording follow-ups from #8153 #8162 tracks them.
  • Independent verifier: PASS on 84537a7, with a live real-stack run. The delta in fdb41a1 (a leftover warning when a forced runtime deletion fails, plus longer test timeouts) has had no fresh verifier, because the maintainer asked to stop spending.
  • Clean-context advisor: ready with follow-ups, no blocking problem.
  • Codex review rounds: 3 of 6.

@ThomasK33
ThomasK33 added this pull request to the merge queue Nov 12, 2026
Merged via the queue into main with commit 7a371f4 Nov 12, 2026
66 of 69 checks passed
@ThomasK33
ThomasK33 deleted the feat/task-remove-force branch November 12, 2026 16:50

This branch was successfully deployed

1 active deployment
staging - docs — fdb41a1a Deployed Nov 12, 2026 by mintlify[bot]
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