@capybara-hq/kernel 0.1.0-rc.49 → 0.1.0-rc.50

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 (128) hide show
  1. package/dist/admin/admin.schemas.d.ts +0 -6
  2. package/dist/background/launch.d.ts +7 -61
  3. package/dist/background/launch.js +8 -133
  4. package/dist/background/poll.job.d.ts +19 -23
  5. package/dist/background/poll.job.js +30 -66
  6. package/dist/background/render.d.ts +9 -0
  7. package/dist/background/render.js +19 -0
  8. package/dist/background/session.d.ts +3 -66
  9. package/dist/background/session.js +3 -114
  10. package/dist/background/stop.d.ts +26 -33
  11. package/dist/background/stop.js +59 -90
  12. package/dist/background/store.d.ts +26 -60
  13. package/dist/background/store.js +23 -108
  14. package/dist/background/tasks.service.d.ts +9 -29
  15. package/dist/background/tasks.service.js +18 -115
  16. package/dist/catalog/marketplaces.service.d.ts +1 -1
  17. package/dist/channels/cards.d.ts +3 -0
  18. package/dist/channels/cards.js +29 -2
  19. package/dist/channels/phrases.d.ts +35 -0
  20. package/dist/channels/phrases.js +32 -0
  21. package/dist/config/load.d.ts +3 -10
  22. package/dist/config/load.js +26 -21
  23. package/dist/config/schema.js +3 -3
  24. package/dist/conversations/events.d.ts +45 -2
  25. package/dist/conversations/events.js +44 -4
  26. package/dist/db/kernel-schema.d.ts +9 -4
  27. package/dist/devices/devices.service.js +1 -1
  28. package/dist/devices/errors.d.ts +5 -0
  29. package/dist/devices/errors.js +5 -0
  30. package/dist/devices/project-rules.d.ts +2 -2
  31. package/dist/errors.d.ts +9 -11
  32. package/dist/errors.js +9 -11
  33. package/dist/identity/settings.d.ts +4 -17
  34. package/dist/identity/settings.js +9 -32
  35. package/dist/infra/config/kernel-config.service.js +2 -9
  36. package/dist/infra/outbox/registry.d.ts +13 -0
  37. package/dist/infra/outbox/registry.js +8 -0
  38. package/dist/local-devices/device-auth.controller.d.ts +1 -1
  39. package/dist/local-devices/device-auth.controller.js +1 -1
  40. package/dist/local-devices/device-auth.d.ts +4 -3
  41. package/dist/local-devices/device-auth.js +1 -1
  42. package/dist/local-devices/device-policy.service.d.ts +6 -6
  43. package/dist/local-devices/device-routes.d.ts +4 -2
  44. package/dist/local-devices/device-routes.js +7 -6
  45. package/dist/local-devices/instance-bindings.d.ts +4 -4
  46. package/dist/local-devices/instance-bindings.js +2 -2
  47. package/dist/local-devices/local-device-gateway.d.ts +12 -12
  48. package/dist/local-devices/local-device-gateway.js +94 -129
  49. package/dist/local-devices/local-device-provider.d.ts +19 -87
  50. package/dist/local-devices/local-device-provider.js +43 -158
  51. package/dist/local-devices/local-devices.module.d.ts +4 -5
  52. package/dist/local-devices/local-devices.module.js +6 -9
  53. package/dist/local-devices/machines.d.ts +6 -6
  54. package/dist/local-devices/machines.js +4 -4
  55. package/dist/local-devices/owner-report.d.ts +3 -3
  56. package/dist/local-devices/owner-report.js +4 -4
  57. package/dist/local-devices/owner-reports.js +2 -2
  58. package/dist/local-devices/policy-summary.js +2 -2
  59. package/dist/local-devices/relay.d.ts +12 -25
  60. package/dist/local-devices/relay.js +17 -31
  61. package/dist/orgs/settings.controller.d.ts +1 -4
  62. package/dist/orgs/settings.controller.js +3 -3
  63. package/dist/orgs/settings.service.d.ts +7 -21
  64. package/dist/orgs/settings.service.js +16 -40
  65. package/dist/overrides.d.ts +3 -3
  66. package/dist/platform/ops/admin.ops.js +6 -8
  67. package/dist/platform/ops/org-settings.ops.js +4 -4
  68. package/dist/platform/ops/orgs.ops.js +0 -1
  69. package/dist/runtime/maintenance.d.ts +1 -1
  70. package/dist/runtime/maintenance.js +7 -1
  71. package/dist/runtime/run-steps.js +2 -2
  72. package/dist/sandbox/held-operations.d.ts +7 -0
  73. package/dist/sandbox/held-operations.js +25 -1
  74. package/dist/sandbox/leases.d.ts +6 -3
  75. package/dist/sandbox/leases.js +16 -10
  76. package/dist/sandbox/legacy-retirement.d.ts +0 -19
  77. package/dist/sandbox/legacy-retirement.js +6 -37
  78. package/dist/sandbox/managed-device-context.d.ts +12 -0
  79. package/dist/sandbox/managed-device-context.js +49 -1
  80. package/dist/sandbox/modes.d.ts +9 -8
  81. package/dist/sandbox/modes.js +4 -15
  82. package/dist/sandbox/operation-authority-types.d.ts +18 -1
  83. package/dist/sandbox/operation-authority-types.js +20 -1
  84. package/dist/sandbox/operation-authority.d.ts +14 -0
  85. package/dist/sandbox/operation-authority.js +120 -18
  86. package/dist/sandbox/operation-intents.d.ts +43 -0
  87. package/dist/sandbox/operation-intents.js +107 -4
  88. package/dist/sandbox/operation-reconcile.job.d.ts +12 -1
  89. package/dist/sandbox/operation-reconcile.job.js +53 -6
  90. package/dist/sandbox/permission-call-grants.d.ts +4 -0
  91. package/dist/sandbox/permission-call-grants.js +32 -3
  92. package/dist/sandbox/permission-call-types.d.ts +27 -2
  93. package/dist/sandbox/permission-ceiling-writes.js +2 -1
  94. package/dist/sandbox/permission-context-types.d.ts +2 -2
  95. package/dist/sandbox/permission-context-types.js +2 -2
  96. package/dist/sandbox/permission-facts.js +10 -2
  97. package/dist/sandbox/platform-full-access.d.ts +8 -26
  98. package/dist/sandbox/platform-full-access.js +8 -20
  99. package/dist/sandbox/review/classifier.d.ts +2 -2
  100. package/dist/sandbox/review/classifier.js +18 -5
  101. package/dist/sandbox/review/permission-candidate.d.ts +59 -3
  102. package/dist/sandbox/review/permission-candidate.js +192 -25
  103. package/dist/sandbox/review/review.service.d.ts +18 -0
  104. package/dist/sandbox/review/review.service.js +158 -12
  105. package/dist/sandbox/sandbox.service.d.ts +71 -47
  106. package/dist/sandbox/sandbox.service.js +234 -133
  107. package/dist/tools/approvals.service.d.ts +6 -1
  108. package/dist/tools/approvals.service.js +10 -0
  109. package/dist/tools/builtins/builtin-tools.d.ts +1 -4
  110. package/dist/tools/builtins/builtin-tools.js +13 -18
  111. package/dist/tools/builtins/sandbox/bash.d.ts +16 -3
  112. package/dist/tools/builtins/sandbox/bash.js +92 -270
  113. package/dist/tools/builtins/sandbox/common.d.ts +15 -9
  114. package/dist/tools/builtins/sandbox/common.js +55 -19
  115. package/dist/tools/builtins/sandbox/device-owner.d.ts +13 -0
  116. package/dist/tools/builtins/sandbox/device-owner.js +14 -0
  117. package/dist/tools/builtins/sandbox/task-list.js +2 -2
  118. package/dist/tools/builtins/sandbox/task-output.d.ts +14 -57
  119. package/dist/tools/builtins/sandbox/task-output.js +88 -210
  120. package/dist/tools/builtins/sandbox/task-stop.d.ts +2 -2
  121. package/dist/tools/builtins/sandbox/task-stop.js +15 -26
  122. package/dist/tools/pipeline.d.ts +31 -2
  123. package/dist/tools/pipeline.js +273 -43
  124. package/dist/tools/registry.d.ts +7 -0
  125. package/package.json +4 -4
  126. package/src/migrations/0162_permission_call_escalation.sql +9 -0
  127. package/dist/background/status.d.ts +0 -35
  128. package/dist/background/status.js +0 -57
@@ -8,8 +8,9 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
8
  return function (target, key) { decorator(target, key, paramIndex); }
9
9
  };
10
10
  import { randomUUID } from "node:crypto";
11
- import { DEVICE_PROTOCOL_VERSION, DeviceProtocolError, FileSystemGoneError, parseDeviceFrame, parseDeviceFrameV3, parseOperationResultV3, parseOpResult, SandboxGoneError, SandboxOperationOutcomeUnknownError, SandboxPermissionUnsupportedError, SandboxScopeDeniedError, STAGED_DEVICE_PROTOCOL_VERSION, ToolError, } from "@capybara-hq/plugin-sdk";
11
+ import { DeviceProtocolError, FileSystemGoneError, parseDeviceFrame, parseLegacyDeviceFrame, parseOperationResult, parseOpResult, SandboxGoneError, SandboxOperationOutcomeUnknownError, SandboxPermissionUnsupportedError, SandboxScopeDeniedError, ToolError, } from "@capybara-hq/plugin-sdk";
12
12
  import { Inject, Injectable } from "@nestjs/common";
13
+ import { machineRevoked } from "../devices/errors.js";
13
14
  import { ApiError } from "../errors.js";
14
15
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
15
16
  import { LockService } from "../infra/lock/lock.service.js";
@@ -20,11 +21,7 @@ import { deviceLeaseKey, deviceReqKey, deviceReqTopic, deviceResKey, deviceResTo
20
21
  import { DeviceTargets } from "./targets.js";
21
22
  /** The device's connected machine is not connected (no replica holds its lease). */
22
23
  export const deviceOffline = () => new ApiError("device.offline", "The machine of this local device is offline. Start capybara-device on that machine, or pick another device.");
23
- /**
24
- * The device's machine was disconnected (revoked, signed out): 403 `device.forbidden`
25
- * with `details: [{ reason: "machine_revoked" }]`, so the tools tell the model what to ask for.
26
- */
27
- export const machineRevoked = () => new ApiError("device.forbidden", "The machine of this local device was disconnected. Run capybara-device logout, then capybara-device login on it, or pick another device.", [{ reason: "machine_revoked" }]);
24
+ export { machineRevoked } from "../devices/errors.js";
28
25
  /** The text a machine's `policy` refusal reaches the model with. */
29
26
  export const POLICY_REFUSAL_PREFIX = "Refused by the machine's local policy: ";
30
27
  /** The text a machine's `error` result reaches the model with (ruling R28). */
@@ -61,11 +58,6 @@ const connectionFenced = (op) => op === "backgroundReadOutput";
61
58
  * before the frame goes out; a frame for another machine is dropped).
62
59
  */
63
60
  export const STOP_MACHINE = "machineId";
64
- /**
65
- * Whether the deployment speaks the staged device protocol: the single gate is the SDK's protocol
66
- * constant (flipped to 3 at the paired activation). Until then the active wire stays protocol 2.
67
- */
68
- export const stagedDeviceProtocolActive = () => DEVICE_PROTOCOL_VERSION === STAGED_DEVICE_PROTOCOL_VERSION;
69
61
  /** The longest one lease check of a waiting caller may take before it counts as "unknown". */
70
62
  export const LEASE_CHECK_TIMEOUT_MS = 2000;
71
63
  /** How often a waiting caller checks that a replica still holds the machine's connection. */
@@ -134,9 +126,9 @@ const errMsg = (e) => (e instanceof Error ? e.message : String(e));
134
126
  * list and forwards the frames to the machine.
135
127
  *
136
128
  * **The holder's half of the wire** (Task 6 follows it): items on the list are `KernelReq` or
137
- * `KernelCancel` frames as JSON text, to be parsed with `parseDeviceFrame(item, "kernel")`; the
129
+ * `KernelCancel` frames as JSON text, to be parsed with `parseLegacyDeviceFrame(item, "kernel")`; the
138
130
  * nudge's payload is `{ id }`. For each `res` frame the machine sends, the holder writes the frame
139
- * (the JSON text as validated by `parseDeviceFrame(…, "device")`) under
131
+ * (the JSON text as validated by `parseLegacyDeviceFrame(…, "device")`) under
140
132
  * `capk:device-res:<requestId>` with a TTL and publishes the same frame object on
141
133
  * `device.res.<requestId>`.
142
134
  *
@@ -169,20 +161,11 @@ let LocalDeviceRelay = class LocalDeviceRelay {
169
161
  return (await this.locks.holderOf(deviceLeaseKey(deviceId))) !== null;
170
162
  }
171
163
  /**
172
- * Whether the protocol gate is open ({@link stagedDeviceProtocolActive}; a test seam opens it
173
- * for one relay instance, the deployment never does).
174
- */
175
- stagedProtocolActive = stagedDeviceProtocolActive;
176
- /**
177
- * The negotiated transport of the device's connection when the platform's own controls (policy
178
- * ops) must speak protocol 3 to it, else null (protocol 2). With the gate closed every
179
- * connection is protocol 2: nothing is looked up (no lease or transport read per op). With it
180
- * open every connection is staged, so this is {@link connection} (a missing or unready one
181
- * throws its typed error).
164
+ * The negotiated transport of the device's connection for the platform's own controls (policy
165
+ * ops): every connection speaks protocol 3, so this is {@link connection} (a missing or unready
166
+ * one throws its typed error).
182
167
  */
183
168
  async stagedTransport(deviceId) {
184
- if (!this.stagedProtocolActive())
185
- return null;
186
169
  return this.connection(deviceId);
187
170
  }
188
171
  /**
@@ -227,9 +210,12 @@ let LocalDeviceRelay = class LocalDeviceRelay {
227
210
  async call(deviceId, op, args, opts) {
228
211
  return this.callWithCodec(deviceId, op, args, opts, false);
229
212
  }
230
- /** Development staging: the active gateway continues rejecting protocol 3 until coordinated cutover. */
213
+ /**
214
+ * Runs a protocol 3 operation on the device's machine over its current staged connection and
215
+ * returns its validated result; the request is checked against the protocol 3 codec first.
216
+ */
231
217
  async callV3(deviceId, op, args, opts) {
232
- parseDeviceFrameV3(JSON.stringify({ type: "req", id: "validation", op, args, deadlineMs: opts.deadlineMs }), "kernel");
218
+ parseDeviceFrame(JSON.stringify({ type: "req", id: "validation", op, args, deadlineMs: opts.deadlineMs }), "kernel");
233
219
  return this.callWithCodec(deviceId, op, args, opts, true);
234
220
  }
235
221
  async callWithCodec(deviceId, op, args, opts, staged) {
@@ -253,7 +239,7 @@ let LocalDeviceRelay = class LocalDeviceRelay {
253
239
  const listTtlMs = graceMs + deadlineMs + LIST_TTL_MARGIN_MS;
254
240
  const frame = { type: "req", id, op, args, deadlineMs };
255
241
  if (connection)
256
- parseDeviceFrameV3(JSON.stringify(frame), "kernel", connection.maxFrameBytes);
242
+ parseDeviceFrame(JSON.stringify(frame), "kernel", connection.maxFrameBytes);
257
243
  const reqJson = JSON.stringify({ ...frame, ...connection });
258
244
  let settle;
259
245
  const outcome = new Promise((resolve) => {
@@ -350,7 +336,7 @@ let LocalDeviceRelay = class LocalDeviceRelay {
350
336
  if (connection && r.notSent)
351
337
  throw notSentError(op);
352
338
  return staged && r.res.ok
353
- ? parseOperationResultV3(op, r.res.result, op === "backgroundReadOutput"
339
+ ? parseOperationResult(op, r.res.result, op === "backgroundReadOutput"
354
340
  ? args
355
341
  : op === "bindInstance"
356
342
  ? args
@@ -486,8 +472,8 @@ let LocalDeviceRelay = class LocalDeviceRelay {
486
472
  wire = JSON.stringify(frame);
487
473
  }
488
474
  const f = connection
489
- ? parseDeviceFrameV3(wire, "device", cap)
490
- : parseDeviceFrame(wire, "device");
475
+ ? parseDeviceFrame(wire, "device", cap)
476
+ : parseLegacyDeviceFrame(wire, "device");
491
477
  if (f.type !== "res" || f.id !== id) {
492
478
  return { error: new DeviceProtocolError("the connected machine sent an unexpected frame") };
493
479
  }
@@ -7,10 +7,7 @@ import { type OrgEffectiveNetwork, type OrgSandboxLimits, type OrgSettingsDeploy
7
7
  * 以及只读的 `sandboxLimits`(组织实际生效的沙箱 cpu / 内存与来源,超级管理员在部署设置里覆盖,C19)。
8
8
  */
9
9
  type SettingsResponse = {
10
- /**
11
- * `scheduledTasks.forbiddenToolsUnreadable: true` when the stored list cannot be read; `autoMode`
12
- * mirrors `fullAccess`.
13
- */
10
+ /** `scheduledTasks.forbiddenToolsUnreadable: true` when the stored list cannot be read. */
14
11
  settings: OrgSettingsView;
15
12
  deployment: OrgSettingsDeployment;
16
13
  /** The org's effective sandbox-mode network (org egress ceiling spec §D4). */
@@ -12,7 +12,7 @@ import { CurrentPrincipal, patTokenId, requireUser, } from "../identity/principa
12
12
  import { createZodDto } from "../infra/validation/create-zod-dto.js";
13
13
  import { ZBody } from "../infra/validation/zod-params.js";
14
14
  import { CurrentOrg, OrgAction } from "./org.guard.js";
15
- import { OrgSettingsPatchSchema, OrgSettingsService, orgSettingsView, } from "./settings.service.js";
15
+ import { OrgSettingsPatchSchema, OrgSettingsService, } from "./settings.service.js";
16
16
  class OrgSettingsPatchBody extends createZodDto(OrgSettingsPatchSchema, "OrgSettingsPatch") {
17
17
  }
18
18
  let OrgSettingsController = class OrgSettingsController {
@@ -23,7 +23,7 @@ let OrgSettingsController = class OrgSettingsController {
23
23
  async get(org) {
24
24
  const settings = await this.settings.get(org.orgId);
25
25
  return {
26
- settings: orgSettingsView(settings),
26
+ settings,
27
27
  deployment: await this.settings.deployment(),
28
28
  effectiveNetwork: this.settings.effectiveNetwork(settings),
29
29
  sandboxLimits: await this.settings.sandboxLimits(org.orgId),
@@ -34,7 +34,7 @@ let OrgSettingsController = class OrgSettingsController {
34
34
  // an API token may narrow auto mode and the cloud network, never widen them (auto mode spec §4.3)
35
35
  const settings = await this.settings.update(org.orgId, body, p.account.id, patTokenId(p), undefined, { onlyNarrows: patTokenId(p) !== undefined });
36
36
  return {
37
- settings: orgSettingsView(settings),
37
+ settings,
38
38
  deployment: await this.settings.deployment(),
39
39
  effectiveNetwork: this.settings.effectiveNetwork(settings),
40
40
  sandboxLimits: await this.settings.sandboxLimits(org.orgId),
@@ -8,7 +8,7 @@ import { KernelDb } from "../infra/database/kernel-db.js";
8
8
  import { TransactionHost } from "../infra/database/transaction-host.js";
9
9
  import type { KernelLogger } from "../log.js";
10
10
  import { PermissionCeilingWrites } from "../sandbox/permission-ceiling-writes.js";
11
- import { type DevicesAutoModeView, type DevicesFullAccessView, type FullAccessPermission } from "../sandbox/platform-full-access.js";
11
+ import { type DevicesFullAccessView } from "../sandbox/platform-full-access.js";
12
12
  import { type ExternalSharingView } from "../shares/settings.js";
13
13
  import { type CloudNetworkSetting } from "./cloud-network-setting.js";
14
14
  import { OrgLock } from "./org-lock.js";
@@ -215,8 +215,6 @@ export type OrgSettingsView = OrgSettings & {
215
215
  scheduledTasks: OrgSettings["scheduledTasks"] & {
216
216
  forbiddenToolsUnreadable?: true;
217
217
  };
218
- /** The old public name of `fullAccess`, mirrored by {@link orgSettingsView}. */
219
- autoMode?: FullAccessPermission;
220
218
  };
221
219
  /** PATCH 体:只改给出的字段;未知字段 → 400。 */
222
220
  export declare const OrgSettingsPatchSchema: z.ZodObject<{
@@ -242,10 +240,6 @@ export declare const OrgSettingsPatchSchema: z.ZodObject<{
242
240
  allowed: "allowed";
243
241
  off: "off";
244
242
  }>>>;
245
- autoMode: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
246
- allowed: "allowed";
247
- off: "off";
248
- }>>>;
249
243
  cloudNetwork: z.ZodOptional<z.ZodNullable<z.ZodObject<{
250
244
  mode: z.ZodOptional<z.ZodEnum<{
251
245
  allowlist: "allowlist";
@@ -299,13 +293,6 @@ export declare const OrgSettingsPatchSchema: z.ZodObject<{
299
293
  }>>>;
300
294
  }, z.core.$strict>;
301
295
  export type OrgSettingsPatch = z.infer<typeof OrgSettingsPatchSchema>;
302
- /** A patch with the old `autoMode` moved to `fullAccess` (the schema refuses both together). */
303
- export declare function normalizeOrgSettingsPatch(patch: OrgSettingsPatch): OrgSettingsPatch;
304
- /**
305
- * The settings as the API answers them ({@link OrgSettingsView}), plus the old public name
306
- * `autoMode` mirroring `fullAccess` until the old public readers are removed.
307
- */
308
- export declare const orgSettingsView: (settings: OrgSettingsView) => OrgSettingsView;
309
296
  /** Whether a finished background task wakes an idle conversation: the org's setting, else the deployment's. */
310
297
  export declare function effectiveWakeOnBackgroundTask(deployment: boolean, org: OrgSettings["wakeOnBackgroundTask"]): boolean;
311
298
  /**
@@ -332,8 +319,6 @@ export interface OrgEffectiveNetwork {
332
319
  export interface OrgSettingsDeployment {
333
320
  /** The platform's Full permission switch and where it comes from. */
334
321
  fullAccess: DevicesFullAccessView;
335
- /** The same switch under its old public name (`{ mode, source }`). */
336
- autoMode: DevicesAutoModeView;
337
322
  /**
338
323
  * The platform's network: its allowlist (what an org's delta applies to), whether orgs may go
339
324
  * beyond it (`sandbox.limits.orgHosts`) and the kill switch (`off`: `sandbox.limits.egress` is
@@ -361,8 +346,9 @@ export interface OrgSettingsDeployment {
361
346
  promptSuggestions: "on" | "off";
362
347
  }
363
348
  /**
364
- * Parses the stored jsonb into settings (leniently, see {@link OrgSettingsSchema}). Until 8.6 `fullAccess` is read
365
- * over both keys, the narrower of it and the old `autoMode` ({@link narrowedOrgFullAccess}).
349
+ * Parses the stored jsonb into settings (leniently, see {@link OrgSettingsSchema}). `fullAccess` is
350
+ * read over both keys, the narrower of it and an old `autoMode` the permission configuration
351
+ * publication has not converted yet ({@link narrowedOrgFullAccess}; fail closed).
366
352
  */
367
353
  export declare function parseOrgSettings(raw: unknown): OrgSettings;
368
354
  /** The org's stored settings jsonb, read live; undefined when the org is missing or deleted. */
@@ -447,7 +433,7 @@ export declare class OrgSettingsService {
447
433
  * The refusals of {@link update} that need no read of the org (the Platform tool's precheck):
448
434
  * auto mode where the platform turned it off, external sharing where the platform denies it.
449
435
  */
450
- check(input: OrgSettingsPatch): Promise<void>;
436
+ check(patch: OrgSettingsPatch): Promise<void>;
451
437
  /**
452
438
  * Under `sandbox.limits.orgHosts: within` (spec §D2), refuses what would widen past the platform
453
439
  * ceiling compared with the stored value `before`: the open cloud network where the org did not
@@ -456,7 +442,7 @@ export declare class OrgSettingsService {
456
442
  * under the ceiling (they are filtered on read), so they never block a write.
457
443
  */
458
444
  assertWithinCeiling(before: OrgSettings, patch: OrgSettingsPatch): void;
459
- update(orgId: string, input: OrgSettingsPatch, actorAccountId: string, actorTokenId?: string,
445
+ update(orgId: string, patch: OrgSettingsPatch, actorAccountId: string, actorTokenId?: string,
460
446
  /** Merged into the audit detail (the Platform tool's `via: "agent"`). */
461
447
  auditDetail?: Record<string, unknown>,
462
448
  /**
@@ -478,7 +464,7 @@ export declare class OrgSettingsService {
478
464
  * that takes effect when the platform relaxes (org egress ceiling spec §D3);
479
465
  * - `externalSharing`: `on` where the org is off (absent = off).
480
466
  */
481
- assertOnlyNarrows(before: OrgSettings, input: OrgSettingsPatch): Promise<void>;
467
+ assertOnlyNarrows(before: OrgSettings, patch: OrgSettingsPatch): Promise<void>;
482
468
  private updateIn;
483
469
  }
484
470
  /**
@@ -22,7 +22,7 @@ import { coversHost, orgCloudMode, orgEffectiveHosts, orgHostOutsideCeiling, } f
22
22
  import { isExecutionMethod } from "../sandbox/operation-authority-types.js";
23
23
  import { PermissionAuthorityModule } from "../sandbox/permission-authority.module.js";
24
24
  import { localMachineRoots, needsFullCeiling, needsWiderDeviceCeiling, PermissionCeilingWrites, } from "../sandbox/permission-ceiling-writes.js";
25
- import { legacyAutoModeView, narrowedOrgFullAccess, readDevicesFullAccess, } from "../sandbox/platform-full-access.js";
25
+ import { narrowedOrgFullAccess, readDevicesFullAccess, } from "../sandbox/platform-full-access.js";
26
26
  import { readExternalSharing, readShareMaxExpiry, } from "../shares/settings.js";
27
27
  import { assertThemeOnIn } from "../themes/theme-state.js";
28
28
  import { IanaTimeZone } from "../time-zone.js";
@@ -200,11 +200,9 @@ export const OrgSettingsPatchSchema = z
200
200
  wakeOnBackgroundTask: z.boolean().nullable().optional(),
201
201
  /**
202
202
  * The org's Full permission switch; null clears it (follow the platform). `allowed` while the
203
- * platform is `off` -> 400 `org.auto_mode_not_allowed`.
203
+ * platform is `off` -> 400 `org.full_access_not_allowed`.
204
204
  */
205
205
  fullAccess: FullAccessSetting.nullable().optional(),
206
- /** The old name of `fullAccess`, still accepted (never together with it). */
207
- autoMode: FullAccessSetting.nullable().optional(),
208
206
  /**
209
207
  * The org's network for cloud devices, replaced whole (hosts left out follow the deployment);
210
208
  * null clears it (open). Through the Platform tool or an API token it may only narrow.
@@ -239,26 +237,7 @@ export const OrgSettingsPatchSchema = z
239
237
  /** The org's prompt suggestions switch (on or off); null clears it (follow the platform). */
240
238
  promptSuggestions: PromptSuggestionsSetting.nullable().optional(),
241
239
  })
242
- .strict()
243
- .refine((p) => p.autoMode === undefined || p.fullAccess === undefined, {
244
- message: "pass fullAccess only, not together with autoMode",
245
- path: ["autoMode"],
246
- });
247
- /** A patch with the old `autoMode` moved to `fullAccess` (the schema refuses both together). */
248
- export function normalizeOrgSettingsPatch(patch) {
249
- if (patch.autoMode === undefined)
250
- return patch;
251
- const { autoMode, ...rest } = patch;
252
- return { ...rest, fullAccess: autoMode };
253
- }
254
- /**
255
- * The settings as the API answers them ({@link OrgSettingsView}), plus the old public name
256
- * `autoMode` mirroring `fullAccess` until the old public readers are removed.
257
- */
258
- export const orgSettingsView = (settings) => ({
259
- ...settings,
260
- ...(settings.fullAccess !== undefined && { autoMode: settings.fullAccess }),
261
- });
240
+ .strict();
262
241
  /** Whether a finished background task wakes an idle conversation: the org's setting, else the deployment's. */
263
242
  export function effectiveWakeOnBackgroundTask(deployment, org) {
264
243
  return org ?? deployment;
@@ -280,8 +259,9 @@ export function effectiveSandboxLimits(deployment, override) {
280
259
  const sameSettings = (a, b) => JSON.stringify(OrgSettingsSchema.parse(a)) === JSON.stringify(OrgSettingsSchema.parse(b));
281
260
  const asObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v) ? v : {};
282
261
  /**
283
- * Parses the stored jsonb into settings (leniently, see {@link OrgSettingsSchema}). Until 8.6 `fullAccess` is read
284
- * over both keys, the narrower of it and the old `autoMode` ({@link narrowedOrgFullAccess}).
262
+ * Parses the stored jsonb into settings (leniently, see {@link OrgSettingsSchema}). `fullAccess` is
263
+ * read over both keys, the narrower of it and an old `autoMode` the permission configuration
264
+ * publication has not converted yet ({@link narrowedOrgFullAccess}; fail closed).
285
265
  */
286
266
  export function parseOrgSettings(raw) {
287
267
  const stored = asObject(raw);
@@ -353,7 +333,7 @@ export function logUnreadableSecuritySettings(log, orgId, raw) {
353
333
  log("org settings: stored scheduledTasks.forbiddenTools is unreadable; unattended runs fail until an org admin saves it again", { orgId });
354
334
  }
355
335
  }
356
- const autoModeNotAllowed = (message) => new ApiError("org.auto_mode_not_allowed", message);
336
+ const fullAccessNotAllowed = (message) => new ApiError("org.full_access_not_allowed", message);
357
337
  const externalSharingNotAllowed = (message) => new ApiError("org.external_sharing_not_allowed", message);
358
338
  /** Whether a stored settings object holds an `externalSharing` this version reads as `off`. */
359
339
  export function invalidStoredExternalSharing(raw) {
@@ -456,7 +436,6 @@ let OrgSettingsService = class OrgSettingsService {
456
436
  ]);
457
437
  return {
458
438
  fullAccess,
459
- autoMode: legacyAutoModeView(fullAccess),
460
439
  cloudNetwork: {
461
440
  allowHosts: [...lim.allowHosts],
462
441
  orgHosts: lim.orgHosts,
@@ -521,13 +500,12 @@ let OrgSettingsService = class OrgSettingsService {
521
500
  * The refusals of {@link update} that need no read of the org (the Platform tool's precheck):
522
501
  * auto mode where the platform turned it off, external sharing where the platform denies it.
523
502
  */
524
- async check(input) {
525
- const patch = normalizeOrgSettingsPatch(input);
503
+ async check(patch) {
526
504
  // allowing Full where the platform turned it off is wider than the platform allows
527
505
  if (patch.fullAccess === "allowed") {
528
506
  const platform = await readDevicesFullAccess(this.db.db, this.config, this.log);
529
507
  if (platform.permission === "off") {
530
- throw autoModeNotAllowed("The platform does not allow Full permission");
508
+ throw fullAccessNotAllowed("The platform does not allow Full permission");
531
509
  }
532
510
  }
533
511
  if (patch.externalSharing === "on") {
@@ -560,7 +538,7 @@ let OrgSettingsService = class OrgSettingsService {
560
538
  throw new ApiError("org.sandbox_egress_not_allowed", `The platform limits sandbox hosts to its allowlist; ask a super admin to add ${outside.join(", ")} to sandbox.limits.allowHosts`, [{ reason: "outside_ceiling", hosts: outside }]);
561
539
  }
562
540
  }
563
- async update(orgId, input, actorAccountId, actorTokenId,
541
+ async update(orgId, patch, actorAccountId, actorTokenId,
564
542
  /** Merged into the audit detail (the Platform tool's `via: "agent"`). */
565
543
  auditDetail,
566
544
  /**
@@ -569,7 +547,6 @@ let OrgSettingsService = class OrgSettingsService {
569
547
  * session widens.
570
548
  */
571
549
  opts) {
572
- const patch = normalizeOrgSettingsPatch(input);
573
550
  await this.check(patch);
574
551
  // the org row, then (for a Full or cloud network change) the org's permission authority lock:
575
552
  // the ordered prelude, so inside a run's fence (the Platform tool's `org-settings.update`) they
@@ -591,13 +568,12 @@ let OrgSettingsService = class OrgSettingsService {
591
568
  * that takes effect when the platform relaxes (org egress ceiling spec §D3);
592
569
  * - `externalSharing`: `on` where the org is off (absent = off).
593
570
  */
594
- async assertOnlyNarrows(before, input) {
595
- const patch = normalizeOrgSettingsPatch(input);
571
+ async assertOnlyNarrows(before, patch) {
596
572
  if (patch.fullAccess !== undefined) {
597
573
  const platform = await readDevicesFullAccess(this.db.db, this.config, this.log);
598
574
  const next = patch.fullAccess === null ? platform.permission : patch.fullAccess;
599
575
  if ((before.fullAccess ?? platform.permission) !== "allowed" && next === "allowed") {
600
- throw autoModeNotAllowed("Allowing Full permission needs a person in the organization settings.");
576
+ throw fullAccessNotAllowed("Allowing Full permission needs a person in the organization settings.");
601
577
  }
602
578
  }
603
579
  if (patch.cloudNetwork !== undefined &&
@@ -653,10 +629,10 @@ let OrgSettingsService = class OrgSettingsService {
653
629
  if (Object.keys(after.uiArrangement).length === 0)
654
630
  delete after.uiArrangement;
655
631
  }
656
- // Until 8.6 a stored old `autoMode` is never dropped: an unconverted key (or one an old
657
- // replica wrote again) is carried in step with `fullAccess`, since old replicas still read it.
658
- // A write that does not choose the value stores what every reader already sees: the narrower
659
- // of the two (never refused, never wider).
632
+ // A stored old `autoMode` is never dropped here: only the permission configuration
633
+ // publication converts it (a mismatch window before activation keeps it). It is carried in
634
+ // step with `fullAccess`; a write that does not choose the value stores what every reader
635
+ // already sees: the narrower of the two (never refused, never wider).
660
636
  const legacy = "autoMode" in stored;
661
637
  if (legacy && patch.fullAccess === undefined)
662
638
  after.fullAccess = narrowedOrgFullAccess(before.fullAccess, stored.autoMode);
@@ -67,9 +67,9 @@ import { EMBED_TOKEN_CLOCK } from "./ui/embed-token.js";
67
67
  * - `EXTENSION_NET_SEAMS`: `ctx.net`'s DNS and dispatcher (a hostname resolving to a private address
68
68
  * served by a loopback fake);
69
69
  * - `APP_INTERCEPTOR`: one more global interceptor (a probe of the matched routes);
70
- * - `PERMISSION_CONTEXT_ACTIVATION`: turns the dormant recorded permission context producers on
71
- * (the request boundary and the managed device context writer) before their paired activation
72
- * flips the production default.
70
+ * - `PERMISSION_CONTEXT_ACTIVATION`: the recorded permission context producers (the request
71
+ * boundary and the managed device context writer); production leaves them on, and a test may
72
+ * turn them off to exercise the dormant state.
73
73
  */
74
74
  interface KernelSeams {
75
75
  [AGENT_LOOP_FACTORY]: AgentLoopFactory;
@@ -19,7 +19,7 @@ import { AdminUsageService } from "../../admin/usage.service.js";
19
19
  import { ApiError } from "../../errors.js";
20
20
  import { ExtensionDisplayNames } from "../../extensions/display-name.js";
21
21
  import { ExtensionRegistry } from "../../extensions/registry.js";
22
- import { DEPLOYMENT_SETTINGS_PATCH, normalizeDeploymentSettingsPatch, SettingsService, } from "../../identity/settings.js";
22
+ import { DEPLOYMENT_SETTINGS_PATCH, SettingsService } from "../../identity/settings.js";
23
23
  import { ModelDisabledPatch, ModelProviderParams } from "../../models/enablement.controller.js";
24
24
  import { ModelEnablement } from "../../models/enablement.js";
25
25
  import { MODEL_PRICE_PUT, PricesService } from "../../models/prices.js";
@@ -44,7 +44,6 @@ const SettingsInput = DEPLOYMENT_SETTINGS_PATCH.pick({
44
44
  uiArrangement: true,
45
45
  clientExtensions: true,
46
46
  devicesFullAccess: true,
47
- devicesAutoMode: true,
48
47
  attribution: true,
49
48
  externalSharing: true,
50
49
  shareMaxExpiryDays: true,
@@ -240,7 +239,7 @@ let AdminOperations = class AdminOperations {
240
239
  next: "Fix the values as the message says (admin.settings shows the current ones).",
241
240
  },
242
241
  {
243
- code: "deployment.auto_mode_not_allowed",
242
+ code: "deployment.full_access_not_allowed",
244
243
  next: "Through this tool the platform's Full permission switch may only be turned off; to allow it, ask a super admin to change it in the admin console settings on the web.",
245
244
  },
246
245
  {
@@ -270,21 +269,20 @@ let AdminOperations = class AdminOperations {
270
269
  };
271
270
  }
272
271
  return precheckBy(async () => {
273
- const full = normalizeDeploymentSettingsPatch(i).devicesFullAccess;
272
+ const full = i.devicesFullAccess;
274
273
  if (full !== undefined)
275
274
  await this.settings.checkDevicesFullAccess(full, { onlyNarrows: true });
276
275
  await this.settings.checkSharing(i, { onlyNarrows: true });
277
276
  });
278
277
  },
279
278
  summary: async (i) => {
280
- const { uiTheme, uiArrangement, clientExtensions, devicesFullAccess, devicesAutoMode, attribution, htmlRenderCdnAllowlist, ...rest } = i;
279
+ const { uiTheme, uiArrangement, clientExtensions, devicesFullAccess, attribution, htmlRenderCdnAllowlist, ...rest } = i;
281
280
  const parts = Object.entries(rest).map(([k, v]) => `${k}=${String(v)}`);
282
281
  if (htmlRenderCdnAllowlist !== undefined) {
283
282
  parts.push(`htmlRenderCdnAllowlist=[${htmlRenderCdnAllowlist.join(", ")}]`);
284
283
  }
285
- const full = devicesFullAccess?.permission ?? devicesAutoMode?.mode;
286
- if (devicesFullAccess !== undefined || devicesAutoMode !== undefined) {
287
- parts.push(`devicesFullAccess=${String(full)}`);
284
+ if (devicesFullAccess !== undefined) {
285
+ parts.push(`devicesFullAccess=${String(devicesFullAccess.permission)}`);
288
286
  }
289
287
  const zh = [...parts];
290
288
  const en = [...parts];
@@ -9,7 +9,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
9
9
  };
10
10
  import { Inject, Injectable } from "@nestjs/common";
11
11
  import { z } from "zod";
12
- import { OrgSettingsPatchSchema, OrgSettingsService, orgSettingsView, } from "../../orgs/settings.service.js";
12
+ import { OrgSettingsPatchSchema, OrgSettingsService } from "../../orgs/settings.service.js";
13
13
  import { ThemesService } from "../../themes/themes.service.js";
14
14
  import { defineOperation } from "../operation.js";
15
15
  import { PlatformOperations } from "../registry.js";
@@ -48,7 +48,7 @@ let OrgSettingsOperations = class OrgSettingsOperations {
48
48
  run: async (_input, ctx) => {
49
49
  const settings = await this.settings.get(ctx.orgId);
50
50
  return {
51
- settings: orgSettingsView(settings),
51
+ settings,
52
52
  deployment: await this.settings.deployment(),
53
53
  effectiveNetwork: this.settings.effectiveNetwork(settings),
54
54
  sandboxLimits: await this.settings.sandboxLimits(ctx.orgId),
@@ -71,7 +71,7 @@ let OrgSettingsOperations = class OrgSettingsOperations {
71
71
  next: "Through this tool the org's cloud network may only be narrowed: it may drop extra hosts, exclude platform hosts, move base to none or switch open to allowlist, but never add an extra host, drop an exclusion or switch back to open (the hosts are the local sandbox-mode ceiling whatever the cloud mode). To widen it, ask an org admin to change it in the organization settings on the web. When the platform limits hosts to its allowlist (deployment.cloudNetwork.orgHosts within), a host outside it needs a super admin.",
72
72
  },
73
73
  {
74
- code: "org.auto_mode_not_allowed",
74
+ code: "org.full_access_not_allowed",
75
75
  next: "Through this tool the org's Full permission (fullAccess) may only be turned off, never allowed (the platform may turn it off too; org-settings.get shows both); to allow it, ask an org admin to change it in the organization settings on the web.",
76
76
  },
77
77
  {
@@ -130,7 +130,7 @@ let OrgSettingsOperations = class OrgSettingsOperations {
130
130
  ? undefined
131
131
  : PLATFORM_TOOL_NOTE[settings.platformTool];
132
132
  return {
133
- settings: orgSettingsView(settings),
133
+ settings,
134
134
  effectiveNetwork: this.settings.effectiveNetwork(settings),
135
135
  ...(note !== undefined && { note }),
136
136
  };
@@ -181,7 +181,6 @@ let OrgsOperations = class OrgsOperations {
181
181
  "uiArrangement",
182
182
  "clientExtensions",
183
183
  "devicesFullAccess",
184
- "devicesAutoMode",
185
184
  "attribution",
186
185
  "compaction",
187
186
  "externalSharing",
@@ -50,7 +50,7 @@ export declare class MaintenanceProcessor extends WorkerHost<Worker> {
50
50
  private readonly operations;
51
51
  private readonly shareObjects;
52
52
  private readonly snapshots?;
53
- constructor(permissionApprovals: Pick<PermissionApprovalJobs, "recheck">, waits: Pick<Waits, "processTimeout" | "childFinished" | "stopChildren" | "stopDescendantsOfStopped" | "stopTree">, sandbox: Pick<SandboxService, "destroyDevice" | "resetFileSystem">, drift: Pick<ToolDrift, "check">, directory: Pick<DirectorySync, "runSyncJob">, deletion: Pick<RunDeletion, "stopOrg" | "stopTree">, offboarding: Pick<Offboarding, "stopRun">, runs: Pick<RunQueue, "ensureRun">, ownedCleanup: Pick<OwnedPluginCleanup, "run">, scheduledTasks: Pick<ScheduledTaskFirer, "fire" | "settle">, deviceOps: Pick<DeviceOpResolver, "resolve">, scheduled: Pick<ScheduledRuns, "runNow">, log: Pick<KernelLogger, "error" | "warn">, operations: Pick<SandboxOperationReconcileJob, "reconcile" | "revoke">, shareObjects: Pick<ShareObjects, "deleteObject">, snapshots?: Pick<CloudPermissionSnapshots, "reconcileDevice"> | undefined);
53
+ constructor(permissionApprovals: Pick<PermissionApprovalJobs, "recheck">, waits: Pick<Waits, "processTimeout" | "childFinished" | "stopChildren" | "stopDescendantsOfStopped" | "stopTree">, sandbox: Pick<SandboxService, "destroyDevice" | "resetFileSystem" | "revokeDeadHolder">, drift: Pick<ToolDrift, "check">, directory: Pick<DirectorySync, "runSyncJob">, deletion: Pick<RunDeletion, "stopOrg" | "stopTree">, offboarding: Pick<Offboarding, "stopRun">, runs: Pick<RunQueue, "ensureRun">, ownedCleanup: Pick<OwnedPluginCleanup, "run">, scheduledTasks: Pick<ScheduledTaskFirer, "fire" | "settle">, deviceOps: Pick<DeviceOpResolver, "resolve">, scheduled: Pick<ScheduledRuns, "runNow">, log: Pick<KernelLogger, "error" | "warn">, operations: Pick<SandboxOperationReconcileJob, "reconcile" | "revoke">, shareObjects: Pick<ShareObjects, "deleteObject">, snapshots?: Pick<CloudPermissionSnapshots, "reconcileDevice"> | undefined);
54
54
  process(job: Job, token?: string): Promise<void>;
55
55
  /** Starts consuming (worker role, after the extensions loaded; built with `autorun: false`). */
56
56
  start(): void;
@@ -25,7 +25,7 @@ import { Offboarding, RUN_STOP_JOB } from "../orgs/offboarding.js";
25
25
  import { OrgsModule } from "../orgs/orgs.module.js";
26
26
  import { CloudPermissionSnapshots } from "../sandbox/cloud-permission-snapshot.js";
27
27
  import { runSandboxDestroyFor, runSandboxResetFiles, SANDBOX_DESTROY_FOR_JOB, SANDBOX_RESET_FILES_JOB, } from "../sandbox/jobs.js";
28
- import { OPERATION_RECONCILE, OPERATION_REVOKE } from "../sandbox/operation-intents.js";
28
+ import { HOLDER_REVOKE, OPERATION_RECONCILE, OPERATION_REVOKE, } from "../sandbox/operation-intents.js";
29
29
  import { SandboxOperationReconcileJob } from "../sandbox/operation-reconcile.job.js";
30
30
  import { PERMISSION_APPROVAL_RECHECK } from "../sandbox/permission-transitions.js";
31
31
  import { SandboxModule } from "../sandbox/sandbox.module.js";
@@ -115,6 +115,12 @@ let MaintenanceProcessor = class MaintenanceProcessor extends WorkerHost {
115
115
  case OPERATION_REVOKE:
116
116
  await this.operations.revoke(job.data.operationId);
117
117
  return;
118
+ // a crashed sandbox holder's intents, owed before its record was forgotten (B-1)
119
+ case HOLDER_REVOKE: {
120
+ const { deviceId, token } = job.data;
121
+ await this.sandbox.revokeDeadHolder(deviceId, token);
122
+ return;
123
+ }
118
124
  case STOP_DELETED_ORG_JOB:
119
125
  await this.deletion.stopOrg(job.data);
120
126
  return;
@@ -81,8 +81,8 @@ let RunSteps = class RunSteps {
81
81
  info: (orgId, conversationId, ids) => attachments.mediaInfo(orgId, conversationId, ids),
82
82
  fetch: (orgId, conversationId, ids, caps) => attachments.fetchMedia(orgId, conversationId, ids, caps),
83
83
  },
84
- // the request boundary of the recorded permission context (spec B2); dormant until the
85
- // paired activation (Task 8 phase 8.6) turns the gate on
84
+ // the request boundary of the recorded permission context (spec B2); on since the paired
85
+ // activation (device protocol 3), off only where a test provides the gate as false
86
86
  ...livePermissionContext(permissionContext, activation),
87
87
  };
88
88
  }
@@ -34,6 +34,13 @@ export declare function assertPermissionSupport(provider: SandboxProvider, handl
34
34
  * then the runtime supports the profile and owns background executions.
35
35
  */
36
36
  export declare function checkManagedStart(provider: SandboxProvider, handle: SandboxHandle, scope: SandboxOperationScope, input: Omit<ManagedStartArgs, "signal">, signal: AbortSignal): Promise<void>;
37
+ /**
38
+ * `provider` whose background starts carry `instanceGeneration`, the kernel's generation of the
39
+ * held instance (its `created_at` milliseconds): a cloud provider cannot know it otherwise (it is
40
+ * allocated after `create` returns), and the acknowledgement requires the ref to name it. A bound
41
+ * (local) device knows its generation from its binding and is not given one.
42
+ */
43
+ export declare function withKernelGeneration(provider: SandboxProvider, generation: string): SandboxProvider;
37
44
  export declare function createHeldOperations(provider: SandboxProvider, handle: SandboxHandle, heldSignal: AbortSignal, dispatch: OperationDispatch): HeldProvider;
38
45
  /** Temporary v2 callback adapter. Removed with the coordinated Task 8 cutover. */
39
46
  export declare function createLegacyHeldProvider(provider: SandboxProvider, tag: string, actor: Parameters<SandboxProvider["exec"]>[1]["actor"], before: () => Promise<void>): HeldProvider;
@@ -1,5 +1,6 @@
1
1
  import { SandboxPermissionUnsupportedError, SandboxScopeDeniedError, } from "@capybara-hq/plugin-sdk";
2
2
  import { assertManagedArtifactAdmitted } from "../background/launch.js";
3
+ import { isFullExecutionScope } from "./operation-authority-types.js";
3
4
  /** The provider's runtime must enforce the scope's profile (and own background executions). */
4
5
  export async function assertPermissionSupport(provider, handle, scope, method, signal) {
5
6
  if (!provider.operation || !provider.permissionSupport || !provider.revokeOperation)
@@ -7,7 +8,7 @@ export async function assertPermissionSupport(provider, handle, scope, method, s
7
8
  const support = await provider.permissionSupport(handle, signal);
8
9
  if (support.version !== 1 ||
9
10
  (method === "backgroundStart" && (!support.background || !provider.background)) ||
10
- (scope.profile === "full-access"
11
+ (isFullExecutionScope(scope)
11
12
  ? !support.fullAccess
12
13
  : !support.restricted?.filesystem ||
13
14
  !support.restricted.network ||
@@ -24,6 +25,29 @@ export async function checkManagedStart(provider, handle, scope, input, signal)
24
25
  assertManagedArtifactAdmitted(scope, input);
25
26
  await assertPermissionSupport(provider, handle, scope, "backgroundStart", signal);
26
27
  }
28
+ /**
29
+ * `provider` whose background starts carry `instanceGeneration`, the kernel's generation of the
30
+ * held instance (its `created_at` milliseconds): a cloud provider cannot know it otherwise (it is
31
+ * allocated after `create` returns), and the acknowledgement requires the ref to name it. A bound
32
+ * (local) device knows its generation from its binding and is not given one.
33
+ */
34
+ export function withKernelGeneration(provider, generation) {
35
+ const background = provider.background;
36
+ if (!background)
37
+ return provider;
38
+ const wrapped = Object.create(provider);
39
+ // only `start` changes; every other method is the provider's own, bound to it (a provider may
40
+ // leave out methods the kernel never calls on it)
41
+ const bound = (m) => typeof m === "function" ? m.bind(background) : m;
42
+ wrapped.background = {
43
+ status: bound(background.status),
44
+ tail: bound(background.tail),
45
+ readOutput: bound(background.readOutput),
46
+ stop: bound(background.stop),
47
+ start: (h, scope, args) => background.start(h, scope, { ...args, instanceGeneration: generation }),
48
+ };
49
+ return wrapped;
50
+ }
27
51
  export function createHeldOperations(provider, handle, heldSignal, dispatch) {
28
52
  const call = (h, method, input, signal, invoke, preflight) => {
29
53
  if (h.id !== handle.id)
@@ -143,10 +143,13 @@ export declare class SandboxLeases {
143
143
  /** Deletes a holder record (after its provider calls). */
144
144
  unregisterHolder(env: string, token: string): Promise<void>;
145
145
  /**
146
- * Tags of holders without a live lease, atomically claimed (their fields removed) so only one
147
- * caller kills them.
146
+ * Tokens of holders without a live lease (crashed holders), read without removing them: a token
147
+ * dies only once, so two readers may both see it and both owe its revocation under the same
148
+ * deterministic job id; {@link forgetHolders} removes them once that is durable.
148
149
  */
149
- claimDeadHolders(env: string): Promise<string[]>;
150
+ deadHolders(env: string): Promise<string[]>;
151
+ /** Removes crashed holders' records whose revocation is owed durably ({@link deadHolders}). */
152
+ forgetHolders(env: string, tokens: readonly string[]): Promise<void>;
150
153
  /**
151
154
  * A short lease on one path of the sandbox (the kernel's own read-modify-write of a file); waits
152
155
  * up to `capMs`, then throws {@link SandboxPathBusyError}. A {@link LockService.hold} lease