@proofoftech/flowsafe 0.21.0 → 0.22.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.
Files changed (61) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +6 -8
  3. package/dist/agent-host/thread-host.d.ts.map +1 -1
  4. package/dist/agent-host/thread-host.js +35 -33
  5. package/dist/agent-host/thread-host.js.map +1 -1
  6. package/dist/agent-host/thread-topology.d.ts.map +1 -1
  7. package/dist/agent-host/thread-topology.js +11 -9
  8. package/dist/agent-host/thread-topology.js.map +1 -1
  9. package/dist/agent-runner/durable-agent-runner.d.ts +21 -30
  10. package/dist/agent-runner/durable-agent-runner.d.ts.map +1 -1
  11. package/dist/agent-runner/durable-agent-runner.js +58 -75
  12. package/dist/agent-runner/durable-agent-runner.js.map +1 -1
  13. package/dist/approval-api/actor-context.js +3 -3
  14. package/dist/approval-api/actor-context.js.map +1 -1
  15. package/dist/approval-api/service.d.ts +6 -9
  16. package/dist/approval-api/service.d.ts.map +1 -1
  17. package/dist/approval-api/service.js +6 -9
  18. package/dist/approval-api/service.js.map +1 -1
  19. package/dist/background-tasks/d1-storage.js +1 -1
  20. package/dist/background-tasks/d1-storage.js.map +1 -1
  21. package/dist/background-tasks/host.d.ts.map +1 -1
  22. package/dist/background-tasks/host.js +3 -2
  23. package/dist/background-tasks/host.js.map +1 -1
  24. package/dist/do-runner/d1-storage.d.ts +4 -2
  25. package/dist/do-runner/d1-storage.d.ts.map +1 -1
  26. package/dist/do-runner/d1-storage.js +4 -2
  27. package/dist/do-runner/d1-storage.js.map +1 -1
  28. package/dist/do-runner/durable-object.d.ts.map +1 -1
  29. package/dist/do-runner/durable-object.js +21 -21
  30. package/dist/do-runner/durable-object.js.map +1 -1
  31. package/dist/do-runner/execution-context.d.ts +5 -1
  32. package/dist/do-runner/execution-context.d.ts.map +1 -1
  33. package/dist/do-runner/execution-context.js +5 -1
  34. package/dist/do-runner/execution-context.js.map +1 -1
  35. package/dist/do-runner/execution-fence.js +2 -2
  36. package/dist/do-runner/execution-fence.js.map +1 -1
  37. package/dist/do-runner/run-lifecycle.js +6 -6
  38. package/dist/do-runner/run-lifecycle.js.map +1 -1
  39. package/dist/do-runner/start-idempotency.js +4 -4
  40. package/dist/do-runner/start-idempotency.js.map +1 -1
  41. package/dist/host-kit/approval-bridge.d.ts +8 -8
  42. package/dist/host-kit/approval-bridge.js +8 -8
  43. package/dist/host-kit/flowsafe-worker.d.ts.map +1 -1
  44. package/dist/host-kit/flowsafe-worker.js +5 -0
  45. package/dist/host-kit/flowsafe-worker.js.map +1 -1
  46. package/dist/schedules/schedules-d1.js +1 -1
  47. package/dist/schedules/tick.d.ts +1 -8
  48. package/dist/schedules/tick.d.ts.map +1 -1
  49. package/dist/schedules/tick.js +8 -19
  50. package/dist/schedules/tick.js.map +1 -1
  51. package/dist/signals/d1-shared.js +1 -1
  52. package/dist/signals/notification-dispatch.d.ts +1 -12
  53. package/dist/signals/notification-dispatch.d.ts.map +1 -1
  54. package/dist/signals/notification-dispatch.js +0 -53
  55. package/dist/signals/notification-dispatch.js.map +1 -1
  56. package/dist/signals/thread-do-routes.d.ts.map +1 -1
  57. package/dist/signals/thread-do-routes.js +11 -21
  58. package/dist/signals/thread-do-routes.js.map +1 -1
  59. package/package.json +6 -7
  60. package/scripts/seed-deployment-identity.mjs +25 -11
  61. package/patches/@mastra__core@1.53.0.patch +0 -54
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @proofoftech/flowsafe
2
2
 
3
+ ## 0.22.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 36c60c8: Require `@mastra/core` 1.67.0 exactly (previously 1.53.0). The peer is exact, so every consumer must move to 1.67.0 as well; this is breaking for consumers pinned to 1.53.0. 1.67.0 bundles for Cloudflare Workers and Vite again — mastra-ai/mastra#20638, the dynamic-import regression that held the pin at 1.53.0, closed upstream.
8
+
9
+ `@mastra/cloudflare-d1` moves from 1.1.1 to 1.3.2, whose own peer requires a core newer than 1.53.0. FlowSafe's `@proofoftech/breakwater` peer floor rises to `>=0.15.0 <1.0.0` in step, that being the first Breakwater release built against the same core.
10
+
11
+ The `@mastra/core` patch FlowSafe shipped under `patches/` is retired: 1.67.0 carries both fixes upstream (mastra-ai/mastra#23693, mastra-ai/mastra#23694). The patch file is gone from the published package, and so are the two refusals that required it — FlowSafe no longer refuses to construct a delivering notification dispatch tick, nor notification ingestion and dispatch requests, on an install whose core lacks the patch. Consequence for anyone running a core outside the declared peer without having applied the patch: a notification `source` named after an `Object.prototype` member is miscounted in the summary core renders, and its source delivery policy resolves the inherited member instead of the configured priority or default action. That configuration was unsupported before and remains so, but it now fails silently rather than loudly. Application roots that copied the patch into their own `patches/` should drop it along with the `patchedDependencies` entry or `postinstall` script that applied it.
12
+
13
+ `createD1Storage({ domains })` composes the two storage domains 1.67.0 adds, `workflowDefinitions` and `knowledge`, through the same override seam as the other domains. `@mastra/cloudflare-d1` backs neither, so each resolves `undefined` unless a host supplies one through that seam.
14
+
15
+ The workspace lockfile behind this release was resolved once with pnpm's seven-day minimum-release-age gate overridden for that resolution only. Five newly resolved versions were younger than the gate at resolution on 2026-09-19: `@mastra/core` 1.67.0 and `@mastra/schema-compat` 1.3.10 (published 2026-09-15), which the workspace's standing `@mastra/*` exclude admits with the gate on, and `posthog-node` 5.52.4 (2026-09-15), `@posthog/types` 1.412.2 (2026-09-17) and `@posthog/core` 1.55.0 (2026-09-18), which the override alone admitted. None of the five declares a lifecycle script or ships a native component; all five carry npm provenance attestations (SLSA v1, published from GitHub Actions); and `posthog-node`, with `@posthog/core` and `@posthog/types` beneath it, is a hard dependency of `@mastra/core` that ships inside a bundled Worker.
16
+
17
+ The private `showcase` and `anchorage-agent-starter` packages move to the same core.
18
+
19
+ ### Patch Changes
20
+
21
+ - 36cfdc2: Keep `flowsafe-provision` inert when imported from stdin, eval or print programs, and virtual workers, even when an entry name aliases the script. Direct execution, file and directory symlinks, and file workers under eval parents continue to invoke the CLI.
22
+
3
23
  ## 0.21.0
4
24
 
5
25
  ### Minor Changes
package/README.md CHANGED
@@ -9,7 +9,7 @@ Flowsafe runs Mastra workflows and agents through Cloudflare Durable Objects, st
9
9
  ## Install
10
10
 
11
11
  ```bash
12
- npm install @mastra/core@1.53.0 @proofoftech/flowsafe
12
+ npm install @mastra/core@1.67.0 @proofoftech/flowsafe
13
13
  ```
14
14
 
15
15
  Install `@proofoftech/breakwater` when resumed steps call approval-protected connectors:
@@ -25,9 +25,9 @@ Compatibility:
25
25
  - Node.js 22.13.0 or later (engine range `>=22.13.0`)
26
26
  - ESM only
27
27
  - TypeScript `moduleResolution: "NodeNext"`, `"Node16"`, or `"Bundler"`
28
- - `@mastra/core` `1.53.0`, with the patch this package ships under `patches/` applied at your application root — see [Apply the flowsafe patch to @mastra/core](https://github.com/ProofOfTechOrg/anchorage/blob/main/docs/getting-started.md#apply-the-flowsafe-patch-to-mastracore)
28
+ - `@mastra/core` `1.67.0`
29
29
  - `react` and `react-dom` `>=18 <20` (React 18 or 19) for the optional approval UI
30
- - `@proofoftech/breakwater` `>=0.13.0 <1.0.0` when used
30
+ - `@proofoftech/breakwater` `>=0.15.0 <1.0.0` when used
31
31
  - host-provided Wrangler `>=4.118 <5` for the optional `flowsafe-provision` CLI
32
32
 
33
33
  ## Choose an export
@@ -103,7 +103,7 @@ export class AppRunner extends DurableObjectRunner<Env> {
103
103
  }
104
104
  ```
105
105
 
106
- `init()` creates D1-backed Mastra storage from the conventional `DB` binding unless you inject storage. Workflow definitions use the same `createWorkflow()` and `createStep()` shape as Mastra. Flowsafe pins `@mastra/cloudflare-d1` 1.1.1 because the shipped D1 storage is written against that release's domain surface: it subclasses the adapter's background-tasks domain to apply the `TaskFilter.resourceId` predicate the adapter declares but omits from its SQL builder, and hand-writes the schedules, notifications, and thread-state domains the adapter does not ship at all. The pin also holds the adapter on its `@cloudflare/workers-types` v4 peer, which is the major Flowsafe still builds against.
106
+ `init()` creates D1-backed Mastra storage from the conventional `DB` binding unless you inject storage. Workflow definitions use the same `createWorkflow()` and `createStep()` shape as Mastra. Flowsafe pins `@mastra/cloudflare-d1` 1.3.2 because the shipped D1 storage is written against that release's domain surface: it subclasses the adapter's background-tasks domain to apply the `TaskFilter.resourceId` predicate the adapter accepts but omits from its SQL builder, and hand-writes the schedules, notifications, and thread-state domains the adapter does not ship at all. `D1StorageOptions.domains` accepts host-supplied `workflowDefinitions` and `knowledge` domains, which have no D1-backed defaults. The pin also holds the adapter on its `@cloudflare/workers-types` v4 peer, which is the major Flowsafe still builds against.
107
107
 
108
108
  If the deployment uses a table prefix, pass one shared constant to storage and host maintenance:
109
109
 
@@ -451,9 +451,9 @@ A policy failure is opaque: direct delivery returns 503, schedule state is left
451
451
 
452
452
  Configure the same positive safe-integer `maxDeliveryAttempts` on `createNotificationDispatchTick()` and `createThreadSignalRoutes()`. Both default to `DEFAULT_MAX_NOTIFICATION_DELIVERY_ATTEMPTS`. A recorded failure at the bound discards the notification with `deliveryReason: "delivery-attempts-exhausted"`, retaining its count and last error. An already-exhausted row is never sent; its discard is conditional on the observed record remaining current. Below the bound, existing retry delays apply.
453
453
 
454
- Dispatch requires `NotificationDeliveryStorage`; `D1NotificationsStorage` implements it. A custom store's `updateNotificationDeliveryIfUnchanged()` must compare the captured observation and apply the failure patch atomically against its other writers. Ordinary Core storage still serves notification ingestion; the `@mastra/core` patch is required for either path. See the [delivery and receipt guide](https://github.com/ProofOfTechOrg/anchorage/blob/main/docs/durable-agents.md#bound-notification-delivery) for custom-store migration, lost responses and receipt retention.
454
+ Dispatch requires `NotificationDeliveryStorage`; `D1NotificationsStorage` implements it. A custom store's `updateNotificationDeliveryIfUnchanged()` must compare the captured observation and apply the failure patch atomically against its other writers. Ordinary Core storage still serves notification ingestion. See the [delivery and receipt guide](https://github.com/ProofOfTechOrg/anchorage/blob/main/docs/durable-agents.md#bound-notification-delivery) for custom-store migration, lost responses and receipt retention.
455
455
 
456
- Summary source counts and a configured source delivery policy read own properties only where the shipped `@mastra/core` patch is applied; without it a source named after an `Object.prototype` member is miscounted in the summary core renders and selects an inherited policy entry instead of the configured priority or default action. Flowsafe refuses notification ingestion and dispatch on an unpatched install, and refuses to construct a notification dispatch tick that does delivery work.
456
+ Summary source counts and a configured source delivery policy read own properties: the declared `@mastra/core` peer guards both lookups, so a source named after an `Object.prototype` member is counted under its own key and resolves the configured priority or default action. A core outside the declared peer range that predates [mastra-ai/mastra#23693](https://github.com/mastra-ai/mastra/issues/23693) and [mastra-ai/mastra#23694](https://github.com/mastra-ai/mastra/issues/23694) miscounts such a source and selects the inherited policy entry instead.
457
457
 
458
458
  Adapt Breakwater without adding a FlowSafe runtime dependency on it:
459
459
 
@@ -589,5 +589,3 @@ pnpm --filter @proofoftech/flowsafe spike:verify:llm
589
589
  ## License
590
590
 
591
591
  Apache-2.0.
592
-
593
- `patches/@mastra__core@1.53.0.patch` is a modification of `@mastra/core` `1.53.0`, which is licensed under Apache-2.0 and copyright its authors. It changes that package's published runtime chunks to correct the two defects reported as mastra-ai/mastra#23693 and mastra-ai/mastra#23694.
@@ -1 +1 @@
1
- {"version":3,"file":"thread-host.d.ts","sourceRoot":"","sources":["../../src/agent-host/thread-host.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAOjE,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,EAGjC,MAAM,8BAA8B,CAAC;AAUtC,OAAO,EAGL,KAAK,sBAAsB,EAC3B,KAAK,UAAU,EAIf,KAAK,mBAAmB,EAExB,KAAK,WAAW,EACjB,MAAM,uBAAuB,CAAC;AAY/B,OAAO,EAE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Ac,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,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;CACvE;AA4SD,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,sBAAsB,GAC9B,eAAe,CAuwEjB"}
@@ -451,13 +451,13 @@ export function createThreadAgentHost(options) {
451
451
  return undefined;
452
452
  for (const key of records.keys()) {
453
453
  const runId = key.slice(AGENT_RUN_STORAGE_KEY_PREFIX.length);
454
- const record = await readRun(runId);
455
- if (!record)
454
+ const runRecord = await readRun(runId);
455
+ if (!runRecord)
456
456
  continue;
457
457
  if (executions.has(runId))
458
- return { runId, principal: record.principal };
458
+ return { runId, principal: runRecord.principal };
459
459
  const state = await selectedAgentState(scope, {
460
- agentId: record.agentId,
460
+ agentId: runRecord.agentId,
461
461
  resourceId: resourceIdFromKey(scope.threadId),
462
462
  runId,
463
463
  }, { includeLegacy: true });
@@ -465,11 +465,11 @@ export function createThreadAgentHost(options) {
465
465
  state.kind === 'initial' ||
466
466
  !isTerminalRunStatus(state.summary.status) ||
467
467
  (state.kind === 'legacy' && !isTerminalRunStatus(state.snapshot.status)))
468
- return { runId, principal: record.principal };
468
+ return { runId, principal: runRecord.principal };
469
469
  const recovery = await storage.get(ownerRecoveryKey(runId));
470
470
  if (recovery !== undefined)
471
- return { runId, principal: record.principal };
472
- await withRecoveryLock(() => finalizeTerminalRecord(scope, runId, record, state));
471
+ return { runId, principal: runRecord.principal };
472
+ await withRecoveryLock(() => finalizeTerminalRecord(scope, runId, runRecord, state));
473
473
  }
474
474
  return undefined;
475
475
  };
@@ -509,14 +509,14 @@ export function createThreadAgentHost(options) {
509
509
  }
510
510
  if (!threaded)
511
511
  throw new AgentHostRequestError(404, 'run not found');
512
- const [threadOwner, resourceOwner] = await Promise.all([
512
+ const [threadOwner, resolvedResourceOwner] = await Promise.all([
513
513
  ownership.owner('thread', ref.threadId),
514
514
  ownership.owner('resource', ref.resourceId),
515
515
  ]);
516
516
  if (!threadOwner ||
517
- !resourceOwner ||
518
- threadOwner.kind !== resourceOwner.kind ||
519
- threadOwner.id !== resourceOwner.id) {
517
+ !resolvedResourceOwner ||
518
+ threadOwner.kind !== resolvedResourceOwner.kind ||
519
+ threadOwner.id !== resolvedResourceOwner.id) {
520
520
  throw new AgentHostRequestError(404, 'run not found');
521
521
  }
522
522
  return { owner: threadOwner };
@@ -943,12 +943,12 @@ export function createThreadAgentHost(options) {
943
943
  runId: summary.runId,
944
944
  }, principalActor(systemPrincipal()));
945
945
  const keys = new Set((summary.suspended ?? []).map((path) => path.join('.')));
946
- return records.filter((record) => {
947
- const key = record.stepPath?.join('.');
946
+ return records.filter((runRecord) => {
947
+ const key = runRecord.stepPath?.join('.');
948
948
  return (key !== undefined &&
949
949
  keys.has(key) &&
950
- record.suspendedAt === summary.suspendedAt?.[key] &&
951
- record.resumeCount === summary.resumeCount?.[key]);
950
+ runRecord.suspendedAt === summary.suspendedAt?.[key] &&
951
+ runRecord.resumeCount === summary.resumeCount?.[key]);
952
952
  });
953
953
  };
954
954
  const envelopeFor = async (scope, ref, principal, summary) => {
@@ -1110,13 +1110,13 @@ export function createThreadAgentHost(options) {
1110
1110
  throw new ExecutionFenceUnreadableError('run start recovery is unresolved');
1111
1111
  }
1112
1112
  const storage = options.stateStorage();
1113
- const binding = await readBinding(), record = await readRun(stored.runId);
1113
+ const binding = await readBinding(), runRecord = await readRun(stored.runId);
1114
1114
  await assertRecoveryCurrent(stored);
1115
1115
  const matches = binding?.agentId === stored.agentId &&
1116
1116
  binding.resourceId === stored.resourceId;
1117
- if (record && !sameRunRecord(record, stored.runRecord))
1117
+ if (runRecord && !sameRunRecord(runRecord, stored.runRecord))
1118
1118
  throw new Error('agent run record changed');
1119
- if (record)
1119
+ if (runRecord)
1120
1120
  await deleteAgentRunRecord(storage, stored.runId);
1121
1121
  if (!stored.bindingPreexisting && matches)
1122
1122
  await deleteAgentThreadBinding(storage, {
@@ -1336,7 +1336,7 @@ export function createThreadAgentHost(options) {
1336
1336
  throw new AgentHostRequestError(409, 'thread is bound to another agent');
1337
1337
  }
1338
1338
  }
1339
- const recovery = {
1339
+ const recoveryState = {
1340
1340
  version: 2,
1341
1341
  phase: 'preparing',
1342
1342
  runRecord: stored,
@@ -1356,14 +1356,14 @@ export function createThreadAgentHost(options) {
1356
1356
  .owner(claim.kind, claim.resourceId)))).some((registered) => registered !== undefined)) {
1357
1357
  throw new AgentHostRequestError(404, 'run not found');
1358
1358
  }
1359
- await armOwnerRecovery(recovery);
1359
+ await armOwnerRecovery(recoveryState);
1360
1360
  if (!(await options
1361
1361
  .resourceAccess()
1362
- .reserveAll(claims, owner, recovery.token))) {
1362
+ .reserveAll(claims, owner, recoveryState.token))) {
1363
1363
  await options
1364
1364
  .resourceAccess()
1365
- .settleReservation(recovery.token, claims);
1366
- await clearOwnerRecovery(recovery);
1365
+ .settleReservation(recoveryState.token, claims);
1366
+ await clearOwnerRecovery(recoveryState);
1367
1367
  throw new AgentHostRequestError(404, 'run not found');
1368
1368
  }
1369
1369
  if (threaded && !existing) {
@@ -1374,7 +1374,7 @@ export function createThreadAgentHost(options) {
1374
1374
  });
1375
1375
  }
1376
1376
  await writeAgentRunRecord(options.stateStorage(), ref.runId, stored);
1377
- return recovery;
1377
+ return recoveryState;
1378
1378
  });
1379
1379
  // From here to the finally below, this object IS the run's execution.
1380
1380
  // Registered BEFORE the stream so the window a replaying start asks
@@ -1429,9 +1429,11 @@ export function createThreadAgentHost(options) {
1429
1429
  catch (error) {
1430
1430
  unwoundExecutions.add(execution);
1431
1431
  try {
1432
- const current = await options.stateStorage().get(recoveryKey);
1433
- if (current !== undefined) {
1434
- const latest = validateOwnerRecovery(scope.threadId, recoveryKey, current);
1432
+ const storedRecovery = await options
1433
+ .stateStorage()
1434
+ .get(recoveryKey);
1435
+ if (storedRecovery !== undefined) {
1436
+ const latest = validateOwnerRecovery(scope.threadId, recoveryKey, storedRecovery);
1435
1437
  if (!sameOwnerRecovery(latest, recovery))
1436
1438
  throw new Error('agent owner recovery changed');
1437
1439
  const summary = await recoverOwner(scope, recoveryKey, latest, execution, error);
@@ -1739,7 +1741,7 @@ export function createThreadAgentHost(options) {
1739
1741
  if (segments.length === 4 &&
1740
1742
  segments[3] === 'terminate' &&
1741
1743
  request.method === 'POST') {
1742
- const runtime = scope.init.runtime;
1744
+ const scopedRuntime = scope.init.runtime;
1743
1745
  const replayOnly = url.searchParams.get('replay') === '1';
1744
1746
  const storedRun = await readRun(ref.runId);
1745
1747
  if (storedRun && storedRun.agentId !== ref.agentId) {
@@ -1750,17 +1752,17 @@ export function createThreadAgentHost(options) {
1750
1752
  .resourceAccess()
1751
1753
  .owner('run', ref.runId);
1752
1754
  if (!replayOnly && !preflightedTermination) {
1753
- await runtime.cancelActiveExecution(await workflowIdFor(scope, ref.agentId), ref.runId, 'cancelled', [scope.principal, preflightOwner ?? scope.principal]);
1755
+ await scopedRuntime.cancelActiveExecution(await workflowIdFor(scope, ref.agentId), ref.runId, 'cancelled', [scope.principal, preflightOwner ?? scope.principal]);
1754
1756
  }
1755
1757
  const owner = await options.resourceAccess().owner('run', ref.runId);
1756
1758
  if (replayOnly) {
1757
- const existing = await runtime.status(await workflowIdFor(scope, ref.agentId), ref.runId);
1759
+ const existing = await scopedRuntime.status(await workflowIdFor(scope, ref.agentId), ref.runId);
1758
1760
  if (existing?.status !== 'cancelled' &&
1759
1761
  existing?.status !== 'timed_out') {
1760
1762
  throw new AgentHostRequestError(404, 'run not found');
1761
1763
  }
1762
1764
  }
1763
- const transition = await runtime.terminateAsPrincipal(await workflowIdFor(scope, ref.agentId), ref.runId, scope.principal, owner ?? scope.principal);
1765
+ const transition = await scopedRuntime.terminateAsPrincipal(await workflowIdFor(scope, ref.agentId), ref.runId, scope.principal, owner ?? scope.principal);
1764
1766
  const selected = await selectedAgentState(scope, ref, {
1765
1767
  includeLegacy: true,
1766
1768
  });
@@ -1802,7 +1804,7 @@ export function createThreadAgentHost(options) {
1802
1804
  if (guard)
1803
1805
  await guard();
1804
1806
  if (selected.kind !== 'legacy')
1805
- await runtime.settleStartExecution(selected);
1807
+ await scopedRuntime.settleStartExecution(selected);
1806
1808
  let summary = legacy?.summary ?? transition.summary;
1807
1809
  if (!cleanup.cleanupCompleted) {
1808
1810
  if (guard)
@@ -1832,7 +1834,7 @@ export function createThreadAgentHost(options) {
1832
1834
  }
1833
1835
  if (guard)
1834
1836
  await guard();
1835
- summary = await runtime.completeTerminalCleanup(workflowId, ref.runId, cleanup.revision);
1837
+ summary = await scopedRuntime.completeTerminalCleanup(workflowId, ref.runId, cleanup.revision);
1836
1838
  }
1837
1839
  if (legacy) {
1838
1840
  if (guard)