agent-orchestrator icon indicating copy to clipboard operation
agent-orchestrator copied to clipboard

bug(cli,web): orchestrator spawn workspace conflict on fresh install

Open OrcInc opened this issue 6 months ago • 4 comments

Bug Description

Spawn orchestrator fails with "AO found an older orchestrator workspace for {project} but could not safely reuse it automatically" on a completely fresh install with zero prior state.

Reproduction Steps

  1. Ensure no global AO state exists: ~/.agent-orchestrator/ does not exist
  2. Ensure no agent-orchestrator.yaml exists in the target repo
  3. Run ao start in a git repo
  4. Dashboard shows degraded state
  5. Click "Fix Config" (repair config) — fixes the degraded state
  6. Click "Spawn Orchestrator"
  7. Error: AO found an older orchestrator workspace for "feat-reviewer-agent-flow_24136efca8" but could not safely reuse it automatically. Your repository is safe. Review the existing workspace, then either reuse it manually or create a fresh orchestrator workspace.

Expected Behavior

Since there is no prior orchestrator workspace, session metadata, worktree, or git branch, the spawn should succeed cleanly.

Actual Behavior

The spawn flow hits findManagedWorkspace() which reports a conflict. This means either:

  • The "fix config" step creates state that the subsequent spawn considers stale
  • The spawn flow itself creates a worktree/branch, fails partway, and the retry path finds its own half-created state as a "conflict"
  • The ensureOrchestrator → degraded → repair → spawn path creates workspace state during repair that conflicts with the spawn

Key Context

  • No ~/.agent-orchestrator/ directory exists before ao start
  • No agent-orchestrator.yaml exists in the repo
  • No prior worktrees, branches, or session metadata
  • This is reproducible — not a one-time race condition

Root Cause Hypothesis

The degraded state → repair config → spawn orchestrator flow likely creates intermediate state (worktree registration, branch, or session metadata) that the spawn path's findManagedWorkspace() then detects and treats as a pre-existing conflict. The conflict detection in packages/plugins/workspace-worktree/src/index.ts:399-437 doesn't distinguish between "stale state from a previous run" and "state I just created in this session."

Relevant Files

File Role
packages/web/src/app/api/orchestrators/route.ts Error classification (classifySpawnError) — produces the user-facing message
packages/plugins/workspace-worktree/src/index.ts findManagedWorkspace() (lines 399-437) — discovers existing worktrees via git worktree list
packages/core/src/session-manager.ts spawnOrchestrator() (line 1488) — orchestrates the workspace reuse flow

Environment

  • AO version: latest (built from main)
  • OS: (fill in)
  • Agent runtime: (fill in — claude-code, codex, opencode?)

OrcInc avatar May 18 '26 16:05 OrcInc

Additional RCA / repro details

I reproduced this locally on Linux against checkout 5d0b624fbef5668d82672179c48309ea74403933 with ao --version = 0.9.1, Node v24.14.1, in /home/madhav/Documents/repos/open-source/gut_microbiome_project.

Exact reproduced sequence

  1. Start with no ~/.agent-orchestrator/ state and no local agent-orchestrator.yaml in gut_microbiome_project.

  2. Run ao start from the repo.

  3. First-run setup creates /home/madhav/Documents/repos/open-source/gut_microbiome_project/agent-orchestrator.yaml and registers the project globally as gut_microbiome_project_ef4e711acc.

  4. CLI continues startup using the local wrapped config project id gut_microbiome_project and successfully spawns gmp-orchestrator.

  5. Open http://localhost:3000.

  6. Dashboard shows project gut_microbiome_project_ef4e711acc as degraded with:

    Local config at /home/madhav/Documents/repos/open-source/gut_microbiome_project/agent-orchestrator.yaml still uses a wrapped projects: format
    
  7. Click Repair config.

  8. Click Spawn Orchestrator.

  9. API returns 409:

    AO found an older orchestrator workspace for "gut_microbiome_project_ef4e711acc" but could not safely reuse it automatically.
    

State evidence from the reproduction

The first spawn creates the worktree under the un-hashed project namespace:

~/.agent-orchestrator/projects/gut_microbiome_project/worktrees/gmp-orchestrator
branch refs/heads/orchestrator/gmp-orchestrator

After repair, the dashboard/API uses the hashed global project id:

gut_microbiome_project_ef4e711acc

The activity event timeline showed:

15:51:44 session.spawn_started      project=gut_microbiome_project
15:51:46 session.spawned            project=gut_microbiome_project session=gmp-orchestrator
15:53:53 api.project_repaired       project=gut_microbiome_project_ef4e711acc
15:54:11 session.spawn_failed       project=gut_microbiome_project_ef4e711acc session=gmp-orchestrator

Failure reason at 15:54:11:

Found existing worktree for orchestrator branch "orchestrator/gmp-orchestrator" at
"/home/madhav/.agent-orchestrator/projects/gut_microbiome_project/worktrees/gmp-orchestrator",
but it is outside AO-managed worktree directories.

Root cause

The bug is a split project identity created during first-run startup:

  • autoCreateConfig() writes a wrapped local config keyed by the repo basename (gut_microbiome_project).
  • It also registers the same repo globally as the hashed id (gut_microbiome_project_ef4e711acc).
  • CLI startup continues from the wrapped local config and spawns the first orchestrator under ~/.agent-orchestrator/projects/gut_microbiome_project/....
  • The dashboard prefers the global config, sees gut_microbiome_project_ef4e711acc as degraded because the local file is wrapped, and repair rewrites the local config to flat form.
  • After repair, dashboard spawn runs for gut_microbiome_project_ef4e711acc. The session prefix is still gmp, so it looks for branch orchestrator/gmp-orchestrator; findManagedWorkspace() finds the worktree created by the first CLI spawn, but rejects it because it lives under the old un-hashed project storage directory.

So the repair step does not create the conflicting worktree. The initial first-run CLI spawn creates it under the pre-global project id, and the repaired dashboard later operates under the global hashed project id.

Suggested fix direction

autoCreateConfig() should avoid continuing startup from the wrapped local config after global registration. It should either:

  • write the new flat local config shape immediately and reload from the global config, or
  • return the registered global project id/config and spawn the first orchestrator under gut_microbiome_project_ef4e711acc from the beginning.

That would keep the initial worktree path and the dashboard's project id in the same AO storage namespace.

miniMaddy avatar May 22 '26 16:05 miniMaddy

Requirement: the fix for this issue should include integration test coverage.

Please add an integration test that reproduces the fresh-install flow:

  1. Start with no ~/.agent-orchestrator/ state.
  2. Start from a repo with no agent-orchestrator.yaml.
  3. Run the config repair / "Fix Config" path.
  4. Spawn the orchestrator.
  5. Assert that the spawn succeeds and does not report an older orchestrator workspace conflict.

This should cover the degraded-state -> repair-config -> spawn-orchestrator path so we do not regress back into treating newly created intermediate state as stale pre-existing workspace state.

miniMaddy avatar May 22 '26 16:05 miniMaddy

Implementation note for the local fix: I’m keeping the patch scoped to the identity split only.

The first-run path should now write the same behavior-only flat local config shape that the degraded-project repair path writes, then register the project in the global registry so both CLI and dashboard resolve the same hashed project ID. That means this fix deliberately does not copy top-level operational fields like port, defaults.notifiers, notifiers, or notificationRouting into the local flat config.

One possible follow-up for a later PR: decide whether first-run / repair / full migration should have a unified policy for preserving old global operational fields. Today the full migration path preserves those fields in the global config, while degraded repair intentionally only rewrites local project behavior. That broader compatibility policy is separable from this bug, so I’m leaving it out of the minimal fix.

miniMaddy avatar May 23 '26 04:05 miniMaddy

Thanks for raising this. The requested capability is now available in the current Go/Electron version of AO:

The rewrite now has a single SQLite-backed first-run project identity and project-creation flow, replacing the legacy split identity path.

Because the request has been fulfilled in the current codebase, we’re closing this issue as completed.

If this capability is missing or not working as expected in the latest version of AO, feel free to open a new issue with updated details, reproduction steps, logs, and screenshots where applicable.

AO is now available as an app on macOS and Windows, with iOS currently in beta and Android coming soon.

Stay connected with AO:

GitHub: https://github.com/AgentWrapper/agent-orchestrator Discord: https://discord.gg/kGbBRRDPv X: https://x.com/aoagents LinkedIn: https://www.linkedin.com/company/agent-orchestrator Instagram: https://www.instagram.com/aoagents

illegalcall avatar Jul 25 '26 06:07 illegalcall