multica-ai/multica · error · worktreePreservedError

local_directory worktree

Error message

local_directory worktree: %w

What it means

Wraps a worktree-mode Finalize failure in runTask: the agent's changes could not be committed back, so Finalize preserved the worktree instead of deleting it. The task is failed (wrapped in worktreePreservedError) precisely so the preserved worktree holding the agent's changes is named and can be recovered before the GC reclaims it — a 'completed' status would silently lose the work.

Solutions

  1. Inspect the wrapped error from the worktree setup and retry.
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at server/internal/daemon/daemon.go:6559 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of multica-ai/multica@2c0912b6ec (2026-08-15). Data as JSON: /api/errors/430bf0a14d7d3ee2. Report an issue: GitHub.

Appendix: source

Thrown at server/internal/daemon/daemon.go:6559

			if finalizeErr == nil {
				return
			}
			// The agent's changes could not be committed, so Finalize kept the
			// worktree instead of deleting them. Fail the task: a "completed"
			// task whose branch is missing the work reads as success, and the
			// user would never learn the changes are sitting in an env root the
			// GC reclaims on a timer.
			//
			// Wrapped in worktreePreservedError so the cancel path can
			// recognise it: a cancelled task discards its result and error, but
			// THIS error names the preserved worktree holding the agent's work
			// and must ride the cancel ack instead of vanishing into a log.
			// Joined rather than replacing an earlier failure — that one is
			// usually the more useful primary cause, but the preserved path
			// must not be displaced by it.
			taskLog.Error("local_directory: worktree finalize could not persist the agent's changes",
				"error", finalizeErr, "preserved_path", outcome.PreservedPath)
			wrapped := &worktreePreservedError{err: fmt.Errorf("local_directory worktree: %w", finalizeErr)}
			if returnErr == nil {
				returnErr = wrapped
			} else {
				returnErr = errors.Join(returnErr, wrapped)
			}
		}()
	}
	// Workdir is preserved for reuse by future tasks on the same (agent,
	// issue) pair in cloud mode; the work_dir path is stored in DB on task
	// completion and passed back via PriorWorkDir on the next claim, so
	// rewriting the marker block in place is the right behavior.
	//
	// In local_directory mode the workdir is the user's own repo, reuse is
	// already disabled above (see localAssignment == nil), and the brief
	// would otherwise live on inside the user's repository — a subsequent
	// manual `claude` / `codex` run in that directory would pick
	// up stale Multica instructions (issue id, trigger comment id, reply
	// rules) and start acting on the previous task's context. Excise the

View on GitHub (pinned to 2c0912b6ec)