@capybara-hq/kernel 0.1.0-rc.121 → 0.1.0-rc.122
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/background/finish.d.ts +5 -1
- package/dist/background/finish.js +29 -18
- package/dist/background/launch.d.ts +0 -5
- package/dist/background/launch.js +1 -6
- package/dist/background/managed.js +1 -4
- package/dist/background/poll.job.d.ts +3 -25
- package/dist/background/poll.job.js +20 -112
- package/dist/background/render.d.ts +2 -8
- package/dist/background/render.js +3 -17
- package/dist/background/stop.d.ts +15 -16
- package/dist/background/stop.js +39 -76
- package/dist/background/store.d.ts +17 -45
- package/dist/background/store.js +60 -94
- package/dist/background/tasks.service.d.ts +2 -5
- package/dist/background/tasks.service.js +9 -20
- package/dist/background/wake.js +3 -2
- package/dist/catalog/admin-catalog.controller.d.ts +2 -18
- package/dist/catalog/admin-catalog.controller.js +2 -28
- package/dist/catalog/catalog-content.d.ts +1 -5
- package/dist/catalog/catalog-items.d.ts +2 -6
- package/dist/catalog/catalog-items.js +5 -26
- package/dist/catalog/catalog-scope.service.d.ts +1 -121
- package/dist/catalog/catalog-scope.service.js +12 -552
- package/dist/catalog/catalog.service.d.ts +4 -15
- package/dist/catalog/catalog.service.js +7 -35
- package/dist/catalog/job-ids.d.ts +0 -18
- package/dist/catalog/job-ids.js +0 -20
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/org-catalog.service.js +6 -20
- package/dist/catalog/org-plugin-uploads.controller.d.ts +4 -19
- package/dist/catalog/org-plugin-uploads.controller.js +6 -34
- package/dist/catalog/org-plugin-uploads.d.ts +3 -10
- package/dist/catalog/org-plugin-uploads.js +4 -18
- package/dist/catalog/org-plugin-uploads.schemas.js +0 -1
- package/dist/catalog/owned-items.d.ts +6 -11
- package/dist/catalog/owned-items.js +10 -20
- package/dist/catalog/ownership.d.ts +3 -29
- package/dist/catalog/ownership.js +4 -54
- package/dist/catalog/platform-components.d.ts +5 -11
- package/dist/catalog/platform-components.js +8 -15
- package/dist/catalog/plugin-import.d.ts +3 -42
- package/dist/catalog/plugin-import.js +26 -195
- package/dist/catalog/plugin-install.js +1 -6
- package/dist/catalog/plugin-package.d.ts +1 -0
- package/dist/catalog/plugin-package.js +5 -0
- package/dist/catalog/plugin-upgrade.d.ts +3 -26
- package/dist/catalog/plugin-upgrade.js +20 -103
- package/dist/catalog/request-rules.js +4 -6
- package/dist/catalog/scope-sync.js +2 -4
- package/dist/catalog/scope.d.ts +2 -5
- package/dist/channels/jobs.d.ts +3 -3
- package/dist/channels/jobs.js +4 -3
- package/dist/channels/outbound.d.ts +1 -0
- package/dist/channels/outbound.js +32 -8
- package/dist/config/load.d.ts +0 -25
- package/dist/config/load.js +0 -57
- package/dist/config/schema.js +2 -3
- package/dist/conversations/attachments.service.js +3 -5
- package/dist/conversations/conversations.service.d.ts +3 -3
- package/dist/conversations/conversations.service.js +3 -3
- package/dist/conversations/job-org.d.ts +3 -0
- package/dist/conversations/job-org.js +11 -0
- package/dist/conversations/prompt-suggestions.d.ts +2 -7
- package/dist/conversations/prompt-suggestions.js +29 -27
- package/dist/conversations/titles.d.ts +3 -4
- package/dist/conversations/titles.js +19 -30
- package/dist/db/kernel-schema.d.ts +6 -16
- package/dist/db/pool.js +7 -2
- package/dist/devices/devices.controller.d.ts +0 -5
- package/dist/devices/devices.controller.js +2 -20
- package/dist/devices/devices.service.d.ts +1 -17
- package/dist/devices/devices.service.js +0 -22
- package/dist/errors.d.ts +1 -5
- package/dist/errors.js +1 -5
- package/dist/evals/judge.d.ts +3 -0
- package/dist/evals/judge.js +1 -1
- package/dist/evals/run-replay.d.ts +1 -1
- package/dist/evals/run-replay.js +26 -29
- package/dist/evals/step-replay.d.ts +3 -1
- package/dist/evals/step-replay.js +10 -1
- package/dist/evals/worker.d.ts +3 -1
- package/dist/evals/worker.js +53 -21
- package/dist/extensions/deployment-config-store.js +18 -14
- package/dist/extensions/effective-config.d.ts +1 -5
- package/dist/extensions/effective-config.js +1 -5
- package/dist/extensions/hooks.d.ts +3 -1
- package/dist/extensions/hooks.js +7 -2
- package/dist/extensions/installs.d.ts +2 -14
- package/dist/extensions/installs.js +10 -32
- package/dist/extensions/org-config.d.ts +3 -4
- package/dist/extensions/org-config.js +3 -4
- package/dist/extensions/plugin-guides.d.ts +0 -1
- package/dist/extensions/plugin-guides.js +0 -1
- package/dist/extensions/plugin-icons.d.ts +0 -1
- package/dist/extensions/plugin-icons.js +0 -3
- package/dist/files/blob-sweep.job.d.ts +2 -11
- package/dist/files/blob-sweep.job.js +7 -21
- package/dist/files/hash-job.d.ts +5 -15
- package/dist/files/hash-job.js +14 -33
- package/dist/files/library-jobs.module.d.ts +1 -6
- package/dist/files/library-jobs.module.js +3 -9
- package/dist/identity/api-tokens.js +54 -40
- package/dist/identity/auth.guard.js +2 -2
- package/dist/identity/sessions.js +7 -3
- package/dist/identity/settings.js +5 -21
- package/dist/inbox/inbox.service.d.ts +2 -3
- package/dist/inbox/org-notices.d.ts +0 -14
- package/dist/inbox/platform-inbox.service.d.ts +1 -8
- package/dist/inbox/platform-inbox.service.js +2 -6
- package/dist/inbox/platform-notices.d.ts +3 -3
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -3
- package/dist/infra/database/database.module.js +2 -1
- package/dist/infra/database/org-scope.d.ts +5 -3
- package/dist/infra/database/org-scope.js +7 -1
- package/dist/infra/database/scoped-dialect.d.ts +3 -1
- package/dist/infra/database/scoped-dialect.js +17 -5
- package/dist/infra/events/kernel-events.d.ts +2 -0
- package/dist/infra/outbox/outbox.service.d.ts +2 -0
- package/dist/infra/outbox/outbox.service.js +10 -0
- package/dist/infra/outbox/registry.d.ts +0 -41
- package/dist/infra/outbox/registry.js +0 -37
- package/dist/models/embeddings.d.ts +0 -5
- package/dist/models/embeddings.js +28 -35
- package/dist/models/images.d.ts +3 -8
- package/dist/models/images.js +19 -37
- package/dist/models/purposes.d.ts +7 -2
- package/dist/models/purposes.js +16 -3
- package/dist/orgs/device-network-setting.d.ts +0 -44
- package/dist/orgs/device-network-setting.js +0 -83
- package/dist/orgs/invitations.service.js +34 -30
- package/dist/orgs/offboarding.d.ts +2 -2
- package/dist/orgs/offboarding.js +2 -2
- package/dist/orgs/orgs.service.d.ts +1 -1
- package/dist/orgs/orgs.service.js +19 -15
- package/dist/orgs/settings.service.d.ts +19 -14
- package/dist/orgs/settings.service.js +12 -37
- package/dist/platform/exclusions.js +0 -11
- package/dist/platform/ops/catalog-admin.ops.js +0 -8
- package/dist/platform/ops/devices.ops.js +0 -28
- package/dist/platform/ops/extensions-admin.ops.js +3 -3
- package/dist/platform/ops/inbox.ops.js +5 -22
- package/dist/platform/ops/org-plugins.ops.d.ts +1 -3
- package/dist/platform/ops/org-plugins.ops.js +11 -67
- package/dist/roles/worker.module.js +0 -9
- package/dist/runtime/hook-calls.d.ts +13 -6
- package/dist/runtime/hook-calls.js +26 -4
- package/dist/runtime/maintenance.d.ts +3 -12
- package/dist/runtime/maintenance.js +25 -55
- package/dist/runtime/model-call.d.ts +4 -2
- package/dist/runtime/model-call.js +59 -58
- package/dist/runtime/providers.d.ts +27 -1
- package/dist/runtime/providers.js +57 -0
- package/dist/runtime/run-jobs.d.ts +1 -1
- package/dist/runtime/run-processors.d.ts +3 -9
- package/dist/runtime/run-worker.d.ts +2 -0
- package/dist/runtime/run-worker.js +23 -8
- package/dist/runtime/subagents/deliveries.js +6 -1
- package/dist/runtime/subagents/dispatch.d.ts +3 -3
- package/dist/runtime/write-base.service.d.ts +2 -3
- package/dist/runtime/write-base.service.js +3 -5
- package/dist/sandbox/device-sandbox-settings.d.ts +38 -92
- package/dist/sandbox/device-sandbox-settings.js +19 -325
- package/dist/sandbox/jobs.d.ts +3 -14
- package/dist/sandbox/jobs.js +2 -20
- package/dist/sandbox/modes.d.ts +5 -45
- package/dist/sandbox/modes.js +3 -60
- package/dist/sandbox/operation-authority.js +0 -11
- package/dist/sandbox/operation-intents.d.ts +32 -9
- package/dist/sandbox/operation-intents.js +241 -32
- package/dist/sandbox/operation-intents.module.js +2 -1
- package/dist/sandbox/operation-reconcile.job.d.ts +9 -11
- package/dist/sandbox/operation-reconcile.job.js +119 -33
- package/dist/sandbox/operation-revoke.d.ts +20 -0
- package/dist/sandbox/operation-revoke.js +3 -0
- package/dist/sandbox/permission-ceiling-writes.d.ts +1 -2
- package/dist/sandbox/permission-ceiling-writes.js +3 -6
- package/dist/sandbox/permission-config-publication.d.ts +1 -28
- package/dist/sandbox/permission-config-publication.js +14 -211
- package/dist/sandbox/permission-facts.d.ts +4 -15
- package/dist/sandbox/permission-facts.js +7 -29
- package/dist/sandbox/permission-instance-writes.d.ts +1 -4
- package/dist/sandbox/permission-instance-writes.js +1 -55
- package/dist/sandbox/providers.d.ts +1 -6
- package/dist/sandbox/providers.js +1 -15
- package/dist/sandbox/review/classifier.js +12 -13
- package/dist/sandbox/sandbox.module.js +3 -6
- package/dist/sandbox/sandbox.service.d.ts +17 -123
- package/dist/sandbox/sandbox.service.js +239 -998
- package/dist/shares/liveness.d.ts +1 -2
- package/dist/shares/liveness.js +1 -2
- package/dist/shares/shares.module.d.ts +1 -2
- package/dist/shares/shares.module.js +2 -5
- package/dist/shares/shares.service.js +1 -2
- package/dist/tools/builtins/image/generate.js +7 -15
- package/dist/tools/builtins/sandbox/common.d.ts +0 -2
- package/dist/tools/builtins/sandbox/common.js +1 -27
- package/dist/tools/builtins/sandbox/task-list.js +10 -10
- package/dist/tools/builtins/sandbox/task-output.d.ts +3 -10
- package/dist/tools/builtins/sandbox/task-output.js +13 -83
- package/dist/tools/builtins/sandbox/task-stop.js +18 -22
- package/dist/tools/builtins/vision/read-image.js +9 -10
- package/dist/tools/builtins/web/extract.js +9 -10
- package/package.json +3 -3
- package/src/migrations/0206_retire_org_extension_uploads.sql +125 -0
- package/src/migrations/0207_confirm_device_instance_destruction.sql +25 -0
- package/src/migrations/0208_convert_stored_permission_settings.sql +189 -0
- package/dist/background/retire-legacy-tasks.job.d.ts +0 -57
- package/dist/background/retire-legacy-tasks.job.js +0 -149
- package/dist/catalog/owned-plugin-cleanup.d.ts +0 -47
- package/dist/catalog/owned-plugin-cleanup.js +0 -140
- package/dist/config/permission-migration.d.ts +0 -34
- package/dist/config/permission-migration.js +0 -115
- package/dist/devices/legacy-cleanup.job.d.ts +0 -34
- package/dist/devices/legacy-cleanup.job.js +0 -147
- package/dist/files/library-backfill.d.ts +0 -63
- package/dist/files/library-backfill.js +0 -143
- package/dist/infra/cli/permission-cutover.d.ts +0 -59
- package/dist/infra/cli/permission-cutover.js +0 -107
- package/dist/sandbox/cloud-permission-snapshot.d.ts +0 -159
- package/dist/sandbox/cloud-permission-snapshot.js +0 -430
- package/dist/sandbox/cloud-permission-snapshot.module.d.ts +0 -8
- package/dist/sandbox/cloud-permission-snapshot.module.js +0 -34
- package/dist/sandbox/legacy-retirement.d.ts +0 -284
- package/dist/sandbox/legacy-retirement.js +0 -1165
- package/dist/sandbox/legacy-retirement.module.d.ts +0 -8
- package/dist/sandbox/legacy-retirement.module.js +0 -25
- package/dist/shares/share-objects.d.ts +0 -47
- package/dist/shares/share-objects.js +0 -93
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
|
-
};
|
|
10
|
-
import { Inject, Injectable } from "@nestjs/common";
|
|
11
|
-
import { sql } from "kysely";
|
|
12
|
-
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
13
|
-
import { asPlatform } from "../infra/database/org-scope.js";
|
|
14
|
-
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
15
|
-
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
16
|
-
import { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
17
|
-
import { KERNEL_LOGGER } from "../infra/tokens.js";
|
|
18
|
-
import { MAINTENANCE_QUEUE_NAME } from "../runtime/maintenance-queue.js";
|
|
19
|
-
/** The one-off catch-up copy's job name and deterministic id (no `:`). */
|
|
20
|
-
export const FILE_LIBRARY_BACKFILL_JOB = "file-library-backfill";
|
|
21
|
-
/**
|
|
22
|
-
* The `deployment_settings` key that records the catch-up copy settled (it ran, or it was skipped
|
|
23
|
-
* because the deploy is too long ago). Not a setting a person edits: the settings reader ignores
|
|
24
|
-
* keys it does not know.
|
|
25
|
-
*/
|
|
26
|
-
export const FILE_LIBRARY_COPY_SETTLED = "fileLibraryCopySettled";
|
|
27
|
-
/** The migration that created the file library and its copy function. */
|
|
28
|
-
export const FILE_LIBRARY_MIGRATION = "0190_file_library.sql";
|
|
29
|
-
/** How long after it is owed the catch-up runs: once the rolling window of the deploy is over. */
|
|
30
|
-
export const BACKFILL_DELAY_MS = 30 * 60_000;
|
|
31
|
-
/** After this many days since the migration the catch-up is skipped (nothing old is left). */
|
|
32
|
-
export const BACKFILL_WINDOW_DAYS = 7;
|
|
33
|
-
/** How far before the migration the catch-up copies from (rows written around the deploy). */
|
|
34
|
-
const BACKFILL_LOOKBACK = "1 hour";
|
|
35
|
-
/**
|
|
36
|
-
* The one-off catch-up of the file library's data copy (plan amendment K9). During a rolling deploy
|
|
37
|
-
* old replicas keep writing chat attachments, artifacts and shares the old way after migration
|
|
38
|
-
* 0191 copied them; once the window is over this job runs `file_library_copy(<0190 applied_at - 1
|
|
39
|
-
* hour>)` (idempotent) so those rows become library files, blobs and references too. It runs once
|
|
40
|
-
* (deterministic job id `file-library-backfill`, the settled marker in the copy's own transaction)
|
|
41
|
-
* and is skipped more than {@link BACKFILL_WINDOW_DAYS} days after the migration.
|
|
42
|
-
*
|
|
43
|
-
* The hashing job merges no blob before the marker exists ({@link settled}): the copy re-points a
|
|
44
|
-
* share whose blob differs from the blob of its legacy `object_key`, so a share merged before the
|
|
45
|
-
* copy would be pointed back at the merged duplicate.
|
|
46
|
-
*/
|
|
47
|
-
let FileLibraryBackfill = class FileLibraryBackfill {
|
|
48
|
-
db;
|
|
49
|
-
txHost;
|
|
50
|
-
outbox;
|
|
51
|
-
log;
|
|
52
|
-
constructor(db, txHost, outbox, log) {
|
|
53
|
-
this.db = db;
|
|
54
|
-
this.txHost = txHost;
|
|
55
|
-
this.outbox = outbox;
|
|
56
|
-
this.log = log;
|
|
57
|
-
}
|
|
58
|
-
/** Whether the catch-up copy settled (ran or was skipped): the hashing job may merge blobs. */
|
|
59
|
-
async settled() {
|
|
60
|
-
const row = await this.db
|
|
61
|
-
.selectFrom("deployment_settings")
|
|
62
|
-
.select("key")
|
|
63
|
-
.where("key", "=", FILE_LIBRARY_COPY_SETTLED)
|
|
64
|
-
.executeTakeFirst();
|
|
65
|
-
return row !== undefined;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Owes the catch-up unless it settled: {@link BACKFILL_DELAY_MS} from now while the migration is
|
|
69
|
-
* within the window (the worker start of a deploy), at once otherwise (it only records the skip).
|
|
70
|
-
* Owing it again while it is waiting is a no-op (the same job id). Returns whether a row was
|
|
71
|
-
* written.
|
|
72
|
-
*/
|
|
73
|
-
async ensureOwed() {
|
|
74
|
-
if (await this.settled())
|
|
75
|
-
return false;
|
|
76
|
-
const applied = await this.appliedAt();
|
|
77
|
-
if (applied === undefined)
|
|
78
|
-
return false;
|
|
79
|
-
const runAt = this.withinWindow(applied) ? new Date(Date.now() + BACKFILL_DELAY_MS) : undefined;
|
|
80
|
-
return this.owe(runAt);
|
|
81
|
-
}
|
|
82
|
-
async owe(runAt) {
|
|
83
|
-
return this.outbox.add({
|
|
84
|
-
queue: MAINTENANCE_QUEUE_NAME,
|
|
85
|
-
name: FILE_LIBRARY_BACKFILL_JOB,
|
|
86
|
-
jobId: FILE_LIBRARY_BACKFILL_JOB,
|
|
87
|
-
data: null,
|
|
88
|
-
...(runAt !== undefined && { runAt }),
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* The job (deployment-wide): the copy from an hour before the migration, or the skip when the
|
|
93
|
-
* migration is older than the window; either way the settled marker, in the same transaction.
|
|
94
|
-
* Nothing to do once settled.
|
|
95
|
-
*/
|
|
96
|
-
run() {
|
|
97
|
-
return asPlatform("file library catch-up copy across every org", () => this.copyOnce());
|
|
98
|
-
}
|
|
99
|
-
async copyOnce() {
|
|
100
|
-
if (await this.settled())
|
|
101
|
-
return "settled";
|
|
102
|
-
const applied = await this.appliedAt();
|
|
103
|
-
if (applied === undefined)
|
|
104
|
-
throw new Error(`${FILE_LIBRARY_MIGRATION} is not applied`);
|
|
105
|
-
let outcome = "skipped";
|
|
106
|
-
if (this.withinWindow(applied)) {
|
|
107
|
-
// the function names the tables itself, each statement deployment-wide by design
|
|
108
|
-
await sql `SELECT capybara.file_library_copy(${applied}::timestamptz - ${BACKFILL_LOOKBACK}::interval)`.execute(this.db.db);
|
|
109
|
-
outcome = "copied";
|
|
110
|
-
}
|
|
111
|
-
const value = { outcome, at: new Date().toISOString() };
|
|
112
|
-
await this.db.db
|
|
113
|
-
.insertInto("deployment_settings")
|
|
114
|
-
.values({ key: FILE_LIBRARY_COPY_SETTLED, value: JSON.stringify(value) })
|
|
115
|
-
.onConflict((oc) => oc.column("key").doNothing())
|
|
116
|
-
.execute();
|
|
117
|
-
this.log.info("file library catch-up copy settled", { outcome });
|
|
118
|
-
return outcome;
|
|
119
|
-
}
|
|
120
|
-
/** When the migration was applied (the migrator's own bookkeeping), undefined when it was not. */
|
|
121
|
-
async appliedAt() {
|
|
122
|
-
const r = await sql `SELECT applied_at FROM capybara._migrations
|
|
123
|
-
WHERE name = ${FILE_LIBRARY_MIGRATION}`.execute(this.db.db);
|
|
124
|
-
return r.rows[0]?.applied_at;
|
|
125
|
-
}
|
|
126
|
-
withinWindow(applied) {
|
|
127
|
-
return Date.now() - applied.getTime() <= BACKFILL_WINDOW_DAYS * 24 * 3_600_000;
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
__decorate([
|
|
131
|
-
Transactional()
|
|
132
|
-
], FileLibraryBackfill.prototype, "owe", null);
|
|
133
|
-
__decorate([
|
|
134
|
-
Transactional()
|
|
135
|
-
], FileLibraryBackfill.prototype, "copyOnce", null);
|
|
136
|
-
FileLibraryBackfill = __decorate([
|
|
137
|
-
Injectable(),
|
|
138
|
-
__param(0, Inject(KernelDb)),
|
|
139
|
-
__param(1, Inject(TransactionHost)),
|
|
140
|
-
__param(2, Inject(OutboxService)),
|
|
141
|
-
__param(3, Inject(KERNEL_LOGGER))
|
|
142
|
-
], FileLibraryBackfill);
|
|
143
|
-
export { FileLibraryBackfill };
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import type { KernelConfig } from "../../config/schema.js";
|
|
2
|
-
import type { KernelLogger } from "../../log.js";
|
|
3
|
-
import { type CloudSnapshotProgress, type CloudSnapshotRun } from "../../sandbox/cloud-permission-snapshot.js";
|
|
4
|
-
import { type LegacyFreezeResult, type LegacyRetirementReport } from "../../sandbox/legacy-retirement.js";
|
|
5
|
-
/**
|
|
6
|
-
* The operator surface of the permission runtime cutover (B-10, B-26): `capybara permissions
|
|
7
|
-
* cutover report | freeze | snapshot`. The report and the freeze use PostgreSQL only (the report
|
|
8
|
-
* reads replica presence from Redis when it answers, and says so when it does not); the snapshot
|
|
9
|
-
* needs Redis, because each device is snapshotted under its lifecycle lease.
|
|
10
|
-
*/
|
|
11
|
-
/** A live replica as the report shows it. */
|
|
12
|
-
export interface CutoverReplica {
|
|
13
|
-
id: string;
|
|
14
|
-
version: string;
|
|
15
|
-
roles: string[];
|
|
16
|
-
startedAt: string;
|
|
17
|
-
/** Runs this CLI's kernel version. */
|
|
18
|
-
sameVersion: boolean;
|
|
19
|
-
}
|
|
20
|
-
/** `capybara permissions cutover report`. */
|
|
21
|
-
export interface PermissionCutoverReport {
|
|
22
|
-
kernelVersion: string;
|
|
23
|
-
/** This CLI's permission configuration is the published one (the snapshot needs it). */
|
|
24
|
-
configCurrent: boolean;
|
|
25
|
-
/**
|
|
26
|
-
* The live replicas by presence (Redis), null when Redis did not answer. A replica on another
|
|
27
|
-
* version may run code without the freeze (unfenced): stop old replicas before the freeze.
|
|
28
|
-
*/
|
|
29
|
-
replicas: CutoverReplica[] | null;
|
|
30
|
-
retirement: LegacyRetirementReport;
|
|
31
|
-
snapshot: CloudSnapshotProgress;
|
|
32
|
-
}
|
|
33
|
-
/** The report (no writes). `presence: false` skips the replica presence read. */
|
|
34
|
-
export declare function permissionCutoverReport(config: KernelConfig, opts: {
|
|
35
|
-
logger: KernelLogger;
|
|
36
|
-
presence?: boolean;
|
|
37
|
-
}): Promise<PermissionCutoverReport>;
|
|
38
|
-
/**
|
|
39
|
-
* Publishes the legacy-launch freeze and enumerates until stable before returning
|
|
40
|
-
* ({@link LegacyRetirementStore.freeze}; idempotent, never undone), then reads the report.
|
|
41
|
-
* Throws `LegacyFreezeUnsettledError` when the enumeration did not settle.
|
|
42
|
-
*/
|
|
43
|
-
export declare function permissionCutoverFreeze(config: KernelConfig, opts: {
|
|
44
|
-
logger: KernelLogger;
|
|
45
|
-
by: string;
|
|
46
|
-
}): Promise<{
|
|
47
|
-
freeze: LegacyFreezeResult;
|
|
48
|
-
report: PermissionCutoverReport;
|
|
49
|
-
}>;
|
|
50
|
-
/**
|
|
51
|
-
* Runs the cloud snapshot driver ({@link CloudPermissionSnapshots.snapshotAll}) in a context with
|
|
52
|
-
* the CLI's Redis (the lifecycle leases). Throws `CutoverBarrierError` before the freeze, and the
|
|
53
|
-
* scope denial when this CLI's permission configuration is not the published one.
|
|
54
|
-
*/
|
|
55
|
-
export declare function permissionCutoverSnapshot(config: KernelConfig, opts: {
|
|
56
|
-
logger: KernelLogger;
|
|
57
|
-
signal?: AbortSignal;
|
|
58
|
-
leaseWaitMs?: number;
|
|
59
|
-
}): Promise<CloudSnapshotRun>;
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { Redis } from "ioredis";
|
|
2
|
-
import { CloudPermissionSnapshots, readCloudSnapshotProgress, } from "../../sandbox/cloud-permission-snapshot.js";
|
|
3
|
-
import { CloudPermissionSnapshotsModule } from "../../sandbox/cloud-permission-snapshot.module.js";
|
|
4
|
-
import { LegacyRetirementStore, } from "../../sandbox/legacy-retirement.js";
|
|
5
|
-
import { LegacyRetirementModule } from "../../sandbox/legacy-retirement.module.js";
|
|
6
|
-
import { PermissionAuthorityModule } from "../../sandbox/permission-authority.module.js";
|
|
7
|
-
import { PermissionConfigPublication } from "../../sandbox/permission-config-publication.js";
|
|
8
|
-
import { KERNEL_VERSION } from "../../version.js";
|
|
9
|
-
import { KernelDb } from "../database/kernel-db.js";
|
|
10
|
-
import { PRESENCE_DEFAULT_INTERVAL_MS, readLiveReplicas } from "../presence/replica-presence.js";
|
|
11
|
-
import { openKernelCli } from "./kernel-cli.module.js";
|
|
12
|
-
/** How long the report waits for Redis before it reports replicas as unknown. */
|
|
13
|
-
const PRESENCE_CONNECT_TIMEOUT_MS = 2_000;
|
|
14
|
-
/** The live replicas, or null when Redis does not answer (the report never fails on it). */
|
|
15
|
-
async function liveReplicas(url) {
|
|
16
|
-
const redis = new Redis(url, {
|
|
17
|
-
lazyConnect: true,
|
|
18
|
-
connectTimeout: PRESENCE_CONNECT_TIMEOUT_MS,
|
|
19
|
-
maxRetriesPerRequest: 0,
|
|
20
|
-
retryStrategy: () => null,
|
|
21
|
-
});
|
|
22
|
-
redis.on("error", () => { });
|
|
23
|
-
try {
|
|
24
|
-
await redis.connect();
|
|
25
|
-
const live = await readLiveReplicas(redis, PRESENCE_DEFAULT_INTERVAL_MS * 3);
|
|
26
|
-
return live.map((r) => ({
|
|
27
|
-
id: r.id,
|
|
28
|
-
version: r.version,
|
|
29
|
-
roles: r.roles,
|
|
30
|
-
startedAt: r.startedAt,
|
|
31
|
-
sameVersion: r.version === KERNEL_VERSION,
|
|
32
|
-
}));
|
|
33
|
-
}
|
|
34
|
-
catch {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
finally {
|
|
38
|
-
redis.disconnect();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
/** Opens the PostgreSQL-only context of the report and the freeze, runs `fn` and closes it. */
|
|
42
|
-
async function withPgContext(config, logger, fn) {
|
|
43
|
-
const app = await openKernelCli(config, {
|
|
44
|
-
logger,
|
|
45
|
-
modules: [LegacyRetirementModule, PermissionAuthorityModule],
|
|
46
|
-
redis: false,
|
|
47
|
-
});
|
|
48
|
-
try {
|
|
49
|
-
return await fn(app);
|
|
50
|
-
}
|
|
51
|
-
finally {
|
|
52
|
-
await app.close().catch((err) => {
|
|
53
|
-
logger.debug("permissions cutover: closing the CLI context failed", { err });
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
async function readReport(app, replicas) {
|
|
58
|
-
const configCurrent = await app
|
|
59
|
-
.get(PermissionConfigPublication)
|
|
60
|
-
.assertCurrent()
|
|
61
|
-
.then(() => true, () => false);
|
|
62
|
-
return {
|
|
63
|
-
kernelVersion: KERNEL_VERSION,
|
|
64
|
-
configCurrent,
|
|
65
|
-
replicas,
|
|
66
|
-
retirement: await app.get(LegacyRetirementStore).report(),
|
|
67
|
-
snapshot: await readCloudSnapshotProgress(app.get(KernelDb)),
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
/** The report (no writes). `presence: false` skips the replica presence read. */
|
|
71
|
-
export async function permissionCutoverReport(config, opts) {
|
|
72
|
-
const replicas = opts.presence === false ? null : await liveReplicas(config.redis.url);
|
|
73
|
-
return withPgContext(config, opts.logger, (app) => readReport(app, replicas));
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Publishes the legacy-launch freeze and enumerates until stable before returning
|
|
77
|
-
* ({@link LegacyRetirementStore.freeze}; idempotent, never undone), then reads the report.
|
|
78
|
-
* Throws `LegacyFreezeUnsettledError` when the enumeration did not settle.
|
|
79
|
-
*/
|
|
80
|
-
export async function permissionCutoverFreeze(config, opts) {
|
|
81
|
-
return withPgContext(config, opts.logger, async (app) => {
|
|
82
|
-
const freeze = await app.get(LegacyRetirementStore).freeze(opts.by);
|
|
83
|
-
return { freeze, report: await readReport(app, null) };
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Runs the cloud snapshot driver ({@link CloudPermissionSnapshots.snapshotAll}) in a context with
|
|
88
|
-
* the CLI's Redis (the lifecycle leases). Throws `CutoverBarrierError` before the freeze, and the
|
|
89
|
-
* scope denial when this CLI's permission configuration is not the published one.
|
|
90
|
-
*/
|
|
91
|
-
export async function permissionCutoverSnapshot(config, opts) {
|
|
92
|
-
const app = await openKernelCli(config, {
|
|
93
|
-
logger: opts.logger,
|
|
94
|
-
modules: [CloudPermissionSnapshotsModule],
|
|
95
|
-
});
|
|
96
|
-
try {
|
|
97
|
-
return await app.get(CloudPermissionSnapshots).snapshotAll({
|
|
98
|
-
...(opts.signal !== undefined && { signal: opts.signal }),
|
|
99
|
-
...(opts.leaseWaitMs !== undefined && { leaseWaitMs: opts.leaseWaitMs }),
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
finally {
|
|
103
|
-
await app.close().catch((err) => {
|
|
104
|
-
opts.logger.debug("permissions cutover: closing the CLI context failed", { err });
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
}
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import { KernelConfigService } from "../infra/config/kernel-config.service.js";
|
|
2
|
-
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
3
|
-
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
4
|
-
import { SandboxLeases } from "./leases.js";
|
|
5
|
-
import { LegacyRetirementStore } from "./legacy-retirement.js";
|
|
6
|
-
import { type AppliedLimits } from "./modes.js";
|
|
7
|
-
import { PermissionAuthorityLock } from "./permission-authority-lock.js";
|
|
8
|
-
import { PermissionCeilingWrites } from "./permission-ceiling-writes.js";
|
|
9
|
-
import { PermissionConfigPublication } from "./permission-config-publication.js";
|
|
10
|
-
import { PermissionFacts } from "./permission-facts.js";
|
|
11
|
-
import { DeviceProviders } from "./providers.js";
|
|
12
|
-
/**
|
|
13
|
-
* What a snapshot or reconciliation found: `unprobed` (no instance or file system yet: the next
|
|
14
|
-
* create applies the desired limits exactly), `bound` (the recorded applied limits are exactly
|
|
15
|
-
* the desired ones), `reconcile-required` (unknown, stale, wider or pending: no admission until a
|
|
16
|
-
* lifecycle action establishes them; `action` names it), `existing` (already snapshotted, kept),
|
|
17
|
-
* `skipped` (not a live cloud device).
|
|
18
|
-
*/
|
|
19
|
-
export type CloudSnapshotState = "unprobed" | "bound" | "reconcile-required" | "existing" | "skipped";
|
|
20
|
-
export interface CloudSnapshotOutcome {
|
|
21
|
-
state: CloudSnapshotState;
|
|
22
|
-
/** The lifecycle action that establishes the exact limits when they are required. */
|
|
23
|
-
action?: "reset-files";
|
|
24
|
-
/**
|
|
25
|
-
* `reconcile-required` on a live instance: the limits that would establish the device's
|
|
26
|
-
* authority, never wider than the instance is known to run in any dimension (B-12). A provider
|
|
27
|
-
* `update` that applies exactly these clears the marker (`SandboxService.reconcileLimits`).
|
|
28
|
-
*/
|
|
29
|
-
target?: AppliedLimits;
|
|
30
|
-
}
|
|
31
|
-
/** One device a {@link CloudPermissionSnapshots.snapshotAll} run snapshotted. */
|
|
32
|
-
export interface CloudSnapshotResult extends CloudSnapshotOutcome {
|
|
33
|
-
deviceId: string;
|
|
34
|
-
orgId: string;
|
|
35
|
-
}
|
|
36
|
-
/** What a {@link CloudPermissionSnapshots.snapshotAll} run did. */
|
|
37
|
-
export interface CloudSnapshotRun {
|
|
38
|
-
/** The devices this run snapshotted (empty on a rerun: nothing published). */
|
|
39
|
-
results: CloudSnapshotResult[];
|
|
40
|
-
/** Devices it could not snapshot (lease wait, a failed transaction); left for the next run. */
|
|
41
|
-
failed: {
|
|
42
|
-
deviceId: string;
|
|
43
|
-
orgId: string;
|
|
44
|
-
error: string;
|
|
45
|
-
}[];
|
|
46
|
-
/** Live cloud devices still without a snapshot after the run. */
|
|
47
|
-
pending: number;
|
|
48
|
-
/** Live cloud devices that keep the reconciliation marker (admission blocked until reset). */
|
|
49
|
-
reconcileRequired: string[];
|
|
50
|
-
}
|
|
51
|
-
/** Where the cloud snapshot stands (read by `capybara permissions cutover report`, too). */
|
|
52
|
-
export interface CloudSnapshotProgress {
|
|
53
|
-
/** Live cloud devices. */
|
|
54
|
-
cloudDevices: number;
|
|
55
|
-
/** Live cloud devices without a snapshot yet. */
|
|
56
|
-
pending: number;
|
|
57
|
-
/** Live cloud devices carrying `permission_reconcile_required`. */
|
|
58
|
-
reconcileRequired: string[];
|
|
59
|
-
}
|
|
60
|
-
/** The live (not deleted) devices of orgs that still exist, whatever their provider. */
|
|
61
|
-
type DeviceReader = Pick<KernelDb, "selectFrom">;
|
|
62
|
-
/** Reads the cloud snapshot's progress; no lock, no lease (a report). */
|
|
63
|
-
export declare function readCloudSnapshotProgress(db: DeviceReader): Promise<CloudSnapshotProgress>;
|
|
64
|
-
/**
|
|
65
|
-
* The B1 cloud per-device authority writer: replaces the old daily mode of a cloud device by an
|
|
66
|
-
* explicit owner Full ceiling and outer network, computed from the device's OLD effective
|
|
67
|
-
* authority (platform switch with its configured / stored precedence, the org's switch and cloud
|
|
68
|
-
* network, the device's narrowing switch, `egress: none`), narrowed by what its instance is known
|
|
69
|
-
* to run, never widened. Each device: the exclusive lifecycle lease outside the transaction, then
|
|
70
|
-
* the device authority write lock (platform -> org -> device order) before the row locks. Written
|
|
71
|
-
* once: a snapshot is never recomputed (a later false stays explicit after a widening). A device
|
|
72
|
-
* whose applied limits are not exactly the desired ones keeps a durable marker that blocks
|
|
73
|
-
* admission ({@link PermissionFacts.assertCloudReconciled}) until {@link reconcile} finds them
|
|
74
|
-
* established: after a file reset (the next create applies them exactly), or once a provider
|
|
75
|
-
* `update` under the lifecycle lease applied the reconcile target (B-12,
|
|
76
|
-
* `SandboxService.reconcileLimits`). Reconciling keeps any stricter boundary the instance is
|
|
77
|
-
* known to run by intersection: the owner ceiling and outer network are narrowed to it (a real
|
|
78
|
-
* narrowing, published like the snapshot's), never the instance widened to the authority.
|
|
79
|
-
*/
|
|
80
|
-
export declare class CloudPermissionSnapshots {
|
|
81
|
-
private readonly db;
|
|
82
|
-
readonly txHost: TransactionHost;
|
|
83
|
-
private readonly leases;
|
|
84
|
-
private readonly locks;
|
|
85
|
-
private readonly config;
|
|
86
|
-
private readonly facts;
|
|
87
|
-
private readonly publication;
|
|
88
|
-
private readonly ceilings;
|
|
89
|
-
private readonly retirement;
|
|
90
|
-
/** Whether a device's provider fixes limits at its file system (B-12 intersection). */
|
|
91
|
-
private readonly providers;
|
|
92
|
-
constructor(db: KernelDb, txHost: TransactionHost, leases: SandboxLeases, locks: PermissionAuthorityLock, config: Pick<KernelConfigService, "get" | "fieldSource">, facts: PermissionFacts, publication: Pick<PermissionConfigPublication, "assertCurrent">, ceilings: Pick<PermissionCeilingWrites, "publishLocked">, retirement: Pick<LegacyRetirementStore, "assertCutoverBarrier">,
|
|
93
|
-
/** Whether a device's provider fixes limits at its file system (B-12 intersection). */
|
|
94
|
-
providers: Pick<DeviceProviders, "forDevice">);
|
|
95
|
-
/**
|
|
96
|
-
* The production driver (B-10, `capybara permissions cutover snapshot`): snapshots every live
|
|
97
|
-
* cloud device that has none yet, one device at a time, each under its exclusive lifecycle
|
|
98
|
-
* lease and in its own transaction ({@link snapshot}).
|
|
99
|
-
*
|
|
100
|
-
* - **Barrier.** Refuses unless legacy admission is closed (the freeze published and enumerated,
|
|
101
|
-
* {@link LegacyRetirementStore.assertCutoverBarrier}) and this replica's permission
|
|
102
|
-
* configuration is the published one; each device re-checks the latter under the platform
|
|
103
|
-
* lock, and a failure there stops the run.
|
|
104
|
-
* - **Idempotent.** Only devices without a snapshot are visited, and {@link snapshot} keeps an
|
|
105
|
-
* existing one under the row lock, so a rerun takes no lease and publishes nothing.
|
|
106
|
-
* - **Resumable.** A device's snapshot, its narrowing publication (epoch, Full consent reset,
|
|
107
|
-
* exact revocation) and its marker commit together or not at all; a crash or a failed device
|
|
108
|
-
* leaves it without a snapshot for the next run, never half written or published twice.
|
|
109
|
-
* - Devices whose applied limits are not established keep `permission_reconcile_required`
|
|
110
|
-
* (listed in the answer) until a file reset reconciles them.
|
|
111
|
-
*/
|
|
112
|
-
snapshotAll(opts?: {
|
|
113
|
-
signal?: AbortSignal;
|
|
114
|
-
leaseWaitMs?: number;
|
|
115
|
-
}): Promise<CloudSnapshotRun>;
|
|
116
|
-
/** Snapshots one device under its exclusive lifecycle lease. */
|
|
117
|
-
snapshot(orgId: string, deviceId: string, signal?: AbortSignal): Promise<CloudSnapshotOutcome>;
|
|
118
|
-
/** Re-checks a device carrying the marker; clears it once its limits are established. */
|
|
119
|
-
reconcile(orgId: string, deviceId: string, signal?: AbortSignal): Promise<CloudSnapshotOutcome>;
|
|
120
|
-
/**
|
|
121
|
-
* {@link reconcile} for a caller that already holds the device's exclusive lifecycle lease
|
|
122
|
-
* (`SandboxService.reconcileLimits`): the same transaction, no lease taken here.
|
|
123
|
-
*/
|
|
124
|
-
reconcileHeld(orgId: string, deviceId: string): Promise<CloudSnapshotOutcome>;
|
|
125
|
-
/** {@link reconcile} by device id alone (after a file reset); nothing for an unknown device. */
|
|
126
|
-
reconcileDevice(deviceId: string): Promise<CloudSnapshotOutcome>;
|
|
127
|
-
private underLease;
|
|
128
|
-
private snapshotLocked;
|
|
129
|
-
/**
|
|
130
|
-
* A narrowed owner ceiling or outer network changes the device's authority: it goes through the
|
|
131
|
-
* device ceiling writer (epoch, Full consent, exact revocation) in the caller's transaction,
|
|
132
|
-
* under the device write lock already held.
|
|
133
|
-
*/
|
|
134
|
-
private publishNarrowing;
|
|
135
|
-
/**
|
|
136
|
-
* Re-checks a marked device under its write lock. With an instance whose applied limits are
|
|
137
|
-
* known (in force, even with a newer value pending a reset), the device's authority is first
|
|
138
|
-
* narrowed to them by intersection (B-12): Full only where the instance runs auto, the outer
|
|
139
|
-
* network cut to the applied network; a real narrowing is published. Then the marker clears
|
|
140
|
-
* when the applied limits are exactly the (narrowed) effective ones with nothing pending;
|
|
141
|
-
* otherwise it stays, with the target that would establish them: the effective limits, which
|
|
142
|
-
* are now never wider than the instance in any dimension, so applying them only narrows.
|
|
143
|
-
*/
|
|
144
|
-
private reconcileLocked;
|
|
145
|
-
private desired;
|
|
146
|
-
/**
|
|
147
|
-
* The device row under the device authority write lock, or undefined (not a live cloud one). The
|
|
148
|
-
* row is locked first (`FOR NO KEY UPDATE`: only non-key columns change), then the permission
|
|
149
|
-
* lock, the order the device writers take (`DevicesService.lockOwn`, the device project writes),
|
|
150
|
-
* then the row is read again under both.
|
|
151
|
-
*/
|
|
152
|
-
private lockedDevice;
|
|
153
|
-
/**
|
|
154
|
-
* The device's instance row when an instance or a file system exists (their limits are in
|
|
155
|
-
* force); null when neither does (the next create applies the desired limits exactly).
|
|
156
|
-
*/
|
|
157
|
-
private lockedInstance;
|
|
158
|
-
}
|
|
159
|
-
export {};
|