@camstack/server 1.2.303 → 1.2.304

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.
@@ -55,6 +55,7 @@ const package_dir_utils_1 = require("./package-dir-utils");
55
55
  const forked_custom_actions_js_1 = require("./forked-custom-actions.js");
56
56
  const prune_misplaced_addons_js_1 = require("./prune-misplaced-addons.js");
57
57
  const runner_convergence_1 = require("./runner-convergence");
58
+ const runner_serialization_1 = require("./runner-serialization");
58
59
  const runner_spawn_fanout_js_1 = require("./runner-spawn-fanout.js");
59
60
  /**
60
61
  * Decide whether an in-memory addon entry should be evicted because it is no
@@ -3167,6 +3168,12 @@ class AddonRegistryService {
3167
3168
  * a group respawns the ENTIRE group (they share a process): the operator's
3168
3169
  * "update one → respawn the whole group" invariant.
3169
3170
  */
3171
+ /**
3172
+ * One converge at a time per runner. See `runner-serialization.ts` for the
3173
+ * two live episodes this closes and why the lock inside `process-service`
3174
+ * could not.
3175
+ */
3176
+ serializeRunner = (0, runner_serialization_1.createRunnerSerializer)();
3170
3177
  async ensureForkedRunner(addonId, opts) {
3171
3178
  const entry = this.addonEntries.get(addonId);
3172
3179
  if (!entry?.declaration || !entry.addonDir) {
@@ -3188,43 +3195,52 @@ class AddonRegistryService {
3188
3195
  Date.now() - (this.recentGroupRespawns.get(runnerId) ?? 0) < GROUP_RESPAWN_COALESCE_MS
3189
3196
  ? false
3190
3197
  : opts.restart;
3191
- const running = await this.listRunnerProcesses();
3192
- const plan = (0, runner_convergence_1.planRunnerConvergence)(runnerId, roster.map((r) => r.addonId), running, { restart: effectiveRestart });
3193
- // 1. Tear down every stale/mismatched runner that hosts a roster member.
3194
- for (const name of plan.stop) {
3195
- await this.broker.call('$process.stop', { name }).catch((err) => {
3196
- this.logger.warn('ensureForkedRunner: failed to stop stale runner (continuing)', {
3197
- meta: { runnerId, stale: name, error: (0, types_1.errMsg)(err) },
3198
+ // EVERYTHING from here is one atomic unit per runner. The read decides what
3199
+ // to stop and what to spawn, so a second converge that reads before this
3200
+ // one has spawned decides to spawn too — and the child nobody tracks keeps
3201
+ // running. `process-service`'s own lock cannot see this: it makes each
3202
+ // action atomic, and the unit that matters is the sequence.
3203
+ return this.serializeRunner(runnerId, async () => {
3204
+ const running = await this.listRunnerProcesses();
3205
+ const plan = (0, runner_convergence_1.planRunnerConvergence)(runnerId, roster.map((r) => r.addonId), running, { restart: effectiveRestart });
3206
+ // 1. Tear down every stale/mismatched runner that hosts a roster member.
3207
+ for (const name of plan.stop) {
3208
+ await this.broker.call('$process.stop', { name }).catch((err) => {
3209
+ this.logger.warn('ensureForkedRunner: failed to stop stale runner (continuing)', {
3210
+ meta: { runnerId, stale: name, error: (0, types_1.errMsg)(err) },
3211
+ });
3198
3212
  });
3199
- });
3200
- }
3201
- // 2. Bring the target runner to the correct roster.
3202
- if (plan.action === 'spawn') {
3203
- await this.broker.call('$process.spawnRunner', { runnerId, addons: roster }).catch((err) => {
3204
- // A concurrent path may have won the spawn race — treat "already
3205
- // running" as success (idempotent), rethrow anything else.
3206
- if (!/already running/i.test((0, types_1.errMsg)(err)))
3207
- throw err;
3208
- });
3209
- this.recentGroupRespawns.set(runnerId, Date.now());
3210
- }
3211
- else if (plan.action === 'restart') {
3212
- const res = (await this.broker.call('$process.restart', { name: runnerId }));
3213
- if (!res.success) {
3214
- throw new Error(`Process restart failed: ${res.reason ?? 'unknown'}`);
3215
3213
  }
3216
- this.recentGroupRespawns.set(runnerId, Date.now());
3217
- }
3218
- // 3. Bookkeeping for EVERY roster member. Mark each member initialized so
3219
- // the in-process core-builtin boot passes skip them. The custom-action
3220
- // catalogs are NOT touched here: the respawned runner describes them in
3221
- // its post-init register frame and `applyChildCustomActions` replaces
3222
- // whatever the previous incarnation registered (D444).
3223
- for (const { addonId: memberId } of roster) {
3224
- const memberEntry = this.addonEntries.get(memberId);
3225
- if (memberEntry)
3226
- memberEntry.initialized = true;
3227
- }
3214
+ // 2. Bring the target runner to the correct roster.
3215
+ if (plan.action === 'spawn') {
3216
+ await this.broker
3217
+ .call('$process.spawnRunner', { runnerId, addons: roster })
3218
+ .catch((err) => {
3219
+ // A concurrent path may have won the spawn race — treat "already
3220
+ // running" as success (idempotent), rethrow anything else.
3221
+ if (!/already running/i.test((0, types_1.errMsg)(err)))
3222
+ throw err;
3223
+ });
3224
+ this.recentGroupRespawns.set(runnerId, Date.now());
3225
+ }
3226
+ else if (plan.action === 'restart') {
3227
+ const res = (await this.broker.call('$process.restart', { name: runnerId }));
3228
+ if (!res.success) {
3229
+ throw new Error(`Process restart failed: ${res.reason ?? 'unknown'}`);
3230
+ }
3231
+ this.recentGroupRespawns.set(runnerId, Date.now());
3232
+ }
3233
+ // 3. Bookkeeping for EVERY roster member. Mark each member initialized so
3234
+ // the in-process core-builtin boot passes skip them. The custom-action
3235
+ // catalogs are NOT touched here: the respawned runner describes them in
3236
+ // its post-init register frame and `applyChildCustomActions` replaces
3237
+ // whatever the previous incarnation registered (D444).
3238
+ for (const { addonId: memberId } of roster) {
3239
+ const memberEntry = this.addonEntries.get(memberId);
3240
+ if (memberEntry)
3241
+ memberEntry.initialized = true;
3242
+ }
3243
+ });
3228
3244
  }
3229
3245
  /**
3230
3246
  * Apply the custom-action catalogs a UDS child DESCRIBED in its register
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createRunnerSerializer = createRunnerSerializer;
4
+ function createRunnerSerializer() {
5
+ const tails = new Map();
6
+ return (runnerId, converge) => {
7
+ const previous = tails.get(runnerId) ?? Promise.resolve();
8
+ // `then(fn, fn)` so a rejected predecessor still lets the next one run.
9
+ const result = previous.then(converge, converge);
10
+ tails.set(runnerId, result.then(() => undefined, () => undefined));
11
+ return result;
12
+ };
13
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/server",
3
- "version": "1.2.303",
3
+ "version": "1.2.304",
4
4
  "private": false,
5
5
  "files": [
6
6
  "dist",
@@ -40,11 +40,11 @@
40
40
  "@camstack/addon-auth": "1.2.115",
41
41
  "@camstack/addon-decoder-nodeav": "1.2.108",
42
42
  "@camstack/addon-notifiers": "1.2.112",
43
- "@camstack/addon-pipeline": "1.2.251",
43
+ "@camstack/addon-pipeline": "1.2.252",
44
44
  "@camstack/addon-pipeline-orchestrator": "1.2.214",
45
- "@camstack/addon-post-analysis": "1.2.255",
45
+ "@camstack/addon-post-analysis": "1.2.256",
46
46
  "@camstack/sdk": "1.2.111",
47
- "@camstack/system": "1.2.246",
47
+ "@camstack/system": "1.2.247",
48
48
  "@camstack/types": "1.2.205",
49
49
  "@camstack/ui-library": "1.2.170",
50
50
  "@fastify/compress": "^9.0.0",