@proofoftech/flowsafe 0.24.0 → 0.26.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 +45 -0
- package/README.md +6 -4
- package/dist/agent-host/thread-host.d.ts.map +1 -1
- package/dist/agent-host/thread-host.js +64 -3
- package/dist/agent-host/thread-host.js.map +1 -1
- package/dist/agent-host/thread-topology.d.ts.map +1 -1
- package/dist/agent-host/thread-topology.js +2 -1
- package/dist/agent-host/thread-topology.js.map +1 -1
- package/dist/agent-runner/durable-agent-runner.d.ts +12 -3
- package/dist/agent-runner/durable-agent-runner.d.ts.map +1 -1
- package/dist/agent-runner/durable-agent-runner.js +217 -102
- package/dist/agent-runner/durable-agent-runner.js.map +1 -1
- package/dist/approval-api/grants.d.ts +11 -1
- package/dist/approval-api/grants.d.ts.map +1 -1
- package/dist/approval-api/grants.js +20 -0
- package/dist/approval-api/grants.js.map +1 -1
- package/dist/approval-api/index.d.ts +1 -1
- package/dist/approval-api/index.d.ts.map +1 -1
- package/dist/approval-api/index.js +1 -1
- package/dist/approval-api/index.js.map +1 -1
- package/dist/approval-api/retention.d.ts.map +1 -1
- package/dist/approval-api/retention.js +6 -5
- package/dist/approval-api/retention.js.map +1 -1
- package/dist/approval-api/service.d.ts +4 -1
- package/dist/approval-api/service.d.ts.map +1 -1
- package/dist/approval-api/service.js +12 -5
- package/dist/approval-api/service.js.map +1 -1
- package/dist/approval-api/types.d.ts +8 -1
- package/dist/approval-api/types.d.ts.map +1 -1
- package/dist/background-tasks/d1-storage.d.ts.map +1 -1
- package/dist/background-tasks/d1-storage.js +7 -12
- package/dist/background-tasks/d1-storage.js.map +1 -1
- package/dist/do-runner/durable-object.d.ts +29 -10
- package/dist/do-runner/durable-object.d.ts.map +1 -1
- package/dist/do-runner/durable-object.js +56 -33
- package/dist/do-runner/durable-object.js.map +1 -1
- package/dist/do-runner/fenced-workflow-capability.d.ts +35 -5
- package/dist/do-runner/fenced-workflow-capability.d.ts.map +1 -1
- package/dist/do-runner/fenced-workflows-d1.d.ts +8 -0
- package/dist/do-runner/fenced-workflows-d1.d.ts.map +1 -1
- package/dist/do-runner/fenced-workflows-d1.js +402 -39
- package/dist/do-runner/fenced-workflows-d1.js.map +1 -1
- package/dist/do-runner/index.d.ts +1 -1
- package/dist/do-runner/index.d.ts.map +1 -1
- package/dist/do-runner/index.js +1 -1
- package/dist/do-runner/index.js.map +1 -1
- package/dist/do-runner/run-input-depth.d.ts +15 -0
- package/dist/do-runner/run-input-depth.d.ts.map +1 -0
- package/dist/do-runner/run-input-depth.js +32 -0
- package/dist/do-runner/run-input-depth.js.map +1 -0
- package/dist/do-runner/run-lifecycle.d.ts +68 -3
- package/dist/do-runner/run-lifecycle.d.ts.map +1 -1
- package/dist/do-runner/run-lifecycle.js +76 -12
- package/dist/do-runner/run-lifecycle.js.map +1 -1
- package/dist/do-runner/runtime.d.ts +46 -9
- package/dist/do-runner/runtime.d.ts.map +1 -1
- package/dist/do-runner/runtime.js +361 -115
- package/dist/do-runner/runtime.js.map +1 -1
- package/dist/do-runner/workflow-snapshot-row.d.ts +4 -5
- package/dist/do-runner/workflow-snapshot-row.d.ts.map +1 -1
- package/dist/do-runner/workflow-snapshot-row.js +14 -18
- package/dist/do-runner/workflow-snapshot-row.js.map +1 -1
- package/dist/host-kit/approval-bridge.d.ts +20 -2
- package/dist/host-kit/approval-bridge.d.ts.map +1 -1
- package/dist/host-kit/approval-bridge.js +66 -7
- package/dist/host-kit/approval-bridge.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 +2 -1
- package/dist/host-kit/do-run-topology.js.map +1 -1
- package/dist/host-kit/flowsafe-worker.d.ts +6 -1
- package/dist/host-kit/flowsafe-worker.d.ts.map +1 -1
- package/dist/host-kit/flowsafe-worker.js +2 -2
- package/dist/host-kit/flowsafe-worker.js.map +1 -1
- package/dist/host-kit/host-approval-service.d.ts +3 -1
- package/dist/host-kit/host-approval-service.d.ts.map +1 -1
- package/dist/host-kit/host-approval-service.js.map +1 -1
- package/dist/host-kit/run-router.d.ts +4 -1
- package/dist/host-kit/run-router.d.ts.map +1 -1
- package/dist/host-kit/run-router.js +14 -0
- package/dist/host-kit/run-router.js.map +1 -1
- package/dist/schedules/tick.d.ts +28 -2
- package/dist/schedules/tick.d.ts.map +1 -1
- package/dist/schedules/tick.js +35 -11
- package/dist/schedules/tick.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,50 @@
|
|
|
1
1
|
# @proofoftech/flowsafe
|
|
2
2
|
|
|
3
|
+
## 0.26.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- a51a1e7: Breaking: on `FencedWorkflowsStorageD1` storage a leg's write can no longer remove a recorded cancellation or timeout intent. Over a row that is not settled, a write whose run lifecycle has a lower revision than the stored one, or none, keeps the stored lifecycle, and a write of the same revision without an intent keeps the stored intent; the rest of the write lands. A write over a recorded intent that records a disputed economic operation is stored as written instead, so the terminate answers `409` with `DISPUTED_SETTLEMENT` rather than leaving the intent beside the dispute, and the capability's `patchRunLifecycle` resolves `false` over a stored dispute, so an intent does not land over one either. A run-deadline intent does not join a write of the same revision that moved its deadline. A run that completes after a terminate's intent landed is therefore recorded as cancelled, or as timed out on the run-deadline route, wherever its leg runs; before this change a completion written by a leg on another instance kept its result and the terminate answered `409`. The intent does not stop a leg on another instance, so such a run may have run every step with its effects, and its summary carries no `result`: check a cancelled run's effects before running its work again. A terminate that answers `503` because such a leg kept writing leaves the intent recorded, so approval resumes of the run answer `409` until a retry of the terminate completes the cancellation. It also closes a window in which a leg's write, serialized just before the intent landed, removed it, so a run whose isolate was then lost settled as `INTERRUPTED`, or stayed suspended, instead of cancelled. A run that completed before the intent landed still keeps its result and the terminate answers `409`. A leg run by an earlier flowsafe version during a deploy or rollback can still remove the intent.
|
|
8
|
+
- 6b77765: Breaking: start and resume now refuse run input nested more than 256 levels deep with HTTP 400: a workflow's `inputData`, `initialState`, each request-context value and `resumeData` (`InvalidRunRequestError`), and an agent start's caller messages and client context, scheduled starts included. `FencedWorkflowsStorageD1` refuses to store a run snapshot that SQLite cannot parse as JSON with the new `RunStateNotStorableError` (HTTP 422, `reason.code` `RUN_STATE_NOT_STORABLE`), unless the stored row is already one SQLite cannot parse. SQLite's JSON functions refuse text nested more than 1,000 levels deep, and the settled-row guard, the liveness touch, the run-deadline sweep, retention, the drain inventory and the approval run fence read run state through them, so such a run had no deadline, was never purged and could block a drain proof. A run whose leg writes state too deep to store now fails at once: it reads `failed` with `errorEnvelope.code` `RUN_STATE_NOT_STORABLE` over the last state it stored, and its leg is aborted. On a durable agent the runner publishes the run's terminal `error` event and the thread is released; the refused write can come after the loop has finished, so the agent's stream can end with a normal `finish` event, and the run's status is authoritative. `RunTerminalErrorEnvelope['code']` gains `RUN_STATE_NOT_STORABLE`. A start whose initial row is too deep, which only a host's `requestContextForRun` values can produce, is refused with `RunStateNotStorableError` and creates no run. The run router answers `400` for `inputData`, a request-context value or `resumeData` nested more than 256 levels deep, at any depth, before it reserves a start key or forwards the body; such a field nested deeper than the Worker could serialize used to answer `500` and leave a keyed start's reservation claimed. A scheduled agent fire that the host refuses with `400`, `403`, `404` or `422` is now recorded as failed instead of staying deferred: a threaded signal always, and a threadless start once the `status` lookup states that the run does not exist, at that fire or on a later reconcile pass. A signal refused with `422` for its content, which every reconcile pass used to send again, now fails the same way. `ScheduleTickSignalAgent` and `ScheduleTickStartAgent` document the statuses a custom seam must report, and deferred fires that an earlier version recorded stay deferred. Rows an earlier version stored stay writable, but the deadline sweep and retention skip them and the drain inventory counts each as outstanding work: the operations runbook gives the query that lists them. During a gradual deployment, a Worker on an earlier version answers a keyed start replay of a run that failed this way with `503`.
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- 44d594d: A settlement or terminate abort now reaches a durable-agent start leg's model or tool call that was already in flight when Mastra's isolate-wide run registry evicted the run's entry, when the run has a total time budget. Before this change the eviction unlinked the leg's abort from the signal that call held. Calls a leg starts after such an eviction take Mastra's rebuilt entry and are not covered.
|
|
13
|
+
- 44d594d: A durable-agent run cancelled while its leg runs in the thread object, or terminated while suspended there, now ends its run stream with a terminal `error` event (`RunCancelledError`, or `RunTimedOutError` for a timeout) and releases the run's local state. A model or tool call that such a cancellation cuts sees an abort reason named `AbortError` whose `cause` is that error. Before this change observers of the run waited indefinitely, the run's Mastra registry entries stayed in memory, and a threaded run kept its thread active in the object, so a signal sent to the thread was queued into the cancelled run and could be lost.
|
|
14
|
+
- 995cca1: The agent thread object's alarm recovers every start journal even when one journal's recovery fails for a reason other than a pending start. The failing journal is kept and logged as an `agent-start-recovery-failed` line naming its run, and the wake reports the failure after the other journals are done. Before this change such a failure stopped recovery of every journal listed after it until it cleared.
|
|
15
|
+
- 44d594d: A durable-agent run resumed in the same thread object no longer leaks the previous leg's Mastra abort-request subscription, which kept that leg's run state in memory for the object's lifetime.
|
|
16
|
+
- 3fe8b05: `reconcileApprovalsForSummary` no longer supersedes or files a step's approval when the step already has an approval bound to a later suspension, one with a greater `resumeCount`, than the summary it was given. A status read whose summary predated a timeout resume closed the approval the run object had just filed for the step's next suspension, and, unless the earlier suspension was a timer, filed one for the suspension that had ended; the new gate was left with no approval that could be filed again. Runs already left that way are not repaired: the operations runbook says how to end or resume them.
|
|
17
|
+
- 98f88cb: A decided approval resumes its step only while the step is still at the suspension the approval was filed for. `resumeRecord`, `resumeViaRuntime` and the agent approval resumer pass the record's suspension to `RunnerRuntime.resume` through the new `ResumeRunOptions.expectedSuspension`, and the runtime refuses a mismatch with the new `SuspensionChangedError` (HTTP 409, `reason.code` `SUSPENSION_CHANGED`) before the step runs. The decision stays recorded and the decide response reports the refused resume, with the new `ResumeOutcome.code` set to `SUSPENSION_CHANGED` so a caller can tell it from a resume worth retrying. The refused approval still counts toward the separation-of-duties check across gates, so its reviewer cannot decide the step's current suspension unless an exemption applies to that reviewer. A workflow run's Durable Object files the step's current suspension at once, and other hosts file it at their next reconciling status read. A resumer that builds its own resume call or body gets the same check by spreading the new `expectedSuspensionFor(record)` into it. Before this change a decision on an approval for an earlier suspension resumed the step's current suspension with that decision's `resumeData`. Records without a captured suspension time, from earlier versions, resume as before.
|
|
18
|
+
- 8d2cebc: `FencedWorkflowsStorageD1` no longer writes over a stored run snapshot that SQLite cannot parse as JSON, such as one nested more than 1,000 levels deep, without deciding it first. The settled-row guard refuses such a write in SQL; the storage then reads the row, evaluates the guard's rule on the run lifecycle it parses from it, and writes an admitted snapshot with a compare-and-set against that row. The liveness touch decides such a row the same way. A leg still running on another instance therefore can no longer overwrite the terminate, timeout, interruption or start repair of such a run, and its next touch aborts it. Before this change the guard wrote over such a row and the touch reported it live, so the leg kept running and its next write replaced the settlement. Stored bytes that are not JSON at all hold no settlement and are still written over. A write over such a row that keeps missing a changing row answers `503` (`EXECUTION_FENCE_UNREADABLE`). A leg run by an earlier flowsafe version during a deploy or rollback still writes over such a row.
|
|
19
|
+
|
|
20
|
+
## 0.25.0
|
|
21
|
+
|
|
22
|
+
### Minor Changes
|
|
23
|
+
|
|
24
|
+
- e50aaa6: The agent thread host's start recovery now waits, as `DurableObjectRunner`'s does, until a pending agent start's run row has gone six minutes without a write before it repairs the start as `StartOutcomeUnknown`, and it stamps the repair so the settled-row guard refuses a later write from that start's leg. Before this change the host repaired a pending start about a minute after admission whether or not its leg was still running, and that leg's later writes overwrote the repair. A dead agent start now reads `StartOutcomeUnknown` about six to seven minutes after its last touch. Until then the thread stays blocked, the run's status and terminate routes and a schedule dispatch status read answer `503 RUN_START_PENDING`, and a keyed start replay answers `409 IDEMPOTENT_START_UNRESOLVABLE`, or `503 IDEMPOTENT_START_PENDING` while the start is live in the thread object's current isolate. Keep re-probing an agent start for at least seven minutes after its last activity before you choose a fresh key. When the start route sees its own leg fail in the object, it still repairs at once. A pending start no longer fails the thread object's alarm: recovery keeps its journal and wake, logs an `agent-start-recovery-pending` line, and goes on with the other journals.
|
|
25
|
+
|
|
26
|
+
Two cases repair a start whose leg is still running on another instance:
|
|
27
|
+
|
|
28
|
+
- A deploy from a version earlier than 0.25.0 leaves outgoing agent legs that do not touch their row. If one goes more than six minutes without a write, the thread object repairs and stamps it. From 0.24.x the settled-row guard refuses the outgoing leg's final write. From a version earlier than 0.24.0 the leg writes without the guard, so its write can land over the repair after the journal and ownership are gone; drain agent starts before such a deploy.
|
|
29
|
+
- A leg whose touches fail to reach D1 for six minutes, for example during a D1 outage, is repaired and stamped. A later touch that reaches D1 aborts the leg; otherwise the settled-row guard refuses its next write. A leg in the thread object's current isolate is never repaired.
|
|
30
|
+
|
|
31
|
+
- 9c66e63: A leg whose run another Durable Object instance has settled is now aborted within about 30 seconds instead of ending at its next workflow write. The liveness touch a running leg makes every 30 seconds on `FencedWorkflowsStorageD1` storage now reports whether its run row is settled: terminated, timed out, interrupted, or repaired by start recovery. When it is, the runtime aborts the leg's Mastra run: the engine starts no further step, the step in flight sees its `abortSignal` aborted, and the leg's next write is refused as before. A step that calls external services should pass its `abortSignal` to them so the call in flight stops; a step that ignores it runs to completion. Mastra re-runs a step with `retries` that throws after the abort, so such a step should check `abortSignal.aborted` before its side effects and throw `MastraNonRetryableError` (from `@mastra/core/error`) once it is aborted. A call the abort cuts mid-flight may already have taken effect, and its abort error does not show whether it did. A run whose stored snapshot SQLite cannot parse, for example one nested past its JSON depth limit, is neither guarded nor reported settled, so its leg is not aborted. The touch no longer moves `updatedAt` on a settled row.
|
|
32
|
+
|
|
33
|
+
The touch moved from `DurableObjectRunner` into `RunnerRuntime.start()` and `resume()`, so durable-agent legs on the agent thread host, and legs an in-process driver runs through a shared `RunnerRuntime`, now touch their run row as well. `FencedWorkflowAdmissionCapability.touchRun` may resolve `'live'`, `'settled'` or `'absent'`; a custom capability that resolves nothing keeps working and reports no settlement, so its legs are not aborted. A capability reports `'settled'` only when its storage refuses the aborted leg's later writes over that row. Legs running a flowsafe version without this change are not aborted.
|
|
34
|
+
|
|
35
|
+
On a durable agent the abort also reaches the model call and the tool calls in flight, on start and resumed legs, and a terminate that the agent's own thread object handles cuts them too. A caller's `abortSignal` still aborts a start leg. A tool should pass the `abortSignal` it receives to its own I/O, and a tool that retries after an error should check `abortSignal.aborted` first, because a cut call's error does not always show that an abort cut it. With the matching Breakwater patch, a keyed connector call cut this way keeps its idempotency key reserved until stale takeover or operator recovery, and a call with the same key meanwhile is refused with `IDEMPOTENCY_CONFLICT`; earlier Breakwater releases free the key.
|
|
36
|
+
|
|
37
|
+
- fdda499: After every suspension-deadline resume, the run object now attempts to close an approval still open for the suspension that resume ended, whether the run then ended or suspended at another step. Before this change such a record stayed open and the SLA sweep escalated it; a reviewer could still decide it, but the decision resumed nothing. When the run has ended, every open approval of the run is closed, because none of them can be decided usefully. The close is one best-effort attempt. A failed read or hook, an eviction between the resume and the reconcile, a resume that throws after its result was saved, or a host status read that files from a summary taken before the resume leaves the record open, and the SLA sweep escalates it as before. Only suspensions a timeout resume ends after the upgrade are covered: a record left open earlier stays open, including one left open by an instance still running the earlier version.
|
|
38
|
+
|
|
39
|
+
`DurableObjectRunLifecycleHooks.reconcileApprovals` receives the ended suspension as an optional third argument, `{ step, suspendedAt, resumeCount }`, and is now called after a timeout resume whatever the run's status, so a custom implementation must accept a summary that is not suspended. An implementation honours the argument by superseding each open record whose step, `suspendedAt` and `resumeCount` equal it exactly, counting an absent `resumeCount` as 0. `createFlowsafeRunnerLifecycle()` reconciles as before, then supersedes each open record bound to exactly that suspension, or every open record of a run that has ended. A hook that ignores the third argument leaves such a record open, as before, and now also receives summaries of finished runs.
|
|
40
|
+
|
|
41
|
+
### Patch Changes
|
|
42
|
+
|
|
43
|
+
- 9e35407: `DurableObjectWorkflowsStorageD1.updateWorkflowState`, the workflow domain `createBackgroundTaskD1Domains()` composes, now applies `expectedStatus` as the compare-and-set guard `@mastra/core` defines: when the stored snapshot's status does not match, the update writes nothing and resolves `undefined`, and the guard is never stored in the snapshot. Before this change the domain ignored the guard and stored it. Because the domain reports concurrent-update support, Mastra relies on that guard to let only one of two concurrent resumes of a suspended run claim it; without it both could proceed.
|
|
44
|
+
- 9e35407: `FencedWorkflowsStorageD1`'s `replaceSnapshot` capability member refuses a replacement whose `snapshot` is not a JSON object or whose `updatedAt` is not an ISO-8601 time in `Date.prototype.toISOString()` form, and writes nothing. Run retention compares the stored `updatedAt` with its cutoff as text, so any other form, including a valid time without milliseconds, can keep a run from being purged on time, and text that is not a time also makes every later settlement read of that run fail as unreadable.
|
|
45
|
+
- 4c673b4: A durable-agent leg resumed through `resumeViaRuntime()` now enforces the total time budget of its run. Before this change the resumed leg ran with no total budget, so a tool or model call that held past it was never aborted. The leg arms the `modelSettings.timeout.totalMs` the run's start call set, else the one in the agent's default options when the run started (or the current default when the start resolved none), and the budget starts again on each resumed leg. When it elapses, the leg's model and tool calls in flight see their `abortSignal` aborted with a `MastraTimeoutError` whose `timeoutType` is `'total'`, and `resumeViaRuntime()` resolves with `status: 'success'` and `result.stepResult.reason: 'error'`. A host that treats the resumed leg's success as completion of the approved action must check that reason. A start leg whose budget elapses ends its run the same way, but its `streamUntilPersisted()` rejects with the `MastraTimeoutError`. A settlement or terminate abort of the leg still reaches those calls with its own reason.
|
|
46
|
+
- 12e9df9: A terminate, and a run-deadline timeout from the maintenance sweep, now write their cancellation intent and terminal record without overwriting progress a leg wrote since they read the run, on `FencedWorkflowsStorageD1` storage. Before this change both writes replaced the run's row without checking that it was still the one they read, so a leg's write that landed between the read and the write was lost: a run that completed in that window could be recorded `cancelled` or `timed_out` without its result. The intent now changes only the run's lifecycle and timestamp, and only while the run's status and lifecycle revision are the ones it read, so a leg's step progress cannot make it miss and a leg in the same Durable Object still takes the cancellation however often it writes. The terminal record is a compare-and-set against the exact row it read. A write that finds the row changed reads the run again and decides from what it finds: a run that completed before the intent landed keeps its result and the request answers `409`. A write that finds the row changed on five attempts in a row answers `503`; retry the request. On `FencedWorkflowsStorageD1` that happens only while a leg on another instance writes continuously. `FencedWorkflowAdmissionCapability` gains an optional `patchRunLifecycle` member for the intent write. Storage that provides `replaceSnapshot` but not `patchRunLifecycle` writes the intent with the exact-row compare-and-set, and a leg in its own object that keeps writing then makes the request answer `503` without stopping the leg; retry it. Storage with neither keeps the unconditional write.
|
|
47
|
+
|
|
3
48
|
## 0.24.0
|
|
4
49
|
|
|
5
50
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -154,7 +154,7 @@ The composed host mounts `POST /runs/:workflowId/:runId/terminate`. It transitio
|
|
|
154
154
|
}
|
|
155
155
|
```
|
|
156
156
|
|
|
157
|
-
Termination is idempotent. A retry by the same trusted principal returns the persisted terminal summary after ownership cleanup. An unrelated principal receives the same opaque `404` as any inaccessible run. A disputed economic settlement returns `409` with `reason.code` set to `DISPUTED_SETTLEMENT` before the runtime cancels active work.
|
|
157
|
+
Termination is idempotent. A retry by the same trusted principal returns the persisted terminal summary after ownership cleanup. An unrelated principal receives the same opaque `404` as any inaccessible run. A disputed economic settlement returns `409` with `reason.code` set to `DISPUTED_SETTLEMENT` before the runtime cancels active work. On `FencedWorkflowsStorageD1` storage, a run that completes before a terminate records its intent keeps its result and the terminate answers `409`. After the intent is recorded, a leg that completes, in the same object or on another instance, is recorded as cancelled, unless an earlier flowsafe version runs that leg during a deploy or a rollback. A leg whose resume recorded a disputed economic settlement removes the intent, and the terminate then answers `409` with `DISPUTED_SETTLEMENT`. The intent does not stop a leg on another instance, so a `cancelled` run may have run every step, with its effects, and its summary carries no `result`: check a cancelled run's effects before running its work again. A terminate that keeps losing to a leg writing on another instance answers `503` and leaves the intent recorded: the leg keeps running, an approval resume of the run answers `409`, and a retry of the terminate completes the cancellation. Retry it.
|
|
158
158
|
|
|
159
159
|
A run whose execution leg stops mid-step, because the platform ended the Durable Object invocation, does not stay `running`. A running leg marks its run row in D1 every 30 seconds. Once the row has gone six minutes without a write, the run's own object settles it on its next wake, and it never re-executes the interrupted step:
|
|
160
160
|
|
|
@@ -169,7 +169,9 @@ A run whose execution leg stops mid-step, because the platform ended the Durable
|
|
|
169
169
|
}
|
|
170
170
|
```
|
|
171
171
|
|
|
172
|
-
A run with a recorded cancellation or timeout completes that transition instead. A deploy does not interrupt a leg: the outgoing instance keeps running it, and its touches keep the run from being settled. A Workers runtime update gives in-flight requests at most 30 seconds, so it interrupts a longer leg. Without a connected client, a Durable Object invocation lasts about 15 minutes, so each step must finish within one. Split long work into steps, and [wait without an approval](#wait-without-an-approval) rather than in an in-memory polling loop. Settlement needs the `FencedWorkflowsStorageD1` workflow domain that `createD1Storage()` composes; terminate a stranded run on other storage. See [interrupted legs](https://github.com/ProofOfTechOrg/anchorage/blob/main/docs/do-runner-design.md#interrupted-legs).
|
|
172
|
+
A run with a recorded cancellation or timeout completes that transition instead. A deploy does not interrupt a leg: the outgoing instance keeps running it, and its touches keep the run from being settled. When another instance terminates, times out or otherwise settles a run whose leg is still running, that leg's next touch aborts it: no further step starts, and the step in flight sees its `abortSignal` aborted. Pass a step's `abortSignal` to the external calls it makes so they stop too; a call the abort cuts mid-flight may already have taken effect, and its abort error does not show whether it did. Mastra re-runs a step with `retries` that throws after the abort, so such a step should check `abortSignal.aborted` before its side effects and throw `MastraNonRetryableError` (from `@mastra/core/error`) once it is aborted. A Workers runtime update gives in-flight requests at most 30 seconds, so it interrupts a longer leg. Without a connected client, a Durable Object invocation lasts about 15 minutes, so each step must finish within one. Split long work into steps, and [wait without an approval](#wait-without-an-approval) rather than in an in-memory polling loop. Settlement needs the `FencedWorkflowsStorageD1` workflow domain that `createD1Storage()` composes; terminate a stranded run on other storage. See [interrupted legs](https://github.com/ProofOfTechOrg/anchorage/blob/main/docs/do-runner-design.md#interrupted-legs).
|
|
173
|
+
|
|
174
|
+
A run whose leg returns state nested more than 1,000 levels deep does not stay `running` either. SQLite's JSON functions cannot parse such state, so `FencedWorkflowsStorageD1` refuses to store it and the runtime fails the run at once, over the last state it stored, with `errorEnvelope.code` set to `RUN_STATE_NOT_STORABLE`. The step is not re-executed, so check its external effects. Start and resume refuse `inputData`, `initialState`, a request-context value or `resumeData` nested more than 256 levels deep with HTTP 400.
|
|
173
175
|
|
|
174
176
|
Economic settlement projections are trusted internal `StartRunOptions.economicOperations` and `ResumeRunOptions.economicOperations` inputs. The host fixes the projection at an execution-leg boundary before that leg becomes cancellable. Public start and resume bodies cannot set it, and Flowsafe does not expose a dynamic mid-leg update API.
|
|
175
177
|
|
|
@@ -258,7 +260,7 @@ const poll = createStep({
|
|
|
258
260
|
});
|
|
259
261
|
```
|
|
260
262
|
|
|
261
|
-
A timer can still receive an approval: the run object lists a step only while it can vouch for the wake, and every other case files an ordinary approval (see [timer suspensions](https://github.com/ProofOfTechOrg/anchorage/blob/main/docs/do-runner-design.md#timer-suspensions)). So a timer step accepts an approval decision's `{ approved, comment?, decidedBy? }` as well as the timeout envelope, in its `resumeSchema` and its branch, and re-checks its wait condition on every resume rather than treating any resume as permission to proceed. The run object files the approvals a timer leaves to a person through the `reconcileApprovals` hook that `createFlowsafeRunnerLifecycle()` fills; see [approvals the run object files](https://github.com/ProofOfTechOrg/anchorage/blob/main/docs/do-runner-design.md#approvals-the-run-object-files) for when it files and what it leaves to a host status read.
|
|
263
|
+
A timer can still receive an approval: the run object lists a step only while it can vouch for the wake, and every other case files an ordinary approval (see [timer suspensions](https://github.com/ProofOfTechOrg/anchorage/blob/main/docs/do-runner-design.md#timer-suspensions)). So a timer step accepts an approval decision's `{ approved, comment?, decidedBy? }` as well as the timeout envelope, in its `resumeSchema` and its branch, and re-checks its wait condition on every resume rather than treating any resume as permission to proceed. The run object files the approvals a timer leaves to a person through the `reconcileApprovals` hook that `createFlowsafeRunnerLifecycle()` fills; see [approvals the run object files](https://github.com/ProofOfTechOrg/anchorage/blob/main/docs/do-runner-design.md#approvals-the-run-object-files) for when it files and what it leaves to a host status read. After every timeout resume it also attempts to close an approval still open for the suspension that resume ended.
|
|
262
264
|
|
|
263
265
|
The marker lives in the step's suspend payload, so a step that spreads untrusted data into that payload can make a gate wait without an approval for up to the deadline. A `foreach` with `concurrency` above 1 reports one payload for its suspended iterations, so one iteration's marker applies to the batch.
|
|
264
266
|
|
|
@@ -376,7 +378,7 @@ Use `GET /admin/inventory` while the fence remains `draining`. A drain is proven
|
|
|
376
378
|
|
|
377
379
|
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.
|
|
378
380
|
|
|
379
|
-
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.
|
|
381
|
+
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. For an agent start, keep re-probing for at least seven minutes after its last activity before choosing a fresh key: until the thread object repairs a start whose leg stopped or runs on another instance, its replay answers `IDEMPOTENT_START_UNRESOLVABLE`. A key remains valid until its reservation-retention horizon expires.
|
|
380
382
|
|
|
381
383
|
### Pass application context at start
|
|
382
384
|
|
|
@@ -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,K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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;AAuTD,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,sBAAsB,GAC9B,eAAe,CA23EjB"}
|
|
@@ -8,10 +8,12 @@ import { AgentRunSelectorMismatchError, } from '../agent-runner/durable-agent-ru
|
|
|
8
8
|
import { AGENT_ENTRY_PATHS, AGENT_RUN_STORAGE_KEY_PREFIX, bindAgentThread, createFlowsafeDurableAgent, deleteAgentRunRecord, deleteAgentThreadBinding, readAgentRunRecord, readAgentThreadBinding, writeAgentRunRecord, } from '../agent-runner/index.js';
|
|
9
9
|
import { canonicalResourceOwner, principalActor, principalAuditFields, principalOwner, RUN_START_ROLES, samePrincipal, } from '../approval-api/index.js';
|
|
10
10
|
import { assertExecutionPrincipal, isExecutionPrincipalId, } from '../approval-api/principal.js';
|
|
11
|
-
import {
|
|
11
|
+
import { errorMessageOf } from '../do-runner/cause-chain.js';
|
|
12
|
+
import { ExecutionFenceUnreadableError, isRunStartPendingError, normalizeD1RunExecutionIdentity, normalizeMutationEpoch, normalizeRunExecutionIdentity, RunStartPendingError, } from '../do-runner/execution-admission.js';
|
|
12
13
|
import { DoStatusError, isPathSafeId, resolveScheduleStartOwner, resourceIdFromKey, SUSPENSION_TIMEOUT_RESUME_KEY, } from '../do-runner/index.js';
|
|
13
14
|
import { isDefinitiveInitialAdmissionRefusal } from '../do-runner/initial-admission-refusal.js';
|
|
14
15
|
import { mastraRegistryEntries } from '../do-runner/mastra-registry.js';
|
|
16
|
+
import { exceedsRunInputDepth, runInputDepthMessage, } from '../do-runner/run-input-depth.js';
|
|
15
17
|
import { lifecycleFromRequestContext, terminalCleanupFor, } from '../do-runner/run-lifecycle.js';
|
|
16
18
|
import { isTerminalRunStatus, } from '../do-runner/run-terminal-state.js';
|
|
17
19
|
import { captureReservation, sameReservationIdentity, } from '../do-runner/start-reservation-contract.js';
|
|
@@ -106,7 +108,10 @@ function entryPath(value) {
|
|
|
106
108
|
function safeContext(value) {
|
|
107
109
|
if (value === undefined ||
|
|
108
110
|
(value !== null && typeof value === 'object' && !Array.isArray(value))) {
|
|
109
|
-
|
|
111
|
+
const context = sanitizeStoredAgentContext(value);
|
|
112
|
+
if (Object.values(context).some((item) => exceedsRunInputDepth(item)))
|
|
113
|
+
throw new AgentHostRequestError(400, runInputDepthMessage('a safeContext value'));
|
|
114
|
+
return context;
|
|
110
115
|
}
|
|
111
116
|
throw new AgentHostRequestError(400, 'safeContext must be an object');
|
|
112
117
|
}
|
|
@@ -1065,6 +1070,10 @@ export function createThreadAgentHost(options) {
|
|
|
1065
1070
|
owner: principalOwner(stored.runRecord.principal),
|
|
1066
1071
|
threaded: stored.threaded,
|
|
1067
1072
|
},
|
|
1073
|
+
// Agent legs touch their row while they run.
|
|
1074
|
+
startLeg: ownFrame !== undefined && unwoundExecutions.has(ownFrame)
|
|
1075
|
+
? 'unwound'
|
|
1076
|
+
: 'touched',
|
|
1068
1077
|
});
|
|
1069
1078
|
}
|
|
1070
1079
|
else {
|
|
@@ -1196,8 +1205,34 @@ export function createThreadAgentHost(options) {
|
|
|
1196
1205
|
const pending = await storage.list({
|
|
1197
1206
|
prefix: AGENT_OWNER_RECOVERY_PREFIX,
|
|
1198
1207
|
});
|
|
1208
|
+
let firstFailure;
|
|
1199
1209
|
for (const [key, stored] of pending) {
|
|
1200
|
-
|
|
1210
|
+
// From the key: a malformed journal may carry no run id.
|
|
1211
|
+
const runId = key.slice(AGENT_OWNER_RECOVERY_PREFIX.length);
|
|
1212
|
+
// Journals recover independently: a failing one keeps its journal
|
|
1213
|
+
// and the wake for a later alarm while the others are recovered.
|
|
1214
|
+
try {
|
|
1215
|
+
await recoverOwner(scope, key, stored);
|
|
1216
|
+
}
|
|
1217
|
+
catch (error) {
|
|
1218
|
+
// A start whose leg may still run, or whose row has not gone
|
|
1219
|
+
// silent, settled nothing.
|
|
1220
|
+
if (isRunStartPendingError(error)) {
|
|
1221
|
+
console.error(JSON.stringify({
|
|
1222
|
+
type: 'agent-start-recovery-pending',
|
|
1223
|
+
threadId: scope.threadId,
|
|
1224
|
+
runId,
|
|
1225
|
+
}));
|
|
1226
|
+
continue;
|
|
1227
|
+
}
|
|
1228
|
+
console.error(JSON.stringify({
|
|
1229
|
+
type: 'agent-start-recovery-failed',
|
|
1230
|
+
threadId: scope.threadId,
|
|
1231
|
+
runId,
|
|
1232
|
+
error: errorMessageOf(error),
|
|
1233
|
+
}));
|
|
1234
|
+
firstFailure ??= { error };
|
|
1235
|
+
}
|
|
1201
1236
|
}
|
|
1202
1237
|
await withRecoveryLock(async () => {
|
|
1203
1238
|
const remaining = await storage.list({
|
|
@@ -1210,6 +1245,8 @@ export function createThreadAgentHost(options) {
|
|
|
1210
1245
|
await storage.deleteAlarm();
|
|
1211
1246
|
}
|
|
1212
1247
|
});
|
|
1248
|
+
if (firstFailure)
|
|
1249
|
+
throw firstFailure.error;
|
|
1213
1250
|
}
|
|
1214
1251
|
catch (error) {
|
|
1215
1252
|
await withRecoveryLock(() => ensureOwnerRecoveryAlarm(storage));
|
|
@@ -1315,6 +1352,8 @@ export function createThreadAgentHost(options) {
|
|
|
1315
1352
|
}
|
|
1316
1353
|
try {
|
|
1317
1354
|
assertNoGuardedSystemMessages(messagesSnapshot);
|
|
1355
|
+
if (exceedsRunInputDepth(messagesSnapshot))
|
|
1356
|
+
throw new AgentHostRequestError(400, runInputDepthMessage('agent input'));
|
|
1318
1357
|
assertAcceptedCallProviderOptions(providerOptionsSnapshot);
|
|
1319
1358
|
}
|
|
1320
1359
|
catch (error) {
|
|
@@ -1730,6 +1769,12 @@ export function createThreadAgentHost(options) {
|
|
|
1730
1769
|
requestedBy: requesterId,
|
|
1731
1770
|
...(step !== undefined ? { step } : {}),
|
|
1732
1771
|
...resumeFields,
|
|
1772
|
+
// The runtime validates it.
|
|
1773
|
+
...(body.expectedSuspension === undefined
|
|
1774
|
+
? {}
|
|
1775
|
+
: {
|
|
1776
|
+
expectedSuspension: body.expectedSuspension,
|
|
1777
|
+
}),
|
|
1733
1778
|
...(snapshotExecution.threaded
|
|
1734
1779
|
? {
|
|
1735
1780
|
memory: {
|
|
@@ -1817,6 +1862,22 @@ export function createThreadAgentHost(options) {
|
|
|
1817
1862
|
}
|
|
1818
1863
|
}
|
|
1819
1864
|
const transition = await scopedRuntime.terminateAsPrincipal(await workflowIdFor(scope, ref.agentId), ref.runId, scope.principal, owner ?? scope.principal);
|
|
1865
|
+
// The dispatch lock this body holds orders the release after the
|
|
1866
|
+
// runner tail of any start or resume leg here, so a cut leg's tail
|
|
1867
|
+
// has published or claimed its terminal ERROR first. A leg cut after
|
|
1868
|
+
// its engine suspended ends without one, and a run suspended in this
|
|
1869
|
+
// object still holds its stream and registries.
|
|
1870
|
+
try {
|
|
1871
|
+
await runtime?.agents.get(ref.agentId)?.releaseEndedRun(ref.runId);
|
|
1872
|
+
}
|
|
1873
|
+
catch (error) {
|
|
1874
|
+
console.error(JSON.stringify({
|
|
1875
|
+
type: 'agent-run-release-failed',
|
|
1876
|
+
threadId: scope.threadId,
|
|
1877
|
+
runId: ref.runId,
|
|
1878
|
+
error: errorMessageOf(error),
|
|
1879
|
+
}));
|
|
1880
|
+
}
|
|
1820
1881
|
const selected = await selectedAgentState(scope, ref, {
|
|
1821
1882
|
includeLegacy: true,
|
|
1822
1883
|
});
|