Skip to content

Commit bee1cc7

Browse files
committed
fix(startup): recommend repair for an installed service, not re-registration
Second instance of the same defect the docs commit fixed, found while checking whether that fix was complete. startupHealthSummary() renders 'background service files are stale' and 'installed service is disabled, stopped, or unhealthy' — both cases where a service is already REGISTERED — and then told the user to run 'ocx service install'. The dashboard recovery panel hardcoded the same command in its copy button. install re-registers: it needs elevation on Windows (schtasks /create) and its transactional backend switch can replace a WinSW install with Task Scheduler. So the advice handed a UAC prompt and a possible backend change to someone whose only problem was stale assets. repair rewrites those assets and restarts the existing registration in place. recommendedCommand now picks repair when serviceInstalled and not conflicting; a genuinely absent service still gets install, and a conflict still gets install because repairService() refuses a two-manager conflict outright and the user must uninstall first. The GUI derives its command the same way instead of hardcoding. Red-green: restoring the unconditional installService fails the stale/disabled/ stopped guard. The DTO contract test was updated for the new commands entry, and eslint caught the constant landing in the tray section rather than the recovery section it renders in. 11 pass / 0 fail autostart-health, 583 pass / 0 fail gui.
1 parent ba68e90 commit bee1cc7

4 files changed

Lines changed: 49 additions & 4 deletions

File tree

‎gui/src/pages/startup-sections.tsx‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,14 @@ export function StartupRecoverySection({
225225
}) {
226226
const { t } = useI18n();
227227

228+
// An already-registered service is refreshed in place. `install` re-registers, which
229+
// needs elevation on Windows and can switch a WinSW backend to Task Scheduler, so
230+
// handing that command to someone who already has a service costs them a UAC prompt
231+
// they do not need. A conflict still needs uninstall-then-install.
232+
const serviceCommand = data.serviceInstalled && !data.serviceConflict
233+
? data.commands.repairService
234+
: data.commands.installService;
235+
228236
return (
229237
<section className="panel startup-actions">
230238
<div className="panel-head">
@@ -237,10 +245,10 @@ export function StartupRecoverySection({
237245
<div className="startup-command-row">
238246
<div>
239247
<strong>{t("startup.command.service")}</strong>
240-
<code>{data.commands.installService}</code>
248+
<code>{serviceCommand}</code>
241249
</div>
242-
<button type="button" className="btn btn-ghost btn-sm" onClick={() => onCopy(data.commands.installService)}>
243-
{copied === data.commands.installService ? t("startup.copied") : t("startup.copy")}
250+
<button type="button" className="btn btn-ghost btn-sm" onClick={() => onCopy(serviceCommand)}>
251+
{copied === serviceCommand ? t("startup.copied") : t("startup.copy")}
244252
</button>
245253
</div>
246254
)}

‎gui/src/pages/startup-shared.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export interface StartupHealthData {
2727
diagnosticStale: boolean;
2828
commands: {
2929
installService: string;
30+
repairService: string;
3031
installShim: string;
3132
restoreNative: string;
3233
};

‎src/codex/autostart-health.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export interface StartupHealth {
5454

5555
const COMMANDS = {
5656
installService: "ocx service install",
57+
repairService: "ocx service repair",
5758
installShim: "ocx codex-shim install",
5859
restoreNative: "ocx restore",
5960
} as const;
@@ -88,7 +89,12 @@ export function deriveStartupHealth(inputs: StartupHealthInputs): StartupHealth
8889
: inputs.routingKind === "custom-local" || inputs.routingKind === "unknown"
8990
? COMMANDS.restoreNative
9091
: inputs.serviceSupported
91-
? COMMANDS.installService
92+
// An already-registered service is refreshed in place: `repair` rewrites its assets
93+
// and restarts it without re-registering, so it needs no elevation on Windows and
94+
// cannot switch a WinSW install to Task Scheduler the way `install` would. Only a
95+
// genuinely absent (or conflicting, which needs uninstall-then-install) service
96+
// gets the registering command.
97+
? (inputs.serviceInstalled && !inputs.serviceConflict ? COMMANDS.repairService : COMMANDS.installService)
9298
: COMMANDS.restoreNative;
9399
return {
94100
...inputs,

‎tests/autostart-health.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,35 @@ describe("Codex startup health", () => {
3333
expect(startupHealthSummary(health)).toContain("ocx service install");
3434
});
3535

36+
// 260804 #970 follow-up: an already-REGISTERED service is refreshed in place. `install`
37+
// re-registers, which needs elevation on Windows and can switch a WinSW backend to Task
38+
// Scheduler, so recommending it to someone who already has a service costs them a UAC
39+
// prompt they do not need. Ablate by restoring the unconditional installService and the
40+
// stale/unhealthy cases below go red.
41+
test("an installed but unhealthy service is repaired, not re-registered", () => {
42+
for (const broken of [
43+
{ serviceInstalled: true, serviceStale: true },
44+
{ serviceInstalled: true, serviceEnabled: false },
45+
{ serviceInstalled: true, serviceRunning: false },
46+
]) {
47+
const health = deriveStartupHealth({ ...base, ...broken });
48+
expect(health.status).toBe("at-risk");
49+
expect(health.recommendedCommand).toBe("ocx service repair");
50+
expect(startupHealthSummary(health)).toContain("ocx service repair");
51+
}
52+
});
53+
54+
test("a genuinely absent service still gets the registering command", () => {
55+
const health = deriveStartupHealth({ ...base, serviceInstalled: false });
56+
expect(health.recommendedCommand).toBe("ocx service install");
57+
});
58+
59+
test("a conflicting service needs uninstall-then-install, not repair", () => {
60+
// repairService() refuses a conflict outright — two managers must be torn down first.
61+
const health = deriveStartupHealth({ ...base, serviceInstalled: true, serviceConflict: true });
62+
expect(health.recommendedCommand).toBe("ocx service install");
63+
});
64+
3665
test("treats a background service as restart protection", () => {
3766
const health = deriveStartupHealth({ ...base, serviceInstalled: true, serviceViable: true, serviceEnabled: true, serviceRunning: true });
3867
expect(health).toMatchObject({
@@ -171,6 +200,7 @@ describe("Codex startup health", () => {
171200
expect(typeof body.routingInjected).toBe("boolean");
172201
expect(body.commands).toEqual({
173202
installService: "ocx service install",
203+
repairService: "ocx service repair",
174204
installShim: "ocx codex-shim install",
175205
restoreNative: "ocx restore",
176206
});

0 commit comments

Comments
 (0)