rollbridge 0.1.66 → 0.1.68

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1727,6 +1727,62 @@ test("same-authority owner replacement preserves completed activation compensati
1727
1727
  }
1728
1728
  })
1729
1729
 
1730
+ test("deploy after activation compensation in a replacement daemon accepts the unchanged config file", async () => {
1731
+ const root = await fs.mkdtemp(path.join(os.tmpdir(), "rollbridge-owner-replacement-post-compensation-deploy-"))
1732
+ const oldSocketPath = path.join(root, "old.sock")
1733
+ const statePath = path.join(root, "state.json")
1734
+ const configPath = path.join(root, "rollbridge.cjs")
1735
+ const lifecycleLogPath = path.join(root, "generation.lifecycle")
1736
+ const v1Path = path.join(root, "v1")
1737
+ const v2Path = path.join(root, "v2")
1738
+ const v3Path = path.join(root, "v3")
1739
+ let owner
1740
+ let candidate
1741
+ const failedConfig = (/** @type {string} */ controlPath) => {
1742
+ const raw = config({activationLogPath: lifecycleLogPath, controlPath, extraCompanion: false, statePath})
1743
+ const processes = /** @type {Record<string, import("../src/json.js").JsonValue>[]} */ (raw.processes)
1744
+ const generationMain = processes.find((processConfig) => processConfig.id === "generation-main")
1745
+ const lifecycle = /** @type {Record<string, import("../src/json.js").JsonValue>} */ (generationMain?.lifecycle)
1746
+
1747
+ lifecycle.activateCommand = `[ "$ROLLBRIDGE_RELEASE_ID" != v2 ] || exit 24; printf 'activate:%s\\n' "$ROLLBRIDGE_RELEASE_ID" >> ${JSON.stringify(lifecycleLogPath)}`
1748
+ return raw
1749
+ }
1750
+
1751
+ try {
1752
+ await Promise.all([fs.mkdir(v1Path), fs.mkdir(v2Path), fs.mkdir(v3Path)])
1753
+ await Promise.all([v1Path, v2Path, v3Path].map((releasePath) => makeFifo(path.join(releasePath, "worker.fifo"))))
1754
+ await writeConfig(configPath, failedConfig(oldSocketPath))
1755
+ owner = spawn(process.execPath, [binPath, "daemon", "--config", configPath], {stdio: ["ignore", "pipe", "pipe"]})
1756
+ await waitForLog(owner, "control socket listening")
1757
+ await sendControlCommand({command: {command: "deploy", releaseId: "v1", releasePath: v1Path, revision: "v1"}, path: oldSocketPath})
1758
+
1759
+ candidate = spawn(process.execPath, [binPath, "daemon", "--config", configPath, "--replace-owner"], {stdio: ["ignore", "pipe", "pipe"]})
1760
+ await waitForLog(candidate, "owner replacement committed")
1761
+
1762
+ // The measured production sequence (2026-11-16, tensorbuzz/production): the replacement
1763
+ // daemon runs a deploy whose activation fails, compensates, and is then asked to deploy a
1764
+ // new release with the same config file. Compensation leaves the daemon's config authority
1765
+ // as the release definition it inherited through the guardian transfer, so the next deploy
1766
+ // must still accept that unchanged file instead of demanding a daemon restart.
1767
+ await expect(sendControlCommand({command: {command: "deploy", releaseId: "v2", releasePath: v2Path, revision: "v2"}, path: oldSocketPath})).rejects.toThrow(/activate command exited non-zero/)
1768
+ const compensated = await sendControlCommand({command: {command: "status"}, path: oldSocketPath})
1769
+
1770
+ expect(compensated.activeReleaseId).toBe("v1")
1771
+ await sendControlCommand({command: {command: "deploy", releaseId: "v3", releasePath: v3Path, revision: "v3"}, path: oldSocketPath})
1772
+ const deployed = await sendControlCommand({command: {command: "status"}, path: oldSocketPath})
1773
+
1774
+ expect(deployed.activeReleaseId).toBe("v3")
1775
+ const shutdown = sendControlCommand({command: {command: "shutdown"}, path: oldSocketPath})
1776
+
1777
+ await Promise.all([v1Path, v2Path, v3Path].map((releasePath) => fs.writeFile(path.join(releasePath, "worker.fifo"), "drained\n")))
1778
+ await shutdown
1779
+ } finally {
1780
+ for (const child of [owner, candidate]) if (child && child.exitCode === null && child.signalCode === null) child.kill("SIGKILL")
1781
+ await stopGuardian(statePath)
1782
+ await fs.rm(root, {force: true, recursive: true})
1783
+ }
1784
+ })
1785
+
1730
1786
  test("config-changing owner replacement proceeds after activation compensation clears the transition", async () => {
1731
1787
  const root = await fs.mkdtemp(path.join(os.tmpdir(), "rollbridge-owner-replacement-unresolved-config-"))
1732
1788
  const oldSocketPath = path.join(root, "old.sock")
@@ -171,6 +171,68 @@ test("a wedged non-blocking process cannot block release retirement", async () =
171
171
  expect(logs).toMatchObject([{message: "release non-blocking process still draining", data: {pid: 4242, processId: "worker"}}])
172
172
  })
173
173
 
174
+ test("an explicit stop bounds the processes it must not kill and reports what it left alive", async () => {
175
+ /** @type {Array<{message: string, data?: import("../src/json.js").JsonValue}>} */
176
+ const logs = []
177
+ /** @type {Array<{id: string, options: {retirementTimeoutMs?: number, timeoutMs?: number}}>} */
178
+ const stopOptions = []
179
+ const release = buildRelease({command: "run web", id: "web", policy: "proxied", port: {from: 0, to: 0}})
180
+
181
+ release.logger = (message, data) => logs.push({message, data})
182
+ release.nonBlockingDrainIds.add("worker")
183
+
184
+ /**
185
+ * @param {string} id - Process id.
186
+ * @param {boolean} unboundedWindow - Whether its graceful window can ever end.
187
+ * @returns {void} A process recorded in the generation.
188
+ */
189
+ const addProcess = (id, unboundedWindow) => {
190
+ const instance = {
191
+ hasUnboundedGracefulWindow: () => unboundedWindow,
192
+ retirementTimedOut: false,
193
+ status: () => ({pid: 4242, state: "stopped"}),
194
+ stop: async (/** @type {{retirementTimeoutMs?: number, timeoutMs?: number}} */ options) => {
195
+ stopOptions.push({id, options})
196
+ // Only the retirement branch sets this, so a process that was never budgeted never claims it.
197
+ if (options.retirementTimeoutMs !== undefined) instance.retirementTimedOut = true
198
+ }
199
+ }
200
+
201
+ // eslint-disable-next-line local/no-unknown-jsdoc-type
202
+ release.processes.set(id, /** @type {import("../src/managed-process.js").default} */ (/** @type {unknown} */ (instance)))
203
+ }
204
+
205
+ addProcess("worker", false)
206
+ addProcess("jobs-main", true)
207
+ addProcess("web", false)
208
+
209
+ await release.stop({retirementTimeoutMs: 40})
210
+
211
+ expect(stopOptions).toEqual([
212
+ {id: "worker", options: {retirementTimeoutMs: 40}},
213
+ {id: "jobs-main", options: {retirementTimeoutMs: 40}},
214
+ {id: "web", options: {}}
215
+ ])
216
+ expect(release.state).toBe("stopped")
217
+ expect(logs).toMatchObject([
218
+ {message: "release stop gave up waiting for a retiring process", data: {pid: 4242, processId: "worker", releaseId: "v1", timeoutMs: 40}},
219
+ {message: "release stop gave up waiting for a retiring process", data: {pid: 4242, processId: "jobs-main", releaseId: "v1", timeoutMs: 40}}
220
+ ])
221
+
222
+ // Shutdown has no budget to hand out and must still wait for the processes it owns, so an
223
+ // unbudgeted stop changes nothing.
224
+ logs.length = 0
225
+ stopOptions.length = 0
226
+ await release.stop()
227
+
228
+ expect(stopOptions).toEqual([
229
+ {id: "worker", options: {}},
230
+ {id: "jobs-main", options: {}},
231
+ {id: "web", options: {}}
232
+ ])
233
+ expect(logs).toHaveLength(0)
234
+ })
235
+
174
236
  test("restoring a stopped release does not re-adopt a stale connection count", async () => {
175
237
  const release = buildRelease({command: "run web", id: "web", policy: "proxied", port: {from: 0, to: 0}})
176
238
 
@@ -303,4 +365,138 @@ test("a generation still holding a process group after its tracked process exite
303
365
  fs.rmSync(procPath, {force: true, recursive: true})
304
366
  }
305
367
  })
368
+
369
+ /**
370
+ * @param {number} pid - Live pid the supervisor can still signal.
371
+ * @param {string[]} escalations - Collects the reason of every escalation delivered to this process.
372
+ * @returns {import("../src/managed-process.js").default} A process whose retirement wait already expired.
373
+ */
374
+ function wedgedProcess(pid, escalations) {
375
+ // eslint-disable-next-line local/no-unknown-jsdoc-type
376
+ return /** @type {import("../src/managed-process.js").default} */ (/** @type {unknown} */ ({
377
+ escalateRetirement: async (/** @type {{reason: string}} */ options) => {
378
+ escalations.push(options.reason)
379
+
380
+ return true
381
+ },
382
+ quiesceStrict: async () => {},
383
+ retirementTimedOut: true,
384
+ status: () => ({pid, retirementTimedOut: true, state: "quiesced"}),
385
+ stop: async () => {}
386
+ }))
387
+ }
388
+
389
+ test("the supervisor escalates a wedged generation whose residue holds no runner child", async () => {
390
+ const procPath = fs.mkdtempSync(path.join(os.tmpdir(), "rollbridge-escalate-wedged-"))
391
+
392
+ try {
393
+ // Group leader only, 5000ms of consumed CPU: nothing left in the group but the wedged worker.
394
+ writeProcMember(procPath, 101, 101, "S", 300, 200)
395
+
396
+ /** @type {Array<{data?: Record<string, import("../src/json.js").JsonValue>, message: string}>} */
397
+ const logs = []
398
+ /** @type {string[]} */
399
+ const escalations = []
400
+ const release = buildRelease({command: "run web", id: "web", policy: "proxied", port: {from: 0, to: 0}}, () => true, procPath)
401
+
402
+ release.logger = (message, data) => logs.push({data, message})
403
+ release.state = "stopped"
404
+ release.processes.set("worker", wedgedProcess(101, escalations))
405
+ // The generation already recorded `release drained`; this is the observation its retirement
406
+ // left behind, a full window behind the read that now acts on it.
407
+ release.drainNewestSample = {
408
+ atMs: Date.now() - 25000,
409
+ processes: [{cpuMs: 5000, heldProcessGroupPgid: undefined, id: "worker", liveChildCount: 0, pid: 101, retirementTimedOut: true}]
410
+ }
411
+
412
+ const escalated = await release.escalateWedgedGeneration({reason: "deploy of v2"})
413
+
414
+ expect(escalated).toEqual(["worker"])
415
+ expect(escalations).toHaveLength(1)
416
+ expect(escalations[0]).toContain("deploy of v2")
417
+ expect(escalations[0]).toContain("no runner child remaining")
418
+ expect(logs).toMatchObject([{data: {escalation: "SIGKILL", processIds: ["worker"], releaseId: "v1", trigger: "deploy of v2"}, message: "release wedged generation escalated"}])
419
+ } finally {
420
+ fs.rmSync(procPath, {force: true, recursive: true})
421
+ }
422
+ })
423
+
424
+ test("a wedged generation that still holds a live runner child is reported, never killed", async () => {
425
+ const procPath = fs.mkdtempSync(path.join(os.tmpdir(), "rollbridge-escalate-refused-"))
426
+
427
+ try {
428
+ writeProcMember(procPath, 101, 101, "S", 300, 200)
429
+ // A live runner child: the wedge is real, and killing it is still the STOE-1077 failure.
430
+ writeProcMember(procPath, 102, 101, "S", 0, 0)
431
+
432
+ /** @type {Array<{data?: Record<string, import("../src/json.js").JsonValue>, message: string}>} */
433
+ const logs = []
434
+ /** @type {string[]} */
435
+ const escalations = []
436
+ const release = buildRelease({command: "run web", id: "web", policy: "proxied", port: {from: 0, to: 0}}, () => true, procPath)
437
+
438
+ release.logger = (message, data) => logs.push({data, message})
439
+ release.state = "stopped"
440
+ release.processes.set("worker", wedgedProcess(101, escalations))
441
+ release.drainNewestSample = {
442
+ atMs: Date.now() - 25000,
443
+ processes: [{cpuMs: 5000, heldProcessGroupPgid: undefined, id: "worker", liveChildCount: 1, pid: 101, retirementTimedOut: true}]
444
+ }
445
+
446
+ const escalated = await release.escalateWedgedGeneration({reason: "deploy of v2"})
447
+
448
+ expect(escalated).toEqual([])
449
+ expect(escalations).toEqual([])
450
+ expect(logs).toMatchObject([{data: {escalation: "refused", pids: [101], processIds: ["worker"], releaseId: "v1"}, message: "release wedged generation left alive"}])
451
+ expect(logs[0].data?.reason).toBe("no escalation: 1 runner child is still live in the generation; SIGKILL would abort in-flight work")
452
+ } finally {
453
+ fs.rmSync(procPath, {force: true, recursive: true})
454
+ }
455
+ })
456
+
457
+ test("the retirement transition brackets its own wait and reports a residue it cannot yet prove wedged", async () => {
458
+ const procPath = fs.mkdtempSync(path.join(os.tmpdir(), "rollbridge-escalate-bracket-"))
459
+
460
+ try {
461
+ writeProcMember(procPath, 4242, 4242, "S", 300, 200)
462
+
463
+ /** @type {Array<{data?: Record<string, import("../src/json.js").JsonValue>, message: string}>} */
464
+ const logs = []
465
+ /** @type {string[]} */
466
+ const escalations = []
467
+ const release = buildRelease({command: "run web", id: "web", policy: "proxied", port: {from: 0, to: 0}}, () => true, procPath)
468
+
469
+ release.logger = (message, data) => logs.push({data, message})
470
+ release.state = "draining"
471
+ release.nonBlockingDrainIds.add("worker")
472
+ release.handoffServiceIds.add("jobs-main")
473
+ release.processes.set("worker", wedgedProcess(4242, escalations))
474
+ // eslint-disable-next-line local/no-unknown-jsdoc-type
475
+ release.processes.set("jobs-main", /** @type {import("../src/managed-process.js").default} */ (/** @type {unknown} */ ({
476
+ status: () => ({pid: undefined, retirementTimedOut: false, state: "stopped"}),
477
+ stop: async () => {}
478
+ })))
479
+
480
+ await release.drainAndStop(0, {
481
+ ...release.config,
482
+ proxy: {...release.config.proxy, nonBlockingDrainTimeoutMs: 20},
483
+ releaseRetention: {...release.config.releaseRetention, escalateWedgedGenerations: true}
484
+ })
485
+
486
+ // The transition still completes: the escalation is its last act, never a wait of its own.
487
+ expect(release.state).toBe("stopped")
488
+ expect(escalations).toEqual([])
489
+ expect(release.drainPriorSample).toBeDefined()
490
+ expect(release.drainNewestSample).toBeDefined()
491
+ expect(logs).toMatchObject([
492
+ {data: {pid: 4242, processId: "worker"}, message: "release non-blocking process still draining"},
493
+ {data: {escalation: "refused", pids: [4242], releaseId: "v1", trigger: "release retirement"}, message: "release wedged generation left alive"}
494
+ ])
495
+ // A bracket shorter than the flatness window cannot justify a kill; the retained pair is
496
+ // what lets the next deploy prove the residue without sampling on a timer.
497
+ expect(logs[1].data?.reason).toContain("is below the 20000ms minimum")
498
+ } finally {
499
+ fs.rmSync(procPath, {force: true, recursive: true})
500
+ }
501
+ })
306
502
  })
@@ -61,6 +61,63 @@ test("a nonBlockingDrain worker stops immediately while its release is still dra
61
61
  }
62
62
  })
63
63
 
64
+ test("an explicit stop returns within its retirement budget instead of waiting on a worker that is still draining", async () => {
65
+ const fixture = await createFixture({nonBlockingDrainWorker: true, workerStopDelayMs: 30000})
66
+ const config = normalizeConfig({
67
+ ...fixture.config,
68
+ processes: fixture.config.processes.map((processConfig) => processConfig.id === "worker"
69
+ ? {...processConfig, gracefulStopMs: "indefinite"}
70
+ : processConfig),
71
+ proxy: {...fixture.config.proxy, nonBlockingDrainTimeoutMs: 100}
72
+ })
73
+ /** @type {Array<{message: string, data?: import("../src/json.js").JsonValue}>} */
74
+ const logs = []
75
+ const daemon = new RollbridgeDaemon({config, logger: (message, data) => logs.push({message, data})})
76
+ /** @type {number | undefined} */
77
+ let workerPid
78
+
79
+ try {
80
+ await daemon.start()
81
+ await daemon.deploy({releaseId: "v1", releasePath: fixture.root, revision: "v1"})
82
+
83
+ workerPid = statusRelease(daemon, "v1").processes.find((processStatus) => processStatus.id === "worker")?.pid
84
+
85
+ if (typeof workerPid !== "number") throw new Error("Expected the worker to be running before the stop")
86
+
87
+ const startedAtMs = Date.now()
88
+
89
+ await daemon.stopRelease("v1")
90
+
91
+ // Before this the command had no deadline for a worker whose graceful window is "indefinite",
92
+ // so it never returned and held the owner-mutation fence for the whole drain, refusing every
93
+ // later deploy for hours (TensorBuzz production, 2026-11-16). The bound is far below the
94
+ // worker's own 30 000 ms stop delay because the stop must still let the generation's other
95
+ // processes exit; what it must not do is wait for the worker at all.
96
+ expect(Date.now() - startedAtMs).toBeLessThan(10000)
97
+
98
+ await retirementRecordSettled(daemon, "v1", "worker")
99
+
100
+ const stopped = statusRelease(daemon, "v1")
101
+ const stoppedWorker = stopped.processes.find((processStatus) => processStatus.id === "worker")
102
+
103
+ expect(stopped.state).toBe("stopped")
104
+ expect(stoppedWorker?.retirementTimedOut).toBe(true)
105
+ // The tracked record is the shell wrapper, which is already gone; the worker it launched is
106
+ // still draining inside the same process group, and that is the residue the stop must report.
107
+ expect(stoppedWorker?.heldProcessGroup?.liveMemberCount).toBeGreaterThan(0)
108
+ expect(logs.filter((entry) => entry.message === "release stop gave up waiting for a retiring process")).toMatchObject([
109
+ {data: {processId: "worker", releaseId: "v1", timeoutMs: 100}}
110
+ ])
111
+ expect(logs.filter((entry) => entry.message === "release stopped")).toMatchObject([{data: {releaseId: "v1"}}])
112
+ } finally {
113
+ await daemon.shutdown()
114
+ if (workerPid !== undefined) {
115
+ try { process.kill(-workerPid, "SIGKILL") } catch (_error) { /* The group already exited. */ }
116
+ }
117
+ await fs.rm(fixture.root, {force: true, recursive: true})
118
+ }
119
+ })
120
+
64
121
  test("deploy switches new HTTP traffic while old WebSockets drain", async () => {
65
122
  const fixture = await createFixture()
66
123
  const daemon = await startDaemon(fixture.config)
@@ -2064,6 +2121,51 @@ test("a draining-generation bound of 0 leaves concurrent drains unbounded", asyn
2064
2121
  }
2065
2122
  })
2066
2123
 
2124
+ test("a deploy is the event that asks a retiring generation for its escalation decision, and nothing else does", async () => {
2125
+ const config = normalizeConfig({
2126
+ application: "demo",
2127
+ control: {path: path.join(os.tmpdir(), "rollbridge-escalate-gate.sock")},
2128
+ processes: [{command: `${JSON.stringify(process.execPath)} -e "setInterval(() => {}, 1000)"`, id: "web", policy: "proxied", port: {from: 0, to: 0}}],
2129
+ proxy: {host: "127.0.0.1", port: 0}
2130
+ })
2131
+ const daemon = new RollbridgeDaemon({config, logger: () => {}})
2132
+ /** @type {Array<{reason: string, releaseId: string}>} */
2133
+ const decided = []
2134
+
2135
+ /**
2136
+ * @param {string} releaseId - Generation id.
2137
+ * @param {import("../src/release-group.js").ReleaseState} state - Recorded state of the generation.
2138
+ * @returns {import("../src/release-group.js").default} A generation that only records the decision request.
2139
+ */
2140
+ // eslint-disable-next-line local/no-unknown-jsdoc-type
2141
+ const retiringRelease = (releaseId, state) => /** @type {import("../src/release-group.js").default} */ (/** @type {unknown} */ ({
2142
+ escalateWedgedGeneration: async (/** @type {{reason: string}} */ options) => {
2143
+ decided.push({reason: options.reason, releaseId})
2144
+
2145
+ return []
2146
+ },
2147
+ releaseId,
2148
+ state
2149
+ }))
2150
+
2151
+ daemon.releases.set("draining", retiringRelease("draining", "draining"))
2152
+ daemon.releases.set("drained", retiringRelease("drained", "stopped"))
2153
+ daemon.releases.set("active", retiringRelease("active", "active"))
2154
+
2155
+ // Off by default: enabling the escalation is the operator's decision, not the daemon's.
2156
+ await daemon.escalateWedgedGenerations(config, "candidate")
2157
+
2158
+ expect(decided).toEqual([])
2159
+
2160
+ const escalating = normalizeConfig({...config, releaseRetention: {...config.releaseRetention, escalateWedgedGenerations: true}})
2161
+
2162
+ await daemon.escalateWedgedGenerations(escalating, "candidate")
2163
+
2164
+ // Every generation still holding a retirement — draining, drained with residue, or failed —
2165
+ // is asked; the active one and the candidate itself are not.
2166
+ expect(decided).toEqual([{reason: "deploy of candidate", releaseId: "draining"}, {reason: "deploy of candidate", releaseId: "drained"}])
2167
+ })
2168
+
2067
2169
  test("status reports the drain classification of each draining generation", async () => {
2068
2170
  const fixture = await createFixture()
2069
2171
  const daemon = await startDaemon(fixture.config)
@@ -2108,6 +2210,7 @@ test("rollback refuses to restore a drained generation that still holds live pro
2108
2210
  // The tracked process (the shell wrapper) is already gone, so the only honest record of
2109
2211
  // the leak is the process group that outlived it.
2110
2212
  await waitFor(() => statusRelease(daemon, "v1").state === "stopped")
2213
+ await retirementRecordSettled(daemon, "v1", "worker")
2111
2214
 
2112
2215
  const worker = statusRelease(daemon, "v1").processes.find((processStatus) => processStatus.id === "worker")
2113
2216
 
@@ -2183,6 +2286,7 @@ test("a restore deploy naming a drained generation that outlived its tracked pro
2183
2286
  // shell wrapper led. The 2026-10-25 carve-out that lets a dead generation's process key be
2184
2287
  // re-registered does not apply here: the group is alive, so the key is still held.
2185
2288
  await waitFor(() => statusRelease(daemon, "v1").state === "stopped")
2289
+ await retirementRecordSettled(daemon, "v1", "worker")
2186
2290
 
2187
2291
  const worker = statusRelease(daemon, "v1").processes.find((processStatus) => processStatus.id === "worker")
2188
2292
 
@@ -2651,6 +2755,27 @@ function statusRelease(daemon, releaseId) {
2651
2755
  return release
2652
2756
  }
2653
2757
 
2758
+ /**
2759
+ * Waits until the daemon has observed the exit of a retiring process's tracked wrapper.
2760
+ *
2761
+ * A bounded retirement stop returns the moment its budget expires — that is the whole point of
2762
+ * the bound — while the wrapper it just signalled is still on its way out, so for a few
2763
+ * milliseconds the record still carries the wrapper pid and reports the process `quiesced`. The
2764
+ * residue the drain specs assert (the process group that outlived the tracked process) is
2765
+ * recorded by that exit observation, not by the stop call, so a spec that reads the record
2766
+ * straight after the stop returns races the observation it is describing. Measured on
2767
+ * 2026-11-16: `stopRelease` returned after 106 ms with `{pid: 13640, state: "quiesced"}` and the
2768
+ * record settled to `{heldProcessGroup: {liveMemberCount: 1, pgid: 13640}, state: "stopped"}`
2769
+ * within the next 50 ms.
2770
+ * @param {RollbridgeDaemon} daemon - Running daemon.
2771
+ * @param {string} releaseId - Retained generation to observe.
2772
+ * @param {string} processId - Process whose wrapper exit must be observed.
2773
+ * @returns {Promise<void>} Resolves once the process record has settled.
2774
+ */
2775
+ async function retirementRecordSettled(daemon, releaseId, processId) {
2776
+ await waitFor(() => statusRelease(daemon, releaseId).processes.find((processStatus) => processStatus.id === processId)?.state === "stopped")
2777
+ }
2778
+
2654
2779
  /**
2655
2780
  * Maps process id to pid across the active release, services, and singletons.
2656
2781
  * @param {import("../src/daemon.js").DaemonStatus} status - Daemon status payload.
@@ -24,7 +24,9 @@ export function isProcessRunning(pid) {
24
24
 
25
25
  return state !== "Z" && state !== "X"
26
26
  } catch (error) {
27
- if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") return false
27
+ // The pid can be reaped between the signal probe and this read, and procfs reports that as
28
+ // ESRCH rather than ENOENT. Both mean the same thing here: there is no process left to wait on.
29
+ if (error && typeof error === "object" && "code" in error && (error.code === "ENOENT" || error.code === "ESRCH")) return false
28
30
  throw error
29
31
  }
30
32
  }