@substrat-run/adapter-cloudflare 0.221.0 → 0.222.0

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.
Files changed (82) hide show
  1. package/dist/broker-telemetry.d.ts +2 -5
  2. package/dist/broker-telemetry.d.ts.map +1 -1
  3. package/dist/broker-telemetry.js +2 -5
  4. package/dist/broker-telemetry.js.map +1 -1
  5. package/dist/control-plane-do.d.ts +244 -67
  6. package/dist/control-plane-do.d.ts.map +1 -1
  7. package/dist/control-plane-do.js +664 -246
  8. package/dist/control-plane-do.js.map +1 -1
  9. package/dist/delivery-broker-do.d.ts +3 -2
  10. package/dist/delivery-broker-do.d.ts.map +1 -1
  11. package/dist/delivery-broker-do.js +10 -4
  12. package/dist/delivery-broker-do.js.map +1 -1
  13. package/dist/delivery-handoff.d.ts +17 -1
  14. package/dist/delivery-handoff.d.ts.map +1 -1
  15. package/dist/delivery-handoff.js +19 -5
  16. package/dist/delivery-handoff.js.map +1 -1
  17. package/dist/directory-cutover.d.ts +243 -0
  18. package/dist/directory-cutover.d.ts.map +1 -0
  19. package/dist/directory-cutover.js +604 -0
  20. package/dist/directory-cutover.js.map +1 -0
  21. package/dist/directory-mirror-apply.d.ts +19 -1
  22. package/dist/directory-mirror-apply.d.ts.map +1 -1
  23. package/dist/directory-mirror-apply.js +19 -3
  24. package/dist/directory-mirror-apply.js.map +1 -1
  25. package/dist/directory-mirror-backfill.d.ts +2 -0
  26. package/dist/directory-mirror-backfill.d.ts.map +1 -1
  27. package/dist/directory-mirror-backfill.js +6 -4
  28. package/dist/directory-mirror-backfill.js.map +1 -1
  29. package/dist/directory-mirror.d.ts +24 -0
  30. package/dist/directory-mirror.d.ts.map +1 -1
  31. package/dist/directory-mirror.js +16 -2
  32. package/dist/directory-mirror.js.map +1 -1
  33. package/dist/directory-objects.d.ts +40 -0
  34. package/dist/directory-objects.d.ts.map +1 -1
  35. package/dist/directory-objects.js +134 -2
  36. package/dist/directory-objects.js.map +1 -1
  37. package/dist/directory-placement.d.ts.map +1 -1
  38. package/dist/directory-placement.js +7 -1
  39. package/dist/directory-placement.js.map +1 -1
  40. package/dist/directory-split-inventory.d.ts +5 -3
  41. package/dist/directory-split-inventory.d.ts.map +1 -1
  42. package/dist/directory-split-inventory.js +12 -6
  43. package/dist/directory-split-inventory.js.map +1 -1
  44. package/dist/directory-tenant-orgs.d.ts +19 -0
  45. package/dist/directory-tenant-orgs.d.ts.map +1 -0
  46. package/dist/directory-tenant-orgs.js +33 -0
  47. package/dist/directory-tenant-orgs.js.map +1 -0
  48. package/dist/directory-tenant-roles.d.ts +35 -0
  49. package/dist/directory-tenant-roles.d.ts.map +1 -0
  50. package/dist/directory-tenant-roles.js +78 -0
  51. package/dist/directory-tenant-roles.js.map +1 -0
  52. package/dist/directory-tenant-tuples.d.ts +165 -0
  53. package/dist/directory-tenant-tuples.d.ts.map +1 -0
  54. package/dist/directory-tenant-tuples.js +197 -0
  55. package/dist/directory-tenant-tuples.js.map +1 -0
  56. package/dist/host.d.ts +26 -1
  57. package/dist/host.d.ts.map +1 -1
  58. package/dist/host.js +262 -45
  59. package/dist/host.js.map +1 -1
  60. package/dist/index.d.ts +1 -0
  61. package/dist/index.d.ts.map +1 -1
  62. package/dist/index.js +1 -0
  63. package/dist/index.js.map +1 -1
  64. package/dist/platform-sweeper-do.d.ts +1 -1
  65. package/dist/platform-sweeper-do.js +1 -1
  66. package/dist/scope-do.d.ts +11 -2
  67. package/dist/scope-do.d.ts.map +1 -1
  68. package/dist/scope-do.js +154 -40
  69. package/dist/scope-do.js.map +1 -1
  70. package/dist/scope-sweeper-do.d.ts +22 -0
  71. package/dist/scope-sweeper-do.d.ts.map +1 -1
  72. package/dist/scope-sweeper-do.js +74 -54
  73. package/dist/scope-sweeper-do.js.map +1 -1
  74. package/dist/scope-wake.d.ts +12 -1
  75. package/dist/scope-wake.d.ts.map +1 -1
  76. package/dist/scope-wake.js +14 -1
  77. package/dist/scope-wake.js.map +1 -1
  78. package/dist/tenant-due-work-do.d.ts +95 -0
  79. package/dist/tenant-due-work-do.d.ts.map +1 -0
  80. package/dist/tenant-due-work-do.js +149 -0
  81. package/dist/tenant-due-work-do.js.map +1 -0
  82. package/package.json +10 -10
package/dist/index.d.ts CHANGED
@@ -26,6 +26,7 @@ export { createDoTupleChecker } from './checker.js';
26
26
  export { definePlatformSweeperDO, PLATFORM_SWEEPER_NAME } from './platform-sweeper-do.js';
27
27
  export { defineKickCoalescerDO, kickCoalescerName, CROSS_VERTICAL_KICK_WINDOW_MS, type KickCoalescerConfig, type KickCoalescerDo, type KickOutcome, type KickProducer, } from './kick-coalescer-do.js';
28
28
  export { defineConnectionSweepDO, connectionSweepName, spreadOf as connectionSweepSpreadOf, CONNECTION_SWEEP_INTERVAL_MS, CONNECTION_SWEEP_OVERDUE_MS, CONNECTION_SWEEP_FIRST_SPREAD_MS, type ConnectionSweepCheck, type ConnectionSweepConfig, type ConnectionSweepDo, type ConnectionSweepRef, type ConnectionSweepRun, } from './connection-sweep-do.js';
29
+ export { defineTenantDueWorkDO, tenantDueWorkName, type TenantDueItem, type TenantDueKind, type TenantDueWorkDo, } from './tenant-due-work-do.js';
29
30
  export type { PlatformSweeperDoConfig, PlatformSweepOutcome } from './platform-sweeper-do.js';
30
31
  export { defineCopyJobDO, type CopyJobDo, type CopyJobDoConfig, type CopyJobDoRecord, type CopyJobStep } from './copy-job-do.js';
31
32
  export { defineScopeSweeperDO, SCOPE_SWEEPER_NAME } from './scope-sweeper-do.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,YAAY,EACV,0BAA0B,EAC1B,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,EACtB,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,EACnB,uBAA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,EACd,oBAAoB,EACpB,cAAc,EACd,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,oBAAoB,EACpB,uBAAuB,EACvB,uBAAuB,GACxB,MAAM,SAAS,CAAC;AACjB,YAAY,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AACrE,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,SAAS,CAAC;AACjB,YAAY,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAG1D,OAAO,EACL,aAAa,EACb,YAAY,EACZ,qBAAqB,EACrB,oBAAoB,EACpB,kBAAkB,EAClB,wBAAwB,EACxB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,GACvB,MAAM,iCAAiC,CAAC;AACzC,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,YAAY,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,uBAAuB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC7E,YAAY,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAEjE,OAAO,EACL,oCAAoC,EACpC,gCAAgC,EAChC,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC"}
package/dist/index.js CHANGED
@@ -27,6 +27,7 @@ export { definePlatformSweeperDO, PLATFORM_SWEEPER_NAME } from './platform-sweep
27
27
  export { defineKickCoalescerDO, kickCoalescerName, CROSS_VERTICAL_KICK_WINDOW_MS, } from './kick-coalescer-do.js';
28
28
  // K-69, step 4.2 (#3376): one object per connection, whose alarm runs that connection's sweep.
29
29
  export { defineConnectionSweepDO, connectionSweepName, spreadOf as connectionSweepSpreadOf, CONNECTION_SWEEP_INTERVAL_MS, CONNECTION_SWEEP_OVERDUE_MS, CONNECTION_SWEEP_FIRST_SPREAD_MS, } from './connection-sweep-do.js';
30
+ export { defineTenantDueWorkDO, tenantDueWorkName, } from './tenant-due-work-do.js';
30
31
  // #2450 step 2: one object per background scope copy, stepped by alarm.
31
32
  export { defineCopyJobDO } from './copy-job-do.js';
32
33
  export { defineScopeSweeperDO, SCOPE_SWEEPER_NAME } from './scope-sweeper-do.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAYhD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,uGAAuG;AACvG,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,uBAAuB,EACvB,YAAY,EACZ,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAiE,MAAM,0BAA0B,CAAC;AACrJ,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAC1F,6FAA6F;AAC7F,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,6BAA6B,GAK9B,MAAM,wBAAwB,CAAC;AAChC,+FAA+F;AAC/F,OAAO,EACL,uBAAuB,EACvB,mBAAmB,EACnB,QAAQ,IAAI,uBAAuB,EACnC,4BAA4B,EAC5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AAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,iGAAiG;AACjG,mGAAmG;AACnG,OAAO,EACL,aAAa,EACb,YAAY,EACZ,qBAAqB,EACrB,oBAAoB,EACpB,kBAAkB,EAClB,wBAAwB,GAKzB,MAAM,iCAAiC,CAAC;AAGzC,OAAO,EAAE,uBAAuB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAE7E,0EAA0E;AAC1E,OAAO,EACL,oCAAoC,EACpC,gCAAgC,EAChC,sBAAsB,GACvB,MAAM,sBAAsB,CAAC"}
@@ -79,7 +79,7 @@ export interface PlatformSweeperDo {
79
79
  * alarm is never left to workerd's own retry (which would tighten the interval
80
80
  * we promised to keep).
81
81
  *
82
- * Wire-up (mirror of the node call site in `demos/meridian/src/server.ts`):
82
+ * Wire-up (mirror of a node deployment's `startPlatformSweeper` call):
83
83
  *
84
84
  * ```ts
85
85
  * export const SweeperDO = definePlatformSweeperDO<Env>({
@@ -42,7 +42,7 @@ export const PLATFORM_SWEEPER_NAME = 'platform-sweeper';
42
42
  * alarm is never left to workerd's own retry (which would tighten the interval
43
43
  * we promised to keep).
44
44
  *
45
- * Wire-up (mirror of the node call site in `demos/meridian/src/server.ts`):
45
+ * Wire-up (mirror of a node deployment's `startPlatformSweeper` call):
46
46
  *
47
47
  * ```ts
48
48
  * export const SweeperDO = definePlatformSweeperDO<Env>({
@@ -80,8 +80,9 @@ export interface ScopeDoEnv {
80
80
  /**
81
81
  * #3540 (K-69's first step): `event` makes the derived purge schedules (`trash: { purgeAfterDays }`)
82
82
  * due by the trashed rows themselves. The scope arms its one alarm for its earliest due row, and the
83
- * alarm asks this deployment's scope sweeper (`SWEEPER`) to run them for this scope alone; the
84
- * sweeper's pass then runs none, and only re-arms the alarm. Unset (the default), or with no
83
+ * alarm runs them for this scope alone, through the vertical's own host once a pass has left them to
84
+ * it, or by asking this deployment's scope sweeper (`SWEEPER`) to; the sweeper's pass then runs
85
+ * none, and only re-arms the alarm, which makes it the safety net. Unset (the default), or with no
85
86
  * `SWEEPER` bound, the pass runs them on their cadence, as before. The uploader binds it from the
86
87
  * control plane's `VERTICAL_PURGE_DUE` (`PURGE_DUE_BINDING`).
87
88
  */
@@ -113,6 +114,14 @@ export interface PurgeAlarmState {
113
114
  * the purges alone, through `runScopePurges`, which every sweeper carrying #3580 answers.
114
115
  */
115
116
  readonly schedules?: true;
117
+ /**
118
+ * A pass said it leaves this scope's due work to the alarm (`runPurgeSweep` or `dueScheduleGate`
119
+ * asked `deferrable`), so the alarm may run that work itself, through the vertical's own host
120
+ * (`SCOPE_DUE_HOST_KEY`), with no sweeper in between. Absent, the alarm asks the sweeper, as before:
121
+ * a pass from a sweeper older than #3580 runs the purges itself, and two runners would be one too many.
122
+ * `schedules` implies it, since only a deferring pass writes that.
123
+ */
124
+ readonly passDefers?: true;
116
125
  }
117
126
  /** #3540: what `dueScheduleGate` answers the host about one `due: 'event'` schedule. */
118
127
  export interface DueScheduleGate {
@@ -1 +1 @@
1
- {"version":3,"file":"scope-do.d.ts","sourceRoot":"","sources":["../src/scope-do.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAyCL,KAAK,OAAO,EAiBZ,KAAK,QAAQ,EAqBd,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAiEL,KAAK,mBAAmB,EASxB,KAAK,SAAS,EA2Bd,KAAK,kBAAkB,EAEvB,KAAK,gBAAgB,EAgJtB,MAAM,sBAAsB,CAAC;AAuD9B,OAAO,EAAW,KAAK,OAAO,EAAE,MAAM,eAAe,CAAC;AAEtD,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAIvE,OAAO,EA6BL,kBAAkB,EAwGnB,MAAM,sBAAsB,CAAC;AA+D9B;;;;;;;;;;;;;GAaG;AAEH,MAAM,WAAW,UAAU;IACzB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,sBAAsB,CAAC;IACv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E,kBAAkB,EAAE,EAC7B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AACzD;;;;GAIG;AACH,OAAO,GAAE;IAAE,WAAW,CAAC,EAAE,mBAAmB,CAAA;CAAO,GAClD,KAAK,GAAG,EAAE,kBAAkB,EAAE,GAAG,EAAE,UAAU,KAAK,aAAa,CAAC,UAAU,CAAC,CAwgU7E"}
package/dist/scope-do.js CHANGED
@@ -1,10 +1,12 @@
1
1
  import { REWIND_REFUSED } from './rewind-refusal.js';
2
2
  import { SYSTEM_DOOR_MOVED } from './system-door.js';
3
3
  import { DurableObject } from 'cloudflare:workers';
4
- import { ATTACHMENT_ADDED, ATTACHMENT_REMOVED, CAPTURE_REFUSALS, attachmentRecord, domainEvent, domainEventInput, eventId, instant, objectRef, entityObjectRef, assertModuleEmittableType, assertKernelAuthoredType, toWireFailure, grantRefFromProof, principalId, principalBecomeCapabilityInput, principalBindLinkInput, scopeId as scopeIdOf, tenantId as tenantIdOf, platformRequestInput, platformRequestId, MAX_PENDING_PLATFORM_REQUESTS, MAX_PENDING_SWEEP_RUNS, SWEEP_RUNS_KIND, SCOPE_DUMP_PAGE_MAX_BYTES, SCOPE_TABLE_PAGE_MAX, SCOPE_QUERY_ROW_MAX, listLimitOf, pageOf, countedPageOf, requestFingerprint, substratError, errorCodeOf, assertReplayableDump, DUMP_OBJECTS_QUERY, dumpObjectsOf, isRuntimeTable, replayDumpObjects, dumpObjectsAudit, REDRAIN_BATCH, storeOperationKeyOf, } from '@substrat-run/contracts';
4
+ import { PRODUCTION_ENVIRONMENT, ATTACHMENT_ADDED, ATTACHMENT_REMOVED, CAPTURE_REFUSALS, attachmentRecord, domainEvent, domainEventInput, eventId, instant, objectRef, entityObjectRef, assertModuleEmittableType, assertKernelAuthoredType, toWireFailure, grantRefFromProof, principalId, principalBecomeCapabilityInput, principalBindLinkInput, scopeId as scopeIdOf, tenantId as tenantIdOf, platformRequestInput, platformRequestId, MAX_PENDING_PLATFORM_REQUESTS, MAX_PENDING_SWEEP_RUNS, SWEEP_RUNS_KIND, SCOPE_DUMP_PAGE_MAX_BYTES, SCOPE_TABLE_PAGE_MAX, SCOPE_QUERY_ROW_MAX, listLimitOf, pageOf, countedPageOf, requestFingerprint, substratError, errorCodeOf, assertReplayableDump, DUMP_OBJECTS_QUERY, dumpObjectsOf, isRuntimeTable, replayDumpObjects, dumpObjectsAudit, REDRAIN_BATCH, storeOperationKeyOf, SCOPE_DUE_HOST_KEY, } from '@substrat-run/contracts';
5
5
  import { ulid, DO_SQL_LIMITS, unknownRoleError, createUlid, assertAllowed, ConnectionSealingKeyUnavailableError, noSealingKeyMessage, sealTo, assertReadOnlyQuery, refuseEntitlement, platformRequestHistoryQuery, platformRequestOf, PLATFORM_REQUEST_COLUMNS, PLATFORM_REQUEST_REDACTION_SQL, platformRequestRedactionParams, platformRequestRedactionQuery, intentPayloadCarriesSubject, redactSubjectJobRuns, eraseSubjectFromModules, readSubjectPage, moduleErasurePlan, redactSubjectScopeText, assertRowLimit, assertRowOffset, JOB_RUN_PATCH_SQL, JOB_RUN_CLAIM_SQL, JOB_RUN_RENEW_SQL, JOB_RUN_BEGIN_SQL, JOB_RUN_MISS_SQL, JOB_RUN_MISS_SETTLE_SQL, admissionMissOutcome, JOB_LEASE_EXPIRED_NOTE, JOB_STEP_RECORD_SQL, DELIVERY_ERROR_REDACTION_SQL, REDACTED_DELIVERY_NOTE, seatScopeTuple, delegatedRevokeSql, writeExplicitTupleIn, grantEntityShapeIn, grantEntityShapeOnceIn, topUpEntityGrantShapes, applyScopeRoleChange, changeScopeRole, revokeScopeRoles, scopeRoleHolders, assertModuleDeclared, noteDeclaredKeys, noteReservedKeys, SCOPE_SEATED_ROLES_SQL, inUnitRoleRefusal, loadedRoleSetRefusedRole, reservedRoleSetRefusedRole, reservedGrantRefusal, reservedRoleRefusal, reservedShapeRefusal, effectiveRoleGrantQuery, switchRecordedOff, switchSystemSchedules, peerGrantsStatus, systemGrantsStatus, systemScheduleState, systemSwitchedOff, OUTBOX_PRUNED_DDL, outboxSubscribersOf, pruneDrainedOutbox, denialListQuery, refusalListQuery, mapRefusalRow, denialSummaryQuery, denialTotalsQuery, DENIAL_WINDOW_QUERY, mapDenialRow, mapDenialSummaryBuckets, PermissionDenied, assertImpersonationAdmitted, assertImpersonationWrites, assertModuleEnqueueableKind, impersonationStampOf, createAtomic, NotSearchable, isSearchIndexTable, countDumpRows, planDumpSample, sampleFilters, sampleGraph, rowCountTable, searchIndexPlans, NotListable, listIndexPlans, moduleMigrations, REGISTERED_MIGRATIONS, registeredMigrationsOf, MIGRATION_DIGEST_FENCE_DDL, MIGRATION_DIGEST_MARK_LEGACY, assertJournalDumpCoherent, assertMigrationSql, migrationDivergence, migrationFailedError, migrationSetDivergence, migrationSteps, planMigrations,
6
6
  // #2993 part 3: the scope's type, recorded here and read at wake, decides which modules it runs.
7
- HOME_SCOPE_TYPE, SCOPE_TYPE_META_KEY, operationNotInScopeType, provisionedScopeType, scopeTypePlanOf, scopeTypeRoleRefusal, scopeTypeRuns, listQuery, cursorOf, searchLimit, searchMatchExpression, searchQuery, ATTACHMENT_TEXT_DDL, ATTACHMENT_BYTES_SQL, ATTACHMENT_CONDEMNED_DDL, ATTACHMENT_SWEEP_LICENCE_DDL, ATTACHMENT_SWEEP_LICENCE_TABLE, WIRE_NONCE_DDL, WIRE_NONCE_FULL, claimWireNonceIn, isWireNonceTable, isWireNonceWrite, clearOrphanSweepLicence, condemnLicensedOrphanAttachments, consumeOrphanSweepLicence, licensedOrphanIds, recordOrphanSweepLicence, refuseUnlicensedOrphanSweep, refuseCondemnedAttachment, refuseCondemnedInDump, rowlessAttachmentIds, attachmentRecordOfRow, enqueueAttachmentText, reconcileAttachmentText, queueAttachmentTextBackfill, startAttachmentTextBackfill, readAttachmentTextRecheckPage, requeueUnsupportedAttachmentText, startAttachmentTextRecheck, recordAttachmentText, searchAttachments, IDEMPOTENCY_DDL, REFUSALS_TABLE_DDL, REFUSALS_INDEX, refusalInsert, refusalOf, markGuardRefusal, REFUSALS_REBUILD, refusalsAdmitGuards, assertIdempotencyKey, assertPermissionKey, idempotencyLookupQuery, idempotencyPruneStatement, idempotencyRecordStatement, idempotencyOptedOutMessage, replayFor, entityVersionQuery, entityVersionOf, assertIfMatch, OUTBOX_ENTITY_INDEX, SCHEDULE_STATE_DDL, SCHEDULE_STATE_REBUILD, scheduleStateHasKind, VERTICAL_EVENTS_DDL, EXPORT_HOPS_SQL, emptyImportResult, IMPORT_CURSORS_SQL, IMPORT_CURSOR_OF_SQL, OUTBOX_MARK_SQL, exportedSinceQuery, emittedSinceQuery, emittedReportOf, EMITTED_REPORT_CAP, noteTransitionInto, withTransitions, IMPORT_CURSOR_ADVANCE_SQL, IMPORT_RECORD_SQL, moveImportCursor, CrossVerticalRegistry, exportReadPlan, exportReadQuery, planExportBatch, withheldNote, JOB_RUN_DDL, JOB_RUN_DUE_AT, jobRunListLimit, SYSTEM_DOOR_WAIT, ancestorsWithin, } from '@substrat-run/kernel';
7
+ HOME_SCOPE_TYPE, SCOPE_TYPE_META_KEY,
8
+ // #2995: and its parent, recorded here beside it, which the doors of a CP-less host read.
9
+ PARENT_SCOPE_META_KEY, provisionedParent, operationNotInScopeType, provisionedScopeType, scopeTypePlanOf, scopeTypeRoleRefusal, scopeTypeRuns, listQuery, cursorOf, searchLimit, searchMatchExpression, searchQuery, ATTACHMENT_TEXT_DDL, ATTACHMENT_BYTES_SQL, ATTACHMENT_CONDEMNED_DDL, ATTACHMENT_SWEEP_LICENCE_DDL, ATTACHMENT_SWEEP_LICENCE_TABLE, WIRE_NONCE_DDL, WIRE_NONCE_FULL, claimWireNonceIn, isWireNonceTable, isWireNonceWrite, clearOrphanSweepLicence, condemnLicensedOrphanAttachments, consumeOrphanSweepLicence, licensedOrphanIds, recordOrphanSweepLicence, refuseUnlicensedOrphanSweep, refuseCondemnedAttachment, refuseCondemnedInDump, rowlessAttachmentIds, attachmentRecordOfRow, enqueueAttachmentText, reconcileAttachmentText, queueAttachmentTextBackfill, startAttachmentTextBackfill, readAttachmentTextRecheckPage, requeueUnsupportedAttachmentText, startAttachmentTextRecheck, recordAttachmentText, searchAttachments, IDEMPOTENCY_DDL, REFUSALS_TABLE_DDL, REFUSALS_INDEX, refusalInsert, refusalOf, markGuardRefusal, REFUSALS_REBUILD, refusalsAdmitGuards, assertIdempotencyKey, assertPermissionKey, idempotencyLookupQuery, idempotencyPruneStatement, idempotencyRecordStatement, idempotencyOptedOutMessage, replayFor, entityVersionQuery, entityVersionOf, assertIfMatch, OUTBOX_ENTITY_INDEX, SCHEDULE_STATE_DDL, SCHEDULE_STATE_REBUILD, scheduleStateHasKind, VERTICAL_EVENTS_DDL, EXPORT_HOPS_SQL, emptyImportResult, IMPORT_CURSORS_SQL, IMPORT_CURSOR_OF_SQL, OUTBOX_MARK_SQL, exportedSinceQuery, emittedSinceQuery, emittedReportOf, EMITTED_REPORT_CAP, noteTransitionInto, withTransitions, IMPORT_CURSOR_ADVANCE_SQL, IMPORT_RECORD_SQL, moveImportCursor, CrossVerticalRegistry, exportReadPlan, exportReadQuery, planExportBatch, withheldNote, JOB_RUN_DDL, JOB_RUN_DUE_AT, jobRunListLimit, SYSTEM_DOOR_WAIT, ancestorsWithin, } from '@substrat-run/kernel';
8
10
  import { isUpgradeRequest, readSubscription, LIVE_DECIDE_ATTEMPTS, LIVE_FANOUT_LIMIT, LIVE_PRINCIPAL_HEADER, LIVE_SCOPE_HEADER, LIVE_SUBSCRIBE_PATH, LIVE_TENANT_HEADER, LIVE_WITHIN_HEADER, LIVE_EXPIRES_HEADER, LIVE_CLOSE, LIVE_SOCKETS_PER_PRINCIPAL, decodeLiveWithin, liveInstant, liveRefusal, liveRefusalStatus, } from './live-reads.js';
9
11
  import { replyOf } from './do-reply.js';
10
12
  import { OperationQueue } from './serialization.js';
@@ -24,7 +26,7 @@ import { DELIVERY_HANDOFF_KEY, DELIVERY_MODE_KEY, HANDOFF_ROUNDS, deliveryModeAf
24
26
  import { registerPlatformDeliveryBroker } from './delivery-broker-platform.js';
25
27
  import { advanceMarks, brokerName, handoffQueries, messagesOf, senderDeliveryOf } from '@substrat-run/kernel';
26
28
  import { DELIVERY_HANDOFF_ENV, intentStateOf, intentStateQuery, witnessesOf, witnessQueries, } from '@substrat-run/kernel';
27
- import { SCOPE_SWEEPER_NAME } from './scope-sweeper-do.js';
29
+ import { SCOPE_SWEEPER_NAME, kickPlatformDrain, runScopeDueWork } from './scope-sweeper-do.js';
28
30
  import { SCOPE_WAKE_KEY, keepRegisteredMeanwhile, kickControlPlane, runWake, wakeAfterCommit, wakeDueAt } from './scope-wake.js';
29
31
  import { CARRIED_AWAY_KEY, COPY_MARK_CLEARED_KEY, KEPT_COPY_REFUSAL, KEPT_DIVERGENT_KEY, LOAD_STAMP_KEY, STORE_LOCAL_META_KEYS, WRITE_REVISION_KEY, carriedAwayDump, isCopyMarkInsert, isWriteStatement, assertSpineTablesBuilt, clearCopyMarker, dumpRowsInsert, isSpineTable, markCopyOrigin, repointScopeGrants, settleCopiedWork, emittedHere, IS_COPY_SQL, CLEAN_ROOM_COPY_SQL, isCopyLoad, isLifecycleWrite, readLifecycle, settleLifecycleAfterLoad, writeLifecycle, spineColumnAdditions } from '@substrat-run/kernel';
30
32
  import { GRANT_CHILDREN_INDEX_DDL, SHAPE_MARKER_INDEX_DDL, grantedEntitiesForContext } from '@substrat-run/kernel';
@@ -1040,6 +1042,8 @@ options = {}) {
1040
1042
  * fix and a load are the only writers, and both set it here). Undefined until first read.
1041
1043
  */
1042
1044
  scopeTypeHeld;
1045
+ /** #2995: this scope's parent as its store holds it (`null`: none), read once; a load clears it. */
1046
+ scopeParentHeld;
1043
1047
  /**
1044
1048
  * #2430: what a registered module, or a module the class's declared `permissions` lists, declares
1045
1049
  * `holder: 'system'` — the role and grant doors' refusals read it.
@@ -1763,7 +1767,12 @@ options = {}) {
1763
1767
  * `servesTenant`.
1764
1768
  */
1765
1769
  admission(tenantId) {
1766
- return { verdict: this.tenantVerdict(tenantId).verdict, lifecycle: readLifecycle(this.switchSql()) };
1770
+ return {
1771
+ verdict: this.tenantVerdict(tenantId).verdict,
1772
+ lifecycle: readLifecycle(this.switchSql()),
1773
+ type: this.scopeType(),
1774
+ parent: this.scopeParent(),
1775
+ };
1767
1776
  }
1768
1777
  /**
1769
1778
  * #1738 / #2016: this scope's tenant against `tenantId` — the one reading behind the served-here
@@ -3116,21 +3125,27 @@ options = {}) {
3116
3125
  * `takesSchedules` is a pass saying its sweeper can take `runScopeDue` (`ScheduleTick.alarmRunsDue`);
3117
3126
  * it is remembered, and only from then on does the alarm cover the `due: 'event'` schedules, so a
3118
3127
  * scope whose sweeper predates that call never arms for work it would not run.
3128
+ *
3129
+ * `fromPass` is a pass leaving the work to the alarm (`deferrable`), remembered as `passDefers`:
3130
+ * from then on the alarm may run it itself rather than ask the sweeper.
3119
3131
  */
3120
- async armPurgeAlarm(tenantId, scopeId, takesSchedules = false) {
3132
+ async armPurgeAlarm(tenantId, scopeId, takesSchedules = false, fromPass = false) {
3121
3133
  if (!this.dueAlarmApplies() || this.isCopyRead())
3122
3134
  return false;
3123
3135
  const held = (await this.ctx.storage.get(PURGE_ALARM_KEY)) ?? null;
3124
3136
  const schedules = takesSchedules || held?.schedules === true;
3137
+ const samePair = held?.tenantId === tenantId && held.scopeId === scopeId;
3138
+ const defers = fromPass || (samePair && held?.passDefers === true);
3125
3139
  const at = this.dueAtNow(Date.now(), schedules);
3126
3140
  if (at === null && !(takesSchedules && !held?.schedules))
3127
3141
  return false;
3128
- if (!held || held.tenantId !== tenantId || held.scopeId !== scopeId || (schedules && !held.schedules)) {
3142
+ if (!held || !samePair || (schedules && !held.schedules) || (defers && !held.passDefers)) {
3129
3143
  await this.ctx.storage.put(PURGE_ALARM_KEY, {
3130
3144
  tenantId,
3131
3145
  scopeId,
3132
- ...(held?.notBefore !== undefined && held.tenantId === tenantId && held.scopeId === scopeId ? { notBefore: held.notBefore } : {}),
3146
+ ...(held?.notBefore !== undefined && samePair ? { notBefore: held.notBefore } : {}),
3133
3147
  ...(schedules ? { schedules: true } : {}),
3148
+ ...(defers ? { passDefers: true } : {}),
3134
3149
  });
3135
3150
  }
3136
3151
  if (at === null)
@@ -3154,18 +3169,41 @@ options = {}) {
3154
3169
  }
3155
3170
  }
3156
3171
  /**
3157
- * #3540: the due alarm's half of `alarm()`. When something is due by event, the scope asks its
3158
- * sweeper to run it for this scope alone — `runScopeDue` (its purges and its `due: 'event'`
3159
- * schedules) once a pass has said the sweeper takes that call, `runScopePurges` until then — which
3160
- * runs it through the coordinator's door, with every gate a pass applies. Then it re-arms from
3161
- * what its rows say now:
3172
+ * #3540: the vertical's own scope host, to run this scope's due work with: the one its
3173
+ * `mountPlatformSurface` builds its routes with and registers under `SCOPE_DUE_HOST_KEY`, built
3174
+ * from this object's env, which is the script's. Its door holds the tenant pair, the lifecycle,
3175
+ * the kill switch and the rewind hold, and its calls into this scope are calls like any other.
3176
+ * Null when the bundle registers none (a vertical-host older than the key, a self-host wiring its
3177
+ * own) or building it throws: the alarm then asks the sweeper, so the work is never stranded.
3178
+ */
3179
+ dueRunHost() {
3180
+ const hostFor = globalThis[Symbol.for(SCOPE_DUE_HOST_KEY)];
3181
+ if (typeof hostFor !== 'function')
3182
+ return null;
3183
+ try {
3184
+ return hostFor(this.env);
3185
+ }
3186
+ catch (err) {
3187
+ console.error('substrat: the due alarm could not build its host; asking the sweeper instead', err);
3188
+ return null;
3189
+ }
3190
+ }
3191
+ /**
3192
+ * #3540: the due alarm's half of `alarm()`. When something is due by event, the scope runs it for
3193
+ * itself alone — its purges, and its `due: 'event'` schedules once a pass has said its sweeper
3194
+ * takes `runScopeDue` — through the host's door, with every gate a pass applies
3195
+ * (`runScopeDueWork`). Once a pass has said it leaves that work to the alarm (`passDefers`), the
3196
+ * scope runs it with the vertical's own host (`dueRunHost`), and no sweeper is asked; until then,
3197
+ * or when the bundle gives it no host, it asks its sweeper to (`runScopeDue`, or `runScopePurges`
3198
+ * before that call), which runs the same work after its roster check. Then it re-arms from what
3199
+ * its rows say now:
3162
3200
  *
3163
3201
  * - nothing left due (a restore cancelled it, or the run did it): nothing armed;
3164
3202
  * - a purge lap left open by a run that answered: due again at once, since that run made progress;
3165
3203
  * - otherwise never sooner than `PURGE_ALARM_MIN_GAP_MS`, or the shortest cadence when the
3166
3204
  * sweeper could not be asked, so a run that cannot progress cannot spin the alarm;
3167
- * - a run the sweeper held (a lifecycle, a switch, a scope off its roster): not re-armed, and no
3168
- * commit re-arms it within the cadence. The pass re-arms it when the scope's schedules run.
3205
+ * - a run that was held (a lifecycle, a switch, a scope off the sweeper's roster): not re-armed, and
3206
+ * no commit re-arms it within the cadence. The pass re-arms it when the scope's schedules run.
3169
3207
  *
3170
3208
  * Never throws: a thrown alarm is retried by the runtime.
3171
3209
  */
@@ -3186,6 +3224,7 @@ options = {}) {
3186
3224
  scopeId: state.scopeId,
3187
3225
  ...(notBefore !== undefined ? { notBefore } : {}),
3188
3226
  ...(schedules ? { schedules: true } : {}),
3227
+ ...(state.passDefers ? { passDefers: true } : {}),
3189
3228
  });
3190
3229
  // Nothing due: only a record that says the sweeper takes `runScopeDue` is worth keeping.
3191
3230
  const settle = async () => {
@@ -3209,10 +3248,22 @@ options = {}) {
3209
3248
  let answer;
3210
3249
  this.#purgeAlarmRunning = true;
3211
3250
  try {
3212
- const stub = sweeper.get(sweeper.idFromName(SCOPE_SWEEPER_NAME));
3213
- answer = schedules
3214
- ? await stub.runScopeDue(state.tenantId, state.scopeId)
3215
- : await stub.runScopePurges(state.tenantId, state.scopeId);
3251
+ // Its own run once a pass has said it leaves the work here, so nothing else runs it; the
3252
+ // sweeper's call otherwise, and whenever this bundle gives the scope no host to run it with.
3253
+ const host = state.passDefers === true || schedules ? this.dueRunHost() : null;
3254
+ if (host) {
3255
+ const { tenantId, scopeId } = state;
3256
+ answer = await runScopeDueWork(host, tenantId, scopeId, schedules, {
3257
+ versionId: this.env.SUBSTRAT_VERSION_ID ?? null,
3258
+ kickPlatformDrain: () => this.ctx.waitUntil(kickPlatformDrain(this.env, tenantId, scopeId).catch(() => { })),
3259
+ });
3260
+ }
3261
+ else {
3262
+ const stub = sweeper.get(sweeper.idFromName(SCOPE_SWEEPER_NAME));
3263
+ answer = schedules
3264
+ ? await stub.runScopeDue(state.tenantId, state.scopeId)
3265
+ : await stub.runScopePurges(state.tenantId, state.scopeId);
3266
+ }
3216
3267
  }
3217
3268
  catch (err) {
3218
3269
  answer = { error: err instanceof Error ? err.message : String(err) };
@@ -3311,14 +3362,17 @@ options = {}) {
3311
3362
  return;
3312
3363
  }
3313
3364
  let answered;
3365
+ let answeredEnvironment;
3314
3366
  const ran = await runWake(state, Date.now(), () => this.wakeWork(), async (body) => {
3315
3367
  const answer = await kickControlPlane(transport, body);
3316
3368
  answered = answer?.broker;
3369
+ answeredEnvironment = answer?.brokerEnvironment;
3317
3370
  return answer;
3318
3371
  });
3319
- // A5: the delivery mode the control plane holds for this tenant, on the same answer.
3372
+ // A5: the delivery mode the control plane holds for this tenant, on the same answer, and
3373
+ // (#3639) the named environment whose broker it hands off to.
3320
3374
  if (answered)
3321
- await this.applyDeliveryMode(state.tenantId, state.scopeId, answered);
3375
+ await this.applyDeliveryMode(state.tenantId, state.scopeId, answered, answeredEnvironment);
3322
3376
  // The object took other calls while the kick was out: keep what a commit stored meanwhile.
3323
3377
  const next = keepRegisteredMeanwhile(state, ran, (await this.ctx.storage.get(SCOPE_WAKE_KEY)) ?? null);
3324
3378
  if (!next) {
@@ -3334,13 +3388,28 @@ options = {}) {
3334
3388
  console.error('substrat: scope wake failed; the pass is the backstop', err);
3335
3389
  }
3336
3390
  }
3337
- /** K-74: this scope's broker, or null when the script binds none (the broker is off). */
3338
- deliveryBroker(tenantId) {
3391
+ /**
3392
+ * K-74: this scope's broker, or null when the script binds none (the broker is off). #3639
3393
+ * (D-83): its environment's, named by `environment`; production's (`<tenant>/<app>`, as before)
3394
+ * when it names none.
3395
+ */
3396
+ deliveryBroker(tenantId, environment) {
3339
3397
  const ns = this.env.SUBSTRAT_DELIVERY_BROKER;
3340
3398
  if (!ns)
3341
3399
  return null;
3342
3400
  const app = this.env.SUBSTRAT_VERTICAL ?? 'vertical';
3343
- return ns.get(ns.idFromName(brokerName(tenantId, app)));
3401
+ return ns.get(ns.idFromName(brokerName(tenantId, app, environment)));
3402
+ }
3403
+ /**
3404
+ * #3639: the named environment whose broker this scope hands off to, or undefined for
3405
+ * production's: what the control plane last told it (`DELIVERY_MODE_KEY`), else what its last
3406
+ * handoff stored, which outlives the mode going off.
3407
+ */
3408
+ async handoffEnvironment() {
3409
+ const mode = (await this.ctx.storage.get(DELIVERY_MODE_KEY)) ?? null;
3410
+ if (mode)
3411
+ return mode.environment;
3412
+ return ((await this.ctx.storage.get(DELIVERY_HANDOFF_KEY)) ?? null)?.environment;
3344
3413
  }
3345
3414
  /**
3346
3415
  * K-74: hand off what the scope's commits left, past its marks, and keep the marks the broker
@@ -3356,14 +3425,17 @@ options = {}) {
3356
3425
  async handOffCommitted(tenantId, scopeId,
3357
3426
  /** #3474: the invocation whose commit this follows, and its trace: its own rows carry the trace. */
3358
3427
  commit) {
3359
- const broker = this.deliveryBroker(tenantId);
3360
- if (!broker)
3428
+ if (!this.env.SUBSTRAT_DELIVERY_BROKER)
3361
3429
  return;
3362
3430
  // A5 (#3471): only while the tenant is in shadow or live, and under that mode.
3363
3431
  const options = await this.handoffOptions(tenantId, scopeId);
3364
3432
  if (options === null)
3365
3433
  return;
3434
+ // #3639: to the broker of the scope's environment, which every state this writes keeps.
3435
+ const environment = await this.handoffEnvironment();
3436
+ const broker = this.deliveryBroker(tenantId, environment);
3366
3437
  const ids = { tenantId, scopeId };
3438
+ const kept = { tenantId, scopeId, ...(environment ? { environment } : {}) };
3367
3439
  const stored = (await this.ctx.storage.get(DELIVERY_HANDOFF_KEY)) ?? null;
3368
3440
  let marks = stored?.marks;
3369
3441
  /** #3474: the round now with the broker, so a throw reports what it tried. */
@@ -3388,7 +3460,7 @@ options = {}) {
3388
3460
  break;
3389
3461
  }
3390
3462
  if (!retry) {
3391
- retry = handoffPending(stored, marks, Date.now(), ids);
3463
+ retry = handoffPending(stored, marks, Date.now(), kept);
3392
3464
  await this.keepHandoff(retry);
3393
3465
  await this.armAlarmBy(retry.due);
3394
3466
  }
@@ -3399,7 +3471,7 @@ options = {}) {
3399
3471
  delete options.start;
3400
3472
  }
3401
3473
  const next = advanceMarks(marks, sent, answer);
3402
- this.reportHandoffRound(tenantId, scopeId, inFlight, handoffOutcome(sent, answer));
3474
+ this.reportHandoffRound(tenantId, scopeId, inFlight, handoffOutcome(sent, answer), environment);
3403
3475
  inFlight = null;
3404
3476
  // An answer that acknowledges nothing new: stop, and leave the retry armed.
3405
3477
  if (sameMarks(next, marks))
@@ -3408,19 +3480,19 @@ options = {}) {
3408
3480
  await this.keepHandoff({ ...retry, marks });
3409
3481
  }
3410
3482
  if (drained) {
3411
- await this.keepHandoff({ tenantId, scopeId, marks });
3483
+ await this.keepHandoff({ ...kept, marks });
3412
3484
  return;
3413
3485
  }
3414
3486
  // The round limit, with work left: continue on the first step of the back-off.
3415
- const more = handoffPending(null, marks, Date.now(), ids);
3487
+ const more = handoffPending(null, marks, Date.now(), kept);
3416
3488
  await this.keepHandoff(more);
3417
3489
  await this.armAlarmBy(more.due);
3418
3490
  }
3419
3491
  catch (err) {
3420
3492
  if (inFlight)
3421
- this.reportHandoffRound(tenantId, scopeId, inFlight, 'failed');
3493
+ this.reportHandoffRound(tenantId, scopeId, inFlight, 'failed', environment);
3422
3494
  console.error('substrat: delivery handoff failed; the scope alarm retries it', err);
3423
- const next = handoffAfterFailure(stored, marks, Date.now(), ids);
3495
+ const next = handoffAfterFailure(stored, marks, Date.now(), kept);
3424
3496
  await this.keepHandoff(next);
3425
3497
  await this.armAlarmBy(next.due);
3426
3498
  }
@@ -3463,10 +3535,12 @@ options = {}) {
3463
3535
  * Public for the platform and the suites; a caller in the script can only change which receivers
3464
3536
  * its own next messages are owed, never what the control plane lets the broker drive.
3465
3537
  */
3466
- async applyDeliveryMode(tenantId, scopeId, mode) {
3538
+ async applyDeliveryMode(tenantId, scopeId, mode, environment) {
3467
3539
  await this.ensureMigrations();
3540
+ // #3639: production is named by no environment, whichever way an answer spells it.
3541
+ const named = environment && environment !== PRODUCTION_ENVIRONMENT ? environment : undefined;
3468
3542
  const prior = (await this.ctx.storage.get(DELIVERY_MODE_KEY)) ?? null;
3469
- const { next, seeded } = deliveryModeAfter(prior, mode, () => this.handoffSeed());
3543
+ const { next, seeded } = deliveryModeAfter(prior, mode, () => this.handoffSeed(), named);
3470
3544
  if (next === prior)
3471
3545
  return;
3472
3546
  if (!next) {
@@ -3474,7 +3548,7 @@ options = {}) {
3474
3548
  return;
3475
3549
  }
3476
3550
  if (seeded)
3477
- await this.keepHandoff({ tenantId, scopeId, marks: seeded });
3551
+ await this.keepHandoff({ tenantId, scopeId, ...(named ? { environment: named } : {}), marks: seeded });
3478
3552
  await this.ctx.storage.put(DELIVERY_MODE_KEY, next);
3479
3553
  // The window's start reaches the broker with the next handoff; one now, so a quiet scope has one too.
3480
3554
  if (seeded)
@@ -3495,14 +3569,16 @@ options = {}) {
3495
3569
  return intentStateOf(this.sql.exec(q.sql, ...q.params).toArray());
3496
3570
  }
3497
3571
  /** #3474: one point per handoff round, when the script binds `SUBSTRAT_BROKER_TELEMETRY`. */
3498
- reportHandoffRound(tenantId, scopeId, round, outcome) {
3572
+ reportHandoffRound(tenantId, scopeId, round, outcome,
3573
+ /** #3639: the named environment whose broker the round went to; undefined for production's. */
3574
+ environment) {
3499
3575
  if (this.brokerSink === undefined) {
3500
3576
  const dataset = brokerTelemetryDataset(this.env);
3501
3577
  this.brokerSink = dataset ? analyticsBrokerSink(dataset) : null;
3502
3578
  }
3503
3579
  if (!this.brokerSink)
3504
3580
  return;
3505
- reportHandoff(this.brokerSink, { tenantId, app: this.env.SUBSTRAT_VERTICAL ?? 'vertical', scopeId }, { ...round, outcome, at: Date.now(), traceId: traceIdOf(currentTraceparent()) });
3581
+ reportHandoff(this.brokerSink, { tenantId, app: this.env.SUBSTRAT_VERTICAL ?? 'vertical', ...(environment ? { environment } : {}), scopeId }, { ...round, outcome, at: Date.now(), traceId: traceIdOf(currentTraceparent()) });
3506
3582
  }
3507
3583
  brokerSink;
3508
3584
  /**
@@ -5410,7 +5486,7 @@ options = {}) {
5410
5486
  // here, so a purge is never run by both. It arms the alarm instead, which is also how a bin
5411
5487
  // filled before the switch was turned on, or an alarm that was lost, comes to be armed.
5412
5488
  if (mode === 'deferrable' && this.purgeDueByEvent()) {
5413
- await this.armPurgeAlarm(tenantId, scopeId);
5489
+ await this.armPurgeAlarm(tenantId, scopeId, false, true);
5414
5490
  return { purged: 0, skipped: 0, errors: [], more: false, lapFailed: 0, byAlarm: true };
5415
5491
  }
5416
5492
  const due = purgeDueOf(doSpineSql(this.sql), this.statePlans, this.operationTarget, operation, schedule.entityType, new Date().toISOString(), PURGE_BATCH);
@@ -5464,7 +5540,7 @@ options = {}) {
5464
5540
  const row = readScheduleDue(doSpineSql(this.sql), due);
5465
5541
  if (mode === 'deferrable' && this.dueByEventSwitched() && !this.isCopyRead()) {
5466
5542
  // The pair is the host's, which has already held it to this scope's record.
5467
- await this.armPurgeAlarm(tenantId, scopeId, true);
5543
+ await this.armPurgeAlarm(tenantId, scopeId, true, true);
5468
5544
  if (row.established)
5469
5545
  return { ...row, byAlarm: true };
5470
5546
  }
@@ -5937,6 +6013,34 @@ options = {}) {
5937
6013
  return type;
5938
6014
  }));
5939
6015
  }
6016
+ /** #2995: this scope's parent, `null` when it has none. Read once; never written but by `fixScopeParentReply`. */
6017
+ scopeParent() {
6018
+ if (this.scopeParentHeld === undefined)
6019
+ this.scopeParentHeld = this.metaValue(PARENT_SCOPE_META_KEY);
6020
+ return this.scopeParentHeld;
6021
+ }
6022
+ /**
6023
+ * #2995 (K-64): fix this scope's parent, at its provision as a child — the hosted half of the pure
6024
+ * host's `scopes.parent_scope_id`, kept in the scope's own `_substrat_meta` beside its type, so a
6025
+ * CP-less host's doors can judge a child with no directory to ask. Fixed once, by the kernel's
6026
+ * `provisionedParent`: a provision restating the link, or naming none, keeps it; one naming another
6027
+ * parent, or a parent for a store already provisioned without one, is `conflict` and writes nothing.
6028
+ * Called after `fixScopeTypeReply` and before anything migrates. Answers the parent held.
6029
+ */
6030
+ async fixScopeParentReply(requested, scopeId) {
6031
+ return replyOf(() => this.queue.enqueue(() => {
6032
+ const held = this.metaValue(PARENT_SCOPE_META_KEY);
6033
+ const recorded = held !== null ? held : this.provisionedFor() !== null || this.holdsData() ? null : undefined;
6034
+ const parent = provisionedParent(requested, recorded, scopeId);
6035
+ if (held === null && parent !== null) {
6036
+ this.revision.transactionSync(() => {
6037
+ this.sql.exec(`INSERT INTO _substrat_meta (key, value) VALUES (?, ?)`, PARENT_SCOPE_META_KEY, parent);
6038
+ });
6039
+ }
6040
+ this.scopeParentHeld = parent;
6041
+ return parent;
6042
+ }));
6043
+ }
5940
6044
  /** #2993 part 3: this scope's type, for a host that seats or probes by it. Reads; writes nothing. */
5941
6045
  async scopeTypeHere() {
5942
6046
  return this.scopeType();
@@ -7389,6 +7493,8 @@ options = {}) {
7389
7493
  const receiptBefore = this.provisionedFor();
7390
7494
  // #2993 part 3: the type this store's own provision fixed, which a load never changes.
7391
7495
  const typeBefore = this.metaValue(SCOPE_TYPE_META_KEY);
7496
+ // #2995: and the parent it fixed, which a load never changes either: a copy carries none.
7497
+ const parentBefore = this.metaValue(PARENT_SCOPE_META_KEY);
7392
7498
  // #2555: this store's own permission flags, read before the drops take them.
7393
7499
  const flagsBefore = keepPermissionFlags ? PERMISSION_FLAG_KEYS.map((key) => [key, this.metaValue(key)]) : [];
7394
7500
  if (provisionedFor !== undefined && receiptBefore !== null && receiptBefore !== provisionedFor) {
@@ -7502,8 +7608,13 @@ options = {}) {
7502
7608
  if (typeBefore !== null) {
7503
7609
  this.sql.exec(`INSERT INTO _substrat_meta (key, value) VALUES (?, ?)`, SCOPE_TYPE_META_KEY, typeBefore);
7504
7610
  }
7611
+ this.sql.exec(`DELETE FROM _substrat_meta WHERE key = ?`, PARENT_SCOPE_META_KEY);
7612
+ if (parentBefore !== null) {
7613
+ this.sql.exec(`INSERT INTO _substrat_meta (key, value) VALUES (?, ?)`, PARENT_SCOPE_META_KEY, parentBefore);
7614
+ }
7505
7615
  // Read again from what the load left, as a wake would: the store is the type's only record.
7506
7616
  this.scopeTypeHeld = undefined;
7617
+ this.scopeParentHeld = undefined;
7507
7618
  // #1722: whatever stamp an export read here no longer describes this store, so every load
7508
7619
  // replaces it: with the carry's own, or with none. And the write revision moves on from
7509
7620
  // where it stood before the drops, so it never goes back.
@@ -8216,7 +8327,9 @@ options = {}) {
8216
8327
  * one: whatever a handoff switch says, since a broker keeps what it took while it was on.
8217
8328
  *
8218
8329
  * The broker and the ids its messages are kept under are named first from the handoff state:
8219
- * the (tenant, scope) every handoff of this scope used, written before its first broker call. A
8330
+ * the (tenant, scope) every handoff of this scope used, written before its first broker call, and
8331
+ * (#3639) the environment whose broker those handoffs reached, so a named environment's messages
8332
+ * are erased where they went, never looked for in production's broker. A
8220
8333
  * scope whose state is gone (a restore) falls back to its own identity, its `provisioned_for`
8221
8334
  * receipt and its object name, as `wakeForReconcileAsk` reads them. So `redactSubject` takes no
8222
8335
  * new argument, and a coordinator of any version reaches the broker. A scope that can name it by
@@ -8231,7 +8344,8 @@ options = {}) {
8231
8344
  if (!tenant.success || !scope.success) {
8232
8345
  throw substratError('unavailable', 'subject erasure: this scope cannot name its delivery broker, so its copies were not erased');
8233
8346
  }
8234
- await this.deliveryBroker(tenant.data).eraseSubject({ tenantId: tenant.data, scopeId: scope.data, subjectId, at });
8347
+ // #3639: the broker of the scope's environment, which the handoff state keeps after the mode went off.
8348
+ await this.deliveryBroker(tenant.data, await this.handoffEnvironment()).eraseSubject({ tenantId: tenant.data, scopeId: scope.data, subjectId, at });
8235
8349
  }
8236
8350
  /**
8237
8351
  * One page of what this scope holds about one data subject (GDPR Art. 15, D-74): the kernel's