Skip to content

test(hosts): fix update-worker timeout flake blocking #576 - #577

Merged
kahme247 merged 1 commit into
mainfrom
fix-update-worker-flake-2026-11-24
Nov 24, 2026
Merged

kahme247 merged 1 commit into
mainfrom
fix-update-worker-flake-2026-11-24

Conversation

@kahme247

@kahme247 kahme247 commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes the lib/hosts/update-worker.test.mjs flake that fails Verify on #576 (run 1 Ubuntu and run 2 macOS, both at :1127): a replacement health.json exists when the test expects none, in "a pending stop whose process identity changes retains recovery-required state and its claim".

Root cause

A test-fixture timing race — no production code changed. The fixture's daemon delays its SIGTERM exit by 11 s, but the stop wait is 10 s, leaving only a ~1 s margin between the stop timing out (stop_pending) and the daemon exiting:

  1. The stop wait throws at ~10 s; the test's patched stopUpgradeProcess mutates plan.current.identity to simulate a recycled/unverifiable identity, and the worker calls reconcilePendingStop.
  2. reconcilePendingStop reads the identity, finds it mismatched, and then re-checks aliveness: if the daemon is still alive it throws (recovery-required, no replacement — the expected path), but if the daemon has already exited it returns success ("a successful signal may outlast the stop wait").
  3. On success the worker rolls back and relaunches the old release, which writes health.json — so :1127 fails (true !== false).

Under a loaded CI runner a slow identity read (macOS spawns ps for it) or a stalled worker easily eats the 1 s margin. Proven locally: delaying the copied worker's identity read by 2 s flips the outcome deterministically — the test fails with state "failed" and "previous host release restored" instead of "running" with recoveryRequired. The same 2 s delay with the fix below still passes.

Fix (test file only)

  • The unreconciled-stop fixture's shutdownDelay goes from 11 s to 60 s, so the daemon is certainly alive when reconciliation reads its identity. The test still ends at ~11 s (the identity mismatch fails reconciliation on its first read), and the after-hook SIGKILLs the lingering daemon.
  • The neighbouring delayed-stop / stop-identity-exit-race tests keep 11 s on purpose: they need the daemon to exit for their own reconciliation path.

No production defect was found: when the daemon really has exited, proceeding to relaunch the old release is the designed behaviour — the test's scenario is a live process with an unverifiable identity, and only the fixture's 1 s margin failed to guarantee that.

Verification

  • bun test on the fixed test: 3/3 pass under hostile umask 0007 (~11 s each, same as before).
  • Robustness check: the same 2 s identity-read delay that deterministically flipped the outcome before now still passes.
  • Neighbours under umask 0007: both "pending stop" tests pass; "delayed-stop" 3/3; the pin-external-runner-swap test 3/3.
  • Full file lib/hosts/update-worker.test.mjs: 86 pass / 0 fail (post-fix run).
  • npx tsc --noEmit and npx eslint lib/hosts/update-worker.test.mjs: clean.

Deliberately left out: the run-2 macOS :1097 failure (stop-identity-exit-race) and the pin-external-runner-swap digest-mismatch note did not reproduce locally (both pass repeatedly here, including under umask 0007), and the digest-mismatch error cannot come from the stop-identity-exit-race worker — its descriptor carries no release pin. Left for observation on the next CI run rather than bundling an unproven fix. The run-2 Ubuntu lib/web-settings.test.mjs:363 failure is a different area and untouched.

Unblocks #576.

Summary by CodeRabbit

  • Tests
    • Updated automated coverage for a daemon stop and recovery scenario. The test now keeps the signalled daemon running longer, while retaining the existing identity-mismatch setup and recovery-state checks. No user-facing behavior changes are included in this update.

@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The unreconciled-stop test now keeps the signalled daemon alive for 60 seconds instead of 11 seconds. The identity-mismatch setup and recovery-state assertions remain unchanged.

Changes: Update worker test timing

Layer / File(s) Summary
Extend daemon shutdown delay
lib/hosts/update-worker.test.mjs
The test documents the timing issue and increases the signalled daemon shutdown delay from 11 seconds to 60 seconds. The existing identity-mismatch setup and recovery-state assertions are unchanged.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Other

Suggested reviewers: andrebrait

Merge Risk: Minimal · up to 32eaa

This is a test-only timing fix that makes a flaky test deterministic. It has no production impact and is ready to merge.

Architecture risk: Low · up to 32eaa

The change affects 1 system.

Changed systems: lib

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — lib (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in lib/hosts/update-worker.test.mjs: The test now documents the timing issue and uses a 60-second shutdown delay instead of 11 seconds; the surrounding identity-mismatch and recovery-state checks remain unchanged.
Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the test(hosts) scope and the update-worker timeout flake fix. The raw summary confirms the only change is a test fixture delay for the unreconciled-stop test, raised from 11 to 60 sec…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the test(hosts) scope and the update-worker timeout flake fix. The raw summary confirms the only change is a test fixture delay for the unreconciled-stop test, raised from 11 to 60 seconds. The title states the type and purpose, and it matches the main change. It omits the specific test name, which is acceptable for a concise title. The #576 reference points to the blocked item, so it adds context but does not mislead.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f56b6604-1e54-4d5e-aaf3-76db0ebf22de
Commits

Reviewing files that changed from the base of the PR and between 76a8a9c and 32eaa9b.

Files selected for processing: 1

  • lib/hosts/update-worker.test.mjs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

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