[Bug]: Background fallback retry schedules a replacement without retiring the predecessor when session identity is missing (dual-writer worktree risk)
Bug Description
In the background-agent fallback-retry path, BackgroundManager.tryFallbackRetry (bundle fallback-retry-handler, source packages/omo-opencode/src/features/background-agent/attempt-lifecycle.ts) selects the next model and schedules the replacement attempt via scheduleRetryAttempt -> processKey.
The predecessor attempt is retired before the replacement is scheduled only when a failed session identity is available. One branch skips retirement entirely:
const failedAttempt = getAttempt(task, failedAttemptID);
const failedSessionID = failedAttempt?.sessionId ?? previousSessionID;
if (failedSessionID) {
// retirement gate: abort + wait for the exact predecessor to retire
...
} else if (failedAttempt?.status !== "pending") {
// fail-closed block when there is no identity
...
}
const nextAttempt = failedAttemptID
? scheduleRetryAttempt(task, failedAttemptID, nextModel, errorInfo.message)
: undefined;So the combination failedSessionID absent AND failedAttempt.status === "pending" falls straight through to scheduleRetryAttempt with no retirement check at all. If the predecessor is in fact still alive (a transient provider error declared the attempt failed while the original turn kept running), the replacement is bound to the same task + worktree and both sessions can write the same git worktree concurrently — the classic dual-writer corruption risk (corrupted index, mixed/lost changes, a commit containing another attempt's files).
[BACKGROUND TASK RETRY ACTIVE] is only positive liveness for the current attempt; it is not proof that a prior attempt is dead.
Steps to Reproduce
- Dispatch a background task (e.g. a resolve worker) into a git worktree.
- Cause the attempt to be declared failed with a retryable provider error (rate limit / credential cooldown) at a point where the attempt has no recorded
sessionIdandpreviousSessionIDis empty (thependingstate). - In
tryFallbackRetry, observe that the replacement is scheduled even though the predecessor was never retired. - If the predecessor session/process recovers and resumes, both writers interleave edits in one worktree.
We cannot deterministically force the "no session identity + pending" state from outside, so this is reported as a latent fail-open branch confirmed by reading the pinned bundle, alongside live dual-writer incidents on our fleet.
Expected Behavior
Retirement must fail closed and be unconditional: if the framework cannot prove the predecessor attempt/session is dead, it must NOT start a replacement that can write the same worktree. A missing identity must be treated as "cannot prove retirement" and must return a retry-blocked terminal signal instead of scheduling the replacement — exactly the behavior the identity-present path already implements.
Actual Behavior
The !failedSessionID && failedAttempt.status === "pending" path calls scheduleRetryAttempt with no retirement wait, so a second writer can be dispatched into the predecessor's worktree.
Additional Context
Live provenance (our fleet, 2026-09-28). Two sessions (Sisyphus - ultraworker and Sisyphus-Junior) received the identical resolve prompt and interleaved edits into one git worktree; neither committed, and the tree had to be hard-reset to origin/main. Related observations: worktrees gained edits after background_cancel, and one successfully-completed retry produced a second commit.
Local mitigation we carry. Against pinned [email protected] we run a version-guarded local patch layer that adds waitForRetryAttemptRetirement (abort the exact prior session, then poll session.status until it is stably idle/terminal/missing within a bounded window; unknown status / identity change / timeout returns retry-blocked). Hardening the missing-identity case there is what surfaced this pending carve-out; we are reporting it so the fix lands in the runtime itself rather than only in local patches.
Environment / doctor output. We did not include bunx oh-my-openagent doctor output because the affected host runs the pinned bundle through a local patch layer rather than the published CLI. Runtime pin: [email protected].
Our tracking: devops/projects-vms-manager issue #1113 (Retry spawns a second writer without retiring the predecessor session), related #845 and #1058.
Source: code-yeongyu/oh-my-openagent