Repository navigation
fix: gate watchdog recovery on bounded runtime observation #491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dofastted
merged 5 commits into
dofastted:main
from
LJC-god:fix/watchdog-observation-isolation
Oct 17, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
abe2bed
fix: gate watchdog recovery on bounded runtime observation
LJC-god f42e0ae
fix: recreate remote restart loops during watchdog revival
LJC-god 5b3e39c
docs: add CHANGELOG entry for watchdog observation (#491)
cursoragent 0cd2a49
ci: retrigger after flaky panel-users test
cursoragent 9fe10e5
test: stub slotDockerCpus in remote restart-loop vm fixture (#491)
cursoragent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,230 @@ | ||
| import assert from 'node:assert/strict' | ||
| import test from 'node:test' | ||
| import * as watchdog from '../../src/lib/transport/kernel-watchdog.mjs' | ||
| import { kernelFaults } from '../../src/lib/transport/rust-kernel-client.mjs' | ||
|
|
||
| test.afterEach(() => { | ||
| for (const id of ['vm-observation', 'vm-bad', 'vm-good']) kernelFaults.delete(id) | ||
| }) | ||
|
|
||
| function fixture({ state = 'running', runtime, node_id, status = 'running', observe, health, ensure, revive } = {}) { | ||
| let at = 0 | ||
| const actions = [] | ||
| const vm = { id: 'vm-observation', status, runtime, node_id } | ||
| const wd = watchdog.createKernelWatchdog({ | ||
| listTargets: () => [vm], | ||
| now: () => at, | ||
| config: { restart_backoff_sec: [10] }, | ||
| health: health || (async () => null), | ||
| observeRuntime: observe || (async () => ({ state })), | ||
| ensure: | ||
| ensure || | ||
| (async () => { | ||
| actions.push('ensure') | ||
| return { ok: true } | ||
| }), | ||
| revive: | ||
| revive || | ||
| (async () => { | ||
| actions.push('revive') | ||
| return { ok: true } | ||
| }), | ||
| }) | ||
| return { | ||
| wd, | ||
| vm, | ||
| actions, | ||
| advance: (ms) => { | ||
| at = ms | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| for (const state of ['unknown', 'paused']) { | ||
| test(`${state} runtime does not spend recovery budget or cause a restart`, async () => { | ||
| const f = fixture({ state }) | ||
| for (const ms of [0, 10_000, 20_000]) { | ||
| f.advance(ms) | ||
| await f.wd.tick() | ||
| } | ||
| assert.deepEqual(f.actions, []) | ||
| assert.equal(f.wd.restartsInWindow(f.vm.id), 0) | ||
| assert.equal(kernelFaults.has(f.vm.id), false) | ||
| }) | ||
| } | ||
| for (const state of ['missing', 'stopped', 'restarting']) { | ||
| for (const placement of [ | ||
| { runtime: { type: 'docker' } }, | ||
| { runtime: { type: 'kvm' } }, | ||
| { node_id: 'node-fixture' }, | ||
| ]) { | ||
| test(`${state} ${JSON.stringify(placement)} revives only after backoff, without a blind kernel restart`, async () => { | ||
| const f = fixture({ state, ...placement }) | ||
| try { | ||
| await f.wd.tick() | ||
| assert.deepEqual(f.actions, []) | ||
| f.advance(10_000) | ||
| await f.wd.tick() | ||
| assert.deepEqual(f.actions, ['revive']) | ||
| assert.equal(f.wd.restartsInWindow(f.vm.id), 1) | ||
| f.advance(30_000) | ||
| await f.wd.tick() | ||
| assert.deepEqual(f.actions, ['revive']) | ||
| assert.ok(kernelFaults.has(f.vm.id)) | ||
| } finally { | ||
| kernelFaults.delete(f.vm.id) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| test('unknown observations recover without consuming retries; running-but-dead kernel is still restarted', async () => { | ||
| let state = 'unknown' | ||
| const f = fixture({ observe: async () => ({ state }) }) | ||
| await f.wd.tick() | ||
| f.advance(30_000) | ||
| await f.wd.tick() | ||
| state = 'running' | ||
| await f.wd.tick() | ||
| assert.deepEqual(f.actions, []) | ||
| f.advance(40_000) | ||
| await f.wd.tick() | ||
| assert.deepEqual(f.actions, ['ensure']) | ||
| }) | ||
|
|
||
| test('stopped intent is not probed or revived and planned intent is not booted', async () => { | ||
| for (const status of ['stopped', 'disabled', 'planned']) { | ||
| const f = fixture({ state: 'missing', status }) | ||
| await f.wd.tick() | ||
| f.advance(10_000) | ||
| await f.wd.tick() | ||
| assert.deepEqual(f.actions, []) | ||
| assert.equal(f.wd.restartsInWindow(f.vm.id), 0) | ||
| } | ||
| }) | ||
|
|
||
| test('a permission-like container_unavailable result cannot trigger boot without confirmed absence', async () => { | ||
| const f = fixture({ | ||
| ensure: async () => ({ ok: false, reason: 'container_unavailable', error: 'daemon not running' }), | ||
| }) | ||
| await f.wd.tick() | ||
| f.advance(10_000) | ||
| await f.wd.tick() | ||
| assert.deepEqual(f.actions, []) | ||
| }) | ||
|
|
||
| test('hold during an observation prevents restart and releases the in-flight tick', async () => { | ||
| let finish | ||
| const f = fixture({ | ||
| observe: () => | ||
| new Promise((resolve) => { | ||
| finish = resolve | ||
| }), | ||
| }) | ||
| const tick = f.wd.tick() | ||
| await new Promise((r) => setImmediate(r)) | ||
| const held = f.wd.hold(f.vm.id) | ||
| finish({ state: 'missing' }) | ||
| await Promise.all([tick, held]) | ||
| f.advance(10_000) | ||
| await f.wd.tick() | ||
| assert.deepEqual(f.actions, []) | ||
| }) | ||
|
|
||
| test('one rejected health probe or ensure call does not starve the next slot or reject tick', async () => { | ||
| for (const phase of ['health', 'ensure', 'observe']) { | ||
| let at = 0 | ||
| const ensured = [] | ||
| const wd = watchdog.createKernelWatchdog({ | ||
| config: { restart_backoff_sec: [10] }, | ||
| listTargets: () => [{ id: 'vm-bad' }, { id: 'vm-good' }], | ||
| now: () => at, | ||
| health: async (exec) => { | ||
| if (phase === 'health' && exec.vmId === 'vm-bad') throw new Error('fixture health') | ||
| return null | ||
| }, | ||
| observeRuntime: async (vm) => { | ||
| if (phase === 'observe' && vm.id === 'vm-bad') throw new Error('fixture permission') | ||
| return { state: 'running' } | ||
| }, | ||
| ensure: async (exec) => { | ||
| if (phase === 'ensure' && exec.vmId === 'vm-bad') throw new Error('fixture ensure') | ||
| ensured.push(exec.vmId) | ||
| return { ok: true } | ||
| }, | ||
| }) | ||
| await wd.tick() | ||
| at = 10_000 | ||
| await wd.tick() | ||
| assert.ok(ensured.includes('vm-good')) | ||
| } | ||
| }) | ||
|
|
||
| test('overlapping ticks do not duplicate observations or recovery', async () => { | ||
| let finish, | ||
| calls = 0 | ||
| const f = fixture({ | ||
| observe: () => { | ||
| calls++ | ||
| return new Promise((r) => { | ||
| finish = r | ||
| }) | ||
| }, | ||
| }) | ||
| const first = f.wd.tick() | ||
| await new Promise((r) => setImmediate(r)) | ||
| await f.wd.tick() | ||
| assert.equal(calls, 1) | ||
| finish({ state: 'running' }) | ||
| await first | ||
| }) | ||
|
|
||
| test('Docker observation distinguishes 404, HTTP failures, malformed payloads and state flags on the selected host', async () => { | ||
| const cases = [ | ||
| [404, {}, 'missing'], | ||
| [403, {}, 'unknown'], | ||
| [500, {}, 'unknown'], | ||
| [200, {}, 'unknown'], | ||
| [200, { State: { Running: true } }, 'running'], | ||
| [200, { State: { Running: true, Paused: true } }, 'paused'], | ||
| [200, { State: { Running: true, Restarting: true } }, 'restarting'], | ||
| [200, { State: { Running: false, Status: 'exited' } }, 'stopped'], | ||
| [200, { State: { Running: false } }, 'unknown'], | ||
| ] | ||
| for (const [status, payload, state] of cases) { | ||
| const vm = { id: 'vm-fixture', node_id: 'node-fixture', runtime: { container: 'custom/name' } } | ||
| const connector = () => { | ||
| throw new Error('fixture must not connect') | ||
| } | ||
| const result = await watchdog.observeWatchdogContainer(vm, { | ||
| hostFor: (target) => { | ||
| assert.equal(target, vm) | ||
| return { dockerApi: () => connector } | ||
| }, | ||
| request: async (connect, options) => { | ||
| assert.equal(connect, connector) | ||
| assert.equal(options.path, '/containers/custom%2Fname/json') | ||
| return { status, body: Buffer.from(JSON.stringify(payload)) } | ||
| }, | ||
| }) | ||
| assert.equal(result.state, state) | ||
| } | ||
| const options = { hostFor: () => ({ dockerApi: () => () => {} }) } | ||
| for (const request of [ | ||
| async () => { | ||
| throw new Error('EACCES') | ||
| }, | ||
| async () => ({ status: 200, body: Buffer.from('broken json') }), | ||
| ]) { | ||
| assert.equal((await watchdog.observeWatchdogContainer({ id: 'vm-01' }, { ...options, request })).state, 'unknown') | ||
| } | ||
| assert.equal( | ||
| ( | ||
| await watchdog.observeWatchdogContainer( | ||
| { id: 'vm-01' }, | ||
| { ...options, request: () => new Promise(() => {}), timeoutMs: 10 }, | ||
| ) | ||
| ).state, | ||
| 'unknown', | ||
| ) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
observeRuntimereturnsrestartingfor a node-placed Docker slot, this branch spends an attempt and invokes the productionrevivecallback (powerOnSlot). Docker reportsState.Running=trueduring restart-policy backoff (as noted invm-runtime.mjs), sostartRemoteSlotatsrc/lib/cluster/remote-slot.mjs:681-683returnsalready-runningwithout restarting or recreating the container; every watchdog attempt is therefore a no-op untiladmitRestartfaults the VM. This state needs an actual remote restart/recreate path rather than the ordinary revive path.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 4f0b315.
startRemoteSlotnow excludesState.Restartingfrom the reusable-container match, so revival removes/recreates/starts a restart-looping container rather than returningalready-running. Healthy running/stopped/missing/config-mismatch behavior is preserved, and failed removal cannot claim successful recovery.Regression:
node --test test/unit/remote-slot-restart-loop.test.mjs— 10/10 pass, including both Running states, Docker/KVM synthetic fixtures, and a watchdog tick -> real remote lifecycle function-body test. Before the fix: 6 failed / 4 passed. Related selected unit tests: 252/252 pass; formatting/diff checks pass. Fresh independent read-only evidence review: PASS.Tests ran in network/mount-isolated synthetic fixtures; no real remote host or KVM boot was tested. These local results are not a full-suite or current-head CI claim.