@opengeni/worker-bundle 0.7.2 → 0.7.4

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeni/worker-bundle",
3
- "version": "0.7.2",
3
+ "version": "0.7.4",
4
4
  "description": "OpenGeni worker entry: runOpenGeniWorker/createOpenGeniWorker(deps) + the un-bundled Temporal workflow source tree. An engine-distribution surface — its runtime closure includes engine-internal packages and the workflow bundle ships as on-disk TS source.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -35,16 +35,16 @@
35
35
  "prepublishOnly": "bash ../../scripts/prepublish-guard"
36
36
  },
37
37
  "dependencies": {
38
- "@opengeni/codex": "^0.2.2",
39
- "@opengeni/config": "^0.5.0",
38
+ "@opengeni/codex": "^0.2.3",
39
+ "@opengeni/config": "^0.5.1",
40
40
  "@opengeni/contracts": "^0.10.0",
41
- "@opengeni/core": "^0.4.7",
42
- "@opengeni/db": "^0.7.0",
43
- "@opengeni/documents": "^0.2.9",
44
- "@opengeni/events": "^0.3.0",
41
+ "@opengeni/core": "^0.4.9",
42
+ "@opengeni/db": "^0.7.2",
43
+ "@opengeni/documents": "^0.2.11",
44
+ "@opengeni/events": "^0.3.2",
45
45
  "@opengeni/observability": "^0.3.0",
46
- "@opengeni/runtime": "^0.7.0",
47
- "@opengeni/storage": "^0.2.9",
46
+ "@opengeni/runtime": "^0.7.1",
47
+ "@opengeni/storage": "^0.2.10",
48
48
  "@temporalio/activity": "^1.17.0",
49
49
  "@temporalio/client": "^1.17.0",
50
50
  "@temporalio/worker": "^1.17.0",
@@ -243,26 +243,17 @@ import { createHash, randomUUID } from "node:crypto";
243
243
  // budget against the same window.
244
244
  export const PROVIDER_BACKPRESSURE_DELAY_MS = 60_000;
245
245
 
246
- /**
247
- * Recovery routing for a turn failed by a RETRYABLE provider error, once the
248
- * activity knows whether the session still has an active goal: a goal-bearing
249
- * session idles and auto-continues after the backpressure delay, a goal-less one
250
- * idles and waits for the next user message. A NON-retryable failure never reaches
251
- * here — it takes the terminal session.failed path — so the contrast this encodes
252
- * is "retryable provider blip ⇒ idle-with-recovery, not a dead session." Single
253
- * source of truth for the recovery mode and continuation delay the retryable
254
- * turn-failure branch publishes.
255
- */
256
- export function providerRetryRecovery(goalActive: boolean): {
257
- recovery: "goal_continuation" | "user_message";
258
- continueDelayMs?: number;
246
+ /** A retryable provider fault recovers the accepted turn itself. Goal state is
247
+ * irrelevant: autonomous continuation and infrastructure recovery are separate
248
+ * concerns. */
249
+ export function providerRecoveryResult(): {
250
+ status: "recovering";
251
+ continueDelayMs: number;
259
252
  } {
260
- return goalActive
261
- ? {
262
- recovery: "goal_continuation",
263
- continueDelayMs: PROVIDER_BACKPRESSURE_DELAY_MS,
264
- }
265
- : { recovery: "user_message" };
253
+ return {
254
+ status: "recovering",
255
+ continueDelayMs: PROVIDER_BACKPRESSURE_DELAY_MS,
256
+ };
266
257
  }
267
258
 
268
259
  /**
@@ -1130,7 +1121,11 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
1130
1121
  >,
1131
1122
  ): RunAgentTurnResult => {
1132
1123
  if (!turnId) throw new Error("Claimed activity result produced before turn admission");
1133
- return { ...result, turnId, attemptId: input.attemptId } as RunAgentTurnResult;
1124
+ return {
1125
+ ...result,
1126
+ turnId,
1127
+ attemptId: input.attemptId,
1128
+ } as RunAgentTurnResult;
1134
1129
  };
1135
1130
  // The Connected Machine op observer for this turn: meters every op AND buffers
1136
1131
  // the eventable ones (infra failures + healed recoveries) as machine.op.* session
@@ -1707,6 +1702,7 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
1707
1702
  const claim = await claimSessionWorkForAttempt(db, input.workspaceId, {
1708
1703
  sessionId: input.sessionId,
1709
1704
  workflowId: input.workflowId,
1705
+ workflowRunId: input.workflowRunId,
1710
1706
  attemptId: input.attemptId,
1711
1707
  dispatchId,
1712
1708
  trigger: input.trigger,
@@ -1874,7 +1870,6 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
1874
1870
  turnId: turnId!,
1875
1871
  triggerEventId: triggerEventId!,
1876
1872
  attemptId: input.attemptId,
1877
- childCompletionParentWakeEnabled: settings.childCompletionParentWakeEnabled,
1878
1873
  turnStatus: inputSettlement.turnStatus,
1879
1874
  sessionStatus: inputSettlement.sessionStatus,
1880
1875
  activeTurnId: inputSettlement.activeTurnId,
@@ -2708,13 +2703,6 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
2708
2703
  if (turn.source === "compaction") {
2709
2704
  const persistentSessionSettings = {
2710
2705
  titleIsSet: Boolean(session.title?.trim()),
2711
- childNotificationsMode:
2712
- typeof session.metadata === "object" &&
2713
- session.metadata !== null &&
2714
- (session.metadata as { childNotificationsMode?: unknown }).childNotificationsMode ===
2715
- "passive"
2716
- ? ("passive" as const)
2717
- : ("digest" as const),
2718
2706
  };
2719
2707
  const compactionInstructions = appendPersistentSessionSettings(
2720
2708
  appendSessionInstructions(
@@ -3250,6 +3238,8 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
3250
3238
  // the caller by its own identity (sacred-pause guard), not the racy
3251
3239
  // live active pointer.
3252
3240
  ...(turnId ? { turnId } : {}),
3241
+ attemptId: input.attemptId,
3242
+ executionGeneration,
3253
3243
  subjectId: "worker:first-party-mcp",
3254
3244
  subjectLabel: "OpenGeni worker",
3255
3245
  resolveCredential,
@@ -3305,13 +3295,6 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
3305
3295
  genesisTitleHint: isGenesisTurn,
3306
3296
  persistentSessionSettings: {
3307
3297
  titleIsSet: Boolean(session.title?.trim()),
3308
- childNotificationsMode:
3309
- typeof session.metadata === "object" &&
3310
- session.metadata !== null &&
3311
- (session.metadata as { childNotificationsMode?: unknown }).childNotificationsMode ===
3312
- "passive"
3313
- ? ("passive" as const)
3314
- : ("digest" as const),
3315
3298
  },
3316
3299
  sandboxEnvironment,
3317
3300
  // TOKEN-BROKER (B1): forward the per-turn git token OFF-MANIFEST as the clone
@@ -3809,6 +3792,7 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
3809
3792
  const ownedEstablished = resolvedSandbox?.established ?? lazyOwnedSandbox;
3810
3793
  const runStreamOnce = (): ReturnType<OpenGeniRuntime["runStream"]> =>
3811
3794
  runtime.runStream(agent, runInput!, modelRunSettings, {
3795
+ ...(activityContext ? { signal: activityContext.cancellationSignal } : {}),
3812
3796
  sandboxEnvironment,
3813
3797
  onRuntimeEvent: async (event) => {
3814
3798
  await renewCodexLease("runtime_event");
@@ -4041,7 +4025,15 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
4041
4025
  }
4042
4026
  } finally {
4043
4027
  if (!streamDone) {
4044
- await iterator.return?.();
4028
+ // ReadableStream cancellation synchronously trips the Agents SDK's
4029
+ // abort controller, but its returned promise may wait for an
4030
+ // uncooperative provider producer. Once this attempt is fenced,
4031
+ // awaiting that provider-side cleanup pins the Temporal activity
4032
+ // (and therefore Pause) even though every late write is already
4033
+ // rejected. Start cancellation and detach only its cleanup wait;
4034
+ // the SDK abort signal stops the producer and the durable attempt
4035
+ // fence remains the authority for every callback that arrives late.
4036
+ void iterator.return?.().catch(() => undefined);
4045
4037
  }
4046
4038
  }
4047
4039
  await batcher.flush();
@@ -4397,10 +4389,13 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
4397
4389
  activityError = error;
4398
4390
  await flushRuntimeBatcher();
4399
4391
  // Ownership already moved to a newer attempt or an authoritative
4400
- // control transaction. Return locally; no Temporal cancellation and no
4401
- // competing turn/session settlement is needed.
4392
+ // control transaction. Surface a transport cancellation instead of a
4393
+ // normal activity result: with WAIT_CANCELLATION_COMPLETED, Temporal
4394
+ // must observe a terminal cancellation before the session workflow may
4395
+ // close. Returning normally after a cancel request is rejected by the
4396
+ // server and leaves the worker task detached indefinitely.
4402
4397
  turnMetricOutcome = "cancelled";
4403
- return claimedResult({ status: "cancelled" });
4398
+ throw new CancelledFailure("TURN_ATTEMPT_FENCED", [], error);
4404
4399
  }
4405
4400
  if (error instanceof CancelledFailure) {
4406
4401
  activityStatus = "cancelled";
@@ -5106,52 +5101,37 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
5106
5101
  return claimedResult({ status: "idle" });
5107
5102
  }
5108
5103
  // A retryable provider/MCP failure is transient external backpressure,
5109
- // not a session failure: the in-client retry budget is already
5110
- // exhausted by the time the error reaches here, so fail the turn
5111
- // truthfully but idle the session. With an active goal the continuation
5112
- // loop resumes after a pacing delay; without one the session simply
5113
- // waits for the next user message. Long-lived sessions (a per-customer
5114
- // ops channel between goals) must never go terminal because the
5115
- // provider had a bad minute -- a failed session would reject the very
5116
- // retry message the failure asks for.
5104
+ // not a session or goal failure. The in-client retry budget is already
5105
+ // exhausted by the time the error reaches here. Checkpoint conversation
5106
+ // truth, recover this SAME accepted turn, then let the workflow re-claim
5107
+ // it after a pacing delay. This is independent of goal state and never
5108
+ // relies on a synthetic continuation prompt.
5117
5109
  const failure = agentRunFailurePayload(error);
5118
5110
  if (failure.retryable && publish && turnId && turnStartedPublished) {
5119
- const goal = await getSessionGoal(db, input.workspaceId, input.sessionId).catch(() => null);
5120
- const goalActive = Boolean(goal && goal.status === "active");
5121
- const recoveryRouting = providerRetryRecovery(goalActive);
5111
+ const recoveryResult = providerRecoveryResult();
5122
5112
  await flushRuntimeBatcher();
5123
- // Provider/MCP errors rarely carry SDK run state; a null falls back to
5124
- // the previous snapshot, same degraded-context contract as the
5125
- // max-turns path above.
5126
- await reconcileConversationTruth();
5127
- if (
5128
- !(await settle!({
5129
- events: [
5130
- {
5131
- type: "turn.failed",
5132
- payload: {
5133
- ...failure,
5134
- recovery: recoveryRouting.recovery,
5135
- },
5136
- },
5137
- { type: "session.status.changed", payload: { status: "idle" } },
5138
- ],
5139
- turnStatus: "failed",
5140
- sessionStatus: "idle",
5141
- activeTurnId: null,
5142
- }))
5143
- ) {
5113
+ await reconcileConversationTruth({ requireDurable: true });
5114
+ const recovery = await requestSessionTurnRecovery(db, input.workspaceId, {
5115
+ sessionId: input.sessionId,
5116
+ turnId,
5117
+ triggerEventId: triggerEventId!,
5118
+ attemptId: input.attemptId,
5119
+ reason: failure.code ?? "provider_unavailable",
5120
+ detail: {
5121
+ ...failure,
5122
+ continueDelayMs: recoveryResult.continueDelayMs,
5123
+ },
5124
+ });
5125
+ if (recovery.action === "stale") {
5126
+ activityStatus = "cancelled";
5127
+ turnMetricOutcome = "cancelled";
5144
5128
  return claimedResult({ status: "cancelled" });
5145
5129
  }
5146
- turnMetricOutcome = "failed";
5147
- activityStatus = "idle";
5130
+ await publishDurableSessionEvents(bus, input.workspaceId, input.sessionId, recovery.events);
5131
+ turnMetricOutcome = "recovering";
5132
+ activityStatus = "recovering";
5148
5133
  activityError = error;
5149
- return claimedResult({
5150
- status: "idle",
5151
- ...(recoveryRouting.continueDelayMs !== undefined
5152
- ? { continueDelayMs: recoveryRouting.continueDelayMs }
5153
- : {}),
5154
- });
5134
+ return claimedResult(recoveryResult);
5155
5135
  }
5156
5136
  activityStatus = "failed";
5157
5137
  activityError = error;
@@ -5407,11 +5387,10 @@ export function createRunAgentTurnActivity(services: () => Promise<ActivityServi
5407
5387
  /**
5408
5388
  * True when the error is transient upstream backpressure — a model-provider 5xx,
5409
5389
  * a "server had a bad minute" body, or a dropped/again-able network connection —
5410
- * rather than a request the session got wrong. These are safe to retry: the turn
5411
- * routes into the SAME idle + goal-continuation recovery the rate-limit branch
5412
- * uses (a goal-bearing session auto-continues after PROVIDER_BACKPRESSURE_DELAY_MS;
5413
- * a goal-less one waits for the next user message), and the resume notice tells the
5414
- * model to re-check side effects before repeating them.
5390
+ * rather than a request the session got wrong. These are safe to recover as a new
5391
+ * fenced attempt of the SAME turn after PROVIDER_BACKPRESSURE_DELAY_MS. Durable
5392
+ * tool results are preserved and ambiguous in-flight effects are closed before
5393
+ * the new attempt, independent of whether the session has an active goal.
5415
5394
  *
5416
5395
  * This is the classification gap that hard-failed a fleet of prod sessions during a
5417
5396
  * provider degradation window: their errors ("Our servers are currently overloaded",
@@ -1,4 +1,9 @@
1
- import type { ResourceRef, SessionStatus, ToolRef } from "@opengeni/contracts";
1
+ import type {
2
+ ResourceRef,
3
+ SessionStatus,
4
+ SessionSystemUpdatePayload,
5
+ ToolRef,
6
+ } from "@opengeni/contracts";
2
7
 
3
8
  export {
4
9
  mergeResourceRefs,
@@ -28,8 +33,9 @@ export function scheduledUserMessagePayload(
28
33
  tools: ToolRef[],
29
34
  taskId: string,
30
35
  runId: string,
31
- ): Record<string, unknown> {
36
+ ): Extract<SessionSystemUpdatePayload, { type: "scheduled_occurrence" }> {
32
37
  return {
38
+ type: "scheduled_occurrence",
33
39
  text: prompt,
34
40
  scheduledTaskId: taskId,
35
41
  scheduledTaskRunId: runId,
@@ -155,7 +155,7 @@ export function createGoalActivities(services: () => Promise<ActivityServices>)
155
155
  accountId: input.accountId,
156
156
  workspaceId: input.workspaceId,
157
157
  sessionId: input.sessionId,
158
- kind: "lifecycle_event",
158
+ kind: "goal_continuation",
159
159
  classification: "info",
160
160
  sourceId: decision.goal.id,
161
161
  dedupeKey: `goal-continuation:${decision.goal.id}:${decision.goal.version}:${decision.autoContinuation}`,
@@ -1,5 +1,5 @@
1
1
  import type { Settings } from "@opengeni/config";
2
- import type { Session, SessionGoal } from "@opengeni/contracts";
2
+ import type { Session, SessionGoal, SessionSystemUpdatePayload } from "@opengeni/contracts";
3
3
  import {
4
4
  getSession,
5
5
  getSessionGoal,
@@ -64,13 +64,6 @@ export async function notifyParentOfChildTerminal(
64
64
  // per work batch and is stable across retries of that same idle transition.
65
65
  episodeKey?: string | null,
66
66
  ): Promise<void> {
67
- // Temporarily disabled by default: child completion remains durable on the
68
- // child session, but must not manufacture parent system-update/inference
69
- // work. Keep this before every DB read, event publish, and workflow signal so
70
- // the disabled path cannot mutate or wake the parent.
71
- if (!svc.settings.childCompletionParentWakeEnabled) {
72
- return;
73
- }
74
67
  try {
75
68
  const child = await getSession(svc.db, workspaceId, childSessionId);
76
69
  if (!child || !child.parentSessionId) {
@@ -89,7 +82,7 @@ export async function notifyParentOfChildTerminal(
89
82
  workspaceId,
90
83
  sourceSessionId: child.id,
91
84
  targetSessionId: child.parentSessionId,
92
- kind: "child_session_update",
85
+ kind: "child_terminal_result",
93
86
  classification:
94
87
  terminalStatus === "failed"
95
88
  ? "failure"
@@ -179,13 +172,6 @@ export async function reconcilePendingParentSystemUpdates(
179
172
  ): Promise<{ claimed: number; delivered: number; failed: number }> {
180
173
  const claimPendingSessionSystemUpdateOutboxFn =
181
174
  overrides.claimPendingSessionSystemUpdateOutbox ?? claimPendingSessionSystemUpdateOutbox;
182
- // Do not claim or deliver the child-terminal outbox while completion wakes
183
- // are disabled. Atomic terminal producers use the same setting, so no new
184
- // backlog is manufactured either. Session-workflow wake repair is owned by
185
- // its dedicated dispatcher and never depends on sandbox or child settings.
186
- if (!svc.settings.childCompletionParentWakeEnabled) {
187
- return { claimed: 0, delivered: 0, failed: 0 };
188
- }
189
175
  const rows = await claimPendingSessionSystemUpdateOutboxFn(svc.db, limit);
190
176
  let delivered = 0;
191
177
  let failed = 0;
@@ -225,7 +211,7 @@ export async function reconcilePendingSessionWorkflowWakes(
225
211
  sessionId: repair.sessionId,
226
212
  workflowId: repair.temporalWorkflowId,
227
213
  wakeRevision: repair.wakeRevision,
228
- ...(repair.controlEventId ? { controlEventId: repair.controlEventId } : {}),
214
+ ...(repair.interruptionRequested ? { interruptionRequested: true } : {}),
229
215
  });
230
216
  delivered += 1;
231
217
  } catch (error) {
@@ -246,8 +232,9 @@ function childCompletionPayload(
246
232
  child: Session,
247
233
  goal: SessionGoal | null,
248
234
  terminalStatus: "idle" | "failed",
249
- ): Record<string, unknown> {
235
+ ): Extract<SessionSystemUpdatePayload, { type: "child_terminal_result" }> {
250
236
  return {
237
+ type: "child_terminal_result",
251
238
  childSessionId: child.id,
252
239
  status: terminalStatus,
253
240
  ...(goal
@@ -224,7 +224,7 @@ export function createScheduledTaskActivities(services: () => Promise<ActivitySe
224
224
  accountId: task.accountId,
225
225
  workspaceId: task.workspaceId,
226
226
  sessionId: session.id,
227
- kind: "scheduled_wake",
227
+ kind: "scheduled_occurrence",
228
228
  classification: "info",
229
229
  sourceId: run.id,
230
230
  dedupeKey: `scheduled-wake:${run.id}`,
@@ -332,7 +332,7 @@ export function createScheduledTaskActivities(services: () => Promise<ActivitySe
332
332
  accountId: task.accountId,
333
333
  workspaceId: task.workspaceId,
334
334
  sessionId: session.id,
335
- kind: "scheduled_wake",
335
+ kind: "scheduled_occurrence",
336
336
  classification: "info",
337
337
  sourceId: run.id,
338
338
  dedupeKey: `scheduled-wake:${run.id}`,
@@ -1,5 +1,5 @@
1
1
  import {
2
- settlePendingSessionControl,
2
+ settleSessionAttemptInterruptions,
3
3
  applySessionTurnSettlement,
4
4
  recoverSessionDispatch,
5
5
  peekSessionWork as peekSessionWorkDb,
@@ -16,14 +16,14 @@ import type {
16
16
  ActivityServices,
17
17
  PeekSessionWorkInput,
18
18
  FailSessionAttemptInput,
19
- SettleSessionControlInput,
19
+ SettleSessionInterruptionsInput,
20
20
  MarkSessionIdleInput,
21
21
  RecoverDispatchInput,
22
22
  RecoverDispatchResult,
23
23
  } from "./types";
24
24
 
25
25
  export type SessionStateActivityOverrides = Partial<{
26
- settlePendingSessionControl: typeof settlePendingSessionControl;
26
+ settleSessionAttemptInterruptions: typeof settleSessionAttemptInterruptions;
27
27
  applySessionTurnSettlement: typeof applySessionTurnSettlement;
28
28
  recoverSessionDispatch: typeof recoverSessionDispatch;
29
29
  peekSessionWork: typeof peekSessionWorkDb;
@@ -47,8 +47,8 @@ export function createSessionStateActivities(
47
47
  services: () => Promise<ActivityServices>,
48
48
  overrides: SessionStateActivityOverrides = {},
49
49
  ) {
50
- const settlePendingSessionControlFn =
51
- overrides.settlePendingSessionControl ?? settlePendingSessionControl;
50
+ const settleSessionAttemptInterruptionsFn =
51
+ overrides.settleSessionAttemptInterruptions ?? settleSessionAttemptInterruptions;
52
52
  const applySessionTurnSettlementFn =
53
53
  overrides.applySessionTurnSettlement ?? applySessionTurnSettlement;
54
54
  const recoverSessionDispatchFn = overrides.recoverSessionDispatch ?? recoverSessionDispatch;
@@ -84,7 +84,6 @@ export function createSessionStateActivities(
84
84
  turnId: turn.id,
85
85
  triggerEventId: turn.triggerEventId,
86
86
  attemptId: input.attemptId,
87
- childCompletionParentWakeEnabled: settings.childCompletionParentWakeEnabled,
88
87
  turnStatus: "failed",
89
88
  sessionStatus: "failed",
90
89
  activeTurnId: null,
@@ -109,18 +108,19 @@ export function createSessionStateActivities(
109
108
  input.workspaceId,
110
109
  input.sessionId,
111
110
  "failed",
111
+ `turn:${turn.id}`,
112
112
  );
113
113
  }
114
114
 
115
- async function settleSessionControl(
116
- input: SettleSessionControlInput,
115
+ async function settleSessionInterruptions(
116
+ input: SettleSessionInterruptionsInput,
117
117
  ): Promise<{ action: "paused" | "continue" | "stale" }> {
118
118
  const { db, bus, observability } = await services();
119
- const applied = await settlePendingSessionControlFn(
119
+ const applied = await settleSessionAttemptInterruptionsFn(
120
120
  db,
121
121
  input.workspaceId,
122
122
  input.sessionId,
123
- input.triggerEventId,
123
+ input.attemptId,
124
124
  );
125
125
  if (applied.events.length > 0) {
126
126
  await publishDurableSessionEventsFn(bus, input.workspaceId, input.sessionId, applied.events);
@@ -143,7 +143,6 @@ export function createSessionStateActivities(
143
143
  attemptId: input.attemptId,
144
144
  timeoutType: input.timeoutType,
145
145
  maxRedispatches: WORKER_DEATH_MAX_REDISPATCHES,
146
- childCompletionParentWakeEnabled: settings.childCompletionParentWakeEnabled,
147
146
  });
148
147
  if (result.action === "stale" || result.action === "unclaimed") {
149
148
  return { action: result.action };
@@ -184,7 +183,6 @@ export function createSessionStateActivities(
184
183
  db,
185
184
  input.workspaceId,
186
185
  input.sessionId,
187
- settings.childCompletionParentWakeEnabled,
188
186
  );
189
187
  if (settled.events.length > 0) {
190
188
  await publishDurableSessionEventsFn(bus, input.workspaceId, input.sessionId, settled.events);
@@ -209,7 +207,7 @@ export function createSessionStateActivities(
209
207
 
210
208
  return {
211
209
  failSessionAttempt,
212
- settleSessionControl,
210
+ settleSessionInterruptions,
213
211
  recoverDispatch,
214
212
  peekSessionWork,
215
213
  markSessionIdle,
@@ -25,7 +25,7 @@ export type WakeSessionWorkflowSignal = (input: {
25
25
  sessionId: string;
26
26
  workflowId: string;
27
27
  wakeRevision: number;
28
- controlEventId?: string;
28
+ interruptionRequested?: boolean;
29
29
  }) => Promise<void>;
30
30
 
31
31
  export type SignalCodexCapacityWorkflow = (input: {
@@ -112,15 +112,16 @@ export type RunAgentTurnInput = {
112
112
  workspaceId: string;
113
113
  sessionId: string;
114
114
  workflowId: string;
115
+ workflowRunId: string;
115
116
  attemptId: string;
116
117
  trigger: { kind: "next" } | { kind: "approval"; triggerEventId: string };
117
118
  };
118
119
 
119
- export type SettleSessionControlInput = {
120
+ export type SettleSessionInterruptionsInput = {
120
121
  accountId: string;
121
122
  workspaceId: string;
122
123
  sessionId: string;
123
- triggerEventId: string;
124
+ attemptId: string;
124
125
  workflowId: string;
125
126
  };
126
127
 
@@ -206,9 +207,8 @@ type ClaimedRunAgentTurnResult = {
206
207
  status: "idle" | "requires_action" | "failed" | "cancelled" | "recovering";
207
208
  turnId: string;
208
209
  attemptId: string;
209
- // Provider backpressure pacing: when set on an idle result, the session
210
- // workflow holds the loop this long before admitting the next turn (an
211
- // active goal's continuation would otherwise immediately re-hit the limit).
210
+ // Provider backpressure pacing: when set on an idle or recovering result, the
211
+ // session workflow holds the loop this long before admitting the next attempt.
212
212
  continueDelayMs?: number;
213
213
  // Multi-account rotation all-capped idle: every connected Codex subscription is
214
214
  // rate-limited/cooling. This is a MANDATORY hold — session.ts must wait
package/src/activities.ts CHANGED
@@ -153,7 +153,7 @@ const defaultTurnActivities = createTurnActivities();
153
153
  export const runAgentTurn = defaultTurnActivities.runAgentTurn;
154
154
  export const indexDocument = defaultControlActivities.indexDocument;
155
155
  export const failSessionAttempt = defaultControlActivities.failSessionAttempt;
156
- export const settleSessionControl = defaultControlActivities.settleSessionControl;
156
+ export const settleSessionInterruptions = defaultControlActivities.settleSessionInterruptions;
157
157
  export const recoverDispatch = defaultControlActivities.recoverDispatch;
158
158
  export const peekSessionWork = defaultControlActivities.peekSessionWork;
159
159
  export const markSessionIdle = defaultControlActivities.markSessionIdle;
package/src/index.ts CHANGED
@@ -34,7 +34,7 @@ import {
34
34
  SESSION_WORKFLOW_WAKE_DISPATCHER_PERIOD_MS,
35
35
  SESSION_WORKFLOW_WAKE_DISPATCHER_SCHEDULE_ID,
36
36
  SESSION_WORKFLOW_WAKE_DISPATCHER_WORKFLOW_TYPE,
37
- } from "./workflow-wake-contract";
37
+ } from "@opengeni/core";
38
38
  import {
39
39
  CONTROL_WORKER_MAX_CONCURRENT_ACTIVITIES,
40
40
  CONTROL_WORKER_MAX_CONCURRENT_WORKFLOW_TASKS,
@@ -157,16 +157,16 @@ export async function createWorkerWorkflowSignaler(
157
157
  sessionId,
158
158
  workflowId,
159
159
  wakeRevision,
160
- controlEventId,
160
+ interruptionRequested,
161
161
  }) => {
162
- if (controlEventId) {
162
+ if (interruptionRequested) {
163
163
  await temporal.workflow.signalWithStart("sessionWorkflow", {
164
164
  taskQueue: settings.temporalTaskQueue,
165
165
  workflowId,
166
166
  workflowIdReusePolicy: "ALLOW_DUPLICATE",
167
167
  args: [{ accountId, workspaceId, sessionId }],
168
168
  signal: "sessionControl",
169
- signalArgs: [controlEventId],
169
+ signalArgs: [],
170
170
  });
171
171
  } else {
172
172
  await temporal.workflow.signalWithStart("sessionWorkflow", {
@@ -1,4 +1,4 @@
1
- import { proxyActivities } from "@temporalio/workflow";
1
+ import { ActivityCancellationType, proxyActivities } from "@temporalio/workflow";
2
2
  import type * as activities from "../activities";
3
3
 
4
4
  type WorkflowControlActivities = Pick<
@@ -11,7 +11,7 @@ type WorkflowControlActivities = Pick<
11
11
  | "peekSessionWork"
12
12
  | "reconcileCodexCapacityWait"
13
13
  | "recoverDispatch"
14
- | "settleSessionControl"
14
+ | "settleSessionInterruptions"
15
15
  >;
16
16
 
17
17
  /**
@@ -57,6 +57,12 @@ export function turnActivityForTaskQueue(baseTaskQueue: string) {
57
57
  // accepts them and performs the atomic claim.
58
58
  startToCloseTimeout: "30 days",
59
59
  heartbeatTimeout: "2 minutes",
60
+ // Pause/Steer may complete the durable control transition immediately,
61
+ // but the session workflow must remain open until the old turn activity is
62
+ // physically gone. Leaving this implicit uses Temporal's try-cancel wire
63
+ // default: the activity promise rejects as soon as cancellation is
64
+ // requested and the workflow can close while the worker keeps streaming.
65
+ cancellationType: ActivityCancellationType.WAIT_CANCELLATION_COMPLETED,
60
66
  retry: { maximumAttempts: 1 },
61
67
  });
62
68
  }