@intentic/sandbox-contract 1.395.0 → 1.397.0

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/README.md +11 -0
  2. package/dist/app-routes/index.d.ts +1 -0
  3. package/dist/app-routes/index.d.ts.map +1 -1
  4. package/dist/app-routes/index.js +1 -0
  5. package/dist/app-routes/index.js.map +1 -1
  6. package/dist/app-routes/sandbox-segment.d.ts +9 -0
  7. package/dist/app-routes/sandbox-segment.d.ts.map +1 -0
  8. package/dist/app-routes/sandbox-segment.js +52 -0
  9. package/dist/app-routes/sandbox-segment.js.map +1 -0
  10. package/dist/contracts/agents.contract.d.ts +98 -0
  11. package/dist/contracts/agents.contract.d.ts.map +1 -1
  12. package/dist/contracts/agents.contract.js +1 -1
  13. package/dist/contracts/agents.contract.js.map +1 -1
  14. package/dist/contracts/device.contract.d.ts +1 -0
  15. package/dist/contracts/device.contract.d.ts.map +1 -1
  16. package/dist/contracts/providers.contract.d.ts +2 -0
  17. package/dist/contracts/providers.contract.d.ts.map +1 -1
  18. package/dist/contracts/providers.contract.js +1 -0
  19. package/dist/contracts/providers.contract.js.map +1 -1
  20. package/dist/contracts/runner.contract.d.ts +2818 -125
  21. package/dist/contracts/runner.contract.d.ts.map +1 -1
  22. package/dist/contracts/runner.contract.js +4 -1
  23. package/dist/contracts/runner.contract.js.map +1 -1
  24. package/dist/contracts/seal.contract.d.ts +25 -0
  25. package/dist/contracts/seal.contract.d.ts.map +1 -1
  26. package/dist/contracts/settings.contract.d.ts +8 -0
  27. package/dist/contracts/settings.contract.d.ts.map +1 -1
  28. package/dist/contracts/system.contract.d.ts +23 -0
  29. package/dist/contracts/system.contract.d.ts.map +1 -1
  30. package/dist/events/agent-events.d.ts +6 -0
  31. package/dist/events/agent-events.d.ts.map +1 -1
  32. package/dist/events/agent-events.js +7 -1
  33. package/dist/events/agent-events.js.map +1 -1
  34. package/dist/events/agent-transcript.d.ts +1 -0
  35. package/dist/events/agent-transcript.d.ts.map +1 -1
  36. package/dist/events/resume.d.ts +1 -0
  37. package/dist/events/resume.d.ts.map +1 -1
  38. package/dist/events/resume.js +2 -0
  39. package/dist/events/resume.js.map +1 -1
  40. package/dist/events/sandbox-notice.d.ts +7 -0
  41. package/dist/events/sandbox-notice.d.ts.map +1 -1
  42. package/dist/events/sandbox-notice.js +2 -0
  43. package/dist/events/sandbox-notice.js.map +1 -1
  44. package/dist/events/system-events.d.ts +20 -0
  45. package/dist/events/system-events.d.ts.map +1 -1
  46. package/dist/events/transcript.d.ts +1 -0
  47. package/dist/events/transcript.d.ts.map +1 -1
  48. package/dist/events/transcript.js +2 -1
  49. package/dist/events/transcript.js.map +1 -1
  50. package/dist/models/key-providers.d.ts +17 -0
  51. package/dist/models/key-providers.d.ts.map +1 -0
  52. package/dist/models/key-providers.js +65 -0
  53. package/dist/models/key-providers.js.map +1 -0
  54. package/dist/policy/failure-codes.d.ts +8 -0
  55. package/dist/policy/failure-codes.d.ts.map +1 -1
  56. package/dist/policy/failure-codes.js +9 -0
  57. package/dist/policy/failure-codes.js.map +1 -1
  58. package/dist/policy/safety-policy.d.ts +2 -1
  59. package/dist/policy/safety-policy.d.ts.map +1 -1
  60. package/dist/policy/safety-policy.js +6 -0
  61. package/dist/policy/safety-policy.js.map +1 -1
  62. package/dist/protocol/doors/runner-protocol.d.ts +18 -0
  63. package/dist/protocol/doors/runner-protocol.d.ts.map +1 -1
  64. package/dist/protocol/doors/runner-protocol.js +15 -1
  65. package/dist/protocol/doors/runner-protocol.js.map +1 -1
  66. package/dist/schemas/agent-search.d.ts +4 -0
  67. package/dist/schemas/agent-search.d.ts.map +1 -1
  68. package/dist/schemas/agent-search.js +9 -2
  69. package/dist/schemas/agent-search.js.map +1 -1
  70. package/dist/schemas/agents-list.d.ts +10 -0
  71. package/dist/schemas/agents-list.d.ts.map +1 -1
  72. package/dist/schemas/agents.d.ts +17 -0
  73. package/dist/schemas/agents.d.ts.map +1 -1
  74. package/dist/schemas/agents.js +8 -1
  75. package/dist/schemas/agents.js.map +1 -1
  76. package/dist/schemas/device-resources.d.ts +5 -0
  77. package/dist/schemas/device-resources.d.ts.map +1 -1
  78. package/dist/schemas/device-resources.js +16 -0
  79. package/dist/schemas/device-resources.js.map +1 -1
  80. package/dist/schemas/devices.d.ts +14 -0
  81. package/dist/schemas/devices.d.ts.map +1 -1
  82. package/dist/schemas/devices.js.map +1 -1
  83. package/dist/schemas/metrics.js +1 -1
  84. package/dist/schemas/metrics.js.map +1 -1
  85. package/dist/schemas/settings.d.ts +8 -0
  86. package/dist/schemas/settings.d.ts.map +1 -1
  87. package/dist/schemas/settings.js +4 -3
  88. package/dist/schemas/settings.js.map +1 -1
  89. package/dist/schemas/turn-break.d.ts +9 -0
  90. package/dist/schemas/turn-break.d.ts.map +1 -1
  91. package/dist/schemas/turn-break.js +9 -2
  92. package/dist/schemas/turn-break.js.map +1 -1
  93. package/dist/state/definition.d.ts +4 -0
  94. package/dist/state/definition.d.ts.map +1 -1
  95. package/dist/text/notice-rows.d.ts +1 -1
  96. package/dist/text/notice-rows.d.ts.map +1 -1
  97. package/dist/text/notice-rows.js +6 -1
  98. package/dist/text/notice-rows.js.map +1 -1
  99. package/package.json +5 -5
  100. package/src/app-routes/index.ts +4 -2
  101. package/src/app-routes/sandbox-segment.test.ts +77 -0
  102. package/src/app-routes/sandbox-segment.ts +82 -0
  103. package/src/contracts/agents.contract.ts +1 -1
  104. package/src/contracts/providers.contract.ts +5 -0
  105. package/src/contracts/runner.contract.ts +12 -0
  106. package/src/events/agent-events.ts +14 -1
  107. package/src/events/resume.test.ts +22 -0
  108. package/src/events/resume.ts +11 -0
  109. package/src/events/sandbox-notice.ts +7 -0
  110. package/src/events/transcript.ts +2 -1
  111. package/src/models/key-providers.ts +97 -0
  112. package/src/policy/failure-codes.ts +26 -0
  113. package/src/policy/safety-policy.ts +11 -0
  114. package/src/policy/tests/command-classes.test.ts +15 -0
  115. package/src/policy/tests/failure-codes.test.ts +23 -2
  116. package/src/policy/tests/safety-policy.test.ts +9 -1
  117. package/src/protocol/doors/runner-protocol.ts +28 -1
  118. package/src/schemas/agent-search.test.ts +22 -0
  119. package/src/schemas/agent-search.ts +23 -4
  120. package/src/schemas/agents.ts +17 -1
  121. package/src/schemas/device-resources.ts +28 -0
  122. package/src/schemas/devices.ts +2 -1
  123. package/src/schemas/ic-shape-args.test.ts +17 -2
  124. package/src/schemas/metrics.ts +1 -1
  125. package/src/schemas/settings.test.ts +15 -0
  126. package/src/schemas/settings.ts +15 -3
  127. package/src/schemas/turn-break.ts +30 -4
  128. package/src/text/notice-rows.ts +12 -4
@@ -185,7 +185,14 @@ export type RunnerSync = z.infer<typeof RunnerSyncSchema>;
185
185
 
186
186
  export const RunnerSyncLineSchema = z.union([
187
187
  z.object({ kind: z.literal("line"), text: z.string() }),
188
- z.object({ kind: z.literal("done"), ok: z.boolean(), detail: z.string().optional() }),
188
+ z.object({
189
+ kind: z.literal("done"),
190
+ ok: z.boolean(),
191
+ detail: z.string().optional(),
192
+ // Why a pull touched nothing: the conversation's previous turn is still running on the runner, in the checkout
193
+ // a pull would reset. The parent collects a held turn before it pulls (runner-dispatch.ts), so this is a guard.
194
+ code: z.enum(["busy"]).optional(),
195
+ }),
189
196
  ]);
190
197
  export type RunnerSyncLine = z.infer<typeof RunnerSyncLineSchema>;
191
198
 
@@ -211,6 +218,26 @@ export const RunnerTurnSchema = z.object({
211
218
  });
212
219
  export type RunnerTurn = z.infer<typeof RunnerTurnSchema>;
213
220
 
221
+ // A turn the runner holds for a conversation, which outlives the socket it was dispatched over: the runner runs it to
222
+ // its end whoever is listening, and keeps every frame it produced until the parent has collected the turn's branch, so a
223
+ // `finished` one is always one the parent has not collected yet (a restart, a wait that ran out). `events` counts those
224
+ // frames; a parent that saw N of them re-attaches with `after: N` and misses nothing.
225
+ export const RunnerHeldTurnSchema = z.object({
226
+ state: z.enum(["none", "live", "finished"]),
227
+ events: z.number().int().nonnegative(),
228
+ // How many the parent last said it has (runnerContract.ackTurn): where a parent that lost its own count, a restart,
229
+ // reads on from without repeating what it already drew.
230
+ acked: z.number().int().nonnegative(),
231
+ });
232
+ export type RunnerHeldTurn = z.infer<typeof RunnerHeldTurnSchema>;
233
+
234
+ export const RunnerAttachSchema = z.object({
235
+ conversationId: z.string().min(1),
236
+ // How many of the turn's frames the parent already has; the replay starts with the next one.
237
+ after: z.number().int().nonnegative(),
238
+ });
239
+ export type RunnerAttach = z.infer<typeof RunnerAttachSchema>;
240
+
214
241
  // OFFLOADED COMMANDS: one shell line the parent hands a runner instead of running it itself (settings `offload`). The
215
242
  // code travels as a snapshot commit of the parent's working tree, uncommitted and untracked work included, parked under
216
243
  // this ref in the repo's git dir for the runner to fetch through the git door, and deleted once the run ends.
@@ -0,0 +1,22 @@
1
+ import { indexOfTerm, searchable, searchTermOf } from "./agent-search.js";
2
+
3
+ // Spaces are part of what was asked for: trimmed away, " ui " could only ever mean "ui", inside "build" and "quit" too.
4
+ test("a term keeps its spaces at the ends and folds a run of them to one", () => {
5
+ expect(searchTermOf(" ui ")).toBe(" ui ");
6
+ expect(searchTermOf("fix the\tbug ")).toBe("fix the bug ");
7
+ });
8
+
9
+ test("spaces never count toward the floor", () => {
10
+ expect(searchable("ui")).toBe(true);
11
+ expect(searchable(" a ")).toBe(false);
12
+ expect(searchable(" ")).toBe(false);
13
+ });
14
+
15
+ // A line's own ends read as spaces, so asking for the word still finds it where a line opens or closes with it.
16
+ test("a spaced term finds the whole word, the line's own ends counting as spaces", () => {
17
+ expect(indexOfTerm("rebuild the ui panel", " ui ")).toBe(11);
18
+ expect(indexOfTerm("rebuild the quiet panel", " ui ")).toBe(-1);
19
+ expect(indexOfTerm("ui first", " ui ")).toBe(0);
20
+ expect(indexOfTerm("make a ui", " ui ")).toBe(6);
21
+ expect(indexOfTerm("build", "ui")).toBe(1);
22
+ });
@@ -2,14 +2,33 @@ import { z } from "zod";
2
2
 
3
3
  // The board's search over what conversations said: the query, and what came back with its evidence.
4
4
 
5
+ // Spaces count, at the ends too: " ui " is the word, not "build" or "quit", and a box that trimmed them made the one
6
+ // cheap way to say "a whole word" impossible. A run of whitespace reads as one space, because every searched line is
7
+ // collapsed the same way, and a line's own start and end read as a space, so " fix" still finds a line opening "fix".
8
+ // One rule for the board's local tier, the daemon's index and its overlay, so the tiers never disagree on a hit.
9
+ export const MIN_SEARCH_CHARS = 2;
10
+
11
+ // The query as it is matched: whitespace runs folded to one space, never trimmed.
12
+ export const searchTermOf = (query: string): string => query.replace(/\s+/gu, " ");
13
+
14
+ // Whether a term is long enough to search: its spaces don't count toward the floor, or " a" would match most lines.
15
+ export const searchable = (term: string): boolean => term.trim().length >= MIN_SEARCH_CHARS;
16
+
17
+ // Where `term` starts in `line`, reading the line's ends as spaces; -1 when absent. Both are already folded to the
18
+ // same case.
19
+ export const indexOfTerm = (line: string, term: string): number => {
20
+ const at = ` ${line} `.indexOf(term);
21
+ return at === -1 ? -1 : Math.min(line.length, Math.max(0, at - 1));
22
+ };
23
+
5
24
  // Searches only speech, both sides of the conversation, never thinking, tool output or protocol text, which would
6
- // otherwise match nearly the whole board. Two-char minimum; `caseSensitive` off means case-insensitive, matching
7
- // workspace search's own switch.
25
+ // otherwise match nearly the whole board. Two characters besides spaces at least, the spaces kept as typed;
26
+ // `caseSensitive` off means case-insensitive, matching workspace search's own switch.
8
27
  export const AgentSearchQuerySchema = z.object({
9
28
  query: z
10
29
  .string()
11
- .trim()
12
- .min(2)
30
+ .min(MIN_SEARCH_CHARS)
31
+ .refine(searchable, { message: "Too short to search: two characters besides spaces." })
13
32
  .describe(
14
33
  "What to look for. Searched against what was said, both sides of the conversation, and nothing else: not the thinking, not the tool output, which between them name nearly every identifier in the workspace and would return most of the board.",
15
34
  ),
@@ -7,7 +7,7 @@ import { AgentHarnessSchema, AgentOriginSchema, AgentProviderSchema, Conversatio
7
7
  import { FROM_BRANCHES_DESCRIPTION } from "./conversation-links.js";
8
8
  import { RepoBranchSchema } from "./shared.js";
9
9
  import { LoopStateSchema } from "./loops.js";
10
- import { LimitPolicySchema, RetryPolicySchema, RoomPolicySchema, TurnBreakPolicySchema, TurnBreakSchema } from "./turn-break.js";
10
+ import { LimitPolicySchema, MemoryKillPolicySchema, RetryPolicySchema, RoomPolicySchema, TurnBreakPolicySchema, TurnBreakSchema } from "./turn-break.js";
11
11
  import { KeepWarmSchema } from "./keep-warm.js";
12
12
  import { AgentNeedSchema } from "./needs.js";
13
13
  import { StrandedCloneSchema } from "./stranded-clone.js";
@@ -281,6 +281,16 @@ export const AgentSummarySchema = z.object({
281
281
  .describe(
282
282
  "Whether `failure` is the sandbox's own sentence rather than the provider's or the harness's words. Absent for theirs, and for an ending recorded before it was said.",
283
283
  ),
284
+ // How many turns in a row ended on this same failure with nothing run (failure-codes.ts failureFingerprint): the chat
285
+ // stops offering Continue at two, since a third press would only fail the same way, and offers the ways out instead.
286
+ failureRepeats: z
287
+ .number()
288
+ .int()
289
+ .min(2)
290
+ .optional()
291
+ .describe(
292
+ "How many turns in a row have ended on this same failure before the model answered. Absent until it has happened twice: sending again would most likely fail the same way.",
293
+ ),
284
294
  // Epoch seconds the spent allowance reopens; absent means genuinely unknown (Grok, Cursor) — never guess one.
285
295
  limitResetsAt: z.number().optional().describe("When the spent allowance reopens, in epoch seconds. Absent when the provider publishes no instant."),
286
296
  limitHeld: z.boolean().optional().describe("Whether the refused turn is held whole, so sending again re-runs it instead of appending to it."),
@@ -339,6 +349,12 @@ export const AgentSummarySchema = z.object({
339
349
  outagePolicy: RetryPolicySchema.optional(),
340
350
  stopPolicy: RetryPolicySchema.optional(),
341
351
  memoryPolicy: RoomPolicySchema.optional(),
352
+ // Carried like the four above, so the chat's control and the board's menu show this conversation's own answer to a
353
+ // memory kill rather than the sandbox's: without it the card could only ever say the sandbox-wide answer, and an
354
+ // answer given in one window read as unchanged in every other until the setting itself moved.
355
+ memoryKillPolicy: MemoryKillPolicySchema.optional().describe(
356
+ "This conversation's own answer to a turn the sandbox killed because it ran out of memory: `resume` sends it again by itself once memory has stayed free, `wait` holds it for a press. Absent means it follows the sandbox-wide setting.",
357
+ ),
342
358
  // A collaborator's ask to land (collaborators can't merge themselves); cleared by whichever merge or discard
343
359
  // answers it.
344
360
  landRequested: z
@@ -17,11 +17,23 @@ export const SandboxResourcesAskFieldsSchema = z.object({
17
17
  // docker's answer: a directive the approved environment demands rides beside it (`overlayRuntime`), and a host
18
18
  // without the NVIDIA runtime drops the GPU. `ic` stores it, validates it against the image's run contract when it is
19
19
  // saved, and prints it in `ic sandbox list --json`; nobody else merges anything into it.
20
+ //
21
+ // `swapGib` (2026-11-05) is the one field that may be absent: ABSENT is an ic or a machine agent from before it, which
22
+ // neither reports nor takes it (an older agent's reading strips it, and its strict order schema refuses it), so a caller
23
+ // sends it only to a machine whose report carried it. `null` is the default, a value is the owner's ask.
20
24
  export const SandboxShapeSchema = z.object({
21
25
  memoryGib: z.int().positive().nullable(),
22
26
  cpus: z.int().positive().nullable(),
23
27
  privileged: z.boolean(),
24
28
  gpu: z.boolean(),
29
+ swapGib: z
30
+ .int()
31
+ .positive()
32
+ .nullable()
33
+ .optional()
34
+ .describe(
35
+ "Whole GiB of swap the sandbox's work (its `workload` cgroup) may page into, the swap alone, not memory plus swap; null for the default, a quarter of the memory cap between 1 and 4 GiB (@intentic/sandbox-run defaultSandboxSwapGib). Changed alone and now, ic applies it to the running sandbox without a restart. Absent from an ic or agent older than it.",
36
+ ),
25
37
  });
26
38
  export type SandboxShape = z.infer<typeof SandboxShapeSchema>;
27
39
  // When a `set-shape` takes effect: `now` restarts the sandbox onto it; `nextRestart` saves it in ic's record and
@@ -46,6 +58,22 @@ export const SandboxResourcesSchema = z.object({
46
58
  // READ-ONLY, from agents older than `set-shape`: their saved share, a delta against what runs. Nothing new writes
47
59
  // it; kept one release so a newer page can still show what an older agent saved. Remove with `later`.
48
60
  saved: SandboxResourcesAskFieldsSchema.optional(),
61
+ // (2026-11-05) The swap bound IN FORCE, read by ic inside the running container from the kernel's own files, never
62
+ // from docker: an engine without swap-limit support records MemorySwap -1 whatever it was asked, and drops the bound.
63
+ swapMaxBytes: z
64
+ .number()
65
+ .nullable()
66
+ .optional()
67
+ .describe(
68
+ "The container's own swap bound as /sys/fs/cgroup/memory.swap.max inside it holds it, in bytes; null when unbounded. Absent when it was not read: the sandbox is not running, did not answer in time, or ic is older than this field.",
69
+ ),
70
+ workloadSwapMaxBytes: z
71
+ .number()
72
+ .nullable()
73
+ .optional()
74
+ .describe(
75
+ "The swap bound of the sandbox's work (/sys/fs/cgroup/workload/memory.swap.max: everything but the daemon and netd), in bytes; null when unbounded. Absent when it was not read, or the image is older than the bound a sandbox holds its own work to.",
76
+ ),
49
77
  });
50
78
  export type SandboxResources = z.infer<typeof SandboxResourcesSchema>;
51
79
 
@@ -136,7 +136,8 @@ export const DeviceSandboxFlowSchema = z.strictObject({
136
136
  to: z.string().min(1).optional(),
137
137
  // `set-shape` only, both required by it: the whole shape, and when it takes effect.
138
138
  // Strict too, unlike the same shape read off a report (where a newer ic's extra field must not fail an older
139
- // reader): an order carrying a field this agent does not know is refused rather than carried out without it.
139
+ // reader): an order carrying a field this agent does not know is refused rather than carried out without it. So the
140
+ // shape's `swapGib` (2026-11-05) is sent only to a machine whose report carried it, which an older agent's never does.
140
141
  shape: z.strictObject(SandboxShapeSchema.shape).optional(),
141
142
  when: SandboxShapeWhenSchema.optional(),
142
143
  // `set-egress` only: the whole policy (required), the owner's passkey over a change that loosens it, and,
@@ -37,6 +37,14 @@ test("a field left out is left to ic, which keeps what it has for it", () => {
37
37
  expect(icShapeArgs("work", { memoryGib: 12, gpu: undefined }, "now")).toEqual(["sandbox", "shape", "work", "--set", "memoryGib=12", "--when", "now"]);
38
38
  });
39
39
 
40
+ // The swap (2026-11-05) travels like the caps, null being the default; left out, it is left to ic, which is how a page
41
+ // talking to a machine whose report never carried it sends nothing an older agent would refuse.
42
+ test("the swap is one more `--set`, in the contract's own name, and only when it is named", () => {
43
+ expect(icShapeArgs("work", { swapGib: 4 }, "now")).toEqual(["sandbox", "shape", "work", "--set", "swapGib=4", "--when", "now"]);
44
+ expect(icShapeArgs("work", { memoryGib: 20, swapGib: null }, "nextRestart").slice(3, 7)).toEqual(["--set", "memoryGib=20", "--set", "swapGib=null"]);
45
+ expect(icShapeArgs("work", { memoryGib: 20, swapGib: undefined }, "now")).toEqual(["sandbox", "shape", "work", "--set", "memoryGib=20", "--when", "now"]);
46
+ });
47
+
40
48
  test("forgetting and power name only the sandbox", () => {
41
49
  expect(icForgetShapeArgs("work")).toEqual(["sandbox", "shape", "work", "--forget"]);
42
50
  expect(icPowerArgs("restart", "work")).toEqual(["sandbox", "restart", "work"]);
@@ -47,6 +55,10 @@ test("a shape missing a field is not a shape", () => {
47
55
  expect(SandboxShapeSchema.safeParse({ memoryGib: 20, cpus: null, privileged: false }).success).toBe(false);
48
56
  expect(SandboxShapeSchema.safeParse({ memoryGib: 0, cpus: null, privileged: false, gpu: false }).success).toBe(false);
49
57
  expect(SandboxShapeSchema.safeParse({ memoryGib: null, cpus: null, privileged: false, gpu: false }).success).toBe(true);
58
+ // The swap alone may be absent: an ic or agent older than it reports a whole shape without it.
59
+ expect(SandboxShapeSchema.safeParse({ memoryGib: null, cpus: null, privileged: false, gpu: false, swapGib: null }).success).toBe(true);
60
+ expect(SandboxShapeSchema.safeParse({ memoryGib: null, cpus: null, privileged: false, gpu: false, swapGib: 0 }).success).toBe(false);
61
+ expect(SandboxShapeSchema.safeParse({ memoryGib: null, cpus: null, privileged: false, gpu: false, swapGib: 1.5 }).success).toBe(false);
50
62
  });
51
63
 
52
64
  // Every device input is strict, the shape nested in one included: an agent that dropped a field it did not know would
@@ -57,8 +69,11 @@ test("a device order refuses a shape or delta field it does not know", () => {
57
69
  const accepted = (fields: object): boolean =>
58
70
  DeviceSandboxFlowSchema.safeParse(JSON.parse(`{"op":"set-shape","slug":"work","when":"now","shape":${JSON.stringify(fields)}}`)).success;
59
71
  expect(accepted(whole)).toBe(true);
60
- expect(accepted({ ...whole, swapGib: 4 })).toBe(false);
72
+ // The swap is the contract's own now; a field it does not know is still refused.
73
+ expect(accepted({ ...whole, swapGib: 4 })).toBe(true);
74
+ expect(accepted({ ...whole, diskGib: 40 })).toBe(false);
75
+ // The old `reshape` op's delta stays as it was released: nothing new sends it, so it never learned the swap.
61
76
  expect(DeviceSandboxFlowSchema.safeParse({ op: "reshape", slug: "work", resources: { memoryGib: 20, swapGib: 4 } }).success).toBe(false);
62
77
  // A report is read leniently: a newer ic's extra field must not fail an older reader.
63
- expect(SandboxShapeSchema.safeParse({ ...whole, swapGib: 4 }).success).toBe(true);
78
+ expect(SandboxShapeSchema.safeParse({ ...whole, diskGib: 40 }).success).toBe(true);
64
79
  });
@@ -89,7 +89,7 @@ export const SandboxUsageSchema = z.object({
89
89
  memoryLimitBytes: z
90
90
  .number()
91
91
  .describe(
92
- "The memory limit work is admitted against: where the kernel starts throttling the container (memory.high), else its hard limit, else the machine's memory.",
92
+ "The memory limit work is admitted against: where the kernel starts throttling the container (memory.high), else its hard limit, else the machine's memory; never above the workload cgroup leaf's own limit plus what runs outside that leaf, since admitted work runs in it.",
93
93
  ),
94
94
  memoryBreakdown: z
95
95
  .object({
@@ -283,3 +283,18 @@ describe(`default job setups`, () => {
283
283
  expect(SandboxSettingsWriteSchema.parse({ ...saved, commandJudge: `watch` }).roleSetups).toEqual({});
284
284
  });
285
285
  });
286
+
287
+ // A memory kill's answer is on to begin with where the restart switch is off: the sandbox knows the cause, and lets its
288
+ // victims back one at a time once memory settles (turn-break.ts). Only the two answers it takes are written.
289
+ describe(`the answer to a memory kill`, () => {
290
+ test(`resumes by default, while resuming after any restart stays off`, () => {
291
+ const defaults = SandboxSettingsSchema.parse({});
292
+ expect(defaults.memoryKillPolicy).toBe(`resume`);
293
+ expect(defaults.autoResumeOnRestart).toBe(false);
294
+ });
295
+
296
+ test(`takes wait or resume and nothing else`, () => {
297
+ expect(SandboxSettingsSchema.parse({ memoryKillPolicy: `wait` }).memoryKillPolicy).toBe(`wait`);
298
+ expect(SandboxSettingsSchema.safeParse({ memoryKillPolicy: `retry` }).success).toBe(false);
299
+ });
300
+ });
@@ -11,7 +11,7 @@ import { GpuSettingsSchema } from "./gpu-settings.js";
11
11
  import { NightHoursSchema } from "./night-hours.js";
12
12
  import { LimitHandoffSchema } from "./providers/handoff.js";
13
13
  import { SessionsPlacementSchema } from "./offload.js";
14
- import { LimitPolicySchema, RetryPolicySchema, RoomPolicySchema } from "./turn-break.js";
14
+ import { LimitPolicySchema, MemoryKillPolicySchema, RetryPolicySchema, RoomPolicySchema } from "./turn-break.js";
15
15
  import { ZoneSchema } from "../time/zone.js";
16
16
  import { DEFAULT_SANDBOX_MODE, SandboxModeSchema } from "./sandbox-mode.js";
17
17
  import { VoiceSettingsSchema } from "./voice.js";
@@ -503,6 +503,18 @@ export const SandboxSettingsSchema = z.object({
503
503
  memoryPolicy: RoomPolicySchema.default("resend").describe(
504
504
  "What happens to a message the sandbox held because it was short of memory: nothing ran, so nothing was spent. `resend` sends it by itself once memory has stayed free for a while, one held conversation at a time. `wait` holds it until somebody presses Send anyway. The sandbox-wide default; any one conversation can say otherwise.",
505
505
  ),
506
+ // The one answer that re-runs a turn which RAN without being asked, on by default, where autoResumeOnRestart (below)
507
+ // is off by default. The two differ in what the sandbox knows. A restart is any cause (an update, a rebuild, a crash
508
+ // nobody named), and re-running everything it cut, all at once, spends the allowance on work nobody is watching and
509
+ // edits files while the owner still waits for the sandbox to come back. A memory kill is one named cause the sandbox
510
+ // can steer around: its turns go one at a time, only once memory has stayed free, never the turn whose own process was
511
+ // the one killed, and not after a second memory kill of the same request (MEMORY_KILL_RERUNS), so what comes back is
512
+ // the victims and not the runaway. Held for a press instead, every victim of the 2026-11-05 runaway sat in Attention
513
+ // with "autoResumeOnRestart is off" though only one conversation had caused it; and switching autoResumeOnRestart on
514
+ // to avoid that would have re-run the cause too, all at once, into a machine still recovering.
515
+ memoryKillPolicy: MemoryKillPolicySchema.default("resume").describe(
516
+ "What happens to a turn the sandbox killed because it ran out of memory, whether only that turn was killed or the whole sandbox restarted. `resume` sends it again by itself once memory has stayed free for a while, one conversation at a time, and tells it what happened. Never a turn whose own process was the one using the memory, and never one killed for memory twice already: those wait for a press whatever this says. `wait` holds every such turn until somebody presses Continue. After a restart that ran out of memory this decides for the turns it cut, instead of the switch for resuming after a restart. The sandbox-wide default; any one conversation can say otherwise.",
517
+ ),
506
518
  // How a held turn continues once its cache has gone cold (schemas/providers/handoff.ts). The card asks each time and
507
519
  // preselects this; a booked send (a move, a resend at the reset) uses it unless a person picked on the card.
508
520
  limitHandoff: LimitHandoffSchema.default("suggested").describe(
@@ -590,7 +602,7 @@ export const SandboxSettingsSchema = z.object({
590
602
  .boolean()
591
603
  .default(false)
592
604
  .describe(
593
- "Whether a turn killed by the sandbox restarting is re-run once it comes back. A switch rather than one of the policies above, because a restart is the one ending with nobody watching it, so there is no in-chat question to answer. Off to begin with: it would spend your allowance on work you are not watching and edit files while you are still waiting for the sandbox to return. Either way the interruption is recorded rather than silently lost.",
605
+ "Whether a turn killed by the sandbox restarting is re-run once it comes back. A switch rather than one of the policies above, because a restart is the one ending with nobody watching it, so there is no in-chat question to answer. Off to begin with: it would spend your allowance on work you are not watching and edit files while you are still waiting for the sandbox to return. Either way the interruption is recorded rather than silently lost. A restart the sandbox traces to memory running out goes by `memoryKillPolicy` instead, whatever this says.",
594
606
  ),
595
607
  // The owner's night (night-hours.ts): with nobody at the editor inside it, an agent's own question is answered by the
596
608
  // sandbox rather than parking the turn until morning. Off until the owner sets the hours: a sleep window guessed for
@@ -671,7 +683,7 @@ export const SandboxSettingsSchema = z.object({
671
683
  .describe("What an agent may do out in the world, per kind of action: go ahead, ask first, or never."),
672
684
  // Command policy itself lives at .intentic/config/safety.md (edited by the Safety page), not here; this only says
673
685
  // whether the judge runs at all. Which model judges is the `safety-judge` job's setup (`roleSetups`), not a field here.
674
- commandJudge: CommandJudgeModeSchema.default("on").describe(
686
+ commandJudge: CommandJudgeModeSchema.default("off").describe(
675
687
  "Whether a model reads your safety policy before a flagged command runs. Off judges nothing and asks about nothing; Watch judges everything and records it without ever interrupting you, which is how you find out what your policy actually does before you let it stop anything; On lets the verdict decide. Wiping a disk or deleting under /history asks at every setting — that rule is typed rather than judged, and cannot be turned off.",
676
688
  ),
677
689
  // Only whether a person is asked: where the install lands (the conversation's own copy, or the daemon's install lane
@@ -10,9 +10,12 @@ import { z } from "zod";
10
10
  // The walls a turn can stop at that take a standing answer. The first three end a turn that leaves finished work behind
11
11
  // a live session, spelled exactly as `TurnEndingSchema.reason` spells them, so the ending a surface reads and the
12
12
  // question it asks are one word. `memory` is the door: the sandbox too short of memory to start the turn at all, which
13
- // holds the message (or the turn the sandbox kept) until a press or room comes back. A restart is handled apart
13
+ // holds the message (or the turn the sandbox kept) until a press or room comes back. `memoryKill` is a turn that was
14
+ // running when the sandbox ran out of memory and was killed for it, whether its runtime alone was killed or the whole
15
+ // daemon went down with it (2026-11-05): it reads as a stopped turn, but what brings it back is room, not a clock, and it
16
+ // ran, so it is a question of its own rather than the stop ladder's or the door's. A restart is otherwise handled apart
14
17
  // (SandboxSettings.autoResumeOnRestart): nobody is watching a restart, so it has no in-chat question.
15
- export const TurnBreakSchema = z.enum(["limit", "outage", "stopped", "memory"]);
18
+ export const TurnBreakSchema = z.enum(["limit", "outage", "stopped", "memory", "memoryKill"]);
16
19
  export type TurnBreak = z.infer<typeof TurnBreakSchema>;
17
20
 
18
21
  // Every ending that leaves a held turn behind: a spent allowance, an outage, a turn that stopped short, plus the
@@ -39,8 +42,14 @@ export type RetryPolicy = z.infer<typeof RetryPolicySchema>;
39
42
  export const RoomPolicySchema = z.enum(["wait", "resend"]);
40
43
  export type RoomPolicy = z.infer<typeof RoomPolicySchema>;
41
44
 
42
- // One answer, whichever ending asked. Read against the ending: only `limit` can be `move`.
43
- export const TurnBreakPolicySchema = z.enum(["wait", "resend", "move", "retry"]);
45
+ // A memory kill's two answers: hold it for a press, or send it again by itself once memory has stayed free, one
46
+ // conversation at a time. Never the turn whose own process was the one killed, nor one killed for memory twice already
47
+ // (MEMORY_KILL_RERUNS): those wait for a press whatever the answer, since re-running them is re-running the runaway.
48
+ export const MemoryKillPolicySchema = z.enum(["wait", "resume"]);
49
+ export type MemoryKillPolicy = z.infer<typeof MemoryKillPolicySchema>;
50
+
51
+ // One answer, whichever ending asked. Read against the ending: only `limit` can be `move`, only `memoryKill` `resume`.
52
+ export const TurnBreakPolicySchema = z.enum(["wait", "resend", "move", "retry", "resume"]);
44
53
  export type TurnBreakPolicy = z.infer<typeof TurnBreakPolicySchema>;
45
54
 
46
55
  // Which answers an ending may take, so a surface offers exactly these and a writer refuses anything else.
@@ -49,6 +58,7 @@ export const TURN_BREAK_POLICIES: Readonly<Record<TurnBreak, readonly TurnBreakP
49
58
  outage: ["wait", "retry"],
50
59
  stopped: ["wait", "retry"],
51
60
  memory: ["wait", "resend"],
61
+ memoryKill: ["wait", "resume"],
52
62
  };
53
63
 
54
64
  /** Whether this ending may be answered this way; the one gate every writer goes through. */
@@ -63,6 +73,22 @@ export const breakArmed = (policy: TurnBreakPolicy): boolean => policy !== "wait
63
73
  export const RETRY_LADDER_MS = [5_000, 15_000, 45_000] as const;
64
74
  export const RETRY_LADDER_TRIES = RETRY_LADDER_MS.length;
65
75
 
76
+ // How many times the sandbox sends one request again by itself after memory killed it. The kill after that holds it for
77
+ // a press: a turn killed for memory every time it runs is more likely the cause than a victim, whatever its process was
78
+ // called. Quoted in the notice that holds it, so the number and the sentence cannot drift.
79
+ export const MEMORY_KILL_RERUNS = 2;
80
+
81
+ // The mark a held turn carries where memory killed it: the failure frame's `held` (agent-events.ts) and the recorded
82
+ // ending's (transcript.ts TurnEnding), which the card's press repeats. A memory kill is held as a stop, so without the
83
+ // mark a surface asked the stop's question, whose answer sets the stop ladder that a memory kill never climbs, and the
84
+ // question that does decide it was asked nowhere. One schema for both, so the frame and the record cannot word it apart.
85
+ export const MemoryKillMarkSchema = z
86
+ .boolean()
87
+ .optional()
88
+ .describe(
89
+ "Killed because the sandbox ran out of memory: the answer that decides whether it goes again by itself is the memory kill's (wait, or resume once memory has stayed free), not the stop's. Absent for every other hold.",
90
+ );
91
+
66
92
  /** The wait before the next rung, or undefined once the ladder is spent. */
67
93
  export const retryLadderDelay = (triesWithoutProgress: number): number | undefined => RETRY_LADDER_MS[triesWithoutProgress];
68
94
 
@@ -6,10 +6,16 @@ import { freshStartLine, freshStartNotice, handedOffLine, handedOffNotice } from
6
6
  import { switchedLine, switchedNotice } from "../schemas/providers/switched.js";
7
7
 
8
8
  // The notices that say what a turn was given to start from, each a row of its own worded from its frame's facts: what
9
- // the window left out of the message, how a held turn continued, where a home's session started over, and what the
10
- // turn switched to since the one before it.
11
- type StartingFrame = Extract<AgentEvent, { kind: "context_trim" | "handoff" | "fresh_start" | "switched" }>;
12
- const STARTING_KINDS: ReadonlySet<AgentEvent["kind"]> = new Set<StartingFrame["kind"]>(["context_trim", "handoff", "fresh_start", "switched"]);
9
+ // the window left out of the message, how a held turn continued, where a home's session started over, what the turn
10
+ // switched to since the one before it, and the copy of the workspace the sandbox had to set up again for it.
11
+ type StartingFrame = Extract<AgentEvent, { kind: "context_trim" | "handoff" | "fresh_start" | "switched" | "workspace_repaired" }>;
12
+ const STARTING_KINDS: ReadonlySet<AgentEvent["kind"]> = new Set<StartingFrame["kind"]>(["context_trim", "handoff", "fresh_start", "switched", "workspace_repaired"]);
13
+
14
+ // The sandbox's one repair of a conversation's view of the workspace, made before the model was asked anything.
15
+ const repairedLine = (layers: number): string =>
16
+ layers === 0
17
+ ? "This conversation's copy of the workspace failed to come up, and was set up again."
18
+ : `This conversation's copy of the workspace failed to come up, so its installed dependencies (${String(layers)} ${layers === 1 ? "layer" : "layers"}) were set aside and it was set up again. Install them again if the work needs them.`;
13
19
 
14
20
  /** Whether the frame is one of those notices. */
15
21
  export const isStartingFrame = (event: AgentEvent): event is StartingFrame => STARTING_KINDS.has(event.kind);
@@ -25,6 +31,8 @@ export const startingRow = (event: StartingFrame): TranscriptRow => {
25
31
  return { role: "notice", text: freshStartLine(event), noticeCode: noticeCode(freshStartNotice(event)) };
26
32
  case "switched":
27
33
  return { role: "notice", text: switchedLine(event), noticeCode: noticeCode(switchedNotice(event)) };
34
+ case "workspace_repaired":
35
+ return { role: "notice", text: repairedLine(event.layers), noticeCode: noticeCode({ code: "workspaceRepaired", params: { layers: event.layers } }) };
28
36
  }
29
37
  };
30
38