open-multi-agent-kit 0.98.5 → 0.99.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 (163) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +3 -2
  3. package/dist/cli/help.d.ts.map +1 -1
  4. package/dist/cli/help.js +1 -0
  5. package/dist/cli/help.js.map +1 -1
  6. package/dist/commands/verified-run-cli.d.ts.map +1 -1
  7. package/dist/commands/verified-run-cli.js +2 -2
  8. package/dist/commands/verified-run-cli.js.map +1 -1
  9. package/dist/core/agent-session.d.ts.map +1 -1
  10. package/dist/core/agent-session.js +19 -2
  11. package/dist/core/agent-session.js.map +1 -1
  12. package/dist/core/devin-harness-dispatch.d.ts +12 -0
  13. package/dist/core/devin-harness-dispatch.d.ts.map +1 -0
  14. package/dist/core/devin-harness-dispatch.js +12 -0
  15. package/dist/core/devin-harness-dispatch.js.map +1 -0
  16. package/dist/core/devin-harness.d.ts +53 -0
  17. package/dist/core/devin-harness.d.ts.map +1 -0
  18. package/dist/core/devin-harness.js +112 -0
  19. package/dist/core/devin-harness.js.map +1 -0
  20. package/dist/core/domain-dispatch.d.ts +4 -1
  21. package/dist/core/domain-dispatch.d.ts.map +1 -1
  22. package/dist/core/domain-dispatch.js +5 -0
  23. package/dist/core/domain-dispatch.js.map +1 -1
  24. package/dist/core/domain-loadouts-provider-harness.d.ts +12 -0
  25. package/dist/core/domain-loadouts-provider-harness.d.ts.map +1 -0
  26. package/dist/core/domain-loadouts-provider-harness.js +122 -0
  27. package/dist/core/domain-loadouts-provider-harness.js.map +1 -0
  28. package/dist/core/domain-loadouts.d.ts +2 -33
  29. package/dist/core/domain-loadouts.d.ts.map +1 -1
  30. package/dist/core/domain-loadouts.js +3 -56
  31. package/dist/core/domain-loadouts.js.map +1 -1
  32. package/dist/core/domain-profile.d.ts +40 -0
  33. package/dist/core/domain-profile.d.ts.map +1 -0
  34. package/dist/core/domain-profile.js +7 -0
  35. package/dist/core/domain-profile.js.map +1 -0
  36. package/dist/core/grok-harness-dispatch.d.ts +6 -20
  37. package/dist/core/grok-harness-dispatch.d.ts.map +1 -1
  38. package/dist/core/grok-harness-dispatch.js +6 -55
  39. package/dist/core/grok-harness-dispatch.js.map +1 -1
  40. package/dist/core/grok-harness.d.ts +7 -9
  41. package/dist/core/grok-harness.d.ts.map +1 -1
  42. package/dist/core/grok-harness.js +9 -23
  43. package/dist/core/grok-harness.js.map +1 -1
  44. package/dist/core/harness-skills.d.ts +20 -0
  45. package/dist/core/harness-skills.d.ts.map +1 -0
  46. package/dist/core/harness-skills.js +36 -0
  47. package/dist/core/harness-skills.js.map +1 -0
  48. package/dist/core/loadout-runtime-state.d.ts +25 -0
  49. package/dist/core/loadout-runtime-state.d.ts.map +1 -0
  50. package/dist/core/loadout-runtime-state.js +39 -0
  51. package/dist/core/loadout-runtime-state.js.map +1 -0
  52. package/dist/core/loadout-runtime.d.ts +2 -12
  53. package/dist/core/loadout-runtime.d.ts.map +1 -1
  54. package/dist/core/loadout-runtime.js +6 -13
  55. package/dist/core/loadout-runtime.js.map +1 -1
  56. package/dist/core/model-resolver.d.ts +1 -41
  57. package/dist/core/model-resolver.d.ts.map +1 -1
  58. package/dist/core/model-resolver.js +2 -49
  59. package/dist/core/model-resolver.js.map +1 -1
  60. package/dist/core/provider-default-models.d.ts +42 -0
  61. package/dist/core/provider-default-models.d.ts.map +1 -0
  62. package/dist/core/provider-default-models.js +50 -0
  63. package/dist/core/provider-default-models.js.map +1 -0
  64. package/dist/core/provider-display-names.d.ts.map +1 -1
  65. package/dist/core/provider-display-names.js +1 -0
  66. package/dist/core/provider-display-names.js.map +1 -1
  67. package/dist/core/provider-harness-dispatch.d.ts +63 -0
  68. package/dist/core/provider-harness-dispatch.d.ts.map +1 -0
  69. package/dist/core/provider-harness-dispatch.js +60 -0
  70. package/dist/core/provider-harness-dispatch.js.map +1 -0
  71. package/dist/core/provider-usage-devin.d.ts +16 -0
  72. package/dist/core/provider-usage-devin.d.ts.map +1 -0
  73. package/dist/core/provider-usage-devin.js +61 -0
  74. package/dist/core/provider-usage-devin.js.map +1 -0
  75. package/dist/core/provider-usage-text.d.ts +5 -0
  76. package/dist/core/provider-usage-text.d.ts.map +1 -0
  77. package/dist/core/provider-usage-text.js +15 -0
  78. package/dist/core/provider-usage-text.js.map +1 -0
  79. package/dist/core/provider-usage-types.d.ts +2 -1
  80. package/dist/core/provider-usage-types.d.ts.map +1 -1
  81. package/dist/core/provider-usage-types.js.map +1 -1
  82. package/dist/core/provider-usage.d.ts +1 -2
  83. package/dist/core/provider-usage.d.ts.map +1 -1
  84. package/dist/core/provider-usage.js +12 -7
  85. package/dist/core/provider-usage.js.map +1 -1
  86. package/dist/core/run-execution-api.d.ts +1 -1
  87. package/dist/core/run-execution-api.d.ts.map +1 -1
  88. package/dist/core/run-execution-api.js.map +1 -1
  89. package/dist/core/sdk.d.ts.map +1 -1
  90. package/dist/core/sdk.js +23 -18
  91. package/dist/core/sdk.js.map +1 -1
  92. package/dist/core/verified-run/dag-phase.d.ts +1 -1
  93. package/dist/core/verified-run/dag-phase.d.ts.map +1 -1
  94. package/dist/core/verified-run/dag-phase.js +46 -8
  95. package/dist/core/verified-run/dag-phase.js.map +1 -1
  96. package/dist/core/verified-run/dag-projection.d.ts.map +1 -1
  97. package/dist/core/verified-run/dag-projection.js +25 -12
  98. package/dist/core/verified-run/dag-projection.js.map +1 -1
  99. package/dist/core/verified-run/dag-types.d.ts +11 -0
  100. package/dist/core/verified-run/dag-types.d.ts.map +1 -1
  101. package/dist/core/verified-run/dag-types.js.map +1 -1
  102. package/dist/core/verified-run/event-parser.d.ts.map +1 -1
  103. package/dist/core/verified-run/event-parser.js +1 -0
  104. package/dist/core/verified-run/event-parser.js.map +1 -1
  105. package/dist/core/verified-run/owned-execution.d.ts +1 -0
  106. package/dist/core/verified-run/owned-execution.d.ts.map +1 -1
  107. package/dist/core/verified-run/owned-execution.js +7 -1
  108. package/dist/core/verified-run/owned-execution.js.map +1 -1
  109. package/dist/core/verified-run/process-projection.d.ts +13 -0
  110. package/dist/core/verified-run/process-projection.d.ts.map +1 -0
  111. package/dist/core/verified-run/process-projection.js +82 -0
  112. package/dist/core/verified-run/process-projection.js.map +1 -0
  113. package/dist/core/verified-run/projection.d.ts.map +1 -1
  114. package/dist/core/verified-run/projection.js +11 -55
  115. package/dist/core/verified-run/projection.js.map +1 -1
  116. package/dist/core/verified-run/run-types.d.ts +1 -0
  117. package/dist/core/verified-run/run-types.d.ts.map +1 -1
  118. package/dist/core/verified-run/run-types.js.map +1 -1
  119. package/dist/core/verified-run/task-execution.d.ts +9 -0
  120. package/dist/core/verified-run/task-execution.d.ts.map +1 -0
  121. package/dist/core/verified-run/task-execution.js +29 -0
  122. package/dist/core/verified-run/task-execution.js.map +1 -0
  123. package/dist/core/verified-run/writer-projection.d.ts.map +1 -1
  124. package/dist/core/verified-run/writer-projection.js +6 -5
  125. package/dist/core/verified-run/writer-projection.js.map +1 -1
  126. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  127. package/dist/modes/interactive/interactive-mode.js +2 -5
  128. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  129. package/dist/modes/interactive/resource-description.d.ts +3 -0
  130. package/dist/modes/interactive/resource-description.d.ts.map +1 -0
  131. package/dist/modes/interactive/resource-description.js +15 -0
  132. package/dist/modes/interactive/resource-description.js.map +1 -0
  133. package/docs/devin-harness.md +121 -0
  134. package/docs/docs.json +4 -0
  135. package/docs/environment-variables.md +2 -1
  136. package/docs/index.md +1 -0
  137. package/docs/loadout-domains/README.md +2 -1
  138. package/docs/loadout-domains/devin-harness.md +72 -0
  139. package/docs/metrics.md +57 -16
  140. package/docs/providers.md +76 -0
  141. package/docs/release-audit-0.98.5.md +17 -0
  142. package/docs/release-audit-0.99.0.md +68 -0
  143. package/docs/run-protocol.md +4 -3
  144. package/docs/runtime-algorithms.md +4 -1
  145. package/docs/sdk.md +9 -5
  146. package/docs/settings.md +1 -1
  147. package/docs/startup-resource-labels-testing.md +47 -0
  148. package/docs/tb21-audit.md +18 -4
  149. package/docs/usage.md +5 -0
  150. package/docs/verified-run-remaining-design.md +881 -0
  151. package/docs/verified-run-testing.md +91 -0
  152. package/docs/verified-run.md +30 -9
  153. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  154. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  155. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  156. package/examples/extensions/gondolin/package-lock.json +2 -2
  157. package/examples/extensions/gondolin/package.json +1 -1
  158. package/examples/extensions/sandbox/package-lock.json +2 -2
  159. package/examples/extensions/sandbox/package.json +1 -1
  160. package/examples/extensions/with-deps/package-lock.json +2 -2
  161. package/examples/extensions/with-deps/package.json +1 -1
  162. package/npm-shrinkwrap.json +18 -18
  163. package/package.json +6 -6
@@ -15,11 +15,11 @@ export function reduceDagEvent(context, event) {
15
15
  !state.budget ||
16
16
  state.candidateDigest ||
17
17
  state.writerOpen ||
18
- state.activeExecutionIds.length ||
19
18
  state.execution === "paused")
20
19
  throw new VerifiedRunError("integrity");
21
20
  if (event.kind === "tasks_paused") {
22
- if (state.tasks.some((task) => task.status === "running") ||
21
+ if (state.activeExecutionIds.length ||
22
+ state.tasks.some((task) => task.status === "running") ||
23
23
  !state.tasks.some((task) => task.status === "failed") ||
24
24
  readyDagTasks(contract.writer, state).length)
25
25
  throw new VerifiedRunError("integrity");
@@ -37,7 +37,8 @@ export function reduceDagEvent(context, event) {
37
37
  switch (event.kind) {
38
38
  case "task_started":
39
39
  if (task.status !== "pending" ||
40
- state.tasks.some((task) => task.status === "running") ||
40
+ state.tasks.filter((task) => task.status === "running").length >=
41
+ (contract.writer.maxConcurrentTasks ?? 1) ||
41
42
  event.attempt !== task.attempt + 1 ||
42
43
  event.attempt > definition.attempts.length ||
43
44
  !readyDagTasks(contract.writer, state).some((task) => task.id === event.taskId))
@@ -47,30 +48,37 @@ export function reduceDagEvent(context, event) {
47
48
  generation: state.generation,
48
49
  attempt: event.attempt,
49
50
  status: "running",
51
+ execution: Object.freeze({ kind: "ready" }),
50
52
  inputDigest: event.inputDigest,
51
53
  outputDigest: null,
52
54
  failure: null,
53
55
  };
54
- context.writerStarted = false;
55
- context.writerFinished = false;
56
56
  break;
57
- case "task_finished":
57
+ case "task_finished": {
58
58
  if (task.status !== "running" ||
59
59
  task.generation !== state.generation ||
60
60
  task.attempt !== event.attempt ||
61
- !context.writerStarted)
61
+ task.execution.kind !== "exited")
62
62
  throw new VerifiedRunError("integrity");
63
+ // Keep checkpoint shape stable: process state belongs only to an in-flight task.
64
+ const checkpoint = {
65
+ taskId: task.taskId,
66
+ generation: task.generation,
67
+ attempt: task.attempt,
68
+ inputDigest: task.inputDigest,
69
+ };
63
70
  if (event.outputDigest !== null) {
64
- if (event.failure !== null || state.failure || !context.writerFinished)
71
+ if (event.failure !== null || task.execution.failure)
65
72
  throw new VerifiedRunError("integrity");
66
- next = { ...task, status: "succeeded", outputDigest: event.outputDigest };
73
+ next = { ...checkpoint, status: "succeeded", outputDigest: event.outputDigest, failure: null };
67
74
  }
68
75
  else {
69
- if (!event.failure || (state.failure && event.failure !== state.failure))
76
+ if (!event.failure || (task.execution.failure && event.failure !== task.execution.failure))
70
77
  throw new VerifiedRunError("integrity");
71
- next = { ...task, status: "failed", failure: event.failure };
78
+ next = { ...checkpoint, status: "failed", outputDigest: null, failure: event.failure };
72
79
  }
73
80
  break;
81
+ }
74
82
  default: {
75
83
  const exhaustive = event;
76
84
  throw new VerifiedRunError(String(exhaustive));
@@ -78,11 +86,16 @@ export function reduceDagEvent(context, event) {
78
86
  }
79
87
  const tasks = state.tasks.map((task) => (task.taskId === next.taskId ? next : task));
80
88
  context.writerFinished = tasks.every((task) => task.status === "succeeded" && task.generation === state.generation);
89
+ let settlement = "settled";
90
+ if (tasks.some((task) => task.status === "running"))
91
+ settlement = "open";
92
+ if (state.activeExecutionIds.length)
93
+ settlement = "draining";
81
94
  context.state = {
82
95
  ...state,
83
96
  tasks,
84
97
  execution: "running",
85
- settlement: "settled",
98
+ settlement,
86
99
  failure: null,
87
100
  lastClockMs: event.observedMs,
88
101
  };
@@ -1 +1 @@
1
- {"version":3,"file":"dag-projection.js","sourceRoot":"","sources":["../../../src/core/verified-run/dag-projection.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,UAAU,aAAa,CAAC,MAAoB,EAAE,KAAoB,EAAyB;IAChG,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IACvE,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,CACzB,CAAC,IAAI,EAAE,EAAE,CACR,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,MAAM,KAAK,SAAS;QACzC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC;YAC5B,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAClC,OAAO,UAAU,EAAE,MAAM,KAAK,WAAW,IAAI,UAAU,CAAC,UAAU,KAAK,KAAK,CAAC,UAAU,CAAC;QAAA,CACxF,CAAC,CACH,CAAC;AAAA,CACF;AAED,+FAA+F;AAC/F,MAAM,UAAU,cAAc,CAAC,OAAwB,EAAE,KAAe,EAAQ;IAC/E,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IACpC,IACC,QAAQ,CAAC,OAAO,KAAK,sBAAsB;QAC3C,CAAC,KAAK,CAAC,WAAW;QAClB,CAAC,KAAK,CAAC,MAAM;QACb,KAAK,CAAC,eAAe;QACrB,KAAK,CAAC,UAAU;QAChB,KAAK,CAAC,kBAAkB,CAAC,MAAM;QAC/B,KAAK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W,EAAE,KAAK,CAAC,UAAU;KAC7B,CAAC;AAAA,CACF","sourcesContent":["import type { RunDagTask, RunDagWriter } from \"omk-protocol\";\nimport type { DagEvent, RunTaskProjection } from \"./dag-types.ts\";\nimport type { RunProjection, WriterReduction } from \"./run-types.ts\";\nimport { VerifiedRunError } from \"./storage.ts\";\n\nexport function readyDagTasks(writer: RunDagWriter, state: RunProjection): readonly RunDagTask[] {\n\tconst states = new Map(state.tasks.map((task) => [task.taskId, task]));\n\treturn writer.tasks.filter(\n\t\t(task) =>\n\t\t\tstates.get(task.id)?.status === \"pending\" &&\n\t\t\ttask.dependsOn.every((id) => {\n\t\t\t\tconst dependency = states.get(id);\n\t\t\t\treturn dependency?.status === \"succeeded\" && dependency.generation === state.generation;\n\t\t\t}),\n\t);\n}\n\n/** Task outputs are execution checkpoints, never verifier receipts or completion authority. */\nexport function reduceDagEvent(context: WriterReduction, event: DagEvent): void {\n\tconst { state, contract } = context;\n\tif (\n\t\tcontract.profile !== \"linux-command-dag-v1\" ||\n\t\t!state.inputDigest ||\n\t\t!state.budget ||\n\t\tstate.candidateDigest ||\n\t\tstate.writerOpen ||\n\t\tstate.activeExecutionIds.length ||\n\t\tstate.execution === \"paused\"\n\t)\n\t\tthrow new VerifiedRunError(\"integrity\");\n\tif (event.kind === \"tasks_paused\") {\n\t\tif (\n\t\t\tstate.tasks.some((task) => task.status === \"running\") ||\n\t\t\t!state.tasks.some((task) => task.status === \"failed\") ||\n\t\t\treadyDagTasks(contract.writer, state).length\n\t\t)\n\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\tcontext.state = { ...state, execution: \"paused\", settlement: \"settled\" };\n\t\treturn;\n\t}\n\tif (\n\t\tevent.observedMs < (state.lastClockMs ?? state.budget.startedMs) ||\n\t\tevent.observedMs >= state.budget.workDeadlineMs\n\t)\n\t\tthrow new VerifiedRunError(\"deadline\");\n\tconst task = state.tasks.find((task) => task.taskId === event.taskId);\n\tconst definition = contract.writer.tasks.find((task) => task.id === event.taskId);\n\tif (!task || !definition) throw new VerifiedRunError(\"integrity\");\n\tlet next: RunTaskProjection;\n\tswitch (event.kind) {\n\t\tcase \"task_started\":\n\t\t\tif (\n\t\t\t\ttask.status !== \"pending\" ||\n\t\t\t\tstate.tasks.some((task) => task.status === \"running\") ||\n\t\t\t\tevent.attempt !== task.attempt + 1 ||\n\t\t\t\tevent.attempt > definition.attempts.length ||\n\t\t\t\t!readyDagTasks(contract.writer, state).some((task) => task.id === event.taskId)\n\t\t\t)\n\t\t\t\tthrow new VerifiedRunError(\"task_not_ready\");\n\t\t\tnext = {\n\t\t\t\ttaskId: task.taskId,\n\t\t\t\tgeneration: state.generation,\n\t\t\t\tattempt: event.attempt,\n\t\t\t\tstatus: \"running\",\n\t\t\t\tinputDigest: event.inputDigest,\n\t\t\t\toutputDigest: null,\n\t\t\t\tfailure: null,\n\t\t\t};\n\t\t\tcontext.writerStarted = false;\n\t\t\tcontext.writerFinished = false;\n\t\t\tbreak;\n\t\tcase \"task_finished\":\n\t\t\tif (\n\t\t\t\ttask.status !== \"running\" ||\n\t\t\t\ttask.generation !== state.generation ||\n\t\t\t\ttask.attempt !== event.attempt ||\n\t\t\t\t!context.writerStarted\n\t\t\t)\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\tif (event.outputDigest !== null) {\n\t\t\t\tif (event.failure !== null || state.failure || !context.writerFinished)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tnext = { ...task, status: \"succeeded\", outputDigest: event.outputDigest };\n\t\t\t} else {\n\t\t\t\tif (!event.failure || (state.failure && event.failure !== state.failure))\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tnext = { ...task, status: \"failed\", failure: event.failure };\n\t\t\t}\n\t\t\tbreak;\n\t\tdefault: {\n\t\t\tconst exhaustive: never = event;\n\t\t\tthrow new VerifiedRunError(String(exhaustive));\n\t\t}\n\t}\n\tconst tasks = state.tasks.map((task) => (task.taskId === next.taskId ? next : task));\n\tcontext.writerFinished = tasks.every((task) => task.status === \"succeeded\" && task.generation === state.generation);\n\tcontext.state = {\n\t\t...state,\n\t\ttasks,\n\t\texecution: \"running\",\n\t\tsettlement: \"settled\",\n\t\tfailure: null,\n\t\tlastClockMs: event.observedMs,\n\t};\n}\n"]}
1
+ {"version":3,"file":"dag-projection.js","sourceRoot":"","sources":["../../../src/core/verified-run/dag-projection.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,UAAU,aAAa,CAAC,MAAoB,EAAE,KAAoB,EAAyB;IAChG,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IACvE,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,CACzB,CAAC,IAAI,EAAE,EAAE,CACR,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,MAAM,KAAK,SAAS;QACzC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC;YAC5B,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAClC,OAAO,UAAU,EAAE,MAAM,KAAK,WAAW,IAAI,UAAU,CAAC,UAAU,KAAK,KAAK,CAAC,UAAU,CAAC;QAAA,CACxF,CAAC,CACH,CAAC;AAAA,CACF;AAED,+FAA+F;AAC/F,MAAM,UAAU,cAAc,CAAC,OAAwB,EAAE,KAAe,EAAQ;IAC/E,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IACpC,IACC,QAAQ,CAAC,OAAO,KAAK,sBAAsB;QAC3C,CAAC,KAAK,CAAC,WAAW;QAClB,CAAC,KAAK,CAAC,MAAM;QACb,KAAK,CAAC,e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AAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IACrF,OAAO,CAAC,cAAc,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,KAAK,WAAW,IAAI,IAAI,CAAC,UAAU,KAAK,KAAK,CAAC,UAAU,CAAC,CAAC;IACpH,IAAI,UAAU,GAAgC,SAAS,CAAC;IACxD,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC;QAAE,UAAU,GAAG,MAAM,CAAC;IACzE,IAAI,KAAK,CAAC,kBAAkB,CAAC,MAAM;QAAE,UAAU,GAAG,UAAU,CAAC;IAC7D,OAAO,CAAC,KAAK,GAAG;QACf,GAAG,KAAK;QACR,KAAK;QACL,SAAS,EAAE,SAAS;QACpB,UAAU;QACV,OAAO,EAAE,IAAI;QACb,WAAW,EAAE,KAAK,CAAC,UAAU;KAC7B,CAAC;AAAA,CACF","sourcesContent":["import type { RunDagTask, RunDagWriter } from \"omk-protocol\";\nimport type { DagEvent, RunTaskProjection } from \"./dag-types.ts\";\nimport type { RunProjection, WriterReduction } from \"./run-types.ts\";\nimport { VerifiedRunError } from \"./storage.ts\";\n\nexport function readyDagTasks(writer: RunDagWriter, state: RunProjection): readonly RunDagTask[] {\n\tconst states = new Map(state.tasks.map((task) => [task.taskId, task]));\n\treturn writer.tasks.filter(\n\t\t(task) =>\n\t\t\tstates.get(task.id)?.status === \"pending\" &&\n\t\t\ttask.dependsOn.every((id) => {\n\t\t\t\tconst dependency = states.get(id);\n\t\t\t\treturn dependency?.status === \"succeeded\" && dependency.generation === state.generation;\n\t\t\t}),\n\t);\n}\n\n/** Task outputs are execution checkpoints, never verifier receipts or completion authority. */\nexport function reduceDagEvent(context: WriterReduction, event: DagEvent): void {\n\tconst { state, contract } = context;\n\tif (\n\t\tcontract.profile !== \"linux-command-dag-v1\" ||\n\t\t!state.inputDigest ||\n\t\t!state.budget ||\n\t\tstate.candidateDigest ||\n\t\tstate.writerOpen ||\n\t\tstate.execution === \"paused\"\n\t)\n\t\tthrow new VerifiedRunError(\"integrity\");\n\tif (event.kind === \"tasks_paused\") {\n\t\tif (\n\t\t\tstate.activeExecutionIds.length ||\n\t\t\tstate.tasks.some((task) => task.status === \"running\") ||\n\t\t\t!state.tasks.some((task) => task.status === \"failed\") ||\n\t\t\treadyDagTasks(contract.writer, state).length\n\t\t)\n\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\tcontext.state = { ...state, execution: \"paused\", settlement: \"settled\" };\n\t\treturn;\n\t}\n\tif (\n\t\tevent.observedMs < (state.lastClockMs ?? state.budget.startedMs) ||\n\t\tevent.observedMs >= state.budget.workDeadlineMs\n\t)\n\t\tthrow new VerifiedRunError(\"deadline\");\n\tconst task = state.tasks.find((task) => task.taskId === event.taskId);\n\tconst definition = contract.writer.tasks.find((task) => task.id === event.taskId);\n\tif (!task || !definition) throw new VerifiedRunError(\"integrity\");\n\tlet next: RunTaskProjection;\n\tswitch (event.kind) {\n\t\tcase \"task_started\":\n\t\t\tif (\n\t\t\t\ttask.status !== \"pending\" ||\n\t\t\t\tstate.tasks.filter((task) => task.status === \"running\").length >=\n\t\t\t\t\t(contract.writer.maxConcurrentTasks ?? 1) ||\n\t\t\t\tevent.attempt !== task.attempt + 1 ||\n\t\t\t\tevent.attempt > definition.attempts.length ||\n\t\t\t\t!readyDagTasks(contract.writer, state).some((task) => task.id === event.taskId)\n\t\t\t)\n\t\t\t\tthrow new VerifiedRunError(\"task_not_ready\");\n\t\t\tnext = {\n\t\t\t\ttaskId: task.taskId,\n\t\t\t\tgeneration: state.generation,\n\t\t\t\tattempt: event.attempt,\n\t\t\t\tstatus: \"running\",\n\t\t\t\texecution: Object.freeze({ kind: \"ready\" }),\n\t\t\t\tinputDigest: event.inputDigest,\n\t\t\t\toutputDigest: null,\n\t\t\t\tfailure: null,\n\t\t\t};\n\t\t\tbreak;\n\t\tcase \"task_finished\": {\n\t\t\tif (\n\t\t\t\ttask.status !== \"running\" ||\n\t\t\t\ttask.generation !== state.generation ||\n\t\t\t\ttask.attempt !== event.attempt ||\n\t\t\t\ttask.execution.kind !== \"exited\"\n\t\t\t)\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t// Keep checkpoint shape stable: process state belongs only to an in-flight task.\n\t\t\tconst checkpoint = {\n\t\t\t\ttaskId: task.taskId,\n\t\t\t\tgeneration: task.generation,\n\t\t\t\tattempt: task.attempt,\n\t\t\t\tinputDigest: task.inputDigest,\n\t\t\t};\n\t\t\tif (event.outputDigest !== null) {\n\t\t\t\tif (event.failure !== null || task.execution.failure) throw new VerifiedRunError(\"integrity\");\n\t\t\t\tnext = { ...checkpoint, status: \"succeeded\", outputDigest: event.outputDigest, failure: null };\n\t\t\t} else {\n\t\t\t\tif (!event.failure || (task.execution.failure && event.failure !== task.execution.failure))\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tnext = { ...checkpoint, status: \"failed\", outputDigest: null, failure: event.failure };\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tdefault: {\n\t\t\tconst exhaustive: never = event;\n\t\t\tthrow new VerifiedRunError(String(exhaustive));\n\t\t}\n\t}\n\tconst tasks = state.tasks.map((task) => (task.taskId === next.taskId ? next : task));\n\tcontext.writerFinished = tasks.every((task) => task.status === \"succeeded\" && task.generation === state.generation);\n\tlet settlement: RunProjection[\"settlement\"] = \"settled\";\n\tif (tasks.some((task) => task.status === \"running\")) settlement = \"open\";\n\tif (state.activeExecutionIds.length) settlement = \"draining\";\n\tcontext.state = {\n\t\t...state,\n\t\ttasks,\n\t\texecution: \"running\",\n\t\tsettlement,\n\t\tfailure: null,\n\t\tlastClockMs: event.observedMs,\n\t};\n}\n"]}
@@ -3,6 +3,16 @@ interface TaskIdentity {
3
3
  readonly attempt: number;
4
4
  readonly generation: number;
5
5
  }
6
+ export type RunTaskExecution = {
7
+ readonly kind: "ready";
8
+ } | {
9
+ readonly kind: "running";
10
+ readonly executionId: string;
11
+ } | {
12
+ readonly kind: "exited";
13
+ readonly executionId: string;
14
+ readonly failure: string | null;
15
+ };
6
16
  export type RunTaskProjection = TaskIdentity & ({
7
17
  readonly status: "pending";
8
18
  readonly inputDigest: null;
@@ -10,6 +20,7 @@ export type RunTaskProjection = TaskIdentity & ({
10
20
  readonly failure: null;
11
21
  } | {
12
22
  readonly status: "running";
23
+ readonly execution: RunTaskExecution;
13
24
  readonly inputDigest: string;
14
25
  readonly outputDigest: null;
15
26
  readonly failure: null;
@@ -1 +1 @@
1
- {"version":3,"file":"dag-types.d.ts","sourceRoot":"","sources":["../../../src/core/verified-run/dag-types.ts"],"names":[],"mappings":"AAAA,UAAU,YAAY;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC5B;AACD,MAAM,MAAM,iBAAiB,GAAG,YAAY,GAC3C,CACG;IAAE,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,WAAW,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAA;CAAE,GAC/G;IACA,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAC3B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC;CACtB,GACD;IACA,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC;CACtB,GACD;IACA,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CACxB,CACH,CAAC;AACH,MAAM,MAAM,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,EAAE;IAAE,MAAM,EAAE,WAAW,CAAA;CAAE,CAAC,CAAC;AACpF,MAAM,MAAM,QAAQ,GACjB;IACA,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC3B,GACD;IACA,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;IAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC3B,GACD;IAAE,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAA;CAAE,CAAC","sourcesContent":["interface TaskIdentity {\n\treadonly taskId: string;\n\treadonly attempt: number;\n\treadonly generation: number;\n}\nexport type RunTaskProjection = TaskIdentity &\n\t(\n\t\t| { readonly status: \"pending\"; readonly inputDigest: null; readonly outputDigest: null; readonly failure: null }\n\t\t| {\n\t\t\t\treadonly status: \"running\";\n\t\t\t\treadonly inputDigest: string;\n\t\t\t\treadonly outputDigest: null;\n\t\t\t\treadonly failure: null;\n\t\t }\n\t\t| {\n\t\t\t\treadonly status: \"succeeded\";\n\t\t\t\treadonly inputDigest: string;\n\t\t\t\treadonly outputDigest: string;\n\t\t\t\treadonly failure: null;\n\t\t }\n\t\t| {\n\t\t\t\treadonly status: \"failed\";\n\t\t\t\treadonly inputDigest: string;\n\t\t\t\treadonly outputDigest: null;\n\t\t\t\treadonly failure: string;\n\t\t }\n\t);\nexport type RunTaskCheckpoint = Extract<RunTaskProjection, { status: \"succeeded\" }>;\nexport type DagEvent =\n\t| {\n\t\t\treadonly kind: \"task_started\";\n\t\t\treadonly taskId: string;\n\t\t\treadonly attempt: number;\n\t\t\treadonly inputDigest: string;\n\t\t\treadonly observedMs: number;\n\t }\n\t| {\n\t\t\treadonly kind: \"task_finished\";\n\t\t\treadonly taskId: string;\n\t\t\treadonly attempt: number;\n\t\t\treadonly outputDigest: string | null;\n\t\t\treadonly failure: string | null;\n\t\t\treadonly observedMs: number;\n\t }\n\t| { readonly kind: \"tasks_paused\" };\n"]}
1
+ {"version":3,"file":"dag-types.d.ts","sourceRoot":"","sources":["../../../src/core/verified-run/dag-types.ts"],"names":[],"mappings":"AAAA,UAAU,YAAY;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC5B;AACD,MAAM,MAAM,gBAAgB,GACzB;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAC1B;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GAC1D;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CA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QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;IAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC3B,GACD;IAAE,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAA;CAAE,CAAC","sourcesContent":["interface TaskIdentity {\n\treadonly taskId: string;\n\treadonly attempt: number;\n\treadonly generation: number;\n}\nexport type RunTaskExecution =\n\t| { readonly kind: \"ready\" }\n\t| { readonly kind: \"running\"; readonly executionId: string }\n\t| { readonly kind: \"exited\"; readonly executionId: string; readonly failure: string | null };\nexport type RunTaskProjection = TaskIdentity &\n\t(\n\t\t| { readonly status: \"pending\"; readonly inputDigest: null; readonly outputDigest: null; readonly failure: null }\n\t\t| {\n\t\t\t\treadonly status: \"running\";\n\t\t\t\treadonly execution: RunTaskExecution;\n\t\t\t\treadonly inputDigest: string;\n\t\t\t\treadonly outputDigest: null;\n\t\t\t\treadonly failure: null;\n\t\t }\n\t\t| {\n\t\t\t\treadonly status: \"succeeded\";\n\t\t\t\treadonly inputDigest: string;\n\t\t\t\treadonly outputDigest: string;\n\t\t\t\treadonly failure: null;\n\t\t }\n\t\t| {\n\t\t\t\treadonly status: \"failed\";\n\t\t\t\treadonly inputDigest: string;\n\t\t\t\treadonly outputDigest: null;\n\t\t\t\treadonly failure: string;\n\t\t }\n\t);\nexport type RunTaskCheckpoint = Extract<RunTaskProjection, { status: \"succeeded\" }>;\nexport type DagEvent =\n\t| {\n\t\t\treadonly kind: \"task_started\";\n\t\t\treadonly taskId: string;\n\t\t\treadonly attempt: number;\n\t\t\treadonly inputDigest: string;\n\t\t\treadonly observedMs: number;\n\t }\n\t| {\n\t\t\treadonly kind: \"task_finished\";\n\t\t\treadonly taskId: string;\n\t\t\treadonly attempt: number;\n\t\t\treadonly outputDigest: string | null;\n\t\t\treadonly failure: string | null;\n\t\t\treadonly observedMs: number;\n\t }\n\t| { readonly kind: \"tasks_paused\" };\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"dag-types.js","sourceRoot":"","sources":["../../../src/core/verified-run/dag-types.ts"],"names":[],"mappings":"","sourcesContent":["interface TaskIdentity {\n\treadonly taskId: string;\n\treadonly attempt: number;\n\treadonly generation: number;\n}\nexport type RunTaskProjection = TaskIdentity &\n\t(\n\t\t| { readonly status: \"pending\"; readonly inputDigest: null; readonly outputDigest: null; readonly failure: null }\n\t\t| {\n\t\t\t\treadonly status: \"running\";\n\t\t\t\treadonly inputDigest: string;\n\t\t\t\treadonly outputDigest: null;\n\t\t\t\treadonly failure: null;\n\t\t }\n\t\t| {\n\t\t\t\treadonly status: \"succeeded\";\n\t\t\t\treadonly inputDigest: string;\n\t\t\t\treadonly outputDigest: string;\n\t\t\t\treadonly failure: null;\n\t\t }\n\t\t| {\n\t\t\t\treadonly status: \"failed\";\n\t\t\t\treadonly inputDigest: string;\n\t\t\t\treadonly outputDigest: null;\n\t\t\t\treadonly failure: string;\n\t\t }\n\t);\nexport type RunTaskCheckpoint = Extract<RunTaskProjection, { status: \"succeeded\" }>;\nexport type DagEvent =\n\t| {\n\t\t\treadonly kind: \"task_started\";\n\t\t\treadonly taskId: string;\n\t\t\treadonly attempt: number;\n\t\t\treadonly inputDigest: string;\n\t\t\treadonly observedMs: number;\n\t }\n\t| {\n\t\t\treadonly kind: \"task_finished\";\n\t\t\treadonly taskId: string;\n\t\t\treadonly attempt: number;\n\t\t\treadonly outputDigest: string | null;\n\t\t\treadonly failure: string | null;\n\t\t\treadonly observedMs: number;\n\t }\n\t| { readonly kind: \"tasks_paused\" };\n"]}
1
+ {"version":3,"file":"dag-types.js","sourceRoot":"","sources":["../../../src/core/verified-run/dag-types.ts"],"names":[],"mappings":"","sourcesContent":["interface TaskIdentity {\n\treadonly taskId: string;\n\treadonly attempt: number;\n\treadonly generation: number;\n}\nexport type RunTaskExecution =\n\t| { readonly kind: \"ready\" }\n\t| { readonly kind: \"running\"; readonly executionId: string }\n\t| { readonly kind: \"exited\"; readonly executionId: string; readonly failure: string | null };\nexport type RunTaskProjection = TaskIdentity &\n\t(\n\t\t| { readonly status: \"pending\"; readonly inputDigest: null; readonly outputDigest: null; readonly failure: null }\n\t\t| {\n\t\t\t\treadonly status: \"running\";\n\t\t\t\treadonly execution: RunTaskExecution;\n\t\t\t\treadonly inputDigest: string;\n\t\t\t\treadonly outputDigest: null;\n\t\t\t\treadonly failure: null;\n\t\t }\n\t\t| {\n\t\t\t\treadonly status: \"succeeded\";\n\t\t\t\treadonly inputDigest: string;\n\t\t\t\treadonly outputDigest: string;\n\t\t\t\treadonly failure: null;\n\t\t }\n\t\t| {\n\t\t\t\treadonly status: \"failed\";\n\t\t\t\treadonly inputDigest: string;\n\t\t\t\treadonly outputDigest: null;\n\t\t\t\treadonly failure: string;\n\t\t }\n\t);\nexport type RunTaskCheckpoint = Extract<RunTaskProjection, { status: \"succeeded\" }>;\nexport type DagEvent =\n\t| {\n\t\t\treadonly kind: \"task_started\";\n\t\t\treadonly taskId: string;\n\t\t\treadonly attempt: number;\n\t\t\treadonly inputDigest: string;\n\t\t\treadonly observedMs: number;\n\t }\n\t| {\n\t\t\treadonly kind: \"task_finished\";\n\t\t\treadonly taskId: string;\n\t\t\treadonly attempt: number;\n\t\t\treadonly outputDigest: string | null;\n\t\t\treadonly failure: string | null;\n\t\t\treadonly observedMs: number;\n\t }\n\t| { readonly kind: \"tasks_paused\" };\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"event-parser.d.ts","sourceRoot":"","sources":["../../../src/core/verified-run/event-parser.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAgC/C,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,QAAQ,CA6GpD","sourcesContent":["import {\n\tparseRunContract,\n\tparseRunResumeCommand,\n\tparseRunStartCommand,\n\tparseRunTaskRetryCommand,\n\tparseRunWriterRestartCommand,\n} from \"omk-protocol\";\nimport type { RunTaskCheckpoint } from \"./dag-types.ts\";\nimport { parseNamespaceIdentity } from \"./namespace-identity.ts\";\nimport { parseRecoveryBudget } from \"./recovery-clock.ts\";\nimport type { RunEvent } from \"./run-types.ts\";\nimport { VerifiedRunError } from \"./storage.ts\";\n\nfunction text(value: unknown): string {\n\tif (typeof value !== \"string\" || !/^[A-Za-z0-9_-]{1,128}$/.test(value)) throw new VerifiedRunError(\"integrity\");\n\treturn value;\n}\nfunction digest(value: unknown): string {\n\tconst result = text(value);\n\tif (!/^[a-f0-9]{64}$/.test(result)) throw new VerifiedRunError(\"integrity\");\n\treturn result;\n}\nfunction integer(value: unknown): number {\n\tif (typeof value !== \"number\" || !Number.isSafeInteger(value) || value < 0) throw new VerifiedRunError(\"integrity\");\n\treturn value;\n}\n\nfunction checkpoint(raw: unknown): RunTaskCheckpoint {\n\tif (typeof raw !== \"object\" || raw === null) throw new VerifiedRunError(\"integrity\");\n\tconst value: Record<string, unknown> = Object.fromEntries(Object.entries(raw));\n\tif (value.status !== \"succeeded\" || value.failure !== null) throw new VerifiedRunError(\"integrity\");\n\treturn Object.freeze({\n\t\ttaskId: text(value.taskId),\n\t\tattempt: integer(value.attempt),\n\t\tgeneration: integer(value.generation),\n\t\tstatus: \"succeeded\",\n\t\tinputDigest: digest(value.inputDigest),\n\t\toutputDigest: digest(value.outputDigest),\n\t\tfailure: null,\n\t});\n}\n\nexport function parseRunEvent(raw: unknown): RunEvent {\n\tif (typeof raw !== \"object\" || raw === null || Array.isArray(raw)) throw new VerifiedRunError(\"integrity\");\n\tconst value: Record<string, unknown> = Object.fromEntries(Object.entries(raw));\n\tswitch (value.kind) {\n\t\tcase \"created\":\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\tcontract: parseRunContract(value.contract),\n\t\t\t\tcommand: parseRunStartCommand(value.command),\n\t\t\t};\n\t\tcase \"budget_anchored\":\n\t\t\tif (value.driver !== \"linux-pidns-gate-v1\") throw new VerifiedRunError(\"integrity\");\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\tbudget: parseRecoveryBudget(value.budget),\n\t\t\t\tenvironmentDigest: digest(value.environmentDigest),\n\t\t\t\tdriver: value.driver,\n\t\t\t};\n\t\tcase \"dispatch\": {\n\t\t\tif (value.role !== \"writer\" && value.role !== \"verifier\") throw new VerifiedRunError(\"integrity\");\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\texecutionId: text(value.executionId),\n\t\t\t\trole: value.role,\n\t\t\t\tclaimId: value.claimId === null ? null : text(value.claimId),\n\t\t\t};\n\t\t}\n\t\tcase \"input_checkpoint\":\n\t\t\treturn { kind: value.kind, digest: digest(value.digest) };\n\t\tcase \"process_ready\":\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\texecutionId: text(value.executionId),\n\t\t\t\tidentity: parseNamespaceIdentity(value.identity),\n\t\t\t};\n\t\tcase \"task_started\":\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\ttaskId: text(value.taskId),\n\t\t\t\tattempt: integer(value.attempt),\n\t\t\t\tinputDigest: digest(value.inputDigest),\n\t\t\t\tobservedMs: integer(value.observedMs),\n\t\t\t};\n\t\tcase \"task_finished\":\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\ttaskId: text(value.taskId),\n\t\t\t\tattempt: integer(value.attempt),\n\t\t\t\toutputDigest: value.outputDigest === null ? null : digest(value.outputDigest),\n\t\t\t\tfailure: value.failure === null ? null : text(value.failure),\n\t\t\t\tobservedMs: integer(value.observedMs),\n\t\t\t};\n\t\tcase \"tasks_paused\":\n\t\tcase \"writer_opened\":\n\t\t\treturn { kind: value.kind };\n\t\tcase \"model_request\":\n\t\t\treturn { kind: value.kind, requestId: text(value.requestId) };\n\t\tcase \"writer_closed\":\n\t\t\tif (typeof value.completed !== \"boolean\") throw new VerifiedRunError(\"integrity\");\n\t\t\treturn { kind: value.kind, completed: value.completed };\n\t\tcase \"exited\":\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\texecutionId: text(value.executionId),\n\t\t\t\tfailure: value.failure === null ? null : text(value.failure),\n\t\t\t};\n\t\tcase \"candidate\":\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\tdigest: digest(value.digest),\n\t\t\t\t...(value.observedMs === undefined ? {} : { observedMs: integer(value.observedMs) }),\n\t\t\t\t...(value.verificationDeadlineMs === undefined\n\t\t\t\t\t? {}\n\t\t\t\t\t: { verificationDeadlineMs: integer(value.verificationDeadlineMs) }),\n\t\t\t};\n\t\tcase \"resumed\":\n\t\tcase \"tasks_retried\":\n\t\tcase \"writer_restarted\": {\n\t\t\tif (!Array.isArray(value.reconciledExecutionIds) || value.reconciledExecutionIds.length > 128)\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\tconst fields = {\n\t\t\t\tobservedMs: integer(value.observedMs),\n\t\t\t\treconciledExecutionIds: Object.freeze(value.reconciledExecutionIds.map(text)),\n\t\t\t};\n\t\t\tswitch (value.kind) {\n\t\t\t\tcase \"resumed\":\n\t\t\t\t\treturn { ...fields, kind: value.kind, command: parseRunResumeCommand(value.command) };\n\t\t\t\tcase \"writer_restarted\":\n\t\t\t\t\treturn { ...fields, kind: value.kind, command: parseRunWriterRestartCommand(value.command) };\n\t\t\t\tcase \"tasks_retried\":\n\t\t\t\t\tif (!Array.isArray(value.adopted) || value.adopted.length > 16) throw new VerifiedRunError(\"integrity\");\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...fields,\n\t\t\t\t\t\tkind: value.kind,\n\t\t\t\t\t\tcommand: parseRunTaskRetryCommand(value.command),\n\t\t\t\t\t\tadopted: Object.freeze(value.adopted.map(checkpoint)),\n\t\t\t\t\t};\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t}\n\t\t}\n\t\tcase \"evaluated\":\n\t\t\tif (typeof value.verified !== \"boolean\") throw new VerifiedRunError(\"integrity\");\n\t\t\treturn { kind: value.kind, receiptDigest: digest(value.receiptDigest), verified: value.verified };\n\t\tcase \"failed\":\n\t\t\treturn { kind: value.kind, code: text(value.code) };\n\t\tdefault:\n\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t}\n}\n"]}
1
+ {"version":3,"file":"event-parser.d.ts","sourceRoot":"","sources":["../../../src/core/verified-run/event-parser.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAgC/C,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,QAAQ,CA8GpD","sourcesContent":["import {\n\tparseRunContract,\n\tparseRunResumeCommand,\n\tparseRunStartCommand,\n\tparseRunTaskRetryCommand,\n\tparseRunWriterRestartCommand,\n} from \"omk-protocol\";\nimport type { RunTaskCheckpoint } from \"./dag-types.ts\";\nimport { parseNamespaceIdentity } from \"./namespace-identity.ts\";\nimport { parseRecoveryBudget } from \"./recovery-clock.ts\";\nimport type { RunEvent } from \"./run-types.ts\";\nimport { VerifiedRunError } from \"./storage.ts\";\n\nfunction text(value: unknown): string {\n\tif (typeof value !== \"string\" || !/^[A-Za-z0-9_-]{1,128}$/.test(value)) throw new VerifiedRunError(\"integrity\");\n\treturn value;\n}\nfunction digest(value: unknown): string {\n\tconst result = text(value);\n\tif (!/^[a-f0-9]{64}$/.test(result)) throw new VerifiedRunError(\"integrity\");\n\treturn result;\n}\nfunction integer(value: unknown): number {\n\tif (typeof value !== \"number\" || !Number.isSafeInteger(value) || value < 0) throw new VerifiedRunError(\"integrity\");\n\treturn value;\n}\n\nfunction checkpoint(raw: unknown): RunTaskCheckpoint {\n\tif (typeof raw !== \"object\" || raw === null) throw new VerifiedRunError(\"integrity\");\n\tconst value: Record<string, unknown> = Object.fromEntries(Object.entries(raw));\n\tif (value.status !== \"succeeded\" || value.failure !== null) throw new VerifiedRunError(\"integrity\");\n\treturn Object.freeze({\n\t\ttaskId: text(value.taskId),\n\t\tattempt: integer(value.attempt),\n\t\tgeneration: integer(value.generation),\n\t\tstatus: \"succeeded\",\n\t\tinputDigest: digest(value.inputDigest),\n\t\toutputDigest: digest(value.outputDigest),\n\t\tfailure: null,\n\t});\n}\n\nexport function parseRunEvent(raw: unknown): RunEvent {\n\tif (typeof raw !== \"object\" || raw === null || Array.isArray(raw)) throw new VerifiedRunError(\"integrity\");\n\tconst value: Record<string, unknown> = Object.fromEntries(Object.entries(raw));\n\tswitch (value.kind) {\n\t\tcase \"created\":\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\tcontract: parseRunContract(value.contract),\n\t\t\t\tcommand: parseRunStartCommand(value.command),\n\t\t\t};\n\t\tcase \"budget_anchored\":\n\t\t\tif (value.driver !== \"linux-pidns-gate-v1\") throw new VerifiedRunError(\"integrity\");\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\tbudget: parseRecoveryBudget(value.budget),\n\t\t\t\tenvironmentDigest: digest(value.environmentDigest),\n\t\t\t\tdriver: value.driver,\n\t\t\t};\n\t\tcase \"dispatch\": {\n\t\t\tif (value.role !== \"writer\" && value.role !== \"verifier\") throw new VerifiedRunError(\"integrity\");\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\texecutionId: text(value.executionId),\n\t\t\t\trole: value.role,\n\t\t\t\tclaimId: value.claimId === null ? null : text(value.claimId),\n\t\t\t\t...(value.taskId === undefined ? {} : { taskId: text(value.taskId) }),\n\t\t\t};\n\t\t}\n\t\tcase \"input_checkpoint\":\n\t\t\treturn { kind: value.kind, digest: digest(value.digest) };\n\t\tcase \"process_ready\":\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\texecutionId: text(value.executionId),\n\t\t\t\tidentity: parseNamespaceIdentity(value.identity),\n\t\t\t};\n\t\tcase \"task_started\":\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\ttaskId: text(value.taskId),\n\t\t\t\tattempt: integer(value.attempt),\n\t\t\t\tinputDigest: digest(value.inputDigest),\n\t\t\t\tobservedMs: integer(value.observedMs),\n\t\t\t};\n\t\tcase \"task_finished\":\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\ttaskId: text(value.taskId),\n\t\t\t\tattempt: integer(value.attempt),\n\t\t\t\toutputDigest: value.outputDigest === null ? null : digest(value.outputDigest),\n\t\t\t\tfailure: value.failure === null ? null : text(value.failure),\n\t\t\t\tobservedMs: integer(value.observedMs),\n\t\t\t};\n\t\tcase \"tasks_paused\":\n\t\tcase \"writer_opened\":\n\t\t\treturn { kind: value.kind };\n\t\tcase \"model_request\":\n\t\t\treturn { kind: value.kind, requestId: text(value.requestId) };\n\t\tcase \"writer_closed\":\n\t\t\tif (typeof value.completed !== \"boolean\") throw new VerifiedRunError(\"integrity\");\n\t\t\treturn { kind: value.kind, completed: value.completed };\n\t\tcase \"exited\":\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\texecutionId: text(value.executionId),\n\t\t\t\tfailure: value.failure === null ? null : text(value.failure),\n\t\t\t};\n\t\tcase \"candidate\":\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\tdigest: digest(value.digest),\n\t\t\t\t...(value.observedMs === undefined ? {} : { observedMs: integer(value.observedMs) }),\n\t\t\t\t...(value.verificationDeadlineMs === undefined\n\t\t\t\t\t? {}\n\t\t\t\t\t: { verificationDeadlineMs: integer(value.verificationDeadlineMs) }),\n\t\t\t};\n\t\tcase \"resumed\":\n\t\tcase \"tasks_retried\":\n\t\tcase \"writer_restarted\": {\n\t\t\tif (!Array.isArray(value.reconciledExecutionIds) || value.reconciledExecutionIds.length > 128)\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\tconst fields = {\n\t\t\t\tobservedMs: integer(value.observedMs),\n\t\t\t\treconciledExecutionIds: Object.freeze(value.reconciledExecutionIds.map(text)),\n\t\t\t};\n\t\t\tswitch (value.kind) {\n\t\t\t\tcase \"resumed\":\n\t\t\t\t\treturn { ...fields, kind: value.kind, command: parseRunResumeCommand(value.command) };\n\t\t\t\tcase \"writer_restarted\":\n\t\t\t\t\treturn { ...fields, kind: value.kind, command: parseRunWriterRestartCommand(value.command) };\n\t\t\t\tcase \"tasks_retried\":\n\t\t\t\t\tif (!Array.isArray(value.adopted) || value.adopted.length > 16) throw new VerifiedRunError(\"integrity\");\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...fields,\n\t\t\t\t\t\tkind: value.kind,\n\t\t\t\t\t\tcommand: parseRunTaskRetryCommand(value.command),\n\t\t\t\t\t\tadopted: Object.freeze(value.adopted.map(checkpoint)),\n\t\t\t\t\t};\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t}\n\t\t}\n\t\tcase \"evaluated\":\n\t\t\tif (typeof value.verified !== \"boolean\") throw new VerifiedRunError(\"integrity\");\n\t\t\treturn { kind: value.kind, receiptDigest: digest(value.receiptDigest), verified: value.verified };\n\t\tcase \"failed\":\n\t\t\treturn { kind: value.kind, code: text(value.code) };\n\t\tdefault:\n\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t}\n}\n"]}
@@ -62,6 +62,7 @@ export function parseRunEvent(raw) {
62
62
  executionId: text(value.executionId),
63
63
  role: value.role,
64
64
  claimId: value.claimId === null ? null : text(value.claimId),
65
+ ...(value.taskId === undefined ? {} : { taskId: text(value.taskId) }),
65
66
  };
66
67
  }
67
68
  case "input_checkpoint":
@@ -1 +1 @@
1
- {"version":3,"file":"event-parser.js","sourceRoot":"","sources":["../../../src/core/verified-run/event-parser.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,gBAAgB,EAChB,qBAAqB,EACrB,oBAAoB,EACpB,wBAAwB,EACxB,4BAA4B,GAC5B,MAAM,cAAc,CAA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AAM,IAAI,gBAAgB,CAAC,WAAW,CAAC,CAAC;oBACxG,OAAO;wBACN,GAAG,MAAM;wBACT,IAAI,EAAE,KAAK,CAAC,IAAI;wBAChB,OAAO,EAAE,wBAAwB,CAAC,KAAK,CAAC,OAAO,CAAC;wBAChD,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;qBACrD,CAAC;gBACH;oBACC,MAAM,IAAI,gBAAgB,CAAC,WAAW,CAAC,CAAC;YAC1C,CAAC;QACF,CAAC;QACD,KAAK,WAAW;YACf,IAAI,OAAO,KAAK,CAAC,QAAQ,KAAK,SAAS;gBAAE,MAAM,IAAI,gBAAgB,CAAC,WAAW,CAAC,CAAC;YACjF,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,aAAa,EAAE,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC;QACnG,KAAK,QAAQ;YACZ,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QACrD;YACC,MAAM,IAAI,gBAAgB,CAAC,WAAW,CAAC,CAAC;IAC1C,CAAC;AAAA,CACD","sourcesContent":["import {\n\tparseRunContract,\n\tparseRunResumeCommand,\n\tparseRunStartCommand,\n\tparseRunTaskRetryCommand,\n\tparseRunWriterRestartCommand,\n} from \"omk-protocol\";\nimport type { RunTaskCheckpoint } from \"./dag-types.ts\";\nimport { parseNamespaceIdentity } from \"./namespace-identity.ts\";\nimport { parseRecoveryBudget } from \"./recovery-clock.ts\";\nimport type { RunEvent } from \"./run-types.ts\";\nimport { VerifiedRunError } from \"./storage.ts\";\n\nfunction text(value: unknown): string {\n\tif (typeof value !== \"string\" || !/^[A-Za-z0-9_-]{1,128}$/.test(value)) throw new VerifiedRunError(\"integrity\");\n\treturn value;\n}\nfunction digest(value: unknown): string {\n\tconst result = text(value);\n\tif (!/^[a-f0-9]{64}$/.test(result)) throw new VerifiedRunError(\"integrity\");\n\treturn result;\n}\nfunction integer(value: unknown): number {\n\tif (typeof value !== \"number\" || !Number.isSafeInteger(value) || value < 0) throw new VerifiedRunError(\"integrity\");\n\treturn value;\n}\n\nfunction checkpoint(raw: unknown): RunTaskCheckpoint {\n\tif (typeof raw !== \"object\" || raw === null) throw new VerifiedRunError(\"integrity\");\n\tconst value: Record<string, unknown> = Object.fromEntries(Object.entries(raw));\n\tif (value.status !== \"succeeded\" || value.failure !== null) throw new VerifiedRunError(\"integrity\");\n\treturn Object.freeze({\n\t\ttaskId: text(value.taskId),\n\t\tattempt: integer(value.attempt),\n\t\tgeneration: integer(value.generation),\n\t\tstatus: \"succeeded\",\n\t\tinputDigest: digest(value.inputDigest),\n\t\toutputDigest: digest(value.outputDigest),\n\t\tfailure: null,\n\t});\n}\n\nexport function parseRunEvent(raw: unknown): RunEvent {\n\tif (typeof raw !== \"object\" || raw === null || Array.isArray(raw)) throw new VerifiedRunError(\"integrity\");\n\tconst value: Record<string, unknown> = Object.fromEntries(Object.entries(raw));\n\tswitch (value.kind) {\n\t\tcase \"created\":\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\tcontract: parseRunContract(value.contract),\n\t\t\t\tcommand: parseRunStartCommand(value.command),\n\t\t\t};\n\t\tcase \"budget_anchored\":\n\t\t\tif (value.driver !== \"linux-pidns-gate-v1\") throw new VerifiedRunError(\"integrity\");\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\tbudget: parseRecoveryBudget(value.budget),\n\t\t\t\tenvironmentDigest: digest(value.environmentDigest),\n\t\t\t\tdriver: value.driver,\n\t\t\t};\n\t\tcase \"dispatch\": {\n\t\t\tif (value.role !== \"writer\" && value.role !== \"verifier\") throw new VerifiedRunError(\"integrity\");\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\texecutionId: text(value.executionId),\n\t\t\t\trole: value.role,\n\t\t\t\tclaimId: value.claimId === null ? null : text(value.claimId),\n\t\t\t};\n\t\t}\n\t\tcase \"input_checkpoint\":\n\t\t\treturn { kind: value.kind, digest: digest(value.digest) };\n\t\tcase \"process_ready\":\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\texecutionId: text(value.executionId),\n\t\t\t\tidentity: parseNamespaceIdentity(value.identity),\n\t\t\t};\n\t\tcase \"task_started\":\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\ttaskId: text(value.taskId),\n\t\t\t\tattempt: integer(value.attempt),\n\t\t\t\tinputDigest: digest(value.inputDigest),\n\t\t\t\tobservedMs: integer(value.observedMs),\n\t\t\t};\n\t\tcase \"task_finished\":\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\ttaskId: text(value.taskId),\n\t\t\t\tattempt: integer(value.attempt),\n\t\t\t\toutputDigest: value.outputDigest === null ? null : digest(value.outputDigest),\n\t\t\t\tfailure: value.failure === null ? null : text(value.failure),\n\t\t\t\tobservedMs: integer(value.observedMs),\n\t\t\t};\n\t\tcase \"tasks_paused\":\n\t\tcase \"writer_opened\":\n\t\t\treturn { kind: value.kind };\n\t\tcase \"model_request\":\n\t\t\treturn { kind: value.kind, requestId: text(value.requestId) };\n\t\tcase \"writer_closed\":\n\t\t\tif (typeof value.completed !== \"boolean\") throw new VerifiedRunError(\"integrity\");\n\t\t\treturn { kind: value.kind, completed: value.completed };\n\t\tcase \"exited\":\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\texecutionId: text(value.executionId),\n\t\t\t\tfailure: value.failure === null ? null : text(value.failure),\n\t\t\t};\n\t\tcase \"candidate\":\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\tdigest: digest(value.digest),\n\t\t\t\t...(value.observedMs === undefined ? {} : { observedMs: integer(value.observedMs) }),\n\t\t\t\t...(value.verificationDeadlineMs === undefined\n\t\t\t\t\t? {}\n\t\t\t\t\t: { verificationDeadlineMs: integer(value.verificationDeadlineMs) }),\n\t\t\t};\n\t\tcase \"resumed\":\n\t\tcase \"tasks_retried\":\n\t\tcase \"writer_restarted\": {\n\t\t\tif (!Array.isArray(value.reconciledExecutionIds) || value.reconciledExecutionIds.length > 128)\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\tconst fields = {\n\t\t\t\tobservedMs: integer(value.observedMs),\n\t\t\t\treconciledExecutionIds: Object.freeze(value.reconciledExecutionIds.map(text)),\n\t\t\t};\n\t\t\tswitch (value.kind) {\n\t\t\t\tcase \"resumed\":\n\t\t\t\t\treturn { ...fields, kind: value.kind, command: parseRunResumeCommand(value.command) };\n\t\t\t\tcase \"writer_restarted\":\n\t\t\t\t\treturn { ...fields, kind: value.kind, command: parseRunWriterRestartCommand(value.command) };\n\t\t\t\tcase \"tasks_retried\":\n\t\t\t\t\tif (!Array.isArray(value.adopted) || value.adopted.length > 16) throw new VerifiedRunError(\"integrity\");\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...fields,\n\t\t\t\t\t\tkind: value.kind,\n\t\t\t\t\t\tcommand: parseRunTaskRetryCommand(value.command),\n\t\t\t\t\t\tadopted: Object.freeze(value.adopted.map(checkpoint)),\n\t\t\t\t\t};\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t}\n\t\t}\n\t\tcase \"evaluated\":\n\t\t\tif (typeof value.verified !== \"boolean\") throw new VerifiedRunError(\"integrity\");\n\t\t\treturn { kind: value.kind, receiptDigest: digest(value.receiptDigest), verified: value.verified };\n\t\tcase \"failed\":\n\t\t\treturn { kind: value.kind, code: text(value.code) };\n\t\tdefault:\n\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t}\n}\n"]}
1
+ {"version":3,"file":"event-parser.js","sourceRoot":"","sources":["../../../src/core/verified-run/event-parser.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,gBAAgB,E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EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,4BAA4B,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC9F,KAAK,eAAe;oBACnB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,EAAE;wBAAE,MAAM,IAAI,gBAAgB,CAAC,WAAW,CAAC,CAAC;oBACxG,OAAO;wBACN,GAAG,MAAM;wBACT,IAAI,EAAE,KAAK,CAAC,IAAI;wBAChB,OAAO,EAAE,wBAAwB,CAAC,KAAK,CAAC,OAAO,CAAC;wBAChD,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;qBACrD,CAAC;gBACH;oBACC,MAAM,IAAI,gBAAgB,CAAC,WAAW,CAAC,CAAC;YAC1C,CAAC;QACF,CAAC;QACD,KAAK,WAAW;YACf,IAAI,OAAO,KAAK,CAAC,QAAQ,KAAK,SAAS;gBAAE,MAAM,IAAI,gBAAgB,CAAC,WAAW,CAAC,CAAC;YACjF,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,aAAa,EAAE,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC;QACnG,KAAK,QAAQ;YACZ,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QACrD;YACC,MAAM,IAAI,gBAAgB,CAAC,WAAW,CAAC,CAAC;IAC1C,CAAC;AAAA,CACD","sourcesContent":["import {\n\tparseRunContract,\n\tparseRunResumeCommand,\n\tparseRunStartCommand,\n\tparseRunTaskRetryCommand,\n\tparseRunWriterRestartCommand,\n} from \"omk-protocol\";\nimport type { RunTaskCheckpoint } from \"./dag-types.ts\";\nimport { parseNamespaceIdentity } from \"./namespace-identity.ts\";\nimport { parseRecoveryBudget } from \"./recovery-clock.ts\";\nimport type { RunEvent } from \"./run-types.ts\";\nimport { VerifiedRunError } from \"./storage.ts\";\n\nfunction text(value: unknown): string {\n\tif (typeof value !== \"string\" || !/^[A-Za-z0-9_-]{1,128}$/.test(value)) throw new VerifiedRunError(\"integrity\");\n\treturn value;\n}\nfunction digest(value: unknown): string {\n\tconst result = text(value);\n\tif (!/^[a-f0-9]{64}$/.test(result)) throw new VerifiedRunError(\"integrity\");\n\treturn result;\n}\nfunction integer(value: unknown): number {\n\tif (typeof value !== \"number\" || !Number.isSafeInteger(value) || value < 0) throw new VerifiedRunError(\"integrity\");\n\treturn value;\n}\n\nfunction checkpoint(raw: unknown): RunTaskCheckpoint {\n\tif (typeof raw !== \"object\" || raw === null) throw new VerifiedRunError(\"integrity\");\n\tconst value: Record<string, unknown> = Object.fromEntries(Object.entries(raw));\n\tif (value.status !== \"succeeded\" || value.failure !== null) throw new VerifiedRunError(\"integrity\");\n\treturn Object.freeze({\n\t\ttaskId: text(value.taskId),\n\t\tattempt: integer(value.attempt),\n\t\tgeneration: integer(value.generation),\n\t\tstatus: \"succeeded\",\n\t\tinputDigest: digest(value.inputDigest),\n\t\toutputDigest: digest(value.outputDigest),\n\t\tfailure: null,\n\t});\n}\n\nexport function parseRunEvent(raw: unknown): RunEvent {\n\tif (typeof raw !== \"object\" || raw === null || Array.isArray(raw)) throw new VerifiedRunError(\"integrity\");\n\tconst value: Record<string, unknown> = Object.fromEntries(Object.entries(raw));\n\tswitch (value.kind) {\n\t\tcase \"created\":\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\tcontract: parseRunContract(value.contract),\n\t\t\t\tcommand: parseRunStartCommand(value.command),\n\t\t\t};\n\t\tcase \"budget_anchored\":\n\t\t\tif (value.driver !== \"linux-pidns-gate-v1\") throw new VerifiedRunError(\"integrity\");\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\tbudget: parseRecoveryBudget(value.budget),\n\t\t\t\tenvironmentDigest: digest(value.environmentDigest),\n\t\t\t\tdriver: value.driver,\n\t\t\t};\n\t\tcase \"dispatch\": {\n\t\t\tif (value.role !== \"writer\" && value.role !== \"verifier\") throw new VerifiedRunError(\"integrity\");\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\texecutionId: text(value.executionId),\n\t\t\t\trole: value.role,\n\t\t\t\tclaimId: value.claimId === null ? null : text(value.claimId),\n\t\t\t\t...(value.taskId === undefined ? {} : { taskId: text(value.taskId) }),\n\t\t\t};\n\t\t}\n\t\tcase \"input_checkpoint\":\n\t\t\treturn { kind: value.kind, digest: digest(value.digest) };\n\t\tcase \"process_ready\":\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\texecutionId: text(value.executionId),\n\t\t\t\tidentity: parseNamespaceIdentity(value.identity),\n\t\t\t};\n\t\tcase \"task_started\":\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\ttaskId: text(value.taskId),\n\t\t\t\tattempt: integer(value.attempt),\n\t\t\t\tinputDigest: digest(value.inputDigest),\n\t\t\t\tobservedMs: integer(value.observedMs),\n\t\t\t};\n\t\tcase \"task_finished\":\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\ttaskId: text(value.taskId),\n\t\t\t\tattempt: integer(value.attempt),\n\t\t\t\toutputDigest: value.outputDigest === null ? null : digest(value.outputDigest),\n\t\t\t\tfailure: value.failure === null ? null : text(value.failure),\n\t\t\t\tobservedMs: integer(value.observedMs),\n\t\t\t};\n\t\tcase \"tasks_paused\":\n\t\tcase \"writer_opened\":\n\t\t\treturn { kind: value.kind };\n\t\tcase \"model_request\":\n\t\t\treturn { kind: value.kind, requestId: text(value.requestId) };\n\t\tcase \"writer_closed\":\n\t\t\tif (typeof value.completed !== \"boolean\") throw new VerifiedRunError(\"integrity\");\n\t\t\treturn { kind: value.kind, completed: value.completed };\n\t\tcase \"exited\":\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\texecutionId: text(value.executionId),\n\t\t\t\tfailure: value.failure === null ? null : text(value.failure),\n\t\t\t};\n\t\tcase \"candidate\":\n\t\t\treturn {\n\t\t\t\tkind: value.kind,\n\t\t\t\tdigest: digest(value.digest),\n\t\t\t\t...(value.observedMs === undefined ? {} : { observedMs: integer(value.observedMs) }),\n\t\t\t\t...(value.verificationDeadlineMs === undefined\n\t\t\t\t\t? {}\n\t\t\t\t\t: { verificationDeadlineMs: integer(value.verificationDeadlineMs) }),\n\t\t\t};\n\t\tcase \"resumed\":\n\t\tcase \"tasks_retried\":\n\t\tcase \"writer_restarted\": {\n\t\t\tif (!Array.isArray(value.reconciledExecutionIds) || value.reconciledExecutionIds.length > 128)\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\tconst fields = {\n\t\t\t\tobservedMs: integer(value.observedMs),\n\t\t\t\treconciledExecutionIds: Object.freeze(value.reconciledExecutionIds.map(text)),\n\t\t\t};\n\t\t\tswitch (value.kind) {\n\t\t\t\tcase \"resumed\":\n\t\t\t\t\treturn { ...fields, kind: value.kind, command: parseRunResumeCommand(value.command) };\n\t\t\t\tcase \"writer_restarted\":\n\t\t\t\t\treturn { ...fields, kind: value.kind, command: parseRunWriterRestartCommand(value.command) };\n\t\t\t\tcase \"tasks_retried\":\n\t\t\t\t\tif (!Array.isArray(value.adopted) || value.adopted.length > 16) throw new VerifiedRunError(\"integrity\");\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...fields,\n\t\t\t\t\t\tkind: value.kind,\n\t\t\t\t\t\tcommand: parseRunTaskRetryCommand(value.command),\n\t\t\t\t\t\tadopted: Object.freeze(value.adopted.map(checkpoint)),\n\t\t\t\t\t};\n\t\t\t\tdefault:\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t}\n\t\t}\n\t\tcase \"evaluated\":\n\t\t\tif (typeof value.verified !== \"boolean\") throw new VerifiedRunError(\"integrity\");\n\t\t\treturn { kind: value.kind, receiptDigest: digest(value.receiptDigest), verified: value.verified };\n\t\tcase \"failed\":\n\t\t\treturn { kind: value.kind, code: text(value.code) };\n\t\tdefault:\n\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t}\n}\n"]}
@@ -6,6 +6,7 @@ export interface OwnedRunCommand {
6
6
  readonly workspace: string;
7
7
  readonly deadline: number;
8
8
  readonly claimId: string | null;
9
+ readonly taskId?: string;
9
10
  }
10
11
  export interface OwnedRunResult {
11
12
  readonly executionId: string;
@@ -1 +1 @@
1
- {"version":3,"file":"owned-execution.d.ts","sourceRoot":"","sources":["../../../src/core/verified-run/owned-execution.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAIvD,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,UAAU,CAAC;IACrC,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AACD,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC3B;AAED,2FAA2F;AAC3F,wBAAsB,iBAAiB,CACtC,OAAO,EAAE,kBAAkB,EAC3B,OAAO,EAAE,eAAe,EACxB,MAAM,EAAE;IACP,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC9B,GACC,OAAO,CAAC,cAAc,CAAC,CAgCzB","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { performance } from \"node:perf_hooks\";\nimport { executeSandbox, type SandboxOutcome } from \"./broker.ts\";\nimport type { VerifiedRunJournal } from \"./journal.ts\";\nimport type { NamespaceIdentity } from \"./namespace-identity.ts\";\nimport { VerifiedRunError } from \"./storage.ts\";\n\nexport interface OwnedRunCommand {\n\treadonly role: \"writer\" | \"verifier\";\n\treadonly argv: readonly string[];\n\treadonly workspace: string;\n\treadonly deadline: number;\n\treadonly claimId: string | null;\n}\nexport interface OwnedRunResult {\n\treadonly executionId: string;\n\treadonly result: SandboxOutcome;\n\treadonly timeoutMs: number;\n}\n\n/** The mandatory durable intent boundary is shared by command and AgentSession writers. */\nexport async function executeRunCommand(\n\tjournal: VerifiedRunJournal,\n\trequest: OwnedRunCommand,\n\tpolicy: {\n\t\treadonly cleanupMs: number;\n\t\treadonly maxOutputBytes: number;\n\t\treadonly signal?: AbortSignal;\n\t},\n): Promise<OwnedRunResult> {\n\tif (Math.floor(request.deadline - performance.now()) <= 0) throw new VerifiedRunError(\"deadline\");\n\tif (policy.signal?.aborted) throw new VerifiedRunError(\"cancelled\");\n\tconst generation = journal.state.generation;\n\tconst executionId = randomUUID();\n\tjournal.append({ kind: \"dispatch\", executionId, role: request.role, claimId: request.claimId });\n\tconst timeoutMs = Math.floor(request.deadline - performance.now());\n\tif (timeoutMs <= 0 || policy.signal?.aborted) {\n\t\tconst failure = policy.signal?.aborted ? \"cancelled\" : \"deadline\";\n\t\tjournal.append({ kind: \"exited\", executionId, failure });\n\t\tthrow new VerifiedRunError(failure);\n\t}\n\tconst result = await executeSandbox({\n\t\tworkspace: request.workspace,\n\t\targv: request.argv,\n\t\twritable: request.role === \"writer\",\n\t\ttimeoutMs,\n\t\tcleanupMs: policy.cleanupMs,\n\t\tmaxOutputBytes: policy.maxOutputBytes,\n\t\t...(policy.signal ? { signal: policy.signal } : {}),\n\t\t...(journal.state.budget\n\t\t\t? {\n\t\t\t\t\tonReady: (identity: NamespaceIdentity) => {\n\t\t\t\t\t\tif (journal.state.generation !== generation) throw new VerifiedRunError(\"stale_generation\");\n\t\t\t\t\t\tjournal.append({ kind: \"process_ready\", executionId, identity });\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t: {}),\n\t});\n\tif (journal.state.generation !== generation) throw new VerifiedRunError(\"stale_generation\");\n\tjournal.append({ kind: \"exited\", executionId, failure: request.role === \"writer\" ? result.failure : null });\n\treturn { executionId, result, timeoutMs };\n}\n"]}
1
+ {"version":3,"file":"owned-execution.d.ts","sourceRoot":"","sources":["../../../src/core/verified-run/owned-execution.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAIvD,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,UAAU,CAAC;IACrC,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CACzB;AACD,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC3B;AAED,2FAA2F;AAC3F,wBAAsB,iBAAiB,CACtC,OAAO,EAAE,kBAAkB,EAC3B,OAAO,EAAE,eAAe,EACxB,MAAM,EAAE;IACP,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC9B,GACC,OAAO,CAAC,cAAc,CAAC,CAsCzB","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { performance } from \"node:perf_hooks\";\nimport { executeSandbox, type SandboxOutcome } from \"./broker.ts\";\nimport type { VerifiedRunJournal } from \"./journal.ts\";\nimport type { NamespaceIdentity } from \"./namespace-identity.ts\";\nimport { VerifiedRunError } from \"./storage.ts\";\n\nexport interface OwnedRunCommand {\n\treadonly role: \"writer\" | \"verifier\";\n\treadonly argv: readonly string[];\n\treadonly workspace: string;\n\treadonly deadline: number;\n\treadonly claimId: string | null;\n\treadonly taskId?: string;\n}\nexport interface OwnedRunResult {\n\treadonly executionId: string;\n\treadonly result: SandboxOutcome;\n\treadonly timeoutMs: number;\n}\n\n/** The mandatory durable intent boundary is shared by command and AgentSession writers. */\nexport async function executeRunCommand(\n\tjournal: VerifiedRunJournal,\n\trequest: OwnedRunCommand,\n\tpolicy: {\n\t\treadonly cleanupMs: number;\n\t\treadonly maxOutputBytes: number;\n\t\treadonly signal?: AbortSignal;\n\t},\n): Promise<OwnedRunResult> {\n\tif (Math.floor(request.deadline - performance.now()) <= 0) throw new VerifiedRunError(\"deadline\");\n\tif (policy.signal?.aborted) throw new VerifiedRunError(\"cancelled\");\n\tconst generation = journal.state.generation;\n\tconst executionId = randomUUID();\n\tjournal.append({\n\t\tkind: \"dispatch\",\n\t\texecutionId,\n\t\trole: request.role,\n\t\tclaimId: request.claimId,\n\t\t...(request.taskId === undefined ? {} : { taskId: request.taskId }),\n\t});\n\tconst timeoutMs = Math.floor(request.deadline - performance.now());\n\tif (timeoutMs <= 0 || policy.signal?.aborted) {\n\t\tconst failure = policy.signal?.aborted ? \"cancelled\" : \"deadline\";\n\t\tjournal.append({ kind: \"exited\", executionId, failure });\n\t\tthrow new VerifiedRunError(failure);\n\t}\n\tconst result = await executeSandbox({\n\t\tworkspace: request.workspace,\n\t\targv: request.argv,\n\t\twritable: request.role === \"writer\",\n\t\ttimeoutMs,\n\t\tcleanupMs: policy.cleanupMs,\n\t\tmaxOutputBytes: policy.maxOutputBytes,\n\t\t...(policy.signal ? { signal: policy.signal } : {}),\n\t\t...(journal.state.budget\n\t\t\t? {\n\t\t\t\t\tonReady: (identity: NamespaceIdentity) => {\n\t\t\t\t\t\tif (journal.state.generation !== generation) throw new VerifiedRunError(\"stale_generation\");\n\t\t\t\t\t\tjournal.append({ kind: \"process_ready\", executionId, identity });\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t: {}),\n\t});\n\tif (journal.state.generation !== generation) throw new VerifiedRunError(\"stale_generation\");\n\tjournal.append({ kind: \"exited\", executionId, failure: request.role === \"writer\" ? result.failure : null });\n\treturn { executionId, result, timeoutMs };\n}\n"]}
@@ -10,7 +10,13 @@ export async function executeRunCommand(journal, request, policy) {
10
10
  throw new VerifiedRunError("cancelled");
11
11
  const generation = journal.state.generation;
12
12
  const executionId = randomUUID();
13
- journal.append({ kind: "dispatch", executionId, role: request.role, claimId: request.claimId });
13
+ journal.append({
14
+ kind: "dispatch",
15
+ executionId,
16
+ role: request.role,
17
+ claimId: request.claimId,
18
+ ...(request.taskId === undefined ? {} : { taskId: request.taskId }),
19
+ });
14
20
  const timeoutMs = Math.floor(request.deadline - performance.now());
15
21
  if (timeoutMs <= 0 || policy.signal?.aborted) {
16
22
  const failure = policy.signal?.aborted ? "cancelled" : "deadline";
@@ -1 +1 @@
1
- {"version":3,"file":"owned-execution.js","sourceRoot":"","sources":["../../../src/core/verified-run/owned-execution.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAuB,MAAM,aAAa,CAAC;AAGlE,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAehD,2FAA2F;AAC3F,MA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E,MAAM,CAAC,SAAS;QAC3B,cAAc,EAAE,MAAM,CAAC,cAAc;QACrC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACnD,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM;YACvB,CAAC,CAAC;gBACA,OAAO,EAAE,CAAC,QAA2B,EAAE,EAAE,CAAC;oBACzC,IAAI,OAAO,CAAC,KAAK,CAAC,UAAU,KAAK,UAAU;wBAAE,MAAM,IAAI,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;oBAC5F,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC,CAAC;gBAAA,CACjE;aACD;YACF,CAAC,CAAC,EAAE,CAAC;KACN,CAAC,CAAC;IACH,IAAI,OAAO,CAAC,KAAK,CAAC,UAAU,KAAK,UAAU;QAAE,MAAM,IAAI,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;IAC5F,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAC5G,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;AAAA,CAC1C","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { performance } from \"node:perf_hooks\";\nimport { executeSandbox, type SandboxOutcome } from \"./broker.ts\";\nimport type { VerifiedRunJournal } from \"./journal.ts\";\nimport type { NamespaceIdentity } from \"./namespace-identity.ts\";\nimport { VerifiedRunError } from \"./storage.ts\";\n\nexport interface OwnedRunCommand {\n\treadonly role: \"writer\" | \"verifier\";\n\treadonly argv: readonly string[];\n\treadonly workspace: string;\n\treadonly deadline: number;\n\treadonly claimId: string | null;\n}\nexport interface OwnedRunResult {\n\treadonly executionId: string;\n\treadonly result: SandboxOutcome;\n\treadonly timeoutMs: number;\n}\n\n/** The mandatory durable intent boundary is shared by command and AgentSession writers. */\nexport async function executeRunCommand(\n\tjournal: VerifiedRunJournal,\n\trequest: OwnedRunCommand,\n\tpolicy: {\n\t\treadonly cleanupMs: number;\n\t\treadonly maxOutputBytes: number;\n\t\treadonly signal?: AbortSignal;\n\t},\n): Promise<OwnedRunResult> {\n\tif (Math.floor(request.deadline - performance.now()) <= 0) throw new VerifiedRunError(\"deadline\");\n\tif (policy.signal?.aborted) throw new VerifiedRunError(\"cancelled\");\n\tconst generation = journal.state.generation;\n\tconst executionId = randomUUID();\n\tjournal.append({ kind: \"dispatch\", executionId, role: request.role, claimId: request.claimId });\n\tconst timeoutMs = Math.floor(request.deadline - performance.now());\n\tif (timeoutMs <= 0 || policy.signal?.aborted) {\n\t\tconst failure = policy.signal?.aborted ? \"cancelled\" : \"deadline\";\n\t\tjournal.append({ kind: \"exited\", executionId, failure });\n\t\tthrow new VerifiedRunError(failure);\n\t}\n\tconst result = await executeSandbox({\n\t\tworkspace: request.workspace,\n\t\targv: request.argv,\n\t\twritable: request.role === \"writer\",\n\t\ttimeoutMs,\n\t\tcleanupMs: policy.cleanupMs,\n\t\tmaxOutputBytes: policy.maxOutputBytes,\n\t\t...(policy.signal ? { signal: policy.signal } : {}),\n\t\t...(journal.state.budget\n\t\t\t? {\n\t\t\t\t\tonReady: (identity: NamespaceIdentity) => {\n\t\t\t\t\t\tif (journal.state.generation !== generation) throw new VerifiedRunError(\"stale_generation\");\n\t\t\t\t\t\tjournal.append({ kind: \"process_ready\", executionId, identity });\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t: {}),\n\t});\n\tif (journal.state.generation !== generation) throw new VerifiedRunError(\"stale_generation\");\n\tjournal.append({ kind: \"exited\", executionId, failure: request.role === \"writer\" ? result.failure : null });\n\treturn { executionId, result, timeoutMs };\n}\n"]}
1
+ {"version":3,"file":"owned-execution.js","sourceRoot":"","sources":["../../../src/core/verified-run/owned-execution.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAuB,MAAM,aAAa,CAAC;AAGlE,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAgBhD,2FAA2F;AAC3F,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACtC,OAA2B,EAC3B,OAAwB,EACxB,MAIC,EACyB;IAC1B,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,gBAAgB,CAAC,UAAU,CAAC,CAAC;IAClG,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO;QAAE,MAAM,IAAI,gBAAgB,CAAC,WAAW,CAAC,CAAC;IACpE,MAAM,UAAU,GAAG,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC;IAC5C,MAAM,WAAW,GAAG,UAAU,EAAE,CAAC;IACjC,OAAO,CAAC,MAAM,CAAC;QACd,IAAI,EAAE,UAAU;QAChB,WAAW;QACX,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;KACnE,CAAC,CAAC;IACH,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,CAAC;IACnE,IAAI,SAAS,IAAI,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,C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AAO,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAC5G,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;AAAA,CAC1C","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { performance } from \"node:perf_hooks\";\nimport { executeSandbox, type SandboxOutcome } from \"./broker.ts\";\nimport type { VerifiedRunJournal } from \"./journal.ts\";\nimport type { NamespaceIdentity } from \"./namespace-identity.ts\";\nimport { VerifiedRunError } from \"./storage.ts\";\n\nexport interface OwnedRunCommand {\n\treadonly role: \"writer\" | \"verifier\";\n\treadonly argv: readonly string[];\n\treadonly workspace: string;\n\treadonly deadline: number;\n\treadonly claimId: string | null;\n\treadonly taskId?: string;\n}\nexport interface OwnedRunResult {\n\treadonly executionId: string;\n\treadonly result: SandboxOutcome;\n\treadonly timeoutMs: number;\n}\n\n/** The mandatory durable intent boundary is shared by command and AgentSession writers. */\nexport async function executeRunCommand(\n\tjournal: VerifiedRunJournal,\n\trequest: OwnedRunCommand,\n\tpolicy: {\n\t\treadonly cleanupMs: number;\n\t\treadonly maxOutputBytes: number;\n\t\treadonly signal?: AbortSignal;\n\t},\n): Promise<OwnedRunResult> {\n\tif (Math.floor(request.deadline - performance.now()) <= 0) throw new VerifiedRunError(\"deadline\");\n\tif (policy.signal?.aborted) throw new VerifiedRunError(\"cancelled\");\n\tconst generation = journal.state.generation;\n\tconst executionId = randomUUID();\n\tjournal.append({\n\t\tkind: \"dispatch\",\n\t\texecutionId,\n\t\trole: request.role,\n\t\tclaimId: request.claimId,\n\t\t...(request.taskId === undefined ? {} : { taskId: request.taskId }),\n\t});\n\tconst timeoutMs = Math.floor(request.deadline - performance.now());\n\tif (timeoutMs <= 0 || policy.signal?.aborted) {\n\t\tconst failure = policy.signal?.aborted ? \"cancelled\" : \"deadline\";\n\t\tjournal.append({ kind: \"exited\", executionId, failure });\n\t\tthrow new VerifiedRunError(failure);\n\t}\n\tconst result = await executeSandbox({\n\t\tworkspace: request.workspace,\n\t\targv: request.argv,\n\t\twritable: request.role === \"writer\",\n\t\ttimeoutMs,\n\t\tcleanupMs: policy.cleanupMs,\n\t\tmaxOutputBytes: policy.maxOutputBytes,\n\t\t...(policy.signal ? { signal: policy.signal } : {}),\n\t\t...(journal.state.budget\n\t\t\t? {\n\t\t\t\t\tonReady: (identity: NamespaceIdentity) => {\n\t\t\t\t\t\tif (journal.state.generation !== generation) throw new VerifiedRunError(\"stale_generation\");\n\t\t\t\t\t\tjournal.append({ kind: \"process_ready\", executionId, identity });\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t: {}),\n\t});\n\tif (journal.state.generation !== generation) throw new VerifiedRunError(\"stale_generation\");\n\tjournal.append({ kind: \"exited\", executionId, failure: request.role === \"writer\" ? result.failure : null });\n\treturn { executionId, result, timeoutMs };\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import type { RunEvent, WriterReduction } from "./run-types.ts";
2
+ /** Replay-only mutable bookkeeping; active processes always share one role/phase. */
3
+ export interface ProcessReduction {
4
+ readonly dispatched: Set<string>;
5
+ readonly checked: Set<string>;
6
+ activeRole: "writer" | "verifier";
7
+ }
8
+ type ProcessEvent = Extract<RunEvent, {
9
+ kind: "dispatch" | "process_ready" | "exited";
10
+ }>;
11
+ export declare function reduceProcessEvent(context: WriterReduction, event: ProcessEvent, progress: ProcessReduction): void;
12
+ export {};
13
+ //# sourceMappingURL=process-projection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-projection.d.ts","sourceRoot":"","sources":["../../../src/core/verified-run/process-projection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAiB,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAK/E,qFAAqF;AACrF,MAAM,WAAW,gBAAgB;IAChC,QAAQ,CAAC,UAAU,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC9B,UAAU,EAAE,QAAQ,GAAG,UAAU,CAAC;CAClC;AACD,KAAK,YAAY,GAAG,OAAO,CAAC,QAAQ,EAAE;IAAE,IAAI,EAAE,UAAU,GAAG,eAAe,GAAG,QAAQ,CAAA;CAAE,CAAC,CAAC;AAEzF,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,gBAAgB,GAAG,IAAI,CAkFlH","sourcesContent":["import type { RunEvent, RunProjection, WriterReduction } from \"./run-types.ts\";\nimport { VerifiedRunError } from \"./storage.ts\";\nimport { endTaskExecution } from \"./task-execution.ts\";\nimport { acceptWriterDispatch } from \"./writer-projection.ts\";\n\n/** Replay-only mutable bookkeeping; active processes always share one role/phase. */\nexport interface ProcessReduction {\n\treadonly dispatched: Set<string>;\n\treadonly checked: Set<string>;\n\tactiveRole: \"writer\" | \"verifier\";\n}\ntype ProcessEvent = Extract<RunEvent, { kind: \"dispatch\" | \"process_ready\" | \"exited\" }>;\n\nexport function reduceProcessEvent(context: WriterReduction, event: ProcessEvent, progress: ProcessReduction): void {\n\tconst { contract, state } = context;\n\tswitch (event.kind) {\n\t\tcase \"dispatch\": {\n\t\t\tconst limit =\n\t\t\t\tevent.role === \"writer\" && contract.profile === \"linux-command-dag-v1\"\n\t\t\t\t\t? (contract.writer.maxConcurrentTasks ?? 1)\n\t\t\t\t\t: 1;\n\t\t\tif (\n\t\t\t\tstate.failure ||\n\t\t\t\tstate.execution === \"paused\" ||\n\t\t\t\tstate.activeExecutionIds.length >= limit ||\n\t\t\t\tprogress.dispatched.has(event.executionId)\n\t\t\t)\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\tif (event.role === \"writer\") {\n\t\t\t\tacceptWriterDispatch(context, event);\n\t\t\t} else {\n\t\t\t\tif (\n\t\t\t\t\tevent.taskId !== undefined ||\n\t\t\t\t\t!context.writerFinished ||\n\t\t\t\t\tstate.writerOpen ||\n\t\t\t\t\t!state.candidateDigest ||\n\t\t\t\t\tevent.claimId === null ||\n\t\t\t\t\t!contract.checks.some((check) => check.claimId === event.claimId) ||\n\t\t\t\t\tprogress.checked.has(event.claimId)\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tprogress.checked.add(event.claimId);\n\t\t\t}\n\t\t\tprogress.dispatched.add(event.executionId);\n\t\t\tprogress.activeRole = event.role;\n\t\t\tcontext.state = {\n\t\t\t\t...context.state,\n\t\t\t\texecution: \"running\",\n\t\t\t\tsettlement: \"draining\",\n\t\t\t\tactiveExecutionIds: [...state.activeExecutionIds, event.executionId],\n\t\t\t};\n\t\t\treturn;\n\t\t}\n\t\tcase \"process_ready\":\n\t\t\tif (\n\t\t\t\t!state.budget ||\n\t\t\t\t!state.activeExecutionIds.includes(event.executionId) ||\n\t\t\t\tevent.identity.bootId !== state.budget.bootId ||\n\t\t\t\tstate.processes.some((item) => item.executionId === event.executionId)\n\t\t\t)\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\tcontext.state = {\n\t\t\t\t...state,\n\t\t\t\tprocesses: [...state.processes, { executionId: event.executionId, identity: event.identity }],\n\t\t\t};\n\t\t\treturn;\n\t\tcase \"exited\": {\n\t\t\tif (\n\t\t\t\t!state.activeExecutionIds.includes(event.executionId) ||\n\t\t\t\t(state.budget &&\n\t\t\t\t\tevent.failure === null &&\n\t\t\t\t\t!state.processes.some((item) => item.executionId === event.executionId))\n\t\t\t)\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\tconst taskWriter = progress.activeRole === \"writer\" && contract.profile === \"linux-command-dag-v1\";\n\t\t\tif (taskWriter) endTaskExecution(context, event);\n\t\t\telse if (progress.activeRole === \"writer\") context.writerFinished = event.failure === null;\n\t\t\tconst activeExecutionIds = state.activeExecutionIds.filter((id) => id !== event.executionId);\n\t\t\tlet settlement: RunProjection[\"settlement\"] = \"settled\";\n\t\t\tif (context.state.writerOpen || context.state.tasks.some((task) => task.status === \"running\"))\n\t\t\t\tsettlement = \"open\";\n\t\t\tif (activeExecutionIds.length) settlement = \"draining\";\n\t\t\tcontext.state = {\n\t\t\t\t...context.state,\n\t\t\t\tactiveExecutionIds,\n\t\t\t\tsettlement,\n\t\t\t\tfailure: taskWriter ? state.failure : event.failure,\n\t\t\t};\n\t\t\treturn;\n\t\t}\n\t\tdefault: {\n\t\t\tconst exhaustive: never = event;\n\t\t\tthrow new VerifiedRunError(String(exhaustive));\n\t\t}\n\t}\n}\n"]}
@@ -0,0 +1,82 @@
1
+ import { VerifiedRunError } from "./storage.js";
2
+ import { endTaskExecution } from "./task-execution.js";
3
+ import { acceptWriterDispatch } from "./writer-projection.js";
4
+ export function reduceProcessEvent(context, event, progress) {
5
+ const { contract, state } = context;
6
+ switch (event.kind) {
7
+ case "dispatch": {
8
+ const limit = event.role === "writer" && contract.profile === "linux-command-dag-v1"
9
+ ? (contract.writer.maxConcurrentTasks ?? 1)
10
+ : 1;
11
+ if (state.failure ||
12
+ state.execution === "paused" ||
13
+ state.activeExecutionIds.length >= limit ||
14
+ progress.dispatched.has(event.executionId))
15
+ throw new VerifiedRunError("integrity");
16
+ if (event.role === "writer") {
17
+ acceptWriterDispatch(context, event);
18
+ }
19
+ else {
20
+ if (event.taskId !== undefined ||
21
+ !context.writerFinished ||
22
+ state.writerOpen ||
23
+ !state.candidateDigest ||
24
+ event.claimId === null ||
25
+ !contract.checks.some((check) => check.claimId === event.claimId) ||
26
+ progress.checked.has(event.claimId))
27
+ throw new VerifiedRunError("integrity");
28
+ progress.checked.add(event.claimId);
29
+ }
30
+ progress.dispatched.add(event.executionId);
31
+ progress.activeRole = event.role;
32
+ context.state = {
33
+ ...context.state,
34
+ execution: "running",
35
+ settlement: "draining",
36
+ activeExecutionIds: [...state.activeExecutionIds, event.executionId],
37
+ };
38
+ return;
39
+ }
40
+ case "process_ready":
41
+ if (!state.budget ||
42
+ !state.activeExecutionIds.includes(event.executionId) ||
43
+ event.identity.bootId !== state.budget.bootId ||
44
+ state.processes.some((item) => item.executionId === event.executionId))
45
+ throw new VerifiedRunError("integrity");
46
+ context.state = {
47
+ ...state,
48
+ processes: [...state.processes, { executionId: event.executionId, identity: event.identity }],
49
+ };
50
+ return;
51
+ case "exited": {
52
+ if (!state.activeExecutionIds.includes(event.executionId) ||
53
+ (state.budget &&
54
+ event.failure === null &&
55
+ !state.processes.some((item) => item.executionId === event.executionId)))
56
+ throw new VerifiedRunError("integrity");
57
+ const taskWriter = progress.activeRole === "writer" && contract.profile === "linux-command-dag-v1";
58
+ if (taskWriter)
59
+ endTaskExecution(context, event);
60
+ else if (progress.activeRole === "writer")
61
+ context.writerFinished = event.failure === null;
62
+ const activeExecutionIds = state.activeExecutionIds.filter((id) => id !== event.executionId);
63
+ let settlement = "settled";
64
+ if (context.state.writerOpen || context.state.tasks.some((task) => task.status === "running"))
65
+ settlement = "open";
66
+ if (activeExecutionIds.length)
67
+ settlement = "draining";
68
+ context.state = {
69
+ ...context.state,
70
+ activeExecutionIds,
71
+ settlement,
72
+ failure: taskWriter ? state.failure : event.failure,
73
+ };
74
+ return;
75
+ }
76
+ default: {
77
+ const exhaustive = event;
78
+ throw new VerifiedRunError(String(exhaustive));
79
+ }
80
+ }
81
+ }
82
+ //# sourceMappingURL=process-projection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-projection.js","sourceRoot":"","sources":["../../../src/core/verified-run/process-projection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAU9D,MAAM,UAAU,kBAAkB,CAAC,OAAwB,EAAE,KAAmB,EAAE,QAA0B,EAAQ;IACnH,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,O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,CAAC,CAAC;YACzC,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,KAAK,QAAQ,IAAI,QAAQ,CAAC,OAAO,KAAK,sBAAsB,CAAC;YACnG,IAAI,UAAU;gBAAE,gBAAgB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;iBAC5C,IAAI,QAAQ,CAAC,UAAU,KAAK,QAAQ;gBAAE,OAAO,CAAC,cAAc,GAAG,KAAK,CAAC,OAAO,KAAK,IAAI,CAAC;YAC3F,MAAM,kBAAkB,GAAG,KAAK,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,KAAK,CAAC,WAAW,CAAC,CAAC;YAC7F,IAAI,UAAU,GAAgC,SAAS,CAAC;YACxD,IAAI,OAAO,CAAC,KAAK,CAAC,UAAU,IAAI,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC;gBAC5F,UAAU,GAAG,MAAM,CAAC;YACrB,IAAI,kBAAkB,CAAC,MAAM;gBAAE,UAAU,GAAG,UAAU,CAAC;YACvD,OAAO,CAAC,KAAK,GAAG;gBACf,GAAG,OAAO,CAAC,KAAK;gBAChB,kBAAkB;gBAClB,UAAU;gBACV,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO;aACnD,CAAC;YACF,OAAO;QACR,CAAC;QACD,SAAS,CAAC;YACT,MAAM,UAAU,GAAU,KAAK,CAAC;YAChC,MAAM,IAAI,gBAAgB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;QAChD,CAAC;IACF,CAAC;AAAA,CACD","sourcesContent":["import type { RunEvent, RunProjection, WriterReduction } from \"./run-types.ts\";\nimport { VerifiedRunError } from \"./storage.ts\";\nimport { endTaskExecution } from \"./task-execution.ts\";\nimport { acceptWriterDispatch } from \"./writer-projection.ts\";\n\n/** Replay-only mutable bookkeeping; active processes always share one role/phase. */\nexport interface ProcessReduction {\n\treadonly dispatched: Set<string>;\n\treadonly checked: Set<string>;\n\tactiveRole: \"writer\" | \"verifier\";\n}\ntype ProcessEvent = Extract<RunEvent, { kind: \"dispatch\" | \"process_ready\" | \"exited\" }>;\n\nexport function reduceProcessEvent(context: WriterReduction, event: ProcessEvent, progress: ProcessReduction): void {\n\tconst { contract, state } = context;\n\tswitch (event.kind) {\n\t\tcase \"dispatch\": {\n\t\t\tconst limit =\n\t\t\t\tevent.role === \"writer\" && contract.profile === \"linux-command-dag-v1\"\n\t\t\t\t\t? (contract.writer.maxConcurrentTasks ?? 1)\n\t\t\t\t\t: 1;\n\t\t\tif (\n\t\t\t\tstate.failure ||\n\t\t\t\tstate.execution === \"paused\" ||\n\t\t\t\tstate.activeExecutionIds.length >= limit ||\n\t\t\t\tprogress.dispatched.has(event.executionId)\n\t\t\t)\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\tif (event.role === \"writer\") {\n\t\t\t\tacceptWriterDispatch(context, event);\n\t\t\t} else {\n\t\t\t\tif (\n\t\t\t\t\tevent.taskId !== undefined ||\n\t\t\t\t\t!context.writerFinished ||\n\t\t\t\t\tstate.writerOpen ||\n\t\t\t\t\t!state.candidateDigest ||\n\t\t\t\t\tevent.claimId === null ||\n\t\t\t\t\t!contract.checks.some((check) => check.claimId === event.claimId) ||\n\t\t\t\t\tprogress.checked.has(event.claimId)\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tprogress.checked.add(event.claimId);\n\t\t\t}\n\t\t\tprogress.dispatched.add(event.executionId);\n\t\t\tprogress.activeRole = event.role;\n\t\t\tcontext.state = {\n\t\t\t\t...context.state,\n\t\t\t\texecution: \"running\",\n\t\t\t\tsettlement: \"draining\",\n\t\t\t\tactiveExecutionIds: [...state.activeExecutionIds, event.executionId],\n\t\t\t};\n\t\t\treturn;\n\t\t}\n\t\tcase \"process_ready\":\n\t\t\tif (\n\t\t\t\t!state.budget ||\n\t\t\t\t!state.activeExecutionIds.includes(event.executionId) ||\n\t\t\t\tevent.identity.bootId !== state.budget.bootId ||\n\t\t\t\tstate.processes.some((item) => item.executionId === event.executionId)\n\t\t\t)\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\tcontext.state = {\n\t\t\t\t...state,\n\t\t\t\tprocesses: [...state.processes, { executionId: event.executionId, identity: event.identity }],\n\t\t\t};\n\t\t\treturn;\n\t\tcase \"exited\": {\n\t\t\tif (\n\t\t\t\t!state.activeExecutionIds.includes(event.executionId) ||\n\t\t\t\t(state.budget &&\n\t\t\t\t\tevent.failure === null &&\n\t\t\t\t\t!state.processes.some((item) => item.executionId === event.executionId))\n\t\t\t)\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\tconst taskWriter = progress.activeRole === \"writer\" && contract.profile === \"linux-command-dag-v1\";\n\t\t\tif (taskWriter) endTaskExecution(context, event);\n\t\t\telse if (progress.activeRole === \"writer\") context.writerFinished = event.failure === null;\n\t\t\tconst activeExecutionIds = state.activeExecutionIds.filter((id) => id !== event.executionId);\n\t\t\tlet settlement: RunProjection[\"settlement\"] = \"settled\";\n\t\t\tif (context.state.writerOpen || context.state.tasks.some((task) => task.status === \"running\"))\n\t\t\t\tsettlement = \"open\";\n\t\t\tif (activeExecutionIds.length) settlement = \"draining\";\n\t\t\tcontext.state = {\n\t\t\t\t...context.state,\n\t\t\t\tactiveExecutionIds,\n\t\t\t\tsettlement,\n\t\t\t\tfailure: taskWriter ? state.failure : event.failure,\n\t\t\t};\n\t\t\treturn;\n\t\t}\n\t\tdefault: {\n\t\t\tconst exhaustive: never = event;\n\t\t\tthrow new VerifiedRunError(String(exhaustive));\n\t\t}\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"projection.d.ts","sourceRoot":"","sources":["../../../src/core/verified-run/projection.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAmB,MAAM,gBAAgB,CAAC;AAI/E,iGAAiG;AACjG,wBAAgB,UAAU,CAAC,MAAM,EAAE,SAAS,QAAQ,EAAE,GAAG,aAAa,CAmOrE","sourcesContent":["import { reduceDagEvent } from \"./dag-projection.ts\";\nimport type { RunTaskProjection } from \"./dag-types.ts\";\nimport { reduceRecoveryEvent } from \"./recovery-projection.ts\";\nimport type { RunEvent, RunProjection, WriterReduction } from \"./run-types.ts\";\nimport { VerifiedRunError } from \"./storage.ts\";\nimport { acceptWriterDispatch, reduceWriterEvent } from \"./writer-projection.ts\";\n\n/** Deterministic replay only. Recovery observations are supplied by the trusted host adapter. */\nexport function projectRun(events: readonly RunEvent[]): RunProjection {\n\tconst first = events[0];\n\tif (first?.kind !== \"created\" || first.contract.runId !== first.command.runId)\n\t\tthrow new VerifiedRunError(\"integrity\");\n\tconst context: WriterReduction = {\n\t\tcontract: first.contract,\n\t\twriterFinished: false,\n\t\twriterStarted: false,\n\t\tproducerStarted: false,\n\t\twriterCommands: 0,\n\t\trequestBaseline: 0,\n\t\trequests: new Set(),\n\t\tstate: {\n\t\t\trunId: first.contract.runId,\n\t\t\trevision: 1,\n\t\t\tgeneration: 1,\n\t\t\texecution: \"ready\",\n\t\t\tsettlement: \"open\",\n\t\t\tverification: \"not_requested\",\n\t\t\tapplication: \"not_requested\",\n\t\t\tcandidateDigest: null,\n\t\t\tinputDigest: null,\n\t\t\treceiptDigest: null,\n\t\t\tfailure: null,\n\t\t\tactiveExecutionIds: [],\n\t\t\twriterOpen: false,\n\t\t\tmodelRequests: 0,\n\t\t\ttasks:\n\t\t\t\tfirst.contract.profile === \"linux-command-dag-v1\"\n\t\t\t\t\t? first.contract.writer.tasks.map(\n\t\t\t\t\t\t\t(task): RunTaskProjection => ({\n\t\t\t\t\t\t\t\ttaskId: task.id,\n\t\t\t\t\t\t\t\tattempt: 0,\n\t\t\t\t\t\t\t\tgeneration: 1,\n\t\t\t\t\t\t\t\tstatus: \"pending\",\n\t\t\t\t\t\t\t\tinputDigest: null,\n\t\t\t\t\t\t\t\toutputDigest: null,\n\t\t\t\t\t\t\t\tfailure: null,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t)\n\t\t\t\t\t: [],\n\t\t\tbudget: null,\n\t\t\tenvironmentDigest: null,\n\t\t\tverificationDeadlineMs: null,\n\t\t\tlastClockMs: null,\n\t\t\tprocesses: [],\n\t\t},\n\t};\n\tconst dispatched = new Set<string>();\n\tconst checked = new Set<string>();\n\tconst commands = new Set([first.command.commandId]);\n\tlet activeRole: \"writer\" | \"verifier\" = \"writer\";\n\tfor (const event of events.slice(1)) {\n\t\tconst state = context.state;\n\t\tif (state.execution === \"failed\" || state.receiptDigest) throw new VerifiedRunError(\"integrity\");\n\t\tswitch (event.kind) {\n\t\t\tcase \"created\":\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\tcase \"budget_anchored\": {\n\t\t\t\tconst budget = event.budget;\n\t\t\t\tconst limits = first.contract.budget;\n\t\t\t\tif (\n\t\t\t\t\tstate.revision !== 1 ||\n\t\t\t\t\tstate.budget ||\n\t\t\t\t\tbudget.workDeadlineMs - budget.startedMs !== limits.workMs ||\n\t\t\t\t\tbudget.verifyCapMs - budget.workDeadlineMs !== limits.verifyMs ||\n\t\t\t\t\tbudget.cleanupDeadlineMs - budget.verifyCapMs !== limits.cleanupMs\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\tbudget,\n\t\t\t\t\tenvironmentDigest: event.environmentDigest,\n\t\t\t\t\tlastClockMs: budget.startedMs,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"input_checkpoint\":\n\t\t\t\tif (\n\t\t\t\t\tstate.revision !== 2 ||\n\t\t\t\t\t!state.budget ||\n\t\t\t\t\tstate.inputDigest ||\n\t\t\t\t\tevent.digest !== first.contract.workspace.baseDigest\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = { ...state, inputDigest: event.digest };\n\t\t\t\tbreak;\n\t\t\tcase \"task_started\":\n\t\t\tcase \"task_finished\":\n\t\t\tcase \"tasks_paused\":\n\t\t\t\treduceDagEvent(context, event);\n\t\t\t\tbreak;\n\t\t\tcase \"writer_opened\":\n\t\t\tcase \"model_request\":\n\t\t\tcase \"writer_closed\":\n\t\t\t\treduceWriterEvent(context, event);\n\t\t\t\tbreak;\n\t\t\tcase \"dispatch\": {\n\t\t\t\tif (state.failure || state.activeExecutionIds.length || dispatched.has(event.executionId))\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tif (event.role === \"writer\") {\n\t\t\t\t\tacceptWriterDispatch(context, event);\n\t\t\t\t} else {\n\t\t\t\t\tif (\n\t\t\t\t\t\t!context.writerFinished ||\n\t\t\t\t\t\tstate.writerOpen ||\n\t\t\t\t\t\t!state.candidateDigest ||\n\t\t\t\t\t\tevent.claimId === null ||\n\t\t\t\t\t\t!first.contract.checks.some((check) => check.claimId === event.claimId) ||\n\t\t\t\t\t\tchecked.has(event.claimId)\n\t\t\t\t\t)\n\t\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\t\tchecked.add(event.claimId);\n\t\t\t\t}\n\t\t\t\tdispatched.add(event.executionId);\n\t\t\t\tactiveRole = event.role;\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\texecution: \"running\",\n\t\t\t\t\tsettlement: \"draining\",\n\t\t\t\t\tactiveExecutionIds: [event.executionId],\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"process_ready\":\n\t\t\t\tif (\n\t\t\t\t\t!state.budget ||\n\t\t\t\t\tstate.activeExecutionIds[0] !== event.executionId ||\n\t\t\t\t\tevent.identity.bootId !== state.budget.bootId ||\n\t\t\t\t\tstate.processes.some((item) => item.executionId === event.executionId)\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\tprocesses: [...state.processes, { executionId: event.executionId, identity: event.identity }],\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase \"exited\":\n\t\t\t\tif (\n\t\t\t\t\tstate.activeExecutionIds[0] !== event.executionId ||\n\t\t\t\t\t(state.budget &&\n\t\t\t\t\t\tevent.failure === null &&\n\t\t\t\t\t\t!state.processes.some((item) => item.executionId === event.executionId))\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tif (activeRole === \"writer\") context.writerFinished = event.failure === null;\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\tsettlement: state.writerOpen ? \"open\" : \"settled\",\n\t\t\t\t\tactiveExecutionIds: [],\n\t\t\t\t\tfailure: event.failure,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase \"candidate\": {\n\t\t\t\tif (\n\t\t\t\t\t!context.writerFinished ||\n\t\t\t\t\tstate.writerOpen ||\n\t\t\t\t\tstate.failure ||\n\t\t\t\t\tstate.activeExecutionIds.length ||\n\t\t\t\t\tstate.candidateDigest ||\n\t\t\t\t\tstate.tasks.some((task) => task.status !== \"succeeded\" || task.generation !== state.generation)\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tif (state.budget) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tevent.observedMs === undefined ||\n\t\t\t\t\t\tevent.verificationDeadlineMs === undefined ||\n\t\t\t\t\t\tevent.observedMs < state.budget.startedMs ||\n\t\t\t\t\t\tevent.observedMs > state.budget.workDeadlineMs ||\n\t\t\t\t\t\tevent.verificationDeadlineMs !==\n\t\t\t\t\t\t\tMath.min(event.observedMs + first.contract.budget.verifyMs, state.budget.verifyCapMs)\n\t\t\t\t\t)\n\t\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\t} else if (event.observedMs !== undefined || event.verificationDeadlineMs !== undefined)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\tcandidateDigest: event.digest,\n\t\t\t\t\tverificationDeadlineMs: event.verificationDeadlineMs ?? null,\n\t\t\t\t\tlastClockMs: event.observedMs ?? null,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"resumed\":\n\t\t\tcase \"tasks_retried\":\n\t\t\tcase \"writer_restarted\":\n\t\t\t\treduceRecoveryEvent(context, event, { commands, checked, activeRole });\n\t\t\t\tbreak;\n\t\t\tcase \"evaluated\":\n\t\t\t\tif (\n\t\t\t\t\t!state.candidateDigest ||\n\t\t\t\t\tstate.writerOpen ||\n\t\t\t\t\tstate.activeExecutionIds.length ||\n\t\t\t\t\tchecked.size !== first.contract.checks.length ||\n\t\t\t\t\t(event.verified && state.failure)\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\treceiptDigest: event.receiptDigest,\n\t\t\t\t\texecution: \"succeeded\",\n\t\t\t\t\tverification: event.verified ? \"verified\" : \"violated\",\n\t\t\t\t\tapplication: event.verified ? \"candidate_ready\" : \"not_requested\",\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase \"failed\":\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\texecution: \"failed\",\n\t\t\t\t\tfailure: event.code,\n\t\t\t\t\tverification: \"inconclusive\",\n\t\t\t\t\tsettlement: state.activeExecutionIds.length || state.writerOpen ? \"quarantined\" : \"settled\",\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tdefault: {\n\t\t\t\tconst exhaustive: never = event;\n\t\t\t\tthrow new VerifiedRunError(String(exhaustive));\n\t\t\t}\n\t\t}\n\t\tcontext.state = { ...context.state, revision: state.revision + 1 };\n\t}\n\treturn Object.freeze({\n\t\t...context.state,\n\t\tactiveExecutionIds: Object.freeze([...context.state.activeExecutionIds]),\n\t\tprocesses: Object.freeze(context.state.processes.map((item) => Object.freeze(item))),\n\t\ttasks: Object.freeze(context.state.tasks.map((task) => Object.freeze(task))),\n\t});\n}\n"]}
1
+ {"version":3,"file":"projection.d.ts","sourceRoot":"","sources":["../../../src/core/verified-run/projection.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAmB,MAAM,gBAAgB,CAAC;AAI/E,iGAAiG;AACjG,wBAAgB,UAAU,CAAC,MAAM,EAAE,SAAS,QAAQ,EAAE,GAAG,aAAa,CAkLrE","sourcesContent":["import { reduceDagEvent } from \"./dag-projection.ts\";\nimport type { RunTaskProjection } from \"./dag-types.ts\";\nimport { type ProcessReduction, reduceProcessEvent } from \"./process-projection.ts\";\nimport { reduceRecoveryEvent } from \"./recovery-projection.ts\";\nimport type { RunEvent, RunProjection, WriterReduction } from \"./run-types.ts\";\nimport { VerifiedRunError } from \"./storage.ts\";\nimport { reduceWriterEvent } from \"./writer-projection.ts\";\n\n/** Deterministic replay only. Recovery observations are supplied by the trusted host adapter. */\nexport function projectRun(events: readonly RunEvent[]): RunProjection {\n\tconst first = events[0];\n\tif (first?.kind !== \"created\" || first.contract.runId !== first.command.runId)\n\t\tthrow new VerifiedRunError(\"integrity\");\n\tconst context: WriterReduction = {\n\t\tcontract: first.contract,\n\t\twriterFinished: false,\n\t\twriterStarted: false,\n\t\tproducerStarted: false,\n\t\twriterCommands: 0,\n\t\trequestBaseline: 0,\n\t\trequests: new Set(),\n\t\tstate: {\n\t\t\trunId: first.contract.runId,\n\t\t\trevision: 1,\n\t\t\tgeneration: 1,\n\t\t\texecution: \"ready\",\n\t\t\tsettlement: \"open\",\n\t\t\tverification: \"not_requested\",\n\t\t\tapplication: \"not_requested\",\n\t\t\tcandidateDigest: null,\n\t\t\tinputDigest: null,\n\t\t\treceiptDigest: null,\n\t\t\tfailure: null,\n\t\t\tactiveExecutionIds: [],\n\t\t\twriterOpen: false,\n\t\t\tmodelRequests: 0,\n\t\t\ttasks:\n\t\t\t\tfirst.contract.profile === \"linux-command-dag-v1\"\n\t\t\t\t\t? first.contract.writer.tasks.map(\n\t\t\t\t\t\t\t(task): RunTaskProjection => ({\n\t\t\t\t\t\t\t\ttaskId: task.id,\n\t\t\t\t\t\t\t\tattempt: 0,\n\t\t\t\t\t\t\t\tgeneration: 1,\n\t\t\t\t\t\t\t\tstatus: \"pending\",\n\t\t\t\t\t\t\t\tinputDigest: null,\n\t\t\t\t\t\t\t\toutputDigest: null,\n\t\t\t\t\t\t\t\tfailure: null,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t)\n\t\t\t\t\t: [],\n\t\t\tbudget: null,\n\t\t\tenvironmentDigest: null,\n\t\t\tverificationDeadlineMs: null,\n\t\t\tlastClockMs: null,\n\t\t\tprocesses: [],\n\t\t},\n\t};\n\tconst progress: ProcessReduction = { dispatched: new Set(), checked: new Set(), activeRole: \"writer\" };\n\tconst commands = new Set([first.command.commandId]);\n\tfor (const event of events.slice(1)) {\n\t\tconst state = context.state;\n\t\tif (state.execution === \"failed\" || state.receiptDigest) throw new VerifiedRunError(\"integrity\");\n\t\tswitch (event.kind) {\n\t\t\tcase \"created\":\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\tcase \"budget_anchored\": {\n\t\t\t\tconst budget = event.budget;\n\t\t\t\tconst limits = first.contract.budget;\n\t\t\t\tif (\n\t\t\t\t\tstate.revision !== 1 ||\n\t\t\t\t\tstate.budget ||\n\t\t\t\t\tbudget.workDeadlineMs - budget.startedMs !== limits.workMs ||\n\t\t\t\t\tbudget.verifyCapMs - budget.workDeadlineMs !== limits.verifyMs ||\n\t\t\t\t\tbudget.cleanupDeadlineMs - budget.verifyCapMs !== limits.cleanupMs\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\tbudget,\n\t\t\t\t\tenvironmentDigest: event.environmentDigest,\n\t\t\t\t\tlastClockMs: budget.startedMs,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"input_checkpoint\":\n\t\t\t\tif (\n\t\t\t\t\tstate.revision !== 2 ||\n\t\t\t\t\t!state.budget ||\n\t\t\t\t\tstate.inputDigest ||\n\t\t\t\t\tevent.digest !== first.contract.workspace.baseDigest\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = { ...state, inputDigest: event.digest };\n\t\t\t\tbreak;\n\t\t\tcase \"task_started\":\n\t\t\tcase \"task_finished\":\n\t\t\tcase \"tasks_paused\":\n\t\t\t\treduceDagEvent(context, event);\n\t\t\t\tbreak;\n\t\t\tcase \"writer_opened\":\n\t\t\tcase \"model_request\":\n\t\t\tcase \"writer_closed\":\n\t\t\t\treduceWriterEvent(context, event);\n\t\t\t\tbreak;\n\t\t\tcase \"dispatch\":\n\t\t\tcase \"process_ready\":\n\t\t\tcase \"exited\":\n\t\t\t\treduceProcessEvent(context, event, progress);\n\t\t\t\tbreak;\n\t\t\tcase \"candidate\": {\n\t\t\t\tif (\n\t\t\t\t\t!context.writerFinished ||\n\t\t\t\t\tstate.writerOpen ||\n\t\t\t\t\tstate.failure ||\n\t\t\t\t\tstate.activeExecutionIds.length ||\n\t\t\t\t\tstate.candidateDigest ||\n\t\t\t\t\tstate.tasks.some((task) => task.status !== \"succeeded\" || task.generation !== state.generation)\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tif (state.budget) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tevent.observedMs === undefined ||\n\t\t\t\t\t\tevent.verificationDeadlineMs === undefined ||\n\t\t\t\t\t\tevent.observedMs < state.budget.startedMs ||\n\t\t\t\t\t\tevent.observedMs > state.budget.workDeadlineMs ||\n\t\t\t\t\t\tevent.verificationDeadlineMs !==\n\t\t\t\t\t\t\tMath.min(event.observedMs + first.contract.budget.verifyMs, state.budget.verifyCapMs)\n\t\t\t\t\t)\n\t\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\t} else if (event.observedMs !== undefined || event.verificationDeadlineMs !== undefined)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\tcandidateDigest: event.digest,\n\t\t\t\t\tverificationDeadlineMs: event.verificationDeadlineMs ?? null,\n\t\t\t\t\tlastClockMs: event.observedMs ?? null,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"resumed\":\n\t\t\tcase \"tasks_retried\":\n\t\t\tcase \"writer_restarted\":\n\t\t\t\treduceRecoveryEvent(context, event, {\n\t\t\t\t\tcommands,\n\t\t\t\t\tchecked: progress.checked,\n\t\t\t\t\tactiveRole: progress.activeRole,\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\tcase \"evaluated\":\n\t\t\t\tif (\n\t\t\t\t\t!state.candidateDigest ||\n\t\t\t\t\tstate.writerOpen ||\n\t\t\t\t\tstate.activeExecutionIds.length ||\n\t\t\t\t\tprogress.checked.size !== first.contract.checks.length ||\n\t\t\t\t\t(event.verified && state.failure)\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\treceiptDigest: event.receiptDigest,\n\t\t\t\t\texecution: \"succeeded\",\n\t\t\t\t\tverification: event.verified ? \"verified\" : \"violated\",\n\t\t\t\t\tapplication: event.verified ? \"candidate_ready\" : \"not_requested\",\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase \"failed\":\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\texecution: \"failed\",\n\t\t\t\t\tfailure: event.code,\n\t\t\t\t\tverification: \"inconclusive\",\n\t\t\t\t\tsettlement: state.activeExecutionIds.length || state.writerOpen ? \"quarantined\" : \"settled\",\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tdefault: {\n\t\t\t\tconst exhaustive: never = event;\n\t\t\t\tthrow new VerifiedRunError(String(exhaustive));\n\t\t\t}\n\t\t}\n\t\tcontext.state = { ...context.state, revision: state.revision + 1 };\n\t}\n\treturn Object.freeze({\n\t\t...context.state,\n\t\tactiveExecutionIds: Object.freeze([...context.state.activeExecutionIds]),\n\t\tprocesses: Object.freeze(context.state.processes.map((item) => Object.freeze(item))),\n\t\ttasks: Object.freeze(context.state.tasks.map((task) => Object.freeze(task))),\n\t});\n}\n"]}