Codex Desktop subagents can drift across Git branches in a shared workspace
Summary
Codex Desktop multi-agent/subagent workflows can observe or mutate unstable Git branch state when multiple agents operate in the same local checkout. In a workflow with two active task branches, the parent agent repeatedly confirmed that it had switched to the intended branch, but a subagent readback still saw the other branch. After follow-up attempts, the parent shell also observed the checkout drift back to the other branch.
This report intentionally omits private repository names, local filesystem paths, real branch names, project code, and screenshots.
Environment
- Product: Codex Desktop
- Feature area: multi-agent / subagent execution
- Repository type: ordinary local Git checkout, not a detached worktree
- Setup: two local feature branches with active uncommitted work
- Subagent API used:
multi_agent_v1.spawn_agent,send_input,wait_agent,close_agent - No private repository details are included.
What Happened
A parent agent was coordinating a workflow-managed task on an intended task branch, represented here as feature-b. Another active task branch, represented here as feature-a, also existed in the same checkout.
The parent agent switched to feature-b and confirmed the branch using git branch --show-current. It then spawned a worker subagent and required the worker to do a read-only context intake before editing files. The worker was instructed to check the current branch and stop if it was not feature-b.
The worker reported that it was on feature-a, not feature-b, and correctly blocked. The parent switched to feature-b again and confirmed it. A follow-up to the same worker still saw feature-a. A new worker was spawned with permission to run git switch feature-b first, and that worker readback succeeded.
Later, during QA, the branch again drifted to feature-a and had to be switched back. Because of this repeated drift, the task was aborted and the temporary task branch was cleaned up to avoid accidentally editing or cleaning files on the wrong branch.
Reproduction Outline
Using placeholder branch names only:
- Start Codex Desktop on a local Git checkout with two active local branches:
feature-aandfeature-b. - Have the parent agent switch to
feature-b. - Confirm from the parent shell:
git branch --show-current. - Spawn a subagent with instructions to check the branch before editing.
- In the subagent, run
git branch --show-currentandgit status --short --branch. - The subagent may report
feature-aeven though the parent just confirmedfeature-b. - Re-switching in the parent may not update the already-spawned subagent's view.
- Branch state may later drift again during another subagent's verification phase.
Expected Behavior
Codex should make multi-agent Git workspace semantics explicit and safe. One of the following would be acceptable:
- Each subagent receives an isolated worktree tied to the intended branch.
- Or
spawn_agentbinds the subagent to the parent agent's current cwd/worktree/branch at dispatch time. - Or
spawn_agentexposes explicit cwd/worktree/branch parameters and verifies them before edits. - Or Codex warns/refuses when multiple agents are working in a mutable shared checkout where branch state can leak across agents.
If a subagent sees a different branch than the parent requested, Codex should surface a hard blocker before any file write can happen.
Actual Behavior
The visible branch state was not stable across parent and subagents. A subagent could see a different active branch from the parent's confirmed branch, and the parent later observed the checkout back on the other branch. This made it unsafe to continue.
Impact
This can cause:
- edits landing on the wrong branch,
- tests or builds being run against the wrong task state,
- task cleanup restoring or deleting the wrong files,
- contradictory readbacks between parent and subagents,
- loss of confidence in multi-agent work on active repositories.
The risk is high because the issue is not obvious until a careful workflow explicitly checks the branch before every write.
Safety Notes
The workflow blocked before any subagent wrote files on the wrong branch. The workaround was to close the affected subagents, stop the task, and clean up the temporary branch.
Related Context
There are existing issues requesting better subagent cwd/worktree support, but this report is specifically about the bug/risk where parent and subagent branch state can diverge or drift in a shared checkout during an active workflow.