rollbridge 0.1.67 → 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.
@@ -0,0 +1,11 @@
1
+ ## Fixed
2
+
3
+ - Make a normalized config identical to its own JSON form, so a release config
4
+ that crossed the guardian's owner-replacement transfer is still equal to the
5
+ config file it came from. Owner replacement publishes release configs over the
6
+ guardian's JSON socket, which drops undefined-valued properties; the candidate
7
+ daemon then held a config that no longer matched its own file, and the next
8
+ deploy aborted with "Config changes to control cannot be applied live" even
9
+ though the file was byte-identical and hashed to the same owner-config digest
10
+ (measured on tensorbuzz/production, 2026-11-16). The only remedy the tool
11
+ offered was a manual daemon restart.
@@ -0,0 +1,29 @@
1
+ ### Fixed
2
+
3
+ - Four drain/retirement specs read the daemon's process record before the daemon had observed the
4
+ event they describe, and failed intermittently on a busy runner while passing locally. Measured
5
+ here in a `node:26` container against `origin/master` `c390da9` (2026-11-16): running the three
6
+ `test/rollbridge.test.js` specs on their own gave `an explicit stop returns within its retirement
7
+ budget…` 0/6 passing, `rollback refuses to restore a drained generation…` 2/6 and `a restore
8
+ deploy naming a drained generation…` 2/6, and `test/managed-process.test.js` "a retirement budget
9
+ caps a finite graceful window…" 0/4. The same invocations inside the whole file passed, which is
10
+ what made them look green locally and red in CI: every recent `rollbridge` master commit carries
11
+ a failed `TensorBuzz: build_1` naming one of these specs.
12
+ - `test/rollbridge.test.js` now gates on the settled record. A bounded retirement stop returns the
13
+ moment its budget expires — that is the point of the bound — while the shell wrapper it signalled
14
+ is still on its way out, so the record briefly reports the wrapper pid and `state: "quiesced"`,
15
+ and `ManagedProcess.currentHeldProcessGroup()` deliberately reports nothing until the tracked
16
+ process is `stopped`. Measured: `stopRelease` returned after 106 ms with
17
+ `{pid: 13640, retirementTimedOut: true, state: "quiesced"}` and the record settled to
18
+ `{heldProcessGroup: {liveMemberCount: 1, pgid: 13640}, state: "stopped"}` within the next 50 ms.
19
+ The new `retirementRecordSettled` helper waits for that observation before the assertions, so the
20
+ specs still prove the group outlived its tracked process instead of assuming it.
21
+ - `test/managed-process.test.js` "a retirement budget caps a finite graceful window instead of being
22
+ outvoted by it" signalled its fixture before the fixture had installed its `SIGTERM` disposition,
23
+ so the default disposition applied, the group exited, `waitForProcessGroupExit` returned true, and
24
+ `retirementTimedOut` stayed false — the same boot race the neighbouring specs already gate on. It
25
+ now announces readiness the same way (`require("node:fs").writeFileSync(readyPath, "ready")` after
26
+ the handler is installed) and waits for that marker before the stop.
27
+ - No product behaviour changed and no wait was lengthened: the gates are on durable observations
28
+ (a process record reaching `stopped`, a marker file the fixture writes), so a daemon that never
29
+ records the residue still fails.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rollbridge",
3
- "version": "0.1.67",
3
+ "version": "0.1.68",
4
4
  "description": "Zero-downtime process supervisor and local traffic switcher for deploy-managed apps.",
5
5
  "keywords": [
6
6
  "deploy",
package/src/config.js CHANGED
@@ -160,6 +160,32 @@ export function normalizeConfig(rawConfig, configPath = process.cwd()) {
160
160
  return config
161
161
  }
162
162
 
163
+ /**
164
+ * Drops every undefined-valued property so a normalized config is identical to its own JSON form.
165
+ *
166
+ * Owner replacement hands the candidate daemon its release configs through the guardian's JSON
167
+ * socket, and JSON serialization drops undefined-valued keys. The inherited config then compares
168
+ * unequal to a freshly loaded one under `isDeepStrictEqual` even when the config file never
169
+ * changed, and the live-reload fence aborts the next deploy. Measured in production on 2026-11-16
170
+ * (tensorbuzz/production): after a failed activation was compensated inside a replacement daemon,
171
+ * the following deploy failed with "Config changes to control cannot be applied live" while both
172
+ * config files were byte-identical and hashed to the same `ownerConfigDigest` — that digest is
173
+ * JSON-based, so the daemon held two contradictory notions of the same config and only the
174
+ * JSON-shaped one survived the handoff.
175
+ * @param {JsonValue} value - Normalized config value.
176
+ * @returns {JsonValue} The same value with every undefined-valued property removed.
177
+ */
178
+ function withoutUndefinedProperties(value) {
179
+ if (Array.isArray(value)) return value.map(withoutUndefinedProperties)
180
+ if (isPlainObject(value)) {
181
+ return Object.fromEntries(Object.entries(value)
182
+ .filter(([, entryValue]) => entryValue !== undefined)
183
+ .map(([key, entryValue]) => [key, withoutUndefinedProperties(entryValue)]))
184
+ }
185
+
186
+ return value
187
+ }
188
+
163
189
  /**
164
190
  * Validates a raw config object and collects every issue instead of throwing on the first one.
165
191
  * @param {JsonValue} rawConfig - Parsed config.
@@ -205,7 +231,7 @@ export function validateConfig(rawConfig, configPath = process.cwd()) {
205
231
  validateComposeUnits(compose, processes, issues)
206
232
 
207
233
  return {
208
- config: {
234
+ config: /** @type {RollbridgeConfig} */ (withoutUndefinedProperties(/** @type {JsonValue} */ ({
209
235
  application,
210
236
  ...(compose.length > 0 ? {compose} : {}),
211
237
  ...(composeStatePath ? {composeStatePath} : {}),
@@ -216,7 +242,7 @@ export function validateConfig(rawConfig, configPath = process.cwd()) {
216
242
  proxy,
217
243
  releaseRetention,
218
244
  statePath
219
- },
245
+ }))),
220
246
  issues
221
247
  }
222
248
  }
@@ -59,8 +59,10 @@ test("a Compose unit is normalized with drain-first defaults", () => {
59
59
  expect(unit.composeFile).toBe("compose.yml")
60
60
  expect(unit.stopGracePeriodMs).toBe(10000)
61
61
  expect(unit.recreateTimeoutMs).toBe(120000)
62
- expect(unit.drain).toEqual({command: undefined, timeoutMs: 60000})
63
- expect(unit.inFlight).toEqual({command: undefined, intervalMs: 1000, timeoutMs: 0})
62
+ // Unset commands are absent from the normalized shape rather than present as undefined, so a unit
63
+ // definition that crossed the guardian's JSON transfer is still equal to a freshly loaded one.
64
+ expect(unit.drain).toEqual({timeoutMs: 60000})
65
+ expect(unit.inFlight).toEqual({intervalMs: 1000, timeoutMs: 0})
64
66
  expect(unit.activation).toMatchObject({healthcheck: true, intervalMs: 1000, startDelayMs: 0, timeoutMs: 60000})
65
67
  expect(unit.rollback).toEqual({enabled: true})
66
68
  expect(config.composeStatePath).toBe(path.resolve("/srv/app", "rollbridge-compose-config-test.compose.state.json"))
@@ -143,7 +143,9 @@ test("validateConfig defaults the restart policy, accepts overrides, and rejects
143
143
  const defaulted = validateRestart(undefined)
144
144
 
145
145
  expect(defaulted.issues).toEqual([])
146
- expect(defaulted.config.processes[0].restart).toEqual({backoffFactor: 1, maxDelayMs: 0, maxRestarts: undefined, windowMs: 0})
146
+ // Unset values are absent from the normalized shape rather than present as undefined, so a config
147
+ // that crossed the guardian's JSON transfer is still equal to a freshly loaded one.
148
+ expect(defaulted.config.processes[0].restart).toEqual({backoffFactor: 1, maxDelayMs: 0, windowMs: 0})
147
149
 
148
150
  const custom = validateRestart({backoffFactor: 2, maxDelayMs: 30000, maxRestarts: 5, windowMs: 60000})
149
151
 
@@ -771,6 +773,24 @@ test("ownerRecovery requires durable state and a non-negative integer reconnecti
771
773
  expect(invalidGrace.issues.some((issue) => issue.message === "ownerRecovery.reconnectGraceMs must be a non-negative integer")).toBeTruthy()
772
774
  })
773
775
 
776
+ test("a normalized config is identical to its own JSON form, so the guardian transfer cannot change it", () => {
777
+ const {config, issues} = validateConfig({
778
+ application: "demo",
779
+ control: {path: "/tmp/demo.sock"},
780
+ processes: [{command: "run web", id: "web", policy: "proxied", port: {from: 18000, to: 18099}}],
781
+ proxy: {host: "127.0.0.1", port: 8182}
782
+ }, "/srv/app/rollbridge.js")
783
+
784
+ expect(issues).toEqual([])
785
+
786
+ // Owner replacement publishes release configs to the candidate daemon over the guardian's JSON
787
+ // socket, which drops undefined-valued properties. A config that is not its own JSON form therefore
788
+ // arrives at the candidate unequal to the config file it was started from, and the live-reload fence
789
+ // aborts the next deploy with "Config changes to control cannot be applied live" even though the
790
+ // file never changed — measured in production on 2026-11-16 (tensorbuzz/production).
791
+ expect(config).toEqual(JSON.parse(JSON.stringify(config)))
792
+ })
793
+
774
794
  test("normalizeConfig throws an aggregated error listing every issue", async () => {
775
795
  const normalization = Promise.resolve().then(() => normalizeConfig({
776
796
  application: "demo",
@@ -486,8 +486,10 @@ test("a retirement budget caps a finite graceful window instead of being outvote
486
486
  const signals = []
487
487
  /** @type {Array<{msFromStopStart: number, phase: string}>} */
488
488
  const deadlines = []
489
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "rollbridge-retirement-bound-"))
490
+ const readyPath = path.join(dir, "ready")
489
491
  const managed = new ManagedProcess({
490
- command: `${JSON.stringify(process.execPath)} -e ${JSON.stringify("process.on('SIGTERM', () => {}); setInterval(() => {}, 1000)")}`,
492
+ command: `${JSON.stringify(process.execPath)} -e ${JSON.stringify(`process.on('SIGTERM', () => {}); require("node:fs").writeFileSync(${JSON.stringify(readyPath)}, "ready"); setInterval(() => {}, 1000)`)}`,
491
493
  cwd: undefined,
492
494
  env: {},
493
495
  id: "worker",
@@ -525,6 +527,10 @@ test("a retirement budget caps a finite graceful window instead of being outvote
525
527
 
526
528
  try {
527
529
  await managed.start()
530
+ // The fixture installs its SIGTERM disposition before it announces readiness. Signalling a
531
+ // child that has not finished booting reaches the default disposition instead, which exits
532
+ // the group and leaves no retirement wait to observe.
533
+ await waitFor(() => fs.existsSync(readyPath))
528
534
  stopStartedAtMs = Date.now()
529
535
 
530
536
  await managed.stop({retirementTimeoutMs: 25})
@@ -545,6 +551,7 @@ test("a retirement budget caps a finite graceful window instead of being outvote
545
551
  const pid = managed.status().pid
546
552
  if (pid) process.kill(-pid, "SIGKILL")
547
553
  if (managed.exitPromise) await managed.exitPromise
554
+ fs.rmSync(dir, {force: true, recursive: true})
548
555
  }
549
556
  })
550
557
 
@@ -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")
@@ -95,6 +95,8 @@ test("an explicit stop returns within its retirement budget instead of waiting o
95
95
  // processes exit; what it must not do is wait for the worker at all.
96
96
  expect(Date.now() - startedAtMs).toBeLessThan(10000)
97
97
 
98
+ await retirementRecordSettled(daemon, "v1", "worker")
99
+
98
100
  const stopped = statusRelease(daemon, "v1")
99
101
  const stoppedWorker = stopped.processes.find((processStatus) => processStatus.id === "worker")
100
102
 
@@ -2208,6 +2210,7 @@ test("rollback refuses to restore a drained generation that still holds live pro
2208
2210
  // The tracked process (the shell wrapper) is already gone, so the only honest record of
2209
2211
  // the leak is the process group that outlived it.
2210
2212
  await waitFor(() => statusRelease(daemon, "v1").state === "stopped")
2213
+ await retirementRecordSettled(daemon, "v1", "worker")
2211
2214
 
2212
2215
  const worker = statusRelease(daemon, "v1").processes.find((processStatus) => processStatus.id === "worker")
2213
2216
 
@@ -2283,6 +2286,7 @@ test("a restore deploy naming a drained generation that outlived its tracked pro
2283
2286
  // shell wrapper led. The 2026-10-25 carve-out that lets a dead generation's process key be
2284
2287
  // re-registered does not apply here: the group is alive, so the key is still held.
2285
2288
  await waitFor(() => statusRelease(daemon, "v1").state === "stopped")
2289
+ await retirementRecordSettled(daemon, "v1", "worker")
2286
2290
 
2287
2291
  const worker = statusRelease(daemon, "v1").processes.find((processStatus) => processStatus.id === "worker")
2288
2292
 
@@ -2751,6 +2755,27 @@ function statusRelease(daemon, releaseId) {
2751
2755
  return release
2752
2756
  }
2753
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
+
2754
2779
  /**
2755
2780
  * Maps process id to pid across the active release, services, and singletons.
2756
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
  }