{"record":{"id":"5946997500cfe612","repo":"itsfatduck/optimizerDuck","slug":"service-verify-failed-for-servicename-expected","errorCode":null,"errorMessage":"Service verify failed for {ServiceName}: expected {OriginalStartupType}, actual={actual.Value}","messagePattern":"Service verify failed for (.+?): expected (.+?), actual=(.+?)","errorType":"exception","errorClass":"StepExecutionException","httpStatus":null,"severity":"error","filePath":"optimizerDuck/Domain/Revert/Steps/ServiceRevertStep.cs","lineNumber":75,"sourceCode":"        }\n\n        var (actual, notFound) = await ServiceProcessService\n            .GetStartupTypeAsync(ServiceName, opCall.Logger)\n            .ConfigureAwait(false);\n\n        // a missing service has nothing to restore.\n        if (notFound)\n            return true;\n\n        // null without NotFound means the query failed; never report an unverified restore.\n        if (actual is null)\n            throw new StepExecutionException(\n                $\"Service verify failed for {ServiceName}: could not query the current startup type.\",\n                null\n            );\n\n        if (actual.Value != OriginalStartupType)\n            throw new StepExecutionException(\n                $\"Service verify failed for {ServiceName}: expected {OriginalStartupType}, actual={actual.Value}\",\n                null\n            );\n        return true;\n    }\n\n    /// <inheritdoc />\n    public JObject ToData()\n    {\n        return new JObject\n        {\n            [nameof(ServiceName)] = ServiceName,\n            [nameof(OriginalStartupType)] = OriginalStartupType.ToString(),\n        };\n    }\n\n    /// <summary>\n    ///     Deserializes a <see cref=\"ServiceRevertStep\" /> from JSON data.","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/itsfatduck/optimizerDuck/blob/36acf585ae122a09f0e29eb4acedfaf94e81c0de/optimizerDuck/Domain/Revert/Steps/ServiceRevertStep.cs#L57-L93","documentation":"ServiceRevertStep.ExecuteAsync throws this when verification succeeds in querying but the actual startup type differs from OriginalStartupType recorded at apply time. The sc.exe config command did not produce the expected state even though it did not error.","triggerScenarios":"Service startup type changed back by Group Policy, a vendor installer, or Windows itself after the revert command; the revert targeted a service whose startup type was changed again after apply (OriginalStartupType no longer the true original); delayed-auto conversions not applied as expected.","commonSituations":"Corporate GPO resetting service start types at refresh; Windows servicing re-enabling a service; user manually changed the service in services.msc between apply and revert so the recorded original no longer matches intent.","solutions":["Re-run the revert; if it fails again, something is actively resetting the value — find and disable that agent.","Check Group Policy results (gpresult) for service policies and remove conflicting ones.","Set the type manually: sc config <ServiceName> start= <auto|delayed-auto|manual|disabled> to the desired original, then discard the revert file.","Re-apply then revert the optimization to refresh the recorded OriginalStartupType if the real original changed."],"exampleFix":"// before\nsc config WSearch start= disabled\n// after (match the recorded original)\nsc config WSearch start= delayed-auto","handlingStrategy":"validation","validationCode":"var (actual, _) = await ServiceProcessService.GetStartupTypeAsync(serviceName, logger);\nbool matches = actual == originalStartupType; // check before assuming revert needed","typeGuard":null,"tryCatchPattern":"catch (StepExecutionException ex) when (ex.Message.Contains(\"expected \"))\n{ logger.LogError(\"Something is resetting {Service}; find the policy/vendor agent before retrying\", serviceName); }","preventionTips":["Disable conflicting Group Policy service settings first","Re-apply then revert if the true original changed since apply","Watch for vendor updaters re-enabling services","Verify with services.msc or sc qc before manual fixes"],"tags":["csharp","windows-services","sc-exe","revert","verification"],"backgroundTag":"invalid-state-transition","analyzedSha":"36acf585ae122a09f0e29eb4acedfaf94e81c0de","analyzedAt":"2026-09-13T08:30:13.845Z","contentChangedAt":"2026-09-13T08:30:13.845Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}