fix(startup): avoid permission-sensitive service re-registration - #970
fix(startup): avoid permission-sensitive service re-registration#970stephen-drew wants to merge 4 commits into
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
|
Confirmed as real and left open — not folded into the current review stack (#951–#973). Two reasons. It touches a permission-sensitive path (service registration during self-update) across 30 files spanning CLI, GUI, and five docs locales, which is its own review with its own risk profile. And per The direction reads right to me — |
…it (#970) `ocx update` stops the proxy before replacing package files, then brought the service back with `ocx service install`. The Windows scheduler installer always reaches `schtasks /create`, which requires elevation the updater does not have, so an ordinary non-elevated update stopped a working proxy and could not restore its managed service. serviceReinstallArgs() now returns ["service", "repair"], which rewrites the wrapper assets and restarts the EXISTING registration without /create. The export name is kept for out-of-module callers; serviceInstallArgs() is split out for the paths that genuinely need to register. Safety of the substitution: repairService() throws when the service is not installed, and the update path runs after `ocx stop` — but stop never deregisters on any platform. macOS unloads the plist, Windows calls /end, Linux calls systemctl stop; deletion lives only in the uninstall paths. Verified across all three (evidence: devlog 020). Two things a straight argv change would have missed: The Windows GUI worker skipped the refresh entirely (update/job.ts) because its own comment said /create would UAC-fail. That reason does not survive repair, so the skip is narrowed to callers still passing install argv — otherwise the dashboard-triggered update, the most common Windows path, keeps the bug while the CLI gets fixed. bin/ocx.mjs infers 'a service manages this proxy' from service-state.json existing, which can be stale. Repair correctly refuses that case, but its thrown Error is indistinguishable from any other failure there (plain Error, inherited stdio, generic exit status), so message-matching was unimplementable and a blanket install-on-failure would resurrect the elevation prompt. It now reads startup.serviceInstalled from the `status --json` subprocess it already spawns — the file is plain Node ESM and cannot import diagnoseService() directly. Advice strings that fire only for an INSTALLED service now say repair: cli/status, winsw missing-binary, stale baked paths, stale scheduler assets, the launchd older-plist and not-loaded hints. First-install and missing-unit guidance stays install. Red-green: restoring the unconditional Windows skip fails the new guard. Six existing tests pinned the install argv and were updated with reasons. 245 pass / 0 fail across the service, update, winsw, doctor, status, startup and Windows-deploy suites.
|
Superseded by #980 (stack 7/7), commit Your diagnosis is correct and it is now fixed. The safety question your PR did not answer, now verified. Two things the reconstruction adds. The Windows GUI worker never reached the command at all. The stale-marker hole. Also carried: the advice strings that fire only for an already-installed service now say Six existing tests pinned the old install argv and were updated with reasons; a new guard proves the non-elevated Windows worker now receives Thank you — the elevation analysis was the hard part and you got it right. |
Summary
ocx service repairduring self-update instead of re-registering it.ocx repairas a documented alias ofocx service repair; reserve Install for a missing, disabled or conflicting registration and explain the Windows administrator requirement.Root cause
On Windows, an existing Task Scheduler registration can be owned by Administrators while the signed-in user is still allowed to run and stop it. Recovery paths that unconditionally suggested
ocx service installinvokedschtasks /create /f, so a repairable service failed with Access denied even thoughschtasks /runand/endwere permitted.User impact
Updates and ordinary recovery no longer overwrite an existing registration. A stopped service can be started, stale generated assets can be repaired without elevation, and a genuine re-registration still follows the explicit administrator-approved install path.
Verification
PATHand updating the obsolete repair assertion.cd docs-site && bun install --frozen-lockfile && bun run buildocx stop, thenocx repair; replacement PID served on127.0.0.1:10100and Startup read backprotected,protection=service,diagnosticStale=false.Source commits before the current
devrebase:52ef5469and70d2066d.Checklist