multica/server/internal/daemon
LinYushen 7df5750979
fix(daemon): update existing worktree to latest remote on reuse (#489)
* fix(daemon): update existing worktree to latest remote on reuse

When an agent receives a new task on the same issue, the execution
environment is reused and the repo worktree already exists on disk.
Previously, `multica repo checkout` would fail because `git worktree add`
cannot create a path that already exists — so the agent worked on stale
code from the prior task.

Now `CreateWorktree` detects existing worktrees and updates them:
fetch origin, reset working tree, then checkout a new branch from the
latest remote default branch. The previous task's branch is preserved.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(daemon): propagate actual branch name and use correct ref in worktree reuse

- Return (string, error) from updateExistingWorktree so collision-retried
  branch name propagates to WorktreeResult
- Use baseRef directly instead of origin/baseRef — bare clone refspec maps
  remote branches to local refs, so remote-tracking refs may not exist
- Remove redundant fetch (worktree shares object store with bare clone)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-08 14:13:44 +08:00
..
execenv Merge pull request #461 from multica-ai/agent/j/70455bdb 2026-04-07 17:29:46 +08:00
repocache fix(daemon): update existing worktree to latest remote on reuse (#489) 2026-04-08 14:13:44 +08:00
usage fix(daemon): fix Codex token usage parsing from session logs 2026-03-28 00:03:47 +08:00
client.go feat(runtime): support CLI update from web runtime page (#331) 2026-04-02 14:12:49 +08:00
config.go feat(agent): add OpenClaw runtime support 2026-04-07 14:40:51 +08:00
daemon.go fix(daemon): ensure multica CLI is on PATH in agent task environment 2026-04-07 15:01:48 +08:00
daemon_test.go refactor: decouple task lifecycle from issue status (#151) 2026-03-27 18:30:21 +08:00
health.go feat(daemon): agent-driven repo checkout with bare clone cache 2026-03-29 19:37:48 +08:00
helpers.go fix(daemon): prevent stuck tasks from blocking queue and add concurrent execution 2026-03-30 03:08:52 +08:00
prompt.go refactor: decouple task lifecycle from issue status (#151) 2026-03-27 18:30:21 +08:00
types.go feat(agents): reply as thread instead of top-level comment (#205) 2026-03-31 13:48:39 +08:00