@opengeni/worker-bundle 0.2.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.
- package/dist/index.d.ts +222 -0
- package/dist/index.js +3960 -0
- package/dist/index.js.map +1 -0
- package/package.json +60 -0
- package/src/activities/agent-turn.ts +2290 -0
- package/src/activities/capabilities.ts +131 -0
- package/src/activities/codex-auth.ts +9 -0
- package/src/activities/codex-rotation.ts +326 -0
- package/src/activities/common.ts +37 -0
- package/src/activities/context-compaction.ts +125 -0
- package/src/activities/documents.ts +67 -0
- package/src/activities/environment.ts +209 -0
- package/src/activities/goals.ts +281 -0
- package/src/activities/packs.ts +116 -0
- package/src/activities/parent-wake.ts +129 -0
- package/src/activities/recording.ts +248 -0
- package/src/activities/redaction.ts +54 -0
- package/src/activities/run-input.ts +331 -0
- package/src/activities/sandbox-lease.ts +612 -0
- package/src/activities/scheduled-tasks.ts +346 -0
- package/src/activities/session-state.ts +201 -0
- package/src/activities/streaming.ts +74 -0
- package/src/activities/types.ts +165 -0
- package/src/activities.ts +124 -0
- package/src/index.ts +184 -0
- package/src/sandbox-resume.ts +558 -0
- package/src/sandbox-routing.ts +232 -0
- package/src/workflows/activities.ts +23 -0
- package/src/workflows/document-index.ts +11 -0
- package/src/workflows/sandbox-reaper.ts +28 -0
- package/src/workflows/scheduled-tasks.ts +38 -0
- package/src/workflows/session.ts +376 -0
- package/src/workflows.ts +19 -0
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
import { ActivityFailure, CancellationScope, condition, continueAsNew, defineSignal, isCancellation, patched, setHandler, TimeoutFailure, workflowInfo } from "@temporalio/workflow";
|
|
2
|
+
import type * as activities from "../activities";
|
|
3
|
+
import { activity, workflowFailureMessage } from "./activities";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Deterministic backstop for continueAsNew. A session workflow is long-lived
|
|
7
|
+
* by design (weeks-long manager goals), so its Temporal EVENT HISTORY grows
|
|
8
|
+
* without bound — every signal, activity schedule/complete and timer adds
|
|
9
|
+
* events, and the server force-terminates a run at its hard history limit
|
|
10
|
+
* (~51,200 events / 50MB), killing the session. The server's
|
|
11
|
+
* `continueAsNewSuggested` flag is the primary trigger (it fires well before
|
|
12
|
+
* the hard cap), but a turn-counter backstop guarantees a continueAsNew even
|
|
13
|
+
* if the suggestion never arrives (e.g. a deployment that never raises it).
|
|
14
|
+
* Conservatively low relative to the event budget: a single turn schedules a
|
|
15
|
+
* handful of history events, so a few thousand turns stays far under the cap
|
|
16
|
+
* while keeping continueAsNew rare enough that it is not a per-turn cost.
|
|
17
|
+
*/
|
|
18
|
+
const TURNS_PER_RUN_BACKSTOP = 2_000;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The minimum hold for a rotation all-capped idle (`idleUntilReset`). A MANDATORY
|
|
22
|
+
* floor so that even a 0/elapsed continueDelayMs (a stale/unknown reset) can never
|
|
23
|
+
* collapse the hold into a tight re-dispatch loop that hammers CPU/DB and never runs
|
|
24
|
+
* the model (invariant 4: NO THRASH). Mirrors MIN_IDLE_MS in codex-rotation.ts; kept
|
|
25
|
+
* local so the deterministic workflow bundle does not import the activities module.
|
|
26
|
+
*/
|
|
27
|
+
const ROTATION_IDLE_FLOOR_MS = 60_000; // 60s
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* How long the continuation loop must hold before re-admitting the next turn. 0 ⇒ no
|
|
31
|
+
* hold (re-dispatch immediately — a rotation candidate is ready, or no idle delay was
|
|
32
|
+
* requested). A rotation all-capped idle (`idleUntilReset`) ALWAYS holds at least
|
|
33
|
+
* `floorMs`, so a 0/elapsed continueDelayMs can never skip the hold (invariant 4).
|
|
34
|
+
* Pure + exported so the boundedness contract is unit-testable without a workflow env.
|
|
35
|
+
*/
|
|
36
|
+
export function continuationHoldMs(
|
|
37
|
+
result: { status: string; continueDelayMs?: number; idleUntilReset?: boolean },
|
|
38
|
+
floorMs: number,
|
|
39
|
+
): number {
|
|
40
|
+
if (result.status !== "idle") {
|
|
41
|
+
return 0;
|
|
42
|
+
}
|
|
43
|
+
const delay = result.continueDelayMs ?? 0;
|
|
44
|
+
if (result.idleUntilReset) {
|
|
45
|
+
return Math.max(delay, floorMs);
|
|
46
|
+
}
|
|
47
|
+
return Math.max(delay, 0);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* True when an agent-turn activity failure means "the worker hosting the
|
|
52
|
+
* turn died or vanished" rather than "the turn itself failed": the server
|
|
53
|
+
* closed the activity with a HEARTBEAT timeout (the worker was killed before
|
|
54
|
+
* the graceful-preempt checkpoint could run — SIGKILL, OOM, node loss, or a
|
|
55
|
+
* rollout whose grace period expired) or a SCHEDULE_TO_START timeout (no
|
|
56
|
+
* worker ever picked the task up). Detection uses the SDK's typed failure
|
|
57
|
+
* classes, not message-string matching: the failure converter rehydrates
|
|
58
|
+
* ActivityFailure/TimeoutFailure instances deterministically from recorded
|
|
59
|
+
* history on replay, so instanceof + timeoutType checks are replay-safe and
|
|
60
|
+
* do not depend on server-controlled message text. START_TO_CLOSE /
|
|
61
|
+
* SCHEDULE_TO_CLOSE timeouts are deliberately excluded: with the 30-day
|
|
62
|
+
* startToClose they mean the turn truly overran, which stays a real failure.
|
|
63
|
+
*/
|
|
64
|
+
function isWorkerDeathFailure(error: unknown): boolean {
|
|
65
|
+
if (!(error instanceof ActivityFailure)) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
const cause = error.cause;
|
|
69
|
+
return cause instanceof TimeoutFailure
|
|
70
|
+
&& (cause.timeoutType === "HEARTBEAT" || cause.timeoutType === "SCHEDULE_TO_START");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export const userMessage = defineSignal<[string]>("userMessage");
|
|
74
|
+
export const queueChanged = defineSignal("queueChanged");
|
|
75
|
+
export const approvalDecision = defineSignal<[string]>("approvalDecision");
|
|
76
|
+
export const interrupt = defineSignal<[string]>("interrupt");
|
|
77
|
+
|
|
78
|
+
export type SessionWorkflowInput = {
|
|
79
|
+
accountId: string;
|
|
80
|
+
workspaceId: string;
|
|
81
|
+
sessionId: string;
|
|
82
|
+
initialEventId?: string;
|
|
83
|
+
// Per-run continueAsNew backstop, propagated across continueAsNew. Production
|
|
84
|
+
// omits it (defaults to TURNS_PER_RUN_BACKSTOP); tests set it low to exercise
|
|
85
|
+
// the boundary without simulating thousands of turns. Never gates correctness
|
|
86
|
+
// — continueAsNewSuggested is the real-world trigger.
|
|
87
|
+
maxTurnsPerRun?: number;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export async function sessionWorkflow(input: SessionWorkflowInput): Promise<void> {
|
|
91
|
+
const approvalQueue: string[] = [];
|
|
92
|
+
let interruptedEventId: string | null = null;
|
|
93
|
+
let wakeups = 0;
|
|
94
|
+
// Turns dispatched on THIS run (reset to 0 by continueAsNew). The backstop
|
|
95
|
+
// for the history-overflow guard below; bounded growth is what makes a
|
|
96
|
+
// weeks-long session survivable.
|
|
97
|
+
let turnsThisRun = 0;
|
|
98
|
+
|
|
99
|
+
setHandler(userMessage, () => {
|
|
100
|
+
wakeups += 1;
|
|
101
|
+
});
|
|
102
|
+
setHandler(queueChanged, () => {
|
|
103
|
+
wakeups += 1;
|
|
104
|
+
});
|
|
105
|
+
setHandler(approvalDecision, (eventId) => {
|
|
106
|
+
approvalQueue.push(eventId);
|
|
107
|
+
});
|
|
108
|
+
setHandler(interrupt, (eventId) => {
|
|
109
|
+
interruptedEventId = eventId;
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
while (true) {
|
|
113
|
+
// History-overflow guard. The top of the loop is the only safe
|
|
114
|
+
// continueAsNew boundary: no turn is mid-flight (every path that reaches a
|
|
115
|
+
// new iteration completed or re-queued its turn first), and a pending
|
|
116
|
+
// interrupt is unbacked in-memory state that the new run could not
|
|
117
|
+
// reconstruct — so we refuse to continueAsNew while one is set and let the
|
|
118
|
+
// loop handle it first. A buffered userMessage/queueChanged signal only
|
|
119
|
+
// bumps `wakeups`, and its turn was written to Postgres BEFORE the signal
|
|
120
|
+
// was sent, so the fresh run re-claims it on its first claimNextQueuedTurn
|
|
121
|
+
// — losing the counter strands nothing. The queue living in Postgres is the
|
|
122
|
+
// safety net: continueAsNew carries only the self-contained
|
|
123
|
+
// SessionWorkflowInput (no initialEventId — the new run claims from the
|
|
124
|
+
// queue, it does not replay a seed event). patched() keeps in-flight
|
|
125
|
+
// histories (recorded before this branch existed) deterministic: they never
|
|
126
|
+
// see the new command.
|
|
127
|
+
//
|
|
128
|
+
// The approval queue is NOT a boundary condition, and is cleared here. A
|
|
129
|
+
// genuinely-pending approval keeps the workflow blocked INSIDE runTurn (the
|
|
130
|
+
// `await condition(...)` in the requires_action branch), so it never
|
|
131
|
+
// reaches the top of the loop — meaning every approvalQueue entry observed
|
|
132
|
+
// here is necessarily STALE (an approvalDecision signal for a turn that
|
|
133
|
+
// already settled; the API guard only checks status==='requires_action', so
|
|
134
|
+
// two decisions submitted while requires_action both land in the queue and
|
|
135
|
+
// the surplus is left behind once the turn completes without re-blocking).
|
|
136
|
+
// Coupling continueAsNew to `approvalQueue.length === 0` would let one such
|
|
137
|
+
// stale entry wedge the guard forever, re-introducing the exact
|
|
138
|
+
// history-overflow termination this branch prevents. Dropping the surplus
|
|
139
|
+
// is safe: a real pending approval also leaves the session in
|
|
140
|
+
// requires_action with the turn re-dispatchable from Postgres.
|
|
141
|
+
if (patched("session-continue-as-new")) {
|
|
142
|
+
const info = workflowInfo();
|
|
143
|
+
const maxTurnsPerRun = input.maxTurnsPerRun ?? TURNS_PER_RUN_BACKSTOP;
|
|
144
|
+
const shouldContinue = info.continueAsNewSuggested || turnsThisRun >= maxTurnsPerRun;
|
|
145
|
+
if (shouldContinue && interruptedEventId === null) {
|
|
146
|
+
approvalQueue.length = 0;
|
|
147
|
+
await continueAsNew<typeof sessionWorkflow>({
|
|
148
|
+
accountId: input.accountId,
|
|
149
|
+
workspaceId: input.workspaceId,
|
|
150
|
+
sessionId: input.sessionId,
|
|
151
|
+
...(input.maxTurnsPerRun !== undefined ? { maxTurnsPerRun: input.maxTurnsPerRun } : {}),
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const workflowId = workflowInfo().workflowId;
|
|
156
|
+
const turn = await activity.claimNextQueuedTurn({ workspaceId: input.workspaceId, sessionId: input.sessionId, workflowId });
|
|
157
|
+
if (!turn) {
|
|
158
|
+
if (interruptedEventId === null) {
|
|
159
|
+
// With an active goal, idling out is replaced by a synthesized
|
|
160
|
+
// continuation turn; the queue (any non-terminal turn) always wins and
|
|
161
|
+
// the no-progress/max-continuation guards auto-pause runaway goals.
|
|
162
|
+
let continuation: activities.MaybeContinueGoalResult = { action: "none" };
|
|
163
|
+
try {
|
|
164
|
+
continuation = await activity.maybeContinueGoal({
|
|
165
|
+
accountId: input.accountId,
|
|
166
|
+
workspaceId: input.workspaceId,
|
|
167
|
+
sessionId: input.sessionId,
|
|
168
|
+
workflowId,
|
|
169
|
+
});
|
|
170
|
+
} catch (error) {
|
|
171
|
+
if (isCancellation(error)) {
|
|
172
|
+
throw error;
|
|
173
|
+
}
|
|
174
|
+
// A failing goal check must not kill the session (activity retry is
|
|
175
|
+
// 1). Fall through to the idle path: the goal stays active in the
|
|
176
|
+
// database and the next wake retries, which means the workflow CAN
|
|
177
|
+
// complete normally with an active goal on this error path.
|
|
178
|
+
}
|
|
179
|
+
if (continuation.action === "continue" || continuation.action === "queue") {
|
|
180
|
+
// "continue": a goal continuation turn was just enqueued; "queue":
|
|
181
|
+
// queued work appeared concurrently. Claim it on the next loop pass.
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
const seenWakeups = wakeups;
|
|
186
|
+
const woke = await condition(() => interruptedEventId !== null || wakeups !== seenWakeups, "5s");
|
|
187
|
+
if (interruptedEventId) {
|
|
188
|
+
const idleInterruptEventId = interruptedEventId;
|
|
189
|
+
interruptedEventId = null;
|
|
190
|
+
// An idle interrupt is an explicit stop: pause an active goal before
|
|
191
|
+
// shutting down so a later wake does not auto-continue it. The
|
|
192
|
+
// activity inspects the trigger and skips the pause for steer-tagged
|
|
193
|
+
// interrupts (steering redirects work, it does not stop it).
|
|
194
|
+
await activity.pauseGoalForInterrupt({ workspaceId: input.workspaceId, sessionId: input.sessionId, triggerEventId: idleInterruptEventId });
|
|
195
|
+
await activity.markSessionIdle({ workspaceId: input.workspaceId, sessionId: input.sessionId });
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (woke) {
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
const finalTurn = await activity.claimNextQueuedTurn({ workspaceId: input.workspaceId, sessionId: input.sessionId, workflowId });
|
|
202
|
+
if (!finalTurn) {
|
|
203
|
+
await activity.markSessionIdle({ workspaceId: input.workspaceId, sessionId: input.sessionId });
|
|
204
|
+
// A queueChanged/userMessage signal can land between the final claim and
|
|
205
|
+
// completion; Temporal blocks completion while a signal is buffered, so
|
|
206
|
+
// re-checking here guarantees the queued turn is picked up instead of
|
|
207
|
+
// stranding it (the signaler skips its start-child fallback on success).
|
|
208
|
+
if (interruptedEventId !== null || wakeups !== seenWakeups) {
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
turnsThisRun += 1;
|
|
214
|
+
if (!await runTurn(input.accountId, input.workspaceId, input.sessionId, finalTurn.id, finalTurn.triggerEventId)) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
turnsThisRun += 1;
|
|
220
|
+
if (!await runTurn(input.accountId, input.workspaceId, input.sessionId, turn.id, turn.triggerEventId)) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
async function runTurn(accountId: string, workspaceId: string, sessionId: string, turnId: string, triggerEventId: string): Promise<boolean> {
|
|
226
|
+
if (interruptedEventId) {
|
|
227
|
+
await activity.interruptActiveTurn({
|
|
228
|
+
accountId,
|
|
229
|
+
workspaceId,
|
|
230
|
+
sessionId,
|
|
231
|
+
triggerEventId: interruptedEventId,
|
|
232
|
+
workflowId: workflowInfo().workflowId,
|
|
233
|
+
});
|
|
234
|
+
interruptedEventId = null;
|
|
235
|
+
return true;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const scope = new CancellationScope();
|
|
239
|
+
const workflowId = workflowInfo().workflowId;
|
|
240
|
+
// P1.2 STATELESS-LEASE GATE. The stateless resume-by-id model (lease acquire
|
|
241
|
+
// + non-owned injection + release) lives ENTIRELY in the runAgentSegment
|
|
242
|
+
// activity, gated by the sandboxOwnershipEnabled config flag — the workflow's
|
|
243
|
+
// command path is intentionally unchanged: the turn still dispatches on the
|
|
244
|
+
// EXISTING GLOBAL queue (the module-level `activity` proxy, NO taskQueue
|
|
245
|
+
// override, NO per-session worker, NO per-session queue), worker-death still
|
|
246
|
+
// re-dispatches via the `worker-death-redispatch` patch below (any worker
|
|
247
|
+
// re-resumes the box by id), and there is NO ownerHeartbeat / openStreamRequest
|
|
248
|
+
// / closeStreamRequest signal. This patched() marker records the
|
|
249
|
+
// stateless-lease cutover point in history so multi-day IN-FLIGHT workflow
|
|
250
|
+
// histories replay deterministically on the original lease-less path, and any
|
|
251
|
+
// future workflow-side lease change can branch on it without breaking replay.
|
|
252
|
+
const statelessLease = patched("sandbox-stateless-lease");
|
|
253
|
+
void statelessLease; // command path unchanged today (see comment above)
|
|
254
|
+
// Deliberately schedules the LEGACY activity name: in-flight session
|
|
255
|
+
// workflows (multi-day by design) recorded this name in their histories,
|
|
256
|
+
// and scheduling a different activity type at the same position is a
|
|
257
|
+
// non-deterministic change on replay. Migrate to runAgentTurn with
|
|
258
|
+
// patched() once pre-rename sessions have drained.
|
|
259
|
+
const turn: Promise<activities.RunAgentTurnResult> = scope.run(() => activity.runAgentSegment({
|
|
260
|
+
accountId,
|
|
261
|
+
workspaceId,
|
|
262
|
+
sessionId,
|
|
263
|
+
triggerEventId,
|
|
264
|
+
workflowId,
|
|
265
|
+
turnId,
|
|
266
|
+
}));
|
|
267
|
+
const outcome: { kind: "result"; result: activities.RunAgentTurnResult } | { kind: "interrupt" } | { kind: "failure"; error: unknown } = await Promise.race([
|
|
268
|
+
turn.then(
|
|
269
|
+
(result: activities.RunAgentTurnResult) => ({ kind: "result" as const, result }),
|
|
270
|
+
(error: unknown) => ({ kind: "failure" as const, error }),
|
|
271
|
+
),
|
|
272
|
+
condition(() => interruptedEventId !== null).then(() => ({ kind: "interrupt" as const })),
|
|
273
|
+
]);
|
|
274
|
+
|
|
275
|
+
if (outcome.kind === "interrupt") {
|
|
276
|
+
scope.cancel();
|
|
277
|
+
await activity.interruptActiveTurn({
|
|
278
|
+
accountId,
|
|
279
|
+
workspaceId,
|
|
280
|
+
sessionId,
|
|
281
|
+
triggerEventId: interruptedEventId!,
|
|
282
|
+
workflowId: workflowInfo().workflowId,
|
|
283
|
+
});
|
|
284
|
+
interruptedEventId = null;
|
|
285
|
+
return true;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
if (outcome.kind === "failure") {
|
|
289
|
+
// An ungraceful worker death never reaches the activity's graceful
|
|
290
|
+
// preemption path — it surfaces here as a heartbeat-timeout failure.
|
|
291
|
+
// Conversation truth was still dual-written during the turn, so the
|
|
292
|
+
// turn is re-queued (resume notice when it persisted progress, original
|
|
293
|
+
// trigger otherwise) and the loop re-claims it on a healthy worker —
|
|
294
|
+
// bounded by a per-turn redispatch counter persisted on the turn row.
|
|
295
|
+
// patched() keeps replays of histories recorded before this branch
|
|
296
|
+
// existed on their original failSession path.
|
|
297
|
+
if (isWorkerDeathFailure(outcome.error) && patched("worker-death-redispatch")) {
|
|
298
|
+
const requeue = await activity.requeueTurnAfterWorkerDeath({
|
|
299
|
+
accountId,
|
|
300
|
+
workspaceId,
|
|
301
|
+
sessionId,
|
|
302
|
+
triggerEventId,
|
|
303
|
+
workflowId,
|
|
304
|
+
turnId,
|
|
305
|
+
});
|
|
306
|
+
if (requeue.action !== "exceeded") {
|
|
307
|
+
// "requeued": the next claim re-dispatches the turn. "stale": the
|
|
308
|
+
// timed-out attempt actually settled the turn (a zombie finished
|
|
309
|
+
// after the server gave up on its heartbeats); nothing to redo.
|
|
310
|
+
return true;
|
|
311
|
+
}
|
|
312
|
+
await activity.failSession({
|
|
313
|
+
accountId,
|
|
314
|
+
workspaceId,
|
|
315
|
+
sessionId,
|
|
316
|
+
triggerEventId,
|
|
317
|
+
workflowId,
|
|
318
|
+
error: `Worker died ${requeue.redispatches + 1} times while running this turn (heartbeat timeout); giving up after ${requeue.redispatches} re-dispatches.`,
|
|
319
|
+
});
|
|
320
|
+
return false;
|
|
321
|
+
}
|
|
322
|
+
await activity.failSession({
|
|
323
|
+
accountId,
|
|
324
|
+
workspaceId,
|
|
325
|
+
sessionId,
|
|
326
|
+
triggerEventId,
|
|
327
|
+
workflowId,
|
|
328
|
+
error: workflowFailureMessage(outcome.error),
|
|
329
|
+
});
|
|
330
|
+
return false;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
if (outcome.result.status === "failed" || outcome.result.status === "cancelled") {
|
|
334
|
+
return outcome.result.status === "cancelled";
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
if (outcome.result.status === "preempted") {
|
|
338
|
+
// The hosting worker shut down gracefully mid-turn: the activity
|
|
339
|
+
// checkpointed conversation truth and put the turn back on the queue
|
|
340
|
+
// before completing. Loop again so the next claim re-dispatches it on a
|
|
341
|
+
// healthy worker (a pending interrupt is honored first by the loop).
|
|
342
|
+
return true;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
if (outcome.result.status === "requires_action") {
|
|
346
|
+
await condition(() => interruptedEventId !== null || approvalQueue.length > 0);
|
|
347
|
+
if (interruptedEventId) {
|
|
348
|
+
await activity.interruptActiveTurn({
|
|
349
|
+
accountId,
|
|
350
|
+
workspaceId,
|
|
351
|
+
sessionId,
|
|
352
|
+
triggerEventId: interruptedEventId,
|
|
353
|
+
workflowId,
|
|
354
|
+
});
|
|
355
|
+
interruptedEventId = null;
|
|
356
|
+
return true;
|
|
357
|
+
}
|
|
358
|
+
const approvalEventId = approvalQueue.shift();
|
|
359
|
+
if (approvalEventId) {
|
|
360
|
+
return await runTurn(accountId, workspaceId, sessionId, turnId, approvalEventId);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
const holdMs = continuationHoldMs(outcome.result, ROTATION_IDLE_FLOOR_MS);
|
|
365
|
+
if (holdMs > 0) {
|
|
366
|
+
// Provider backpressure / rotation all-capped idle: hold the loop so an active
|
|
367
|
+
// goal's continuation does not immediately re-enter the same rate-limit window.
|
|
368
|
+
// A rotation all-capped idle is a MANDATORY hold (idleUntilReset) — a 0/elapsed
|
|
369
|
+
// delay can never skip it (invariant 4: NO THRASH). An interrupt or user signal
|
|
370
|
+
// ends the wait early and is handled by the main loop.
|
|
371
|
+
const seenWakeups = wakeups;
|
|
372
|
+
await condition(() => interruptedEventId !== null || wakeups !== seenWakeups, holdMs);
|
|
373
|
+
}
|
|
374
|
+
return true;
|
|
375
|
+
}
|
|
376
|
+
}
|
package/src/workflows.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export {
|
|
2
|
+
documentIndexWorkflow,
|
|
3
|
+
type DocumentIndexWorkflowInput,
|
|
4
|
+
} from "./workflows/document-index";
|
|
5
|
+
export {
|
|
6
|
+
approvalDecision,
|
|
7
|
+
interrupt,
|
|
8
|
+
queueChanged,
|
|
9
|
+
sessionWorkflow,
|
|
10
|
+
userMessage,
|
|
11
|
+
type SessionWorkflowInput,
|
|
12
|
+
} from "./workflows/session";
|
|
13
|
+
export {
|
|
14
|
+
scheduledTaskFireWorkflow,
|
|
15
|
+
type ScheduledTaskFireWorkflowInput,
|
|
16
|
+
} from "./workflows/scheduled-tasks";
|
|
17
|
+
export {
|
|
18
|
+
sandboxReaperWorkflow,
|
|
19
|
+
} from "./workflows/sandbox-reaper";
|