@opengeni/worker-bundle 0.7.1 → 0.7.2

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 (45) hide show
  1. package/dist/index.d.ts +182 -67
  2. package/dist/index.js +7113 -1652
  3. package/dist/index.js.map +1 -1
  4. package/package.json +18 -18
  5. package/src/activities/agent-turn.ts +4337 -1052
  6. package/src/activities/capabilities.ts +43 -8
  7. package/src/activities/codex-capacity.ts +223 -0
  8. package/src/activities/codex-rotation.ts +550 -54
  9. package/src/activities/common.ts +7 -1
  10. package/src/activities/context-compaction.ts +152 -118
  11. package/src/activities/documents.ts +32 -27
  12. package/src/activities/environment.ts +318 -75
  13. package/src/activities/file-upload-reaper.ts +79 -0
  14. package/src/activities/git-credential-renewal.ts +183 -0
  15. package/src/activities/goals.ts +142 -123
  16. package/src/activities/packs.ts +55 -5
  17. package/src/activities/parent-wake.ts +228 -41
  18. package/src/activities/recording.ts +154 -122
  19. package/src/activities/redaction.ts +3 -1
  20. package/src/activities/rig-verification.ts +441 -0
  21. package/src/activities/run-input.ts +110 -122
  22. package/src/activities/sandbox-lease.ts +186 -51
  23. package/src/activities/scheduled-tasks.ts +287 -171
  24. package/src/activities/session-state.ts +168 -157
  25. package/src/activities/streaming.ts +143 -19
  26. package/src/activities/turn-attempt-fenced.ts +14 -0
  27. package/src/activities/types.ts +102 -32
  28. package/src/activities/workflow-wake.ts +44 -0
  29. package/src/activities/workspace-capture.ts +964 -0
  30. package/src/activities.ts +75 -35
  31. package/src/concurrency.ts +11 -0
  32. package/src/http.ts +16 -6
  33. package/src/index.ts +322 -49
  34. package/src/observability-metrics.ts +441 -8
  35. package/src/op-journal.ts +46 -0
  36. package/src/sandbox-resume.ts +431 -201
  37. package/src/sandbox-routing.ts +209 -22
  38. package/src/workflow-wake-contract.ts +5 -0
  39. package/src/workflows/activities.ts +58 -7
  40. package/src/workflows/file-upload-reaper.ts +12 -0
  41. package/src/workflows/rig-verification.ts +28 -0
  42. package/src/workflows/scheduled-tasks.ts +12 -26
  43. package/src/workflows/session.ts +330 -173
  44. package/src/workflows/workflow-wake.ts +12 -0
  45. package/src/workflows.ts +9 -7
@@ -21,13 +21,17 @@ import {
21
21
  buildSelfhostedBackendSession,
22
22
  makeActiveBackendResolver,
23
23
  NatsControlRpc,
24
+ NatsOpStreamTransport,
24
25
  RoutingSandboxSession,
25
26
  type ControlRpc,
26
27
  type EstablishedSandboxSession,
27
28
  type NatsRequestConnection,
28
29
  type RoutableBackendSession,
29
30
  type RoutableSandbox,
31
+ type SelfhostedOpObserver,
30
32
  type SelfhostedRelayConfig,
33
+ type OpStreamJournal,
34
+ type SelfhostedOpStreamDeps,
31
35
  } from "@opengeni/runtime";
32
36
 
33
37
  export type RoutingWiringServices = {
@@ -37,6 +41,14 @@ export type RoutingWiringServices = {
37
41
  * Optional: when absent (or NATS unconfigured) a selfhosted swap target
38
42
  * surfaces agent_offline on its first op rather than failing to build. */
39
43
  bus?: EventBus;
44
+ /** The per-op observer wired into every selfhosted session this turn builds
45
+ * (out-of-band telemetry — op metrics + machine.* events). Absent ⇒ no-op. */
46
+ onOp?: SelfhostedOpObserver;
47
+ /** The op-stream durable-resume journal (the Temporal adaptation from
48
+ * op-journal.ts): attach generation + settled-frontier persistence. Absent ⇒
49
+ * the runtime defaults (generation "1", no persistence) — tests / non-turn
50
+ * callers. Only consulted when op-stream is actually enabled for the turn. */
51
+ opJournal?: OpStreamJournal;
40
52
  };
41
53
 
42
54
  export type RoutingWiringIds = {
@@ -63,6 +75,16 @@ export type RoutingWiringIds = {
63
75
  * swap target is built fresh).
64
76
  */
65
77
  pinnedSelfhosted?: { sandboxId: string; epoch: number };
78
+ /**
79
+ * Whether the turn's `defaultBackend` IS the session's home (so the null pointer may
80
+ * resolve to it). Defaults to TRUE (omitted). Set explicitly FALSE on a machine-primary
81
+ * turn of a Modal-HOME session (pinned to a machine, no Modal group box established this
82
+ * turn): the routing resolver's null branch then throws a typed `home_unavailable_this_turn`
83
+ * error on a mid-turn clear-to-null instead of silently serving the pinned machine — the
84
+ * detach's pointer commit stands and takes effect next turn. A genuine machine-HOME turn
85
+ * (home IS the machine) passes true.
86
+ */
87
+ defaultIsHome?: boolean;
66
88
  };
67
89
 
68
90
  /** Map the deployment relay URL to the leaf's `SelfhostedRelayConfig` shape
@@ -83,6 +105,30 @@ export function relayConfigFromSettings(settings: Settings): SelfhostedRelayConf
83
105
  }
84
106
  }
85
107
 
108
+ /** The selfhosted CONTROL vs EXEC op deadlines for a turn, from settings. Control
109
+ * ops (ping/fs/desktop/pty) stay on the short timeout so machine liveness is never
110
+ * masked by a slow op; exec gets its own much larger budget so a real command is not
111
+ * killed at the control wall. Threaded into every turn-path session build + resolver. */
112
+ export function selfhostedTimeoutsFromSettings(settings: Settings): {
113
+ timeoutMs: number;
114
+ execTimeoutMs: number;
115
+ } {
116
+ return {
117
+ timeoutMs: settings.sandboxSelfhostedControlTimeoutMs,
118
+ execTimeoutMs: settings.sandboxSelfhostedExecTimeoutMs,
119
+ };
120
+ }
121
+
122
+ /** The same split deadlines shaped for `makeActiveBackendResolver`'s dep names
123
+ * (`selfhostedTimeoutMs` / `selfhostedExecTimeoutMs`), for a swap/pin target. */
124
+ function selfhostedResolverTimeouts(settings: Settings): {
125
+ selfhostedTimeoutMs: number;
126
+ selfhostedExecTimeoutMs: number;
127
+ } {
128
+ const { timeoutMs, execTimeoutMs } = selfhostedTimeoutsFromSettings(settings);
129
+ return { selfhostedTimeoutMs: timeoutMs, selfhostedExecTimeoutMs: execTimeoutMs };
130
+ }
131
+
86
132
  /** Build the selfhosted `ControlRpc` over the events bus's request/reply
87
133
  * connection. A null bus / unconfigured NATS yields a NatsControlRpc whose
88
134
  * connection factory returns null → agent_offline on every op (never a throw). */
@@ -113,7 +159,7 @@ export function wrapTurnBoxWithRouting(
113
159
  ids: RoutingWiringIds,
114
160
  established: EstablishedSandboxSession,
115
161
  ): EstablishedSandboxSession {
116
- const { db, settings, bus } = services;
162
+ const { db, settings, bus, onOp } = services;
117
163
  const resolver = makeActiveBackendResolver({
118
164
  workspaceId: ids.workspaceId,
119
165
  defaultBackend: established.session as RoutableBackendSession,
@@ -121,11 +167,20 @@ export function wrapTurnBoxWithRouting(
121
167
  getSandbox: async (sandboxId): Promise<RoutableSandbox | null> => {
122
168
  const sandbox = await getSandbox(db, ids.workspaceId, sandboxId);
123
169
  return sandbox
124
- ? { id: sandbox.id, kind: sandbox.kind, name: sandbox.name, enrollmentId: sandbox.enrollmentId }
170
+ ? {
171
+ id: sandbox.id,
172
+ kind: sandbox.kind,
173
+ name: sandbox.name,
174
+ enrollmentId: sandbox.enrollmentId,
175
+ }
125
176
  : null;
126
177
  },
127
178
  controlRpcFactory: controlRpcFactory(bus),
128
179
  relay: relayConfigFromSettings(settings),
180
+ // A selfhosted swap target runs real commands too, so give it the same split
181
+ // deadlines the machine-primary establish path uses (short control, long exec).
182
+ ...selfhostedResolverTimeouts(settings),
183
+ ...(onOp !== undefined ? { selfhostedOnOp: onOp } : {}),
129
184
  // The turn's declared environment → a selfhosted swap target's manifest, so the
130
185
  // SDK's per-turn manifest-env delta is empty (no "cannot change manifest
131
186
  // environment variables" throw when the turn pins to a vm). Mirrors the group
@@ -137,18 +192,24 @@ export function wrapTurnBoxWithRouting(
137
192
  // bound to (sandboxId, epoch).
138
193
  ...(ids.pinnedSelfhosted
139
194
  ? {
140
- pinnedSelfhosted: {
141
- sandboxId: ids.pinnedSelfhosted.sandboxId,
142
- epoch: ids.pinnedSelfhosted.epoch,
143
- session: established.session as RoutableBackendSession,
144
- },
145
- }
195
+ pinnedSelfhosted: {
196
+ sandboxId: ids.pinnedSelfhosted.sandboxId,
197
+ epoch: ids.pinnedSelfhosted.epoch,
198
+ session: established.session as RoutableBackendSession,
199
+ },
200
+ }
146
201
  : {}),
147
202
  // A modal swap target in the turn path would need its own lease resume-by-id;
148
203
  // that is a future cross-group-box concern. Until then a modal swap target is
149
204
  // unresolvable (the swap tool validates liveness, so this only triggers if a
150
205
  // session points at a sibling modal box the turn cannot resume here) and the
151
206
  // op surfaces unresolvable — never a silent wrong-box landing.
207
+ //
208
+ // For a machine-primary turn of a Modal-HOME session (pinned to a machine, no
209
+ // group box established this turn), a mid-turn clear-to-null must NOT fall back to
210
+ // the pinned machine — passing defaultIsHome:false makes the null branch throw typed
211
+ // `home_unavailable_this_turn` instead. Forward the explicit boolean (including false).
212
+ ...(ids.defaultIsHome !== undefined ? { defaultIsHome: ids.defaultIsHome } : {}),
152
213
  });
153
214
 
154
215
  const proxy = new RoutingSandboxSession({
@@ -173,6 +234,97 @@ export function wrapTurnBoxWithRouting(
173
234
  return { ...established, session: proxy };
174
235
  }
175
236
 
237
+ export function wrapLazyTurnBoxWithRouting(
238
+ services: RoutingWiringServices,
239
+ ids: RoutingWiringIds,
240
+ args: {
241
+ client: EstablishedSandboxSession["client"];
242
+ backendId: string;
243
+ agentDefaultManifest: unknown;
244
+ provisioner: { get(): Promise<{ established: EstablishedSandboxSession }> };
245
+ },
246
+ ): EstablishedSandboxSession {
247
+ const { db, settings, bus, onOp } = services;
248
+ const syntheticSession: RoutableBackendSession = {
249
+ state: { manifest: args.agentDefaultManifest },
250
+ };
251
+ const routedResolver = makeActiveBackendResolver({
252
+ workspaceId: ids.workspaceId,
253
+ defaultBackend: syntheticSession,
254
+ defaultKind: "unprovisioned",
255
+ getSandbox: async (sandboxId): Promise<RoutableSandbox | null> => {
256
+ const sandbox = await getSandbox(db, ids.workspaceId, sandboxId);
257
+ return sandbox
258
+ ? {
259
+ id: sandbox.id,
260
+ kind: sandbox.kind,
261
+ name: sandbox.name,
262
+ enrollmentId: sandbox.enrollmentId,
263
+ }
264
+ : null;
265
+ },
266
+ controlRpcFactory: controlRpcFactory(bus),
267
+ relay: relayConfigFromSettings(settings),
268
+ ...selfhostedResolverTimeouts(settings),
269
+ ...(onOp !== undefined ? { selfhostedOnOp: onOp } : {}),
270
+ ...(ids.environment !== undefined ? { environment: ids.environment } : {}),
271
+ });
272
+
273
+ const proxy = new RoutingSandboxSession({
274
+ // Before the first op the SDK reads `state.manifest`; the synthetic backend
275
+ // points at agent.defaultManifest BY REFERENCE so the provided-session delta is
276
+ // empty. The first default-pointer op resolves the real box through the
277
+ // provisioner and `state` switches to that real backend by reference.
278
+ defaultResolved: {
279
+ session: syntheticSession,
280
+ sandboxId: null,
281
+ kind: "unprovisioned",
282
+ },
283
+ readPointer: async () => {
284
+ const pointer = await readActiveSandbox(db, ids.workspaceId, ids.sessionId);
285
+ return pointer ?? { activeSandboxId: null, activeEpoch: 0 };
286
+ },
287
+ resolveActiveBackend: async (pointer) => {
288
+ if (pointer.activeSandboxId === null || !routingEnabled(settings)) {
289
+ const provisioned = await args.provisioner.get();
290
+ return {
291
+ session: provisioned.established.session as RoutableBackendSession,
292
+ sandboxId: null,
293
+ kind: provisioned.established.backendId,
294
+ };
295
+ }
296
+ return routedResolver(pointer);
297
+ },
298
+ });
299
+
300
+ return {
301
+ client: args.client,
302
+ session: proxy,
303
+ sessionState: undefined,
304
+ instanceId: "unprovisioned",
305
+ backendId: args.backendId,
306
+ };
307
+ }
308
+
309
+ export type SelfhostedTurnSessionArgs = {
310
+ workspaceId: string;
311
+ /** The target machine's enrollment id == the agent subject id. */
312
+ agentId: string;
313
+ /** Whether the target machine advertised Capabilities.op_stream in its latest
314
+ * Hello. The runtime-side transport gate must still require the server flag. */
315
+ opStream: boolean;
316
+ /** The active pointer's epoch — the control-op fence echoed to the agent. */
317
+ epoch: number;
318
+ /** The run's declared sandbox environment (the SAME object fed to buildAgent +
319
+ * the manifest), threaded so the SDK's per-turn provided-session env delta is
320
+ * empty. */
321
+ environment: Record<string, string>;
322
+ /** The session working directory (per-session pointer). Null ⇒ workspace_root. */
323
+ workingDir: string | null;
324
+ };
325
+
326
+ type LegacySelfhostedTurnSessionArgs = Omit<SelfhostedTurnSessionArgs, "opStream">;
327
+
176
328
  /**
177
329
  * Stage D machine-primary establish: bind the live SelfhostedSession for a turn
178
330
  * whose ACTIVE sandbox is a connected machine — WITHOUT establishing or leasing a
@@ -188,23 +340,37 @@ export function wrapTurnBoxWithRouting(
188
340
  * No NATS round-trip happens here — `resume()` just re-addresses the subject — so a
189
341
  * headless/offline machine binds fine; its ops surface agent_offline lazily.
190
342
  */
343
+ /**
344
+ * The op-stream injection for a machine-primary turn: present iff the machine
345
+ * advertised `Capabilities.op_stream` in its latest Hello AND the server flag
346
+ * is on AND a bus exists to carry frames. The transport rides the SAME managed
347
+ * NATS connection as the control rpc (the bus's op-stream accessor); a bus
348
+ * without the accessor (a test double) simply yields no connection and the
349
+ * session falls back to the legacy exec on first use. Swap TARGETS resolved
350
+ * mid-turn stay legacy for now — their capability row is not at hand in the
351
+ * resolver, and legacy is always correct.
352
+ */
353
+ function opStreamDepsFor(
354
+ services: RoutingWiringServices,
355
+ machineAdvertisesOpStream: boolean,
356
+ ): SelfhostedOpStreamDeps | undefined {
357
+ const { settings, bus, opJournal } = services;
358
+ if (!machineAdvertisesOpStream || settings.agentOpStreamEnabled !== true || !bus) {
359
+ return undefined;
360
+ }
361
+ return {
362
+ transport: new NatsOpStreamTransport(async () => bus.getOpStreamConnection?.() ?? null),
363
+ ...(opJournal !== undefined ? { journal: opJournal } : {}),
364
+ };
365
+ }
366
+
191
367
  export async function establishSelfhostedTurnSession(
192
368
  services: RoutingWiringServices,
193
- args: {
194
- workspaceId: string;
195
- /** The target machine's enrollment id == the agent subject id. */
196
- agentId: string;
197
- /** The active pointer's epoch — the control-op fence echoed to the agent. */
198
- epoch: number;
199
- /** The run's declared sandbox environment (the SAME object fed to buildAgent +
200
- * the manifest), threaded so the SDK's per-turn provided-session env delta is
201
- * empty. */
202
- environment: Record<string, string>;
203
- /** The session working directory (per-session pointer). Null ⇒ workspace_root. */
204
- workingDir: string | null;
205
- },
369
+ args: SelfhostedTurnSessionArgs | LegacySelfhostedTurnSessionArgs,
206
370
  ): Promise<EstablishedSandboxSession> {
207
- const { settings, bus } = services;
371
+ const { settings, bus, onOp } = services;
372
+ const { timeoutMs, execTimeoutMs } = selfhostedTimeoutsFromSettings(settings);
373
+ const opStream = opStreamDepsFor(services, "opStream" in args && args.opStream === true);
208
374
  const { client, session } = await buildSelfhostedBackendSession({
209
375
  workspaceId: args.workspaceId,
210
376
  agentId: args.agentId,
@@ -213,6 +379,16 @@ export async function establishSelfhostedTurnSession(
213
379
  epoch: args.epoch,
214
380
  environment: args.environment,
215
381
  workingDir: args.workingDir,
382
+ // Give this turn's exec ops the long deadline (control ops stay short) so a real
383
+ // command is not killed at the control wall.
384
+ timeoutMs,
385
+ execTimeoutMs,
386
+ // Meter every control op (out-of-band telemetry) — no-op when unwired.
387
+ ...(onOp !== undefined ? { onOp } : {}),
388
+ // The streaming exec transport — present iff the machine advertised the
389
+ // capability AND the server flag is on (latched per-op at OpStart; the
390
+ // legacy exec stays the permanent fallback wire form).
391
+ ...(opStream !== undefined ? { opStream } : {}),
216
392
  });
217
393
  return {
218
394
  client,
@@ -230,3 +406,14 @@ export async function establishSelfhostedTurnSession(
230
406
  export function routingEnabled(settings: Settings): boolean {
231
407
  return settings.sandboxSelfhostedEnabled === true;
232
408
  }
409
+
410
+ /** Whether the turn should defer sandbox provisioning to the first dispatched op
411
+ * (the in-process single-flight provisioner behind the routing proxy's
412
+ * resolveActiveBackend). Lazy is a property of the OWNED path only — the SDK never
413
+ * creates/resumes an injected session, so we own establish timing — hence gated on
414
+ * BOTH flags. With either off the turn provisions eagerly at turn start, exactly as
415
+ * today. NB: under lazy the box is ALWAYS wrapped in the routing proxy (the proxy's
416
+ * resolver IS the establish seam), independent of `routingEnabled`. */
417
+ export function lazyProvisionEnabled(settings: Settings): boolean {
418
+ return settings.sandboxLazyProvisionEnabled === true && settings.sandboxOwnershipEnabled === true;
419
+ }
@@ -0,0 +1,5 @@
1
+ export const SESSION_WORKFLOW_WAKE_DISPATCHER_SCHEDULE_ID =
2
+ "opengeni-session-workflow-wake-dispatcher";
3
+ export const SESSION_WORKFLOW_WAKE_DISPATCHER_WORKFLOW_TYPE =
4
+ "sessionWorkflowWakeDispatcherWorkflow";
5
+ export const SESSION_WORKFLOW_WAKE_DISPATCHER_PERIOD_MS = 10_000;
@@ -1,15 +1,66 @@
1
1
  import { proxyActivities } from "@temporalio/workflow";
2
2
  import type * as activities from "../activities";
3
3
 
4
- export const activity = proxyActivities<typeof activities>({
5
- // Agent segments legitimately run for days (goal-bearing infrastructure
6
- // sessions). Dead workers are detected by the heartbeat, not this timeout,
7
- // so it is deliberately generous rather than a pacing bound.
8
- startToCloseTimeout: "30 days",
9
- heartbeatTimeout: "30 seconds",
10
- retry: { maximumAttempts: 1 },
4
+ type WorkflowControlActivities = Pick<
5
+ typeof activities,
6
+ | "dispatchScheduledTaskRun"
7
+ | "enqueueGoalRetryWake"
8
+ | "failSessionAttempt"
9
+ | "getCodexCapacityWait"
10
+ | "markSessionIdle"
11
+ | "peekSessionWork"
12
+ | "reconcileCodexCapacityWait"
13
+ | "recoverDispatch"
14
+ | "settleSessionControl"
15
+ >;
16
+
17
+ /**
18
+ * Session/schedule workflow control activities are bounded, idempotent database
19
+ * and provider-metadata operations. They must not inherit the agent turn's
20
+ * 30-day attempt: Temporal cannot otherwise detect that the pod which accepted
21
+ * a non-heartbeating control activity disappeared, leaving the workflow pinned
22
+ * to a dead worker for the full 30 days. A bounded attempt plus an unbounded
23
+ * Temporal retry keeps the durable workflow alive across rollout, node loss, or
24
+ * transient database/network failure; retries re-run on a healthy control pod.
25
+ */
26
+ export const activity = proxyActivities<WorkflowControlActivities>({
27
+ startToCloseTimeout: "2 minutes",
28
+ retry: {
29
+ initialInterval: "1 second",
30
+ backoffCoefficient: 2,
31
+ maximumInterval: "30 seconds",
32
+ },
33
+ });
34
+
35
+ /** Goal continuation is advisory at an idle boundary. A transient failure gets
36
+ * a short retry window, then records an explicit delayed outbox wake instead
37
+ * of relying on an unrelated future mutation. */
38
+ export const goalActivity = proxyActivities<Pick<typeof activities, "maybeContinueGoal">>({
39
+ startToCloseTimeout: "30 seconds",
40
+ retry: {
41
+ initialInterval: "1 second",
42
+ backoffCoefficient: 2,
43
+ maximumInterval: "5 seconds",
44
+ maximumAttempts: 3,
45
+ },
11
46
  });
12
47
 
48
+ export function turnTaskQueue(baseTaskQueue: string): string {
49
+ return `${baseTaskQueue}-turns`;
50
+ }
51
+
52
+ export function turnActivityForTaskQueue(baseTaskQueue: string) {
53
+ return proxyActivities<Pick<typeof activities, "runAgentTurn">>({
54
+ taskQueue: turnTaskQueue(baseTaskQueue),
55
+ // Agent segments legitimately run for days. A started turn heartbeats;
56
+ // queued activities remain queued truthfully until a capped turn worker
57
+ // accepts them and performs the atomic claim.
58
+ startToCloseTimeout: "30 days",
59
+ heartbeatTimeout: "2 minutes",
60
+ retry: { maximumAttempts: 1 },
61
+ });
62
+ }
63
+
13
64
  export const documentActivity = proxyActivities<Pick<typeof activities, "indexDocument">>({
14
65
  startToCloseTimeout: "30 minutes",
15
66
  retry: { maximumAttempts: 1 },
@@ -0,0 +1,12 @@
1
+ import { proxyActivities } from "@temporalio/workflow";
2
+ import type * as activities from "../activities";
3
+
4
+ const reaperActivity = proxyActivities<Pick<typeof activities, "reapExpiredFileUploads">>({
5
+ startToCloseTimeout: "5 minutes",
6
+ retry: { maximumAttempts: 1 },
7
+ });
8
+
9
+ /** One bounded provider/DB sweep; the Temporal Schedule owns the cadence. */
10
+ export async function fileUploadReaperWorkflow(): Promise<void> {
11
+ await reaperActivity.reapExpiredFileUploads();
12
+ }
@@ -0,0 +1,28 @@
1
+ import { proxyActivities } from "@temporalio/workflow";
2
+ import type * as activities from "../activities";
3
+ import type { RigVerificationWorkflowInput } from "../activities/rig-verification";
4
+
5
+ const rigVerificationActivities = proxyActivities<
6
+ Pick<typeof activities, "verifyRigChange" | "verifyRigVersion">
7
+ >({
8
+ startToCloseTimeout: "15 minutes",
9
+ retry: { maximumAttempts: 1 },
10
+ });
11
+
12
+ export type { RigVerificationWorkflowInput };
13
+
14
+ export async function rigVerificationWorkflow(input: RigVerificationWorkflowInput): Promise<void> {
15
+ if (input.changeId) {
16
+ await rigVerificationActivities.verifyRigChange({
17
+ workspaceId: input.workspaceId,
18
+ changeId: input.changeId,
19
+ });
20
+ return;
21
+ }
22
+ if (input.versionId) {
23
+ await rigVerificationActivities.verifyRigVersion({
24
+ workspaceId: input.workspaceId,
25
+ versionId: input.versionId,
26
+ });
27
+ }
28
+ }
@@ -1,6 +1,5 @@
1
- import { getExternalWorkflowHandle, ParentClosePolicy, startChild } from "@temporalio/workflow";
1
+ import { workflowInfo } from "@temporalio/workflow";
2
2
  import { activity } from "./activities";
3
- import { queueChanged } from "./session";
4
3
 
5
4
  export type ScheduledTaskFireWorkflowInput = {
6
5
  accountId: string;
@@ -10,29 +9,16 @@ export type ScheduledTaskFireWorkflowInput = {
10
9
  agentRunUsageIdempotencyKey?: string;
11
10
  };
12
11
 
13
- export async function scheduledTaskFireWorkflow(input: ScheduledTaskFireWorkflowInput): Promise<void> {
14
- const dispatched = await activity.dispatchScheduledTaskRun({
15
- workspaceId: input.workspaceId,
16
- taskId: input.taskId,
17
- triggerType: input.triggerType,
18
- ...(input.agentRunUsageIdempotencyKey ? { agentRunUsageIdempotencyKey: input.agentRunUsageIdempotencyKey } : {}),
19
- });
20
- if (dispatched.action === "start") {
21
- await startSessionChild(dispatched.accountId, dispatched.workspaceId, dispatched.sessionId, dispatched.workflowId);
22
- return;
23
- }
24
- try {
25
- await getExternalWorkflowHandle(dispatched.workflowId).signal(queueChanged);
26
- } catch {
27
- await startSessionChild(dispatched.accountId, dispatched.workspaceId, dispatched.sessionId, dispatched.workflowId);
28
- }
29
- }
30
-
31
- async function startSessionChild(accountId: string, workspaceId: string, sessionId: string, workflowId: string): Promise<void> {
32
- await startChild("sessionWorkflow", {
33
- workflowId,
34
- parentClosePolicy: ParentClosePolicy.ABANDON,
35
- workflowIdReusePolicy: "ALLOW_DUPLICATE",
36
- args: [{ accountId, workspaceId, sessionId }],
12
+ export async function scheduledTaskFireWorkflow(
13
+ input: ScheduledTaskFireWorkflowInput,
14
+ ): Promise<void> {
15
+ await activity.dispatchScheduledTaskRun({
16
+ workspaceId: input.workspaceId,
17
+ taskId: input.taskId,
18
+ triggerType: input.triggerType,
19
+ producerKey: workflowInfo().workflowId,
20
+ ...(input.agentRunUsageIdempotencyKey
21
+ ? { agentRunUsageIdempotencyKey: input.agentRunUsageIdempotencyKey }
22
+ : {}),
37
23
  });
38
24
  }