Skip to content

feat(cli): add a fail-closed --cancel-worktree command that safely tears down a cancelled agent's leased workspace (#230)#231

Merged
qwen-code-dev-bot merged 1 commit into
mainfrom
issue/230-cancellation-cleanup
Jul 23, 2026
Merged

feat(cli): add a fail-closed --cancel-worktree command that safely tears down a cancelled agent's leased workspace (#230)#231
qwen-code-dev-bot merged 1 commit into
mainfrom
issue/230-cancellation-cleanup

Conversation

@qwen-code-dev-bot

Copy link
Copy Markdown
Owner

Summary

Adds an opt-in (--cancel-worktree) fail-closed command that safely tears down a cancelled agent's leased workspace, decomposed from roadmap #39 (isolated parallel agents).

cleanWorktreeLease (#50) only cleans a lease after its work is verified complete and merged; nothing defined the safe teardown path for an agent cancelled mid-work, so a naive cancellation could leave a dangling worktree, an unreleased lease, or silently discard committed work.

Design

  • src/worktree-lease.ts: new cancelWorktreeLease(opts, { force }) (reusing the module's identity/git helpers) plus formatWorktreeCancelResult. Unlike cleanWorktreeLease, cancellation preserves committed work by keeping the lease branch (reporting the preserved, bounded/redacted commits for later integration via Parallel integration: reviewably integrate a parallel agent's branch into the target, preserving commit identity and failing closed on conflict or dirty state #228) and only removing the worktree. It fails closed on uncommitted changes unless force acknowledges the discard, is idempotent (cancelling an absent lease is a no-op), and never touches the parent worktree.
  • src/index.ts: opt-in --cancel-worktree with --cancel-force, wired into the existing leased-worktree mode (JSON + text), exiting 0 on success, 1 on a safety refusal, and 2 on a usage/git error.

Testing

  • tests/unit/cancellation-cleanup.test.ts (8 tests): clean cancellation (worktree removed, branch preserved), preserved-commit reporting, fail-closed on uncommitted work, --cancel-force discard, idempotent no-op on an absent lease, missing-identity refusal, and formatting.
  • tests/integration/cancellation-cleanup.test.ts (4 tests): CLI cancels a clean lease (worktree removed, branch preserved), refuses a dirty lease without --cancel-force (exit 1, worktree retained), discards with --cancel-force (exit 0), and rejects combining --cancel-worktree with --clean-worktree (exit 2).

Gates: typecheck, build, unit (1647), integration (455 + desktop), smoke (51) all pass.

Closes #230

…ars down a cancelled agent's leased workspace (#230)

cleanWorktreeLease (#50) only cleans a lease after its work is verified complete and merged; nothing defined the safe teardown path for an agent cancelled mid-work, so a naive cancellation could leave a dangling worktree, an unreleased lease, or silently discard committed work. Add cancelWorktreeLease plus an opt-in --cancel-worktree [--cancel-force] command that preserves committed work by keeping the lease branch (reporting the preserved commits for later integration via #228), removes the worktree, and fails closed on uncommitted changes unless --cancel-force acknowledges the discard. Idempotent (cancelling an absent lease is a no-op) and never touches the parent worktree.
@qwen-code-dev-bot

Copy link
Copy Markdown
Owner Author

E2E verification

  • Repository: qwen-code-dev-bot/oh-my-cli
  • Pull request: #231
  • Commit: 8cfc25a26e864c1cbd47d5ede5005af8d14d0e19
  • Evidence mode: terminal
  • Result: PASS
Scenario Command Exit Duration
integration npm run test:integration 0 30.068s
smoke npm run smoke 0 3.267s

E2E evidence

Full immutable report

@qwen-code-dev-bot
qwen-code-dev-bot merged commit 6ae165a into main Jul 23, 2026
2 checks passed
@qwen-code-dev-bot
qwen-code-dev-bot deleted the issue/230-cancellation-cleanup branch July 23, 2026 01:36
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.

Parallel safety: on cancellation, safely tear down a parallel agent's leased workspace, preserving committed work and failing closed

1 participant