fix(harness): retain recovery intent until a managed release switch is reconciled
What goes wrong
After an interrupted managed release switch, AO can retain two different answers to “which version is active?”: current points at the candidate while the durable record still says the old release. Cleanup can remove the recovery marker before those answers agree. Startup then has no marker to tell it to reconcile this state.
Expected: A failed switch stays recoverable until the executable pointer and durable record agree, even when no sessions are running. A subsequent launch should not resolve or record an inconsistent release. The fixture below proves the inconsistent state, not that a real Windows launch failed.
Environment and reproduction
AO 9b99c47565d312c5c2bbc9b24b1f132611163ee2; Linux, real managed updater/cleanup/reconciliation, existing managed Codex fixture, POSIX links, in-memory fixture release registry. Test TestReproPruneDropsUnreconciledManagedSwitch.
- Seed a known-good managed release (
v1) with no live sessions. Begin stagingv2. - Inject a release-recording error after the pointer moves. Force rollback to fail by obstructing its temporary
.current-v1path. Verify the update failed and.unsettledremains. - Restore the release registry to a writable state. Run
RemoveUnusedManagedReleases, thenReconcileManagedReleases(the startup recovery code).
before prune: current=v2 recorded=v1 marker_present=true live_sessions=0
after prune and startup reconciliation: current=v2 recorded=v1 marker_present=false
The test passes when it reproduces the mismatch, not when recovery succeeds. No native Windows junctions or Windows launch behavior were exercised.
Code and investigation history
The initial design review asked whether a Windows junction replacement could leave an inconsistent active release. The agent tested a narrower question first: once rollback has already failed and left recovery intent, can ordinary cleanup discard it? The two snapshots above show exactly where that happens.
- Cleanup order: no live sessions is enough to delete the marker before agreement is established.
- Startup reconciliation: recovery consults the marker. The injected sequence checks that rollback leaves the marker and isolates cleanup as where it is lost.
- Windows switch implementation removes and recreates the junction; a missing pointer needs a distinct test. #6745 added rollback/recovery; this is a subsequent failure in cleanup, not a request to remove junctions.
Proposed change and acceptance
Keep recovery intent and required releases while current is missing or the durable record disagrees, even with zero live sessions. Clear the marker only after a verified recovery and any uncertain live references are safe. Cover mismatched-record and missing-pointer cases on a native Windows runner with an actual junction, then make a fresh launch and assert junction target, resolved executable, and recorded release agree.
Runnable fixtures
Run at the pinned revision from backend/ on Linux (verified with Go 1.27.4). The Go overlay adds a temporary test without editing the checkout. These assertions pass when the behavior is reproduced.
TestReproPruneDropsUnreconciledManagedSwitch: source and command
Save as /tmp/junction_test.go:
package systeminstall
import (
"context"
"os"
"path/filepath"
"testing"
"github.com/aoagents/agent-orchestrator/backend/internal/domain"
)
func TestReproPruneDropsUnreconciledManagedSwitch(t *testing.T) {
f := newManagedCodexFixture(t, nil)
if j := f.update(t, "1.1.0"); j.Status != StatusSucceeded {
t.Fatalf("seed: %+v", j)
}
d := f.s.managedTargetDir(TargetCodex)
if err := os.MkdirAll(filepath.Join(d, ".current-v1", "blocked"), 0755); err != nil {
t.Fatal(err)
}
f.releases.failSet = true
if j := f.update(t, "1.2.0"); j.Status != StatusFailed {
t.Fatalf("expected failure: %+v", j)
}
f.releases.failSet = false
marker := filepath.Join(d, unsettledMarker)
_, before := os.Stat(marker)
current := f.s.currentManagedRelease(d)
if before != nil || current != "v2" || f.releases.current[domain.HarnessCodex] != "v1" {
t.Fatal("fixture did not reach inconsistent recovery state")
}
t.Logf("before prune: current=%s recorded=%s marker_present=true live_sessions=0", current, f.releases.current[domain.HarnessCodex])
f.s.RemoveUnusedManagedReleases(context.Background())
_, after := os.Stat(marker)
if !os.IsNotExist(after) {
t.Fatalf("marker preserved, missing-marker failure not reproduced: %v", after)
}
if err := f.s.ReconcileManagedReleases(context.Background()); err != nil {
t.Fatal(err)
}
t.Logf("after prune and startup reconciliation: current=%s recorded=%s marker_present=false", f.s.currentManagedRelease(d), f.releases.current[domain.HarnessCodex])
if f.releases.current[domain.HarnessCodex] != "v1" {
t.Fatal("failure not reproduced: the recorded release was corrected")
}
}
overlay=$(mktemp)
printf '{"Replace":{"%s/internal/service/systeminstall/ao_issue_junction_test.go":"/tmp/junction_test.go"}}\n' "$PWD" > "$overlay"
go test -overlay "$overlay" ./internal/service/systeminstall -run '^TestReproPruneDropsUnreconciledManagedSwitch$' -v
rm -f "$overlay"
Native Windows fixture evidence (2026-11-19)
Ran on native Windows amd64 (build 26200, NTFS, Go 1.27.4) at 9b99c47565d312c5c2bbc9b24b1f132611163ee2 in a disposable checkout. The test assertions describe the reported behavior, so PASS means the fixture reproduced it, not that it is fixed.
TestWindowsNativeReproJunctionIntentLostBeforeRecovery passed (0.60 s) using real NTFS junctions and launcher probes. With a mismatched pointer, current=v2, recorded v1, and the launcher reported 1.2.0 but cleanup deleted the recovery marker without reconciling. With a missing pointer, cleanup deleted the marker, left current absent, and the launcher kept failing. With the same missing pointer and no cleanup, recovery recreated current=v2, reconciled the recorded release to v2, and the launcher reported 1.2.0. This was seeded crash residue with an in-memory release record, not a real updater crash or interrupted install.