@substrat-run/kernel 0.221.0 → 0.223.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.
- package/dist/app-environments.d.ts +123 -4
- package/dist/app-environments.d.ts.map +1 -1
- package/dist/app-environments.js +212 -6
- package/dist/app-environments.js.map +1 -1
- package/dist/broker-counts.d.ts +8 -30
- package/dist/broker-counts.d.ts.map +1 -1
- package/dist/broker-counts.js +41 -6
- package/dist/broker-counts.js.map +1 -1
- package/dist/broker-shadow.d.ts +3 -0
- package/dist/broker-shadow.d.ts.map +1 -1
- package/dist/broker-shadow.js +1 -0
- package/dist/broker-shadow.js.map +1 -1
- package/dist/broker-telemetry.d.ts +11 -0
- package/dist/broker-telemetry.d.ts.map +1 -1
- package/dist/broker-telemetry.js +5 -0
- package/dist/broker-telemetry.js.map +1 -1
- package/dist/carried-copy.d.ts.map +1 -1
- package/dist/carried-copy.js +3 -1
- package/dist/carried-copy.js.map +1 -1
- package/dist/credential-bound-fetch.d.ts +73 -0
- package/dist/credential-bound-fetch.d.ts.map +1 -0
- package/dist/credential-bound-fetch.js +241 -0
- package/dist/credential-bound-fetch.js.map +1 -0
- package/dist/delivery-broker.d.ts +24 -5
- package/dist/delivery-broker.d.ts.map +1 -1
- package/dist/delivery-broker.js +30 -7
- package/dist/delivery-broker.js.map +1 -1
- package/dist/delivery-contract.d.ts +47 -3
- package/dist/delivery-contract.d.ts.map +1 -1
- package/dist/delivery-contract.js +101 -1
- package/dist/delivery-contract.js.map +1 -1
- package/dist/dependent-erasure.d.ts +106 -0
- package/dist/dependent-erasure.d.ts.map +1 -0
- package/dist/dependent-erasure.js +150 -0
- package/dist/dependent-erasure.js.map +1 -0
- package/dist/directory-lake-keep.d.ts.map +1 -1
- package/dist/directory-lake-keep.js +7 -1
- package/dist/directory-lake-keep.js.map +1 -1
- package/dist/home-scope.d.ts +104 -0
- package/dist/home-scope.d.ts.map +1 -0
- package/dist/home-scope.js +127 -0
- package/dist/home-scope.js.map +1 -0
- package/dist/index.d.ts +15 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -7
- package/dist/index.js.map +1 -1
- package/dist/membership-executor.d.ts +5 -2
- package/dist/membership-executor.d.ts.map +1 -1
- package/dist/membership-executor.js +5 -1
- package/dist/membership-executor.js.map +1 -1
- package/dist/module-operations.d.ts +9 -0
- package/dist/module-operations.d.ts.map +1 -1
- package/dist/module-operations.js +22 -0
- package/dist/module-operations.js.map +1 -1
- package/dist/owned-reaps.d.ts +73 -0
- package/dist/owned-reaps.d.ts.map +1 -0
- package/dist/owned-reaps.js +71 -0
- package/dist/owned-reaps.js.map +1 -0
- package/dist/platform-sweep.d.ts +14 -1
- package/dist/platform-sweep.d.ts.map +1 -1
- package/dist/platform-sweep.js +117 -59
- package/dist/platform-sweep.js.map +1 -1
- package/dist/relay-intents.d.ts +38 -0
- package/dist/relay-intents.d.ts.map +1 -0
- package/dist/relay-intents.js +45 -0
- package/dist/relay-intents.js.map +1 -0
- package/dist/release-within-major.d.ts +54 -2
- package/dist/release-within-major.d.ts.map +1 -1
- package/dist/release-within-major.js +80 -6
- package/dist/release-within-major.js.map +1 -1
- package/dist/scope-copy-ledger.d.ts +5 -0
- package/dist/scope-copy-ledger.d.ts.map +1 -1
- package/dist/scope-copy-ledger.js +8 -0
- package/dist/scope-copy-ledger.js.map +1 -1
- package/dist/scope-host.d.ts +142 -6
- package/dist/scope-host.d.ts.map +1 -1
- package/dist/scope-host.js.map +1 -1
- package/dist/scope-types.d.ts +15 -0
- package/dist/scope-types.d.ts.map +1 -1
- package/dist/scope-types.js +19 -0
- package/dist/scope-types.js.map +1 -1
- package/dist/sealed-box.d.ts +12 -0
- package/dist/sealed-box.d.ts.map +1 -1
- package/dist/sealed-box.js +15 -0
- package/dist/sealed-box.js.map +1 -1
- package/package.json +2 -2
package/dist/platform-sweep.js
CHANGED
|
@@ -2,6 +2,7 @@ import { drainedEvent, instant, scopeId as scopeIdSchema, substratError } from '
|
|
|
2
2
|
import { sweepDirectoryLake } from './directory-lake.js';
|
|
3
3
|
import { withheldOpsFailure, withheldStaffFailure } from './ops-failure-reference.js';
|
|
4
4
|
import { ulid } from './ulid.js';
|
|
5
|
+
import { OWNED_REAP_HORIZON_MS, isRetentionReapDue, isSnapshotReapDue, isTenantReapDue, reapTenantThroughScopes, retentionReapDueAt, snapshotReapDueAt, tenantReapDueAt, } from './owned-reaps.js';
|
|
5
6
|
import { STORAGE_GAUGE_PRUNE_BATCH, STORED_SCOPE_STATUSES, holdsStore } from './storage-gauge.js';
|
|
6
7
|
import { BILLING_ROLLUP_RETENTION_MONTHS, billingRollupHorizon, utcDayOf } from './billing-retention.js';
|
|
7
8
|
import { METER_DAYS_PRUNE_BATCH, METER_SNAPSHOT_TIMEOUT_MS } from './meter-days.js';
|
|
@@ -15,7 +16,7 @@ import { MIGRATION_FLAG_THRESHOLD, migrationFleet, migrationProgress, scopeMigra
|
|
|
15
16
|
import { UNDRAINED_SKIPPED_IDS } from './outbox-event.js';
|
|
16
17
|
import { OUTBOX_PRUNE_BATCH, OUTBOX_RETENTION_DAYS, outboxPruneDue } from './outbox-prune.js';
|
|
17
18
|
import { resolveVerticalInstanceFrom } from './peer.js';
|
|
18
|
-
import { isPrimaryScope, servingPointersFor } from './scope-identity.js';
|
|
19
|
+
import { INERT_SCOPE_REASON, isPrimaryScope, servingPointersFor } from './scope-identity.js';
|
|
19
20
|
import { provisionReconcileTarget } from './provision-reconcile.js';
|
|
20
21
|
import { mapBounded, message } from './map-bounded.js';
|
|
21
22
|
import { runningImportsOf } from './export-break.js';
|
|
@@ -400,6 +401,7 @@ async function runPlatformSweepPass(host, options) {
|
|
|
400
401
|
snapshotsReaped: 0,
|
|
401
402
|
archivedScopesReaped: 0,
|
|
402
403
|
tenantsReaped: 0,
|
|
404
|
+
reapsHandedOver: null,
|
|
403
405
|
platformRequestTotals: { scopes: 0, drained: 0, done: 0, failed: 0, pending: 0, skipped: 0, unreachable: 0, unsettleable: 0 },
|
|
404
406
|
provisionReconcile: null,
|
|
405
407
|
migrations: null,
|
|
@@ -799,6 +801,11 @@ async function runPlatformSweepPass(host, options) {
|
|
|
799
801
|
const scopes = (await listScopes({ status: 'active' })).filter((s) => isPrimaryScope(s) && !failedThisPass.has(s.id));
|
|
800
802
|
report.orphanAttachments = await sweepOrphanAttachmentWindow(host, options, options.orphanAttachments, scopes, report);
|
|
801
803
|
}
|
|
804
|
+
// K-69 (#3650): the reaps' owner. With `ownedReaps`, the three phases below reap nothing: each
|
|
805
|
+
// collects what is due within the horizon and hands it over, so the owner's alarm runs it.
|
|
806
|
+
const owned = options.ownedReaps;
|
|
807
|
+
const horizonMs = owned?.horizonMs ?? OWNED_REAP_HORIZON_MS;
|
|
808
|
+
const handOver = [];
|
|
802
809
|
if (options.gcSnapshots !== false) {
|
|
803
810
|
// Reap expired previews (§3/§9). Two shapes qualify, both throwaway-by-construction:
|
|
804
811
|
// a FORK (`forkedFrom` set — a snapshot of another scope) and a clean-room PREVIEW
|
|
@@ -814,21 +821,33 @@ async function runPlatformSweepPass(host, options) {
|
|
|
814
821
|
// claim (the control plane's `reapExpiredSnapshot` does).
|
|
815
822
|
const now = new Date().toISOString();
|
|
816
823
|
const scopes = await listScopes();
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
await reap(s.tenantId, s.id);
|
|
826
|
-
report.snapshotsReaped += 1;
|
|
827
|
-
}
|
|
828
|
-
catch (err) {
|
|
829
|
-
report.errors.push({ kind: 'gc', id: s.id, error: message(err) });
|
|
824
|
+
if (owned) {
|
|
825
|
+
const by = new Date(Date.now() + horizonMs).toISOString();
|
|
826
|
+
for (const s of scopes) {
|
|
827
|
+
if (s.status === 'reaped')
|
|
828
|
+
continue;
|
|
829
|
+
const dueAt = snapshotReapDueAt(s);
|
|
830
|
+
if (dueAt !== null && dueAt <= by)
|
|
831
|
+
handOver.push({ kind: 'snapshot', tenantId: s.tenantId, scopeId: s.id, dueAt });
|
|
830
832
|
}
|
|
831
|
-
}
|
|
833
|
+
}
|
|
834
|
+
else {
|
|
835
|
+
const expired = scopes.filter((s) => isSnapshotReapDue(s, now));
|
|
836
|
+
const reap = options.deleteSnapshotFn ??
|
|
837
|
+
(async (tenantId, scopeId) => {
|
|
838
|
+
await host.admin.beginScopeScriptReap(options.actor, tenantId, scopeId, { expiredBy: now });
|
|
839
|
+
await host.deleteSnapshot(options.actor, tenantId, scopeId);
|
|
840
|
+
});
|
|
841
|
+
await mapBounded(expired, concurrency, async (s) => {
|
|
842
|
+
try {
|
|
843
|
+
await reap(s.tenantId, s.id);
|
|
844
|
+
report.snapshotsReaped += 1;
|
|
845
|
+
}
|
|
846
|
+
catch (err) {
|
|
847
|
+
report.errors.push({ kind: 'gc', id: s.id, error: message(err) });
|
|
848
|
+
}
|
|
849
|
+
});
|
|
850
|
+
}
|
|
832
851
|
}
|
|
833
852
|
// -- reap long-archived scopes (control-plane.md §4.4) ----------------------
|
|
834
853
|
// Free the storage of scopes archived longer than the retention window — Cloudflare
|
|
@@ -838,22 +857,33 @@ async function runPlatformSweepPass(host, options) {
|
|
|
838
857
|
// knowable age and is left for a manual reap. `reapScope` re-checks the `archived`
|
|
839
858
|
// status below the seam, so a row that changed underneath fails closed there.
|
|
840
859
|
if (options.reapArchivedAfterDays !== undefined && options.reapArchivedAfterDays >= 0) {
|
|
841
|
-
const
|
|
860
|
+
const days = options.reapArchivedAfterDays;
|
|
842
861
|
const archived = await listScopes({ status: ['archived'] });
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
try {
|
|
850
|
-
await reap(s.tenantId, s.id);
|
|
851
|
-
report.archivedScopesReaped += 1;
|
|
862
|
+
if (owned) {
|
|
863
|
+
const by = new Date(Date.now() + horizonMs).toISOString();
|
|
864
|
+
for (const s of archived) {
|
|
865
|
+
const dueAt = retentionReapDueAt(s, days);
|
|
866
|
+
if (dueAt !== null && dueAt <= by)
|
|
867
|
+
handOver.push({ kind: 'retention', tenantId: s.tenantId, scopeId: s.id, dueAt });
|
|
852
868
|
}
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
869
|
+
}
|
|
870
|
+
else {
|
|
871
|
+
const nowMs = Date.now();
|
|
872
|
+
const due = archived.filter((s) => isRetentionReapDue(s, days, nowMs));
|
|
873
|
+
const reap = options.reapScopeFn ??
|
|
874
|
+
// Retention reap is a deliberate policy on already-archived scopes: force past the
|
|
875
|
+
// bound-hostname guard (which exists to stop the INTERACTIVE per-scope mistake).
|
|
876
|
+
((tenantId, scopeId) => host.admin.reapScope(options.actor, tenantId, scopeId, { force: true }));
|
|
877
|
+
await mapBounded(due, concurrency, async (s) => {
|
|
878
|
+
try {
|
|
879
|
+
await reap(s.tenantId, s.id);
|
|
880
|
+
report.archivedScopesReaped += 1;
|
|
881
|
+
}
|
|
882
|
+
catch (err) {
|
|
883
|
+
report.errors.push({ kind: 'reap', id: s.id, error: message(err) });
|
|
884
|
+
}
|
|
885
|
+
});
|
|
886
|
+
}
|
|
857
887
|
}
|
|
858
888
|
// -- reap tenants past their grace window (control-plane.md §4.8) ------------
|
|
859
889
|
// A tenant flipped to `deleting` sits in a reversible grace window; once it is older
|
|
@@ -865,43 +895,49 @@ async function runPlatformSweepPass(host, options) {
|
|
|
865
895
|
// applies here for free. `reapTenant` re-checks the `deleting` status below the seam,
|
|
866
896
|
// so a row that changed underneath fails closed there.
|
|
867
897
|
if (options.reapDeletingAfterDays !== undefined && options.reapDeletingAfterDays >= 0) {
|
|
868
|
-
const
|
|
898
|
+
const days = options.reapDeletingAfterDays;
|
|
869
899
|
const tenants = await host.admin.listTenants(options.actor);
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
//
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
900
|
+
if (owned) {
|
|
901
|
+
const by = new Date(Date.now() + horizonMs).toISOString();
|
|
902
|
+
for (const t of tenants) {
|
|
903
|
+
const dueAt = tenantReapDueAt(t, days);
|
|
904
|
+
if (dueAt !== null && dueAt <= by)
|
|
905
|
+
handOver.push({ kind: 'tenant', tenantId: t.id, dueAt });
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
else {
|
|
909
|
+
const nowMs = Date.now();
|
|
910
|
+
const due = tenants.filter((t) => isTenantReapDue(t, days, nowMs));
|
|
911
|
+
const reapOneScope = options.reapTenantScopeFn ??
|
|
912
|
+
options.reapScopeFn ??
|
|
913
|
+
// Tenant teardown releases every name by design: force past the bound-hostname guard.
|
|
914
|
+
((tenantId, scopeId) => host.admin.reapScope(options.actor, tenantId, scopeId, { force: true }));
|
|
915
|
+
const reapTenant = options.reapTenantFn ??
|
|
916
|
+
// Co-located default: every scope through the scope seam, then the tenant's directory rows.
|
|
917
|
+
((tenantId) => reapTenantThroughScopes(host.admin, options.actor, tenantId, reapOneScope));
|
|
918
|
+
await mapBounded(due, concurrency, async (t) => {
|
|
919
|
+
try {
|
|
920
|
+
await reapTenant(t.id);
|
|
921
|
+
report.tenantsReaped += 1;
|
|
922
|
+
}
|
|
923
|
+
catch (err) {
|
|
924
|
+
report.errors.push({ kind: 'reap-tenant', id: t.id, error: message(err) });
|
|
893
925
|
}
|
|
894
|
-
await host.admin.reapTenant(options.actor, tenantId);
|
|
895
926
|
});
|
|
896
|
-
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
if (owned) {
|
|
930
|
+
report.reapsHandedOver = handOver.length;
|
|
931
|
+
if (handOver.length > 0) {
|
|
897
932
|
try {
|
|
898
|
-
await
|
|
899
|
-
report.tenantsReaped += 1;
|
|
933
|
+
await owned.ensure(handOver);
|
|
900
934
|
}
|
|
901
935
|
catch (err) {
|
|
902
|
-
|
|
936
|
+
// Nothing is reaped in its place: a reap is irreversible, and the owner may be mid-run.
|
|
937
|
+
// The next pass hands the same reaps over again.
|
|
938
|
+
report.errors.push({ kind: 'reap-owner', id: '*', error: message(err) });
|
|
903
939
|
}
|
|
904
|
-
}
|
|
940
|
+
}
|
|
905
941
|
}
|
|
906
942
|
// -- connector sweeps (#574, #3324) ------------------------------------------
|
|
907
943
|
// Skipped when the caller runs them itself, after everything else (`sweepConnectors: false`
|
|
@@ -2549,6 +2585,28 @@ async function sweepConnections(host, options, report, listScopes, concurrency)
|
|
|
2549
2585
|
record('skipped', { error: CONNECTOR_SWEEP_PAUSED });
|
|
2550
2586
|
return;
|
|
2551
2587
|
}
|
|
2588
|
+
// #3530 step 6: a scope's own connection is swept only while that scope may make effects through
|
|
2589
|
+
// it: an install, or the scope of a named environment given connections of its own. A choice
|
|
2590
|
+
// taken back, a name taken off or a preview archived leaves the connection bound and unswept, so
|
|
2591
|
+
// an environment without connections of its own is inert again. Recorded, as a pause is: the
|
|
2592
|
+
// connection is live and nothing polls it.
|
|
2593
|
+
// A connection that names no owner (null, or a record from before owners) is the tenant's.
|
|
2594
|
+
if (c.ownerScopeId) {
|
|
2595
|
+
let reach;
|
|
2596
|
+
try {
|
|
2597
|
+
reach = await host.admin.connectionReach(options.actor, c.tenantId, c.ownerScopeId);
|
|
2598
|
+
}
|
|
2599
|
+
catch (err) {
|
|
2600
|
+
report.errors.push({ kind: 'sweep', id: c.id, error: `cannot read whether the scope owning the connection may make effects: ${message(err)}` });
|
|
2601
|
+
report.connectionsSkipped += 1;
|
|
2602
|
+
return;
|
|
2603
|
+
}
|
|
2604
|
+
if (reach === 'none') {
|
|
2605
|
+
report.connectionsSkipped += 1;
|
|
2606
|
+
record('skipped', { error: INERT_SCOPE_REASON });
|
|
2607
|
+
return;
|
|
2608
|
+
}
|
|
2609
|
+
}
|
|
2552
2610
|
const sweeper = options.sweepers[c.provider] ?? options.sweeperFor?.(c);
|
|
2553
2611
|
if (!sweeper) {
|
|
2554
2612
|
report.connectionsSkipped += 1;
|