@proofoftech/flowsafe 0.19.0 → 0.20.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 +25 -0
- package/README.md +15 -0
- package/deployment-identity-protocol.d.mts +45 -1
- package/deployment-identity-protocol.mjs +169 -5
- package/dist/agent-host/index.d.ts +1 -1
- package/dist/agent-host/index.d.ts.map +1 -1
- package/dist/agent-host/index.js.map +1 -1
- package/dist/agent-host/router.d.ts.map +1 -1
- package/dist/agent-host/router.js +6 -2
- package/dist/agent-host/router.js.map +1 -1
- package/dist/agent-host/thread-host.d.ts +11 -0
- package/dist/agent-host/thread-host.d.ts.map +1 -1
- package/dist/agent-host/thread-host.js +53 -1
- package/dist/agent-host/thread-host.js.map +1 -1
- package/dist/agent-host/thread-topology.d.ts +35 -1
- package/dist/agent-host/thread-topology.d.ts.map +1 -1
- package/dist/agent-host/thread-topology.js +103 -7
- package/dist/agent-host/thread-topology.js.map +1 -1
- package/dist/agent-runner/durable-agent-runner.d.ts +19 -4
- package/dist/agent-runner/durable-agent-runner.d.ts.map +1 -1
- package/dist/agent-runner/durable-agent-runner.js +58 -28
- package/dist/agent-runner/durable-agent-runner.js.map +1 -1
- package/dist/approval-api/d1-store.d.ts.map +1 -1
- package/dist/approval-api/d1-store.js +6 -3
- package/dist/approval-api/d1-store.js.map +1 -1
- package/dist/approval-api/principal-identity.d.ts +32 -0
- package/dist/approval-api/principal-identity.d.ts.map +1 -0
- package/dist/approval-api/principal-identity.js +69 -0
- package/dist/approval-api/principal-identity.js.map +1 -0
- package/dist/approval-api/principal.d.ts +9 -12
- package/dist/approval-api/principal.d.ts.map +1 -1
- package/dist/approval-api/principal.js +9 -45
- package/dist/approval-api/principal.js.map +1 -1
- package/dist/approval-api/router.d.ts.map +1 -1
- package/dist/approval-api/router.js +9 -1
- package/dist/approval-api/router.js.map +1 -1
- package/dist/approval-api/service.d.ts +19 -0
- package/dist/approval-api/service.d.ts.map +1 -1
- package/dist/approval-api/service.js +41 -10
- package/dist/approval-api/service.js.map +1 -1
- package/dist/approval-api/types.d.ts +12 -0
- package/dist/approval-api/types.d.ts.map +1 -1
- package/dist/approval-api/types.js +12 -0
- package/dist/approval-api/types.js.map +1 -1
- package/dist/background-tasks/host.d.ts +127 -14
- package/dist/background-tasks/host.d.ts.map +1 -1
- package/dist/background-tasks/host.js +579 -50
- package/dist/background-tasks/host.js.map +1 -1
- package/dist/background-tasks/index.d.ts +2 -2
- package/dist/background-tasks/index.d.ts.map +1 -1
- package/dist/background-tasks/index.js +11 -6
- package/dist/background-tasks/index.js.map +1 -1
- package/dist/background-tasks/routes.d.ts +19 -2
- package/dist/background-tasks/routes.d.ts.map +1 -1
- package/dist/background-tasks/routes.js +4 -4
- package/dist/background-tasks/routes.js.map +1 -1
- package/dist/deployment-identity-protocol.d.ts +2 -2
- package/dist/deployment-identity-protocol.d.ts.map +1 -1
- package/dist/deployment-identity-protocol.js +1 -1
- package/dist/deployment-identity-protocol.js.map +1 -1
- package/dist/do-runner/cause-chain.d.ts +53 -0
- package/dist/do-runner/cause-chain.d.ts.map +1 -0
- package/dist/do-runner/cause-chain.js +96 -0
- package/dist/do-runner/cause-chain.js.map +1 -0
- package/dist/do-runner/d1-storage.d.ts +109 -5
- package/dist/do-runner/d1-storage.d.ts.map +1 -1
- package/dist/do-runner/d1-storage.js +289 -44
- package/dist/do-runner/d1-storage.js.map +1 -1
- package/dist/do-runner/deployment-identity.d.ts +29 -5
- package/dist/do-runner/deployment-identity.d.ts.map +1 -1
- package/dist/do-runner/deployment-identity.js +23 -6
- package/dist/do-runner/deployment-identity.js.map +1 -1
- package/dist/do-runner/do-error-response.d.ts +4 -23
- package/dist/do-runner/do-error-response.d.ts.map +1 -1
- package/dist/do-runner/do-error-response.js +19 -24
- package/dist/do-runner/do-error-response.js.map +1 -1
- package/dist/do-runner/do-status-error.d.ts +37 -0
- package/dist/do-runner/do-status-error.d.ts.map +1 -0
- package/dist/do-runner/do-status-error.js +42 -0
- package/dist/do-runner/do-status-error.js.map +1 -0
- package/dist/do-runner/durable-object.d.ts +2 -1
- package/dist/do-runner/durable-object.d.ts.map +1 -1
- package/dist/do-runner/durable-object.js +205 -19
- package/dist/do-runner/durable-object.js.map +1 -1
- package/dist/do-runner/execution-fence.d.ts +335 -0
- package/dist/do-runner/execution-fence.d.ts.map +1 -0
- package/dist/do-runner/execution-fence.js +534 -0
- package/dist/do-runner/execution-fence.js.map +1 -0
- package/dist/do-runner/index.d.ts +10 -3
- package/dist/do-runner/index.d.ts.map +1 -1
- package/dist/do-runner/index.js +16 -3
- package/dist/do-runner/index.js.map +1 -1
- package/dist/do-runner/init.d.ts +82 -1
- package/dist/do-runner/init.d.ts.map +1 -1
- package/dist/do-runner/init.js +58 -3
- package/dist/do-runner/init.js.map +1 -1
- package/dist/do-runner/inventory.d.ts +294 -0
- package/dist/do-runner/inventory.d.ts.map +1 -0
- package/dist/do-runner/inventory.js +811 -0
- package/dist/do-runner/inventory.js.map +1 -0
- package/dist/do-runner/notification-predicate.d.ts +8 -0
- package/dist/do-runner/notification-predicate.d.ts.map +1 -0
- package/dist/do-runner/notification-predicate.js +9 -0
- package/dist/do-runner/notification-predicate.js.map +1 -0
- package/dist/do-runner/runtime.d.ts +83 -0
- package/dist/do-runner/runtime.d.ts.map +1 -1
- package/dist/do-runner/runtime.js +131 -4
- package/dist/do-runner/runtime.js.map +1 -1
- package/dist/do-runner/start-idempotency.d.ts +508 -0
- package/dist/do-runner/start-idempotency.d.ts.map +1 -0
- package/dist/do-runner/start-idempotency.js +886 -0
- package/dist/do-runner/start-idempotency.js.map +1 -0
- package/dist/goals/objective-routes.d.ts +14 -0
- package/dist/goals/objective-routes.d.ts.map +1 -1
- package/dist/goals/objective-routes.js +45 -24
- package/dist/goals/objective-routes.js.map +1 -1
- package/dist/host-kit/do-run-topology.d.ts +15 -0
- package/dist/host-kit/do-run-topology.d.ts.map +1 -1
- package/dist/host-kit/do-run-topology.js +22 -1
- package/dist/host-kit/do-run-topology.js.map +1 -1
- package/dist/host-kit/flowsafe-worker.d.ts +11 -0
- package/dist/host-kit/flowsafe-worker.d.ts.map +1 -1
- package/dist/host-kit/flowsafe-worker.js +343 -62
- package/dist/host-kit/flowsafe-worker.js.map +1 -1
- package/dist/host-kit/host-approval-service.d.ts +20 -0
- package/dist/host-kit/host-approval-service.d.ts.map +1 -1
- package/dist/host-kit/host-approval-service.js +6 -0
- package/dist/host-kit/host-approval-service.js.map +1 -1
- package/dist/host-kit/index.d.ts +2 -2
- package/dist/host-kit/index.d.ts.map +1 -1
- package/dist/host-kit/index.js +1 -1
- package/dist/host-kit/index.js.map +1 -1
- package/dist/host-kit/run-route-error.d.ts +18 -0
- package/dist/host-kit/run-route-error.d.ts.map +1 -1
- package/dist/host-kit/run-route-error.js +23 -0
- package/dist/host-kit/run-route-error.js.map +1 -1
- package/dist/host-kit/run-router.d.ts +58 -1
- package/dist/host-kit/run-router.d.ts.map +1 -1
- package/dist/host-kit/run-router.js +120 -11
- package/dist/host-kit/run-router.js.map +1 -1
- package/dist/host-kit/stream-router.d.ts.map +1 -1
- package/dist/host-kit/stream-router.js +18 -9
- package/dist/host-kit/stream-router.js.map +1 -1
- package/dist/schedules/router.d.ts +15 -0
- package/dist/schedules/router.d.ts.map +1 -1
- package/dist/schedules/router.js +47 -17
- package/dist/schedules/router.js.map +1 -1
- package/dist/schedules/tick.d.ts +13 -0
- package/dist/schedules/tick.d.ts.map +1 -1
- package/dist/schedules/tick.js +59 -39
- package/dist/schedules/tick.js.map +1 -1
- package/dist/signal-providers/host-do.d.ts +12 -1
- package/dist/signal-providers/host-do.d.ts.map +1 -1
- package/dist/signal-providers/host-do.js +28 -3
- package/dist/signal-providers/host-do.js.map +1 -1
- package/dist/signal-providers/webhook-route.d.ts +14 -0
- package/dist/signal-providers/webhook-route.d.ts.map +1 -1
- package/dist/signal-providers/webhook-route.js +28 -5
- package/dist/signal-providers/webhook-route.js.map +1 -1
- package/dist/signals/notification-dispatch.d.ts +13 -0
- package/dist/signals/notification-dispatch.d.ts.map +1 -1
- package/dist/signals/notification-dispatch.js +20 -1
- package/dist/signals/notification-dispatch.js.map +1 -1
- package/dist/signals/notifications-d1.d.ts +8 -0
- package/dist/signals/notifications-d1.d.ts.map +1 -1
- package/dist/signals/notifications-d1.js +15 -9
- package/dist/signals/notifications-d1.js.map +1 -1
- package/dist/signals/thread-do-routes.d.ts.map +1 -1
- package/dist/signals/thread-do-routes.js +86 -18
- package/dist/signals/thread-do-routes.js.map +1 -1
- package/package.json +1 -1
- package/scripts/seed-deployment-identity.mjs +22 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @proofoftech/flowsafe
|
|
2
2
|
|
|
3
|
+
## 0.20.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 1212ba5: Flowsafe now exposes deployment-wide execution fencing, owner-bound idempotent starts, and a read-only drain inventory for physical deployment migrations.
|
|
8
|
+
|
|
9
|
+
This changes the public runtime and host contract:
|
|
10
|
+
|
|
11
|
+
- The execution fence has `open`, `draining`, `migration-locked`, and `proof-only` states. Transitions use compare-and-set through `POST /admin/execution-fence`; a stale expected state returns `409` with `FENCE_CAS_CONFLICT`, and invalid state or proof-key values return `400` with `INVALID_EXECUTION_FENCE_REQUEST`. `GET /admin/execution-fence` reads the current state. Both routes require `MAINTENANCE_ADMIN_SECRET`.
|
|
12
|
+
- Fence refusals return `503` with `EXECUTION_FENCED`. `open` admits every entry. `draining` refuses new run mints and future-work authoring, but admits work on existing runs, dispatch of queued background tasks, and new background-task enqueues. `migration-locked` refuses every execution entry, including background-task enqueue, dispatch, and stale-task re-drive. `proof-only` admits only the start carrying the nominated proof key and later work addressed to its bound proof run; it also refuses background-task enqueue, dispatch, and stale-task re-drive. Reads, termination, cancellation, timeout, objective clear, and schedule pause or delete remain available. In-flight compute is not preempted.
|
|
13
|
+
- The new `flowsafe_execution_fence` table stores one deployment-wide row. The deployment-identity protocol treats it as protocol-owned state during ownership checks. A database created before this release reads an absent table or row as `open`.
|
|
14
|
+
- **BREAKING:** `ExecutionFenceWiring` is required on the non-`'none'` `RunRouterStartIdempotency` arm of `RunRouterOptions.startIdempotency`, and on `HostApprovalServiceOptions`, `ScheduleTickOptions`, `ScheduleRouterOptions`, `SignalProviderHostWiring`, `WebhookRouterOptions`, `ApprovalServiceOptions`, `NotificationDispatchTickOptions`, `StorageInitOptions`, `AgentThreadTopologyOptions`, `ObjectiveRouterOptions`, and `BackgroundTaskHostOptions`.
|
|
15
|
+
- **BREAKING:** `provisionDeploymentIdentityProtocol()`, `seedDeploymentIdentity()`, and the `flowsafe-provision --initial-fence-state` CLI require an initial state. Provisioning accepts only `open` or `migration-locked`; there is no default.
|
|
16
|
+
- **BREAKING:** `BackgroundTaskHost.manager` is removed. Use `enqueue()`, `getTask()`, `listTasks()`, and `stream()`, and type read-only consumers with `BackgroundTaskReads`.
|
|
17
|
+
- **BEHAVIOR CHANGE:** the agent-host and host-kit stream routers preserve structured Durable Object refusals. Clients now receive the original `503` or `409` and a `reason` body instead of a bare `500` for structured server-side refusals.
|
|
18
|
+
- Refusal and denial message text no longer exposes internal plan identifiers. Reason codes and statuses are unchanged.
|
|
19
|
+
- `idempotencyKey` makes `POST /runs`, trusted agent-host starts, and `streamUntilPersisted()` converge on the same server-minted run. Callers still cannot supply `runId` to `POST /runs`; doing so returns `400`.
|
|
20
|
+
- Idempotent-start decisions return `IDEMPOTENT_START_OWNER_MISMATCH` (`403`), `IDEMPOTENT_START_TARGET_MISMATCH` (`409`), `IDEMPOTENT_START_PENDING` (`503`), `IDEMPOTENT_START_UNRESOLVABLE` (`409`), or `IDEMPOTENT_START_ALREADY_SETTLED` (`409`). Operational failures return `IDEMPOTENT_START_UNSUPPORTED` (`503`) or `IDEMPOTENT_START_UNREADABLE` (`503`), and malformed input returns `INVALID_START_IDEMPOTENCY_REQUEST` (`400`). `isStartReservationRefusal()` recognizes the five decision refusals, unsupported wiring, and malformed input; unreadable storage propagates separately.
|
|
21
|
+
- A replay returns the original run's persisted state. `IDEMPOTENT_START_PENDING` includes `pendingSince`. `IDEMPOTENT_START_UNRESOLVABLE` is a point-in-time answer, so re-probe before acting. A replayed suspended start omits the start response's `approval` and `approvals` fields. The `flowsafe_start_idempotency` row remains valid for the configured reservation-retention horizon.
|
|
22
|
+
- **BREAKING:** `RunRouterOptions`, `AgentThreadTopologyOptions`, and `StorageInitOptions` require `startIdempotency` wiring. `START_IDEMPOTENCY_RETENTION_DAYS` controls how long spent keys remain valid and defaults to run retention.
|
|
23
|
+
- `GET /admin/inventory` reports work categories `runs`, `approvals-waiting`, `schedule-deferred-dispatches`, `pending-notifications`, `background-tasks`, `resource-owners`, and `start-reservations`, plus standing categories `schedules` and `signal-subscriptions`. Standing categories are never required to empty.
|
|
24
|
+
- `INVENTORY_DRAIN_PROOF` requires every work category to be empty across two consecutive full sweeps at least one 60-second alarm cadence apart, while the fence remains `draining`. Inventory readings are point-in-time observations rather than snapshots and can move in either direction while draining admits work. Empty results cannot over-count, and keyset pagination never skips a row that existed before the sweep began. A host that needs a hard guarantee can re-sweep once after transitioning to `migration-locked`: an empty post-lock sweep is conclusive, while a non-empty one means work is still outstanding, either because it entered after the proof or because the lock parked it before it finished. Return to `draining` and repeat the proof. An inventory read taken under `migration-locked` measures what the fence parked rather than what the deployment would otherwise be doing. `INVENTORY_UNENUMERABLE` declares the run-owner recovery journal and persisted idle signals; the latter deliberately survive migration. `FLOWSAFE_TABLES` keeps every Flowsafe-owned table accounted for.
|
|
25
|
+
|
|
26
|
+
When upgrading, pass `'none'` only for leaf hosts with no database, select `open` or `migration-locked` during provisioning, replace `host.manager` reads with the host methods, preserve structured `503` and `409` refusal bodies, and re-probe `IDEMPOTENT_START_UNRESOLVABLE` before deciding whether to use a fresh key.
|
|
27
|
+
|
|
3
28
|
## 0.19.0
|
|
4
29
|
|
|
5
30
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -291,16 +291,27 @@ npm install --save-dev "wrangler@>=4.118 <5"
|
|
|
291
291
|
npx flowsafe-provision \
|
|
292
292
|
--database <database> \
|
|
293
293
|
--tag <tag> \
|
|
294
|
+
--initial-fence-state open \
|
|
294
295
|
--remote \
|
|
295
296
|
--config wrangler.jsonc
|
|
296
297
|
```
|
|
297
298
|
|
|
298
299
|
Fleet control planes can import the same fail-closed sentinel implementation from `@proofoftech/flowsafe/deployment-identity-protocol` instead of duplicating its schema or race handling.
|
|
299
300
|
|
|
301
|
+
### Fence and drain a deployment
|
|
302
|
+
|
|
303
|
+
One Flowsafe deployment is one tenant, so the execution fence controls the complete deployment. `open` admits all work. `draining` refuses new run mints and future-work authoring while existing runs and deliveries finish. It still accepts new background-task enqueues and dispatches queued tasks because both are drainable work. Background-task enqueue, dispatch, and stale-task re-drive are refused in `migration-locked` and `proof-only`. Signal wakes that would mint a run persist instead. `migration-locked` refuses execution, and `proof-only` admits only the nominated start and its bound run. The fence never preempts compute already in flight.
|
|
304
|
+
|
|
305
|
+
Provisioning requires `--initial-fence-state open` or `--initial-fence-state migration-locked`; it never chooses a default. A pre-0.20 database without a fence row reads as `open`. For locked-at-birth provisioning, read `GET /admin/execution-fence` afterward and fail unless it reports `migration-locked`.
|
|
306
|
+
|
|
307
|
+
Use `GET /admin/inventory` while the fence remains `draining`. A drain is proven only after every work category is empty across two complete sweeps at least 60 seconds apart. Readings are point-in-time observations rather than snapshots and can move in either direction while draining admits work. Empty results cannot over-count, and keyset pagination never skips a row that existed before the sweep began. If you need a hard guarantee, re-sweep once after transitioning to `migration-locked`: an empty post-lock sweep is conclusive; a non-empty one means work is still outstanding, either because it entered after the proof or because the lock parked it before it finished. Return to `draining` and repeat the proof. An inventory read taken under `migration-locked` measures what the fence parked rather than what the deployment would otherwise be doing. Schedules and signal subscriptions are standing configuration and need not empty. Persisted idle signals are deliberately unenumerable and carry into the replacement deployment.
|
|
308
|
+
|
|
300
309
|
### Runtime ids are opaque
|
|
301
310
|
|
|
302
311
|
The host mints opaque, path-safe run and thread ids. `RunnerRuntime.start()` requires a host-owned run id and has no generation fallback. The id scopes the snapshot, Durable Object, approval lookup, stream address, and artifact path, but it carries no customer identity.
|
|
303
312
|
|
|
313
|
+
Callers that need exactly-once start behavior supply an `idempotencyKey`, never a run ID. The key is available on `POST /runs`, trusted agent-host starts, and `streamUntilPersisted()`. A retry returns the same persisted run. `IDEMPOTENT_START_PENDING` includes `pendingSince`; re-probe the point-in-time `IDEMPOTENT_START_UNRESOLVABLE` result before acting. A key remains valid until its reservation-retention horizon expires.
|
|
314
|
+
|
|
304
315
|
### Stores are deployment-wide
|
|
305
316
|
|
|
306
317
|
`D1ApprovalStoreFactory.store()` and `D1SubscriptionStoreFactory.store()` return the store for the bound database. Tables and indexes contain no tenant column. Legacy pooled schemas require a fresh database.
|
|
@@ -484,6 +495,10 @@ Complete wiring is in the [durable-agents guide](https://github.com/ProofOfTechO
|
|
|
484
495
|
|
|
485
496
|
The composed `createFlowsafeWorker()` owns the shared route and maintenance-duty pipeline. Hosts inject workflows, identity verification, topology-backed optional routers, budget wrappers, notification transport, an invocation-scoped artifact-store factory, the storage table prefix, schedule tick, and extra purge duties.
|
|
486
497
|
|
|
498
|
+
Protect `GET` and `POST /admin/execution-fence` plus `GET /admin/inventory` with a distinct `MAINTENANCE_ADMIN_SECRET`. Fence transitions use CAS and return `409` with `FENCE_CAS_CONFLICT` when the expected state is stale. Fenced execution returns `503` with an `EXECUTION_FENCED` reason. The agent-host and stream routers preserve structured `503` and `409` refusals instead of collapsing them to a generic `500`.
|
|
499
|
+
|
|
500
|
+
Every leaf option that accepts `ExecutionFenceWiring` requires an explicit store or `'none'`. Run-router, agent-thread-topology, and storage initialization also require explicit start-idempotency wiring. Use `'none'` only when no database exists. `BackgroundTaskHost` no longer exposes its manager; call `enqueue()`, `getTask()`, `listTasks()`, or `stream()` on the host and use `BackgroundTaskReads` for read-only route composition.
|
|
501
|
+
|
|
487
502
|
`createFlowsafeMaintenanceDurableObject()` runs deadline expiry, approval service-level agreement (SLA) sweep, retention purge, and optional schedule fire as separate alarm invocations. Provider polling and background recovery use their own Durable Object alarms.
|
|
488
503
|
|
|
489
504
|
Read:
|
|
@@ -29,8 +29,44 @@ export const DEPLOYMENT_SENTINEL_COLUMNS: readonly Readonly<{
|
|
|
29
29
|
pk: number;
|
|
30
30
|
}>[];
|
|
31
31
|
|
|
32
|
+
/** The table the single deployment execution fence row lives in. */
|
|
33
|
+
export const EXECUTION_FENCE_TABLE: 'flowsafe_execution_fence';
|
|
34
|
+
/** The fence row's fixed primary key — one deployment, one database, one row. */
|
|
35
|
+
export const EXECUTION_FENCE_ROW_ID: 'deployment';
|
|
36
|
+
/** Every fence state, ordered from most to least permissive. */
|
|
37
|
+
export const EXECUTION_FENCE_STATES: readonly [
|
|
38
|
+
'open',
|
|
39
|
+
'draining',
|
|
40
|
+
'migration-locked',
|
|
41
|
+
'proof-only',
|
|
42
|
+
];
|
|
43
|
+
/** The states a deployment may be BORN in. */
|
|
44
|
+
export const INITIAL_EXECUTION_FENCE_STATES: readonly [
|
|
45
|
+
'open',
|
|
46
|
+
'migration-locked',
|
|
47
|
+
];
|
|
48
|
+
/**
|
|
49
|
+
* The fence table's schema. `do-runner/execution-fence.ts` issues this exact
|
|
50
|
+
* string, so the store and the provisioning protocol cannot create differently
|
|
51
|
+
* shaped tables.
|
|
52
|
+
*/
|
|
53
|
+
export const EXECUTION_FENCE_DDL: string;
|
|
54
|
+
|
|
55
|
+
/** The fence state a deployment is provisioned into. Required; no default. */
|
|
56
|
+
export type InitialExecutionFenceState =
|
|
57
|
+
(typeof INITIAL_EXECUTION_FENCE_STATES)[number];
|
|
58
|
+
|
|
32
59
|
export class DeploymentIdentityError extends Error {}
|
|
33
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Validate the fence state a deployment is to be born in, throwing
|
|
63
|
+
* DeploymentIdentityError on anything else.
|
|
64
|
+
*/
|
|
65
|
+
export function assertInitialExecutionFenceState(
|
|
66
|
+
state: unknown,
|
|
67
|
+
caller: string,
|
|
68
|
+
): InitialExecutionFenceState;
|
|
69
|
+
|
|
34
70
|
export function assertDeploymentIdentitySecret(
|
|
35
71
|
secret: unknown,
|
|
36
72
|
caller?: string,
|
|
@@ -62,8 +98,16 @@ export function readDeploymentIdentityProtocol(
|
|
|
62
98
|
export function provisionDeploymentIdentityProtocol(
|
|
63
99
|
execute: DeploymentIdentityProtocolExecutor,
|
|
64
100
|
tag: string,
|
|
65
|
-
options
|
|
101
|
+
options: {
|
|
66
102
|
caller?: string;
|
|
67
103
|
provisionedAt?: string;
|
|
104
|
+
/** Injectable clock (epoch milliseconds) for the seeded rows. */
|
|
105
|
+
now?: () => number;
|
|
106
|
+
/**
|
|
107
|
+
* The fence state the deployment is born in. REQUIRED and without a
|
|
108
|
+
* default: a migration host that forgot to ask for 'migration-locked'
|
|
109
|
+
* would otherwise silently get an executing deployment.
|
|
110
|
+
*/
|
|
111
|
+
initialExecutionFenceState: InitialExecutionFenceState;
|
|
68
112
|
},
|
|
69
113
|
): Promise<void>;
|
|
@@ -26,12 +26,82 @@ export const DEPLOYMENT_SENTINEL_COLUMNS = Object.freeze([
|
|
|
26
26
|
}),
|
|
27
27
|
]);
|
|
28
28
|
|
|
29
|
+
// --- Deployment execution fence (F1) ---------------------------------------
|
|
30
|
+
//
|
|
31
|
+
// The fence table and its single row are created BY THIS PROTOCOL, so every
|
|
32
|
+
// database provisioned from 0.20 on is born carrying an EXPLICIT fence state
|
|
33
|
+
// instead of leaning on the absent-row-reads-open upgrade rule.
|
|
34
|
+
//
|
|
35
|
+
// The vocabulary and the DDL live HERE rather than beside the store that reads
|
|
36
|
+
// them (src/do-runner/execution-fence.ts, which imports them from this module)
|
|
37
|
+
// for one reason: this file is the only place both sides can share. It ships at
|
|
38
|
+
// the package root and is loaded by the provisioning CLI, by fleet-control's
|
|
39
|
+
// backends, and by the runtime — none of which can import the package's
|
|
40
|
+
// TypeScript sources. And the two MUST be one string: the store's own
|
|
41
|
+
// `CREATE TABLE IF NOT EXISTS` silently accepts a differently-shaped table this
|
|
42
|
+
// protocol created, so a drifted copy would not fail, it would quietly drop the
|
|
43
|
+
// CHECK constraints that make the store's compare-and-sets total.
|
|
44
|
+
|
|
45
|
+
/** The table the single fence row lives in — flowsafe-owned, outside `mastra_%`. */
|
|
46
|
+
export const EXECUTION_FENCE_TABLE = 'flowsafe_execution_fence';
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The fence row's fixed primary key. The fence is a property of the DEPLOYMENT
|
|
50
|
+
* and a deployment is one database, so there is exactly one row and its key is
|
|
51
|
+
* a constant.
|
|
52
|
+
*/
|
|
53
|
+
export const EXECUTION_FENCE_ROW_ID = 'deployment';
|
|
54
|
+
|
|
55
|
+
/** Every fence state, ordered from most to least permissive. */
|
|
56
|
+
export const EXECUTION_FENCE_STATES = Object.freeze([
|
|
57
|
+
'open',
|
|
58
|
+
'draining',
|
|
59
|
+
'migration-locked',
|
|
60
|
+
'proof-only',
|
|
61
|
+
]);
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The states a deployment may be BORN in. `draining` and `proof-only` are
|
|
65
|
+
* transitions out of a state that already exists — draining finishes work a
|
|
66
|
+
* fresh database has none of, and proof-only nominates a run nothing has yet
|
|
67
|
+
* started — so neither is a coherent initial condition.
|
|
68
|
+
*/
|
|
69
|
+
export const INITIAL_EXECUTION_FENCE_STATES = Object.freeze([
|
|
70
|
+
'open',
|
|
71
|
+
'migration-locked',
|
|
72
|
+
]);
|
|
73
|
+
|
|
74
|
+
export const EXECUTION_FENCE_DDL = `CREATE TABLE IF NOT EXISTS ${EXECUTION_FENCE_TABLE} (
|
|
75
|
+
id TEXT PRIMARY KEY CHECK (id = '${EXECUTION_FENCE_ROW_ID}'),
|
|
76
|
+
state TEXT NOT NULL CHECK (state IN (${EXECUTION_FENCE_STATES.map((state) => `'${state}'`).join(', ')})),
|
|
77
|
+
proof_key TEXT,
|
|
78
|
+
proof_run_id TEXT,
|
|
79
|
+
updated_at INTEGER NOT NULL
|
|
80
|
+
)`;
|
|
81
|
+
|
|
29
82
|
const SENTINEL_SQL_PATTERN =
|
|
30
83
|
/^create table (?:if not exists )?flowsafe_deployment\s*\(\s*id integer primary key check\s*\(\s*id\s*=\s*1\s*\)\s*,\s*tenant_tag text not null\s*,\s*provisioned_at text not null\s*\)$/i;
|
|
31
84
|
const D1_OWNED_INTERNAL_TABLES = Object.freeze(['_cf_KV', '_cf_METADATA']);
|
|
85
|
+
/**
|
|
86
|
+
* Tables whose presence does NOT make a database "unowned application state":
|
|
87
|
+
* D1's own internal tables plus every table this protocol creates itself.
|
|
88
|
+
*
|
|
89
|
+
* The fence table belongs here because it can legitimately exist BEFORE the
|
|
90
|
+
* ownership row does — a previous provisioning attempt that died between the
|
|
91
|
+
* fence DDL and the sentinel insert leaves exactly that residue, and the
|
|
92
|
+
* runtime store also materializes the table on its first control-plane
|
|
93
|
+
* transition. Without the exclusion the next provisioning pass would read its
|
|
94
|
+
* own leftovers as somebody else's application data and refuse the database
|
|
95
|
+
* forever (`unownedDatabaseError`), and the conditional ownership insert below
|
|
96
|
+
* would never fire.
|
|
97
|
+
*/
|
|
98
|
+
const NON_APPLICATION_TABLES = Object.freeze([
|
|
99
|
+
...D1_OWNED_INTERNAL_TABLES,
|
|
100
|
+
EXECUTION_FENCE_TABLE,
|
|
101
|
+
]);
|
|
32
102
|
const MIN_DEPLOYMENT_CREDENTIAL_LENGTH = 32;
|
|
33
103
|
const MAX_DEPLOYMENT_CREDENTIAL_LENGTH = 256;
|
|
34
|
-
const
|
|
104
|
+
const NON_APPLICATION_TABLE_EXCLUSIONS = NON_APPLICATION_TABLES.map(
|
|
35
105
|
(name) => ` AND name <> '${name}'`,
|
|
36
106
|
).join('\n');
|
|
37
107
|
|
|
@@ -60,6 +130,11 @@ const CREATE_SENTINEL = Object.freeze({
|
|
|
60
130
|
sql: DEPLOYMENT_SENTINEL_DDL,
|
|
61
131
|
bindings: Object.freeze([]),
|
|
62
132
|
});
|
|
133
|
+
const CREATE_EXECUTION_FENCE = Object.freeze({
|
|
134
|
+
mode: 'write',
|
|
135
|
+
sql: EXECUTION_FENCE_DDL,
|
|
136
|
+
bindings: Object.freeze([]),
|
|
137
|
+
});
|
|
63
138
|
|
|
64
139
|
export class DeploymentIdentityError extends Error {
|
|
65
140
|
constructor(message) {
|
|
@@ -106,6 +181,28 @@ export function assertValidDeploymentTag(tag, caller) {
|
|
|
106
181
|
}
|
|
107
182
|
}
|
|
108
183
|
|
|
184
|
+
/**
|
|
185
|
+
* Validate the fence state a deployment is to be born in.
|
|
186
|
+
*
|
|
187
|
+
* Loud on anything else, and with NO default anywhere above it: the failure
|
|
188
|
+
* this closes is a migration host forgetting to ask for 'migration-locked' and
|
|
189
|
+
* silently getting an executing deployment, which is exactly the condition a
|
|
190
|
+
* migration exists to prevent. Making the argument required turns that into an
|
|
191
|
+
* obligation the caller cannot skip, while still letting a host that wants an
|
|
192
|
+
* open deployment say so.
|
|
193
|
+
*/
|
|
194
|
+
export function assertInitialExecutionFenceState(state, caller) {
|
|
195
|
+
if (
|
|
196
|
+
typeof state !== 'string' ||
|
|
197
|
+
!INITIAL_EXECUTION_FENCE_STATES.includes(state)
|
|
198
|
+
) {
|
|
199
|
+
throw new DeploymentIdentityError(
|
|
200
|
+
`${caller}: initialExecutionFenceState must be one of ${INITIAL_EXECUTION_FENCE_STATES.join(', ')} (got '${String(state)}') — it has no default on purpose`,
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
return state;
|
|
204
|
+
}
|
|
205
|
+
|
|
109
206
|
export function normalizeDeploymentSentinelSql(sql) {
|
|
110
207
|
return sql.replace(/\s+/g, ' ').trim();
|
|
111
208
|
}
|
|
@@ -118,7 +215,7 @@ export function deploymentIdentityApplicationTables(rows) {
|
|
|
118
215
|
typeof name === 'string' &&
|
|
119
216
|
name !== DEPLOYMENT_SENTINEL_TABLE &&
|
|
120
217
|
!name.startsWith('sqlite_') &&
|
|
121
|
-
!
|
|
218
|
+
!NON_APPLICATION_TABLES.includes(name),
|
|
122
219
|
)
|
|
123
220
|
.sort();
|
|
124
221
|
}
|
|
@@ -170,13 +267,48 @@ function conditionalOwnershipInsert(tag, provisionedAt) {
|
|
|
170
267
|
SELECT 1 FROM sqlite_schema
|
|
171
268
|
WHERE type = 'table'
|
|
172
269
|
AND name <> '${DEPLOYMENT_SENTINEL_TABLE}'
|
|
173
|
-
${
|
|
270
|
+
${NON_APPLICATION_TABLE_EXCLUSIONS}
|
|
174
271
|
AND name NOT GLOB 'sqlite_*'
|
|
175
272
|
)`,
|
|
176
273
|
bindings: [tag, provisionedAt],
|
|
177
274
|
};
|
|
178
275
|
}
|
|
179
276
|
|
|
277
|
+
function seedExecutionFenceRow(state, seededAt) {
|
|
278
|
+
return {
|
|
279
|
+
mode: 'write',
|
|
280
|
+
sql: `INSERT OR IGNORE INTO ${EXECUTION_FENCE_TABLE}
|
|
281
|
+
(id, state, proof_key, proof_run_id, updated_at)
|
|
282
|
+
VALUES (?, ?, NULL, NULL, ?)`,
|
|
283
|
+
// INSERT OR IGNORE, never an upsert: seeding runs on every provisioning
|
|
284
|
+
// pass, and a re-provision of a LIVE deployment must not silently reopen a
|
|
285
|
+
// fence an operator closed.
|
|
286
|
+
//
|
|
287
|
+
// `updated_at` is an INTEGER column bound as TEXT because D1's REST query
|
|
288
|
+
// API takes every parameter as a string (fleet-control's
|
|
289
|
+
// d1RestParameters rejects anything else). SQLite's INTEGER affinity
|
|
290
|
+
// converts a well-formed integer literal on write, so the column still
|
|
291
|
+
// holds a number.
|
|
292
|
+
bindings: [EXECUTION_FENCE_ROW_ID, state, String(seededAt)],
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Write the deployment's initial fence row, if it has none.
|
|
298
|
+
*
|
|
299
|
+
* Two statements rather than one request: every executor this protocol is
|
|
300
|
+
* driven through — the runtime's `db.prepare()`, the CLI's
|
|
301
|
+
* `wrangler d1 execute --command`, and both fleet-control backends' REST
|
|
302
|
+
* `/query` with bound parameters — carries exactly ONE statement per call, so
|
|
303
|
+
* there is no seam here through which a batch could be sent. The DDL therefore
|
|
304
|
+
* runs first and the row second; a crash between them leaves an empty fence
|
|
305
|
+
* table, which reads as `open` and is healed by the next invocation.
|
|
306
|
+
*/
|
|
307
|
+
async function seedExecutionFence(execute, state, seededAt) {
|
|
308
|
+
await execute(CREATE_EXECUTION_FENCE);
|
|
309
|
+
await execute(seedExecutionFenceRow(state, seededAt));
|
|
310
|
+
}
|
|
311
|
+
|
|
180
312
|
async function scanTables(execute) {
|
|
181
313
|
return execute(SCAN_TABLES);
|
|
182
314
|
}
|
|
@@ -214,9 +346,24 @@ function differentOwnerError(caller, stored, tag) {
|
|
|
214
346
|
export async function provisionDeploymentIdentityProtocol(
|
|
215
347
|
execute,
|
|
216
348
|
tag,
|
|
217
|
-
{
|
|
349
|
+
{
|
|
350
|
+
caller = 'seedDeploymentIdentity',
|
|
351
|
+
provisionedAt,
|
|
352
|
+
now = Date.now,
|
|
353
|
+
initialExecutionFenceState,
|
|
354
|
+
} = {},
|
|
218
355
|
) {
|
|
219
356
|
assertValidDeploymentTag(tag, caller);
|
|
357
|
+
// Validated BEFORE the first statement: a caller that omitted the fence state
|
|
358
|
+
// must learn so without having stamped ownership onto a database first.
|
|
359
|
+
const fenceState = assertInitialExecutionFenceState(
|
|
360
|
+
initialExecutionFenceState,
|
|
361
|
+
caller,
|
|
362
|
+
);
|
|
363
|
+
// One instant for both rows. The sentinel stores it as ISO TEXT and the fence
|
|
364
|
+
// as epoch-milliseconds INTEGER because that is what each column already is;
|
|
365
|
+
// an explicit `provisionedAt` still wins for the sentinel, as before.
|
|
366
|
+
const seededAt = now();
|
|
220
367
|
const tables = await scanTables(execute);
|
|
221
368
|
const applicationTables = deploymentIdentityApplicationTables(tables);
|
|
222
369
|
const sentinelExists = tables.some(
|
|
@@ -227,6 +374,13 @@ export async function provisionDeploymentIdentityProtocol(
|
|
|
227
374
|
if (storedBeforeCreate !== tag) {
|
|
228
375
|
throw differentOwnerError(caller, storedBeforeCreate, tag);
|
|
229
376
|
}
|
|
377
|
+
// The already-owned early return still seeds the fence. A previous pass
|
|
378
|
+
// that died between the ownership insert and the fence row left a
|
|
379
|
+
// deployment with an owner and NO explicit fence — permanently implicit-open
|
|
380
|
+
// residue, on the one deployment a migration most needs to be able to lock.
|
|
381
|
+
// Seeding here is what heals it, and INSERT-if-absent is what makes
|
|
382
|
+
// repeating it safe on a deployment whose fence has since been moved.
|
|
383
|
+
await seedExecutionFence(execute, fenceState, seededAt);
|
|
230
384
|
return;
|
|
231
385
|
}
|
|
232
386
|
if (applicationTables.length > 0) {
|
|
@@ -239,11 +393,15 @@ export async function provisionDeploymentIdentityProtocol(
|
|
|
239
393
|
if (storedAfterCreate !== tag) {
|
|
240
394
|
throw differentOwnerError(caller, storedAfterCreate, tag);
|
|
241
395
|
}
|
|
396
|
+
await seedExecutionFence(execute, fenceState, seededAt);
|
|
242
397
|
return;
|
|
243
398
|
}
|
|
244
399
|
|
|
245
400
|
await execute(
|
|
246
|
-
conditionalOwnershipInsert(
|
|
401
|
+
conditionalOwnershipInsert(
|
|
402
|
+
tag,
|
|
403
|
+
provisionedAt ?? new Date(seededAt).toISOString(),
|
|
404
|
+
),
|
|
247
405
|
);
|
|
248
406
|
const seeded = await readDeploymentIdentityProtocol(execute);
|
|
249
407
|
if (seeded === undefined) {
|
|
@@ -260,4 +418,10 @@ export async function provisionDeploymentIdentityProtocol(
|
|
|
260
418
|
if (seeded !== tag) {
|
|
261
419
|
throw differentOwnerError(caller, seeded, tag);
|
|
262
420
|
}
|
|
421
|
+
// Last, never first: the fence DDL is the one statement that could add a
|
|
422
|
+
// table to an as-yet-unowned database, and running it only after ownership is
|
|
423
|
+
// PROVEN keeps it out of the window where `unownedDatabaseError` and the
|
|
424
|
+
// conditional ownership insert are still deciding whether this database is
|
|
425
|
+
// ours to write to at all.
|
|
426
|
+
await seedExecutionFence(execute, fenceState, seededAt);
|
|
263
427
|
}
|
|
@@ -3,7 +3,7 @@ export { type AgentApprovalResumer, type AgentApprovalResumerOptions, createAgen
|
|
|
3
3
|
export { createAgentCatalog, createAgentModuleCatalog, validateAgentMeta, validateAgentModule, } from './catalog.js';
|
|
4
4
|
export { type AgentRouter, type AgentRouterOptions, createAgentRouter, } from './router.js';
|
|
5
5
|
export { type AgentThreadInstanceScope, type AgentThreadStateStorage, type AutomatedEntryAuthorizer, type AutomatedEntryRequest, type BlockingAgentRun, type BoundThreadAgent, createThreadAgentHost, type PrincipalPermissionResolution, type PrincipalPermissionResolver, type ThreadAgentHost, type ThreadAgentHostOptions, type ThreadAgentStartInput, } from './thread-host.js';
|
|
6
|
-
export { AGENT_HOST_ROUTE_PREFIX, type AgentThreadBoundTopology, type AgentThreadDispatchTopology, type AgentThreadObserveInput, type AgentThreadRunRef, type AgentThreadStartInput, type AgentThreadTopology, createAgentThreadTopology, } from './thread-topology.js';
|
|
6
|
+
export { AGENT_HOST_ROUTE_PREFIX, type AgentThreadBoundTopology, type AgentThreadDispatchTopology, type AgentThreadObserveInput, type AgentThreadRunRef, type AgentThreadStartInput, type AgentThreadTopology, type AgentThreadTopologyOptions, createAgentThreadTopology, } from './thread-topology.js';
|
|
7
7
|
export { AGENT_AUDIT_CONTEXT_KEY, createTrustedAgentRequestContext, deriveTrustedAgentContext, sanitizeStoredAgentContext, } from './trusted-context.js';
|
|
8
8
|
export type { AgentAutomationRule, AgentCatalog, AgentEntryPath, AgentMeta, AgentModule, AgentModuleCatalog, AgentRunEnvelope, AutomationCheck, Permission, TrustedAgentExecution, } from './types.js';
|
|
9
9
|
export { isPermissionIdentifier } from './types.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/agent-host/index.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,gCAAgC,EAChC,+BAA+B,EAC/B,6BAA6B,EAC7B,+BAA+B,EAC/B,6BAA6B,EAC7B,6BAA6B,GAC9B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,KAAK,oBAAoB,EACzB,KAAK,2BAA2B,EAChC,0BAA0B,GAC3B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,kBAAkB,EAClB,wBAAwB,EACxB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,iBAAiB,GAClB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC5B,KAAK,wBAAwB,EAC7B,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,qBAAqB,EACrB,KAAK,6BAA6B,EAClC,KAAK,2BAA2B,EAChC,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,GAC3B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,uBAAuB,EACvB,KAAK,wBAAwB,EAC7B,KAAK,2BAA2B,EAChC,KAAK,uBAAuB,EAC5B,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,yBAAyB,GAC1B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,uBAAuB,EACvB,gCAAgC,EAChC,yBAAyB,EACzB,0BAA0B,GAC3B,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,mBAAmB,EACnB,YAAY,EACZ,cAAc,EACd,SAAS,EACT,WAAW,EACX,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,UAAU,EACV,qBAAqB,GACtB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/agent-host/index.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,gCAAgC,EAChC,+BAA+B,E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":"","sources":["../../src/agent-host/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,0EAA0E;AAC1E,qEAAqE;AAErE,OAAO,EACL,gCAAgC,EAChC,+BAA+B,EAC/B,6BAA6B,EAC7B,+BAA+B,EAC/B,6BAA6B,EAC7B,6BAA6B,GAC9B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAGL,0BAA0B,GAC3B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,kBAAkB,EAClB,wBAAwB,EACxB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,cAAc,CAAC;AACtB,OAAO,EAGL,iBAAiB,GAClB,MAAM,aAAa,CAAC;AACrB,OAAO,EAOL,qBAAqB,GAMtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,uBAAuB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/agent-host/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,0EAA0E;AAC1E,qEAAqE;AAErE,OAAO,EACL,gCAAgC,EAChC,+BAA+B,EAC/B,6BAA6B,EAC7B,+BAA+B,EAC/B,6BAA6B,EAC7B,6BAA6B,GAC9B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAGL,0BAA0B,GAC3B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,kBAAkB,EAClB,wBAAwB,EACxB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,cAAc,CAAC;AACtB,OAAO,EAGL,iBAAiB,GAClB,MAAM,aAAa,CAAC;AACrB,OAAO,EAOL,qBAAqB,GAMtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,uBAAuB,EAQvB,yBAAyB,GAC1B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,uBAAuB,EACvB,gCAAgC,EAChC,yBAAyB,EACzB,0BAA0B,GAC3B,MAAM,sBAAsB,CAAC;AAa9B,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/agent-host/router.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,aAAa,EAEnB,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/agent-host/router.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,aAAa,EAEnB,MAAM,0BAA0B,CAAC;AASlC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAK5C,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,SAAS,SAAS,EAAE,CAAC;IAC7B,OAAO,EAAE,aAAa,CAAC;IACvB,QAAQ,EAAE,mBAAmB,CAAC;CAC/B;AAED,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;AA2LzE,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,GAAG,WAAW,CAiI1E"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
import { ActorResolutionError, RUN_START_ROLES, } from '../approval-api/index.js';
|
|
3
3
|
import { isPathSafeId } from '../do-runner/index.js';
|
|
4
|
-
import { RunRouteError, requireResourceAccess } from '../host-kit/index.js';
|
|
4
|
+
import { RunRouteError, requireResourceAccess, runRouteReason, } from '../host-kit/index.js';
|
|
5
5
|
import { readBoundedBody } from '../http-body.js';
|
|
6
6
|
import { createAgentCatalog } from './catalog.js';
|
|
7
7
|
const MAX_BODY_BYTES = 16_384;
|
|
@@ -130,7 +130,11 @@ function internalError(error, route) {
|
|
|
130
130
|
return json({ error: 'forbidden' }, 403);
|
|
131
131
|
}
|
|
132
132
|
if (error instanceof RunRouteError) {
|
|
133
|
-
|
|
133
|
+
// A structured reason is the DO saying what it refused and why, in a code
|
|
134
|
+
// it means to publish — so it passes through at ANY status, 5xx included.
|
|
135
|
+
// Without this a 503 EXECUTION_FENCED became a bare 500 here and the
|
|
136
|
+
// caller could not tell a fenced deployment from a broken one.
|
|
137
|
+
if (error.status < 500 || runRouteReason(error) !== undefined) {
|
|
134
138
|
return json({
|
|
135
139
|
error: error.message,
|
|
136
140
|
...(error.reason === undefined ? {} : { reason: error.reason }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/agent-host/router.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC,OAAO,EACL,oBAAoB,EAEpB,eAAe,GAChB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/agent-host/router.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC,OAAO,EACL,oBAAoB,EAEpB,eAAe,GAChB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EACL,aAAa,EACb,qBAAqB,EACrB,cAAc,GACf,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAIlD,MAAM,cAAc,GAAG,MAAM,CAAC;AAC9B,MAAM,qBAAqB,GAAG,MAAM,CAAC;AAoCrC,SAAS,IAAI,CAAC,OAAgB,EAAE,MAAM,GAAG,GAAG,EAAE,KAAc;IAC1D,MAAM,OAAO,GAA2B;QACtC,cAAc,EAAE,kBAAkB;QAClC,eAAe,EAAE,UAAU;QAC3B,wBAAwB,EAAE,SAAS;KACpC,CAAC;IACF,IAAI,KAAK;QAAE,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC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,EAAE,GAAG,CAAC,CAAC;YAC5D,IAAI,OAAO,CAAC,MAAM,KAAK,KAAK,CAAC,KAAK,EAAE,CAAC;gBACnC,OAAO,IAAI,CAAC,EAAE,KAAK,EAAE,oBAAoB,EAAE,EAAE,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;YACjE,CAAC;YAED,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBAC5B,IAAI,GAAG,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;oBACtB,OAAO,IAAI,CAAC,EAAE,KAAK,EAAE,8BAA8B,EAAE,EAAE,GAAG,CAAC,CAAC;gBAC9D,CAAC;gBACD,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC;YACxB,CAAC;YAED,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;YAC9B,IAAI,MAAM,YAAY,QAAQ;gBAAE,OAAO,MAAM,CAAC;YAC9C,OAAO,MAAM,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,GAAG,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;QACvE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QACrC,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -87,6 +87,17 @@ export interface ThreadAgentStartInput {
|
|
|
87
87
|
safeContext?: Record<string, unknown>;
|
|
88
88
|
/** Trusted, JSON-safe model provider options from schedule dispatch only. */
|
|
89
89
|
providerOptions?: Record<string, unknown>;
|
|
90
|
+
/**
|
|
91
|
+
* The idempotency key the thread topology already RESERVED for this run.
|
|
92
|
+
*
|
|
93
|
+
* Nothing at this layer reserves, claims, or replays on it: the reservation
|
|
94
|
+
* lives on the Worker side, where a retry that minted a fresh thread can
|
|
95
|
+
* still be redirected to the original one. It travels down here only so
|
|
96
|
+
* `RunnerRuntime.start` can compare it against the execution fence's
|
|
97
|
+
* nominated proof key.
|
|
98
|
+
* @internal
|
|
99
|
+
*/
|
|
100
|
+
idempotencyKey?: string;
|
|
90
101
|
}
|
|
91
102
|
export interface BoundThreadAgent {
|
|
92
103
|
agentId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-host.d.ts","sourceRoot":"","sources":["../../src/agent-host/thread-host.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAGjE,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,EAEjC,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAGL,KAAK,sBAAsB,EAC3B,KAAK,UAAU,EAIf,KAAK,mBAAmB,EAExB,KAAK,WAAW,EACjB,MAAM,uBAAuB,CAAC;AAa/B,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,GAAG,SAAS,CAAC,CAAC;IACtD,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7C,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACtC,IAAI,CAAC,CAAC,GAAG,OAAO,EAAE,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,GAAG,CAA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C,EAAE,sBAAsB,GAAG,sBAAsB,CAAC;IAC5E,qFAAqF;IACrF,iBAAiB,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAC9D,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,CACd,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,EACvC,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;CACvE;AAuQD,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,sBAAsB,GAC9B,eAAe,CAskDjB"}
|
|
@@ -219,6 +219,20 @@ export function createThreadAgentHost(options) {
|
|
|
219
219
|
const withBindingLock = createFifoLock();
|
|
220
220
|
const withDispatchLock = createFifoLock();
|
|
221
221
|
const withRecoveryLock = createFifoLock();
|
|
222
|
+
/**
|
|
223
|
+
* Run ids this object is currently starting — the liveness half of the
|
|
224
|
+
* idempotent-start replay decision, and the reason a retried agent start can
|
|
225
|
+
* tell "the first one is still working" from "the first one died holding the
|
|
226
|
+
* claim" without a timer.
|
|
227
|
+
*
|
|
228
|
+
* In memory, never stored: liveness is a property of an isolate that is
|
|
229
|
+
* running code, so the honest answer after an eviction is `false`, and any
|
|
230
|
+
* durable proxy would keep saying `true` for a run nothing is executing.
|
|
231
|
+
* Scoped to this host instance, which `instanceScopeFor` already pins to one
|
|
232
|
+
* Durable Object — the same object an agent run is bound to for its whole
|
|
233
|
+
* life, so this object's answer is the only one there is.
|
|
234
|
+
*/
|
|
235
|
+
const startsInFlight = new Set();
|
|
222
236
|
const instanceScopeFor = (scope) => {
|
|
223
237
|
if (stableScope) {
|
|
224
238
|
if (stableScope.threadId !== scope.threadId ||
|
|
@@ -954,6 +968,10 @@ export function createThreadAgentHost(options) {
|
|
|
954
968
|
await writeAgentRunRecord(options.stateStorage(), ref.runId, stored);
|
|
955
969
|
return recovery;
|
|
956
970
|
});
|
|
971
|
+
// From here to the finally below, this object IS the run's execution.
|
|
972
|
+
// Registered BEFORE the stream so the window a replaying start asks
|
|
973
|
+
// about — the one before core has persisted anything — is covered too.
|
|
974
|
+
startsInFlight.add(ref.runId);
|
|
957
975
|
try {
|
|
958
976
|
const streamOptions = {
|
|
959
977
|
runId: ref.runId,
|
|
@@ -978,7 +996,7 @@ export function createThreadAgentHost(options) {
|
|
|
978
996
|
input.scheduleDispatchLease === 'executing'
|
|
979
997
|
? { scheduleId: input.scheduleId, dispatchId: input.dispatchId }
|
|
980
998
|
: undefined;
|
|
981
|
-
await durable.streamUntilPersisted(messages, streamOptions, scope.principal.id, scope.principal.kind, recovery.token,
|
|
999
|
+
await durable.streamUntilPersisted(messages, streamOptions, scope.principal.id, scope.principal.kind, recovery.token, scheduleDispatch, input.idempotencyKey);
|
|
982
1000
|
const summary = await scope.init.runtime.status(DURABLE_AGENTIC_LOOP_WORKFLOW_ID, ref.runId);
|
|
983
1001
|
if (!summary)
|
|
984
1002
|
throw new Error('agent run did not persist a summary');
|
|
@@ -1029,6 +1047,12 @@ export function createThreadAgentHost(options) {
|
|
|
1029
1047
|
}
|
|
1030
1048
|
throw error;
|
|
1031
1049
|
}
|
|
1050
|
+
finally {
|
|
1051
|
+
// Unconditional: an entry left behind would answer every later probe
|
|
1052
|
+
// "live" for the lifetime of the isolate, turning a crashed start's
|
|
1053
|
+
// honest UNRESOLVABLE into an endless PENDING.
|
|
1054
|
+
startsInFlight.delete(ref.runId);
|
|
1055
|
+
}
|
|
1032
1056
|
});
|
|
1033
1057
|
},
|
|
1034
1058
|
resolveBoundAgent: async (scope, input) => {
|
|
@@ -1058,6 +1082,23 @@ export function createThreadAgentHost(options) {
|
|
|
1058
1082
|
? preflightUrl.pathname.slice(AGENT_HOST_ROUTE_PREFIX.length)
|
|
1059
1083
|
: '';
|
|
1060
1084
|
const preflightSegments = preflightSuffix.split('/').filter(Boolean);
|
|
1085
|
+
// The liveness probe, answered BEFORE withDispatchLock on purpose: the
|
|
1086
|
+
// start it is asking about holds that lock for its whole first leg, so a
|
|
1087
|
+
// probe that queued behind it would block for exactly as long as the run
|
|
1088
|
+
// it was trying to describe — and time out reporting nothing.
|
|
1089
|
+
//
|
|
1090
|
+
// It reads no storage and reveals only whether this object is currently
|
|
1091
|
+
// executing a run id the caller already had to know. Authorization is the
|
|
1092
|
+
// deployment-identity header every request to this object carries: the
|
|
1093
|
+
// probe travels the internal Worker-to-DO channel, and the reservation on
|
|
1094
|
+
// the far side already proved the caller owns the key that names this run.
|
|
1095
|
+
if (request.method === 'GET' &&
|
|
1096
|
+
preflightSegments.length === 4 &&
|
|
1097
|
+
preflightSegments[0] === 'runs' &&
|
|
1098
|
+
preflightSegments[3] === 'start-liveness') {
|
|
1099
|
+
const runId = decode(preflightSegments[2]);
|
|
1100
|
+
return json({ live: runId !== undefined && startsInFlight.has(runId) });
|
|
1101
|
+
}
|
|
1061
1102
|
if (request.method === 'POST' &&
|
|
1062
1103
|
preflightSegments.length === 4 &&
|
|
1063
1104
|
preflightSegments[0] === 'runs' &&
|
|
@@ -1123,6 +1164,17 @@ export function createThreadAgentHost(options) {
|
|
|
1123
1164
|
threaded: body.threaded !== false,
|
|
1124
1165
|
safeContext: safeContext(body.safeContext),
|
|
1125
1166
|
providerOptions: providerOptions(body.providerOptions),
|
|
1167
|
+
// Validated, not trusted: this body is JSON, and the same string
|
|
1168
|
+
// reaches the execution fence's proof-only comparison.
|
|
1169
|
+
...(body.idempotencyKey === undefined
|
|
1170
|
+
? {}
|
|
1171
|
+
: {
|
|
1172
|
+
idempotencyKey: isPathSafeId(body.idempotencyKey)
|
|
1173
|
+
? body.idempotencyKey
|
|
1174
|
+
: (() => {
|
|
1175
|
+
throw new AgentHostRequestError(400, 'idempotencyKey must be a URL-path-safe identifier');
|
|
1176
|
+
})(),
|
|
1177
|
+
}),
|
|
1126
1178
|
...(body.scheduleId !== undefined
|
|
1127
1179
|
? {
|
|
1128
1180
|
scheduleId: isPathSafeId(body.scheduleId)
|