pilotswarm-sdk 0.4.1 → 0.5.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/api/src/protocol.js +7 -0
- package/dist/blob-store.d.ts +10 -1
- package/dist/blob-store.d.ts.map +1 -1
- package/dist/blob-store.js +275 -13
- package/dist/blob-store.js.map +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +3 -1
- package/dist/client.js.map +1 -1
- package/dist/cms-migrations.d.ts.map +1 -1
- package/dist/cms-migrations.js +164 -0
- package/dist/cms-migrations.js.map +1 -1
- package/dist/cms.d.ts +6 -0
- package/dist/cms.d.ts.map +1 -1
- package/dist/cms.js +3 -0
- package/dist/cms.js.map +1 -1
- package/dist/fault-injection.d.ts +2 -0
- package/dist/fault-injection.d.ts.map +1 -0
- package/dist/fault-injection.js +45 -0
- package/dist/fault-injection.js.map +1 -0
- package/dist/orchestration/index.d.ts +3 -3
- package/dist/orchestration/index.js +1 -1
- package/dist/orchestration/lifecycle.d.ts +9 -2
- package/dist/orchestration/lifecycle.d.ts.map +1 -1
- package/dist/orchestration/lifecycle.js +21 -55
- package/dist/orchestration/lifecycle.js.map +1 -1
- package/dist/orchestration/runtime.d.ts +1 -1
- package/dist/orchestration/state.d.ts +7 -3
- package/dist/orchestration/state.d.ts.map +1 -1
- package/dist/orchestration/state.js +13 -4
- package/dist/orchestration/state.js.map +1 -1
- package/dist/orchestration/turn.d.ts.map +1 -1
- package/dist/orchestration/turn.js +98 -66
- package/dist/orchestration/turn.js.map +1 -1
- package/dist/orchestration-registry.d.ts.map +1 -1
- package/dist/orchestration-registry.js +6 -2
- package/dist/orchestration-registry.js.map +1 -1
- package/dist/orchestration-version.d.ts +1 -1
- package/dist/orchestration-version.js +1 -1
- package/dist/orchestration.d.ts +2 -2
- package/dist/orchestration.js +4 -4
- package/dist/orchestration_1_0_46.d.ts +1 -1
- package/dist/orchestration_1_0_47.d.ts +1 -1
- package/dist/orchestration_1_0_48.d.ts +1 -1
- package/dist/orchestration_1_0_49.d.ts +1 -1
- package/dist/orchestration_1_0_50.d.ts +1 -1
- package/dist/orchestration_1_0_56/agents.d.ts +41 -0
- package/dist/orchestration_1_0_56/agents.d.ts.map +1 -0
- package/dist/orchestration_1_0_56/agents.js +758 -0
- package/dist/orchestration_1_0_56/agents.js.map +1 -0
- package/dist/orchestration_1_0_56/index.d.ts +24 -0
- package/dist/orchestration_1_0_56/index.d.ts.map +1 -0
- package/dist/orchestration_1_0_56/index.js +13 -0
- package/dist/orchestration_1_0_56/index.js.map +1 -0
- package/dist/orchestration_1_0_56/lifecycle.d.ts +41 -0
- package/dist/orchestration_1_0_56/lifecycle.d.ts.map +1 -0
- package/dist/orchestration_1_0_56/lifecycle.js +580 -0
- package/dist/orchestration_1_0_56/lifecycle.js.map +1 -0
- package/dist/orchestration_1_0_56/queue.d.ts +7 -0
- package/dist/orchestration_1_0_56/queue.d.ts.map +1 -0
- package/dist/orchestration_1_0_56/queue.js +644 -0
- package/dist/orchestration_1_0_56/queue.js.map +1 -0
- package/dist/orchestration_1_0_56/runtime.d.ts +29 -0
- package/dist/orchestration_1_0_56/runtime.d.ts.map +1 -0
- package/dist/orchestration_1_0_56/runtime.js +194 -0
- package/dist/orchestration_1_0_56/runtime.js.map +1 -0
- package/dist/orchestration_1_0_56/state.d.ts +126 -0
- package/dist/orchestration_1_0_56/state.d.ts.map +1 -0
- package/dist/orchestration_1_0_56/state.js +106 -0
- package/dist/orchestration_1_0_56/state.js.map +1 -0
- package/dist/orchestration_1_0_56/turn.d.ts +30 -0
- package/dist/orchestration_1_0_56/turn.d.ts.map +1 -0
- package/dist/orchestration_1_0_56/turn.js +1075 -0
- package/dist/orchestration_1_0_56/turn.js.map +1 -0
- package/dist/orchestration_1_0_56/utils.d.ts +22 -0
- package/dist/orchestration_1_0_56/utils.d.ts.map +1 -0
- package/dist/orchestration_1_0_56/utils.js +226 -0
- package/dist/orchestration_1_0_56/utils.js.map +1 -0
- package/dist/orchestration_1_0_57/agents.d.ts +41 -0
- package/dist/orchestration_1_0_57/agents.d.ts.map +1 -0
- package/dist/orchestration_1_0_57/agents.js +758 -0
- package/dist/orchestration_1_0_57/agents.js.map +1 -0
- package/dist/orchestration_1_0_57/index.d.ts +24 -0
- package/dist/orchestration_1_0_57/index.d.ts.map +1 -0
- package/dist/orchestration_1_0_57/index.js +13 -0
- package/dist/orchestration_1_0_57/index.js.map +1 -0
- package/dist/orchestration_1_0_57/lifecycle.d.ts +49 -0
- package/dist/orchestration_1_0_57/lifecycle.d.ts.map +1 -0
- package/dist/orchestration_1_0_57/lifecycle.js +583 -0
- package/dist/orchestration_1_0_57/lifecycle.js.map +1 -0
- package/dist/orchestration_1_0_57/queue.d.ts +7 -0
- package/dist/orchestration_1_0_57/queue.d.ts.map +1 -0
- package/dist/orchestration_1_0_57/queue.js +644 -0
- package/dist/orchestration_1_0_57/queue.js.map +1 -0
- package/dist/orchestration_1_0_57/runtime.d.ts +29 -0
- package/dist/orchestration_1_0_57/runtime.d.ts.map +1 -0
- package/dist/orchestration_1_0_57/runtime.js +198 -0
- package/dist/orchestration_1_0_57/runtime.js.map +1 -0
- package/dist/orchestration_1_0_57/state.d.ts +133 -0
- package/dist/orchestration_1_0_57/state.d.ts.map +1 -0
- package/dist/orchestration_1_0_57/state.js +115 -0
- package/dist/orchestration_1_0_57/state.js.map +1 -0
- package/dist/orchestration_1_0_57/turn.d.ts +30 -0
- package/dist/orchestration_1_0_57/turn.d.ts.map +1 -0
- package/dist/orchestration_1_0_57/turn.js +1110 -0
- package/dist/orchestration_1_0_57/turn.js.map +1 -0
- package/dist/orchestration_1_0_57/utils.d.ts +22 -0
- package/dist/orchestration_1_0_57/utils.d.ts.map +1 -0
- package/dist/orchestration_1_0_57/utils.js +226 -0
- package/dist/orchestration_1_0_57/utils.js.map +1 -0
- package/dist/session-lifecycle.d.ts +80 -0
- package/dist/session-lifecycle.d.ts.map +1 -0
- package/dist/session-lifecycle.js +257 -0
- package/dist/session-lifecycle.js.map +1 -0
- package/dist/session-manager.d.ts +21 -0
- package/dist/session-manager.d.ts.map +1 -1
- package/dist/session-manager.js +137 -1
- package/dist/session-manager.js.map +1 -1
- package/dist/session-proxy.d.ts +5 -1
- package/dist/session-proxy.d.ts.map +1 -1
- package/dist/session-proxy.js +1113 -957
- package/dist/session-proxy.js.map +1 -1
- package/dist/session-store.d.ts +48 -3
- package/dist/session-store.d.ts.map +1 -1
- package/dist/session-store.js +394 -28
- package/dist/session-store.js.map +1 -1
- package/dist/snapshot-protocol.d.ts +101 -0
- package/dist/snapshot-protocol.d.ts.map +1 -0
- package/dist/snapshot-protocol.js +120 -0
- package/dist/snapshot-protocol.js.map +1 -0
- package/dist/types.d.ts +24 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/wait-affinity.d.ts +11 -0
- package/dist/wait-affinity.d.ts.map +1 -1
- package/dist/wait-affinity.js +6 -0
- package/dist/wait-affinity.js.map +1 -1
- package/dist/web/web-management-client.d.ts +28 -9
- package/dist/web/web-management-client.d.ts.map +1 -1
- package/dist/web/web-management-client.js +30 -15
- package/dist/web/web-management-client.js.map +1 -1
- package/dist/worker.d.ts +16 -1
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +63 -6
- package/dist/worker.js.map +1 -1
- package/package.json +7 -4
|
@@ -43,9 +43,15 @@ export interface DurableSessionState {
|
|
|
43
43
|
loopIteration: number;
|
|
44
44
|
retryCount: number;
|
|
45
45
|
needsHydration: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Session lifecycle protocol: last committed snapshot-store version,
|
|
48
|
+
* recorded from each runTurn result. 0 = no commit recorded yet.
|
|
49
|
+
* Threaded through continue-as-new; the next turn's activity input
|
|
50
|
+
* carries it as `snapshot.expectedVersion` for worker self-validation.
|
|
51
|
+
*/
|
|
52
|
+
snapshotVersion: number;
|
|
46
53
|
preserveAffinityOnHydrate: boolean;
|
|
47
54
|
blobEnabled: boolean;
|
|
48
|
-
lastLiveSessionAction: "session-activity" | "dehydrate";
|
|
49
55
|
pendingRehydrationMessage?: string;
|
|
50
56
|
pendingPrompt?: string;
|
|
51
57
|
pendingRequiredTool?: string;
|
|
@@ -77,10 +83,8 @@ export interface DurableSessionState {
|
|
|
77
83
|
}
|
|
78
84
|
/** Immutable per-execution configuration derived from the orchestration input. */
|
|
79
85
|
export interface DurableSessionOptions {
|
|
80
|
-
dehydrateThreshold: number;
|
|
81
86
|
idleTimeout: number;
|
|
82
87
|
inputGracePeriod: number;
|
|
83
|
-
checkpointInterval: number;
|
|
84
88
|
isSystem: boolean;
|
|
85
89
|
parentSessionId?: string;
|
|
86
90
|
nestingLevel: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/orchestration/state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,kBAAkB,EAClB,yBAAyB,EACzB,mBAAmB,EACnB,aAAa,EACb,UAAU,EACb,MAAM,aAAa,CAAC;AAGrB,MAAM,WAAW,WAAW;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,YAAY,GAAG,aAAa,CAAC;IAC1E,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,EAAE;QAAE,eAAe,EAAE,OAAO,CAAC;QAAC,wBAAwB,EAAE,OAAO,CAAC;QAAC,yBAAyB,EAAE,OAAO,CAAA;KAAE,CAAC;IAC/G,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,MAAM,MAAM,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IAC3B,OAAO,EAAE,qBAAqB,CAAC;CAClC;AAID,eAAO,MAAM,2BAA2B,uHACgF,CAAC;AAEzH,eAAO,MAAM,WAAW,IAAI,CAAC;AAC7B,eAAO,MAAM,cAAc,KAAK,CAAC;AACjC,eAAO,MAAM,iBAAiB,IAAI,CAAC;AACnC,eAAO,MAAM,qBAAqB,QAAS,CAAC;AAC5C,eAAO,MAAM,mBAAmB,QAAS,CAAC;AAC1C,eAAO,MAAM,yBAAyB,OAAQ,CAAC;AAE/C,eAAO,MAAM,qBAAqB,QAAS,CAAC;AAC5C,eAAO,MAAM,sBAAsB,SAAU,CAAC;AAE9C,eAAO,MAAM,iBAAiB,KAAK,CAAC;AACpC,eAAO,MAAM,gBAAgB,QAAY,CAAC;AAC1C,eAAO,MAAM,kBAAkB,KAAK,CAAC;AACrC,eAAO,MAAM,qBAAqB,KAAK,CAAC;AACxC,eAAO,MAAM,4BAA4B,KAAK,CAAC;AAC/C,eAAO,MAAM,6CAA6C,QAAa,CAAC;AACxE,eAAO,MAAM,sCAAsC,IAAI,CAAC;AACxD,eAAO,MAAM,qBAAqB,KAAK,CAAC;AACxC,eAAO,MAAM,2BAA2B,MAAM,CAAC;AAqB/C,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,qBAAqB,GAAG,mBAAmB,CAiEjH;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,qBAAqB,CAqB9E"}
|
|
@@ -57,9 +57,9 @@ export function createInitialState(input, options) {
|
|
|
57
57
|
loopIteration: 0,
|
|
58
58
|
retryCount: input.retryCount ?? 0,
|
|
59
59
|
needsHydration: input.needsHydration ?? false,
|
|
60
|
+
snapshotVersion: input.snapshotVersion ?? 0,
|
|
60
61
|
preserveAffinityOnHydrate: input.preserveAffinityOnHydrate ?? false,
|
|
61
62
|
blobEnabled: input.blobEnabled ?? false,
|
|
62
|
-
lastLiveSessionAction: "session-activity",
|
|
63
63
|
pendingRehydrationMessage: input.rehydrationMessage,
|
|
64
64
|
pendingPrompt: input.prompt,
|
|
65
65
|
pendingRequiredTool: input.requiredTool,
|
|
@@ -92,10 +92,19 @@ export function createInitialState(input, options) {
|
|
|
92
92
|
}
|
|
93
93
|
export function deriveOptions(input) {
|
|
94
94
|
return {
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
// Lifecycle protocol: the idle timer is the affinity HOLD WINDOW —
|
|
96
|
+
// its fire releases the worker (GUID rotation), it no longer
|
|
97
|
+
// dehydrates. 30 minutes, not 60 seconds. Legacy executions CAN in
|
|
98
|
+
// with an explicit 60 (the old system default, threaded through
|
|
99
|
+
// every historical CAN input) — treat that sentinel as unset so
|
|
100
|
+
// migrated sessions actually get the hold window.
|
|
101
|
+
// (dehydrateThreshold / checkpointInterval inputs are accepted but
|
|
102
|
+
// meaningless here: turns commit inside the runTurn activity and
|
|
103
|
+
// waits never dehydrate — the fields live on only for ≤1.0.56.)
|
|
104
|
+
idleTimeout: input.idleTimeout == null || input.idleTimeout === 60
|
|
105
|
+
? 1_800
|
|
106
|
+
: input.idleTimeout,
|
|
97
107
|
inputGracePeriod: input.inputGracePeriod ?? 30,
|
|
98
|
-
checkpointInterval: input.checkpointInterval ?? -1,
|
|
99
108
|
isSystem: input.isSystem ?? false,
|
|
100
109
|
parentSessionId: input.parentSessionId
|
|
101
110
|
?? (input.parentOrchId ? input.parentOrchId.replace(/^session-/, "") : undefined),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/orchestration/state.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/orchestration/state.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAsH/C,+DAA+D;AAE/D,MAAM,CAAC,MAAM,2BAA2B,GACpC,oHAAoH,CA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
|
|
|
1
1
|
import { SESSION_STATE_MISSING_PREFIX, stopTurnQueueName } from "../types.js";
|
|
2
2
|
import { createSessionProxy } from "../session-proxy.js";
|
|
3
|
-
import {
|
|
3
|
+
import { planHoldRelease } from "../wait-affinity.js";
|
|
4
4
|
import { buildShutdownWaitReason, failPendingShutdown, getStillRunningAgentIds, handleSubAgentAction, isSubAgentTerminalStatus, maybeResolveAgentWaitCompletion, refreshTrackedSubAgents, } from "./agents.js";
|
|
5
|
-
import { applyCronAtAction, applyCronAction, continueInput, continueInputWithPrompt,
|
|
5
|
+
import { applyCronAtAction, applyCronAction, continueInput, continueInputWithPrompt, drainLeadingQueuedScheduleActions, ensureTaskContext, maybeSummarize, publishStatus, releaseAffinity, versionedContinueAsNew, wrapWithResumeContext, writeCommandResponse, writeLatestResponse, } from "./lifecycle.js";
|
|
6
6
|
import { describeCronAt } from "../cron-at.js";
|
|
7
7
|
import { shouldWakeParentForChildUpdate } from "../child-notifications.js";
|
|
8
8
|
import { INTERNAL_SYSTEM_TURN_PROMPT, MAX_RETRIES, SHUTDOWN_POLL_INTERVAL_MS, SHUTDOWN_TIMEOUT_MS, } from "./state.js";
|
|
@@ -53,8 +53,12 @@ function* handleConnectionClosedRetry(runtime, errorMessage, rc) {
|
|
|
53
53
|
recoverableTransportLoss: true,
|
|
54
54
|
});
|
|
55
55
|
runtime.ctx.traceInfo(`[orch] live Copilot connection lost; retrying in ${COPILOT_CONNECTION_CLOSED_RETRY_DELAY_SECONDS}s`);
|
|
56
|
+
// Lifecycle protocol: nothing to dehydrate — the last commit is the
|
|
57
|
+
// durable truth. Release affinity so the retry can land anywhere;
|
|
58
|
+
// the retry's preamble hydrates clean from the committed snapshot
|
|
59
|
+
// (the broken warm session is detected via the turn sentinel).
|
|
56
60
|
if (state.blobEnabled) {
|
|
57
|
-
yield*
|
|
61
|
+
yield* releaseAffinity(runtime, "error", {
|
|
58
62
|
detail: retryDetail,
|
|
59
63
|
error: errorMessage,
|
|
60
64
|
phase: rc.phase,
|
|
@@ -82,22 +86,21 @@ function* handleConnectionClosedRetry(runtime, errorMessage, rc) {
|
|
|
82
86
|
phase: rc.phase,
|
|
83
87
|
retries: COPILOT_CONNECTION_CLOSED_MAX_RETRIES,
|
|
84
88
|
retryDelaySeconds: COPILOT_CONNECTION_CLOSED_RETRY_DELAY_SECONDS,
|
|
85
|
-
nextStep: "
|
|
89
|
+
nextStep: "release_affinity_and_resume_on_any_worker",
|
|
86
90
|
},
|
|
87
91
|
}]);
|
|
88
92
|
if (state.blobEnabled) {
|
|
89
|
-
yield*
|
|
93
|
+
yield* releaseAffinity(runtime, "lossy_handoff", {
|
|
90
94
|
detail: handoffMessage,
|
|
91
95
|
error: errorMessage,
|
|
92
96
|
phase: rc.phase,
|
|
93
97
|
retries: COPILOT_CONNECTION_CLOSED_MAX_RETRIES,
|
|
94
98
|
retryDelaySeconds: COPILOT_CONNECTION_CLOSED_RETRY_DELAY_SECONDS,
|
|
95
|
-
nextStep: "
|
|
99
|
+
nextStep: "release_affinity_and_resume_on_any_worker",
|
|
96
100
|
});
|
|
97
101
|
yield* versionedContinueAsNew(runtime, continueInput(runtime, {
|
|
98
102
|
...retryContinueOverrides(state, rc),
|
|
99
103
|
retryCount: 0,
|
|
100
|
-
needsHydration: true,
|
|
101
104
|
rehydrationMessage: buildLossyHandoffRehydrationMessage(errorMessage),
|
|
102
105
|
}));
|
|
103
106
|
return;
|
|
@@ -115,7 +118,7 @@ function retryContinueOverrides(state, rc) {
|
|
|
115
118
|
prompt: rc.sourcePrompt,
|
|
116
119
|
...(rc.cycleOrigin ? { cycleOrigin: rc.cycleOrigin } : {}),
|
|
117
120
|
retryCount: state.retryCount,
|
|
118
|
-
needsHydration: state.
|
|
121
|
+
needsHydration: state.needsHydration,
|
|
119
122
|
};
|
|
120
123
|
}
|
|
121
124
|
return {
|
|
@@ -124,7 +127,7 @@ function retryContinueOverrides(state, rc) {
|
|
|
124
127
|
...(rc.turnSystemPrompt ? { systemPrompt: rc.turnSystemPrompt } : {}),
|
|
125
128
|
...(rc.cycleOrigin ? { cycleOrigin: rc.cycleOrigin } : {}),
|
|
126
129
|
retryCount: state.retryCount,
|
|
127
|
-
needsHydration: state.
|
|
130
|
+
needsHydration: state.needsHydration,
|
|
128
131
|
};
|
|
129
132
|
}
|
|
130
133
|
function* handleGenericRetry(runtime, errorMessage, rc) {
|
|
@@ -144,7 +147,7 @@ function* handleGenericRetry(runtime, errorMessage, rc) {
|
|
|
144
147
|
});
|
|
145
148
|
runtime.ctx.traceInfo(`[orch] retrying in ${retryDelay}s${rc.phase === "turn.result.error" ? " after turn error" : ""}`);
|
|
146
149
|
if (state.blobEnabled) {
|
|
147
|
-
yield*
|
|
150
|
+
yield* releaseAffinity(runtime, "error", {
|
|
148
151
|
detail: errorMessage,
|
|
149
152
|
error: errorMessage,
|
|
150
153
|
phase: rc.phase,
|
|
@@ -161,14 +164,13 @@ export function* processPrompt(runtime, promptText, isBootstrap, requiredTool, c
|
|
|
161
164
|
const { ctx, state } = runtime;
|
|
162
165
|
let prompt = promptText;
|
|
163
166
|
let promptIsBootstrap = isBootstrap;
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
167
|
+
// Lifecycle protocol (P5): no needsHydration probe. The old protocol
|
|
168
|
+
// asked a worker "do you have my files?" before every turn — an extra
|
|
169
|
+
// session activity whose answer could desync from reality, and whose
|
|
170
|
+
// "no" triggered a legacy hydrate that the runTurn preamble would then
|
|
171
|
+
// repeat (double download per cold wake). The preamble self-validates
|
|
172
|
+
// against the versioned store; state.needsHydration survives only as
|
|
173
|
+
// one-shot normalization of legacy (≤1.0.56) continue-as-new inputs.
|
|
172
174
|
if (state.needsHydration && state.blobEnabled && prompt) {
|
|
173
175
|
prompt = wrapWithResumeContext(runtime, prompt);
|
|
174
176
|
}
|
|
@@ -199,7 +201,6 @@ export function* processPrompt(runtime, promptText, isBootstrap, requiredTool, c
|
|
|
199
201
|
yield runtime.session.hydrate();
|
|
200
202
|
state.needsHydration = false;
|
|
201
203
|
state.preserveAffinityOnHydrate = false;
|
|
202
|
-
state.lastLiveSessionAction = "session-activity";
|
|
203
204
|
break;
|
|
204
205
|
}
|
|
205
206
|
catch (hydrateErr) {
|
|
@@ -243,7 +244,6 @@ export function* processPrompt(runtime, promptText, isBootstrap, requiredTool, c
|
|
|
243
244
|
publishStatus(runtime, "running", { iteration: state.iteration + 1 });
|
|
244
245
|
let turnResult;
|
|
245
246
|
try {
|
|
246
|
-
state.lastLiveSessionAction = "session-activity";
|
|
247
247
|
// Stop-turn race: the in-flight runTurn activity vs a dequeue on the
|
|
248
248
|
// TURN-SCOPED stop queue (stopTurn.<iteration>). Scoping the queue to
|
|
249
249
|
// the turn index makes stale stop events structurally unable to kill a
|
|
@@ -252,6 +252,11 @@ export function* processPrompt(runtime, promptText, isBootstrap, requiredTool, c
|
|
|
252
252
|
// work item (lock-steal → isCancelled poll → SDK abort) as the
|
|
253
253
|
// guaranteed backstop; handleTurnStopped layers the fast-path
|
|
254
254
|
// same-affinity abortTurn on top.
|
|
255
|
+
// Lifecycle protocol: a deterministic per-turn key (recorded GUID)
|
|
256
|
+
// rides in the activity input with the last committed version. The
|
|
257
|
+
// worker self-validates against them (preamble) and commits the
|
|
258
|
+
// post-turn snapshot inside the activity, returning the new version.
|
|
259
|
+
const snapshotTurnKey = state.blobEnabled ? yield ctx.newGuid() : "";
|
|
255
260
|
const turnTask = runtime.session.runTurn(prompt, promptIsBootstrap, state.iteration, {
|
|
256
261
|
...(runtime.options.parentSessionId ? { parentSessionId: runtime.options.parentSessionId } : {}),
|
|
257
262
|
nestingLevel: runtime.options.nestingLevel,
|
|
@@ -259,6 +264,9 @@ export function* processPrompt(runtime, promptText, isBootstrap, requiredTool, c
|
|
|
259
264
|
...(cycleOrigin ? { cycleOrigin } : {}),
|
|
260
265
|
retryCount: state.retryCount,
|
|
261
266
|
...(clientMessageIds && clientMessageIds.length > 0 ? { clientMessageIds } : {}),
|
|
267
|
+
...(snapshotTurnKey
|
|
268
|
+
? { snapshot: { expectedVersion: state.snapshotVersion, turnKey: snapshotTurnKey } }
|
|
269
|
+
: {}),
|
|
262
270
|
});
|
|
263
271
|
const stopTask = ctx.dequeueEvent(stopTurnQueueName(state.iteration));
|
|
264
272
|
const race = yield ctx.race(turnTask, stopTask);
|
|
@@ -318,6 +326,12 @@ export function* processPrompt(runtime, promptText, isBootstrap, requiredTool, c
|
|
|
318
326
|
state.config.turnSystemPrompt = undefined;
|
|
319
327
|
state.retryCount = 0;
|
|
320
328
|
let result = typeof turnResult === "string" ? JSON.parse(turnResult) : turnResult;
|
|
329
|
+
// Lifecycle protocol: adopt the version the activity committed. The
|
|
330
|
+
// returned value is authoritative even when it disagrees with the
|
|
331
|
+
// expectation (self-healing after a store restore).
|
|
332
|
+
if (typeof result?.snapshotVersion === "number") {
|
|
333
|
+
state.snapshotVersion = result.snapshotVersion;
|
|
334
|
+
}
|
|
321
335
|
const observedAt = yield ctx.utcNow();
|
|
322
336
|
state.contextUsage = updateContextUsageFromEvents(state.contextUsage, result?.events, observedAt);
|
|
323
337
|
const failedModelSwitchContinuePrompt = captureFailedModelSwitchNotice(runtime, result);
|
|
@@ -450,8 +464,16 @@ function* schedulePostTurnContinuation(runtime) {
|
|
|
450
464
|
const saved = state.interruptedWaitTimer;
|
|
451
465
|
state.interruptedWaitTimer = null;
|
|
452
466
|
ctx.traceInfo(`[orch] auto-resuming interrupted wait: ${saved.remainingSec}s (${saved.reason})`);
|
|
453
|
-
|
|
454
|
-
|
|
467
|
+
// Lifecycle protocol: state is durable from the turn commit — the
|
|
468
|
+
// wait only decides hold (keep GUID, worker stays warm) vs release
|
|
469
|
+
// (rotate GUID, wake-up hydrates anywhere).
|
|
470
|
+
const resumeWaitPlan = planHoldRelease({
|
|
471
|
+
blobEnabled: state.blobEnabled,
|
|
472
|
+
seconds: saved.remainingSec,
|
|
473
|
+
holdWindowSeconds: options.idleTimeout,
|
|
474
|
+
});
|
|
475
|
+
if (resumeWaitPlan.shouldRelease) {
|
|
476
|
+
yield* releaseAffinity(runtime, "timer");
|
|
455
477
|
}
|
|
456
478
|
const resumeNow = yield ctx.utcNow();
|
|
457
479
|
publishStatus(runtime, "waiting", {
|
|
@@ -459,15 +481,11 @@ function* schedulePostTurnContinuation(runtime) {
|
|
|
459
481
|
waitReason: saved.reason,
|
|
460
482
|
waitStartedAt: resumeNow,
|
|
461
483
|
});
|
|
462
|
-
if (!saved.shouldRehydrate)
|
|
463
|
-
yield* maybeCheckpoint(runtime);
|
|
464
484
|
state.activeTimer = {
|
|
465
485
|
deadlineMs: resumeNow + saved.remainingSec * 1000,
|
|
466
486
|
originalDurationMs: saved.remainingSec * 1000,
|
|
467
487
|
reason: saved.reason,
|
|
468
488
|
type: "wait",
|
|
469
|
-
shouldRehydrate: saved.shouldRehydrate,
|
|
470
|
-
waitPlan: saved.waitPlan,
|
|
471
489
|
};
|
|
472
490
|
return;
|
|
473
491
|
}
|
|
@@ -477,13 +495,13 @@ function* schedulePostTurnContinuation(runtime) {
|
|
|
477
495
|
const remainingMs = Math.max(0, saved.remainingMs);
|
|
478
496
|
const remainingSec = Math.max(1, Math.round(remainingMs / 1000));
|
|
479
497
|
ctx.traceInfo(`[orch] auto-resuming interrupted cron: ${remainingSec}s remain (${saved.reason})`);
|
|
480
|
-
const cronResumePlan =
|
|
498
|
+
const cronResumePlan = planHoldRelease({
|
|
481
499
|
blobEnabled: state.blobEnabled,
|
|
482
500
|
seconds: remainingSec,
|
|
483
|
-
|
|
501
|
+
holdWindowSeconds: options.idleTimeout,
|
|
484
502
|
});
|
|
485
|
-
if (cronResumePlan.
|
|
486
|
-
yield*
|
|
503
|
+
if (cronResumePlan.shouldRelease) {
|
|
504
|
+
yield* releaseAffinity(runtime, "cron");
|
|
487
505
|
}
|
|
488
506
|
const resumeNow = yield ctx.utcNow();
|
|
489
507
|
publishStatus(runtime, "waiting", {
|
|
@@ -491,26 +509,23 @@ function* schedulePostTurnContinuation(runtime) {
|
|
|
491
509
|
waitReason: saved.reason,
|
|
492
510
|
waitStartedAt: resumeNow,
|
|
493
511
|
});
|
|
494
|
-
if (!cronResumePlan.shouldDehydrate)
|
|
495
|
-
yield* maybeCheckpoint(runtime);
|
|
496
512
|
state.activeTimer = {
|
|
497
513
|
deadlineMs: resumeNow + remainingMs,
|
|
498
514
|
originalDurationMs: remainingMs,
|
|
499
515
|
reason: saved.reason,
|
|
500
516
|
type: "cron",
|
|
501
|
-
shouldRehydrate: cronResumePlan.shouldDehydrate,
|
|
502
517
|
};
|
|
503
518
|
return;
|
|
504
519
|
}
|
|
505
520
|
if (state.cronSchedule) {
|
|
506
521
|
const activeCron = { ...state.cronSchedule };
|
|
507
|
-
const cronPlan =
|
|
522
|
+
const cronPlan = planHoldRelease({
|
|
508
523
|
blobEnabled: state.blobEnabled,
|
|
509
524
|
seconds: activeCron.intervalSeconds,
|
|
510
|
-
|
|
525
|
+
holdWindowSeconds: options.idleTimeout,
|
|
511
526
|
});
|
|
512
|
-
if (cronPlan.
|
|
513
|
-
yield*
|
|
527
|
+
if (cronPlan.shouldRelease) {
|
|
528
|
+
yield* releaseAffinity(runtime, "cron");
|
|
514
529
|
}
|
|
515
530
|
yield runtime.manager.recordSessionEvent(runtime.input.sessionId, [{
|
|
516
531
|
eventType: "session.cron_started",
|
|
@@ -523,14 +538,11 @@ function* schedulePostTurnContinuation(runtime) {
|
|
|
523
538
|
waitReason: activeCron.reason,
|
|
524
539
|
waitStartedAt: cronStartedAt,
|
|
525
540
|
});
|
|
526
|
-
if (!cronPlan.shouldDehydrate)
|
|
527
|
-
yield* maybeCheckpoint(runtime);
|
|
528
541
|
state.activeTimer = {
|
|
529
542
|
deadlineMs: cronStartedAt + activeCron.intervalSeconds * 1000,
|
|
530
543
|
originalDurationMs: activeCron.intervalSeconds * 1000,
|
|
531
544
|
reason: activeCron.reason,
|
|
532
545
|
type: "cron",
|
|
533
|
-
shouldRehydrate: cronPlan.shouldDehydrate,
|
|
534
546
|
};
|
|
535
547
|
return;
|
|
536
548
|
}
|
|
@@ -562,13 +574,13 @@ function* schedulePostTurnContinuation(runtime) {
|
|
|
562
574
|
}
|
|
563
575
|
const waitMs = Math.max(0, nextFireAtMs - nowMs);
|
|
564
576
|
const waitSeconds = Math.max(0, Math.ceil(waitMs / 1000));
|
|
565
|
-
const cronAtPlan =
|
|
577
|
+
const cronAtPlan = planHoldRelease({
|
|
566
578
|
blobEnabled: state.blobEnabled,
|
|
567
579
|
seconds: waitSeconds,
|
|
568
|
-
|
|
580
|
+
holdWindowSeconds: options.idleTimeout,
|
|
569
581
|
});
|
|
570
|
-
if (cronAtPlan.
|
|
571
|
-
yield*
|
|
582
|
+
if (cronAtPlan.shouldRelease) {
|
|
583
|
+
yield* releaseAffinity(runtime, "cron_at");
|
|
572
584
|
}
|
|
573
585
|
yield runtime.manager.recordSessionEvent(runtime.input.sessionId, [{
|
|
574
586
|
eventType: "session.cron_at_started",
|
|
@@ -582,23 +594,21 @@ function* schedulePostTurnContinuation(runtime) {
|
|
|
582
594
|
waitReason: activeCronAt.reason,
|
|
583
595
|
waitStartedAt: nowMs,
|
|
584
596
|
});
|
|
585
|
-
if (!cronAtPlan.shouldDehydrate)
|
|
586
|
-
yield* maybeCheckpoint(runtime);
|
|
587
597
|
state.activeTimer = {
|
|
588
598
|
deadlineMs: nowMs + waitMs,
|
|
589
599
|
originalDurationMs: waitMs,
|
|
590
600
|
reason: activeCronAt.reason,
|
|
591
601
|
type: "cron_at",
|
|
592
|
-
shouldRehydrate: cronAtPlan.shouldDehydrate,
|
|
593
602
|
};
|
|
594
603
|
return;
|
|
595
604
|
}
|
|
596
605
|
if (!state.blobEnabled || options.idleTimeout < 0) {
|
|
597
|
-
yield* maybeCheckpoint(runtime);
|
|
598
606
|
return;
|
|
599
607
|
}
|
|
608
|
+
// The idle timer IS the affinity hold window (lifecycle protocol §3.4):
|
|
609
|
+
// any session activity re-arms it via the drain machinery, and its fire
|
|
610
|
+
// releases the worker — it no longer dehydrates.
|
|
600
611
|
publishStatus(runtime, "idle");
|
|
601
|
-
yield* maybeCheckpoint(runtime);
|
|
602
612
|
const idleNow = yield ctx.utcNow();
|
|
603
613
|
state.activeTimer = {
|
|
604
614
|
deadlineMs: idleNow + options.idleTimeout * 1000,
|
|
@@ -704,7 +714,6 @@ export function* handleTurnResult(runtime, result, sourcePrompt, cycleOrigin) {
|
|
|
704
714
|
}
|
|
705
715
|
if (runtime.input.isSystem && !state.cronSchedule && !state.cronAtSchedule) {
|
|
706
716
|
ctx.traceInfo(`[orch] system sub-agent completed turn, continuing loop`);
|
|
707
|
-
yield* maybeCheckpoint(runtime);
|
|
708
717
|
return;
|
|
709
718
|
}
|
|
710
719
|
}
|
|
@@ -756,14 +765,18 @@ export function* handleTurnResult(runtime, result, sourcePrompt, cycleOrigin) {
|
|
|
756
765
|
}
|
|
757
766
|
}
|
|
758
767
|
ctx.traceInfo(`[orch] durable timer: ${result.seconds}s (${result.reason})`);
|
|
759
|
-
|
|
768
|
+
// Lifecycle protocol: waits within the hold window keep the
|
|
769
|
+
// affinity GUID (worker stays warm — this is now the default,
|
|
770
|
+
// no wait_on_worker opt-in needed); longer waits release. The
|
|
771
|
+
// legacy `preserveWorkerAffinity` flag is accepted and simply
|
|
772
|
+
// subsumed: holds within the window always preserve affinity.
|
|
773
|
+
const waitPlan = planHoldRelease({
|
|
760
774
|
blobEnabled: state.blobEnabled,
|
|
761
775
|
seconds: result.seconds,
|
|
762
|
-
|
|
763
|
-
preserveWorkerAffinity: result.preserveWorkerAffinity,
|
|
776
|
+
holdWindowSeconds: options.idleTimeout,
|
|
764
777
|
});
|
|
765
|
-
if (waitPlan.
|
|
766
|
-
yield*
|
|
778
|
+
if (waitPlan.shouldRelease) {
|
|
779
|
+
yield* releaseAffinity(runtime, "timer");
|
|
767
780
|
}
|
|
768
781
|
const waitStartedAt = yield ctx.utcNow();
|
|
769
782
|
if (result.content) {
|
|
@@ -782,21 +795,17 @@ export function* handleTurnResult(runtime, result, sourcePrompt, cycleOrigin) {
|
|
|
782
795
|
waitSeconds: result.seconds,
|
|
783
796
|
waitReason: result.reason,
|
|
784
797
|
waitStartedAt,
|
|
785
|
-
preserveWorkerAffinity: waitPlan.
|
|
798
|
+
preserveWorkerAffinity: !waitPlan.shouldRelease,
|
|
786
799
|
});
|
|
787
|
-
if (!waitPlan.shouldDehydrate)
|
|
788
|
-
yield* maybeCheckpoint(runtime);
|
|
789
800
|
yield runtime.manager.recordSessionEvent(runtime.input.sessionId, [{
|
|
790
801
|
eventType: "session.wait_started",
|
|
791
|
-
data: { seconds: result.seconds, reason: result.reason, preserveAffinity: waitPlan.
|
|
802
|
+
data: { seconds: result.seconds, reason: result.reason, preserveAffinity: !waitPlan.shouldRelease },
|
|
792
803
|
}]);
|
|
793
804
|
state.activeTimer = {
|
|
794
805
|
deadlineMs: waitStartedAt + result.seconds * 1000,
|
|
795
806
|
originalDurationMs: result.seconds * 1000,
|
|
796
807
|
reason: result.reason,
|
|
797
808
|
type: "wait",
|
|
798
|
-
shouldRehydrate: waitPlan.shouldDehydrate,
|
|
799
|
-
waitPlan,
|
|
800
809
|
content: result.content,
|
|
801
810
|
};
|
|
802
811
|
return;
|
|
@@ -818,11 +827,20 @@ export function* handleTurnResult(runtime, result, sourcePrompt, cycleOrigin) {
|
|
|
818
827
|
};
|
|
819
828
|
publishStatus(runtime, "input_required");
|
|
820
829
|
if (!state.blobEnabled || options.inputGracePeriod < 0) {
|
|
821
|
-
yield* maybeCheckpoint(runtime);
|
|
822
830
|
return;
|
|
823
831
|
}
|
|
832
|
+
// Lifecycle protocol: waiting on a human is a HOLD, not a
|
|
833
|
+
// dehydrate — arm the hold-window timer directly (its fire
|
|
834
|
+
// releases affinity; an answer within the window lands warm).
|
|
824
835
|
if (options.inputGracePeriod === 0) {
|
|
825
|
-
yield
|
|
836
|
+
const inputHoldNow = yield ctx.utcNow();
|
|
837
|
+
const inputHoldSeconds = options.idleTimeout > 0 ? options.idleTimeout : 1_800;
|
|
838
|
+
state.activeTimer = {
|
|
839
|
+
deadlineMs: inputHoldNow + inputHoldSeconds * 1000,
|
|
840
|
+
originalDurationMs: inputHoldSeconds * 1000,
|
|
841
|
+
reason: "idle timeout (input required)",
|
|
842
|
+
type: "idle",
|
|
843
|
+
};
|
|
826
844
|
return;
|
|
827
845
|
}
|
|
828
846
|
const graceNow = yield ctx.utcNow();
|
|
@@ -990,8 +1008,12 @@ export function* processTimer(runtime, timerItem) {
|
|
|
990
1008
|
return;
|
|
991
1009
|
}
|
|
992
1010
|
case "idle": {
|
|
993
|
-
|
|
994
|
-
|
|
1011
|
+
// Lifecycle protocol: hold window expired → release the worker.
|
|
1012
|
+
// No dehydrate — every completed turn already committed its
|
|
1013
|
+
// snapshot; the old worker's copy is a cache its own eviction
|
|
1014
|
+
// clock reclaims.
|
|
1015
|
+
ctx.traceInfo("[session] hold window expired, releasing worker affinity");
|
|
1016
|
+
yield* releaseAffinity(runtime, "idle");
|
|
995
1017
|
return;
|
|
996
1018
|
}
|
|
997
1019
|
case "agent-poll": {
|
|
@@ -1067,7 +1089,17 @@ export function* processTimer(runtime, timerItem) {
|
|
|
1067
1089
|
return;
|
|
1068
1090
|
}
|
|
1069
1091
|
case "input-grace": {
|
|
1070
|
-
|
|
1092
|
+
// Lifecycle protocol: grace elapsed without an answer → enter
|
|
1093
|
+
// the hold window (idle timer). The eventual idle fire releases
|
|
1094
|
+
// affinity; an answer any time before that lands warm.
|
|
1095
|
+
const graceElapsedNow = yield runtime.ctx.utcNow();
|
|
1096
|
+
const holdSeconds = runtime.options.idleTimeout > 0 ? runtime.options.idleTimeout : 1_800;
|
|
1097
|
+
state.activeTimer = {
|
|
1098
|
+
deadlineMs: graceElapsedNow + holdSeconds * 1000,
|
|
1099
|
+
originalDurationMs: holdSeconds * 1000,
|
|
1100
|
+
reason: "idle timeout (input required)",
|
|
1101
|
+
type: "idle",
|
|
1102
|
+
};
|
|
1071
1103
|
return;
|
|
1072
1104
|
}
|
|
1073
1105
|
}
|