gastownhall/beads · warning

worktree removal interrupted after target resolution: %w

Error message

worktree removal interrupted after target resolution: %w

What it means

This error reports that a caller-injected interruption hook (`afterTargetResolution`) returned an error while bd was building the worktree removal plan, after the target worktree had been resolved but before any mutation. bd wraps the hook's error so it is clear the abort happened at the 'after target resolution' checkpoint of the removal pipeline. It is a deliberate abort mechanism (used by tests/preview flows), not an internal fault.

Source

Thrown at cmd/bd/worktree_cmd.go:1258

		return nil, err
	}
	plan := &worktreeRemovalPlan{
		force: options.force.value,
		prepareFacts: worktreeremove.PrepareFacts{
			Registration: worktreeremove.Present,
		},
	}
	if targetEntry.isMain {
		plan.prepareFacts.Target = worktreeremove.PrimaryWorktree
		return plan, nil
	}
	if sameWorktreePath(targetEntry.path, currentRoot) {
		plan.prepareFacts.Target = worktreeremove.CurrentWorktree
		return plan, nil
	}
	if afterTargetResolution != nil {
		if err := afterTargetResolution(); err != nil {
			return nil, fmt.Errorf("worktree removal interrupted after target resolution: %w", err)
		}
	}

	mainCommonDirOutput, err := gitRunner.output(
		ctx,
		mainWorktree.path,
		"rev-parse",
		"--path-format=absolute",
		"--git-common-dir",
	)
	if err != nil {
		return nil, fmt.Errorf("failed to resolve repository common git directory: %w", err)
	}
	mainCommonDir := filepath.Clean(strings.TrimSpace(string(mainCommonDirOutput)))

	target, err := inspectWorktreeTarget(ctx, gitRunner, targetEntry)
	if err != nil {
		return nil, err

View on GitHub (pinned to 71377f2769)

Solutions

  1. Inspect the wrapped cause (%w) to see why the hook aborted; that cause is the real error
  2. Re-run the removal and accept the confirmation/hook when prompted
  3. If a test or script injects the abort, fix the hook to return nil when removal should proceed

Example fix

// before
afterTargetResolution: func() error { return errors.New("user cancelled") }
// after: proceed with removal
afterTargetResolution: nil // or return nil from the hook
Defensive patterns

Strategy: try-catch

Validate before calling

null

Try / catch

plan, err := buildWorktreeRemovalPlan(ctx, git, name, afterHook)
var we *fmt.wrapError
if err != nil && errors.As(err, &we) {
	return fmt.Errorf("removal aborted at afterTargetResolution: %v", we.Unwrap())
}

Prevention

When it happens

Trigger: Any worktree removal that passes an `afterTargetResolution` callback (testing hooks, preview/confirm flows) where the callback returns a non-nil error — e.g. a user answering 'no' at a confirmation prompt or a test injecting an abort.

Common situations: Interactive confirmation cancelled by the user; automated tests simulating a crash between target resolution and common-dir inspection; external tooling aborting the plan mid-way.

Related errors


AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30). Data as JSON: /api/errors/46b3433c51adc150. Report an issue: GitHub.