deepline 0.3.44 → 0.3.46

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 (99) hide show
  1. package/dist/bundling-sources/sdk/src/client.ts +2 -3
  2. package/dist/bundling-sources/sdk/src/errors.ts +2 -2
  3. package/dist/bundling-sources/sdk/src/http.ts +1 -1
  4. package/dist/bundling-sources/sdk/src/play.ts +7 -10
  5. package/dist/bundling-sources/sdk/src/plays/bundle-play-file.ts +3 -3
  6. package/dist/bundling-sources/sdk/src/release.ts +3 -3
  7. package/dist/bundling-sources/sdk/src/version.ts +2 -2
  8. package/dist/bundling-sources/shared_libs/play-data-plane/contracts.ts +25 -0
  9. package/dist/bundling-sources/shared_libs/play-data-plane/index.ts +1 -0
  10. package/dist/bundling-sources/shared_libs/play-data-plane/sheet-contract.ts +1 -1
  11. package/dist/bundling-sources/shared_libs/play-runtime/app-runtime-api.ts +19 -19
  12. package/dist/bundling-sources/shared_libs/play-runtime/backend.ts +5 -6
  13. package/dist/bundling-sources/shared_libs/play-runtime/cell-staleness.ts +1 -66
  14. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +1551 -276
  15. package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +14 -3
  16. package/dist/bundling-sources/shared_libs/play-runtime/dataset-id.ts +4 -3
  17. package/dist/bundling-sources/shared_libs/play-runtime/durable-call-cache.ts +3 -4
  18. package/dist/bundling-sources/shared_libs/play-runtime/durable-receipt-execution.ts +2 -2
  19. package/dist/bundling-sources/shared_libs/play-runtime/email-status.ts +1 -275
  20. package/dist/bundling-sources/shared_libs/play-runtime/execution-ledger-store.ts +1 -1
  21. package/dist/bundling-sources/shared_libs/play-runtime/extractor-targets.ts +1 -106
  22. package/dist/bundling-sources/shared_libs/play-runtime/gateway-postgres-admission.ts +1 -2
  23. package/dist/bundling-sources/shared_libs/play-runtime/governor/in-memory-rate-state-backend.ts +13 -4
  24. package/dist/bundling-sources/shared_libs/play-runtime/live-events.ts +1 -5
  25. package/dist/bundling-sources/shared_libs/play-runtime/map-row-identity.ts +2 -3
  26. package/dist/bundling-sources/shared_libs/play-runtime/map-row-outcome.ts +2 -1
  27. package/dist/bundling-sources/shared_libs/play-runtime/modal-runtime-config.ts +1 -1
  28. package/dist/bundling-sources/shared_libs/play-runtime/output-size-limits.ts +1 -1
  29. package/dist/bundling-sources/shared_libs/play-runtime/projection.ts +5 -5
  30. package/dist/bundling-sources/shared_libs/play-runtime/protocol.ts +3 -3
  31. package/dist/bundling-sources/shared_libs/play-runtime/run-failure.ts +1 -1
  32. package/dist/bundling-sources/shared_libs/play-runtime/run-snapshot-stream.ts +1 -1
  33. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-lifecycle.ts +4 -4
  34. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-modal-fallback.ts +3 -3
  35. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-payload-transport.ts +8 -8
  36. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona-session-execution.ts +11 -1
  37. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/daytona.ts +26 -8
  38. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/local-process.ts +7 -7
  39. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/backends/modal.ts +23 -11
  40. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/bundle.ts +13 -2
  41. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/index.ts +2 -2
  42. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/runner-events.ts +1 -1
  43. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/runtime-sandbox-reconciliation.ts +1 -1
  44. package/dist/bundling-sources/shared_libs/play-runtime/runner-backends/types.ts +58 -2
  45. package/dist/bundling-sources/shared_libs/play-runtime/runtime-actions.ts +1 -1
  46. package/dist/bundling-sources/shared_libs/play-runtime/runtime-api.ts +6 -3
  47. package/dist/bundling-sources/shared_libs/play-runtime/runtime-constants.ts +1 -1
  48. package/dist/bundling-sources/shared_libs/play-runtime/runtime-constraints.ts +1 -2
  49. package/dist/bundling-sources/shared_libs/play-runtime/runtime-env.ts +55 -0
  50. package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/contract.ts +418 -0
  51. package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/index.ts +452 -0
  52. package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/runner-backend-adapter.ts +304 -0
  53. package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runs/testkit.ts +83 -0
  54. package/dist/bundling-sources/shared_libs/play-runtime/sandbox-runtime-limits.ts +1 -109
  55. package/dist/bundling-sources/shared_libs/play-runtime/step-program-dataset-builder.ts +1 -1
  56. package/dist/bundling-sources/shared_libs/play-runtime/test-runtime-seams.ts +1 -1
  57. package/dist/bundling-sources/shared_libs/play-runtime/tool-call/always-fresh-adapter.ts +50 -0
  58. package/dist/bundling-sources/shared_libs/play-runtime/tool-call/contract.ts +135 -0
  59. package/dist/bundling-sources/shared_libs/play-runtime/tool-call/index.ts +291 -0
  60. package/dist/bundling-sources/shared_libs/play-runtime/tool-call/native-batch.ts +335 -0
  61. package/dist/bundling-sources/shared_libs/play-runtime/tool-call/receipt-cohort.ts +904 -0
  62. package/dist/bundling-sources/shared_libs/play-runtime/tool-call/runtime-step-receipts-adapter.ts +522 -0
  63. package/dist/bundling-sources/shared_libs/play-runtime/tool-call/testkit.ts +165 -0
  64. package/dist/bundling-sources/shared_libs/play-runtime/tool-execute-retry-policy.ts +1 -1
  65. package/dist/bundling-sources/shared_libs/play-runtime/tool-execution-outcome.ts +6 -5
  66. package/dist/bundling-sources/shared_libs/play-runtime/tool-http-errors.ts +1 -1
  67. package/dist/bundling-sources/shared_libs/play-runtime/tool-result-types.ts +1 -206
  68. package/dist/bundling-sources/shared_libs/play-runtime/tool-result.ts +10 -7
  69. package/dist/bundling-sources/shared_libs/play-runtime/work-receipts.ts +1 -1
  70. package/dist/bundling-sources/shared_libs/plays/artifact-types.ts +8 -3
  71. package/dist/bundling-sources/shared_libs/plays/authoring-contract.ts +4 -4
  72. package/dist/bundling-sources/shared_libs/plays/bundling/index.ts +3 -6
  73. package/dist/bundling-sources/shared_libs/plays/cell-staleness.ts +66 -0
  74. package/dist/bundling-sources/shared_libs/plays/compiler-manifest.ts +1 -1
  75. package/dist/bundling-sources/shared_libs/plays/contracts.ts +2 -2
  76. package/dist/bundling-sources/shared_libs/plays/core.ts +466 -0
  77. package/dist/bundling-sources/shared_libs/plays/email-status.ts +287 -0
  78. package/dist/bundling-sources/shared_libs/plays/extractor-targets.ts +106 -0
  79. package/dist/bundling-sources/shared_libs/plays/row-identity.ts +1 -3
  80. package/dist/bundling-sources/shared_libs/plays/runtime-constraints.ts +2 -0
  81. package/dist/bundling-sources/shared_libs/plays/runtime-validation.ts +4 -2
  82. package/dist/bundling-sources/shared_libs/plays/sandbox-runtime-limits.ts +109 -0
  83. package/dist/bundling-sources/shared_libs/plays/tool-execution-error.ts +624 -0
  84. package/dist/bundling-sources/shared_libs/plays/tool-result-types.ts +206 -0
  85. package/dist/bundling-sources/shared_libs/security/safe-outbound-fetch.ts +1 -1
  86. package/dist/cli/index.js +174 -168
  87. package/dist/cli/index.mjs +182 -169
  88. package/dist/{compiler-manifest-DwYe2C2S.d.mts → compiler-manifest-BuoqasqI.d.mts} +585 -540
  89. package/dist/{compiler-manifest-DwYe2C2S.d.ts → compiler-manifest-BuoqasqI.d.ts} +585 -540
  90. package/dist/index.d.mts +9 -2
  91. package/dist/index.d.ts +9 -2
  92. package/dist/index.js +47 -40
  93. package/dist/index.mjs +47 -40
  94. package/dist/install-integrity.json +24 -3
  95. package/dist/plays/bundle-play-file.d.mts +4 -61
  96. package/dist/plays/bundle-play-file.d.ts +4 -61
  97. package/dist/plays/bundle-play-file.mjs +157 -155
  98. package/package.json +9 -6
  99. /package/dist/bundling-sources/shared_libs/{play-runtime → plays}/tool-response-contract.ts +0 -0
@@ -0,0 +1,418 @@
1
+ /**
2
+ * Sandbox Runs is the portable lifecycle boundary around a physical execution
3
+ * resource. It is deliberately narrower than the scheduler attempt: it does
4
+ * not claim an attempt, choose retry policy, write a terminal, or delete a
5
+ * sandbox. Its one non-negotiable rule is that a resource fact is durable
6
+ * before the runner command can be accepted.
7
+ */
8
+
9
+ export type SandboxProvider = 'daytona' | 'modal' | 'local';
10
+
11
+ /** A portable, credential-free description of one execution resource. */
12
+ export type SandboxRunResource = {
13
+ provider: SandboxProvider;
14
+ resourceId: string;
15
+ billingStartedAtMs: number;
16
+ /** Provider ownership domain used later by the cleanup Adapter. */
17
+ routingDomain: string | null;
18
+ /** The scheduler's already-reserved soft-capacity slot, if managed. */
19
+ capacityLeaseId?: string;
20
+ maxBillingDurationSeconds?: number | null;
21
+ };
22
+
23
+ /** The scheduler's already claimed attempt; it is never a provider credential. */
24
+ export type SandboxRunInput = {
25
+ attempt: {
26
+ runId: string;
27
+ number: number;
28
+ };
29
+ /** Opaque scheduler authority that the resource-fact Adapter fences. */
30
+ authority: {
31
+ fenceId: string;
32
+ };
33
+ };
34
+
35
+ /** A pre-code rejection is safe for the attempt policy to defer or retry. */
36
+ export type SandboxPreCodeDeferralReason =
37
+ | 'capacity'
38
+ | 'provider_unavailable'
39
+ | 'rate_limited'
40
+ | 'startup_timeout';
41
+
42
+ export type SandboxAcquisition<Handle> =
43
+ | {
44
+ kind: 'acquired';
45
+ resource: SandboxRunResource;
46
+ /** Private to the acquire/start Adapters; never persisted by this job. */
47
+ handle: Handle;
48
+ }
49
+ | { kind: 'pre_code_deferred'; reason: SandboxPreCodeDeferralReason }
50
+ /**
51
+ * A provider create may have crossed a local timeout. Its Adapter has kept
52
+ * a durable reconciliation obligation; this job must not acquire again.
53
+ */
54
+ | { kind: 'acquisition_unknown'; reason: string };
55
+
56
+ /** The durable resource writer also binds capacity in the same fence. */
57
+ export type SandboxResourceFacts = {
58
+ record(input: {
59
+ attempt: SandboxRunInput['attempt'];
60
+ authority: SandboxRunInput['authority'];
61
+ resource: SandboxRunResource;
62
+ }): Promise<{ kind: 'recorded' } | { kind: 'fence_lost' }>;
63
+ };
64
+
65
+ /** A scheduler-owned observation target, not a provider command or payload. */
66
+ export type SandboxRunnerObservation = {
67
+ boundaryId: string;
68
+ baselineHeartbeatAt: string | null;
69
+ };
70
+
71
+ export type SandboxRunnerStart<Handle> = {
72
+ start(input: {
73
+ attempt: SandboxRunInput['attempt'];
74
+ resource: SandboxRunResource;
75
+ handle: Handle;
76
+ }): Promise<
77
+ | { kind: 'command_accepted'; observation: SandboxRunnerObservation }
78
+ /** The command is known not to have been accepted; cleanup owns resource release. */
79
+ | { kind: 'not_started'; reason: string }
80
+ /** Command acceptance cannot be proven either way; never acquire/replay. */
81
+ | { kind: 'start_unknown'; reason: string }
82
+ >;
83
+ };
84
+
85
+ export type SandboxRunnerObserver = {
86
+ observe(input: {
87
+ attempt: SandboxRunInput['attempt'];
88
+ resource: SandboxRunResource;
89
+ observation: SandboxRunnerObservation;
90
+ }): Promise<
91
+ | { kind: 'heartbeat_observed'; heartbeatAt: string }
92
+ | {
93
+ kind: 'terminal_observed';
94
+ terminal: 'completed' | 'failed' | 'cancelled';
95
+ }
96
+ /** The command could already be executing; caller must not replay it. */
97
+ | { kind: 'unconfirmed'; reason: string }
98
+ >;
99
+ };
100
+
101
+ export type SandboxRunDependencies<Handle> = {
102
+ acquire: {
103
+ acquire(input: SandboxRunInput): Promise<SandboxAcquisition<Handle>>;
104
+ };
105
+ resourceFacts: SandboxResourceFacts;
106
+ runner: SandboxRunnerStart<Handle>;
107
+ observer: SandboxRunnerObserver;
108
+ };
109
+
110
+ /** Canonical lifecycle outcomes consumed by the attempt policy. */
111
+ export type SandboxRunOutcome =
112
+ | { kind: 'pre_code_deferred'; reason: SandboxPreCodeDeferralReason }
113
+ | { kind: 'acquisition_unknown'; reason: string }
114
+ /** A physical resource exists but the scheduler fence rejected its fact. */
115
+ | { kind: 'resource_recording_rejected'; resource: SandboxRunResource }
116
+ /** Resource fact exists; no command was accepted; cleanup is now authoritative. */
117
+ | {
118
+ kind: 'post_record_start_failed';
119
+ resource: SandboxRunResource;
120
+ reason: string;
121
+ }
122
+ /** Resource fact exists and command acceptance is ambiguous; no replay is safe. */
123
+ | {
124
+ kind: 'runner_start_unknown';
125
+ resource: SandboxRunResource;
126
+ reason: string;
127
+ }
128
+ | {
129
+ kind: 'parked';
130
+ resource: SandboxRunResource;
131
+ observation: SandboxRunnerObservation;
132
+ heartbeatAt: string;
133
+ }
134
+ | {
135
+ kind: 'terminal_observed';
136
+ resource: SandboxRunResource;
137
+ terminal: 'completed' | 'failed' | 'cancelled';
138
+ }
139
+ | {
140
+ kind: 'runner_start_unconfirmed';
141
+ resource: SandboxRunResource;
142
+ observation: SandboxRunnerObservation;
143
+ reason: string;
144
+ };
145
+
146
+ export type SandboxRunsJob = {
147
+ execute(input: SandboxRunInput): Promise<SandboxRunOutcome>;
148
+ };
149
+
150
+ /**
151
+ * The rich Sandbox Runs boundary used by the real runner adapters.
152
+ *
153
+ * The legacy four-port contract above remains exported while callers migrate,
154
+ * but it cannot describe a production sandbox launch: Daytona may retire and
155
+ * recreate sandboxes, and Modal must record an ambiguity fence before create
156
+ * can begin. This contract keeps those facts explicit without importing a
157
+ * scheduler, provider SDK, or runner payload into the portable library.
158
+ */
159
+
160
+ export type SandboxExecutionMode<Checkpoint, Suspension> =
161
+ | { kind: 'fresh'; checkpoint: Checkpoint | null }
162
+ | {
163
+ kind: 'continuation';
164
+ checkpoint: Checkpoint;
165
+ /** A scheduler continuation can resume after a non-sandbox boundary. */
166
+ suspension: Suspension | null;
167
+ }
168
+ | {
169
+ /** Read persisted runner state; never create another sandbox first. */
170
+ kind: 'detached_observation';
171
+ checkpoint: Checkpoint;
172
+ suspension: Suspension;
173
+ };
174
+
175
+ /** The launch is opaque here; only the runner/provider Adapter may interpret it. */
176
+ export type SandboxExecutionInput<Launch, Checkpoint, Suspension> =
177
+ SandboxRunInput & {
178
+ launch: Launch;
179
+ mode: SandboxExecutionMode<Checkpoint, Suspension>;
180
+ };
181
+
182
+ /**
183
+ * A resource fact has enough identity to be recovered and deleted safely. It
184
+ * deliberately excludes provider handles, commands, credentials, and payloads.
185
+ */
186
+ export type SandboxExecutionResource = SandboxRunResource & {
187
+ kind: 'daytona_sandbox' | 'modal_sandbox' | 'local_process';
188
+ runtimeEnvironment?: 'preview' | 'production';
189
+ billingEndedAtMs?: number | null;
190
+ cpu?: number | null;
191
+ memoryGiB?: number | null;
192
+ diskGiB?: number | null;
193
+ /** A create settled after the launching attempt had already timed out. */
194
+ lateAcquired?: boolean;
195
+ };
196
+
197
+ export type SandboxCreateIntent = {
198
+ provider: 'modal';
199
+ routingDomain: string;
200
+ runtimeEnvironment: 'preview' | 'production';
201
+ /** Stable, non-secret provider correlation attributes only. */
202
+ correlation: Record<string, string>;
203
+ capacityLeaseId?: string;
204
+ };
205
+
206
+ export type SandboxProviderLifecycleEvent = {
207
+ provider: 'daytona' | 'modal';
208
+ type: 'create_call_started' | 'create_call_succeeded' | 'create_call_failed';
209
+ providerAttempt: number;
210
+ occurredAtMs: number;
211
+ resourceId?: string;
212
+ errorClass?: 'timeout' | 'capacity' | 'rate_limit' | 'other';
213
+ };
214
+
215
+ export type SandboxExecutionAdmission = {
216
+ beforeFirstProviderCreate(input: {
217
+ attempt: SandboxRunInput['attempt'];
218
+ authority: SandboxRunInput['authority'];
219
+ }): Promise<
220
+ | { kind: 'allowed' }
221
+ | { kind: 'pre_code_deferred'; reason: SandboxPreCodeDeferralReason }
222
+ >;
223
+ reserveCapacity(input: {
224
+ provider: Exclude<SandboxProvider, 'local'>;
225
+ /** Distinguishes provider retries within one scheduler attempt. */
226
+ providerAttempt?: number;
227
+ }): Promise<
228
+ | {
229
+ kind: 'reserved';
230
+ leaseId: string;
231
+ /** Stable provider correlation for operation-first managed creates. */
232
+ providerOperationToken?: string | null;
233
+ }
234
+ | { kind: 'pre_code_deferred'; reason: SandboxPreCodeDeferralReason }
235
+ >;
236
+ releaseCapacity(input: { leaseId: string }): Promise<void>;
237
+ claimProviderCircuit(input: {
238
+ provider: Exclude<SandboxProvider, 'local'>;
239
+ }): Promise<{ allowed: boolean; probeToken: string | null }>;
240
+ markProviderHealthy(input: {
241
+ provider: Exclude<SandboxProvider, 'local'>;
242
+ probeToken: string | null;
243
+ }): Promise<void>;
244
+ };
245
+
246
+ export type SandboxExecutionResourceFacts = {
247
+ record(input: {
248
+ attempt: SandboxRunInput['attempt'];
249
+ authority: SandboxRunInput['authority'];
250
+ resource: SandboxExecutionResource;
251
+ }): Promise<{ kind: 'recorded' } | { kind: 'fence_lost' }>;
252
+ /** A late create must become a cleanup obligation, never an invisible resource. */
253
+ recordLate(input: {
254
+ attempt: SandboxRunInput['attempt'];
255
+ authority: SandboxRunInput['authority'];
256
+ resource: SandboxExecutionResource;
257
+ }): Promise<{ kind: 'recorded' } | { kind: 'fence_lost' }>;
258
+ };
259
+
260
+ export type SandboxExecutionCreateIntents = {
261
+ record(input: {
262
+ attempt: SandboxRunInput['attempt'];
263
+ authority: SandboxRunInput['authority'];
264
+ intent: SandboxCreateIntent;
265
+ }): Promise<{ kind: 'recorded' } | { kind: 'fence_lost' }>;
266
+ resolve(input: {
267
+ attempt: SandboxRunInput['attempt'];
268
+ authority: SandboxRunInput['authority'];
269
+ }): Promise<{ kind: 'resolved' } | { kind: 'fence_lost' }>;
270
+ };
271
+
272
+ export type SandboxExecutionLifecycleEvents = {
273
+ record(input: {
274
+ attempt: SandboxRunInput['attempt'];
275
+ authority: SandboxRunInput['authority'];
276
+ event: SandboxProviderLifecycleEvent;
277
+ }): Promise<{ kind: 'recorded' } | { kind: 'fence_lost' }>;
278
+ };
279
+
280
+ /** The only capability a provider Adapter receives while executing a launch. */
281
+ export type SandboxExecutionLifecycle = {
282
+ beforeFirstProviderCreate(): Promise<
283
+ | { kind: 'allowed' }
284
+ | { kind: 'pre_code_deferred'; reason: SandboxPreCodeDeferralReason }
285
+ >;
286
+ reserveCapacity(input: {
287
+ provider: Exclude<SandboxProvider, 'local'>;
288
+ /** Preserves one provider-create retry's durable operation identity. */
289
+ providerAttempt?: number;
290
+ }): Promise<
291
+ | {
292
+ kind: 'reserved';
293
+ leaseId: string;
294
+ /** Stable provider correlation for operation-first managed creates. */
295
+ providerOperationToken?: string | null;
296
+ }
297
+ | { kind: 'pre_code_deferred'; reason: SandboxPreCodeDeferralReason }
298
+ >;
299
+ releaseCapacity(input: { leaseId: string }): Promise<void>;
300
+ claimProviderCircuit(input: {
301
+ provider: Exclude<SandboxProvider, 'local'>;
302
+ }): Promise<{ allowed: boolean; probeToken: string | null }>;
303
+ markProviderHealthy(input: {
304
+ provider: Exclude<SandboxProvider, 'local'>;
305
+ probeToken: string | null;
306
+ }): Promise<void>;
307
+ recordCreateIntent(input: SandboxCreateIntent): Promise<void>;
308
+ resolveCreateIntent(): Promise<void>;
309
+ recordProviderLifecycleEvent(
310
+ input: SandboxProviderLifecycleEvent,
311
+ ): Promise<void>;
312
+ /** Must resolve before the Adapter can accept a command for this resource. */
313
+ recordResource(input: SandboxExecutionResource): Promise<void>;
314
+ /** Same durable rule for a create that settles after the caller timed out. */
315
+ recordLateResource(input: SandboxExecutionResource): Promise<void>;
316
+ /**
317
+ * Marks the non-replayable boundary. Remote providers require a previously
318
+ * recorded resource; local execution has no physical sandbox resource.
319
+ */
320
+ commandAccepted(input: {
321
+ provider: SandboxProvider;
322
+ resource?: SandboxExecutionResource;
323
+ }): void;
324
+ /** A detached runner cannot be parked until scheduler-owned readiness exists. */
325
+ runnerReady(input: {
326
+ provider: Exclude<SandboxProvider, 'local'>;
327
+ resource: SandboxExecutionResource;
328
+ observation: SandboxRunnerObservation;
329
+ }): void;
330
+ };
331
+
332
+ /** Outcome returned by the provider/runner Adapter after exactly one execution. */
333
+ export type SandboxExecutionPortOutcome<RunnerResult> =
334
+ | { kind: 'pre_code_deferred'; reason: SandboxPreCodeDeferralReason }
335
+ | { kind: 'acquisition_unknown'; reason: string }
336
+ /** Provider or customer code may have started. The attempt must not replay. */
337
+ | { kind: 'post_code_unknown'; reason: string }
338
+ | {
339
+ kind: 'suspended';
340
+ runnerResult: RunnerResult;
341
+ /**
342
+ * Only a detached runner needs a scheduler-owned liveness proof before
343
+ * the worker parks. Ordinary Play boundaries (sleep, signal, etc.) do
344
+ * not create or observe a long-lived sandbox command.
345
+ */
346
+ requiresDetachedRunnerReadiness?: boolean;
347
+ }
348
+ | { kind: 'terminal'; runnerResult: RunnerResult };
349
+
350
+ /**
351
+ * One invocation of the existing runner backend, not separate acquire/start
352
+ * calls. This preserves the provider boundary while moving its durable
353
+ * lifecycle callbacks behind the Sandbox Runs Module.
354
+ */
355
+ export type SandboxExecutionPort<Launch, Checkpoint, Suspension, RunnerResult> =
356
+ {
357
+ execute(input: {
358
+ execution: SandboxExecutionInput<Launch, Checkpoint, Suspension>;
359
+ lifecycle: SandboxExecutionLifecycle;
360
+ }): Promise<SandboxExecutionPortOutcome<RunnerResult>>;
361
+ };
362
+
363
+ export type SandboxExecutionDependencies<
364
+ Launch,
365
+ Checkpoint,
366
+ Suspension,
367
+ RunnerResult,
368
+ > = {
369
+ execution: SandboxExecutionPort<Launch, Checkpoint, Suspension, RunnerResult>;
370
+ /** Every resource record binds its capacity lease in the scheduler fence. */
371
+ resourceFacts: SandboxExecutionResourceFacts;
372
+ /** Required when the Adapter crosses Modal's ambiguous-create boundary. */
373
+ createIntents?: SandboxExecutionCreateIntents;
374
+ /** Required when the Adapter emits provider-edge lifecycle evidence. */
375
+ lifecycleEvents?: SandboxExecutionLifecycleEvents;
376
+ /** Required when the Adapter opts into admission, capacity, or circuit policy. */
377
+ admission?: SandboxExecutionAdmission;
378
+ };
379
+
380
+ export type SandboxExecutionOutcome<RunnerResult> =
381
+ | { kind: 'pre_code_deferred'; reason: SandboxPreCodeDeferralReason }
382
+ | { kind: 'acquisition_unknown'; reason: string }
383
+ | {
384
+ kind: 'post_code_unknown';
385
+ reason: string;
386
+ resources: readonly SandboxExecutionResource[];
387
+ }
388
+ | {
389
+ kind: 'resource_recording_rejected';
390
+ resources: readonly SandboxExecutionResource[];
391
+ }
392
+ | {
393
+ kind: 'suspended';
394
+ runnerResult: RunnerResult;
395
+ resources: readonly SandboxExecutionResource[];
396
+ }
397
+ | {
398
+ kind: 'terminal';
399
+ runnerResult: RunnerResult;
400
+ resources: readonly SandboxExecutionResource[];
401
+ };
402
+
403
+ export type SandboxExecutionJob<Launch, Checkpoint, Suspension, RunnerResult> =
404
+ {
405
+ execute(
406
+ input: SandboxExecutionInput<Launch, Checkpoint, Suspension>,
407
+ ): Promise<SandboxExecutionOutcome<RunnerResult>>;
408
+ };
409
+
410
+ /** A fence loss must stop the Adapter before it can accept a provider command. */
411
+ export class SandboxResourceFenceLostError extends Error {
412
+ constructor() {
413
+ super(
414
+ 'Sandbox Runs lost its scheduler fence while recording a durable lifecycle fact.',
415
+ );
416
+ this.name = 'SandboxResourceFenceLostError';
417
+ }
418
+ }