Bug Description
When a codebase is registered as a managed clone (stored under ~/.archon/workspaces/), Archon calls syncWorkspace on every incoming message. The call always
passes baseBranch = undefined, which causes syncWorkspace to auto-detect the remote's default branch — typically main — and run git reset --hard origin/main
on the source clone.
This silently and repeatedly destroys all local feature-branch work in the source clone, even when a different branch is checked out and the user never asked
Archon to touch it.
To Reproduce
- Register a repository as a codebase and let Archon clone it (managed clone under ~/.archon/workspaces/).
- Check out a feature branch (e.g. task-rewrite-v1-to-python) in the source clone.
- Do some work — commit or leave files staged/unstaged.
- Send any chat message to Archon with that codebase selected.
- The source clone silently resets to origin/main. All local branch work is gone.
The reset happens on every message. There is no warning and no error — the UI just shows the AI response as if nothing happened.
Expected Behavior
syncWorkspace should respect the default_branch value stored in remote_agent_codebases. If a non-default branch is configured for a codebase, the sync should
fetch and reset to origin/, not origin/main.
Root Cause
packages/core/src/orchestrator/orchestrator-agent.ts around line 407:
// Before fix — always passes undefined as baseBranch
syncResult = await syncWorkspace(toRepoPath(codebase.default_cwd), undefined, {
resetAfterFetch: isManagedClone,
});
syncWorkspace (in packages/git/src/repo.ts) resolves undefined via getDefaultBranch(), which queries the remote's HEAD — always returning main for most
repositories — and then runs git reset --hard origin/main.
The default_branch column in remote_agent_codebases (default value 'main') is never read at this call site.
Fix
Pass codebase.default_branch as baseBranch:
const configuredBranch = codebase.default_branch
? toBranchName(codebase.default_branch)
: undefined;
syncResult = await syncWorkspace(toRepoPath(codebase.default_cwd), configuredBranch, {
resetAfterFetch: isManagedClone,
});
Additionally, when a repository is registered (cloned), default_branch should be set to the branch actually checked out after cloning — not left as the
hardcoded schema default 'main'.
Related Issues
Impact
- Any user working on a feature branch with a managed clone loses work silently on every message.
- The git reflog is the only recovery path; once TTL expires the commits are unrecoverable.
- No error is surfaced to the user — the AI response appears normally.
Bug Description
When a codebase is registered as a managed clone (stored under ~/.archon/workspaces/), Archon calls syncWorkspace on every incoming message. The call always
passes baseBranch = undefined, which causes syncWorkspace to auto-detect the remote's default branch — typically main — and run git reset --hard origin/main
on the source clone.
This silently and repeatedly destroys all local feature-branch work in the source clone, even when a different branch is checked out and the user never asked
Archon to touch it.
To Reproduce
The reset happens on every message. There is no warning and no error — the UI just shows the AI response as if nothing happened.
Expected Behavior
syncWorkspace should respect the default_branch value stored in remote_agent_codebases. If a non-default branch is configured for a codebase, the sync should
fetch and reset to origin/, not origin/main.
Root Cause
packages/core/src/orchestrator/orchestrator-agent.ts around line 407:
// Before fix — always passes undefined as baseBranch
syncResult = await syncWorkspace(toRepoPath(codebase.default_cwd), undefined, {
resetAfterFetch: isManagedClone,
});
syncWorkspace (in packages/git/src/repo.ts) resolves undefined via getDefaultBranch(), which queries the remote's HEAD — always returning main for most
repositories — and then runs git reset --hard origin/main.
The default_branch column in remote_agent_codebases (default value 'main') is never read at this call site.
Fix
Pass codebase.default_branch as baseBranch:
const configuredBranch = codebase.default_branch
? toBranchName(codebase.default_branch)
: undefined;
syncResult = await syncWorkspace(toRepoPath(codebase.default_cwd), configuredBranch, {
resetAfterFetch: isManagedClone,
});
Additionally, when a repository is registered (cloned), default_branch should be set to the branch actually checked out after cloning — not left as the
hardcoded schema default 'main'.
Related Issues
becomes the UI layer needed to let users change default_branch without touching the database directly.
Impact