velocious 1.0.749 → 1.0.751

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.749",
6
+ "version": "1.0.751",
7
7
  "main": "build/index.js",
8
8
  "types": "build/index.d.ts",
9
9
  "files": [
@@ -648,14 +648,36 @@ export default class BackgroundJobsMain {
648
648
  }
649
649
  this.lifecycleState = "active"
650
650
  this._creditReadyWorkers()
651
- await this._settleForeignGenerationHandoffs()
652
- await this._settleDeadOwnerHandoffs()
653
651
  this.logger.info(() => ["Background jobs generation activation acknowledged", {generationId: this.generationId}])
652
+ // Activation is the handoff boundary. Durable orphan settlement is recovery
653
+ // work and must not keep the lifecycle socket open while it examines rows
654
+ // owned by a retiring generation. A slow ledger query is allowed to finish
655
+ // in the background; it cannot turn a successful candidate into a
656
+ // timed-out release that Rollbridge incorrectly reports as recovered.
657
+ void this._settleActivationHandoffs().catch((error) => {
658
+ const normalizedError = error instanceof Error ? error : new Error(String(error))
659
+ const payload = {context: {generationId: this.generationId, stage: "background-job-activation-handoff-settlement"}, error: normalizedError}
660
+ const errorEvents = this.configuration.getErrorEvents()
661
+
662
+ this.logger.error(() => ["Failed to settle background-job handoffs after activation:", normalizedError])
663
+ errorEvents.emit("framework-error", payload)
664
+ errorEvents.emit("all-error", {...payload, errorType: "framework-error"})
665
+ })
654
666
  void this._drain().catch((error) => {
655
667
  this.logger.error(() => ["Background jobs generation post-activation drain failed", {error, generationId: this.generationId}])
656
668
  })
657
669
  }
658
670
 
671
+ /**
672
+ * Settles activation-time handoffs after the lifecycle acknowledgement.
673
+ * @returns {Promise<void>} - Resolves after recovery work completes.
674
+ */
675
+ async _settleActivationHandoffs() {
676
+ await this._settleForeignGenerationHandoffs()
677
+ const deadOwnerJobs = await this._settleDeadOwnerHandoffs()
678
+ await this._handleOrphanedJobs({jobs: deadOwnerJobs, warning: "Marked orphaned background jobs after generation activation"})
679
+ }
680
+
659
681
  /**
660
682
  * Establishes the synchronous retirement fence and then drains ownership setup.
661
683
  * @returns {Promise<void>} - Resolves after the retirement fence is durable in memory.
@@ -820,6 +820,8 @@ export default class VelociousDatabaseQueryModelClassQuery extends DatabaseQuery
820
820
  * @returns {Promise<void>} - Resolves when complete.
821
821
  */
822
822
  async destroyAll() {
823
+ await this._ensureInitialized()
824
+
823
825
  const records = await this.toArray()
824
826
 
825
827
  for (const record of records) {
@@ -878,6 +880,8 @@ export default class VelociousDatabaseQueryModelClassQuery extends DatabaseQuery
878
880
  * @returns {Promise<number>} - Affected row count.
879
881
  */
880
882
  async deleteAll() {
883
+ await this._ensureInitialized()
884
+
881
885
  const driver = this.driver
882
886
  const tableName = this.getModelClass().tableName()
883
887
  const joinsSql = new JoinsParser({pretty: false, query: this}).toSql()
@@ -910,6 +914,8 @@ export default class VelociousDatabaseQueryModelClassQuery extends DatabaseQuery
910
914
  * @returns {Promise<number>} - Affected row count.
911
915
  */
912
916
  async unlinkAll(relationshipName) {
917
+ await this._ensureInitialized()
918
+
913
919
  const modelClass = this.getModelClass()
914
920
  const relationship = modelClass.getRelationshipByName(relationshipName)
915
921