Exit codes

WinRE Manager returns one of four exit codes. Orchestration should treat them as distinct outcomes, not as success/failure booleans.

The four codes

Code Name Meaning
0 EXIT_SUCCESS WinRE enabled, dedicated recovery partition healthy, state file written or already current.
1 EXIT_REBOOT_REQUIRED A reboot is required to complete or confirm WinRE registration. Pending deployment material remains protected until verification.
2 EXIT_WARNING The run did not achieve a clean success. Inspect the log for a deferral, constrained fallback, preservation decision or recoverable failure. Sub-cases: WinRE functional but degraded (OS-fallback); the run deferred work (Audit Mode, VMD indeterminate, offline, pre-shrink, race-detector, architecture gate, VHDX gate, intervening-anchor surplus, multi-intervening, offline LocalInputsId mismatch); a non-fatal failure is queued for retry (enable-only failure, restore /enable failure, strip-failure abort, base-WIM copy-integrity check, driver-enumeration failure, storage-applicability gate refusal, Step 3 → Step 4 pipeline gate); or the source was deliberately preserved (Foreign-With-Drivers, never-downgrade). Details in the log.
3 EXIT_FATAL The run cannot verify an acceptable completed outcome, or a required integrity/trust/persistence check failed. Existing good routes and pending recovery material can remain; investigate the log.

Priority

When a run’s outcome satisfies more than one condition, the priority order is:

EXIT_FATAL  >  EXIT_REBOOT_REQUIRED  >  EXIT_WARNING  >  EXIT_SUCCESS

EXIT_FATAL always wins. Between EXIT_REBOOT_REQUIRED and EXIT_WARNING, reboot-required wins — the machine needs to reboot either way.

In practice only two combinations are reachable through the final exit-code determination:

Some exit paths bypass the final determination and exit EXIT_WARNING or EXIT_FATAL directly — the v47 strip-failure abort, the v47 patch 2 base-WIM copy-integrity check, source-ownership driver-enumeration failure, the v49 storage-applicability gate refusal, the Step 3 → Step 4 pipeline gate, the Audit Mode deferral, the VMD-query-indeterminate deferral, the OS-fallback BitLocker deferral, the v45 pre-shrink deferral (including the v47 race-detector abort reason), the v47 Step 5 race-detector abort, the enable-only target-preparation failure, the enable-failure counter exit, the concurrent-instance deferral, the offline-fallback deferral, the v48 architecture-gate refusal, the v48 elevation-guard refusal, the indeterminate WinRE-status refusals, the v48 intervening-anchor surplus rejection, the v48 multi-intervening rejection, the v48 offline LocalInputsId mismatch, the v49 native-boot VHDX fail-closed gate, the v49 restore /enable failure (exit code 2), the v49 restore /setreimage failure (exit code 3), the v50 patch 3 restore WIM-deployment failure (exit code 3), the main full-update path’s WIM deployment failure (Step 6, exit code 3), the loop-breaker, and the two v50 backup-action fatal paths (destination drive letter unresolvable; insufficient destination free space). Those cases are described in the sections below.

When each code is returned

EXIT_SUCCESS (0)

The fast path found nothing to do and exited cleanly. Or the full-update path completed, WinRE reports Enabled, the state file was written, and no warning flags were set.

Also returned by -DryRun when the dry run completes without errors. Dry runs do not write a state file; they exit 0 from the deployment step.

Also returned by -Action Backup when the byte-for-byte copy completes and the sidecar backup.json is written. Backup does not rebuild, replace or reconfigure the active WinRE route, and does not write deployment state. A verified WIM copy whose sidecar write fails returns EXIT_WARNING (2); the WIM remains usable. See the warning case below and backup troubleshooting. A failed WIM copy or integrity check returns EXIT_FATAL (3).

Also returned by -Action Restore when the restore completes: the previously captured WIM is written back to the currently registered route transactionally, WinRE is re-registered, and reagentc /enable succeeds. A restore that writes the WIM but fails to re-enable WinRE exits non-zero (see EXIT_WARNING and EXIT_FATAL below) and leaves the temporary resume task registered so the operation is resumed on the next boot or within the hour.

Restore also returns 0 when the target WIM already matches the backup. That no-op leaves WinRE registration and enablement unchanged; success confirms image equivalence. Run the default Repair action if enablement or recovery-layout repair is needed.

EXIT_REBOOT_REQUIRED (1)

reagentc /enable returned exit 0 but reagentc /info did not immediately report Enabled. This is a common result after a fresh registration: Windows schedules the registration to complete on the next reboot.

The script writes the state file with PendingReboot = true, records the deployed partition number and disk number so the next run knows where the WIM is, and exits with code 1.

Also returned by the pending-reboot path when the retry reagentc /enable still returns reboot-required, by the enable-only path when reagentc /enable returns reboot-required, and by the restore action when the WIM was replaced and reagentc /enable returns reboot-required after the restore.

EXIT_WARNING (2)

Reached when any of the following is true at exit time:

Warning can arise before any deployment or after completed work with a non-fatal condition. Backup and Restore also return it from their own validation/failure paths. State may remain unchanged, be updated, or be invalidated after replacement or geometry failure; preservation alone does not determine that outcome. Read the route verification, state-write and pending-operation messages together.

Important for orchestration: the table below summarizes warning and refusal cases that require different actions. A lost active route or failed required persistence check can make a patch 5 transition fatal. The bulleted list above this paragraph describes the underlying conditions in more detail; some bullets map to a single table row and a few do not appear as their own row. The state file’s LastUpdated timestamp, the presence of the UsedOSFallback flag, the presence of the deferral marker at C:\Recovery\OEM\winre_partition_deferred.json, the presence of a WinRE Manager - Resume scheduled task, and the specific log content distinguish them.

Case State file LastUpdated Log signature Action
OS-fallback Saved fallback state; pending record retained Last-resort fallback and retained-operation messages Dedicated creation actually failed, geometry was verified and C: was fully decrypted. Inspect actual registration/hash checks. The warning retains candidate, journal and task for dedicated remediation; it is not a healthy fast-path state.
Source-ownership driver-enumeration failure (v49) Unchanged, or state file absent Source-ownership decision: driver enumeration failed after 3 attempts: … - candidate rejected The pre-classification enumeration of the mounted image’s third-party driver set failed all three retries. The classification cannot be performed without the driver count, so the candidate was discarded. No WIM was deployed, no partition touched, WinRE not disabled. The checkpoint was set back to 2. Investigate the DISM WIM provider state; the failure may be transient.
Foreign-With-Drivers source preserved Depends on layout/commit outcome Foreign source preserved byte-identically; assessing dedicated layout without strip, injection or export. Original bytes are preserved; patch 5 still assesses and can repair dedicated placement. Acceptance stays separate from CurrentImageHash; matching DSI alone does not skip layout remediation.
Never-downgrade detection Depends on layout/commit outcome Never-downgrade invariant: discarding the candidate edits and preserving the original source bytes. and per-driver detail Servicing edits are discarded; unchanged-source placement is assessed independently. Inspect the final route and pending record.
Strip-failure abort (v47) Unchanged, or state file absent Strip stage failed - candidate rejected. Dismounting with -Discard and deferring before injection, export, partition work, or WinRE disable. The strip stage could not normalize the mounted image to zero third-party drivers. The WIM was not deployed, the partition was not touched, and WinRE was not disabled. The checkpoint was set back to 2, and base.wim and any stale winre_optimized.wim were removed. The next run will retry from step 2 and re-acquire the source. Investigate the specific strip failure reason (enumeration, removal, missing INF field, or budget exhaustion) in the log lines immediately preceding the abort.
Storage-applicability gate refusal (v49) Unchanged, or state file absent Line naming the candidate image path, the machine’s present SCSIAdapter-class devices, and the count of controllers with no matching INF (e.g. 2 of 4 storage controller(s) have no matching INF in the candidate image). The candidate WIM was fully prepared — mounted, source-ownership-classified, strip-applied or preserved, injected, never-downgrade-checked — and then refused by the applicability gate before ResetBase and before the dismount. The WIM was not written to the active route; no partition was touched, WinRE was not disabled. This gate has never fired in the field — a field log is high-signal. Operator action: run Test-WinRE.ps1 Option 1 (harness v28) and compare the “Storage controllers” block against the manifest’s VMD patterns; update the manifest’s requiredDevices patterns to include the machine’s controller, or update the OEM pack resolution to a version whose INFs match, then delete the state file and re-run.
Base-WIM copy-integrity check (v47 patch 2) Unchanged, or state file absent Base WIM copy hash mismatch: source=..., copied=... - rejecting candidate or Base WIM copy is unreadable after Copy-Item - rejecting candidate The candidate base.wim did not match the selected source’s SHA256, or the copied file could not be re-read. The candidate is removed, the checkpoint is reset to Step 2, and the run exits EXIT_WARNING. Investigate whether the source changed during acquisition.
Step 3 → Step 4 pipeline gate Unchanged, or state file absent Image injection did not complete. Stopping before Step 4 and before any deployment. The OEM or VMD injection failed after a successful strip, never-downgrade check, and applicability gate. The WIM was not deployed, the partition was not touched, and WinRE was not disabled. The checkpoint was set back to 2. The next run will retry from step 2. Investigate the injection failure reason (OEM pack download, extraction, INF validation, or VMD driver download).
Audit Mode deferral Unchanged, or state file absent Deferring WinRE Manager: Windows is not in a normal-running state (Setup\State\ImageState=…) The machine has not finished OOBE, or is in Audit Mode or a sysprep phase. No partition work was attempted. Complete OOBE, sign in to a normal desktop session, and re-run. Do not retry immediately.
VMD query indeterminate (v44 patch 6) Unchanged, or state file absent VMD hardware detection reported N error(s) during PnP enumeration: … followed by VMD hardware detection was indeterminate; deferring because the driver set cannot be safely determined. A PnP enumeration error prevented the VMD hardware presence check from completing. The correct driver set cannot be determined, so the run defers rather than guessing. No WIM was deployed, no partition was touched, no reagentc call was made. Resolve the PnP service issue (Windows device management, an antivirus/EDR product blocking device enumeration, a device in an error state) and re-run.
OS-fallback BitLocker refusal Depends on the preceding transition; unresolved operation retained Fallback refusal because C: is not confirmed fully decrypted Patch 5 first attempts safe dedicated remediation. Encrypted C: cannot authorize last-resort fallback. If the active recovery partition was lost, failure is fatal rather than a healthy warning. Do not decrypt C: merely to bypass this policy.
Partition preparation deferred Usually unchanged; geometry failures can invalidate state The reason returned by partition preparation Read the specific capacity, query, source, resize or restoration result. A pre-deletion refusal retains the old partition; a deletion failure may follow partial work. Capacity is reassessed and eligible execution failures receive a one-hour backoff.
Registered-source fingerprint abort at Step 5 (v47) Unchanged, or state file absent Registered WinRE source changed during candidate preparation - aborting before /disable. The old WinRE route remains intact; no partition changes have been made at this site. The v47 race detector caught a Windows Update servicing event during candidate preparation, at the Step 5 /disable site. WinRE is still Enabled, no partition was touched, no WIM was deployed. The checkpoint was set back to 2, and base.wim and any stale winre_optimized.wim were removed. Simply re-run — the next run will re-select the source and prepare a fresh candidate based on the newly-registered image. This is not a failure; it is the design’s intended response to a source that changed mid-preparation.
Enable-only failure (counter < 3) Newer than the run start (state file written this run, with LastEnableResult set to "failed" or "bitlocker" and the counter incremented) One of: Enable-only /enable failed (attempt N of 3).; Enable-only /enable refused with the BitLocker error after the target partition was confirmed unencrypted (attempt N of 3).; Enable-only path: target recovery partition could not be made unencrypted - deferring without further changes (target-preparation failure). The deployment is current; only the enable step failed. Do not rebuild. Investigate the enable failure itself (ReAgent.xml corruption, missing registration, a Windows component problem, an antivirus product holding the recovery partition open). The next run will retry enable-only. After three consecutive failures the loop-breaker fires and the next run exits with code 3.
Concurrent-instance deferral (v44 patch 4) Unchanged, or state file absent Another WinRE Manager instance is already running (program lock file is exclusively held). Not a failure. The other instance is doing the work and will complete on its own. Do not investigate the log for a deployment problem, do not retry, do not intervene. If your orchestration treats exit 2 as a soft failure and re-queues the remediation, be aware that the re-queue will also exit 2 until the first instance completes. Either wait, or disable the scheduled task before running a manual remediation. See deployment.md. A resume task and a scheduled task are serialized by the same lock; a resume run that coincides with a scheduled run produces this deferral on whichever side loses the race.
Offline-fallback deferral (v44 patch 5) Unchanged, or state file absent Offline fallback: the machine requires a full update (state file is stale or unhealthy), but the driver manifest is unavailable. Cannot proceed without a live manifest. Will retry on the next scheduled run when the network is available. The network was unavailable and the state file indicates a full update is needed. A full update requires the live manifest to resolve the driver set. No WIM was deployed, no partition was touched, WinRE was not disabled, no state file was written or modified. No operator action is required — the next scheduled run with network will complete the work. If the log instead shows Offline fallback: using state file's stored DesiredStateId …, the fast path fired successfully and the outcome is a degraded-success, not a deferral — see the “Fast path under offline fallback” row below.
Fast path under offline fallback (v44 patch 5; metadata-based as of v47) Unchanged, or state file absent Offline fallback: using state file's stored DesiredStateId <id> The network was unavailable but the state file’s local safety checks all passed, so the fast path fired successfully. This is a degraded-success, not a deferral. The machine is healthy and unchanged. No operator action is required; the next run with network will re-evaluate the DSI and either converge or force a rebuild if any input has drifted while offline.
Architecture-gate refusal (v48 patch 1) Unchanged, or state file absent Unsupported OS architecture '<arch>': this manager supports x64 only. The startup architecture check refused. Expected on ARM64, x86, or machines whose architecture could not be resolved. No state was committed. This is a stable deferral: any machine whose architecture is not x64 will continue to exit 2 on every run until the manager adds support or the machine is replaced. Do not retry expecting a different result.
Intervening-anchor surplus rejection (v48 patch 1) Unchanged, or state file absent intervening anchor is N MiB smaller than the plan requires to seat the recovery partition at the disk tail; this v48 scope does not extend the anchor (BitLocker). The intervening-anchor layout (C: \| D: \| Recovery) had a surplus: the recovery partition being reclaimed is larger than the new bucket size, so the plan cannot seat the new recovery partition at the disk tail without extending the anchor. The v48 scope does not extend the anchor (BitLocker-encrypted anchors are not safely growable via Resize-Partition alone). The old recovery partition is intact; no partition was touched. Operator action: extend the anchor to close the gap, or reduce the desired recovery partition size, then delete C:\Recovery\OEM\winre_state.json and C:\Recovery\OEM\winre_partition_deferred.json to force a retry.
Multi-intervening rejection (v48 patch 1) Unchanged, or state file absent recovery-typed partitions exist beyond the intervening anchor's recovery cluster; this layout is not supported The layout has two or more non-recovery partitions between C: and the type-coded recovery cluster (C: \| D: \| E: \| Recovery). The v48 scope is deliberately narrow: exactly one intervening partition, no partition-moving. Same stable deferral as v47, but the v48 message names the intervening partitions via Format-PartitionRef. Automating multi-intervening handling was floated as a v49 candidate, but v49 shipped without it, so it remains a candidate for a future release.
Offline LocalInputsId mismatch (v48 patch 1) Unchanged, or state file absent Offline fallback: stored LocalInputsId <hash> does not match the current locally-computable inputs <hash>. The machine was offline and the state file’s stored LocalInputsId did not match the current machine’s locally-computable inputs (hardware identity, OS build, CPU vendor/generation). A hardware or OS input changed while the machine was offline; the stored DesiredStateId no longer describes this machine. The machine is unchanged. Operator action: bring the machine online so a fresh manifest can be fetched and a new DesiredStateId computed; the next scheduled run will do this automatically.
Native-boot VHDX fail-closed gate (v49) Unchanged, or state file absent Topology-named refusal that states the OS disk’s bus type is File Backed Virtual and at least one other disk is on a physical bus, and that the manager’s partition-resize and recovery-partition-creation operations are not supported under that topology. The startup topology check refused. No partition was touched, no WIM deployed, WinRE not disabled, no state file written. This is a stable deferral: a VHDX-boot machine will continue to exit 2 on every run until the topology is supported or the machine is converted. Do not retry expecting a different result. The gate has no -DryRun carve-out — a dry run on a VHDX-boot host also exits EXIT_WARNING.
Restore /enable failure after WIM replacement (v49) Deleted (the WIM changed, so the state file was removed) Restore: WIM replaced but reagentc /enable returned <failed\|bitlocker> The restore replaced the WIM on the active route and re-registered it via /setreimage, but /enable did not succeed. The temporary WinRE Manager - Resume task was preserved; the next boot (or the T+1h one-shot) will re-invoke the script with its default Repair action and complete the operation. Do not delete the resume task manually unless you intend to abandon the interrupted restore. If the task keeps reappearing after each attempt, read the log around the failing step. This path has not been exercised in the field. (The sibling restore failure — /setreimage failing after the WIM was replaced — exits EXIT_FATAL, not EXIT_WARNING; its log signature is Restore failed at reagentc /setreimage: … and it also deletes the state file.)

Use LastUpdated together with the final route, pending record and log. It cannot distinguish all patch 5 outcomes by itself: preservation can lead to no work, deferral or byte-identical relocation, and state persistence can fail after a valid route is established.

A partition-creation failure — with its Dedicated recovery partition creation failed after all attempts. banner — is only logged when the destructive attempt actually ran and failed. A deferral or a pipeline gate is not that.

EXIT_FATAL (3)

Reached when any of the following occurs:

Fatal exits do not write a state file. If a state file was written earlier in the run and the fatal exit occurs after that point, the state file is left as-is; on the next run, the fast path may fire if the state is now healthy, or the full-update path may re-run if it is not.

Special case for orchestration: exit code 3 with the log line FATAL: WinRE is not enabled at exit on a machine that no longer has a recovery partition indicates the pre-patch-5 failure mode. Do not retry automatically. Follow the recovery procedure in troubleshooting.md.

Second special case: exit code 3 with the log line Refusing to retry reagentc /enable indicates the enable-failure loop-breaker. Do not retry automatically — the same guard will fire on the next run because the state file still records the counter value. Resolve the underlying cause, delete the state file, and re-run. See troubleshooting.md for the diagnosis procedure.

Third special case: exit code 3 with the log line rollback restore hash verification failed or rollback restore failed on a v49 -Action Restore run indicates the transactional helper could not restore the previous WIM after a failed replacement. The machine’s WinRE WIM may be in an inconsistent state. Capture the full log and file a bug; the branch has not been exercised in the field.

Fourth special case: exit code 3 with the log line Restore failed at reagentc /setreimage: … on a v49 -Action Restore run indicates the WIM was replaced but reagentc was not re-registered. The state file, checkpoint, and deferral marker were deleted, and the resume task was preserved, so a subsequent repair run (or the resume task’s re-invocation) will re-attempt registration. Capture the full log for a bug report; the branch has not been exercised in the field.

Pending deployments (v50 patch 5)

An independently verified candidate and trusted operation record can outlive the current process. Code 1 retains them while enablement awaits reboot; code 2 can retain them after a pre-switch refusal with the old route preserved. Code 3 covers an unresolved transition or required persistence/integrity failure. A valid dedicated route followed by a state-write or journal-retirement failure must remain active; failure reporting does not authorize reverting it.

The pending record and candidate remain separate from DSI and ordinary checkpoints. Do not delete them to make a warning disappear. Resolve the cause, re-run Repair, and inspect the final registration, hash and capacity observations. No exit code by itself proves a successful recovery boot.

What the codes do not tell you

For any of those details, read the log. See troubleshooting.md.

Exit codes on the pending-reboot path

The pending-reboot path has its own exit logic. In order:

  1. Check the repair-attempt count first. The state file’s RepairAttempts is incremented before any other work. If the incremented value exceeds 3 (equivalently, the state file already records RepairAttempts >= 3), the run exits EXIT_FATAL immediately without attempting repair. This guard is a precondition on the whole pending-reboot path, not a post-condition on its outcome.
  2. Resolve the deployed target from the state file (DeployedDiskNumber / DeployedPartitionNumber, or C:\Recovery\WindowsRE for OS-fallback).
  3. Prepare the target:
  4. Re-run reagentc /enable against the recorded path. If the retry succeeded and WinRE reports Enabled:
  5. If the retry still reports reboot-required → EXIT_REBOOT_REQUIRED.

Note that PendingReboot and RepairAttempts are recorded in the state file before the exit, so a machine that exits with code 3 due to too many repair attempts still has a state file reflecting the current repair count.

The pending-reboot path writes the state file with LastEnableResult = "ok" and EnableFailureAttempts = 0 on the paths that reach a state write (successful enable, reboot-required enable). A machine that completes those paths therefore has its enable-failure counter reset — the pending-reboot path represents a different failure mode (registration did not complete after a reboot) and is tracked by the separate RepairAttempts counter. The target-preparation-failure path exits before the state write and leaves the counter preserved. The two counters are independent. A target-preparation failure on the pending-reboot path does not increment EnableFailureAttempts; the exclusion is deliberate, because immediately after a reboot the target partition’s encryption state may be transiently indeterminate, and the pending-reboot path is tracked exclusively by RepairAttempts.

Exit codes and orchestration

Recommended orchestration policy:

Code Action
0 Record success. No further action.
1 Schedule a reboot at the next maintenance window. The next run will finish the registration.
2 Read the summary Why: field and the detailed warning case above. Backup can leave a usable verified WIM despite a sidecar failure. Repair warnings can mean preserved-image handling, a safe deferral, last-resort OS-fallback or unresolved pending work; inspect the actual route, state and pending record. Preservation alone does not establish an adequate or bootable recovery route. Retain an unresolved candidate, journal and resume task.
3 Investigate the fatal case above before retrying. A preflight/status refusal can occur before repair work; a deployment failure can leave the recovery route unavailable; a persistence failure can leave a verified new route intact. Use the log and actual registration to distinguish them. Preserve pending recovery material and any registered resume task, and resolve the reported query, provider, integrity or persistence failure.

Do not use exit code 0 as the sole health signal. A machine that reached OS-fallback exits with 2, which is a legitimate “the machine is functional but the design goal was not achieved” signal. If your deployment policy requires dedicated recovery partitions, treat 2 as a soft failure and route it to a queue.

Do not configure retry loops that ignore the exit code and re-run unconditionally. None of the deferral states is made better by retrying — the same gate will fire on the next run. Wait until the underlying condition resolves (manage-bde -status C: reads a safe state on the OS-fallback route, the PnP enumeration error clears, the machine has finished OOBE, the pre-shrink constraint is freed, the anchor is extended, or the marker is cleared), then re-run. Six v47/v49-specific retry exceptions:

For the enable-failure counter, do not retry blindly: the counter is designed to break a silent loop, and after three consecutive failures the loop-breaker fires and requires manual intervention. Investigate the enable failure itself rather than cycling the script. For the concurrent-instance deferral, the correct action is to wait; the other instance is already doing the work.

For a v49 restore that exits 2 with a WinRE Manager - Resume task present, do not intervene — the task will resume the operation on the next boot or within the hour. Deleting the task manually abandons the interrupted restore. If the task keeps reappearing after each attempt, the interrupted operation is failing in the same way every time; read the log around the failing step.