velocious 1.0.757 → 1.0.758

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.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "velocious": "build/bin/velocious.js"
4
4
  },
5
5
  "name": "velocious",
6
- "version": "1.0.757",
6
+ "version": "1.0.758",
7
7
  "main": "build/index.js",
8
8
  "types": "build/index.d.ts",
9
9
  "files": [
@@ -239,6 +239,12 @@ export default class BackgroundJobsMain {
239
239
  this._startupHandoffReclaimTimer = undefined
240
240
  /** @type {Promise<void> | undefined} */
241
241
  this._startupHandoffReclaimPromise = undefined
242
+ /**
243
+ * Activation handoff settlement started by this generation. Activation is
244
+ * acknowledged before the pass runs, so `_stop()` and any observer that
245
+ * needs the settled rows awaits this instead of racing the ledger queries.
246
+ * @type {Promise<void> | undefined} */
247
+ this._activationSettlementPromise = undefined
242
248
  /**
243
249
  * Narrows the runtime value to the documented type.
244
250
  * @type {BackgroundJobsScheduler | undefined} */
@@ -304,6 +310,7 @@ export default class BackgroundJobsMain {
304
310
  this._startupHandoffAdoptionsAtDeadline = []
305
311
  this._startupHandoffGraceElapsed = false
306
312
  this._startupHandoffReclaimPromise = undefined
313
+ this._activationSettlementPromise = undefined
307
314
  this.configuration.setCurrent()
308
315
 
309
316
  try {
@@ -415,9 +422,13 @@ export default class BackgroundJobsMain {
415
422
  await this._drainStartupHandoffReclaim()
416
423
  } finally {
417
424
  try {
418
- await this._releaseGenerationLivenessLock()
425
+ await this.drainActivationSettlement()
419
426
  } finally {
420
- await this._stopBeaconAndServer()
427
+ try {
428
+ await this._releaseGenerationLivenessLock()
429
+ } finally {
430
+ await this._stopBeaconAndServer()
431
+ }
421
432
  }
422
433
  }
423
434
  }
@@ -667,7 +678,7 @@ export default class BackgroundJobsMain {
667
678
  // owned by a retiring generation. A slow ledger query is allowed to finish
668
679
  // in the background; it cannot turn a successful candidate into a
669
680
  // timed-out release that Rollbridge incorrectly reports as recovered.
670
- void this._settleActivationHandoffs().catch((error) => {
681
+ const settlement = this._settleActivationHandoffs().catch((error) => {
671
682
  const normalizedError = error instanceof Error ? error : new Error(String(error))
672
683
  const payload = {context: {generationId: this.generationId, stage: "background-job-activation-handoff-settlement"}, error: normalizedError}
673
684
  const errorEvents = this.configuration.getErrorEvents()
@@ -676,6 +687,14 @@ export default class BackgroundJobsMain {
676
687
  errorEvents.emit("framework-error", payload)
677
688
  errorEvents.emit("all-error", {...payload, errorType: "framework-error"})
678
689
  })
690
+
691
+ this._activationSettlementPromise = settlement
692
+ const clearSettlement = () => {
693
+ if (this._activationSettlementPromise === settlement) {
694
+ this._activationSettlementPromise = undefined
695
+ }
696
+ }
697
+ void settlement.then(clearSettlement, clearSettlement)
679
698
  void this._drain().catch((error) => {
680
699
  this.logger.error(() => ["Background jobs generation post-activation drain failed", {error, generationId: this.generationId}])
681
700
  })
@@ -691,6 +710,19 @@ export default class BackgroundJobsMain {
691
710
  await this._handleOrphanedJobs({jobs: deadOwnerJobs, warning: "Marked orphaned background jobs after generation activation"})
692
711
  }
693
712
 
713
+ /**
714
+ * Waits for the activation settlement pass this generation started. Activation
715
+ * is acknowledged before the pass runs, so a caller that must observe the
716
+ * reclaimed rows awaits this rather than reading the ledger immediately after
717
+ * `activate()` resolves.
718
+ * @returns {Promise<void>} - Resolves when no activation pass remains.
719
+ */
720
+ async drainActivationSettlement() {
721
+ while (this._activationSettlementPromise) {
722
+ await this._activationSettlementPromise
723
+ }
724
+ }
725
+
694
726
  /**
695
727
  * Establishes the synchronous retirement fence and then drains ownership setup.
696
728
  * @returns {Promise<void>} - Resolves after the retirement fence is durable in memory.