Skip to content

fix(daemon): precheckout task repos before agent start (MUL-2454)#2915

Open
KiwiGaze wants to merge 1 commit into
multica-ai:mainfrom
KiwiGaze:kiwi/fix-2639-daemon-precheckout
Open

fix(daemon): precheckout task repos before agent start (MUL-2454)#2915
KiwiGaze wants to merge 1 commit into
multica-ai:mainfrom
KiwiGaze:kiwi/fix-2639-daemon-precheckout

Conversation

@KiwiGaze
Copy link
Copy Markdown
Contributor

@KiwiGaze KiwiGaze commented May 20, 2026

What does this PR do?

Fixes daemon-side repo isolation for local agent tasks so agents start with managed worktrees instead of needing to discover and run multica repo checkout themselves.

flowchart TD
  A["Daemon claims task"] --> B["registerTaskRepos(task.Repos)"]
  B --> C["Prepare or reuse isolated workdir"]
  C --> D["preCheckoutTaskRepos"]
  D --> E{"Repo cache ready?"}
  E -- "yes" --> F["Create managed git worktree under workdir"]
  E -- "no" --> G["Keep fallback checkout instructions"]
  F --> H["Inject runtime config with LocalPath"]
  G --> H
  H --> I["Start agent in isolated workdir"]
  I --> J["After completion: audit workdir for raw clones"]
Loading

Root cause: agents could ignore the runtime brief and run raw git clone, bypassing the daemon repo cache and per-task worktree isolation. This change moves the happy path into the daemon before the agent starts, while retaining the existing checkout command as a fallback when precheckout cannot complete.

Related Issue

Fixes #2639

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • Tests (adding or improving test coverage)

Changes Made

  • server/internal/daemon/daemon.go
    • Adds daemon precheckout for task repos after the workdir exists and before runtime config injection.
    • Ensures project-only repo URLs can sync even when GetWorkspaceRepos does not return them.
    • Adds a post-run audit warning for raw .git/ clone directories in the task workdir.
  • server/internal/daemon/execenv/execenv.go
    • Adds RepoContextForEnv.LocalPath for already-created worktree paths.
  • server/internal/daemon/execenv/runtime_config.go
    • Renders checked-out repo paths in the injected runtime brief.
    • Keeps explicit multica repo checkout fallback instructions when precheckout fails.
  • Tests cover successful precheckout, project-only repo precheckout, failure fallback behavior, nil repo cache behavior, raw clone auditing, and runtime brief rendering.

How to Test

  1. Run targeted daemon verification:

    cd server
    go test -count=1 ./internal/daemon ./internal/daemon/execenv ./internal/daemon/repocache
  2. Manual test case: Project-Only Repo Precheckout Creates Managed Worktree

    Setup:

    • Run the local web app, server, and daemon.
    • Use a workspace project with a GitHub repo project resource, for example https://github.com/octocat/Hello-World.git.
    • Create an issue in that project and assign it to an online local agent.
    • Use a prompt that asks the agent to inspect its injected context and workdir, but does not ask it to run multica repo checkout or git clone.

    Steps:

    1. In Chrome, open the issue and wait for the local agent run to complete.
    2. Open the issue sidebar's Execution log and confirm the run is completed.
    3. In local Postgres, find the task row for that issue and record agent_task_queue.work_dir.
    4. Inspect <work_dir>/AGENTS.md or <work_dir>/CLAUDE.md and confirm the repository line says already checked out at <work_dir>/<repo-name>.
    5. Inspect <work_dir>/<repo-name>/.git and confirm it is a file whose contents point into the daemon repo cache worktrees directory, not a .git/ directory.
    6. Query persisted task_message rows for that task and confirm there are no git clone or multica repo checkout tool invocations.

    Expected result:

    • The agent starts with a managed repo worktree already present under its isolated task workdir.
    • The injected runtime brief includes the prechecked local path.
    • The task logs show the agent did not need to run checkout or raw clone commands.
    • Chrome shows the corresponding issue run as completed in the Execution log.

    Local evidence from this PR branch:

    • I ran this test with a local verification issue in the Kiwi-Labs workspace, using Hello-World as the project repo resource.
    • The task workdir contained Hello-World/README and a .git pointer file under the task workdir.
    • The persisted task logs had zero git clone and zero multica repo checkout commands for the verified runs.

Known local caveat: go test ./... currently fails in unrelated server/pkg/agent fake CLI timeout tests (codex, opencode, copilot, claude). The touched daemon, execenv, and repo-cache packages pass uncached.

Checklist

  • I have included a thinking path that traces from project context to this change
  • I have run tests locally and documented the result
  • I have added or updated tests where applicable
  • I have considered and documented risks above
  • I will address all reviewer comments before requesting merge

Risks

  • Precheckout adds a cache/worktree step before agent startup, so repo sync failures now happen earlier. The implementation logs warnings and preserves fallback checkout instructions rather than failing the task outright.
  • Reused workdirs update an existing managed worktree through the repo-cache path, matching existing checkout behavior.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 20, 2026

@KiwiGaze is attempting to deploy a commit to the IndexLabs Team on Vercel.

A member of the Team first needs to authorize it.

@Bohan-J Bohan-J changed the title fix(daemon): precheckout task repos before agent start fix(daemon): precheckout task repos before agent start (MUL-2454) May 20, 2026
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.

[Bug]: Agents skip worktree isolation, work in wrong directories, and cause repo conflicts

1 participant