fix(updater): recover superseded pending transactions / 自动恢复过期更新事务
Summary
- recover valid pending file-update transactions that belong to the superseded flat install layout
- prove the running process is the active versioned desktop before archiving any transaction
- reconcile before downloading and again before install dispatch, avoiding wasted bandwidth and a fail-once/retry user flow
- preserve the exact transaction JSON and every rollback backup for diagnosis or manual recovery
Problem
After a flat-to-versioned Windows reinstall or upgrade, pending-update.json can still describe the old flat desktop and Guard release unit. The transaction is structurally valid, so the debris recovery added by #7366 correctly preserves it. Ordinary reconciliation then compares its targets with the current versioned executable directory and fails with:
update recovery: could not safely finish the previous update: reconcile pending update: pending update target is outside the current Guard installation
Retrying or reinstalling does not help because the transaction lives in the Reasonix state directory. Every later in-app update remains blocked.
Root cause
ArchiveSupersededPendingFileUpdate was intended to retire this old transaction after the versioned desktop started successfully, but it began with ReadPendingUpdate. That reader enforces the same current-launcher-directory invariant that rejects old flat-layout targets, so the recovery path could never reach the transaction it was designed to heal.
Fix
The superseded path now performs a separate, strict eligibility check:
- the running executable must resolve to the supplied install root;
- a valid
current.jsonmust name the running version and exact active desktop; - the pending transaction platform must match the current platform;
- the ordinary transaction, member, hash, filename, and backup invariants must all pass;
- the primary target and every release-unit member must be direct children of the old flat install root;
- the running version must be the same as or newer than the pending target version.
The transaction is read again under the pending-update lock and its full identity is compared. Archival uses a no-replace rename, verifies the moved JSON, restores it if a late rewrite is detected, and never deletes rollback backups. Foreign, newer, malformed, or concurrently replaced state continues to fail closed.
The Desktop updater attempts this recovery before download, then runs ordinary reconciliation. It repeats reconciliation immediately before install dispatch to close profile-change and concurrent-process gaps.
User impact
- no manual deletion of
pending-update.json - no reinstall ritual
- no first failed update followed by a retry
- no full installer download when an unrecoverable pending transaction should block the request
- same-version reinstall recovery is supported when the active versioned-install identity is proven
Compatibility
| State or contract | Behavior | Result |
|---|---|---|
| Existing pending-update JSON | No schema or field changes | Backward compatible |
| Valid current-layout transaction | Ordinary cancel/rollback/reconcile remains authoritative | Preserved |
| Valid superseded flat-layout transaction | Archived only after active versioned-install identity is proven | Automatically recovered |
| Structurally unusable marker | Existing #7366 debris classification remains authoritative | Preserved |
| Foreign install, platform mismatch, newer pending version, or changed transaction | Refused without deletion | Fail closed |
| Rollback backups | Never removed by superseded archival | Preserved |
| Provider, prompt, tool, or cache contracts | Unchanged | No cache impact |
Concurrency and security
- the initial snapshot is re-read and compared under the existing cross-process pending lock
- archive destinations are constrained to the repair directory and never replaced
- the moved transaction is parsed and identity-checked before success is reported
- deterministic tests cover replacement while waiting for the lock, a late uncooperative rewrite, and two concurrent recovery attempts
Verification
go test ./...go vet ./...go test ./internal/repair -count=1go test -race ./internal/repair -run 'ArchiveSuperseded|PendingUpdate|Reconcile' -count=1go test ./internal/repair -run 'TestArchiveSupersededPendingFileUpdate' -count=10cd desktop && go test ./...cd desktop && go vet ./...cd desktop && go test . -run 'TestUpdater(ArchivesSuperseded|ReconcilesPending|ReconcilesBeforeDownloading|BlocksInstall)' -count=5- Windows amd64 cross-compilation of the repair and Desktop test binaries
git diff --check
Related
- follow-up to #7366 for valid environment-relative transactions that must not be treated as debris
- addresses the Windows failure reported in #7244 and consolidated in #7342
- independent of #7369; the PRs do not modify the same files