@opengeni/worker-bundle 0.7.4 → 0.8.3

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 (42) hide show
  1. package/dist/chunk-BJUW5LCM.js +325 -0
  2. package/dist/chunk-BJUW5LCM.js.map +1 -0
  3. package/dist/host-export.d.ts +70 -0
  4. package/dist/host-export.js +7 -0
  5. package/dist/host-export.js.map +1 -0
  6. package/dist/index.d.ts +98 -6
  7. package/dist/index.js +2853 -834
  8. package/dist/index.js.map +1 -1
  9. package/dist/workflow-bundle.js +12358 -0
  10. package/package.json +18 -12
  11. package/src/activities/agent-turn.ts +2052 -554
  12. package/src/activities/capabilities.ts +9 -2
  13. package/src/activities/codex-capacity.ts +6 -11
  14. package/src/activities/codex-rotation.ts +75 -86
  15. package/src/activities/context-compaction.ts +104 -24
  16. package/src/activities/environment.ts +367 -92
  17. package/src/activities/expiring-material-renewal.ts +143 -0
  18. package/src/activities/goals.ts +4 -0
  19. package/src/activities/mcp-credentials.ts +38 -0
  20. package/src/activities/packs.ts +115 -2
  21. package/src/activities/parent-wake.ts +48 -38
  22. package/src/activities/run-credential-renewal.ts +70 -0
  23. package/src/activities/run-credentials.ts +132 -0
  24. package/src/activities/run-input.ts +23 -0
  25. package/src/activities/sandbox-lease.ts +1 -1
  26. package/src/activities/scheduled-tasks.ts +21 -0
  27. package/src/activities/session-state.ts +83 -12
  28. package/src/activities/streaming.ts +1 -0
  29. package/src/activities/toolspace-token-renewal.ts +57 -0
  30. package/src/activities/types.ts +44 -6
  31. package/src/activities/workspace-capture.ts +113 -93
  32. package/src/activities.ts +10 -2
  33. package/src/host-export-pump.ts +416 -0
  34. package/src/host-export.ts +22 -0
  35. package/src/http.ts +77 -28
  36. package/src/index.ts +360 -156
  37. package/src/sandbox-resume.ts +47 -1
  38. package/src/sandbox-routing.ts +1 -1
  39. package/src/worker-service-lifecycle.ts +104 -0
  40. package/src/workflows/activities.ts +13 -7
  41. package/src/workflows/session.ts +219 -23
  42. package/src/workflows.ts +1 -0
@@ -2,6 +2,7 @@ import type { FileAsset, ResourceRef, SessionSystemUpdate } from "@opengeni/cont
2
2
  import {
3
3
  getActiveSessionHistoryItems,
4
4
  getLatestRunState,
5
+ getHumanInputResumeForEvent,
5
6
  getSandboxSessionEnvelope,
6
7
  getSessionEvent,
7
8
  listSessionSystemUpdatesForTurn,
@@ -144,6 +145,7 @@ export type TurnInputOptions = {
144
145
  turnId: string;
145
146
  recovering?: boolean;
146
147
  unavailableSandboxFilesNote?: string;
148
+ runCredentialsNote?: string;
147
149
  };
148
150
 
149
151
  export async function turnInput(
@@ -173,6 +175,7 @@ export async function turnInput(
173
175
  : undefined,
174
176
  updateContext,
175
177
  options.unavailableSandboxFilesNote,
178
+ options.runCredentialsNote,
176
179
  );
177
180
  if (trigger.type === "user.message") {
178
181
  const payload = trigger.payload as { text?: unknown; resources?: unknown };
@@ -228,6 +231,26 @@ export async function turnInput(
228
231
  modelHistoryFromItems: false,
229
232
  };
230
233
  }
234
+ if (trigger.type === "user.humanInputResponse") {
235
+ const [state, resume] = await Promise.all([
236
+ getLatestRunState(db, trigger.workspaceId, trigger.sessionId),
237
+ getHumanInputResumeForEvent(db, trigger.workspaceId, trigger.sessionId, trigger),
238
+ ]);
239
+ if (!state) {
240
+ throw new Error("No saved run state is available for human-input response");
241
+ }
242
+ if (!resume) {
243
+ throw new Error("Human-input response does not resolve to a durable request");
244
+ }
245
+ return {
246
+ input: await runtime.prepareInput(agent, {
247
+ kind: "human_input",
248
+ serializedRunState: resumeRunStateForCodexAccount(state, current),
249
+ toolCallId: resume.toolCallId,
250
+ }),
251
+ modelHistoryFromItems: false,
252
+ };
253
+ }
231
254
  throw new Error(`Unsupported trigger event type: ${trigger.type}`);
232
255
  }
233
256
 
@@ -647,7 +647,7 @@ export async function terminateProviderBox(
647
647
  return true;
648
648
  }
649
649
 
650
- // CRITICAL SAFETY (bring-your-own-compute, dossier §19/§21): NEVER provider-stop
650
+ // CRITICAL SAFETY (bring-your-own-compute): NEVER provider-stop
651
651
  // a selfhosted box. The "box" is a user's PHYSICAL machine — you cannot kill it,
652
652
  // and a delete()/kill() reaching the agent would be catastrophic. The reaper
653
653
  // DRAINS the lease to cold only (refcount→0 → draining → this returns true so
@@ -77,6 +77,9 @@ export function createScheduledTaskActivities(services: () => Promise<ActivitySe
77
77
  unit: "run",
78
78
  sourceResourceType: "scheduled_task_run",
79
79
  sourceResourceId: run.id,
80
+ initiator: { kind: "service", subjectId: "scheduler" },
81
+ initiatorContext: { scheduledTaskId: task.id, scheduledTaskRunId: run.id },
82
+ origin: "scheduled_task",
80
83
  idempotencyKey: `usage:scheduled_task.fired:${run.id}`,
81
84
  });
82
85
  if (run.status === "dispatched" && run.sessionId && run.triggerEventId) {
@@ -88,6 +91,10 @@ export function createScheduledTaskActivities(services: () => Promise<ActivitySe
88
91
  unit: "run",
89
92
  sourceResourceType: "scheduled_task_run",
90
93
  sourceResourceId: run.id,
94
+ sessionId: run.sessionId,
95
+ initiator: { kind: "service", subjectId: "scheduler" },
96
+ initiatorContext: { scheduledTaskId: task.id, scheduledTaskRunId: run.id },
97
+ origin: "scheduled_task",
91
98
  idempotencyKey:
92
99
  input.agentRunUsageIdempotencyKey ?? `usage:agent_run.created:scheduled:${run.id}`,
93
100
  });
@@ -164,6 +171,15 @@ export function createScheduledTaskActivities(services: () => Promise<ActivitySe
164
171
  scheduledTaskId: task.id,
165
172
  scheduledTaskRunId: run.id,
166
173
  },
174
+ createdBy: {
175
+ kind: "service",
176
+ subjectId: "scheduler",
177
+ label: "OpenGeni scheduler",
178
+ },
179
+ createdByContext: {
180
+ scheduledTaskId: task.id,
181
+ scheduledTaskRunId: run.id,
182
+ },
167
183
  model,
168
184
  sandboxBackend,
169
185
  variableSetId: task.variableSetId ?? null,
@@ -193,6 +209,7 @@ export function createScheduledTaskActivities(services: () => Promise<ActivitySe
193
209
  type: "session.created",
194
210
  payload: {
195
211
  status: session.status,
212
+ createdBy: session.createdBy,
196
213
  scheduledTaskId: task.id,
197
214
  scheduledTaskRunId: run.id,
198
215
  // Names/ids only; never values.
@@ -390,6 +407,10 @@ export function createScheduledTaskActivities(services: () => Promise<ActivitySe
390
407
  unit: "run",
391
408
  sourceResourceType: "scheduled_task_run",
392
409
  sourceResourceId: run.id,
410
+ sessionId: result.sessionId,
411
+ initiator: { kind: "service", subjectId: "scheduler" },
412
+ initiatorContext: { scheduledTaskId: task.id, scheduledTaskRunId: run.id },
413
+ origin: "scheduled_task",
393
414
  idempotencyKey:
394
415
  input.agentRunUsageIdempotencyKey ?? `usage:agent_run.created:scheduled:${run.id}`,
395
416
  });
@@ -6,18 +6,23 @@ import {
6
6
  countQueuedTurns,
7
7
  getSessionEvent,
8
8
  getSessionTurnForAttempt,
9
+ expireSessionHumanInputRequest,
10
+ markSessionAttemptQuiesced,
9
11
  requireSession,
10
12
  settleSessionIdleWithParentOutbox,
11
13
  } from "@opengeni/db";
12
14
  import { publishDurableSessionEvents } from "@opengeni/events";
13
- import { notifyParentOfChildTerminal } from "./parent-wake";
15
+ import { deliverFailedChildTurnToParent, notifyParentOfChildIdle } from "./parent-wake";
14
16
  import { recordTurnsQueuedGauge } from "../observability-metrics";
15
17
  import type {
16
18
  ActivityServices,
19
+ ExpireSessionHumanInputInput,
20
+ ExpireSessionHumanInputResult,
17
21
  PeekSessionWorkInput,
18
22
  FailSessionAttemptInput,
19
23
  SettleSessionInterruptionsInput,
20
24
  MarkSessionIdleInput,
25
+ PersistSessionAttemptQuiescenceInput,
21
26
  RecoverDispatchInput,
22
27
  RecoverDispatchResult,
23
28
  } from "./types";
@@ -30,10 +35,13 @@ export type SessionStateActivityOverrides = Partial<{
30
35
  countQueuedTurns: typeof countQueuedTurns;
31
36
  getSessionEvent: typeof getSessionEvent;
32
37
  getSessionTurnForAttempt: typeof getSessionTurnForAttempt;
38
+ expireSessionHumanInputRequest: typeof expireSessionHumanInputRequest;
33
39
  requireSession: typeof requireSession;
34
40
  settleSessionIdleWithParentOutbox: typeof settleSessionIdleWithParentOutbox;
41
+ markSessionAttemptQuiesced: typeof markSessionAttemptQuiesced;
35
42
  publishDurableSessionEvents: typeof publishDurableSessionEvents;
36
- notifyParentOfChildTerminal: typeof notifyParentOfChildTerminal;
43
+ deliverFailedChildTurnToParent: typeof deliverFailedChildTurnToParent;
44
+ notifyParentOfChildIdle: typeof notifyParentOfChildIdle;
37
45
  recordTurnsQueuedGauge: typeof recordTurnsQueuedGauge;
38
46
  }>;
39
47
 
@@ -56,13 +64,18 @@ export function createSessionStateActivities(
56
64
  const countQueuedTurnsFn = overrides.countQueuedTurns ?? countQueuedTurns;
57
65
  const getSessionEventFn = overrides.getSessionEvent ?? getSessionEvent;
58
66
  const getSessionTurnForAttemptFn = overrides.getSessionTurnForAttempt ?? getSessionTurnForAttempt;
67
+ const expireSessionHumanInputRequestFn =
68
+ overrides.expireSessionHumanInputRequest ?? expireSessionHumanInputRequest;
59
69
  const requireSessionFn = overrides.requireSession ?? requireSession;
60
70
  const settleSessionIdleWithParentOutboxFn =
61
71
  overrides.settleSessionIdleWithParentOutbox ?? settleSessionIdleWithParentOutbox;
72
+ const markSessionAttemptQuiescedFn =
73
+ overrides.markSessionAttemptQuiesced ?? markSessionAttemptQuiesced;
62
74
  const publishDurableSessionEventsFn =
63
75
  overrides.publishDurableSessionEvents ?? publishDurableSessionEvents;
64
- const notifyParentOfChildTerminalFn =
65
- overrides.notifyParentOfChildTerminal ?? notifyParentOfChildTerminal;
76
+ const deliverFailedChildTurnToParentFn =
77
+ overrides.deliverFailedChildTurnToParent ?? deliverFailedChildTurnToParent;
78
+ const notifyParentOfChildIdleFn = overrides.notifyParentOfChildIdle ?? notifyParentOfChildIdle;
66
79
  const recordTurnsQueuedGaugeFn = overrides.recordTurnsQueuedGauge ?? recordTurnsQueuedGauge;
67
80
 
68
81
  async function failSessionAttempt(input: FailSessionAttemptInput): Promise<void> {
@@ -103,12 +116,11 @@ export function createSessionStateActivities(
103
116
  return;
104
117
  }
105
118
  await publishDurableSessionEventsFn(bus, input.workspaceId, input.sessionId, result.events);
106
- await notifyParentOfChildTerminalFn(
119
+ await deliverFailedChildTurnToParentFn(
107
120
  { db, bus, settings, observability, wakeSessionWorkflow },
108
121
  input.workspaceId,
109
122
  input.sessionId,
110
- "failed",
111
- `turn:${turn.id}`,
123
+ turn.id,
112
124
  );
113
125
  }
114
126
 
@@ -116,6 +128,19 @@ export function createSessionStateActivities(
116
128
  input: SettleSessionInterruptionsInput,
117
129
  ): Promise<{ action: "paused" | "continue" | "stale" }> {
118
130
  const { db, bus, observability } = await services();
131
+ if (input.phase === "attempt_quiesced") {
132
+ // Replay compatibility only: v1 histories scheduled this idempotent
133
+ // fallback after WAIT_CANCELLATION_COMPLETED. Receipt-gated v2 workflows
134
+ // never call it; runAgentTurn writes immediately after its hard fence.
135
+ const events = await markSessionAttemptQuiescedFn(db, {
136
+ workspaceId: input.workspaceId,
137
+ sessionId: input.sessionId,
138
+ attemptId: input.attemptId,
139
+ temporalWorkflowId: input.workflowId,
140
+ });
141
+ await publishDurableSessionEventsFn(bus, input.workspaceId, input.sessionId, events);
142
+ return { action: "stale" };
143
+ }
119
144
  const applied = await settleSessionAttemptInterruptionsFn(
120
145
  db,
121
146
  input.workspaceId,
@@ -129,6 +154,38 @@ export function createSessionStateActivities(
129
154
  return { action: applied.action };
130
155
  }
131
156
 
157
+ /** Persist an exact activity-owned physical-quiescence proof through the
158
+ * workflow control-activity retry policy. The DB transaction remains the
159
+ * sole receipt/wake authority; duplicate signals and activity retries reuse
160
+ * its attempt-scoped idempotency key. */
161
+ async function persistSessionAttemptQuiescence(
162
+ input: PersistSessionAttemptQuiescenceInput,
163
+ ): Promise<void> {
164
+ const { db, bus, observability } = await services();
165
+ const events = await markSessionAttemptQuiescedFn(db, {
166
+ accountId: input.accountId,
167
+ workspaceId: input.workspaceId,
168
+ sessionId: input.sessionId,
169
+ attemptId: input.attemptId,
170
+ temporalWorkflowId: input.workflowId,
171
+ temporalWorkflowRunId: input.workflowRunId,
172
+ temporalActivityId: input.activityId,
173
+ allowUninterrupted: true,
174
+ });
175
+ try {
176
+ await publishDurableSessionEventsFn(bus, input.workspaceId, input.sessionId, events);
177
+ } catch (error) {
178
+ // The receipt and exact workflow wake already committed atomically in
179
+ // Postgres. NATS is best-effort live fanout and must not keep this
180
+ // control activity retrying or delay receipt-gated admission.
181
+ observability.error("session-attempt quiescence event fanout failed", {
182
+ "opengeni.session_id": input.sessionId,
183
+ "opengeni.attempt_id": input.attemptId,
184
+ error: error instanceof Error ? error.message : String(error),
185
+ });
186
+ }
187
+ }
188
+
132
189
  /**
133
190
  * Recover the same current inference when its worker dies without completing
134
191
  * a graceful checkpoint (heartbeat timeout, SIGKILL, OOM, or node loss).
@@ -150,12 +207,11 @@ export function createSessionStateActivities(
150
207
  await publishDurableSessionEventsFn(bus, input.workspaceId, input.sessionId, result.events);
151
208
  await refreshQueuedTurnsGauge(db, observability, countQueuedTurnsFn, recordTurnsQueuedGaugeFn);
152
209
  if (result.action === "exceeded") {
153
- await notifyParentOfChildTerminalFn(
210
+ await deliverFailedChildTurnToParentFn(
154
211
  { db, bus, settings, observability, wakeSessionWorkflow },
155
212
  input.workspaceId,
156
213
  input.sessionId,
157
- "failed",
158
- `turn:${result.turnId}`,
214
+ result.turnId,
159
215
  );
160
216
  return {
161
217
  action: "exceeded",
@@ -177,6 +233,20 @@ export function createSessionStateActivities(
177
233
  return peek;
178
234
  }
179
235
 
236
+ async function expireSessionHumanInput(
237
+ input: ExpireSessionHumanInputInput,
238
+ ): Promise<ExpireSessionHumanInputResult> {
239
+ const { db, bus } = await services();
240
+ const result = await expireSessionHumanInputRequestFn(db, input);
241
+ if (result.action === "not_found") return { action: "not_found" };
242
+ if (result.events.length > 0) {
243
+ await publishDurableSessionEventsFn(bus, input.workspaceId, input.sessionId, result.events);
244
+ }
245
+ return {
246
+ action: result.request.status === "expired" ? "expired" : "stale",
247
+ };
248
+ }
249
+
180
250
  async function markSessionIdle(input: MarkSessionIdleInput): Promise<void> {
181
251
  const { db, bus, settings, observability, wakeSessionWorkflow } = await services();
182
252
  const settled = await settleSessionIdleWithParentOutboxFn(
@@ -196,11 +266,10 @@ export function createSessionStateActivities(
196
266
  // point for a spawned worker, whatever the cause (goal completed, agent or
197
267
  // system paused goal, goalless work finished, idle control settlement). Wake
198
268
  // the parent here, deduped per idle episode so the manager is nudged once.
199
- await notifyParentOfChildTerminalFn(
269
+ await notifyParentOfChildIdleFn(
200
270
  { db, bus, settings, observability, wakeSessionWorkflow },
201
271
  input.workspaceId,
202
272
  input.sessionId,
203
- "idle",
204
273
  settled.episodeKey,
205
274
  );
206
275
  }
@@ -208,8 +277,10 @@ export function createSessionStateActivities(
208
277
  return {
209
278
  failSessionAttempt,
210
279
  settleSessionInterruptions,
280
+ persistSessionAttemptQuiescence,
211
281
  recoverDispatch,
212
282
  peekSessionWork,
283
+ expireSessionHumanInput,
213
284
  markSessionIdle,
214
285
  };
215
286
  }
@@ -53,6 +53,7 @@ export function createRuntimeBatcher(
53
53
  "agent.toolCall.output",
54
54
  "agent.message.completed",
55
55
  "tool.auth_needed",
56
+ "credential.auth_needed",
56
57
  "session.requiresAction",
57
58
  "turn.completed",
58
59
  "turn.failed",
@@ -0,0 +1,57 @@
1
+ import {
2
+ startExpiringMaterialRenewalLoop,
3
+ type ExpiringMaterialRenewalController,
4
+ } from "./expiring-material-renewal";
5
+ import type { MintedSandboxToolspaceToken } from "./environment";
6
+
7
+ export const TOOLSPACE_TOKEN_DEFAULT_REFRESH_MS = 30 * 60_000;
8
+ export const TOOLSPACE_TOKEN_EXPIRY_LEAD_MS = 5 * 60_000;
9
+ export const TOOLSPACE_TOKEN_MIN_REFRESH_MS = 5_000;
10
+ export const TOOLSPACE_TOKEN_MAX_RETRY_MS = 5 * 60_000;
11
+
12
+ export type ToolspaceTokenRenewalController = ExpiringMaterialRenewalController;
13
+
14
+ export type ToolspaceTokenRenewalOptions = {
15
+ initialExpiresAt: Date;
16
+ mint: () => Promise<MintedSandboxToolspaceToken | undefined>;
17
+ write: (material: MintedSandboxToolspaceToken) => Promise<void>;
18
+ now?: () => number;
19
+ schedule?: (callback: () => void, delayMs: number) => unknown;
20
+ clearSchedule?: (timer: unknown) => void;
21
+ onSuccess?: (result: { nextDelayMs: number }) => void;
22
+ onFailure?: (failure: { retryDelayMs: number; errorClass: string }) => void;
23
+ };
24
+
25
+ class ToolspaceTokenRenewalError extends Error {
26
+ override readonly name = "ToolspaceTokenRenewalError";
27
+ }
28
+
29
+ export function startToolspaceTokenRenewalLoop(
30
+ options: ToolspaceTokenRenewalOptions,
31
+ ): ToolspaceTokenRenewalController {
32
+ return startExpiringMaterialRenewalLoop<MintedSandboxToolspaceToken>({
33
+ initialExpiresAt: options.initialExpiresAt,
34
+ resolve: async () => {
35
+ const minted = await options.mint();
36
+ if (!minted) {
37
+ throw new ToolspaceTokenRenewalError("Toolspace token mint is no longer available");
38
+ }
39
+ return minted;
40
+ },
41
+ write: options.write,
42
+ expiresAt: (material) => material.expiresAt,
43
+ policy: {
44
+ defaultRefreshMs: TOOLSPACE_TOKEN_DEFAULT_REFRESH_MS,
45
+ expiryLeadMs: TOOLSPACE_TOKEN_EXPIRY_LEAD_MS,
46
+ minRefreshMs: TOOLSPACE_TOKEN_MIN_REFRESH_MS,
47
+ maxRetryMs: TOOLSPACE_TOKEN_MAX_RETRY_MS,
48
+ },
49
+ ...(options.now ? { now: options.now } : {}),
50
+ ...(options.schedule ? { schedule: options.schedule } : {}),
51
+ ...(options.clearSchedule ? { clearSchedule: options.clearSchedule } : {}),
52
+ ...(options.onSuccess
53
+ ? { onSuccess: ({ nextDelayMs }) => options.onSuccess?.({ nextDelayMs }) }
54
+ : {}),
55
+ ...(options.onFailure ? { onFailure: options.onFailure } : {}),
56
+ });
57
+ }
@@ -36,6 +36,21 @@ export type SignalCodexCapacityWorkflow = (input: {
36
36
  wakeRevision: number;
37
37
  }) => Promise<void>;
38
38
 
39
+ /** Exact activity-owned proof that the hard sandbox/tool fence physically
40
+ * drained. This is delivery evidence only: the workflow still validates the
41
+ * persisted attempt dispatch and commits the authoritative Postgres receipt. */
42
+ export type SessionAttemptQuiescenceProof = {
43
+ accountId: string;
44
+ workspaceId: string;
45
+ sessionId: string;
46
+ attemptId: string;
47
+ workflowId: string;
48
+ workflowRunId: string;
49
+ activityId: string;
50
+ };
51
+
52
+ export type SignalSessionAttemptQuiesced = (input: SessionAttemptQuiescenceProof) => Promise<void>;
53
+
39
54
  export type ActivityServices = {
40
55
  settings: Settings;
41
56
  db: Database;
@@ -45,6 +60,9 @@ export type ActivityServices = {
45
60
  documentServices: DocumentServices;
46
61
  observability: Observability;
47
62
  wakeSessionWorkflow: WakeSessionWorkflowSignal | null;
63
+ /** Durable signalWithStart fallback used only after the activity's direct
64
+ * physical-quiescence receipt write exhausts its bounded DB retries. */
65
+ signalSessionAttemptQuiesced: SignalSessionAttemptQuiesced | null;
48
66
  /** Revision-carrying capacity nudge; generic outbox repair is also sufficient. */
49
67
  signalCodexCapacityWorkflow?: SignalCodexCapacityWorkflow | null;
50
68
  // §7.5 P3 — host-entitlements port, the WORKER half of the same seam the API
@@ -61,7 +79,7 @@ export type ActivityServices = {
61
79
  // admission and metering are separate operations, and only metering carries
62
80
  // the idempotency key.
63
81
  entitlements?: EntitlementsPort | null;
64
- // §7.6 P4a — host connection-credential provider, the WORKER half of the
82
+ // §7.6 connection-credential provider — host connection-credential provider, the WORKER half of the
65
83
  // federated-connection boundary. When set, the run's per-run credential mint
66
84
  // delegates to the host instead of self-minting from `settings`:
67
85
  // - `gitCredentials` REPLACES `createGitHubAppInstallationToken(settings,…)`
@@ -72,7 +90,7 @@ export type ActivityServices = {
72
90
  // self-mint for THAT leg. null/undefined (standalone default) → both legs
73
91
  // self-mint byte-for-byte as today.
74
92
  //
75
- // FORK-7 CROSS-CHECK: a provider echoes the `workspaceId` it scoped the
93
+ // workspace-scope cross-check CROSS-CHECK: a provider echoes the `workspaceId` it scoped the
76
94
  // credential to; the consuming activity ASSERTS agreement with the run's
77
95
  // workspace BEFORE injecting `GH_TOKEN` (or applying decrypted values). A host
78
96
  // mapping bug returning tenant B's creds for a tenant-A run is caught here.
@@ -123,8 +141,16 @@ export type SettleSessionInterruptionsInput = {
123
141
  sessionId: string;
124
142
  attemptId: string;
125
143
  workflowId: string;
144
+ /**
145
+ * Replay-only compatibility for session workflow histories created before
146
+ * the receipt-gated cancellation v2 patch. New histories never send this
147
+ * phase; the exact activity writes the authoritative receipt itself.
148
+ */
149
+ phase?: "logical" | "attempt_quiesced";
126
150
  };
127
151
 
152
+ export type PersistSessionAttemptQuiescenceInput = SessionAttemptQuiescenceProof;
153
+
128
154
  export type FailSessionAttemptInput = {
129
155
  accountId: string;
130
156
  workspaceId: string;
@@ -160,6 +186,17 @@ export type PeekSessionWorkInput = {
160
186
  sessionId: string;
161
187
  };
162
188
 
189
+ export type ExpireSessionHumanInputInput = {
190
+ accountId: string;
191
+ workspaceId: string;
192
+ sessionId: string;
193
+ requestId: string;
194
+ };
195
+
196
+ export type ExpireSessionHumanInputResult = {
197
+ action: "expired" | "stale" | "not_found";
198
+ };
199
+
163
200
  export type MarkSessionIdleInput = {
164
201
  workspaceId: string;
165
202
  sessionId: string;
@@ -220,10 +257,11 @@ type ClaimedRunAgentTurnResult = {
220
257
  // persisted in Postgres and reconstructed after workflow/worker restart.
221
258
  // The workflow must not call maybeContinueGoal while this waiter is active.
222
259
  capacityWait?: CodexCapacityWaitRef;
223
- // A maintenance execution could not run (for example, every Codex account
224
- // is unavailable). End this workflow run without consuming the durable
225
- // request; a later prompt/control wake starts the workflow again and normal
226
- // prompt claim ordering consumes the request in-turn.
260
+ // This execution reached a durable terminal-for-now boundary (for example,
261
+ // maintenance could not run or same-turn context recovery failed). End this
262
+ // workflow run without synthesizing another goal continuation from unchanged
263
+ // state. A later prompt/control/new-update wake may retry through normal claim
264
+ // ordering.
227
265
  deferredUntilWake?: boolean;
228
266
  };
229
267