Skip to content

fix(updater): keep a confirmed worker's next update from rolling back - #10

Merged
nixuuu merged 1 commit into
devfrom
fix/updater-candidate-rollback
Nov 3, 2026
Merged

nixuuu merged 1 commit into
devfrom
fix/updater-candidate-rollback

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 3, 2026

Copy link
Copy Markdown
Member

After a gateway update the worker showed Failed — New version exited before becoming healthy (exit 75); clicking Update worker then worked.

The supervisor (superviseBinary) decided once, when it spawned a child, whether that child was an update candidate. A candidate that confirmed its startup and later applied the next update (writing a new restarting record and exiting 75) was still treated as an unconfirmed candidate, so its restart request was rolled back — every second update failed. The candidate is now tracked by the update's commandId: only a child that never confirmed its own update is rolled back; a confirmed child's exit 75 is a normal restart.

New updater test reproduces it (fails before the change, passes after); updates integration tests and typecheck pass.

Note: the running supervisor is the binary loaded when the service started, so installs pick this up after the worker service restarts once on a fixed version.

The supervisor decided once, when it started a child, whether that child was an update candidate. A candidate that confirmed its startup and later applied the next update (exit 75) was still treated as unconfirmed, so every second update rolled back with "New version exited before becoming healthy (exit 75)". The candidate is now tracked by its update command id.
@nixuuu
nixuuu merged commit 66c5b19 into dev Nov 3, 2026
2 checks passed
@nixuuu
nixuuu deleted the fix/updater-candidate-rollback branch November 3, 2026 14:27
nixuuu added a commit that referenced this pull request Nov 3, 2026
Standalone worker and gateway binaries run a resident supervisor that
was never replaced: it kept the code of whatever version systemd
started. On production it ran pre-#10 code for hours, so every second
automatic update rolled back with "exit 75" until a manual restart.

Now, after a confirmed update, the supervisor asks the healthy child
over IPC to hand over; the child uses the existing idle/drain mechanics
(never interrupts work), exits with 76, and the supervisor
`process.execve`s the installed binary, keeping its PID (systemd/launchd
need no changes). Unconfirmed candidates keep the rollback watchdog; no
hand-over on rollback, on execve failure (logged, keeps running) or on
Windows/without execve; a supervisor already matching the binary does
nothing (no loops). Children under an older supervisor without IPC are
unaffected. Docker, source and desktop installs are unchanged.

Tests: real compiled binaries A → B → C replace the supervisor code with
the same PID; rollback, active work, replacement races, startup
mismatch, no restart loop, execve failure. check:tmp 683 pass / 0 fail.
Supervisors started before this version need one manual restart to load
it.
nixuuu added a commit that referenced this pull request Nov 12, 2026
The chained-update watchdog test intermittently exposed an empty or
partially written `.update.json` through shell `>` redirection. CI run
43270195463, attempt 2, failed with `SyntaxError: Unexpected EOF` in
`readUpdateRecord`. The production writer has used a private temporary
file, file `fsync`, and atomic rename since its introduction; the
failing fixture bypassed it.

The v2 and v3 fixtures now call the real `confirmStartup` and
`stageBinaryUpdate` APIs. A deterministic write barrier pauses the real
confirmation writer after half its bytes and checks that readers still
see the previous pending record, then the complete confirmation. A torn
authoritative JSON regression checks that corruption remains an error.
No read retries or updater/protocol behavior changes are needed for this
failure. The frozen update protocol is untouched.

Validation: Bun 1.4.4; `bun install --frozen-lockfile`; 10 consecutive
separate executions of `TMPDIR=/var/tmp nice -n 19 bun test
packages/updater/src/binary.test.ts` (8 tests each, 80 passes, 0
failures, about 4 seconds total); repository-wide `bun run lint` and
`bun run format:check`; `git diff --check`. Generation, typecheck, the
full test/temp checks, and builds are left to CI under the local
verification constraints. CI repetition is pending.

History: #10 introduced the shell fixture; this test-only correction
uses `Related:` so it does not trigger a release/promotion hold.

Related: #10
Related: #582
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant