Skip to content

fix(update): release an interrupted Windows update marker once its supervisor is gone - #8534

Merged
lidge-jun merged 2 commits into
devfrom
fix/windows-update-marker-release
Nov 11, 2026
Merged

lidge-jun merged 2 commits into
devfrom
fix/windows-update-marker-release

Conversation

@lidge-jun

Copy link
Copy Markdown
Owner

Summary

On Windows, an interrupted ocx update (console closed, Ctrl+C, Task Manager, sleep or power loss after "Service manager stopped") left update-orchestrated.json with terminationUnconfirmed: true and no process-tree witness. Every later ocx update, ocx sync and ocx update --plan --yes then failed with update-in-flight, permanently (#8524). inspectUpdateMarker frees an unconfirmed marker only through installerPgid, and only the POSIX supervisor ever writes it.

The Windows installer runs inside a private kill-on-close Job Object (npm-install-job.ps1). Breakaway is not allowed, the job handle is never inherited, and its only handle lives in the PowerShell supervisor. When that supervisor process is gone, the job is closed and its tree terminated. The supervisor pid is therefore the Windows counterpart of the POSIX process group.

  • runNpmInstall records the supervisor pid as installerPid (new src/update/windows-installer-marker.mjs) before writing the supervisor's stdin request. The supervisor creates no job or installer until stdin closes, so a launcher killed after the publish leaves a marker whose witness is the supervisor itself. runWindowsInstallerSync forwards markerPath, and all four session call sites pass join(configDir, "update-orchestrated.json").
  • inspectUpdateMarker frees an unconfirmed Windows marker once installerPid and the launcher pid are gone and the fence has passed. On Windows it reads installerPid only while terminationUnconfirmed is set, so a finished update never reads as in flight because Windows reused the supervisor's old pid. POSIX behavior is unchanged.
  • confirmInstallerExit drops a Windows-shaped witness (installerPid without installerPgid), so a pnpm rollback, the second installer run in one session, can record its own supervisor.
  • The publish refuses unless the marker is exactly awaiting an installer: mutating, termination unconfirmed, no POSIX group, and no live earlier supervisor.
    • If nothing can be recorded, the supervisor gets no request, is killed, and the run reports status: 1, processTreeExited: true after its close. The caller then confirms the exit instead of recreating the stuck marker.
    • If an earlier supervisor is still alive, its witness is kept and the run stays unconfirmed (processTreeExited: false).

Not covered (owner decision). A marker that already exists without installerPid, written by 2.100.x or earlier like the reporter's file, still reads unknown. Releasing it on fence and launcher pid alone would also release a supervisor suspended across sleep. Options are in the Maintainer judgment.

Accepted residuals.

  • A few milliseconds may pass between the supervisor pid vanishing and job teardown finishing.
  • If Windows reuses a dead supervisor's pid, the marker reads active until that process exits. This fails closed.
  • Processes that lifecycle scripts launch outside the job escape it, the same as POSIX setsid.
  • A supervisor whose close never arrives after a refused publish hits the existing watchdog failure.

Closes #8524

Verification

  • New tests/update/update-windows-installer-witness.test.ts, 12 cases, with the platform and the supervisor launcher injected:

    • marker inspection on win32 and POSIX;
    • publish preconditions;
    • install then rollback in one session;
    • the POSIX group being preserved;
    • runNpmInstall recording the pid before the request is written;
    • the unrecordable and live-witness outcomes.

    Fail-first: with sync-update-mutex.mjs and orchestrated-session.mjs reverted to dev, the four core cases fail. These are the reporter's shape, live and unknown handling, legacy-marker handling, and the rollback run.

  • bun test tests/update: 1038 pass, 1 fail. The failure is update-orchestrated-entry "npm child fences identity…", which took 28.8 s under host load and passes alone (32.4 s).

  • bun run typecheck, bun run privacy:scan, bun run structure:check (structure/ops/service-and-sidecars.md edited in place), the test-layout guards, the file-size ratchet and the Lab boundary all pass.

  • The data-reading update lint contracts were updated by hand: the child.kill() count from 2 to 3, the bridge input string, rows for the new module's primitives, and import policy. Their parser-backed tests skip on POSIX hosts (Bun cannot start the TypeScript sync client there), so only the Windows lane exercises them.

NOT RUN:

  • Windows real device; there is no Windows checkout on this host.
  • The parser-backed update lint, which runs only on Windows.
  • bun run test:changed: on this loaded host (load average about 9 from other lanes) it times out unrelated server e2e files. CI's Linux shards cover it.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

…pervisor is gone

An interrupted Windows update left update-orchestrated.json with
terminationUnconfirmed and no process-tree witness, because only the POSIX
supervisor records installerPid/installerPgid. inspectUpdateMarker then answered
"unknown" forever and every later update and sync refused with update-in-flight
(#8524).

The Windows installer runs in a kill-on-close Job Object whose only handle
lives in its PowerShell supervisor, so the supervisor pid is the Windows
witness. runNpmInstall now records it in the marker before the supervisor
receives its request; inspectUpdateMarker frees an unconfirmed Windows marker
once that pid and the fence are gone, and ignores the pid once the exit is
confirmed. A supervisor that cannot be recorded gets no request and reports an
unstarted installer; a live earlier supervisor keeps its witness.

Closes #8524
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner November 11, 2026 09:54
@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T09:56:27.319450Z f4d468d PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions github-actions Bot added the bug Something isn't working label Nov 11, 2026
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@lidge-jun

Copy link
Copy Markdown
Owner Author

Maintainer judgment (bundle lane: service / platform / link diagnostics)

Value. An interrupted Windows update no longer blocks every later ocx update and ocx sync with update-in-flight forever. Once the 15-minute fence has passed and the recorded supervisor and launcher are gone, the next update proceeds. Users no longer have to rename update-orchestrated.json by hand.

UX change. None on the success path. On Windows, an interrupted update now clears itself after the fence. Two new refusals are both fail-safe:

  • If the supervisor pid cannot be recorded (for example, the marker is briefly locked), the update fails before anything is installed, and a rerun fixes it.
  • If an earlier supervisor is still alive, the run stays fenced.

Existing users. POSIX behavior is unchanged: same probe, same installerPgid witness. Windows callers without a session pass no marker path and behave exactly as before. A finished Windows update never probes an old supervisor pid, so pid reuse cannot invent a new false update-in-flight. A pnpm rollback, the second installer run in one session, records its own supervisor.

Windows impact. The witness is sound because npm-install-job.ps1 blocks on ReadToEnd() before creating the job, uses a kill-on-close job with no breakaway, and keeps the job handle out of every child. Accepted residuals:

  • a few milliseconds of job teardown after the pid vanishes;
  • a reused pid keeping the marker active until that process exits (fails closed);
  • processes started outside the job by lifecycle scripts (the same residual as POSIX setsid);
  • a launcher killed between noteUntrackedInstaller and the publish, which leaves no witness and reads unknown, as before.

Verification.

  • New tests/update/update-windows-installer-witness.test.ts, 13 cases with the platform and launcher injected. The four core cases fail on dev and pass with the change.
  • bun test tests/update: 1038 pass. The one load-timeout failure passes when run alone.
  • Typecheck, privacy:scan, structure:check, test-layout, the file-size ratchet and the Lab boundary all pass.
  • Reviews:
    • A general review approved f4d468dcdb, and a separate security review approved the same head.
    • Their notes were addressed in b4707d4c00: the seam refuses outside a test process, and the doc wording is corrected.
    • A fresh combined general and security review then approved b4707d4c00.
  • The first reviewer also bundled the parser-backed update lint and ran it under Node 24 with TypeScript 7.0.2. It found no violations or contract mismatches, and it does detect a deliberately broken child.kill() count.

NOT RUN.

  • A real Windows device; there is no Windows checkout on this host. Release safety relies on process.kill(pid, 0) returning ESRCH only for a process that is really gone, under both Node and Bun on Windows. That still needs real-device evidence.
  • The parser-backed lint in its own CI lane, which only the manual Windows lane runs.
  • CI on this head was still running at merge.

Owner decision (not implemented). Markers that already exist without installerPid, written by 2.100.x or earlier, still read unknown. Options:

  • (A) Keep them unknown and add a recovery hint that names the marker file. (Recommended for now.)
  • (B) Release them on fence and launcher pid alone. Risk: a supervisor suspended across sleep could resume after the release.
  • (C) Add an explicit ocx update --clear-stale-marker that first checks that no supervisor process exists.

Closes #8524.

@lidge-jun
lidge-jun merged commit e753651 into dev Nov 11, 2026
29 of 30 checks passed
@lidge-jun
lidge-jun deleted the fix/windows-update-marker-release branch November 11, 2026 10:04
lidge-jun added a commit that referenced this pull request Nov 11, 2026
The Windows supervisor tests loaded a data: URL copy of npm-install.mjs that pinned only ./mutation-guard.mjs, so the relative imports #8534 added could not resolve; a shared loader now pins every relative ./*.mjs import and a cross-platform case loads the copy on every host. #8534's win32 rule that skipped a recorded installerPid unless terminationUnconfirmed is reverted; confirmInstallerExit already drops the Windows witness.

Refs #8524
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: ocx update leaves a permanent update-in-flight tombstone on Windows after an interrupted update

1 participant