@capybara-hq/kernel 0.1.0-rc.121 → 0.1.0-rc.123

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 (230) hide show
  1. package/bootstrap.json +3 -3
  2. package/dist/background/finish.d.ts +5 -1
  3. package/dist/background/finish.js +29 -18
  4. package/dist/background/launch.d.ts +0 -5
  5. package/dist/background/launch.js +1 -6
  6. package/dist/background/managed.js +1 -4
  7. package/dist/background/poll.job.d.ts +3 -25
  8. package/dist/background/poll.job.js +20 -112
  9. package/dist/background/render.d.ts +2 -8
  10. package/dist/background/render.js +3 -17
  11. package/dist/background/stop.d.ts +15 -16
  12. package/dist/background/stop.js +39 -76
  13. package/dist/background/store.d.ts +17 -45
  14. package/dist/background/store.js +60 -94
  15. package/dist/background/tasks.service.d.ts +2 -5
  16. package/dist/background/tasks.service.js +9 -20
  17. package/dist/background/wake.js +3 -2
  18. package/dist/catalog/admin-catalog.controller.d.ts +2 -18
  19. package/dist/catalog/admin-catalog.controller.js +2 -28
  20. package/dist/catalog/catalog-content.d.ts +1 -5
  21. package/dist/catalog/catalog-items.d.ts +2 -6
  22. package/dist/catalog/catalog-items.js +5 -26
  23. package/dist/catalog/catalog-scope.service.d.ts +1 -121
  24. package/dist/catalog/catalog-scope.service.js +12 -552
  25. package/dist/catalog/catalog.service.d.ts +4 -15
  26. package/dist/catalog/catalog.service.js +7 -35
  27. package/dist/catalog/job-ids.d.ts +0 -18
  28. package/dist/catalog/job-ids.js +0 -20
  29. package/dist/catalog/marketplaces.service.d.ts +1 -1
  30. package/dist/catalog/org-catalog.service.js +6 -20
  31. package/dist/catalog/org-plugin-uploads.controller.d.ts +4 -19
  32. package/dist/catalog/org-plugin-uploads.controller.js +6 -34
  33. package/dist/catalog/org-plugin-uploads.d.ts +3 -10
  34. package/dist/catalog/org-plugin-uploads.js +4 -18
  35. package/dist/catalog/org-plugin-uploads.schemas.js +0 -1
  36. package/dist/catalog/owned-items.d.ts +6 -11
  37. package/dist/catalog/owned-items.js +10 -20
  38. package/dist/catalog/ownership.d.ts +3 -29
  39. package/dist/catalog/ownership.js +4 -54
  40. package/dist/catalog/platform-components.d.ts +5 -11
  41. package/dist/catalog/platform-components.js +8 -15
  42. package/dist/catalog/plugin-import.d.ts +3 -42
  43. package/dist/catalog/plugin-import.js +26 -195
  44. package/dist/catalog/plugin-install.js +1 -6
  45. package/dist/catalog/plugin-package.d.ts +1 -0
  46. package/dist/catalog/plugin-package.js +5 -0
  47. package/dist/catalog/plugin-upgrade.d.ts +3 -26
  48. package/dist/catalog/plugin-upgrade.js +20 -103
  49. package/dist/catalog/request-rules.js +4 -6
  50. package/dist/catalog/scope-sync.js +2 -4
  51. package/dist/catalog/scope.d.ts +2 -5
  52. package/dist/channels/jobs.d.ts +3 -3
  53. package/dist/channels/jobs.js +4 -3
  54. package/dist/channels/outbound.d.ts +1 -0
  55. package/dist/channels/outbound.js +32 -8
  56. package/dist/config/load.d.ts +0 -25
  57. package/dist/config/load.js +0 -57
  58. package/dist/config/schema.js +2 -3
  59. package/dist/conversations/attachments.service.js +3 -5
  60. package/dist/conversations/conversations.service.d.ts +3 -3
  61. package/dist/conversations/conversations.service.js +3 -3
  62. package/dist/conversations/job-org.d.ts +3 -0
  63. package/dist/conversations/job-org.js +11 -0
  64. package/dist/conversations/prompt-suggestions.d.ts +2 -7
  65. package/dist/conversations/prompt-suggestions.js +29 -27
  66. package/dist/conversations/titles.d.ts +3 -4
  67. package/dist/conversations/titles.js +19 -30
  68. package/dist/db/kernel-schema.d.ts +6 -16
  69. package/dist/db/pool.js +7 -2
  70. package/dist/devices/devices.controller.d.ts +0 -5
  71. package/dist/devices/devices.controller.js +2 -20
  72. package/dist/devices/devices.service.d.ts +1 -17
  73. package/dist/devices/devices.service.js +0 -22
  74. package/dist/errors.d.ts +1 -5
  75. package/dist/errors.js +1 -5
  76. package/dist/evals/judge.d.ts +3 -0
  77. package/dist/evals/judge.js +1 -1
  78. package/dist/evals/run-replay.d.ts +1 -1
  79. package/dist/evals/run-replay.js +26 -29
  80. package/dist/evals/step-replay.d.ts +3 -1
  81. package/dist/evals/step-replay.js +10 -1
  82. package/dist/evals/worker.d.ts +3 -1
  83. package/dist/evals/worker.js +53 -21
  84. package/dist/extensions/deployment-config-store.js +18 -14
  85. package/dist/extensions/effective-config.d.ts +1 -5
  86. package/dist/extensions/effective-config.js +1 -5
  87. package/dist/extensions/hooks.d.ts +3 -1
  88. package/dist/extensions/hooks.js +7 -2
  89. package/dist/extensions/installs.d.ts +2 -14
  90. package/dist/extensions/installs.js +10 -32
  91. package/dist/extensions/org-config.d.ts +3 -4
  92. package/dist/extensions/org-config.js +3 -4
  93. package/dist/extensions/plugin-guides.d.ts +0 -1
  94. package/dist/extensions/plugin-guides.js +0 -1
  95. package/dist/extensions/plugin-icons.d.ts +0 -1
  96. package/dist/extensions/plugin-icons.js +0 -3
  97. package/dist/files/blob-sweep.job.d.ts +2 -11
  98. package/dist/files/blob-sweep.job.js +7 -21
  99. package/dist/files/hash-job.d.ts +5 -15
  100. package/dist/files/hash-job.js +14 -33
  101. package/dist/files/library-jobs.module.d.ts +1 -6
  102. package/dist/files/library-jobs.module.js +3 -9
  103. package/dist/identity/api-tokens.js +54 -40
  104. package/dist/identity/auth.guard.js +2 -2
  105. package/dist/identity/sessions.js +7 -3
  106. package/dist/identity/settings.js +5 -21
  107. package/dist/inbox/inbox.service.d.ts +2 -3
  108. package/dist/inbox/org-notices.d.ts +0 -14
  109. package/dist/inbox/platform-inbox.service.d.ts +1 -8
  110. package/dist/inbox/platform-inbox.service.js +2 -6
  111. package/dist/inbox/platform-notices.d.ts +3 -3
  112. package/dist/index.d.ts +0 -4
  113. package/dist/index.js +0 -3
  114. package/dist/infra/database/database.module.js +2 -1
  115. package/dist/infra/database/org-scope.d.ts +5 -3
  116. package/dist/infra/database/org-scope.js +7 -1
  117. package/dist/infra/database/scoped-dialect.d.ts +3 -1
  118. package/dist/infra/database/scoped-dialect.js +17 -5
  119. package/dist/infra/events/kernel-events.d.ts +2 -0
  120. package/dist/infra/outbox/outbox.service.d.ts +2 -0
  121. package/dist/infra/outbox/outbox.service.js +10 -0
  122. package/dist/infra/outbox/registry.d.ts +0 -41
  123. package/dist/infra/outbox/registry.js +0 -37
  124. package/dist/models/embeddings.d.ts +0 -5
  125. package/dist/models/embeddings.js +28 -35
  126. package/dist/models/images.d.ts +3 -8
  127. package/dist/models/images.js +19 -37
  128. package/dist/models/purposes.d.ts +7 -2
  129. package/dist/models/purposes.js +16 -3
  130. package/dist/orgs/device-network-setting.d.ts +0 -44
  131. package/dist/orgs/device-network-setting.js +0 -83
  132. package/dist/orgs/invitations.service.js +34 -30
  133. package/dist/orgs/offboarding.d.ts +2 -2
  134. package/dist/orgs/offboarding.js +2 -2
  135. package/dist/orgs/orgs.service.d.ts +1 -1
  136. package/dist/orgs/orgs.service.js +19 -15
  137. package/dist/orgs/settings.service.d.ts +19 -14
  138. package/dist/orgs/settings.service.js +12 -37
  139. package/dist/platform/exclusions.js +0 -11
  140. package/dist/platform/ops/catalog-admin.ops.js +0 -8
  141. package/dist/platform/ops/devices.ops.js +0 -28
  142. package/dist/platform/ops/extensions-admin.ops.js +3 -3
  143. package/dist/platform/ops/inbox.ops.js +5 -22
  144. package/dist/platform/ops/org-plugins.ops.d.ts +1 -3
  145. package/dist/platform/ops/org-plugins.ops.js +11 -67
  146. package/dist/roles/worker.module.js +0 -9
  147. package/dist/runtime/hook-calls.d.ts +13 -6
  148. package/dist/runtime/hook-calls.js +26 -4
  149. package/dist/runtime/maintenance.d.ts +3 -12
  150. package/dist/runtime/maintenance.js +25 -55
  151. package/dist/runtime/model-call.d.ts +4 -2
  152. package/dist/runtime/model-call.js +59 -58
  153. package/dist/runtime/providers.d.ts +27 -1
  154. package/dist/runtime/providers.js +57 -0
  155. package/dist/runtime/run-jobs.d.ts +1 -1
  156. package/dist/runtime/run-processors.d.ts +3 -9
  157. package/dist/runtime/run-worker.d.ts +2 -0
  158. package/dist/runtime/run-worker.js +23 -8
  159. package/dist/runtime/subagents/deliveries.js +6 -1
  160. package/dist/runtime/subagents/dispatch.d.ts +3 -3
  161. package/dist/runtime/write-base.service.d.ts +2 -3
  162. package/dist/runtime/write-base.service.js +3 -5
  163. package/dist/sandbox/device-sandbox-settings.d.ts +38 -92
  164. package/dist/sandbox/device-sandbox-settings.js +19 -325
  165. package/dist/sandbox/jobs.d.ts +3 -14
  166. package/dist/sandbox/jobs.js +2 -20
  167. package/dist/sandbox/modes.d.ts +5 -45
  168. package/dist/sandbox/modes.js +3 -60
  169. package/dist/sandbox/operation-authority.js +0 -11
  170. package/dist/sandbox/operation-intents.d.ts +32 -9
  171. package/dist/sandbox/operation-intents.js +241 -32
  172. package/dist/sandbox/operation-intents.module.js +2 -1
  173. package/dist/sandbox/operation-reconcile.job.d.ts +9 -11
  174. package/dist/sandbox/operation-reconcile.job.js +119 -33
  175. package/dist/sandbox/operation-revoke.d.ts +20 -0
  176. package/dist/sandbox/operation-revoke.js +3 -0
  177. package/dist/sandbox/permission-ceiling-writes.d.ts +1 -2
  178. package/dist/sandbox/permission-ceiling-writes.js +3 -6
  179. package/dist/sandbox/permission-config-publication.d.ts +1 -28
  180. package/dist/sandbox/permission-config-publication.js +14 -211
  181. package/dist/sandbox/permission-facts.d.ts +4 -15
  182. package/dist/sandbox/permission-facts.js +7 -29
  183. package/dist/sandbox/permission-instance-writes.d.ts +1 -4
  184. package/dist/sandbox/permission-instance-writes.js +1 -55
  185. package/dist/sandbox/providers.d.ts +1 -6
  186. package/dist/sandbox/providers.js +1 -15
  187. package/dist/sandbox/review/classifier.js +12 -13
  188. package/dist/sandbox/sandbox.module.js +3 -6
  189. package/dist/sandbox/sandbox.service.d.ts +17 -123
  190. package/dist/sandbox/sandbox.service.js +239 -998
  191. package/dist/shares/liveness.d.ts +1 -2
  192. package/dist/shares/liveness.js +1 -2
  193. package/dist/shares/shares.module.d.ts +1 -2
  194. package/dist/shares/shares.module.js +2 -5
  195. package/dist/shares/shares.service.js +1 -2
  196. package/dist/tools/builtins/image/generate.js +7 -15
  197. package/dist/tools/builtins/sandbox/common.d.ts +0 -2
  198. package/dist/tools/builtins/sandbox/common.js +1 -27
  199. package/dist/tools/builtins/sandbox/task-list.js +10 -10
  200. package/dist/tools/builtins/sandbox/task-output.d.ts +3 -10
  201. package/dist/tools/builtins/sandbox/task-output.js +13 -83
  202. package/dist/tools/builtins/sandbox/task-stop.js +18 -22
  203. package/dist/tools/builtins/vision/read-image.js +9 -10
  204. package/dist/tools/builtins/web/extract.js +9 -10
  205. package/package.json +3 -3
  206. package/src/migrations/0206_retire_org_extension_uploads.sql +125 -0
  207. package/src/migrations/0207_confirm_device_instance_destruction.sql +25 -0
  208. package/src/migrations/0208_convert_stored_permission_settings.sql +189 -0
  209. package/dist/background/retire-legacy-tasks.job.d.ts +0 -57
  210. package/dist/background/retire-legacy-tasks.job.js +0 -149
  211. package/dist/catalog/owned-plugin-cleanup.d.ts +0 -47
  212. package/dist/catalog/owned-plugin-cleanup.js +0 -140
  213. package/dist/config/permission-migration.d.ts +0 -34
  214. package/dist/config/permission-migration.js +0 -115
  215. package/dist/devices/legacy-cleanup.job.d.ts +0 -34
  216. package/dist/devices/legacy-cleanup.job.js +0 -147
  217. package/dist/files/library-backfill.d.ts +0 -63
  218. package/dist/files/library-backfill.js +0 -143
  219. package/dist/infra/cli/permission-cutover.d.ts +0 -59
  220. package/dist/infra/cli/permission-cutover.js +0 -107
  221. package/dist/sandbox/cloud-permission-snapshot.d.ts +0 -159
  222. package/dist/sandbox/cloud-permission-snapshot.js +0 -430
  223. package/dist/sandbox/cloud-permission-snapshot.module.d.ts +0 -8
  224. package/dist/sandbox/cloud-permission-snapshot.module.js +0 -34
  225. package/dist/sandbox/legacy-retirement.d.ts +0 -284
  226. package/dist/sandbox/legacy-retirement.js +0 -1165
  227. package/dist/sandbox/legacy-retirement.module.d.ts +0 -8
  228. package/dist/sandbox/legacy-retirement.module.js +0 -25
  229. package/dist/shares/share-objects.d.ts +0 -47
  230. package/dist/shares/share-objects.js +0 -93
@@ -123,25 +123,15 @@ export declare class PermissionFacts {
123
123
  /**
124
124
  * The device's lifecycle policy: the kernel-internal mode tier (`auto` / `sandbox`, recorded with
125
125
  * an instance's applied limits) and the network an instance is created with: its device sandbox
126
- * network ({@link deviceSandbox}), the same for every provider. The B1 snapshot's
127
- * `outer_network` is no longer read: migrations 0165 and 0167 and the snapshot writer copy an
128
- * allowlist snapshot into the device's own network choice (`network_mode`, `network_hosts`).
126
+ * network ({@link deviceSandbox}), the same for every provider.
129
127
  */
130
128
  devicePolicy(device: {
131
129
  orgId: string;
132
130
  deviceId?: string;
133
131
  }): Promise<EffectiveDevicePolicy>;
134
132
  /**
135
- * Refuses admission on a cloud device whose B1 snapshot found applied limits it could not
136
- * establish exactly (unknown, stale, wider or pending a reset): only a lifecycle action that
137
- * establishes them clears the marker (`CloudPermissionSnapshots.reconcile`). Read under the
138
- * caller's device authority lock, which the snapshot writer takes for writing.
139
- */
140
- assertCloudReconciled(orgId: string, deviceId: string): Promise<void>;
141
- /**
142
- * The mode tier a device chose: the narrower of its old switch and its B1 owner snapshot
143
- * (`cloudChosenMode`), or null for a device that follows the platform and the org; `found`:
144
- * a live device of the org. The tier is kernel-internal (instance limits); whether a call may
133
+ * The device's narrowing switch, or null to follow the platform and org. `found` denotes a live
134
+ * device of the org. The tier is kernel-internal (instance limits); whether a call may
145
135
  * run outside the sandbox is the device sandbox's.
146
136
  */
147
137
  private chosenMode;
@@ -352,8 +342,7 @@ export declare function hostsWithinOuter(hosts: readonly string[], outer: Applie
352
342
  export declare function networkOfSandbox(box: DeviceSandbox): DeviceNetwork;
353
343
  /**
354
344
  * A device's own sandbox network, whatever its provider: its stored choice (`network_mode`,
355
- * `network_hosts`; null follows the org). A B1 snapshot is copied into it by migrations 0165 and
356
- * 0167, the snapshot writer and every publication (`copyCloudSnapshotNetworks`), never read here.
345
+ * `network_hosts`; null follows the org).
357
346
  */
358
347
  export declare function ownNetwork(row: {
359
348
  network_mode?: unknown;
@@ -23,7 +23,7 @@ import { readOrgSettings } from "../orgs/settings.service.js";
23
23
  import { storedReport, storedSupport } from "./device-reports.js";
24
24
  import { canonicalHostCeiling, deviceListAddRefusal, effectiveDeviceSandbox, hostGrantCeiling, hostGrantRefusal, orgHostsOf, providerLayerOf, reachWithin, } from "./device-sandbox.js";
25
25
  import { readDeviceSandboxSettings } from "./device-sandbox-settings.js";
26
- import { appliedOf, appliedWider, cloudChosenMode, coversHost, effectiveDevicePolicy, readDeploymentDevicePolicy, readInstanceLimits, } from "./modes.js";
26
+ import { appliedOf, appliedWider, coversHost, effectiveDevicePolicy, readDeploymentDevicePolicy, readInstanceLimits, } from "./modes.js";
27
27
  import { assertAuthorityHeld } from "./permission-authority-lock.js";
28
28
  import { deviceWorkAvailability, permissionAvailabilityFor, } from "./permission-availability.js";
29
29
  import { readCurrentReport } from "./permission-runtime-reports.js";
@@ -211,9 +211,7 @@ let PermissionFacts = class PermissionFacts {
211
211
  /**
212
212
  * The device's lifecycle policy: the kernel-internal mode tier (`auto` / `sandbox`, recorded with
213
213
  * an instance's applied limits) and the network an instance is created with: its device sandbox
214
- * network ({@link deviceSandbox}), the same for every provider. The B1 snapshot's
215
- * `outer_network` is no longer read: migrations 0165 and 0167 and the snapshot writer copy an
216
- * allowlist snapshot into the device's own network choice (`network_mode`, `network_hosts`).
214
+ * network ({@link deviceSandbox}), the same for every provider.
217
215
  */
218
216
  async devicePolicy(device) {
219
217
  const [deployment, settings, chosen] = await Promise.all([
@@ -232,38 +230,19 @@ let PermissionFacts = class PermissionFacts {
232
230
  return { ...policy, network: networkOfSandbox(box) };
233
231
  }
234
232
  /**
235
- * Refuses admission on a cloud device whose B1 snapshot found applied limits it could not
236
- * establish exactly (unknown, stale, wider or pending a reset): only a lifecycle action that
237
- * establishes them clears the marker (`CloudPermissionSnapshots.reconcile`). Read under the
238
- * caller's device authority lock, which the snapshot writer takes for writing.
239
- */
240
- async assertCloudReconciled(orgId, deviceId) {
241
- const row = await this.db
242
- .selectFrom("devices")
243
- .select("permission_reconcile_required")
244
- .where("id", "=", deviceId)
245
- .where("org_id", "=", orgId)
246
- .executeTakeFirst();
247
- if (row?.permission_reconcile_required)
248
- throw new ApiError("device.permission_reconcile_required", "This device's sandbox limits must be established again before it runs anything; reset the device's files to apply them");
249
- }
250
- /**
251
- * The mode tier a device chose: the narrower of its old switch and its B1 owner snapshot
252
- * (`cloudChosenMode`), or null for a device that follows the platform and the org; `found`:
253
- * a live device of the org. The tier is kernel-internal (instance limits); whether a call may
233
+ * The device's narrowing switch, or null to follow the platform and org. `found` denotes a live
234
+ * device of the org. The tier is kernel-internal (instance limits); whether a call may
254
235
  * run outside the sandbox is the device sandbox's.
255
236
  */
256
237
  async chosenMode(orgId, deviceId) {
257
238
  const row = await this.db
258
239
  .selectFrom("devices")
259
- .select(["mode", "owner_full_access"])
240
+ .select("mode")
260
241
  .where("id", "=", deviceId)
261
242
  .where("org_id", "=", orgId)
262
243
  .where("deleted_at", "is", null)
263
244
  .executeTakeFirst();
264
- return row === undefined
265
- ? { found: false, mode: null }
266
- : { found: true, mode: cloudChosenMode(row) };
245
+ return row === undefined ? { found: false, mode: null } : { found: true, mode: row.mode };
267
246
  }
268
247
  /**
269
248
  * The device's current permission availability: the provider's capability shape, then the
@@ -689,8 +668,7 @@ export function networkOfSandbox(box) {
689
668
  }
690
669
  /**
691
670
  * A device's own sandbox network, whatever its provider: its stored choice (`network_mode`,
692
- * `network_hosts`; null follows the org). A B1 snapshot is copied into it by migrations 0165 and
693
- * 0167, the snapshot writer and every publication (`copyCloudSnapshotNetworks`), never read here.
671
+ * `network_hosts`; null follows the org).
694
672
  */
695
673
  export function ownNetwork(row) {
696
674
  const hosts = row?.network_hosts;
@@ -40,10 +40,7 @@ export declare class PermissionInstanceWrites {
40
40
  * handle and its evidence appear together (B-15). Absent: none recorded (a failed read leaves
41
41
  * the instance unprobed).
42
42
  */
43
- commitHandle(orgId: string, deviceId: string, generation: number, roots: SandboxRoots, set: UpdateObject<KernelDatabase, "device_instances">, signal: AbortSignal, evidence?: SupportReport, providerGeneration?: string): Promise<Date>;
44
- /** Preserve the exact old handle pairing before a lifecycle write can discard that handle. */
45
- preserveRetirementIdentity(orgId: string, deviceId: string, fence: number, providerGeneration: string, signal: AbortSignal): Promise<void>;
46
- private recordRetirementIdentity;
43
+ commitHandle(orgId: string, deviceId: string, generation: number, roots: SandboxRoots, set: UpdateObject<KernelDatabase, "device_instances">, signal: AbortSignal, evidence?: SupportReport): Promise<Date>;
47
44
  /**
48
45
  * Records an instance's permission support read after a resume, a limits change, a provider
49
46
  * version change or a new report revision, under the caller's lifecycle lease (B-15). Recorded only while the
@@ -16,7 +16,6 @@ import { canonicalJson } from "../tools/canonical-json.js";
16
16
  import { SandboxLockLostError } from "./leases.js";
17
17
  import { PermissionCeilingWrites } from "./permission-ceiling-writes.js";
18
18
  import { PermissionRuntimeReports } from "./permission-runtime-reports.js";
19
- import { LOCAL_RETIREMENT_PROVIDER } from "./providers.js";
20
19
  const rootKey = (r) => JSON.stringify([r.workspace, r.skills, r.tmp]);
21
20
  /** The greatest epoch millisecond a JavaScript Date (and so a generation) can represent. */
22
21
  export const MAX_GENERATION_MS = 8_640_000_000_000_000;
@@ -47,7 +46,7 @@ let PermissionInstanceWrites = class PermissionInstanceWrites {
47
46
  * handle and its evidence appear together (B-15). Absent: none recorded (a failed read leaves
48
47
  * the instance unprobed).
49
48
  */
50
- async commitHandle(orgId, deviceId, generation, roots, set, signal, evidence, providerGeneration) {
49
+ async commitHandle(orgId, deviceId, generation, roots, set, signal, evidence) {
51
50
  signal.throwIfAborted();
52
51
  await this.lockDevice(orgId, deviceId);
53
52
  await this.ceilings.lock({ orgId, deviceId }, "device");
@@ -84,60 +83,10 @@ let PermissionInstanceWrites = class PermissionInstanceWrites {
84
83
  throw new SandboxLockLostError(deviceId, "generation");
85
84
  if (updated.created_at.getTime() !== createdAt.getTime())
86
85
  throw new Error("Instance generation was not stored exactly; check the database clock type");
87
- if (providerGeneration !== undefined)
88
- await this.recordRetirementIdentity(orgId, deviceId, createdAt, providerGeneration);
89
86
  if (evidence)
90
87
  await this.reports.recordSupport(deviceId, evidence.provider, evidence.version, evidence.report);
91
88
  return updated.created_at;
92
89
  }
93
- /** Preserve the exact old handle pairing before a lifecycle write can discard that handle. */
94
- async preserveRetirementIdentity(orgId, deviceId, fence, providerGeneration, signal) {
95
- signal.throwIfAborted();
96
- await this.lockDevice(orgId, deviceId);
97
- const row = await this.db
98
- .selectFrom("device_instances")
99
- .select("created_at")
100
- .where("device_id", "=", deviceId)
101
- .where("org_id", "=", orgId)
102
- .where("provider", "=", LOCAL_RETIREMENT_PROVIDER)
103
- .where("generation", "=", fence)
104
- .where("handle", "is not", null)
105
- .where("had_instance", "=", true)
106
- .forUpdate()
107
- .executeTakeFirst();
108
- if (!row)
109
- throw new SandboxLockLostError(deviceId, "generation");
110
- signal.throwIfAborted();
111
- await this.recordRetirementIdentity(orgId, deviceId, row.created_at, providerGeneration);
112
- signal.throwIfAborted();
113
- }
114
- async recordRetirementIdentity(orgId, deviceId, createdAt, providerGeneration) {
115
- const generation = String(createdAt.getTime());
116
- const r = await this.db
117
- .insertInto("device_instance_retirement_identities")
118
- .values({
119
- org_id: orgId,
120
- device_id: deviceId,
121
- provider: LOCAL_RETIREMENT_PROVIDER,
122
- instance_generation: generation,
123
- provider_generation: providerGeneration,
124
- })
125
- .onConflict((oc) => oc.doNothing())
126
- .returning("provider_generation")
127
- .executeTakeFirst();
128
- if (r !== undefined)
129
- return;
130
- const existing = await this.db
131
- .selectFrom("device_instance_retirement_identities")
132
- .select("provider_generation")
133
- .where("org_id", "=", orgId)
134
- .where("device_id", "=", deviceId)
135
- .where("provider", "=", LOCAL_RETIREMENT_PROVIDER)
136
- .where("instance_generation", "=", generation)
137
- .executeTakeFirst();
138
- if (existing?.provider_generation !== providerGeneration)
139
- throw new InconsistentGenerationError("The local provider returned a conflicting generation");
140
- }
141
90
  /**
142
91
  * Records an instance's permission support read after a resume, a limits change, a provider
143
92
  * version change or a new report revision, under the caller's lifecycle lease (B-15). Recorded only while the
@@ -267,9 +216,6 @@ let PermissionInstanceWrites = class PermissionInstanceWrites {
267
216
  __decorate([
268
217
  Transactional({ propagation: "requires_new" })
269
218
  ], PermissionInstanceWrites.prototype, "commitHandle", null);
270
- __decorate([
271
- Transactional({ propagation: "requires_new" })
272
- ], PermissionInstanceWrites.prototype, "preserveRetirementIdentity", null);
273
219
  __decorate([
274
220
  Transactional({ propagation: "requires_new" })
275
221
  ], PermissionInstanceWrites.prototype, "recordSupport", null);
@@ -1,15 +1,10 @@
1
- import { type DeviceProvider, type SandboxHandle } from "@capybara-hq/plugin-sdk";
1
+ import { type DeviceProvider } from "@capybara-hq/plugin-sdk";
2
2
  import { ExtensionRegistry } from "../extensions/registry.js";
3
3
  /**
4
4
  * An in-process provider name: it starts with `@`, which no extension name can
5
5
  * (`EXTENSION_NAME_RE`), so it never collides with a loaded `device-provider@1` plugin.
6
6
  */
7
7
  export declare const isInProcessName: (name: string) => boolean;
8
- /** Only this provider's machine journal can attest a local retirement. */
9
- export declare const LOCAL_RETIREMENT_PROVIDER = "device-local";
10
- export declare const RETIREMENT_GENERATION: RegExp;
11
- /** The optional provider identity is immutable evidence about this exact committed handle. */
12
- export declare function localRetirementGeneration(provider: DeviceProviderEntry, handle: SandboxHandle, deviceId: string): string | undefined;
13
8
  /**
14
9
  * Whether a provider serves its devices over the dial-in channel: it implements
15
10
  * `DeviceProvider.dialIn` (an extension may only when it declares `permissions.dialIn`, checked
@@ -7,7 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __param = (this && this.__param) || function (paramIndex, decorator) {
8
8
  return function (target, key) { decorator(target, key, paramIndex); }
9
9
  };
10
- import { DEVICE_PROVIDER_EXTENSION_POINT, } from "@capybara-hq/plugin-sdk";
10
+ import { DEVICE_PROVIDER_EXTENSION_POINT } from "@capybara-hq/plugin-sdk";
11
11
  import { Inject, Injectable } from "@nestjs/common";
12
12
  import { ExtensionRegistry } from "../extensions/registry.js";
13
13
  import { guardProviderConnection } from "./unreachable.js";
@@ -16,20 +16,6 @@ import { guardProviderConnection } from "./unreachable.js";
16
16
  * (`EXTENSION_NAME_RE`), so it never collides with a loaded `device-provider@1` plugin.
17
17
  */
18
18
  export const isInProcessName = (name) => name.startsWith("@");
19
- /** Only this provider's machine journal can attest a local retirement. */
20
- export const LOCAL_RETIREMENT_PROVIDER = "device-local";
21
- export const RETIREMENT_GENERATION = /^[1-9][0-9]{0,15}$/;
22
- /** The optional provider identity is immutable evidence about this exact committed handle. */
23
- export function localRetirementGeneration(provider, handle, deviceId) {
24
- if (provider.plugin !== LOCAL_RETIREMENT_PROVIDER ||
25
- handle.id !== deviceId ||
26
- !servesDialIn(provider))
27
- return undefined;
28
- const generation = provider.impl.retirement?.generation(handle);
29
- return typeof generation === "string" && RETIREMENT_GENERATION.test(generation)
30
- ? generation
31
- : undefined;
32
- }
33
19
  /**
34
20
  * Whether a provider serves its devices over the dial-in channel: it implements
35
21
  * `DeviceProvider.dialIn` (an extension may only when it declares `permissions.dialIn`, checked
@@ -3,7 +3,7 @@ import { isModelError, } from "@capybara-hq/plugin-sdk";
3
3
  import { z } from "zod";
4
4
  import { PurposeAttemptError } from "../../models/purposes.js";
5
5
  import { estimateTokens } from "../../runtime/context/tokens.js";
6
- import { fireObserve, hookDeniedAudit, hookDeniedEvent, hookRequestOf, hookScope, } from "../../runtime/hook-calls.js";
6
+ import { fireObserve, hookDeniedAudit, hookDeniedEvent, hookScope, } from "../../runtime/hook-calls.js";
7
7
  import { appendCounted } from "../../runtime/model-call.js";
8
8
  import { escalationBackgroundText } from "./permission-candidate.js";
9
9
  /**
@@ -495,19 +495,18 @@ export async function callReviewModel(deps, args, call) {
495
495
  toolChoice: "none",
496
496
  maxOutputTokens: REVIEW_MAX_OUTPUT_TOKENS,
497
497
  }, signal, {
498
+ hooks: deps.hooks,
499
+ scope,
500
+ step: args.step,
501
+ onDenied: async (verdict) => {
502
+ const { detail: _rawDetail, ...denialFacts } = verdict;
503
+ const denial = call.privateInput
504
+ ? { ...denialFacts, reason: "A policy hook refused the review request." }
505
+ : verdict;
506
+ await recordDenial(deps, args, call, outcomes, denial);
507
+ throw new ReviewDenied(denial.reason);
508
+ },
498
509
  beforeSend: async (target, request) => {
499
- const base = hookBase(target);
500
- if (base && deps.hooks?.has("model.request")) {
501
- const verdict = await deps.hooks.run("model.request", { ...base, request: hookRequestOf(request, deps.log) }, signal);
502
- if (!verdict.allowed) {
503
- const { detail: _rawDetail, ...denialFacts } = verdict;
504
- const denial = call.privateInput
505
- ? { ...denialFacts, reason: "A policy hook refused the review request." }
506
- : verdict;
507
- await recordDenial(deps, args, call, outcomes, denial);
508
- throw new ReviewDenied(denial.reason);
509
- }
510
- }
511
510
  await args.beforeSend?.(target, request);
512
511
  sent = { ...target, at: Date.now() };
513
512
  },
@@ -14,11 +14,10 @@ import { QueueModule } from "../infra/queue/queue.module.js";
14
14
  import { ModelsModule } from "../models/models.module.js";
15
15
  import { MAINTENANCE_QUEUE_NAME } from "../runtime/maintenance-queue.js";
16
16
  import { StepLogModule } from "../runtime/step-log.js";
17
- import { CloudPermissionSnapshotsModule } from "./cloud-permission-snapshot.module.js";
18
17
  import { DeviceReportsModule } from "./device-reports.module.js";
19
18
  import { DeviceServices } from "./device-services.js";
20
19
  import { SandboxJobs } from "./jobs.js";
21
- import { LegacyRetirementModule } from "./legacy-retirement.module.js";
20
+ import { SandboxLeases } from "./leases.js";
22
21
  import { LoopbackGrantLock, LoopbackGrants } from "./loopback-grants.js";
23
22
  import { LoopbackLivePorts } from "./loopback-live-ports.js";
24
23
  import { OperationAuthorityModule } from "./operation-authority.module.js";
@@ -52,8 +51,6 @@ SandboxModule = __decorate([
52
51
  OperationIntentsModule,
53
52
  OperationAuthorityModule,
54
53
  BackgroundStoreModule,
55
- LegacyRetirementModule,
56
- CloudPermissionSnapshotsModule,
57
54
  // the command review's classifier: the `review` purpose, its hooks, usage and audit writes
58
55
  ModelsModule,
59
56
  ExtensionsModule,
@@ -63,6 +60,7 @@ SandboxModule = __decorate([
63
60
  ],
64
61
  providers: [
65
62
  SandboxService,
63
+ SandboxLeases,
66
64
  SandboxJobs,
67
65
  CommandReviewService,
68
66
  DeviceServices,
@@ -72,16 +70,15 @@ SandboxModule = __decorate([
72
70
  ],
73
71
  exports: [
74
72
  SandboxProviderRegistryModule,
75
- LegacyRetirementModule,
76
73
  PermissionAuthorityModule,
77
74
  SandboxService,
75
+ SandboxLeases,
78
76
  DeviceServices,
79
77
  LoopbackGrants,
80
78
  OperationIntentsModule,
81
79
  OperationAuthorityModule,
82
80
  SandboxJobs,
83
81
  CommandReviewService,
84
- CloudPermissionSnapshotsModule,
85
82
  DeviceReportsModule,
86
83
  ],
87
84
  })
@@ -15,12 +15,10 @@ import { ApiError } from "../errors.js";
15
15
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
16
16
  import { KernelDb } from "../infra/database/kernel-db.js";
17
17
  import type { KernelLogger } from "../log.js";
18
- import { CloudPermissionSnapshots, type CloudSnapshotOutcome } from "./cloud-permission-snapshot.js";
19
18
  import { DeviceReports } from "./device-reports.js";
20
19
  import type { DeviceSandbox, HostGrantCeiling } from "./device-sandbox.js";
21
20
  import { type KernelReadInvocation } from "./kernel-read.js";
22
21
  import { SandboxLeases, type SandboxPathLease } from "./leases.js";
23
- import { LegacyRetirementStore, type LocalRetirementCheck } from "./legacy-retirement.js";
24
22
  import { type AppliedLimits, type DeviceLimits, type EffectiveDevicePolicy } from "./modes.js";
25
23
  import type { HeldDeviceContextEvidence } from "./permission-context-types.js";
26
24
  import { PermissionFacts } from "./permission-facts.js";
@@ -189,21 +187,6 @@ export declare const sandboxUnavailable: () => ApiError;
189
187
  * stopped in between (idle suspension) or one that could not be started; retrying starts it.
190
188
  */
191
189
  export declare const deviceNotRunning: () => ApiError;
192
- /**
193
- * The device's old instance incarnation may still run legacy work that was never retired (503):
194
- * the device stays unavailable until the provider confirms that incarnation destroyed, or for
195
- * good when it is quarantined (permission runtime cutover 8.5). Never a retirement claim.
196
- */
197
- export declare class RetirementPendingError extends ApiError {
198
- name: string;
199
- }
200
- export declare const retirementPending: () => ApiError;
201
- /**
202
- * A cloud device's earlier instance may still run legacy work and no evidence the kernel can get
203
- * will ever cover it (an incarnation replaced without a recorded confirmed destruction, or an
204
- * unknown one it cannot clear) (503, 8.5): the owner deletes the device and creates it again.
205
- */
206
- export declare const recreateRequired: (local?: boolean) => ApiError;
207
190
  /**
208
191
  * The kernel's sandbox service over the `device-provider@1` provider, keyed by **device** (spec
209
192
  * 2026-11-07-environments-design §4.2, §5.1): one file system kept until the device is
@@ -289,10 +272,6 @@ export declare class SandboxService {
289
272
  private readonly operationIntents;
290
273
  private readonly authority;
291
274
  private readonly instanceWrites;
292
- /** The retirement obligations every lifecycle acquisition is gated on (8.5). */
293
- private readonly retirement;
294
- /** The cloud snapshot writer's reconcile, for the lifecycle reconcile of marked devices (B-12). */
295
- private readonly snapshots;
296
275
  /** The stored device report, refreshed after a create or a resume (never fails the use). */
297
276
  private readonly reports;
298
277
  /**
@@ -304,13 +283,9 @@ export declare class SandboxService {
304
283
  /** The record of the instance each holder last used (`capk:sandbox-seen:…`). */
305
284
  redis: Pick<Redis, "get" | "set" | "getdel">, leases: SandboxLeases,
306
285
  /** The providers (read at every call: providers are ready after the extension load). */
307
- providers: Pick<DeviceProviders, "forDevice" | "loaded" | "all">,
286
+ providers: Pick<DeviceProviders, "forDevice" | "all">,
308
287
  /** Whether a device's provider serves its org now (read at every use, never cached). */
309
- selection: Pick<DeviceProviderSelection, "isOnInOrg">, config: Pick<KernelConfigService, "get" | "fieldSource">, log: Pick<KernelLogger, "info" | "warn">, facts: Pick<PermissionFacts, "devicePolicy" | "assertCloudReconciled" | "readHeldEnvironment" | "readDevice" | "deviceSandbox" | "deviceSandboxFacts" | "orgHostGrantCeiling">, operationIntents: SandboxOperationIntents, authority: SandboxOperationAuthority, instanceWrites: PermissionInstanceWrites,
310
- /** The retirement obligations every lifecycle acquisition is gated on (8.5). */
311
- retirement: Pick<LegacyRetirementStore, "unresolved" | "hasUnresolved" | "scanUntilStable" | "frozen" | "frozenAt" | "quarantine" | "noteFailure" | "resolveDestroyed" | "resolveCancelled" | "membersOf" | "recordDestruction" | "destructionRecorded" | "quarantinedLocal" | "localProviderGeneration" | "resolveLocalProof">,
312
- /** The cloud snapshot writer's reconcile, for the lifecycle reconcile of marked devices (B-12). */
313
- snapshots: Pick<CloudPermissionSnapshots, "reconcileHeld">,
288
+ selection: Pick<DeviceProviderSelection, "isOnInOrg">, config: Pick<KernelConfigService, "get" | "fieldSource">, log: Pick<KernelLogger, "info" | "warn">, facts: Pick<PermissionFacts, "devicePolicy" | "readHeldEnvironment" | "readDevice" | "deviceSandbox" | "deviceSandboxFacts" | "orgHostGrantCeiling">, operationIntents: SandboxOperationIntents, authority: SandboxOperationAuthority, instanceWrites: PermissionInstanceWrites,
314
289
  /** The stored device report, refreshed after a create or a resume (never fails the use). */
315
290
  reports: Pick<DeviceReports, "refresh">,
316
291
  /**
@@ -489,20 +464,9 @@ export declare class SandboxService {
489
464
  * to `fn` aborts with `signal` or when the lease is lost. Errors of `fn` (`SandboxGoneError`
490
465
  * too) are thrown as they are.
491
466
  */
492
- ifRunning<T>(deviceId: string,
493
- /**
494
- * `exactRef`: an exact-ref managed drain (status, stop, the revoke worker), allowed on an
495
- * incarnation under a retirement obligation; every other caller (legacy SID polls, stops and
496
- * reads, staged browse) is refused there with a {@link RetirementPendingError} (8.5).
497
- */
498
- instance: {
467
+ ifRunning<T>(deviceId: string, instance: {
499
468
  createdAt: Date;
500
- exactRef?: boolean;
501
469
  }, fn: (p: TaggedProvider, h: SandboxHandle, signal: AbortSignal) => Promise<T>, signal?: AbortSignal): Promise<IfRunningResult<T>>;
502
- /**
503
- * {@link ifRunning}; `use` (staged owner browse) also refuses a device carrying the B1
504
- * reconcile marker under the shared lease, before any provider call (B-11).
505
- */
506
470
  private ifRunningAs;
507
471
  /**
508
472
  * Holds the device's running instance for a stream to one of its services (browser use spec
@@ -554,8 +518,8 @@ export declare class SandboxService {
554
518
  * Makes the device's instance run for its owner (permission activation L2, Hook 3), before an
555
519
  * owner browse ({@link withBrowse}) of a device that may be stopped: the owner, membership and
556
520
  * browsing ceiling checks of the browse first (`resolveBrowse`), then the lifecycle `enter` a
557
- * use takes (the exclusive lease creates or resumes the instance through the retirement gate,
558
- * the B-11 reconcile marker, `maxRunningSandboxes` and fencing), and the lease
521
+ * use takes (the exclusive lease creates or resumes the instance with `maxRunningSandboxes` and
522
+ * fencing), and the lease
559
523
  * is left at once. No conversation holds it and nothing runs in it; what the start caused is
560
524
  * not marked seen, so each conversation's next use still learns of it. `narrow` is the browse's
561
525
  * own (see {@link withBrowse}), checked before the start, so a browse the narrowed scope refuses
@@ -571,7 +535,7 @@ export declare class SandboxService {
571
535
  /**
572
536
  * Makes the device's instance run for a managed call before its permission review reads the
573
537
  * device's facts: the lifecycle `enter` the call's own use takes (the exclusive lease creates
574
- * or resumes the instance through the retirement gate, the binding, the limits and fencing, and
538
+ * or resumes the bound instance with the current limits and fencing, and
575
539
  * records a cloud instance's permission evidence), then the lease is left at once. Nothing runs
576
540
  * in it; what the start caused is kept for the holder's next use to tell (as a silent use).
577
541
  */
@@ -584,7 +548,7 @@ export declare class SandboxService {
584
548
  * never creates, resumes or rebuilds an instance: without a running one (none, suspended, being
585
549
  * created or destroyed, files lost) there is nothing to apply and the next use's resume applies
586
550
  * the limits. Nothing is done when the limits already apply (no lease is taken, so open viewers
587
- * stay), or while the device carries a retirement obligation (only a use's gate settles it).
551
+ * stay).
588
552
  *
589
553
  * The exclusive lease is taken with intent. Only the wait is bounded by `signal` and by
590
554
  * `sandbox.lockWaitSeconds` (`sandbox.busy` after that: a tool call holding the device keeps
@@ -615,8 +579,8 @@ export declare class SandboxService {
615
579
  withKernelRead<T>(ctx: SandboxUseContext, read: KernelReadInvocation, fn: (h: SandboxHandle, p: HeldProvider, info: SandboxUseInfo, signal: AbortSignal) => Promise<T>, signal: AbortSignal): Promise<T>;
616
580
  /**
617
581
  * A `write_base` kernel read ({@link withKernelRead}) on the instance the device runs now, under
618
- * a shared lease taken the way {@link ifRunning} takes it (B1 reconcile marker and retirement
619
- * gate included): a device with no running instance, or one that changes instance before the
582
+ * a shared lease taken the way {@link ifRunning} takes it: a device with no running instance, or
583
+ * one that changes instance before the
620
584
  * lease, throws {@link KernelReadInstanceNotRunning} with nothing made, woken or sent.
621
585
  *
622
586
  * Unlike a use's `enter`, this path neither applies changed limits (`mustApply`, which needs the
@@ -864,66 +828,6 @@ export declare class SandboxService {
864
828
  * provider is not loaded, or when its instance row names another provider.
865
829
  */
866
830
  resetFileSystem(deviceId: string): Promise<void>;
867
- /** The owner's proof-only pass of the retirement gate, with no provider lifecycle mutation. */
868
- checkLocalRetirement(owner: Pick<LocalRetirementCheck, "orgId" | "deviceId" | "accountId">, requested: AbortSignal): Promise<"clear" | "blocked" | "busy">;
869
- private ownerLocalProvider;
870
- /**
871
- * The worker's retirement of a device's old incarnations (8.5, `RetireLegacyTasksJob`): one try
872
- * at the exclusive lifecycle lease, then the same gate as every acquisition. `busy`: a holder
873
- * has the device (the inline gate runs on its next lifecycle acquisition anyway); `unavailable`:
874
- * an obligation stays (quarantined, or a destroy that failed); `clear`: none left.
875
- */
876
- retireLegacy(deviceId: string,
877
- /** The worker's signal (its stop, a lost run lock): ends a destroy in flight. */
878
- signal?: AbortSignal): Promise<"clear" | "unavailable" | "busy">;
879
- /**
880
- * The lifecycle reconcile of a cloud device carrying `permission_reconcile_required` (B-12),
881
- * under one try at its exclusive lifecycle lease (`busy`: a holder has it). The snapshot
882
- * writer's reconcile runs first ({@link CloudPermissionSnapshots.reconcileHeld}: it narrows the
883
- * authority to what the instance is known to run, and may clear the marker by itself). A device
884
- * with an unresolved retirement obligation stops there: its incarnation is the retirement
885
- * gate's alone (never resumed here). When the
886
- * marker stays on a live instance whose provider can `update`, the provider applies the
887
- * reconcile target, which is never wider than the instance in any dimension, so this only
888
- * narrows; a suspended instance is resumed for it (its leftover operations revoked exactly,
889
- * nobody else holds it) and suspended again, as its row still says. `updated` records the target as
890
- * applied (fenced) and the reconcile runs again, which clears the marker. No `update`, a
891
- * `recreate` answer, a gone instance or a failure leave the marker and its file reset action.
892
- */
893
- reconcileLimits(deviceId: string, signal?: AbortSignal): Promise<CloudSnapshotOutcome | "busy">;
894
- /**
895
- * The worker's sweep of {@link reconcileLimits} (`sandbox-reconcile-limits`): for each loaded
896
- * provider that can `update`, up to `limit` live cloud devices of its own carrying the marker on
897
- * a live instance, in id order from that provider's shared keyset cursor that wraps around (no
898
- * starvation), each tried at most once per {@link RECONCILE_RETRY_SECONDS} across replicas (a
899
- * Redis marker). Rows of a provider that is not loaded are never touched. Returns how many it
900
- * reconciled.
901
- */
902
- reconcileMarked(limit?: number): Promise<number>;
903
- /** {@link reconcileMarked} for the devices of one provider. */
904
- private reconcileMarkedOf;
905
- /**
906
- * The retirement gate (permission runtime cutover 8.5), under the exclusive lifecycle lease and
907
- * before the instance is used, resumed, rebuilt, switched to another provider, bound or
908
- * downgraded to shared use: every unresolved obligation of the device is settled here or the
909
- * device is unavailable ({@link retirementPending}).
910
- * - The obligation names the **current** incarnation (provider and exact generation): it is
911
- * destroyed whole by its provider, whatever the provider (never resumed, never `killAll`ed,
912
- * the file system kept), the confirmed destruction is recorded and the row reads
913
- * `destroyed`, so the use creates a fresh instance; a failed destroy keeps the obligation.
914
- * - B-22: a **suspended** current incarnation whose members are all revoked managed starts
915
- * is not destroyed whole (its other tasks would be lost): each revoked ref gets its exact stop
916
- * (persisted while suspended), the instance is resumed, each stop is confirmed (`stopped` or
917
- * `already-exited`), and the obligation resolves as `exact-cancelled`. Any failure is noted on
918
- * the obligation and falls back to the whole-instance destroy above. `resumed` given (a use):
919
- * the resumed instance is left running for it (`resumed.resumed` set); otherwise (the worker),
920
- * or when the device stays refused, it is suspended again, as its row still says.
921
- * - It names an incarnation that is **not current** (replaced, a reused handle with another
922
- * generation, unknown): resolved only by a recorded provider-confirmed destruction of exactly
923
- * it, else quarantined. A newer generation is never evidence.
924
- * Returns the row as it is afterwards.
925
- */
926
- private retireIncarnations;
927
831
  /**
928
832
  * A fenced write: only while the lease holds and the row's generation is still the one read
929
833
  * under it (and incremented); otherwise {@link SandboxLockLostError}.
@@ -944,19 +848,10 @@ export declare class SandboxService {
944
848
  * rebuilt it the new one is used.
945
849
  */
946
850
  private ensure;
947
- /**
948
- * Under the exclusive lease, before the rebuild of an instance its provider answered gone
949
- * (`SandboxGoneError` during a use, or `resume` answering `gone`): the row's incarnation is
950
- * destroyed through its provider with this holder's fence token (a no-op where it is really
951
- * gone; on a provider whose `gone` means "never served again", such as a local machine whose
952
- * program restarted, it ends what the generation left) and that confirmed destruction is
953
- * recorded (8.5 evidence) before anything new is created. Its revoked starts and owed revokes
954
- * then settle against the record once a new incarnation runs, instead of quarantining the
955
- * device for an incarnation replaced without a recorded destruction. A destroy that fails fails
956
- * the use with nothing rebuilt: the row still names the gone incarnation, so the next use is
957
- * told gone again and retries (unavailable for now, never `device.recreate_required`).
958
- */
959
- private destroyGone;
851
+ /** Persist exact cancellations on the suspended instance before its processes can run again. */
852
+ private cancelBeforeResume;
853
+ /** Destroy the exact instance with the current fence before replacing it on the same files. */
854
+ private destroyForReplacement;
960
855
  /**
961
856
  * {@link create} from {@link ensure}, then, for a provider whose limits are fixed at its file
962
857
  * system (the new instance keeps the network its file system enforces, E2B), the installed
@@ -1018,9 +913,8 @@ export declare class SandboxService {
1018
913
  /** Runs `call` with its own short signal; a failure is warned and returns false. */
1019
914
  private bestEffort;
1020
915
  /**
1021
- * Destroys an instance an earlier kernel recorded in `prev_*` (left by a provider replaced back
1022
- * then) with that provider: still loaded and destroyed → false; otherwise warns and returns true
1023
- * (the record must be kept).
916
+ * Destroy the exact previous handle before its row can be cleared or deleted. An earlier
917
+ * kernel recorded no generation for this handle, so its destruction cannot acknowledge an intent.
1024
918
  */
1025
919
  private retire;
1026
920
  /**
@@ -1029,6 +923,8 @@ export declare class SandboxService {
1029
923
  * the handle was recorded) is destroyed by name. Returns the `prev_*` patch.
1030
924
  */
1031
925
  private destroyInstance;
926
+ /** A dial-in destroy can return while the machine is offline or already on another generation. */
927
+ private recordDestruction;
1032
928
  /**
1033
929
  * Under the lease: destroys the row's file system with its own provider `p` (by name when no
1034
930
  * handle was recorded: `createFileSystem` may have finished before the kernel stopped).
@@ -1041,8 +937,6 @@ export declare class SandboxService {
1041
937
  private destroyRow;
1042
938
  /** Due for suspension: made by this provider, running, and idle or running for too long. */
1043
939
  private suspendDue;
1044
- /** The loaded provider of an instance row (its own `provider`); undefined when not loaded. */
1045
- private rowProvider;
1046
940
  /** The device was deleted, or its org was: the instance and the files go. */
1047
941
  private deviceGone;
1048
942
  /** Due for instance destruction: an instance (or a create in progress) unused for too long. */