@proofoftech/flowsafe 0.31.0 → 0.33.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/CHANGELOG.md +34 -0
- package/README.md +6 -0
- package/dist/agent-host/thread-host.d.ts.map +1 -1
- package/dist/agent-host/thread-host.js +18 -19
- package/dist/agent-host/thread-host.js.map +1 -1
- package/dist/agent-host/thread-topology.d.ts +1 -0
- package/dist/agent-host/thread-topology.d.ts.map +1 -1
- package/dist/agent-host/thread-topology.js +3 -2
- package/dist/agent-host/thread-topology.js.map +1 -1
- package/dist/approval-api/actor-context.d.ts +1 -0
- package/dist/approval-api/actor-context.d.ts.map +1 -1
- package/dist/approval-api/actor-context.js +12 -1
- package/dist/approval-api/actor-context.js.map +1 -1
- package/dist/approval-api/resource-ownership.d.ts +3 -0
- package/dist/approval-api/resource-ownership.d.ts.map +1 -1
- package/dist/approval-api/resource-ownership.js +14 -2
- package/dist/approval-api/resource-ownership.js.map +1 -1
- package/dist/do-runner/d1-storage.d.ts +29 -5
- package/dist/do-runner/d1-storage.d.ts.map +1 -1
- package/dist/do-runner/d1-storage.js +244 -84
- package/dist/do-runner/d1-storage.js.map +1 -1
- package/dist/do-runner/do-error-response.d.ts +1 -5
- package/dist/do-runner/do-error-response.d.ts.map +1 -1
- package/dist/do-runner/do-error-response.js +3 -6
- package/dist/do-runner/do-error-response.js.map +1 -1
- package/dist/do-runner/durable-object.d.ts +4 -5
- package/dist/do-runner/durable-object.d.ts.map +1 -1
- package/dist/do-runner/durable-object.js +74 -17
- package/dist/do-runner/durable-object.js.map +1 -1
- package/dist/do-runner/index.d.ts +7 -5
- package/dist/do-runner/index.d.ts.map +1 -1
- package/dist/do-runner/index.js +5 -3
- package/dist/do-runner/index.js.map +1 -1
- package/dist/do-runner/inventory.d.ts +6 -5
- package/dist/do-runner/inventory.d.ts.map +1 -1
- package/dist/do-runner/inventory.js +116 -26
- package/dist/do-runner/inventory.js.map +1 -1
- package/dist/do-runner/legacy-drain-classifier.d.ts +23 -0
- package/dist/do-runner/legacy-drain-classifier.d.ts.map +1 -0
- package/dist/do-runner/legacy-drain-classifier.js +77 -0
- package/dist/do-runner/legacy-drain-classifier.js.map +1 -0
- package/dist/do-runner/own-data-copy.d.ts +2 -0
- package/dist/do-runner/own-data-copy.d.ts.map +1 -0
- package/dist/do-runner/own-data-copy.js +14 -0
- package/dist/do-runner/own-data-copy.js.map +1 -0
- package/dist/do-runner/remote-step-expiry.d.ts +6 -0
- package/dist/do-runner/remote-step-expiry.d.ts.map +1 -0
- package/dist/do-runner/remote-step-expiry.js +5 -0
- package/dist/do-runner/remote-step-expiry.js.map +1 -0
- package/dist/do-runner/remote-step-journal.d.ts +27 -1
- package/dist/do-runner/remote-step-journal.d.ts.map +1 -1
- package/dist/do-runner/remote-step-journal.js +350 -2
- package/dist/do-runner/remote-step-journal.js.map +1 -1
- package/dist/do-runner/runtime.d.ts +19 -1
- package/dist/do-runner/runtime.d.ts.map +1 -1
- package/dist/do-runner/runtime.js +86 -16
- package/dist/do-runner/runtime.js.map +1 -1
- package/dist/do-runner/start-idempotency.d.ts +37 -16
- package/dist/do-runner/start-idempotency.d.ts.map +1 -1
- package/dist/do-runner/start-idempotency.js +280 -38
- package/dist/do-runner/start-idempotency.js.map +1 -1
- package/dist/do-runner/start-reservation-contract.d.ts +9 -5
- package/dist/do-runner/start-reservation-contract.d.ts.map +1 -1
- package/dist/do-runner/start-reservation-contract.js +18 -4
- package/dist/do-runner/start-reservation-contract.js.map +1 -1
- package/dist/do-runner/workflow-snapshot-row.d.ts +3 -0
- package/dist/do-runner/workflow-snapshot-row.d.ts.map +1 -1
- package/dist/do-runner/workflow-snapshot-row.js +28 -0
- package/dist/do-runner/workflow-snapshot-row.js.map +1 -1
- package/dist/host-kit/approval-bridge.d.ts +12 -13
- package/dist/host-kit/approval-bridge.d.ts.map +1 -1
- package/dist/host-kit/approval-bridge.js +69 -21
- package/dist/host-kit/approval-bridge.js.map +1 -1
- package/dist/host-kit/do-response.d.ts.map +1 -1
- package/dist/host-kit/do-response.js +3 -10
- package/dist/host-kit/do-response.js.map +1 -1
- package/dist/host-kit/do-run-topology.d.ts +3 -1
- package/dist/host-kit/do-run-topology.d.ts.map +1 -1
- package/dist/host-kit/do-run-topology.js +8 -0
- package/dist/host-kit/do-run-topology.js.map +1 -1
- package/dist/host-kit/flowsafe-worker.d.ts +17 -10
- package/dist/host-kit/flowsafe-worker.d.ts.map +1 -1
- package/dist/host-kit/flowsafe-worker.js +214 -25
- package/dist/host-kit/flowsafe-worker.js.map +1 -1
- package/dist/host-kit/host-approval-service.d.ts +2 -2
- package/dist/host-kit/host-approval-service.d.ts.map +1 -1
- package/dist/host-kit/host-approval-service.js +2 -2
- package/dist/host-kit/host-approval-service.js.map +1 -1
- package/dist/host-kit/index.d.ts +2 -1
- package/dist/host-kit/index.d.ts.map +1 -1
- package/dist/host-kit/index.js +1 -0
- package/dist/host-kit/index.js.map +1 -1
- package/dist/host-kit/maintenance-capability.d.ts +1 -0
- package/dist/host-kit/maintenance-capability.d.ts.map +1 -1
- package/dist/host-kit/maintenance-capability.js +1 -0
- package/dist/host-kit/maintenance-capability.js.map +1 -1
- package/dist/host-kit/memory-boundary.js +4 -2
- package/dist/host-kit/memory-boundary.js.map +1 -1
- package/dist/host-kit/run-router.d.ts +3 -3
- package/dist/host-kit/run-router.d.ts.map +1 -1
- package/dist/host-kit/run-router.js +10 -17
- package/dist/host-kit/run-router.js.map +1 -1
- package/dist/schedules/router.d.ts.map +1 -1
- package/dist/schedules/router.js +7 -6
- package/dist/schedules/router.js.map +1 -1
- package/dist/schedules/target-policy.d.ts +2 -2
- package/dist/schedules/target-policy.d.ts.map +1 -1
- package/dist/schedules/target-policy.js +3 -0
- package/dist/schedules/target-policy.js.map +1 -1
- package/dist/schedules/tick.d.ts +3 -4
- package/dist/schedules/tick.d.ts.map +1 -1
- package/dist/schedules/tick.js +13 -10
- package/dist/schedules/tick.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# @proofoftech/flowsafe
|
|
2
2
|
|
|
3
|
+
## 0.33.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 01b7ecc: The run-deadline sweep also enforces deadlines on runs whose stored snapshot SQLite cannot parse (rows stored before 0.26.0). Each pass scans up to 10 legacy rows. Runs already past their deadline time out as the maintenance passes reach them after upgrade. Before upgrading, count them with `countUnreadableExpiredRunDeadlines()`.
|
|
8
|
+
|
|
9
|
+
After upgrading, the maintenance status route reports the first page in `unreadableExpiredRunDeadlines`. It caches the lookup for 30 seconds and reports count failures in the same field while still returning maintenance health. The sweep skips non-JSON snapshots. Older versions ignore the new cursor key on rollback.
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 79acfa4: Approval reconciliation treats a stored approval with a later suspension time as current even when the resume count is equal, and withdraws an approval it filed from a status read that the run has already moved past.
|
|
14
|
+
- 9160aae: Admin JSON responses of the Flowsafe Worker and its maintenance object send `cache-control: no-store`. A maintenance duty whose error renders as an empty string records `unknown error`, so health readers no longer reject the record. `assertNoClientMemoryIds` walks wide arrays and objects without spreading them as call arguments, so a large body answers 400 or passes instead of a 500.
|
|
15
|
+
- 3800481: The schedule tick refuses unknown stored target kinds with `unknown-target-kind`, regardless of the host's policy. The built-in schedule target policy also refuses unknown kinds with status 400 and reason `unknown-target-kind`. Both values are now part of `ScheduleTargetDecision`.
|
|
16
|
+
- 98f3053: Agent routes answer `404 run not found` when a run is addressed under a thread or agent it does not belong to, instead of a retryable `503 RUN_STATE_UNREADABLE`.
|
|
17
|
+
|
|
18
|
+
## 0.32.0
|
|
19
|
+
|
|
20
|
+
### Minor Changes
|
|
21
|
+
|
|
22
|
+
- e3ad810: `beginIdempotentStart` accepts `{ signal }` and writes no claim after the signal fires (`IdempotentStartAbortedError`). Maintenance and `POST /admin/settle-unprogressable` abandon unbound reservations idle for five minutes. Same-key retries return `IDEMPOTENT_START_PENDING` while the original start is live and can reclaim the reservation after it unwinds. The drain inventory reports expired and abandoned unbound reservations as informational, and retention purges abandoned reservations on the terminal window.
|
|
23
|
+
|
|
24
|
+
Maintenance and the admin route settle aged bound reservations in pages when a run has a terminal snapshot or a fenced workflow run has no snapshot. The admin response reports the bound settlement count as `settledBound`. The reservation schema stays compatible with older runners, which report abandoned keys as settled.
|
|
25
|
+
|
|
26
|
+
- b759673: `POST /runs/:workflowId/:runId/terminate` can cancel a run during its first leg, including before the first stored row. The same ownership policy applies to reserved and committed runs. An authorized retry can finish recording and cleaning up a run that Mastra already canceled. A run that finishes before cancellation applies returns `409` with reason code `RUN_TERMINAL_CONFLICT`. A terminate replay returns `404` immediately while the start leg is executing. Custom `ResourceOwnershipStore` implementations may add `reservedOwner` to enable first-leg terminate.
|
|
27
|
+
- cb6e2d4: Add `classifyLegacyDrainRow`, a pure classifier for rows of a Flowsafe 0.31.0 `/admin/inventory` response. It can mark expired `pending` and `dispatched` remote steps and expired workflow steps with retained results as `expired-unprogressable` when their runs are no longer live. It also handles remote steps already settled as `deadline-expired` or `terminal-not-success` and old `started` reservations without a live run. Supply the live run IDs from every deployment sharing the database. Take categories and classes from the deployed runner's index and classify every `work` sweep, including the re-sweep after `migration-locked`.
|
|
28
|
+
|
|
29
|
+
After promotion, settlement requires every prefix sharing the database to run this version's maintenance with the remote-step expiry tick and reservation purge configured. Classified rows still reported as `work` in this version's inventory continue to block its drain until their maintenance pass settles them.
|
|
30
|
+
|
|
31
|
+
- a994bf8: Add `RemoteStepJournal.settleExpiredInvocation` and `settleExpiredInvocations`, with an opt-in `remoteStepExpiry` maintenance duty. Configure it with `remoteStepExpiryTick`, `maintenance.remoteStepExpiryIntervalMs`, and `createRemoteStepExpirySweep`. The journal settles open invocations without a retained result as `failed` / `deadline-expired`. Workflow invocations become eligible at their own deadline, when the journal also refuses new results and resume claims. An expired agent invocation becomes eligible when the run is terminal, gone, or past its own deadline. A live agent run with a future or unset run deadline can still use a late result. `recordResult` and `consumePermit` refuse a settled invocation before calling the host verifier.
|
|
32
|
+
|
|
33
|
+
The drain inventory adds the `informational` class and the `expired-remote-steps` category. Eligible unconsumed invocations and eligible settled records appear there. An expired invocation whose permit was consumed remains drain work until settlement. Code that switches over `InventoryCategoryClass` or `InventoryCategory` must handle the new members.
|
|
34
|
+
|
|
35
|
+
- 0dbfba3: Terminating a run or timing it out settles its open remote-step invocations, including when the Durable Object finishes the transition during recovery. Workflow invocations with a retained result settle as `terminal-not-success` and keep the result for audit. Invocations without a result settle as `deadline-expired` once their deadline elapses and as `terminal-not-success` before it. The optional `settleClosedRunInvocations` reader hook handles run close, and the `remoteStepExpiry` duty handles missed settlements.
|
|
36
|
+
|
|
3
37
|
## 0.31.0
|
|
4
38
|
|
|
5
39
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -194,6 +194,12 @@ A timeout records its intent as a terminate does, so the `cancelled` caveat in t
|
|
|
194
194
|
|
|
195
195
|
Monitor `nextDeadlineAt`, `lastDeadlineAt`, `lastDeadlineAttemptAt`, and `lastDeadlineError` on the maintenance health projection. The sweep is bounded by `maintenance.deadlineLimit`, which defaults to 100.
|
|
196
196
|
|
|
197
|
+
### Settle expired remote steps
|
|
198
|
+
|
|
199
|
+
Use `RemoteStepJournal.settleExpiredInvocation(invocationId)` for one invocation or `settleExpiredInvocations({ limit })` for a batch. Settlement records `failed` with `settlementOutcome: 'deadline-expired'` and preserves the permit audit. An open workflow invocation without a retained result becomes eligible for settlement at its own deadline. At that deadline, the journal refuses new workflow results and resume claims. A live agent run may still use a late result while its run deadline is in the future or unset.
|
|
200
|
+
|
|
201
|
+
Configure the `remoteStepExpiry` maintenance duty to sweep the journal. See the [maintenance configuration](https://github.com/ProofOfTechOrg/anchorage/blob/main/docs/deployment-reference.md#alarm-driven-maintenance) and [drain inventory](https://github.com/ProofOfTechOrg/anchorage/blob/main/docs/do-runner-design.md#http-surface-inside-the-object).
|
|
202
|
+
|
|
197
203
|
### Time out one suspension
|
|
198
204
|
|
|
199
205
|
A suspended step can carry its own deadline. It arms one by adding the reserved `SUSPENSION_DEADLINE_PAYLOAD_KEY` to the payload it passes to Mastra's `suspend()`. When the deadline elapses before the awaited signal arrives, the run's own Durable Object resumes that step with a payload the step can tell apart from a real signal. `createStep` below is the import-swapped factory `init()` returns:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-host.d.ts","sourceRoot":"","sources":["../../src/agent-host/thread-host.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAWjE,OAAO,EAGL,KAAK,cAAc,EAQnB,KAAK,oBAAoB,EACzB,KAAK,2BAA2B,EAIjC,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,KAAK,iBAAiB,EAEtB,KAAK,eAAe,EAEpB,KAAK,kBAAkB,EAIvB,KAAK,iCAAiC,EAIvC,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,KAAK,2BAA2B,EAIjC,MAAM,8BAA8B,CAAC;AAYtC,OAAO,EAGL,KAAK,sBAAsB,EAG3B,KAAK,UAAU,EAIf,KAAK,mBAAmB,EAExB,KAAK,WAAW,EACjB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAGL,KAAK,iBAAiB,EAEvB,MAAM,qCAAqC,CAAC;AAU7C,OAAO,EAEL,KAAK,SAAS,EACf,MAAM,oCAAoC,CAAC;AAK5C,OAAO,EAEL,KAAK,uBAAuB,EAE7B,MAAM,4CAA4C,CAAC;AAWpD,OAAO,EAGL,KAAK,4BAA4B,EAClC,MAAM,sBAAsB,CAAC;AAM9B,OAAO,KAAK,EACV,WAAW,EAEX,gBAAgB,EAEhB,2BAA2B,EAE5B,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,uBAAuB;IACtC,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC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AAC,CAAC;IACpB,KAAK,CACH,KAAK,EAAE,WAAW,EAClB,KAAK,EAAE,qBAAqB,GAC3B,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC7B,iBAAiB,CACf,KAAK,EAAE,WAAW,EAClB,KAAK,EAAE;QACL,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,cAAc,CAAC;KAC3B,GACA,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC7B;;;;OAIG;IACH,WAAW,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC,CAAC;IACvE,uEAAuE;IACvE,sBAAsB,CACpB,KAAK,EAAE,WAAW,EAClB,KAAK,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAC5D,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;IACnC,gBAAgB,CAAC,KAAK,EAAE,wBAAwB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjE,4BAA4B,CAC1B,KAAK,EAAE,WAAW,EAClB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,kBAAkB,GAAG,YAAY,CAAC,CAAC;IAC9C,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;CACvE;AA0WD,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,sBAAsB,GAC9B,eAAe,CA0+FjB"}
|
|
@@ -787,9 +787,11 @@ export function createThreadAgentHost(options) {
|
|
|
787
787
|
return assertSelectedResource(await durable.authoritativeAgentStartState(scope.init.runtime, scope.threadId, ref.runId, { includeLegacy: true }));
|
|
788
788
|
return assertSelectedResource(await durable.authoritativeAgentStartState(scope.init.runtime, scope.threadId, ref.runId));
|
|
789
789
|
}
|
|
790
|
-
const
|
|
790
|
+
const routeAgentState = async (scope, ref, readOptions) => {
|
|
791
791
|
try {
|
|
792
|
-
return
|
|
792
|
+
return readOptions
|
|
793
|
+
? await selectedAgentState(scope, ref, readOptions)
|
|
794
|
+
: await selectedAgentState(scope, ref);
|
|
793
795
|
}
|
|
794
796
|
catch (error) {
|
|
795
797
|
if (error instanceof AgentRunSelectorMismatchError)
|
|
@@ -983,7 +985,7 @@ export function createThreadAgentHost(options) {
|
|
|
983
985
|
return summary;
|
|
984
986
|
});
|
|
985
987
|
const finalizeTerminalAgentState = async (scope, ref, state, expectedRecord) => {
|
|
986
|
-
const selected = state ?? (await
|
|
988
|
+
const selected = state ?? (await routeAgentState(scope, ref, { includeLegacy: true }));
|
|
987
989
|
if (!selected ||
|
|
988
990
|
selected.kind === 'initial' ||
|
|
989
991
|
!isTerminalRunStatus(selected.summary.status))
|
|
@@ -1097,10 +1099,8 @@ export function createThreadAgentHost(options) {
|
|
|
1097
1099
|
approvals,
|
|
1098
1100
|
};
|
|
1099
1101
|
};
|
|
1100
|
-
const snapshotExecutionFor = async (scope, ref,
|
|
1101
|
-
const state =
|
|
1102
|
-
? await selectedAgentState(scope, ref, { includeLegacy: true })
|
|
1103
|
-
: knownState;
|
|
1102
|
+
const snapshotExecutionFor = async (scope, ref, readAgentState) => {
|
|
1103
|
+
const state = await readAgentState(scope, ref, { includeLegacy: true });
|
|
1104
1104
|
if (!state)
|
|
1105
1105
|
throw new AgentHostRequestError(404, 'run not found');
|
|
1106
1106
|
if (state.kind === 'initial')
|
|
@@ -1111,13 +1111,13 @@ export function createThreadAgentHost(options) {
|
|
|
1111
1111
|
safeContext: sanitizeStoredAgentContext(state.snapshot.requestContext),
|
|
1112
1112
|
};
|
|
1113
1113
|
};
|
|
1114
|
-
const readRemoteStepHostAuthority = async (scope, invocation) => {
|
|
1114
|
+
const readRemoteStepHostAuthority = async (scope, invocation, readAgentState) => {
|
|
1115
1115
|
const ref = {
|
|
1116
1116
|
agentId: invocation.agentId,
|
|
1117
1117
|
resourceId: invocation.resourceId,
|
|
1118
1118
|
runId: invocation.runId,
|
|
1119
1119
|
};
|
|
1120
|
-
const selected = await snapshotExecutionFor(scope, ref);
|
|
1120
|
+
const selected = await snapshotExecutionFor(scope, ref, readAgentState);
|
|
1121
1121
|
const state = selected.state;
|
|
1122
1122
|
if (state.kind !== 'result' ||
|
|
1123
1123
|
state.storage !== 'd1' ||
|
|
@@ -1329,7 +1329,7 @@ export function createThreadAgentHost(options) {
|
|
|
1329
1329
|
operation.state === 'unresolved' ||
|
|
1330
1330
|
operation.state === 'prepared')
|
|
1331
1331
|
return 'unresolved';
|
|
1332
|
-
await readRemoteStepHostAuthority(scope, invocation);
|
|
1332
|
+
await readRemoteStepHostAuthority(scope, invocation, selectedAgentState);
|
|
1333
1333
|
const retained = await profile.journal.readRetainedResult(invocationId);
|
|
1334
1334
|
if (!retained || invocation.status !== 'result-retained')
|
|
1335
1335
|
throw new AgentHostRequestError(409, 'remote step result is unavailable');
|
|
@@ -1852,6 +1852,7 @@ export function createThreadAgentHost(options) {
|
|
|
1852
1852
|
threadId: scope.threadId,
|
|
1853
1853
|
resourceId: preflightUrl.searchParams.get('resourceId'),
|
|
1854
1854
|
});
|
|
1855
|
+
// Start admission treats a replay 404 as proof the snapshot is absent.
|
|
1855
1856
|
const state = await selectedAgentState(scope, ref);
|
|
1856
1857
|
if (state &&
|
|
1857
1858
|
(state.execution.owner.kind !== scope.principal.kind ||
|
|
@@ -1880,9 +1881,7 @@ export function createThreadAgentHost(options) {
|
|
|
1880
1881
|
if (storedRun && storedRun.agentId !== ref.agentId) {
|
|
1881
1882
|
throw new AgentHostRequestError(404, 'run not found');
|
|
1882
1883
|
}
|
|
1883
|
-
await snapshotExecutionFor(scope, ref,
|
|
1884
|
-
? undefined
|
|
1885
|
-
: await publicAgentState(scope, ref));
|
|
1884
|
+
await snapshotExecutionFor(scope, ref, routeAgentState);
|
|
1886
1885
|
const owner = await options.resourceAccess().owner('run', ref.runId);
|
|
1887
1886
|
// Cancels outside the dispatch lock, which a running start or resume
|
|
1888
1887
|
// leg holds; the intent it records refuses a resume queued behind the
|
|
@@ -2023,7 +2022,7 @@ export function createThreadAgentHost(options) {
|
|
|
2023
2022
|
invocation.status !== 'result-retained' ||
|
|
2024
2023
|
invocation.deadlineAt <= Date.now())
|
|
2025
2024
|
throw new AgentHostRequestError(404, 'invocation not found');
|
|
2026
|
-
const { ref, selected, state, stored } = await readRemoteStepHostAuthority(scope, invocation);
|
|
2025
|
+
const { ref, selected, state, stored } = await readRemoteStepHostAuthority(scope, invocation, routeAgentState);
|
|
2027
2026
|
const key = invocation.stepPath.join('.');
|
|
2028
2027
|
const summary = state.summary;
|
|
2029
2028
|
const payload = summary.suspendPayload !== null &&
|
|
@@ -2166,7 +2165,7 @@ export function createThreadAgentHost(options) {
|
|
|
2166
2165
|
if (resumeBody) {
|
|
2167
2166
|
const body = resumeBody;
|
|
2168
2167
|
const ref = runRef(scope, body);
|
|
2169
|
-
const snapshotExecution = await snapshotExecutionFor(scope, ref);
|
|
2168
|
+
const snapshotExecution = await snapshotExecutionFor(scope, ref, routeAgentState);
|
|
2170
2169
|
const { summary: latest } = await statusFor(scope, ref, snapshotExecution.state);
|
|
2171
2170
|
const { state } = snapshotExecution;
|
|
2172
2171
|
// An ended run's record is deleted, so only the snapshot's execution
|
|
@@ -2280,7 +2279,7 @@ export function createThreadAgentHost(options) {
|
|
|
2280
2279
|
}
|
|
2281
2280
|
return json(await statusFor(scope, ref));
|
|
2282
2281
|
}
|
|
2283
|
-
return json(await statusFor(scope, ref, await
|
|
2282
|
+
return json(await statusFor(scope, ref, await routeAgentState(scope, ref, { includeLegacy: true })));
|
|
2284
2283
|
}
|
|
2285
2284
|
if (segments.length === 4 &&
|
|
2286
2285
|
segments[3] === 'terminate' &&
|
|
@@ -2291,7 +2290,7 @@ export function createThreadAgentHost(options) {
|
|
|
2291
2290
|
if (storedRun && storedRun.agentId !== ref.agentId) {
|
|
2292
2291
|
throw new AgentHostRequestError(404, 'run not found');
|
|
2293
2292
|
}
|
|
2294
|
-
await snapshotExecutionFor(scope, ref,
|
|
2293
|
+
await snapshotExecutionFor(scope, ref, routeAgentState);
|
|
2295
2294
|
const owner = await options.resourceAccess().owner('run', ref.runId);
|
|
2296
2295
|
if (replayOnly) {
|
|
2297
2296
|
const existing = await scopedRuntime.status(await workflowIdFor(scope, ref.agentId), ref.runId);
|
|
@@ -2317,7 +2316,7 @@ export function createThreadAgentHost(options) {
|
|
|
2317
2316
|
error: errorMessageOf(error),
|
|
2318
2317
|
}));
|
|
2319
2318
|
}
|
|
2320
|
-
const selected = await
|
|
2319
|
+
const selected = await routeAgentState(scope, ref, {
|
|
2321
2320
|
includeLegacy: true,
|
|
2322
2321
|
});
|
|
2323
2322
|
if (!selected || selected.kind === 'initial')
|
|
@@ -2408,7 +2407,7 @@ export function createThreadAgentHost(options) {
|
|
|
2408
2407
|
if (segments.length === 4 &&
|
|
2409
2408
|
segments[3] === 'stream' &&
|
|
2410
2409
|
request.method === 'GET') {
|
|
2411
|
-
const run = await statusFor(scope, ref, await
|
|
2410
|
+
const run = await statusFor(scope, ref, await routeAgentState(scope, ref, { includeLegacy: true }));
|
|
2412
2411
|
const offset = Number(url.searchParams.get('offset') ?? '0');
|
|
2413
2412
|
if (!Number.isSafeInteger(offset) || offset < 0) {
|
|
2414
2413
|
throw new AgentHostRequestError(400, 'invalid stream offset');
|