@capybara-hq/kernel 0.1.0-rc.146 → 0.1.0-rc.148
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/admin/extensions.controller.d.ts +0 -11
- package/dist/admin/extensions.controller.js +0 -28
- package/dist/admin/health.service.d.ts +25 -1
- package/dist/admin/health.service.js +50 -18
- package/dist/audit/full-access.d.ts +78 -0
- package/dist/audit/full-access.js +283 -0
- package/dist/automations/automations.service.d.ts +1 -0
- package/dist/automations/automations.service.js +3 -1
- package/dist/automations/calendar.js +3 -1
- package/dist/automations/grant-rules.d.ts +2 -1
- package/dist/automations/grant-rules.js +8 -1
- package/dist/automations/unattended.d.ts +13 -1
- package/dist/automations/unattended.js +13 -1
- package/dist/catalog/admin-catalog.controller.d.ts +8 -0
- package/dist/catalog/admin-catalog.controller.js +8 -2
- package/dist/catalog/admin-catalog.schemas.d.ts +10 -0
- package/dist/catalog/admin-catalog.schemas.js +8 -1
- package/dist/catalog/catalog-content.d.ts +6 -0
- package/dist/catalog/catalog-scope.service.d.ts +22 -2
- package/dist/catalog/catalog-scope.service.js +27 -3
- package/dist/catalog/catalog.service.js +19 -2
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/catalog/org-catalog.service.d.ts +8 -1
- package/dist/catalog/org-catalog.service.js +36 -3
- package/dist/catalog/platform-components.js +3 -2
- package/dist/catalog/platform-import-update.d.ts +2 -0
- package/dist/catalog/platform-import-update.js +8 -1
- package/dist/catalog/plugin-connectors.d.ts +11 -0
- package/dist/catalog/plugin-connectors.js +33 -0
- package/dist/catalog/plugin-import.d.ts +35 -15
- package/dist/catalog/plugin-import.js +110 -35
- package/dist/catalog/plugin-install.js +6 -0
- package/dist/catalog/provenance.d.ts +2 -0
- package/dist/catalog/provenance.js +5 -1
- package/dist/config/auto-approve.d.ts +16 -0
- package/dist/config/auto-approve.js +24 -0
- package/dist/config/capacity-presets.d.ts +243 -0
- package/dist/config/capacity-presets.js +195 -0
- package/dist/config/env.d.ts +2 -1
- package/dist/config/env.js +6 -1
- package/dist/config/load.js +15 -0
- package/dist/config/schema.d.ts +46 -9
- package/dist/config/schema.js +154 -30
- package/dist/ctx/net.d.ts +5 -1
- package/dist/ctx/net.js +62 -12
- package/dist/db/kernel-schema.d.ts +31 -0
- package/dist/db/migrator.js +0 -36
- package/dist/dial-in/routes.js +1 -1
- package/dist/erasure/org-batches.js +1 -6
- package/dist/erasure/org-catalog.js +6 -2
- package/dist/erasure/org-rules.js +1 -0
- package/dist/erasure/org-worker.js +0 -13
- package/dist/errors.d.ts +6 -0
- package/dist/errors.js +6 -0
- package/dist/extensions/admin-ops.d.ts +14 -1
- package/dist/extensions/admin-ops.js +30 -3
- package/dist/extensions/admin-view.d.ts +21 -1
- package/dist/extensions/admin-view.js +43 -0
- package/dist/extensions/bootstrap-packages.d.ts +5 -0
- package/dist/extensions/bootstrap-packages.js +1 -1
- package/dist/extensions/bootstrap-review.d.ts +251 -0
- package/dist/extensions/bootstrap-review.js +676 -0
- package/dist/extensions/bootstrap.d.ts +21 -1
- package/dist/extensions/bootstrap.js +72 -2
- package/dist/extensions/cli.d.ts +6 -0
- package/dist/extensions/cli.js +4 -0
- package/dist/extensions/enabled.d.ts +3 -0
- package/dist/extensions/extensions.module.js +9 -0
- package/dist/extensions/full-access-disclosure.d.ts +15 -0
- package/dist/extensions/full-access-disclosure.js +57 -0
- package/dist/extensions/grant-epoch.d.ts +5 -0
- package/dist/extensions/grant-epoch.js +9 -0
- package/dist/extensions/host.d.ts +71 -2
- package/dist/extensions/host.js +293 -27
- package/dist/extensions/installs.d.ts +18 -0
- package/dist/extensions/installs.js +28 -0
- package/dist/extensions/isolated/admission.d.ts +17 -2
- package/dist/extensions/isolated/admission.js +18 -8
- package/dist/extensions/isolated/authorization.d.ts +8 -2
- package/dist/extensions/isolated/authorization.js +11 -3
- package/dist/extensions/isolated/broker.d.ts +3 -0
- package/dist/extensions/isolated/broker.js +50 -14
- package/dist/extensions/isolated/configured-package.d.ts +5 -0
- package/dist/extensions/isolated/configured-package.js +2 -0
- package/dist/extensions/isolated/lanes.d.ts +44 -3
- package/dist/extensions/isolated/lanes.js +263 -80
- package/dist/extensions/isolated/metrics.d.ts +146 -0
- package/dist/extensions/isolated/metrics.js +304 -0
- package/dist/extensions/isolated/revision.d.ts +7 -1
- package/dist/extensions/isolated/revision.js +26 -5
- package/dist/extensions/isolated/rpc.d.ts +5 -0
- package/dist/extensions/isolated/rpc.js +7 -2
- package/dist/extensions/isolated/sandbox.d.ts +23 -0
- package/dist/extensions/isolated/sandbox.js +50 -0
- package/dist/extensions/isolated/status.d.ts +79 -0
- package/dist/extensions/isolated/status.js +216 -0
- package/dist/extensions/isolated/tier.d.ts +127 -2
- package/dist/extensions/isolated/tier.js +266 -7
- package/dist/extensions/isolated/usage.d.ts +134 -0
- package/dist/extensions/isolated/usage.js +322 -0
- package/dist/extensions/lifecycle.d.ts +42 -2
- package/dist/extensions/lifecycle.js +100 -4
- package/dist/extensions/org-config.js +11 -0
- package/dist/extensions/package.d.ts +14 -0
- package/dist/extensions/package.js +24 -3
- package/dist/extensions/permission-set.d.ts +12 -3
- package/dist/extensions/permission-set.js +5 -5
- package/dist/extensions/permission-view.d.ts +12 -5
- package/dist/extensions/permission-view.js +23 -2
- package/dist/extensions/permissions.controller.d.ts +35 -0
- package/dist/extensions/permissions.controller.js +98 -0
- package/dist/extensions/permissions.schemas.d.ts +288 -0
- package/dist/extensions/permissions.schemas.js +96 -0
- package/dist/extensions/permissions.service.d.ts +116 -0
- package/dist/extensions/permissions.service.js +428 -0
- package/dist/extensions/realm-retirement.d.ts +65 -0
- package/dist/extensions/realm-retirement.js +150 -0
- package/dist/extensions/revision-approvals.d.ts +58 -3
- package/dist/extensions/revision-approvals.js +135 -14
- package/dist/extensions/revision-review.d.ts +144 -0
- package/dist/extensions/revision-review.js +297 -0
- package/dist/extensions/revocation.js +3 -0
- package/dist/extensions/state.module.js +12 -0
- package/dist/git/run-end.d.ts +35 -7
- package/dist/git/run-end.js +87 -38
- package/dist/http/api.module.js +2 -0
- package/dist/identity/audit.d.ts +2 -1
- package/dist/identity/audit.js +4 -17
- package/dist/index.d.ts +6 -2
- package/dist/index.js +6 -2
- package/dist/infra/config/kernel-config.service.d.ts +6 -0
- package/dist/infra/config/kernel-config.service.js +21 -0
- package/dist/infra/outbox/registry.d.ts +13 -0
- package/dist/infra/outbox/registry.js +8 -0
- package/dist/lifecycle/kernel-lifecycle.d.ts +25 -1
- package/dist/lifecycle/kernel-lifecycle.js +73 -18
- package/dist/net/private-endpoint-preflight.d.ts +159 -0
- package/dist/net/private-endpoint-preflight.js +417 -0
- package/dist/net/private-endpoints.d.ts +68 -0
- package/dist/net/private-endpoints.js +164 -0
- package/dist/net/public-address.d.ts +14 -0
- package/dist/net/public-address.js +15 -1
- package/dist/net/safe-fetch.d.ts +2 -1
- package/dist/net/safe-fetch.js +10 -3
- package/dist/overrides.d.ts +4 -0
- package/dist/overrides.js +2 -0
- package/dist/packages/official-publisher.d.ts +26 -1
- package/dist/packages/official-publisher.js +48 -1
- package/dist/packages/provenance.d.ts +11 -0
- package/dist/packages/provenance.js +24 -0
- package/dist/platform/exclusions.js +4 -4
- package/dist/platform/ops/automations.ops.js +1 -1
- package/dist/platform/ops/catalog-admin.ops.js +25 -4
- package/dist/platform/ops/extension-permissions.ops.d.ts +11 -0
- package/dist/platform/ops/extension-permissions.ops.js +159 -0
- package/dist/platform/platform-ops.module.d.ts +2 -1
- package/dist/platform/platform-ops.module.js +2 -0
- package/dist/platform/route-schemas.js +2 -0
- package/dist/retention/purge-batch.js +10 -14
- package/dist/runtime/maintenance.d.ts +4 -2
- package/dist/runtime/maintenance.js +16 -3
- package/dist/runtime/run-finish.d.ts +3 -3
- package/dist/runtime/run-finish.js +7 -3
- package/dist/sandbox/permission-availability.d.ts +17 -2
- package/dist/sandbox/permission-availability.js +22 -1
- package/dist/sandbox/permission-facts.js +7 -1
- package/dist/tools/builtins/sandbox/common.js +2 -0
- package/dist/tools/pipeline.d.ts +2 -1
- package/dist/tools/pipeline.js +7 -2
- package/package.json +4 -3
- package/src/migrations/0238_extension_usage.sql +40 -0
- package/src/migrations/0239_extension_replica_isolation.sql +28 -0
|
@@ -10,6 +10,8 @@ export declare function readIsolatedGrant(db: KernelSchemaDb, grant: {
|
|
|
10
10
|
export interface IsolatedInvocationGrant {
|
|
11
11
|
signal: AbortSignal;
|
|
12
12
|
release(): void;
|
|
13
|
+
/** Whether this admission checked the grant against PostgreSQL (a cold grant, for metrics). */
|
|
14
|
+
checked?: boolean;
|
|
13
15
|
}
|
|
14
16
|
export interface IsolatedRevocation {
|
|
15
17
|
plugin?: string;
|
|
@@ -37,7 +39,10 @@ export interface GrantEpochView {
|
|
|
37
39
|
fresh(): string | undefined;
|
|
38
40
|
ensureFresh(): Promise<string | undefined>;
|
|
39
41
|
}
|
|
40
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* A grant checked at the current epoch is still rechecked after this long (backstop only): the
|
|
44
|
+
* default of `extensionHost.capacity.grantFullRevalidationMs`.
|
|
45
|
+
*/
|
|
41
46
|
export declare const GRANT_FULL_REVALIDATION_MS: number;
|
|
42
47
|
/**
|
|
43
48
|
* Replica-local cache of authority checked against deployment and org state.
|
|
@@ -51,12 +56,13 @@ export declare class IsolatedInvocationGrants {
|
|
|
51
56
|
private readonly epochs;
|
|
52
57
|
private readonly capacity;
|
|
53
58
|
private readonly now;
|
|
59
|
+
private readonly fullRevalidationMs;
|
|
54
60
|
private readonly instances;
|
|
55
61
|
private readonly rechecks;
|
|
56
62
|
/** Every cached grant across instances, least recently used first. */
|
|
57
63
|
private readonly lru;
|
|
58
64
|
private revalidating;
|
|
59
|
-
constructor(epochs: GrantEpochView, capacity: number, now?: () => number);
|
|
65
|
+
constructor(epochs: GrantEpochView, capacity: number, now?: () => number, fullRevalidationMs?: number);
|
|
60
66
|
issue({ plugin, orgId }: IsolatedRevocation, check: CachedGrant["check"], onRevoked: CachedGrant["onRevoked"] | undefined, instance: AbortSignal): Promise<IsolatedInvocationGrant | undefined>;
|
|
61
67
|
revoke({ plugin, orgId }: IsolatedRevocation): void;
|
|
62
68
|
/**
|
|
@@ -27,7 +27,10 @@ export async function readIsolatedGrant(db, grant) {
|
|
|
27
27
|
const snapshot = await query.executeTakeFirst();
|
|
28
28
|
return snapshotCovers(snapshot, permissions);
|
|
29
29
|
}
|
|
30
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* A grant checked at the current epoch is still rechecked after this long (backstop only): the
|
|
32
|
+
* default of `extensionHost.capacity.grantFullRevalidationMs`.
|
|
33
|
+
*/
|
|
31
34
|
export const GRANT_FULL_REVALIDATION_MS = 5 * 60_000;
|
|
32
35
|
const REVALIDATION_BATCH = 8;
|
|
33
36
|
const IN_FLIGHT_RECHECK_BATCH = 64;
|
|
@@ -43,15 +46,17 @@ export class IsolatedInvocationGrants {
|
|
|
43
46
|
epochs;
|
|
44
47
|
capacity;
|
|
45
48
|
now;
|
|
49
|
+
fullRevalidationMs;
|
|
46
50
|
instances = new Map();
|
|
47
51
|
rechecks = new Map();
|
|
48
52
|
/** Every cached grant across instances, least recently used first. */
|
|
49
53
|
lru = new Map();
|
|
50
54
|
revalidating;
|
|
51
|
-
constructor(epochs, capacity, now = () => performance.now()) {
|
|
55
|
+
constructor(epochs, capacity, now = () => performance.now(), fullRevalidationMs = GRANT_FULL_REVALIDATION_MS) {
|
|
52
56
|
this.epochs = epochs;
|
|
53
57
|
this.capacity = capacity;
|
|
54
58
|
this.now = now;
|
|
59
|
+
this.fullRevalidationMs = fullRevalidationMs;
|
|
55
60
|
}
|
|
56
61
|
async issue({ plugin, orgId }, check, onRevoked, instance) {
|
|
57
62
|
if (instance.aborted)
|
|
@@ -99,6 +104,7 @@ export class IsolatedInvocationGrants {
|
|
|
99
104
|
}
|
|
100
105
|
this.lru.set(entry, { orgs, orgId, entry });
|
|
101
106
|
entry.admitting += 1;
|
|
107
|
+
let checked = false;
|
|
102
108
|
try {
|
|
103
109
|
for (;;) {
|
|
104
110
|
const epoch = this.epochs.fresh() ?? (await this.epochs.ensureFresh());
|
|
@@ -106,6 +112,7 @@ export class IsolatedInvocationGrants {
|
|
|
106
112
|
return undefined;
|
|
107
113
|
if (this.valid(entry, epoch))
|
|
108
114
|
break;
|
|
115
|
+
checked = true;
|
|
109
116
|
if (!(await this.validate(orgs, orgId, entry)))
|
|
110
117
|
return undefined;
|
|
111
118
|
}
|
|
@@ -116,6 +123,7 @@ export class IsolatedInvocationGrants {
|
|
|
116
123
|
const call = new AbortController();
|
|
117
124
|
entry.calls += 1;
|
|
118
125
|
return {
|
|
126
|
+
checked,
|
|
119
127
|
signal: AbortSignal.any([entry.abort.signal, call.signal]),
|
|
120
128
|
release: () => {
|
|
121
129
|
if (call.signal.aborted)
|
|
@@ -201,7 +209,7 @@ export class IsolatedInvocationGrants {
|
|
|
201
209
|
valid(entry, epoch) {
|
|
202
210
|
return (entry.pending === undefined &&
|
|
203
211
|
entry.epoch === epoch &&
|
|
204
|
-
this.now() - entry.checkedAt <
|
|
212
|
+
this.now() - entry.checkedAt < this.fullRevalidationMs);
|
|
205
213
|
}
|
|
206
214
|
evictIdle() {
|
|
207
215
|
for (const { orgs, orgId, entry } of this.lru.values()) {
|
|
@@ -2,6 +2,7 @@ import type { KernelExtensionContext } from "../../ctx/create-ctx.js";
|
|
|
2
2
|
import { type ExtensionEffects } from "../../ctx/durable-effects.service.js";
|
|
3
3
|
import type { ExtensionEffectKeys } from "../../ctx/durable-keys.js";
|
|
4
4
|
import type { BrokerCall } from "./lanes.js";
|
|
5
|
+
import type { IsolationObserver } from "./metrics.js";
|
|
5
6
|
export interface BrokerOptions {
|
|
6
7
|
ctx: KernelExtensionContext;
|
|
7
8
|
plugin: string;
|
|
@@ -10,6 +11,8 @@ export interface BrokerOptions {
|
|
|
10
11
|
current: () => boolean;
|
|
11
12
|
network: (url: URL, orgId?: string) => Promise<boolean>;
|
|
12
13
|
redactLog?: (message: string, config: unknown) => string;
|
|
14
|
+
/** Metrics (streams, frames) and usage counters (ctx.net bytes) of the revision. */
|
|
15
|
+
observer?: IsolationObserver | undefined;
|
|
13
16
|
}
|
|
14
17
|
/** The only route from an isolated process to kernel services. Authority comes from the live call. */
|
|
15
18
|
export declare function createIsolatedBroker(options: BrokerOptions): BrokerCall;
|
|
@@ -44,9 +44,36 @@ const ACKNOWLEDGED_WRITES = new Set([
|
|
|
44
44
|
"triggers.emit",
|
|
45
45
|
"ui.invalidate",
|
|
46
46
|
]);
|
|
47
|
+
function callLabels(scope) {
|
|
48
|
+
return {
|
|
49
|
+
laneClass: scope.mode === "setupCheck" ? "control" : "standard",
|
|
50
|
+
mode: scope.mode,
|
|
51
|
+
role: scope.role ?? "none",
|
|
52
|
+
orgId: scope.orgId,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
47
55
|
class Handles {
|
|
56
|
+
observer;
|
|
48
57
|
owners = new WeakMap();
|
|
49
|
-
|
|
58
|
+
constructor(observer) {
|
|
59
|
+
this.observer = observer;
|
|
60
|
+
}
|
|
61
|
+
/** `stream`: the kind of byte stream the handle is, for the open streams gauge. */
|
|
62
|
+
add(scope, value, release, stream) {
|
|
63
|
+
let close = release;
|
|
64
|
+
if (stream && this.observer) {
|
|
65
|
+
const observer = this.observer;
|
|
66
|
+
const labels = callLabels(scope);
|
|
67
|
+
let open = true;
|
|
68
|
+
observer.streamOpened(labels, stream);
|
|
69
|
+
close = () => {
|
|
70
|
+
if (open) {
|
|
71
|
+
open = false;
|
|
72
|
+
observer.streamClosed(labels, stream);
|
|
73
|
+
}
|
|
74
|
+
return release();
|
|
75
|
+
};
|
|
76
|
+
}
|
|
50
77
|
let entries = this.owners.get(scope);
|
|
51
78
|
if (!entries) {
|
|
52
79
|
entries = new Map();
|
|
@@ -123,9 +150,10 @@ export function createIsolatedBroker(options) {
|
|
|
123
150
|
const { ctx } = options;
|
|
124
151
|
const loggedAt = new Map();
|
|
125
152
|
let modelRequests = 0;
|
|
126
|
-
const
|
|
153
|
+
const { observer } = options;
|
|
154
|
+
const readers = new Handles(observer);
|
|
127
155
|
const leases = new Handles();
|
|
128
|
-
const uploads = new Handles();
|
|
156
|
+
const uploads = new Handles(observer);
|
|
129
157
|
const own = (org, supplied) => {
|
|
130
158
|
if (org !== supplied)
|
|
131
159
|
return refuse();
|
|
@@ -141,9 +169,9 @@ export function createIsolatedBroker(options) {
|
|
|
141
169
|
return refuse();
|
|
142
170
|
return Reflect.apply(method, api, args);
|
|
143
171
|
};
|
|
144
|
-
const openReader = (scope, body) => {
|
|
172
|
+
const openReader = (scope, body, kind) => {
|
|
145
173
|
const reader = body.getReader();
|
|
146
|
-
return readers.add(scope, { reader, reading: false }, () => reader.cancel());
|
|
174
|
+
return readers.add(scope, { reader, reading: false }, () => reader.cancel(), kind);
|
|
147
175
|
};
|
|
148
176
|
const modelResult = async (run, scope) => {
|
|
149
177
|
if (modelRequests >= 2)
|
|
@@ -183,7 +211,7 @@ export function createIsolatedBroker(options) {
|
|
|
183
211
|
finally {
|
|
184
212
|
release();
|
|
185
213
|
}
|
|
186
|
-
}),
|
|
214
|
+
}, "models"),
|
|
187
215
|
};
|
|
188
216
|
}
|
|
189
217
|
catch (error) {
|
|
@@ -197,6 +225,8 @@ export function createIsolatedBroker(options) {
|
|
|
197
225
|
if (!(await options.network(url, org)) || !isCurrent(signal))
|
|
198
226
|
return refuse();
|
|
199
227
|
const init = requestInit.parse(initValue);
|
|
228
|
+
if (init.body !== undefined)
|
|
229
|
+
observer?.netBytesOut(org, Buffer.byteLength(init.body, "base64"));
|
|
200
230
|
return ctx.net.fetch(url.href, {
|
|
201
231
|
method: init.method,
|
|
202
232
|
headers: init.headers,
|
|
@@ -315,7 +345,7 @@ export function createIsolatedBroker(options) {
|
|
|
315
345
|
...record(opts ?? {}),
|
|
316
346
|
signal,
|
|
317
347
|
});
|
|
318
|
-
return found && { head: found.head, stream: openReader(scope, found.body) };
|
|
348
|
+
return found && { head: found.head, stream: openReader(scope, found.body, "storage") };
|
|
319
349
|
},
|
|
320
350
|
"storage.openPut": ([supplied, key, opts], org, scope, signal) => {
|
|
321
351
|
own(org, supplied);
|
|
@@ -333,7 +363,7 @@ export function createIsolatedBroker(options) {
|
|
|
333
363
|
signal,
|
|
334
364
|
});
|
|
335
365
|
void result.catch(() => { });
|
|
336
|
-
return uploads.add(scope, { writer, result, writing: false }, () => writer.abort());
|
|
366
|
+
return uploads.add(scope, { writer, result, writing: false }, () => writer.abort(), "upload");
|
|
337
367
|
},
|
|
338
368
|
"storage.write": async ([id, chunk], _org, scope) => {
|
|
339
369
|
const upload = uploads.get(scope, id);
|
|
@@ -343,6 +373,7 @@ export function createIsolatedBroker(options) {
|
|
|
343
373
|
upload.writing = true;
|
|
344
374
|
try {
|
|
345
375
|
await upload.writer.write(chunk);
|
|
376
|
+
observer?.streamFrame(callLabels(scope), "upload");
|
|
346
377
|
}
|
|
347
378
|
finally {
|
|
348
379
|
upload.writing = false;
|
|
@@ -369,7 +400,7 @@ export function createIsolatedBroker(options) {
|
|
|
369
400
|
"lock.renew": ([id], _org, scope) => leases.get(scope, id).renew(),
|
|
370
401
|
"lock.release": ([id], _org, scope) => leases.close(scope, id),
|
|
371
402
|
};
|
|
372
|
-
const read = async ([id],
|
|
403
|
+
const read = (kind) => async ([id], org, scope) => {
|
|
373
404
|
const stream = readers.get(scope, id);
|
|
374
405
|
if (stream.reading)
|
|
375
406
|
return refuse();
|
|
@@ -385,16 +416,21 @@ export function createIsolatedBroker(options) {
|
|
|
385
416
|
}
|
|
386
417
|
const chunk = stream.remainder.subarray(0, CHUNK_BYTES);
|
|
387
418
|
stream.remainder =
|
|
388
|
-
stream.remainder.length > CHUNK_BYTES
|
|
419
|
+
stream.remainder.length > CHUNK_BYTES
|
|
420
|
+
? stream.remainder.subarray(CHUNK_BYTES)
|
|
421
|
+
: undefined;
|
|
422
|
+
observer?.streamFrame(callLabels(scope), kind);
|
|
423
|
+
if (kind === "net")
|
|
424
|
+
observer?.netBytesIn(org, chunk.length);
|
|
389
425
|
return new RpcByteChunk({ done: false }, chunk);
|
|
390
426
|
}
|
|
391
427
|
finally {
|
|
392
428
|
stream.reading = false;
|
|
393
429
|
}
|
|
394
430
|
};
|
|
395
|
-
dispatch["net.read"] = read;
|
|
396
|
-
dispatch["storage.read"] = read;
|
|
397
|
-
dispatch["models.read"] = read;
|
|
431
|
+
dispatch["net.read"] = read("net");
|
|
432
|
+
dispatch["storage.read"] = read("storage");
|
|
433
|
+
dispatch["models.read"] = read("models");
|
|
398
434
|
dispatch["models.close"] = ([id], _org, scope) => readers.close(scope, id);
|
|
399
435
|
dispatch["net.close"] = ([id], _org, scope) => readers.close(scope, id);
|
|
400
436
|
dispatch["storage.close"] = ([id], _org, scope) => readers.close(scope, id);
|
|
@@ -459,7 +495,7 @@ export function createIsolatedBroker(options) {
|
|
|
459
495
|
status: response.status,
|
|
460
496
|
statusText: response.statusText,
|
|
461
497
|
headers: [...response.headers],
|
|
462
|
-
...(response.body && { stream: openReader(scope, response.body) }),
|
|
498
|
+
...(response.body && { stream: openReader(scope, response.body, "net") }),
|
|
463
499
|
};
|
|
464
500
|
}
|
|
465
501
|
// The scope was checked before dispatch. Reporting a completed write as refused can cause
|
|
@@ -3,6 +3,11 @@ export interface ConfiguredExtensionPackage {
|
|
|
3
3
|
readonly archiveUrl: string;
|
|
4
4
|
readonly review: ExtensionPackage;
|
|
5
5
|
readonly maxBytes: number;
|
|
6
|
+
/**
|
|
7
|
+
* The lowercase hex sha512 of the captured archive: the digest its revision grants are keyed by
|
|
8
|
+
* (the bootstrap review and start gate resolve them, plan task 1.3c).
|
|
9
|
+
*/
|
|
10
|
+
readonly sha512: string;
|
|
6
11
|
/** A copy of the captured archive. Writes to the copy cannot change the reviewed package. */
|
|
7
12
|
bytes(): Uint8Array;
|
|
8
13
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
1
2
|
import { constants } from "node:fs";
|
|
2
3
|
import { open } from "node:fs/promises";
|
|
3
4
|
import { isAbsolute, resolve } from "node:path";
|
|
@@ -60,6 +61,7 @@ export async function readConfiguredExtensionPackage(specifier, resolveFrom, max
|
|
|
60
61
|
archiveUrl: pathToFileURL(path).href,
|
|
61
62
|
review,
|
|
62
63
|
maxBytes,
|
|
64
|
+
sha512: createHash("sha512").update(bytes).digest("hex"),
|
|
63
65
|
bytes: () => Uint8Array.from(bytes),
|
|
64
66
|
});
|
|
65
67
|
}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import type { StaticExtensionManifest } from "@capybara-hq/plugin-sdk";
|
|
2
|
-
import { type
|
|
2
|
+
import { type IsolatedCapacity } from "../../config/capacity-presets.js";
|
|
3
|
+
import type { IsolationObserver, RejectionReason } from "./metrics.js";
|
|
4
|
+
import { IsolatedRpcError, type RpcBudget } from "./rpc.js";
|
|
3
5
|
import { type ExtensionSandboxOptions } from "./sandbox.js";
|
|
4
|
-
|
|
6
|
+
/**
|
|
7
|
+
* The limits below the `extensionHost.capacity` config (task 1.2c) are read from
|
|
8
|
+
* {@link IsolatedExtensionQuota.limits} at each admission and lane start; the `standard` preset is
|
|
9
|
+
* the set of constants this file had before.
|
|
10
|
+
*/
|
|
5
11
|
export type ServingRole = "api" | "worker" | "gateway";
|
|
6
12
|
type InvocationMode = "org" | "deployment" | "setupCheck";
|
|
7
13
|
export interface Invocation {
|
|
@@ -12,6 +18,10 @@ export interface Invocation {
|
|
|
12
18
|
signal?: AbortSignal | undefined;
|
|
13
19
|
toolCall?: unknown;
|
|
14
20
|
cleanup?: Set<() => Promise<unknown> | undefined>;
|
|
21
|
+
/** `performance.now()` when the kernel took the call, for the call overhead metric. */
|
|
22
|
+
receivedAt?: number;
|
|
23
|
+
/** Whether the grant was checked against PostgreSQL for this call (a cold grant). */
|
|
24
|
+
grantChecked?: boolean;
|
|
15
25
|
}
|
|
16
26
|
export type BrokerCall = (method: string, args: unknown[], invocation: Invocation, signal: AbortSignal) => Promise<unknown>;
|
|
17
27
|
export interface IsolatedLaneOptions {
|
|
@@ -30,8 +40,14 @@ export interface IsolatedLaneOptions {
|
|
|
30
40
|
broker: BrokerCall;
|
|
31
41
|
quota: IsolatedExtensionQuota;
|
|
32
42
|
revision: string;
|
|
33
|
-
|
|
43
|
+
/**
|
|
44
|
+
* A lane failed: its sandbox exited unexpectedly (`exited`) or its start failed (`start_failed`).
|
|
45
|
+
* The revision backs off for `retryAfterMs`. A guard capacity refusal is not a failure.
|
|
46
|
+
*/
|
|
47
|
+
onCrash?: ((retryAfterMs: number, cause: "exited" | "start_failed") => void) | undefined;
|
|
34
48
|
cleanupFault: () => void;
|
|
49
|
+
/** Metrics and usage counters of this revision; absent in tests that do not measure. */
|
|
50
|
+
observer?: IsolationObserver | undefined;
|
|
35
51
|
}
|
|
36
52
|
type ProcessKind = "serving" | "control";
|
|
37
53
|
interface ProcessIngress {
|
|
@@ -48,12 +64,25 @@ interface PendingRemoval {
|
|
|
48
64
|
timer?: ReturnType<typeof setTimeout> | undefined;
|
|
49
65
|
running: boolean;
|
|
50
66
|
}
|
|
67
|
+
/** An `overloaded` refusal before the call reached a lane, with its reason for the metrics. */
|
|
68
|
+
export declare class IsolatedRejection extends IsolatedRpcError {
|
|
69
|
+
readonly reason: RejectionReason;
|
|
70
|
+
constructor(reason: RejectionReason);
|
|
71
|
+
}
|
|
51
72
|
export declare class IsolatedExtensionQuota {
|
|
73
|
+
readonly limits: () => IsolatedCapacity;
|
|
52
74
|
private readonly processes;
|
|
53
75
|
private calls;
|
|
54
76
|
private readonly services;
|
|
55
77
|
private readonly preflights;
|
|
56
78
|
private readonly starts;
|
|
79
|
+
/**
|
|
80
|
+
* `limits` is read at every admission and lane start (the hot capacity fields apply at once).
|
|
81
|
+
* Without it the quota uses the `standard` preset.
|
|
82
|
+
*/
|
|
83
|
+
constructor(limits?: () => IsolatedCapacity);
|
|
84
|
+
private processLimit;
|
|
85
|
+
private startRate;
|
|
57
86
|
private readonly retryTimers;
|
|
58
87
|
private readonly available;
|
|
59
88
|
private readonly removals;
|
|
@@ -65,6 +94,8 @@ export declare class IsolatedExtensionQuota {
|
|
|
65
94
|
process(kind: ProcessKind): ProcessLease | undefined;
|
|
66
95
|
call(): () => void;
|
|
67
96
|
admitPreflight(orgId?: string, role?: ServingRole, setupCheck?: boolean): () => void;
|
|
97
|
+
/** Concurrent broker requests one lane may hold: each serving call can hold one. */
|
|
98
|
+
servicesPerLane(kind: ProcessKind, limits?: IsolatedCapacity): number;
|
|
68
99
|
service(kind: ProcessKind): () => void;
|
|
69
100
|
inBackoff(revision: string): boolean;
|
|
70
101
|
crashed(revision: string): number;
|
|
@@ -83,7 +114,17 @@ export declare class IsolatedLanes {
|
|
|
83
114
|
private draining?;
|
|
84
115
|
private control?;
|
|
85
116
|
private expected;
|
|
117
|
+
/** Lane keys whose serving lane exited unexpectedly: the next start there replaces a crash. */
|
|
118
|
+
private readonly crashedKeys;
|
|
86
119
|
constructor(options: IsolatedLaneOptions);
|
|
120
|
+
private get limits();
|
|
121
|
+
/** The serving and control lanes as the gauges see them. */
|
|
122
|
+
private snapshot;
|
|
123
|
+
private servingLabels;
|
|
124
|
+
private reject;
|
|
125
|
+
/** Books the busy time of a lane whose calls just ended, or of every busy lane at a flush. */
|
|
126
|
+
private bookBusy;
|
|
127
|
+
private checkpointBusy;
|
|
87
128
|
register(): Promise<unknown>;
|
|
88
129
|
invoke(callback: string, args: readonly unknown[], scope: Invocation): Promise<unknown>;
|
|
89
130
|
private admit;
|