@proofoftech/flowsafe 0.20.0 → 0.21.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 +81 -0
- package/README.md +55 -8
- package/deployment-identity-protocol.d.mts +28 -3
- package/deployment-identity-protocol.mjs +275 -21
- package/dist/agent-host/router.d.ts.map +1 -1
- package/dist/agent-host/router.js +11 -2
- package/dist/agent-host/router.js.map +1 -1
- package/dist/agent-host/thread-host.d.ts +3 -1
- package/dist/agent-host/thread-host.d.ts.map +1 -1
- package/dist/agent-host/thread-host.js +837 -332
- package/dist/agent-host/thread-host.js.map +1 -1
- package/dist/agent-host/thread-topology.d.ts +8 -0
- package/dist/agent-host/thread-topology.d.ts.map +1 -1
- package/dist/agent-host/thread-topology.js +239 -62
- package/dist/agent-host/thread-topology.js.map +1 -1
- package/dist/agent-runner/durable-agent-runner.d.ts +90 -6
- package/dist/agent-runner/durable-agent-runner.d.ts.map +1 -1
- package/dist/agent-runner/durable-agent-runner.js +371 -29
- package/dist/agent-runner/durable-agent-runner.js.map +1 -1
- package/dist/agent-runner/index.d.ts +1 -1
- package/dist/agent-runner/index.d.ts.map +1 -1
- package/dist/agent-runner/index.js.map +1 -1
- package/dist/approval-api/actor-context.d.ts +4 -0
- package/dist/approval-api/actor-context.d.ts.map +1 -1
- package/dist/approval-api/actor-context.js +53 -5
- package/dist/approval-api/actor-context.js.map +1 -1
- package/dist/approval-api/principal.d.ts +1 -1
- package/dist/approval-api/principal.js +1 -1
- package/dist/approval-api/retention.d.ts +1 -2
- package/dist/approval-api/retention.d.ts.map +1 -1
- package/dist/approval-api/retention.js.map +1 -1
- package/dist/approval-api/service.d.ts +10 -14
- package/dist/approval-api/service.d.ts.map +1 -1
- package/dist/approval-api/service.js +49 -22
- package/dist/approval-api/service.js.map +1 -1
- package/dist/audit-export/index.d.ts +2 -2
- package/dist/audit-export/index.js +2 -2
- package/dist/background-tasks/d1-storage.d.ts +4 -3
- package/dist/background-tasks/d1-storage.d.ts.map +1 -1
- package/dist/background-tasks/d1-storage.js +7 -13
- package/dist/background-tasks/d1-storage.js.map +1 -1
- package/dist/do-runner/constants.d.ts +3 -0
- package/dist/do-runner/constants.d.ts.map +1 -0
- package/dist/do-runner/constants.js +3 -0
- package/dist/do-runner/constants.js.map +1 -0
- package/dist/do-runner/d1-storage.d.ts +31 -157
- package/dist/do-runner/d1-storage.d.ts.map +1 -1
- package/dist/do-runner/d1-storage.js +933 -402
- package/dist/do-runner/d1-storage.js.map +1 -1
- package/dist/do-runner/durable-object.d.ts.map +1 -1
- package/dist/do-runner/durable-object.js +462 -175
- package/dist/do-runner/durable-object.js.map +1 -1
- package/dist/do-runner/execution-admission.d.ts +114 -0
- package/dist/do-runner/execution-admission.d.ts.map +1 -0
- package/dist/do-runner/execution-admission.js +206 -0
- package/dist/do-runner/execution-admission.js.map +1 -0
- package/dist/do-runner/execution-context.d.ts.map +1 -1
- package/dist/do-runner/execution-context.js +1 -0
- package/dist/do-runner/execution-context.js.map +1 -1
- package/dist/do-runner/execution-fence.d.ts +74 -30
- package/dist/do-runner/execution-fence.d.ts.map +1 -1
- package/dist/do-runner/execution-fence.js +684 -120
- package/dist/do-runner/execution-fence.js.map +1 -1
- package/dist/do-runner/fenced-workflow-capability.d.ts +64 -0
- package/dist/do-runner/fenced-workflow-capability.d.ts.map +1 -0
- package/dist/do-runner/fenced-workflow-capability.js +3 -0
- package/dist/do-runner/fenced-workflow-capability.js.map +1 -0
- package/dist/do-runner/fenced-workflows-d1.d.ts +15 -0
- package/dist/do-runner/fenced-workflows-d1.d.ts.map +1 -0
- package/dist/do-runner/fenced-workflows-d1.js +894 -0
- package/dist/do-runner/fenced-workflows-d1.js.map +1 -0
- package/dist/do-runner/index.d.ts +13 -8
- package/dist/do-runner/index.d.ts.map +1 -1
- package/dist/do-runner/index.js +6 -2
- package/dist/do-runner/index.js.map +1 -1
- package/dist/do-runner/initial-admission-refusal.d.ts +7 -0
- package/dist/do-runner/initial-admission-refusal.d.ts.map +1 -0
- package/dist/do-runner/initial-admission-refusal.js +41 -0
- package/dist/do-runner/initial-admission-refusal.js.map +1 -0
- package/dist/do-runner/inventory.d.ts +2 -1
- package/dist/do-runner/inventory.d.ts.map +1 -1
- package/dist/do-runner/inventory.js +28 -39
- package/dist/do-runner/inventory.js.map +1 -1
- package/dist/do-runner/notification-predicate.d.ts +7 -7
- package/dist/do-runner/notification-predicate.d.ts.map +1 -1
- package/dist/do-runner/notification-predicate.js +134 -7
- package/dist/do-runner/notification-predicate.js.map +1 -1
- package/dist/do-runner/run-lifecycle.d.ts +20 -1
- package/dist/do-runner/run-lifecycle.d.ts.map +1 -1
- package/dist/do-runner/run-lifecycle.js +67 -13
- package/dist/do-runner/run-lifecycle.js.map +1 -1
- package/dist/do-runner/run-provenance.d.ts +38 -0
- package/dist/do-runner/run-provenance.d.ts.map +1 -0
- package/dist/do-runner/run-provenance.js +152 -0
- package/dist/do-runner/run-provenance.js.map +1 -0
- package/dist/do-runner/run-storage-tables.d.ts +2 -0
- package/dist/do-runner/run-storage-tables.d.ts.map +1 -0
- package/dist/do-runner/run-storage-tables.js +4 -0
- package/dist/do-runner/run-storage-tables.js.map +1 -0
- package/dist/do-runner/run-terminal-state.d.ts +29 -0
- package/dist/do-runner/run-terminal-state.d.ts.map +1 -0
- package/dist/do-runner/run-terminal-state.js +105 -0
- package/dist/do-runner/run-terminal-state.js.map +1 -0
- package/dist/do-runner/runtime.d.ts +108 -46
- package/dist/do-runner/runtime.d.ts.map +1 -1
- package/dist/do-runner/runtime.js +927 -438
- package/dist/do-runner/runtime.js.map +1 -1
- package/dist/do-runner/start-idempotency.d.ts +35 -258
- package/dist/do-runner/start-idempotency.d.ts.map +1 -1
- package/dist/do-runner/start-idempotency.js +602 -494
- package/dist/do-runner/start-idempotency.js.map +1 -1
- package/dist/do-runner/start-reservation-contract.d.ts +103 -0
- package/dist/do-runner/start-reservation-contract.d.ts.map +1 -0
- package/dist/do-runner/start-reservation-contract.js +338 -0
- package/dist/do-runner/start-reservation-contract.js.map +1 -0
- package/dist/do-runner/suspension-deadline.d.ts +4 -11
- package/dist/do-runner/suspension-deadline.d.ts.map +1 -1
- package/dist/do-runner/suspension-deadline.js +8 -12
- package/dist/do-runner/suspension-deadline.js.map +1 -1
- package/dist/do-runner/table-prefix.d.ts.map +1 -1
- package/dist/do-runner/table-prefix.js +2 -1
- package/dist/do-runner/table-prefix.js.map +1 -1
- package/dist/do-runner/testing.d.ts +3 -0
- package/dist/do-runner/testing.d.ts.map +1 -0
- package/dist/do-runner/testing.js +3 -0
- package/dist/do-runner/testing.js.map +1 -0
- package/dist/do-runner/thread-do.d.ts +2 -1
- package/dist/do-runner/thread-do.d.ts.map +1 -1
- package/dist/do-runner/thread-do.js +14 -10
- package/dist/do-runner/thread-do.js.map +1 -1
- package/dist/do-runner/workflow-snapshot-row.d.ts +49 -0
- package/dist/do-runner/workflow-snapshot-row.d.ts.map +1 -0
- package/dist/do-runner/workflow-snapshot-row.js +97 -0
- package/dist/do-runner/workflow-snapshot-row.js.map +1 -0
- package/dist/goals/objective-routes.d.ts +1 -5
- package/dist/goals/objective-routes.d.ts.map +1 -1
- package/dist/goals/objective-routes.js +32 -53
- package/dist/goals/objective-routes.js.map +1 -1
- package/dist/host-kit/approval-bridge.d.ts.map +1 -1
- package/dist/host-kit/approval-bridge.js +10 -7
- package/dist/host-kit/approval-bridge.js.map +1 -1
- package/dist/host-kit/do-response.d.ts +16 -0
- package/dist/host-kit/do-response.d.ts.map +1 -1
- package/dist/host-kit/do-response.js +181 -0
- package/dist/host-kit/do-response.js.map +1 -1
- package/dist/host-kit/do-run-topology.d.ts +2 -14
- package/dist/host-kit/do-run-topology.d.ts.map +1 -1
- package/dist/host-kit/do-run-topology.js +31 -24
- package/dist/host-kit/do-run-topology.js.map +1 -1
- package/dist/host-kit/env-vars.d.ts.map +1 -1
- package/dist/host-kit/env-vars.js +5 -6
- package/dist/host-kit/env-vars.js.map +1 -1
- package/dist/host-kit/flowsafe-worker.d.ts +38 -6
- package/dist/host-kit/flowsafe-worker.d.ts.map +1 -1
- package/dist/host-kit/flowsafe-worker.js +110 -93
- package/dist/host-kit/flowsafe-worker.js.map +1 -1
- package/dist/host-kit/host-approval-service.d.ts +4 -14
- package/dist/host-kit/host-approval-service.d.ts.map +1 -1
- package/dist/host-kit/host-approval-service.js +23 -40
- package/dist/host-kit/host-approval-service.js.map +1 -1
- package/dist/host-kit/index.d.ts +7 -1
- package/dist/host-kit/index.d.ts.map +1 -1
- package/dist/host-kit/index.js +4 -0
- package/dist/host-kit/index.js.map +1 -1
- package/dist/host-kit/run-route-error.d.ts +3 -17
- package/dist/host-kit/run-route-error.d.ts.map +1 -1
- package/dist/host-kit/run-route-error.js +4 -24
- package/dist/host-kit/run-route-error.js.map +1 -1
- package/dist/host-kit/run-router.d.ts +6 -2
- package/dist/host-kit/run-router.d.ts.map +1 -1
- package/dist/host-kit/run-router.js +93 -80
- package/dist/host-kit/run-router.js.map +1 -1
- package/dist/host-kit/thread-topology.d.ts +1 -1
- package/dist/host-kit/thread-topology.d.ts.map +1 -1
- package/dist/host-kit/thread-topology.js +7 -3
- package/dist/host-kit/thread-topology.js.map +1 -1
- package/dist/internal-error-response.d.ts.map +1 -1
- package/dist/internal-error-response.js +16 -6
- package/dist/internal-error-response.js.map +1 -1
- package/dist/schedules/index.d.ts +1 -0
- package/dist/schedules/index.d.ts.map +1 -1
- package/dist/schedules/index.js +1 -7
- package/dist/schedules/index.js.map +1 -1
- package/dist/schedules/mutation-contract.d.ts +38 -0
- package/dist/schedules/mutation-contract.d.ts.map +1 -0
- package/dist/schedules/mutation-contract.js +21 -0
- package/dist/schedules/mutation-contract.js.map +1 -0
- package/dist/schedules/router.d.ts +11 -19
- package/dist/schedules/router.d.ts.map +1 -1
- package/dist/schedules/router.js +130 -49
- package/dist/schedules/router.js.map +1 -1
- package/dist/schedules/schedules-d1.d.ts +11 -5
- package/dist/schedules/schedules-d1.d.ts.map +1 -1
- package/dist/schedules/schedules-d1.js +570 -143
- package/dist/schedules/schedules-d1.js.map +1 -1
- package/dist/schedules/storage.d.ts +0 -7
- package/dist/schedules/storage.d.ts.map +1 -1
- package/dist/schedules/storage.js +0 -27
- package/dist/schedules/storage.js.map +1 -1
- package/dist/schedules/tick.d.ts.map +1 -1
- package/dist/schedules/tick.js +7 -1
- package/dist/schedules/tick.js.map +1 -1
- package/dist/signal-providers/webhook-route.d.ts +1 -1
- package/dist/signal-providers/webhook-route.d.ts.map +1 -1
- package/dist/signal-providers/webhook-route.js +99 -109
- package/dist/signal-providers/webhook-route.js.map +1 -1
- package/dist/signals/d1-shared.d.ts +11 -8
- package/dist/signals/d1-shared.d.ts.map +1 -1
- package/dist/signals/d1-shared.js +1 -6
- package/dist/signals/d1-shared.js.map +1 -1
- package/dist/signals/index.d.ts +1 -1
- package/dist/signals/index.d.ts.map +1 -1
- package/dist/signals/index.js +1 -1
- package/dist/signals/index.js.map +1 -1
- package/dist/signals/notification-dispatch.d.ts +96 -5
- package/dist/signals/notification-dispatch.d.ts.map +1 -1
- package/dist/signals/notification-dispatch.js +418 -53
- package/dist/signals/notification-dispatch.js.map +1 -1
- package/dist/signals/notifications-d1.d.ts +6 -1
- package/dist/signals/notifications-d1.d.ts.map +1 -1
- package/dist/signals/notifications-d1.js +215 -10
- package/dist/signals/notifications-d1.js.map +1 -1
- package/dist/signals/router.d.ts +6 -4
- package/dist/signals/router.d.ts.map +1 -1
- package/dist/signals/router.js +49 -84
- package/dist/signals/router.js.map +1 -1
- package/dist/signals/thread-do-routes.d.ts +2 -0
- package/dist/signals/thread-do-routes.d.ts.map +1 -1
- package/dist/signals/thread-do-routes.js +252 -73
- package/dist/signals/thread-do-routes.js.map +1 -1
- package/package.json +6 -3
- package/patches/@mastra__core@1.53.0.patch +54 -0
- package/scripts/seed-deployment-identity.mjs +12 -5
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ActorContext, ActorResolver, ApprovalAuditEvent, ApprovalDatabase, ApprovalNotificationSink } from '../approval-api/index.js';
|
|
2
2
|
import { type AuditProxyNamespaceLike, type AuditQueue, type InfrastructureAuditEnvelope } from '../audit-export/index.js';
|
|
3
3
|
import type { DurableObjectRunLifecycleHooks } from '../do-runner/durable-object.js';
|
|
4
|
-
import type { DeploymentIdentityDatabase, RunArtifactPurger, RunDeadlineCursor, SnapshotDatabase } from '../do-runner/index.js';
|
|
4
|
+
import type { DeploymentIdentityDatabase, RunArtifactPurger, RunDeadlineCursor, RunRetentionCursor, SnapshotDatabase } from '../do-runner/index.js';
|
|
5
5
|
import { type ResumeRunFn } from './approval-bridge.js';
|
|
6
6
|
import { type DoRunTopology, type RunnerNamespaceLike } from './do-run-topology.js';
|
|
7
7
|
import { type MaintenanceOutcome } from './host-approval-service.js';
|
|
@@ -86,8 +86,7 @@ export interface FlowsafeWorkerEnv {
|
|
|
86
86
|
FLEET_DEPLOYMENT_SCRIPT?: string;
|
|
87
87
|
/** Fleet resource group stamped onto trusted state. */
|
|
88
88
|
FLEET_RESOURCE_GROUP?: string;
|
|
89
|
-
|
|
90
|
-
FLEET_RESOURCE_ROLE?: 'platform-state';
|
|
89
|
+
FLEET_RESOURCE_ROLE?: 'platform-state' | 'platform-catalog';
|
|
91
90
|
/** Per-deployment Worker-to-Durable-Object credential. */
|
|
92
91
|
DEPLOYMENT_IDENTITY_SECRET: string;
|
|
93
92
|
/** The runner DO namespace createDoRunTopology drives. */
|
|
@@ -209,6 +208,11 @@ export interface FlowsafeRunnerLifecycleConfig<Env extends FlowsafeWorkerEnv> {
|
|
|
209
208
|
storageTablePrefix?: string;
|
|
210
209
|
}
|
|
211
210
|
export interface FlowsafeWorkerConfig<Env extends FlowsafeWorkerEnv> extends FlowsafeRunnerLifecycleConfig<Env> {
|
|
211
|
+
/**
|
|
212
|
+
* Trusted host epoch, captured before request authentication and storage waits.
|
|
213
|
+
* Callbacks return a number or undefined synchronously; client headers cannot supply it.
|
|
214
|
+
*/
|
|
215
|
+
mutationEpoch?: number | ((env: Env) => unknown);
|
|
212
216
|
/** The catalog createRunRouter serves and gates (hosts pass their metas). */
|
|
213
217
|
workflows: ReadonlyArray<WorkflowMeta>;
|
|
214
218
|
/**
|
|
@@ -243,7 +247,7 @@ export interface FlowsafeWorkerConfig<Env extends FlowsafeWorkerEnv> extends Flo
|
|
|
243
247
|
topology: DoRunTopology;
|
|
244
248
|
}) => Promise<Response | null>;
|
|
245
249
|
/** Host policy immediately before a validated start reaches the run DO. */
|
|
246
|
-
beforeStart?: (context: ActorContext, env: Env, workflowId: string, inputData: unknown) => Promise<void>;
|
|
250
|
+
beforeStart?: (context: ActorContext, env: Env, workflowId: string, inputData: unknown, requestContext: Record<string, unknown> | undefined) => Promise<void>;
|
|
247
251
|
/** Host policy immediately before a validated raw resume reaches the run DO. */
|
|
248
252
|
beforeResume?: (context: ActorContext, env: Env, workflowId: string, runId: string, body: unknown) => Promise<void>;
|
|
249
253
|
/**
|
|
@@ -309,7 +313,10 @@ export interface FlowsafeWorkerConfig<Env extends FlowsafeWorkerEnv> extends Flo
|
|
|
309
313
|
* (which needs the schedules store, its run-start seam — topology.start — and
|
|
310
314
|
* the run-cap + audit config) and returns the closure here. The composer runs
|
|
311
315
|
* it as its OWN failure-isolated alarm duty (own try/catch,
|
|
312
|
-
* own `schedule-tick` log line).
|
|
316
|
+
* own `schedule-tick` log line). The composer invokes THIS BUILDER outside
|
|
317
|
+
* that try, so a builder that throws is logged as `maintenance-error` with
|
|
318
|
+
* `surface: 'tick-duty'`; build a factory that can refuse at construction
|
|
319
|
+
* inside the returned closure. INJECTED (not built here, structurally typed as
|
|
313
320
|
* `() => Promise<unknown>`) because createScheduleTick lives in `schedules/`,
|
|
314
321
|
* which transitively imports host-kit — host-kit importing it back would cycle.
|
|
315
322
|
* Absent (or `tickIntervalMs` unset) ⇒ no tick invocation.
|
|
@@ -334,14 +341,39 @@ export interface FlowsafeRunnerLifecycleOptions {
|
|
|
334
341
|
*/
|
|
335
342
|
export declare function createFlowsafeRunnerLifecycle<Env extends FlowsafeWorkerEnv>(config: FlowsafeRunnerLifecycleConfig<Env>, env: Env, options?: FlowsafeRunnerLifecycleOptions): DurableObjectRunLifecycleHooks;
|
|
336
343
|
export type MaintenanceDuty = 'deadline' | 'sweep' | 'purge' | 'tick';
|
|
344
|
+
/**
|
|
345
|
+
* The cursor seam a duty resumes from and advances. Each field is optional
|
|
346
|
+
* because the deadline duty and the retention purge own one pair each, and a
|
|
347
|
+
* caller driving one duty has nothing to say about the other's cursor. The
|
|
348
|
+
* purge takes `MaintenancePurgeDutyContext` instead, which requires its half.
|
|
349
|
+
* The deadline duty reads `deadlineCursor` only alongside
|
|
350
|
+
* `advanceDeadlineCursor`: a cursor supplied without the callback that
|
|
351
|
+
* advances it is ignored.
|
|
352
|
+
*/
|
|
337
353
|
export interface MaintenanceDutyContext {
|
|
338
354
|
deadlineCursor?: RunDeadlineCursor;
|
|
339
355
|
advanceDeadlineCursor?(cursor: RunDeadlineCursor): Promise<void>;
|
|
356
|
+
retentionCursor?: RunRetentionCursor;
|
|
357
|
+
advanceRetentionCursor?(cursor: RunRetentionCursor): Promise<void>;
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* The retention purge's own context. `advanceRetentionCursor` is required here
|
|
361
|
+
* because the layer it feeds requires it: `purgeExpiredWorkflowRuns` declares
|
|
362
|
+
* `advanceCursor` non-optional (do-runner/d1-storage.ts), and a purge with
|
|
363
|
+
* nowhere to record its progress rescans the same terminal rows on every
|
|
364
|
+
* alarm. The type keeps a typed host from omitting it; `hasRetentionCursorSeam`
|
|
365
|
+
* refuses an untyped one under `config-error` before any purge surface runs,
|
|
366
|
+
* rather than letting the purge report a `retention-purge` failure.
|
|
367
|
+
*/
|
|
368
|
+
export interface MaintenancePurgeDutyContext extends MaintenanceDutyContext {
|
|
369
|
+
advanceRetentionCursor(cursor: RunRetentionCursor): Promise<void>;
|
|
340
370
|
}
|
|
341
371
|
/** The Worker handler plus the maintenance duty seam consumed by its DO. */
|
|
342
372
|
export interface FlowsafeWorker<Env extends FlowsafeWorkerEnv> {
|
|
343
373
|
fetch(request: Request, env: Env, ctx: FlowsafeWorkerContext): Promise<Response>;
|
|
344
|
-
|
|
374
|
+
/** The purge duty requires the retention cursor seam; the others do not. */
|
|
375
|
+
runMaintenanceDuty(duty: 'purge', env: Env, context: MaintenancePurgeDutyContext): Promise<MaintenanceOutcome>;
|
|
376
|
+
runMaintenanceDuty(duty: Exclude<MaintenanceDuty, 'purge'>, env: Env, context?: MaintenanceDutyContext): Promise<MaintenanceOutcome>;
|
|
345
377
|
}
|
|
346
378
|
export declare function createFlowsafeWorker<Env extends FlowsafeWorkerEnv>(config: FlowsafeWorkerConfig<Env>): FlowsafeWorker<Env>;
|
|
347
379
|
export type MaintenanceDurableObjectConstructor<Env extends FlowsafeWorkerEnv> = new (state: MaintenanceDurableObjectState, env: Env) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flowsafe-worker.d.ts","sourceRoot":"","sources":["../../src/host-kit/flowsafe-worker.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"flowsafe-worker.d.ts","sourceRoot":"","sources":["../../src/host-kit/flowsafe-worker.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,wBAAwB,EAKzB,MAAM,0BAA0B,CAAC;AASlC,OAAO,EACL,KAAK,uBAAuB,EAC5B,KAAK,UAAU,EAGf,KAAK,2BAA2B,EACjC,MAAM,0BAA0B,CAAC;AAGlC,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,gCAAgC,CAAC;AAKrF,OAAO,KAAK,EACV,0BAA0B,EAG1B,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAEjB,MAAM,uBAAuB,CAAC;AA2B/B,OAAO,EAA0B,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEhF,OAAO,EA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AAE,2BAA2B,GACnC,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC/B,kBAAkB,CAChB,IAAI,EAAE,OAAO,CAAC,eAAe,EAAE,OAAO,CAAC,EACvC,GAAG,EAAE,GAAG,EACR,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CAAC;CAChC;AAuYD,wBAAgB,oBAAoB,CAAC,GAAG,SAAS,iBAAiB,EAChE,MAAM,EAAE,oBAAoB,CAAC,GAAG,CAAC,GAChC,cAAc,CAAC,GAAG,CAAC,CA0nBrB;AAUD,MAAM,MAAM,mCAAmC,CAAC,GAAG,SAAS,iBAAiB,IAC3E,KACE,KAAK,EAAE,6BAA6B,EACpC,GAAG,EAAE,GAAG,KACL;IACH,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC3C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB,CAAC;AAEJ,0EAA0E;AAC1E,wBAAgB,sCAAsC,CACpD,GAAG,SAAS,iBAAiB,EAC7B,MAAM,EAAE,oBAAoB,CAAC,GAAG,CAAC,GAAG,mCAAmC,CAAC,GAAG,CAAC,CA0V7E"}
|
|
@@ -1,17 +1,9 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
// createFlowsafeWorker — the whole production-Worker skeleton the deploy
|
|
3
|
-
// template and the showcase host previously carried as near-byte copies:
|
|
4
|
-
// the /healthz → routers → 404 fetch pipeline over one actor resolver, the
|
|
5
|
-
// alarm-driven maintenance (deadline, sweep, purge, and optional schedule tick
|
|
6
|
-
// never share an invocation). Hosts stay thin shells: they supply workflows,
|
|
7
|
-
// their identity seam (buildVerifier), and their deployment-specific hooks —
|
|
8
|
-
// preRoutes (extra unauthenticated/authenticated mounts), beforeStart/
|
|
9
|
-
// beforeResume (e.g. a budget charge), notify (reviewer-facing transport), and
|
|
10
|
-
// extraPurgeDuties (e.g. a host-specific purge). Everything here is structural:
|
|
11
|
-
// host-kit never imports @cloudflare/workers-types.
|
|
12
2
|
import { APPROVAL_ROLES, createActorResolver, createApprovalRouter, createResourceOwnershipSchema, RESOURCE_OWNERSHIP_TABLE, trustAutomationPrincipal, } from '../approval-api/index.js';
|
|
13
3
|
import { createAuditProxyDurableObjectBinding, createAuditProxyQueue, } from '../audit-export/index.js';
|
|
4
|
+
import { parseRunRetentionCursor } from '../do-runner/d1-storage.js';
|
|
14
5
|
import { credentialsMatch } from '../do-runner/deployment-identity.js';
|
|
6
|
+
import { InvalidMutationEpochError, normalizeMutationEpoch, } from '../do-runner/execution-admission.js';
|
|
15
7
|
import { assertExecutionFenceState, DEPLOYMENT_IDENTITY_HEADER, DeploymentIdentityError, DeploymentInventory, DoStatusError, deploymentIdentityHeaders, ensureDeploymentIdentityBindings, executionFenceFor, executionFenceReadingPayload, InvalidInventoryRequestError, isInventoryCategory, purgeExpiredBackgroundTasks, purgeExpiredNotifications, purgeExpiredScheduleTriggers, purgeExpiredThreadState, purgeExpiredThreads, purgeExpiredWorkflowRuns, START_IDEMPOTENCY_TABLE, startIdempotencyFor, sweepExpiredRunDeadlines, verifyDurableObjectDeploymentIdentity, verifyDurableObjectDeploymentRequest, } from '../do-runner/index.js';
|
|
16
8
|
import { validateTablePrefix } from '../do-runner/table-prefix.js';
|
|
17
9
|
import { readBoundedBody } from '../http-body.js';
|
|
@@ -19,7 +11,7 @@ import { abandonApprovalsForRun } from './approval-bridge.js';
|
|
|
19
11
|
import { bearerActorAuthenticator } from './bearer-auth.js';
|
|
20
12
|
import { createDoRunTopology, } from './do-run-topology.js';
|
|
21
13
|
import { numberVar, optionalNumberVar, selfDecisionPolicyVar, } from './env-vars.js';
|
|
22
|
-
import { approvalStoreFactoryFor, buildHostApprovalService, maintenancePrincipal, reconcileApprovalsOnStatusDetached, runApprovalRetentionPurge, runSlaSweepMaintenance, } from './host-approval-service.js';
|
|
14
|
+
import { approvalStoreFactoryFor, buildHostApprovalService, hostErrorText, maintenancePrincipal, reconcileApprovalsOnStatusDetached, runApprovalRetentionPurge, runSlaSweepMaintenance, } from './host-approval-service.js';
|
|
23
15
|
import { createHubTopology } from './hub-topology.js';
|
|
24
16
|
import { MAINTENANCE_RECEIPT_HEADER, mintMaintenanceReceipt, verifyAsymmetricMaintenanceCapability, verifyMaintenanceCapability, } from './maintenance-capability.js';
|
|
25
17
|
import { createRunRouter } from './run-router.js';
|
|
@@ -41,6 +33,7 @@ function buildConfiguredApprovalService(config, env, topology, options) {
|
|
|
41
33
|
allowSelfDecision: options.allowSelfDecision,
|
|
42
34
|
stream: options.stream,
|
|
43
35
|
executionFence: options.executionFence,
|
|
36
|
+
workflowTablePrefix: options.workflowTablePrefix,
|
|
44
37
|
});
|
|
45
38
|
}
|
|
46
39
|
/**
|
|
@@ -58,6 +51,7 @@ export function createFlowsafeRunnerLifecycle(config, env, options = {}) {
|
|
|
58
51
|
const service = buildConfiguredApprovalService(config, env, topology, {
|
|
59
52
|
store: approvalStoreFactoryFor(env.DB, storageTablePrefix).store(),
|
|
60
53
|
executionFence: executionFenceForEnv(env),
|
|
54
|
+
workflowTablePrefix: (storageTablePrefix ?? '').toLowerCase(),
|
|
61
55
|
waitUntil: options.waitUntil,
|
|
62
56
|
notify: config.notify?.(env),
|
|
63
57
|
allowSelfDecision,
|
|
@@ -137,6 +131,10 @@ async function validateFleetChannelTopology(env) {
|
|
|
137
131
|
throw new Error('external fleet release has a direct audit queue binding');
|
|
138
132
|
}
|
|
139
133
|
}
|
|
134
|
+
const RETENTION_CURSOR_SEAM_REASON = 'retention purge requires advanceRetentionCursor';
|
|
135
|
+
function hasRetentionCursorSeam(context) {
|
|
136
|
+
return typeof context?.advanceRetentionCursor === 'function';
|
|
137
|
+
}
|
|
140
138
|
function json(payload, status = 200) {
|
|
141
139
|
return new Response(JSON.stringify(payload), {
|
|
142
140
|
status,
|
|
@@ -145,26 +143,6 @@ function json(payload, status = 200) {
|
|
|
145
143
|
}
|
|
146
144
|
const MAINTENANCE_ADMIN_SECRET_PATTERN = /^[\x21-\x7e]{32,256}$/;
|
|
147
145
|
const FLEET_SPEC_DIGEST_PATTERN = /^[a-f0-9]{64}$/;
|
|
148
|
-
/**
|
|
149
|
-
* The credential preamble EVERY /admin surface runs before it does anything.
|
|
150
|
-
*
|
|
151
|
-
* One function rather than a copy per route because this is the trust boundary
|
|
152
|
-
* itself (docs/security-threat-model.md, "The provisioning boundary"): it
|
|
153
|
-
* proves MAINTENANCE_ADMIN_SECRET is configured, proves it is DISTINCT from the
|
|
154
|
-
* deployment identity secret (sharing them would let a Worker-to-DO credential
|
|
155
|
-
* move the fence, and vice versa), and constant-time compares the request's
|
|
156
|
-
* Bearer token against it. A second copy is a second place for one of those
|
|
157
|
-
* three to be dropped in a hurry, and the inventory route lands here next.
|
|
158
|
-
*
|
|
159
|
-
* The surfaces differ in exactly ONE thing, which is why it is a parameter
|
|
160
|
-
* rather than a fork: what an ABSENT secret means. `/admin/execution-fence`
|
|
161
|
-
* always refuses — the fence is the control that stops a deployment executing,
|
|
162
|
-
* so an unauthenticated caller must never reach it. The maintenance routes
|
|
163
|
-
* delegate instead when the fleet requires capability tokens, because there the
|
|
164
|
-
* Durable Object verifies a signed capability and this Worker is only a relay;
|
|
165
|
-
* the longer credential cap applies to that path alone, since a capability
|
|
166
|
-
* token is not a shared secret.
|
|
167
|
-
*/
|
|
168
146
|
async function authorizeAdminCredential(request, env, options) {
|
|
169
147
|
const { surface } = options;
|
|
170
148
|
const unavailable = (reason) => {
|
|
@@ -183,10 +161,13 @@ async function authorizeAdminCredential(request, env, options) {
|
|
|
183
161
|
response: json({ error: 'authentication required' }, 401),
|
|
184
162
|
});
|
|
185
163
|
const expected = env.MAINTENANCE_ADMIN_SECRET;
|
|
186
|
-
const delegating =
|
|
187
|
-
if (
|
|
188
|
-
if (
|
|
189
|
-
|
|
164
|
+
const delegating = options.delegateCapability;
|
|
165
|
+
if (expected === undefined) {
|
|
166
|
+
if (!delegating)
|
|
167
|
+
return unavailable(`${surface} is not configured`);
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
if (!MAINTENANCE_ADMIN_SECRET_PATTERN.test(expected)) {
|
|
190
171
|
return unavailable(`${surface} is not configured`);
|
|
191
172
|
}
|
|
192
173
|
if (await credentialsMatch(expected, env.DEPLOYMENT_IDENTITY_SECRET)) {
|
|
@@ -198,7 +179,8 @@ async function authorizeAdminCredential(request, env, options) {
|
|
|
198
179
|
if (!credential || credential.length > maximumCredentialLength) {
|
|
199
180
|
return unauthenticated();
|
|
200
181
|
}
|
|
201
|
-
if (
|
|
182
|
+
if (!delegating &&
|
|
183
|
+
expected !== undefined &&
|
|
202
184
|
!(await credentialsMatch(credential, expected))) {
|
|
203
185
|
return unauthenticated();
|
|
204
186
|
}
|
|
@@ -223,10 +205,7 @@ async function maintenanceAdminResponse(request, env) {
|
|
|
223
205
|
}
|
|
224
206
|
const gate = await authorizeAdminCredential(request, env, {
|
|
225
207
|
surface: 'maintenance administration',
|
|
226
|
-
|
|
227
|
-
// requires capability tokens authenticates at the maintenance DO, which
|
|
228
|
-
// verifies a signed capability this Worker only relays.
|
|
229
|
-
delegateWhenUnconfigured: env.FLEET_MAINTENANCE_CAPABILITIES === 'required',
|
|
208
|
+
delegateCapability: env.FLEET_MAINTENANCE_CAPABILITIES === 'required',
|
|
230
209
|
});
|
|
231
210
|
if (!gate.authorized)
|
|
232
211
|
return gate.response;
|
|
@@ -319,7 +298,7 @@ async function executionFenceAdminResponse(request, env) {
|
|
|
319
298
|
// Unconfigured is 503, never open: the fence is the control that stops a
|
|
320
299
|
// deployment executing, so an unauthenticated caller must never move it.
|
|
321
300
|
// There is no capability-token relay behind this route to delegate to.
|
|
322
|
-
|
|
301
|
+
delegateCapability: false,
|
|
323
302
|
});
|
|
324
303
|
if (!gate.authorized)
|
|
325
304
|
return gate.response;
|
|
@@ -349,8 +328,11 @@ async function executionFenceAdminResponse(request, env) {
|
|
|
349
328
|
expected: assertExecutionFenceState(body.expected, 'expected'),
|
|
350
329
|
next: assertExecutionFenceState(body.next, 'next'),
|
|
351
330
|
...(body.proofKey === undefined ? {} : { proofKey: body.proofKey }),
|
|
331
|
+
expectedMutationEpoch: body.expectedMutationEpoch,
|
|
332
|
+
expectedRevision: body.expectedRevision,
|
|
333
|
+
advanceMutationEpoch: body.advanceMutationEpoch,
|
|
352
334
|
});
|
|
353
|
-
return json(
|
|
335
|
+
return json(executionFenceReadingPayload(reading));
|
|
354
336
|
}
|
|
355
337
|
catch (error) {
|
|
356
338
|
if (error instanceof DoStatusError) {
|
|
@@ -361,7 +343,7 @@ async function executionFenceAdminResponse(request, env) {
|
|
|
361
343
|
}
|
|
362
344
|
console.error(JSON.stringify({
|
|
363
345
|
type: 'execution-fence-admin-error',
|
|
364
|
-
reason: error
|
|
346
|
+
reason: hostErrorText(error, true),
|
|
365
347
|
}));
|
|
366
348
|
return json({ error: 'execution fence administration failed' }, 500);
|
|
367
349
|
}
|
|
@@ -420,7 +402,7 @@ async function inventoryAdminResponse(request, env, storageTablePrefix) {
|
|
|
420
402
|
// Unconfigured is 503, never open: this read enumerates every outstanding
|
|
421
403
|
// run, approval, and reservation on the deployment. There is no capability
|
|
422
404
|
// relay behind it to delegate to, either.
|
|
423
|
-
|
|
405
|
+
delegateCapability: false,
|
|
424
406
|
});
|
|
425
407
|
if (!gate.authorized)
|
|
426
408
|
return gate.response;
|
|
@@ -459,22 +441,27 @@ async function inventoryAdminResponse(request, env, storageTablePrefix) {
|
|
|
459
441
|
}
|
|
460
442
|
console.error(JSON.stringify({
|
|
461
443
|
type: 'inventory-admin-error',
|
|
462
|
-
reason: error
|
|
444
|
+
reason: hostErrorText(error, true),
|
|
463
445
|
}));
|
|
464
446
|
return json({ error: 'deployment inventory failed' }, 500);
|
|
465
447
|
}
|
|
466
448
|
}
|
|
467
449
|
export function createFlowsafeWorker(config) {
|
|
450
|
+
const epochSource = config.mutationEpoch;
|
|
451
|
+
if (typeof epochSource !== 'function')
|
|
452
|
+
normalizeMutationEpoch(epochSource);
|
|
468
453
|
const storageTablePrefix = validateTablePrefix(config.storageTablePrefix, 'storageTablePrefix');
|
|
469
454
|
// Authenticate before constructing request-scoped services.
|
|
470
|
-
const buildResolve = (env, topology, waitUntil, notify, selfDecision, stream) => {
|
|
455
|
+
const buildResolve = (env, topology, waitUntil, notify, selfDecision, stream, mutationEpoch) => {
|
|
471
456
|
const base = createActorResolver({
|
|
457
|
+
mutationEpoch,
|
|
472
458
|
authenticate: bearerActorAuthenticator(config.buildVerifier(env)),
|
|
473
459
|
storeFactory: approvalStoreFactoryFor(env.DB, storageTablePrefix),
|
|
474
460
|
deploymentTag: env.DEPLOYMENT_TENANT,
|
|
475
461
|
buildService: (store) => buildConfiguredApprovalService(config, env, topology, {
|
|
476
462
|
store,
|
|
477
463
|
executionFence: executionFenceForEnv(env),
|
|
464
|
+
workflowTablePrefix: (storageTablePrefix ?? '').toLowerCase(),
|
|
478
465
|
waitUntil,
|
|
479
466
|
notify,
|
|
480
467
|
stream,
|
|
@@ -508,10 +495,10 @@ export function createFlowsafeWorker(config) {
|
|
|
508
495
|
selfDecisionCache.set(raw, policy);
|
|
509
496
|
return policy;
|
|
510
497
|
};
|
|
511
|
-
async function runPurgeMaintenance(env, trigger) {
|
|
498
|
+
async function runPurgeMaintenance(env, trigger, context) {
|
|
512
499
|
const failures = [];
|
|
513
500
|
const recordFailure = (surface, error) => {
|
|
514
|
-
const failure =
|
|
501
|
+
const failure = hostErrorText(error).slice(0, 256);
|
|
515
502
|
failures.push(`${surface}: ${failure}`);
|
|
516
503
|
console.error(JSON.stringify({
|
|
517
504
|
type: 'maintenance-error',
|
|
@@ -522,12 +509,31 @@ export function createFlowsafeWorker(config) {
|
|
|
522
509
|
};
|
|
523
510
|
let purged;
|
|
524
511
|
try {
|
|
512
|
+
const advanceCursor = context.advanceRetentionCursor;
|
|
513
|
+
const db = env.DB;
|
|
514
|
+
const prepare = db.prepare;
|
|
515
|
+
const batch = db.batch;
|
|
516
|
+
if (typeof prepare !== 'function' || typeof batch !== 'function') {
|
|
517
|
+
throw new Error('retention purge requires database.prepare() and batch()');
|
|
518
|
+
}
|
|
519
|
+
const retentionDb = {
|
|
520
|
+
prepare: prepare.bind(db),
|
|
521
|
+
batch: batch.bind(db),
|
|
522
|
+
};
|
|
523
|
+
const storedCursor = parseRunRetentionCursor(context.retentionCursor);
|
|
524
|
+
const cursor = storedCursor?.tablePrefix ===
|
|
525
|
+
(storageTablePrefix?.toLowerCase() ?? '') &&
|
|
526
|
+
storedCursor.startIdempotencyTable === START_IDEMPOTENCY_TABLE
|
|
527
|
+
? storedCursor
|
|
528
|
+
: undefined;
|
|
525
529
|
const artifactStore = config.artifactStore?.(env);
|
|
526
530
|
// The resource registry is lazy like Mastra's snapshot table. Retention
|
|
527
531
|
// may be the first resource-aware operation in a fresh deployment, so
|
|
528
532
|
// initialize it before asking the atomic purge to reference it.
|
|
529
|
-
await createResourceOwnershipSchema(
|
|
530
|
-
purged = await purgeExpiredWorkflowRuns(
|
|
533
|
+
await createResourceOwnershipSchema(retentionDb);
|
|
534
|
+
purged = await purgeExpiredWorkflowRuns(retentionDb, {
|
|
535
|
+
cursor,
|
|
536
|
+
advanceCursor,
|
|
531
537
|
// allowZero: RUN_RETENTION_DAYS=0 means "purge terminal runs now".
|
|
532
538
|
ttlMs: numberVar(env.RUN_RETENTION_DAYS, 30, 'RUN_RETENTION_DAYS', {
|
|
533
539
|
allowZero: true,
|
|
@@ -536,21 +542,9 @@ export function createFlowsafeWorker(config) {
|
|
|
536
542
|
60 *
|
|
537
543
|
60 *
|
|
538
544
|
1000,
|
|
539
|
-
// Pairs each expired run's R2 artifacts with its snapshot-row deletion
|
|
540
|
-
// (artifacts BEFORE the row — the row is the only record of their keys).
|
|
541
|
-
// Undefined on hosts that wire no R2, so the purge stays byte-identical.
|
|
542
545
|
artifactStore,
|
|
543
546
|
tablePrefix: storageTablePrefix,
|
|
544
|
-
// Snapshot + owner release share one D1 transaction, so retention
|
|
545
|
-
// cannot leave unbounded run-ownership tombstones or expose a live row
|
|
546
|
-
// without its authorization record.
|
|
547
547
|
resourceOwnerTable: RESOURCE_OWNERSHIP_TABLE,
|
|
548
|
-
// Start reservations join the same transaction, for the same reason:
|
|
549
|
-
// an idempotency key must never be reaped while the run it names is
|
|
550
|
-
// still readable, or the next retry of that key would start a second
|
|
551
|
-
// run beside the live one. The horizon defaults to run retention —
|
|
552
|
-
// START_IDEMPOTENCY_RETENTION_DAYS is what a host sets when its callers
|
|
553
|
-
// retry for longer than it keeps run summaries.
|
|
554
548
|
startIdempotencyTable: START_IDEMPOTENCY_TABLE,
|
|
555
549
|
...(env.START_IDEMPOTENCY_RETENTION_DAYS === undefined
|
|
556
550
|
? {}
|
|
@@ -566,9 +560,6 @@ export function createFlowsafeWorker(config) {
|
|
|
566
560
|
catch (error) {
|
|
567
561
|
recordFailure('retention-purge', error);
|
|
568
562
|
}
|
|
569
|
-
// Own containment (inside runApprovalRetentionPurge), same isolation as
|
|
570
|
-
// the snapshot purge above: a failure in any one purge duty must never
|
|
571
|
-
// stop the others.
|
|
572
563
|
const approvalPurge = await runApprovalRetentionPurge({
|
|
573
564
|
store: approvalStoreFactoryFor(env.DB, storageTablePrefix).store(),
|
|
574
565
|
retentionDays: env.APPROVAL_RETENTION_DAYS,
|
|
@@ -578,11 +569,6 @@ export function createFlowsafeWorker(config) {
|
|
|
578
569
|
failures.push(`approval-retention-purge: ${approvalPurge.error}`);
|
|
579
570
|
}
|
|
580
571
|
const approvalsPurged = approvalPurge.ok ? approvalPurge.value : undefined;
|
|
581
|
-
// Agent-memory thread TTL, opt-in.
|
|
582
|
-
// Its OWN try/catch, like every sibling duty above and below: isolating one
|
|
583
|
-
// loop while a sibling shares its failure is a defect this codebase has
|
|
584
|
-
// already shipped once — a wedged thread purge must cost the run-snapshot
|
|
585
|
-
// purge, the approval purge, and the extra duties nothing.
|
|
586
572
|
let threadsPurged;
|
|
587
573
|
let threadMessagesPurged;
|
|
588
574
|
// optionalNumberVar, not numberVar: this var GATES the duty rather than
|
|
@@ -604,9 +590,6 @@ export function createFlowsafeWorker(config) {
|
|
|
604
590
|
recordFailure('thread-retention-purge', error);
|
|
605
591
|
}
|
|
606
592
|
}
|
|
607
|
-
// Background-task TTL cleanup (opt-in). Its OWN try/catch, like
|
|
608
|
-
// every sibling duty: a wedged background-task purge must cost the
|
|
609
|
-
// run-snapshot, approval, and thread purges nothing.
|
|
610
593
|
let backgroundTasksPurged;
|
|
611
594
|
if (config.backgroundTasks) {
|
|
612
595
|
try {
|
|
@@ -620,8 +603,6 @@ export function createFlowsafeWorker(config) {
|
|
|
620
603
|
recordFailure('background-task-purge', error);
|
|
621
604
|
}
|
|
622
605
|
}
|
|
623
|
-
// Notification TTL cleanup (opt-in). Its OWN try/catch, like every sibling
|
|
624
|
-
// duty. optionalNumberVar (GATES the duty; unset/garbage => do not delete).
|
|
625
606
|
let notificationsPurged;
|
|
626
607
|
const notificationRetentionDays = optionalNumberVar(env.NOTIFICATION_RETENTION_DAYS, 'NOTIFICATION_RETENTION_DAYS', { allowZero: true });
|
|
627
608
|
if (notificationRetentionDays !== undefined) {
|
|
@@ -635,7 +616,6 @@ export function createFlowsafeWorker(config) {
|
|
|
635
616
|
recordFailure('notification-purge', error);
|
|
636
617
|
}
|
|
637
618
|
}
|
|
638
|
-
// Thread-state TTL cleanup (opt-in). Same isolation + opt-in posture.
|
|
639
619
|
let threadStatePurged;
|
|
640
620
|
const threadStateRetentionDays = optionalNumberVar(env.THREAD_STATE_RETENTION_DAYS, 'THREAD_STATE_RETENTION_DAYS', { allowZero: true });
|
|
641
621
|
if (threadStateRetentionDays !== undefined) {
|
|
@@ -649,9 +629,6 @@ export function createFlowsafeWorker(config) {
|
|
|
649
629
|
recordFailure('thread-state-purge', error);
|
|
650
630
|
}
|
|
651
631
|
}
|
|
652
|
-
// Schedule-trigger history TTL cleanup (opt-in). Same isolation + opt-in
|
|
653
|
-
// posture. Only the fire HISTORY expires; schedule config rows are reaped
|
|
654
|
-
// only at deployment teardown.
|
|
655
632
|
let scheduleTriggersPurged;
|
|
656
633
|
const scheduleTriggerRetentionDays = optionalNumberVar(env.SCHEDULE_TRIGGER_RETENTION_DAYS, 'SCHEDULE_TRIGGER_RETENTION_DAYS', { allowZero: true });
|
|
657
634
|
if (scheduleTriggerRetentionDays !== undefined) {
|
|
@@ -717,7 +694,7 @@ export function createFlowsafeWorker(config) {
|
|
|
717
694
|
return { ok: true, value: undefined };
|
|
718
695
|
}
|
|
719
696
|
catch (error) {
|
|
720
|
-
const failure =
|
|
697
|
+
const failure = hostErrorText(error);
|
|
721
698
|
console.error(JSON.stringify({
|
|
722
699
|
type: 'schedule-tick-error',
|
|
723
700
|
trigger,
|
|
@@ -756,7 +733,7 @@ export function createFlowsafeWorker(config) {
|
|
|
756
733
|
return { ok: true, value: undefined };
|
|
757
734
|
}
|
|
758
735
|
catch (error) {
|
|
759
|
-
const failure =
|
|
736
|
+
const failure = hostErrorText(error);
|
|
760
737
|
console.error(JSON.stringify({
|
|
761
738
|
type: 'deadline-sweep-error',
|
|
762
739
|
trigger,
|
|
@@ -768,6 +745,7 @@ export function createFlowsafeWorker(config) {
|
|
|
768
745
|
return {
|
|
769
746
|
async fetch(request, env, ctx) {
|
|
770
747
|
try {
|
|
748
|
+
const mutationEpoch = normalizeMutationEpoch(typeof epochSource === 'function' ? epochSource(env) : epochSource);
|
|
771
749
|
await ensureDeploymentIdentityBindings(env);
|
|
772
750
|
await validateFleetChannelTopology(env);
|
|
773
751
|
const url = new URL(request.url);
|
|
@@ -803,10 +781,10 @@ export function createFlowsafeWorker(config) {
|
|
|
803
781
|
const hubTopology = createHubTopology(hub, env.DEPLOYMENT_IDENTITY_SECRET);
|
|
804
782
|
streamSink = (event) => waitUntil(hubTopology.publish(event).catch((error) => console.error(JSON.stringify({
|
|
805
783
|
type: 'stream-publish-error',
|
|
806
|
-
reason: error
|
|
784
|
+
reason: hostErrorText(error, true),
|
|
807
785
|
}))));
|
|
808
786
|
}
|
|
809
|
-
const resolve = buildResolve(env, topology, waitUntil, notify, selfDecision, streamSink);
|
|
787
|
+
const resolve = buildResolve(env, topology, waitUntil, notify, selfDecision, streamSink, mutationEpoch);
|
|
810
788
|
if (config.preRoutes) {
|
|
811
789
|
const preResponse = await config.preRoutes(request, env, ctx, {
|
|
812
790
|
resolve,
|
|
@@ -887,10 +865,11 @@ export function createFlowsafeWorker(config) {
|
|
|
887
865
|
startIdempotency: {
|
|
888
866
|
store: startIdempotencyForEnv(env),
|
|
889
867
|
live: topology.startLiveness,
|
|
868
|
+
persistedStart: topology.persistedStart,
|
|
890
869
|
executionFence: executionFenceForEnv(env),
|
|
891
870
|
},
|
|
892
871
|
beforeStart: beforeStart
|
|
893
|
-
? (context, workflowId, inputData) => beforeStart(context, env, workflowId, inputData)
|
|
872
|
+
? (context, workflowId, inputData, requestContext) => beforeStart(context, env, workflowId, inputData, requestContext)
|
|
894
873
|
: undefined,
|
|
895
874
|
beforeResume: beforeResume
|
|
896
875
|
? (context, workflowId, runId, body) => beforeResume(context, env, workflowId, runId, body)
|
|
@@ -907,17 +886,20 @@ export function createFlowsafeWorker(config) {
|
|
|
907
886
|
if (error instanceof DeploymentIdentityError) {
|
|
908
887
|
console.error(JSON.stringify({
|
|
909
888
|
type: 'deployment-identity-error',
|
|
910
|
-
reason: error
|
|
889
|
+
reason: hostErrorText(error, true),
|
|
911
890
|
}));
|
|
912
891
|
return json({ error: 'deployment unavailable' }, 503);
|
|
913
892
|
}
|
|
893
|
+
if (error instanceof InvalidMutationEpochError) {
|
|
894
|
+
return json({ error: error.message, reason: error.reason }, error.status);
|
|
895
|
+
}
|
|
914
896
|
// Backstop: a mounted router (or any handler fault) that THROWS before
|
|
915
897
|
// returning a Response — e.g. a future unguarded path decode — is
|
|
916
898
|
// contained as a generic 500 here rather than rejecting out of fetch()
|
|
917
899
|
// as an unhandled promise. Never surface error.message to the client.
|
|
918
900
|
console.error(JSON.stringify({
|
|
919
901
|
type: 'worker-fetch-error',
|
|
920
|
-
reason: error
|
|
902
|
+
reason: hostErrorText(error, true),
|
|
921
903
|
}));
|
|
922
904
|
return json({ error: 'internal error' }, 500);
|
|
923
905
|
}
|
|
@@ -947,12 +929,28 @@ export function createFlowsafeWorker(config) {
|
|
|
947
929
|
});
|
|
948
930
|
}
|
|
949
931
|
if (duty === 'purge') {
|
|
950
|
-
|
|
932
|
+
if (!hasRetentionCursorSeam(context)) {
|
|
933
|
+
// The same refusal the tick duty makes below for an unwired
|
|
934
|
+
// builder: the cursor seam is part of the purge's wiring, not one
|
|
935
|
+
// of its surfaces, so a host that omits it gets the misconfig
|
|
936
|
+
// named rather than its remaining surfaces purged and the run
|
|
937
|
+
// retention reported as failed. MaintenancePurgeDutyContext
|
|
938
|
+
// requires the seam; this is the check for hosts types do not
|
|
939
|
+
// reach.
|
|
940
|
+
console.error(JSON.stringify({
|
|
941
|
+
type: 'config-error',
|
|
942
|
+
var: 'maintenance.purge.advanceRetentionCursor',
|
|
943
|
+
trigger: duty,
|
|
944
|
+
reason: RETENTION_CURSOR_SEAM_REASON,
|
|
945
|
+
}));
|
|
946
|
+
return { ok: false, error: RETENTION_CURSOR_SEAM_REASON };
|
|
947
|
+
}
|
|
948
|
+
return await runPurgeMaintenance(env, duty, context);
|
|
951
949
|
}
|
|
952
950
|
return await runScheduleTickDuty(env, duty);
|
|
953
951
|
}
|
|
954
952
|
catch (error) {
|
|
955
|
-
const failure =
|
|
953
|
+
const failure = hostErrorText(error);
|
|
956
954
|
console.error(JSON.stringify({
|
|
957
955
|
type: 'maintenance-error',
|
|
958
956
|
surface: `${duty}-duty`,
|
|
@@ -967,6 +965,7 @@ export function createFlowsafeWorker(config) {
|
|
|
967
965
|
const MAINTENANCE_HEALTH_KEY = 'flowsafe:maintenance-health:v1';
|
|
968
966
|
const MAINTENANCE_NONCES_KEY = 'flowsafe:maintenance-nonces:v1';
|
|
969
967
|
const MAINTENANCE_DEADLINE_CURSOR_KEY = 'flowsafe:maintenance-deadline-cursor:v1';
|
|
968
|
+
const MAINTENANCE_RUN_RETENTION_CURSOR_KEY = 'flowsafe:maintenance-run-retention-cursor:v1';
|
|
970
969
|
const DUTY_ORDER = ['deadline', 'sweep', 'purge', 'tick'];
|
|
971
970
|
/** Build the fixed-name maintenance Durable Object class for one host. */
|
|
972
971
|
export function createFlowsafeMaintenanceDurableObject(config) {
|
|
@@ -1110,6 +1109,10 @@ export function createFlowsafeMaintenanceDurableObject(config) {
|
|
|
1110
1109
|
}
|
|
1111
1110
|
if (!capability)
|
|
1112
1111
|
return undefined;
|
|
1112
|
+
if (this.#env.FLEET_RESOURCE_ROLE === 'platform-catalog' &&
|
|
1113
|
+
(capability.scriptName !== this.#env.FLEET_DEPLOYMENT_SCRIPT ||
|
|
1114
|
+
capability.specDigest !== this.#env.FLEET_SPEC_DIGEST))
|
|
1115
|
+
return undefined;
|
|
1113
1116
|
if (operation === 'maintenance-status')
|
|
1114
1117
|
return capability;
|
|
1115
1118
|
const nowSeconds = Math.floor(Date.now() / 1_000);
|
|
@@ -1178,7 +1181,7 @@ export function createFlowsafeMaintenanceDurableObject(config) {
|
|
|
1178
1181
|
}
|
|
1179
1182
|
console.error(JSON.stringify({
|
|
1180
1183
|
type: 'maintenance-do-error',
|
|
1181
|
-
reason: error
|
|
1184
|
+
reason: hostErrorText(error, true),
|
|
1182
1185
|
}));
|
|
1183
1186
|
return json({ error: 'internal error' }, 500);
|
|
1184
1187
|
}
|
|
@@ -1206,17 +1209,31 @@ export function createFlowsafeMaintenanceDurableObject(config) {
|
|
|
1206
1209
|
setNextAt(health, duty, advancePast(dueAt, interval, now));
|
|
1207
1210
|
const followUpAt = nextAlarmAt(health, intervals);
|
|
1208
1211
|
await this.#persistAndArm(health, hasDueDuty(health, intervals, now) ? now : followUpAt);
|
|
1209
|
-
|
|
1212
|
+
// Each duty carries the cursor pair it owns, so the call sits inside the
|
|
1213
|
+
// branch that builds it: the purge seam is required by its context type,
|
|
1214
|
+
// which a single call over the whole duty union cannot satisfy.
|
|
1215
|
+
let outcome;
|
|
1210
1216
|
if (duty === 'deadline') {
|
|
1211
1217
|
const deadlineCursor = await this.#state.storage.get(MAINTENANCE_DEADLINE_CURSOR_KEY);
|
|
1212
|
-
|
|
1218
|
+
outcome = await worker.runMaintenanceDuty(duty, this.#env, {
|
|
1213
1219
|
...(deadlineCursor ? { deadlineCursor } : {}),
|
|
1214
1220
|
advanceDeadlineCursor: (cursor) => this.#state.storage.transaction(async (transaction) => {
|
|
1215
1221
|
await transaction.put(MAINTENANCE_DEADLINE_CURSOR_KEY, cursor);
|
|
1216
1222
|
}),
|
|
1217
|
-
};
|
|
1223
|
+
});
|
|
1224
|
+
}
|
|
1225
|
+
else if (duty === 'purge') {
|
|
1226
|
+
const retentionCursor = await this.#state.storage.get(MAINTENANCE_RUN_RETENTION_CURSOR_KEY);
|
|
1227
|
+
outcome = await worker.runMaintenanceDuty(duty, this.#env, {
|
|
1228
|
+
...(retentionCursor === undefined ? {} : { retentionCursor }),
|
|
1229
|
+
advanceRetentionCursor: (cursor) => this.#state.storage.transaction(async (transaction) => {
|
|
1230
|
+
await transaction.put(MAINTENANCE_RUN_RETENTION_CURSOR_KEY, cursor);
|
|
1231
|
+
}),
|
|
1232
|
+
});
|
|
1233
|
+
}
|
|
1234
|
+
else {
|
|
1235
|
+
outcome = await worker.runMaintenanceDuty(duty, this.#env);
|
|
1218
1236
|
}
|
|
1219
|
-
const outcome = await worker.runMaintenanceDuty(duty, this.#env, context);
|
|
1220
1237
|
await this.#recordOutcome(duty, Date.now(), outcome);
|
|
1221
1238
|
}
|
|
1222
1239
|
};
|