@proofoftech/flowsafe 0.28.0 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +6 -2
  3. package/deployment-identity-protocol.mjs +3 -4
  4. package/dist/agent-host/catalog.js +1 -1
  5. package/dist/agent-host/catalog.js.map +1 -1
  6. package/dist/agent-host/index.d.ts +4 -1
  7. package/dist/agent-host/index.d.ts.map +1 -1
  8. package/dist/agent-host/index.js +2 -1
  9. package/dist/agent-host/index.js.map +1 -1
  10. package/dist/agent-host/thread-host.d.ts +18 -0
  11. package/dist/agent-host/thread-host.d.ts.map +1 -1
  12. package/dist/agent-host/thread-host.js +407 -10
  13. package/dist/agent-host/thread-host.js.map +1 -1
  14. package/dist/agent-host/thread-topology.d.ts +83 -0
  15. package/dist/agent-host/thread-topology.d.ts.map +1 -1
  16. package/dist/agent-host/thread-topology.js +202 -1
  17. package/dist/agent-host/thread-topology.js.map +1 -1
  18. package/dist/agent-host/workflow-remote-step-route.d.ts +7 -0
  19. package/dist/agent-host/workflow-remote-step-route.d.ts.map +1 -0
  20. package/dist/agent-host/workflow-remote-step-route.js +148 -0
  21. package/dist/agent-host/workflow-remote-step-route.js.map +1 -0
  22. package/dist/agent-runner/agent-run-state.d.ts +1 -1
  23. package/dist/agent-runner/agent-run-state.d.ts.map +1 -1
  24. package/dist/agent-runner/agent-run-state.js +1 -0
  25. package/dist/agent-runner/agent-run-state.js.map +1 -1
  26. package/dist/agent-runner/durable-agent-runner.d.ts +1 -0
  27. package/dist/agent-runner/durable-agent-runner.d.ts.map +1 -1
  28. package/dist/agent-runner/durable-agent-runner.js +69 -32
  29. package/dist/agent-runner/durable-agent-runner.js.map +1 -1
  30. package/dist/do-runner/durable-object.d.ts +2 -0
  31. package/dist/do-runner/durable-object.d.ts.map +1 -1
  32. package/dist/do-runner/durable-object.js +252 -3
  33. package/dist/do-runner/durable-object.js.map +1 -1
  34. package/dist/do-runner/execution-admission.d.ts +31 -0
  35. package/dist/do-runner/execution-admission.d.ts.map +1 -1
  36. package/dist/do-runner/execution-admission.js +26 -2
  37. package/dist/do-runner/execution-admission.js.map +1 -1
  38. package/dist/do-runner/execution-fence.d.ts +11 -2
  39. package/dist/do-runner/execution-fence.d.ts.map +1 -1
  40. package/dist/do-runner/execution-fence.js +44 -1
  41. package/dist/do-runner/execution-fence.js.map +1 -1
  42. package/dist/do-runner/index.d.ts +2 -1
  43. package/dist/do-runner/index.d.ts.map +1 -1
  44. package/dist/do-runner/index.js +2 -1
  45. package/dist/do-runner/index.js.map +1 -1
  46. package/dist/do-runner/inventory.d.ts +1 -1
  47. package/dist/do-runner/inventory.d.ts.map +1 -1
  48. package/dist/do-runner/inventory.js +85 -1
  49. package/dist/do-runner/inventory.js.map +1 -1
  50. package/dist/do-runner/notification-predicate.d.ts +1 -0
  51. package/dist/do-runner/notification-predicate.d.ts.map +1 -1
  52. package/dist/do-runner/notification-predicate.js +1 -0
  53. package/dist/do-runner/notification-predicate.js.map +1 -1
  54. package/dist/do-runner/remote-step-journal.d.ts +143 -0
  55. package/dist/do-runner/remote-step-journal.d.ts.map +1 -0
  56. package/dist/do-runner/remote-step-journal.js +2090 -0
  57. package/dist/do-runner/remote-step-journal.js.map +1 -0
  58. package/dist/host-kit/do-response.d.ts +19 -1
  59. package/dist/host-kit/do-response.d.ts.map +1 -1
  60. package/dist/host-kit/do-response.js +71 -2
  61. package/dist/host-kit/do-response.js.map +1 -1
  62. package/dist/host-kit/do-run-topology.d.ts +8 -2
  63. package/dist/host-kit/do-run-topology.d.ts.map +1 -1
  64. package/dist/host-kit/do-run-topology.js +26 -1
  65. package/dist/host-kit/do-run-topology.js.map +1 -1
  66. package/dist/host-kit/flowsafe-worker.d.ts +38 -4
  67. package/dist/host-kit/flowsafe-worker.d.ts.map +1 -1
  68. package/dist/host-kit/flowsafe-worker.js +104 -15
  69. package/dist/host-kit/flowsafe-worker.js.map +1 -1
  70. package/dist/host-kit/index.d.ts +5 -5
  71. package/dist/host-kit/index.d.ts.map +1 -1
  72. package/dist/host-kit/index.js +3 -3
  73. package/dist/host-kit/index.js.map +1 -1
  74. package/dist/host-kit/maintenance-capability.js +3 -3
  75. package/dist/host-kit/maintenance-capability.js.map +1 -1
  76. package/dist/host-kit/state-egress.d.ts +34 -6
  77. package/dist/host-kit/state-egress.d.ts.map +1 -1
  78. package/dist/host-kit/state-egress.js +49 -8
  79. package/dist/host-kit/state-egress.js.map +1 -1
  80. package/dist/schedules/schedules-d1.d.ts +3 -3
  81. package/dist/schedules/schedules-d1.d.ts.map +1 -1
  82. package/dist/schedules/schedules-d1.js +61 -62
  83. package/dist/schedules/schedules-d1.js.map +1 -1
  84. package/dist/schedules/tick.d.ts +4 -0
  85. package/dist/schedules/tick.d.ts.map +1 -1
  86. package/dist/schedules/tick.js +28 -7
  87. package/dist/schedules/tick.js.map +1 -1
  88. package/dist/signal-providers/delivery.d.ts +2 -1
  89. package/dist/signal-providers/delivery.d.ts.map +1 -1
  90. package/dist/signal-providers/delivery.js +20 -4
  91. package/dist/signal-providers/delivery.js.map +1 -1
  92. package/dist/signal-providers/host-do.d.ts +2 -0
  93. package/dist/signal-providers/host-do.d.ts.map +1 -1
  94. package/dist/signal-providers/host-do.js +16 -5
  95. package/dist/signal-providers/host-do.js.map +1 -1
  96. package/dist/signal-providers/subscription-d1.d.ts +3 -2
  97. package/dist/signal-providers/subscription-d1.d.ts.map +1 -1
  98. package/dist/signal-providers/subscription-d1.js +25 -7
  99. package/dist/signal-providers/subscription-d1.js.map +1 -1
  100. package/dist/signal-providers/webhook-route.d.ts +2 -0
  101. package/dist/signal-providers/webhook-route.d.ts.map +1 -1
  102. package/dist/signal-providers/webhook-route.js +18 -18
  103. package/dist/signal-providers/webhook-route.js.map +1 -1
  104. package/dist/signals/index.d.ts +1 -0
  105. package/dist/signals/index.d.ts.map +1 -1
  106. package/dist/signals/index.js.map +1 -1
  107. package/dist/signals/notification-dispatch.d.ts +2 -64
  108. package/dist/signals/notification-dispatch.d.ts.map +1 -1
  109. package/dist/signals/notification-dispatch.js +20 -2
  110. package/dist/signals/notification-dispatch.js.map +1 -1
  111. package/dist/signals/notifications-d1.d.ts +100 -3
  112. package/dist/signals/notifications-d1.d.ts.map +1 -1
  113. package/dist/signals/notifications-d1.js +350 -16
  114. package/dist/signals/notifications-d1.js.map +1 -1
  115. package/dist/signals/storage.d.ts +1 -1
  116. package/dist/signals/storage.d.ts.map +1 -1
  117. package/dist/signals/storage.js +3 -3
  118. package/dist/signals/storage.js.map +1 -1
  119. package/dist/signals/thread-do-routes.d.ts +6 -3
  120. package/dist/signals/thread-do-routes.d.ts.map +1 -1
  121. package/dist/signals/thread-do-routes.js +30 -5
  122. package/dist/signals/thread-do-routes.js.map +1 -1
  123. package/package.json +1 -1
@@ -12,7 +12,8 @@
12
12
  // recovering run-owner claims that outlive an interrupted start, and for the
13
13
  // per-suspension deadlines of this run (suspension-deadline.ts); the duties
14
14
  // share one wake, armed at the earliest due time.
15
- import { decodeExecutionPrincipal, isExecutionPrincipalId, isExecutionPrincipalKind, } from '../approval-api/principal.js';
15
+ import { decodeExecutionPrincipal, isExecutionPrincipalId, isExecutionPrincipalKind, isOwnedBy, samePrincipal, } from '../approval-api/principal.js';
16
+ import { readBoundedBody } from '../http-body.js';
16
17
  import { errorMessageOf } from './cause-chain.js';
17
18
  import { newWebSocketPair, safeSend } from './cf-types.js';
18
19
  import { isDatabaseBinding, verifyDurableObjectDeploymentIdentity, verifyDurableObjectDeploymentRequest, } from './deployment-identity.js';
@@ -22,6 +23,7 @@ import { admitsRunStart, ExecutionFencedError, isExecutionFenceRefusal, readExec
22
23
  import { EXECUTION_PRINCIPAL_HEADER } from './execution-principal-header.js';
23
24
  import { isDefinitiveInitialAdmissionRefusal } from './initial-admission-refusal.js';
24
25
  import { isPathSafeId } from './path-safe-id.js';
26
+ import { WORKFLOW_REMOTE_STEP_RESULT_KEY, } from './remote-step-journal.js';
25
27
  import { lifecycleFromRequestContext, terminalCleanupFor, } from './run-lifecycle.js';
26
28
  import { isDurableRunStatus, isTerminalRunStatus, } from './run-terminal-state.js';
27
29
  import { InvalidRunRequestError, RunAlreadyExistsError, RunnerRuntime, RunStateUnreadableError, SuspensionChangedError, UnknownRunError, } from './runtime.js';
@@ -29,6 +31,7 @@ import { resolveScheduleStartOwner, } from './schedule-source.js';
29
31
  import { captureReservation, sameReservationIdentity, } from './start-reservation-contract.js';
30
32
  import { dueSuspensionDeadline, isReadableRunSummary, isSuspensionDeadlineDue, MAX_SUSPENSION_DEADLINE_ATTEMPTS, MAX_SUSPENSION_DEADLINES_PER_RUN, mergeSuspensionDeadlines, nextSuspensionDeadlineAt, ownSuspensionDeadlines, parseSuspensionDeadlineRecord, SUSPENSION_DEADLINE_PRINCIPAL_ID, SUSPENSION_DEADLINE_STORAGE_KEY, SUSPENSION_TIMEOUT_RESUME_KEY, suspensionDeadlinesOf, suspensionTimeoutResumeData, suspensionTimerSteps, tombstoned, } from './suspension-deadline.js';
31
33
  const RUN_OWNER_RECOVERY_KEY = 'flowsafe:run-owner-recovery:v1';
34
+ const START_PRINCIPAL_RECEIPT_KEY = 'flowsafe:start-principal:v1';
32
35
  export const RUN_OWNER_RECOVERY_DELAY_MS = 60_000;
33
36
  const SUSPENSION_DEADLINE_RETRY_MS = 60_000;
34
37
  // How long a run's state may stay unreadable before the entries due under it
@@ -134,6 +137,9 @@ function sameRunRecovery(actual, expected) {
134
137
  claim.updatedAt === wantedClaim.updatedAt &&
135
138
  claim.binding.kind === wantedClaim.binding.kind));
136
139
  }
140
+ function preparedRunExecution(recovery) {
141
+ return recovery.phase === 'preparing' ? undefined : recovery.execution;
142
+ }
137
143
  class DurableObjectRunIdentityError extends DoStatusError {
138
144
  status = 403;
139
145
  }
@@ -187,6 +193,7 @@ export class DurableObjectRunner {
187
193
  /** Absent in Node tests; present under workerd for storage and the alarm. */
188
194
  state;
189
195
  #runtime;
196
+ #workflowRemoteReader;
190
197
  #operationTail = Promise.resolve();
191
198
  /** `step\0reason` of every suspension deadline this object has reported. */
192
199
  #reportedSuspensionRejections = new Set();
@@ -198,6 +205,9 @@ export class DurableObjectRunner {
198
205
  this.state = state;
199
206
  this.env = env;
200
207
  }
208
+ async workflowRemoteSteps(_env, _runtime) {
209
+ return undefined;
210
+ }
201
211
  /** Existing schedules domain used only for target-verifiable schedule fires. */
202
212
  scheduleSource(_env) {
203
213
  return undefined;
@@ -318,8 +328,12 @@ export class DurableObjectRunner {
318
328
  #resumeData(value) {
319
329
  if (value !== null &&
320
330
  typeof value === 'object' &&
321
- SUSPENSION_TIMEOUT_RESUME_KEY in value) {
322
- throw new InvalidRunRequestError(`resume data must not carry the reserved '${SUSPENSION_TIMEOUT_RESUME_KEY}' key`);
331
+ (SUSPENSION_TIMEOUT_RESUME_KEY in value ||
332
+ WORKFLOW_REMOTE_STEP_RESULT_KEY in value)) {
333
+ const key = SUSPENSION_TIMEOUT_RESUME_KEY in value
334
+ ? SUSPENSION_TIMEOUT_RESUME_KEY
335
+ : WORKFLOW_REMOTE_STEP_RESULT_KEY;
336
+ throw new InvalidRunRequestError(`resume data must not carry the reserved '${key}' key`);
323
337
  }
324
338
  return value;
325
339
  }
@@ -629,6 +643,99 @@ export class DurableObjectRunner {
629
643
  }
630
644
  return prepared;
631
645
  }
646
+ async #recordStartPrincipal(execution, owner, principal) {
647
+ const storage = this.state?.storage;
648
+ if (!storage)
649
+ return;
650
+ const receipt = JSON.stringify({
651
+ version: 1,
652
+ execution: normalizeRunExecutionIdentity(execution),
653
+ owner,
654
+ principal,
655
+ });
656
+ try {
657
+ const existing = await storage.get(START_PRINCIPAL_RECEIPT_KEY);
658
+ if (existing !== undefined && existing !== receipt) {
659
+ console.error('start principal receipt conflicts with prepared start');
660
+ return;
661
+ }
662
+ if (existing === undefined) {
663
+ try {
664
+ await storage.put(START_PRINCIPAL_RECEIPT_KEY, receipt);
665
+ }
666
+ catch {
667
+ // A lost acknowledgment is resolved by the read below.
668
+ }
669
+ }
670
+ if ((await storage.get(START_PRINCIPAL_RECEIPT_KEY)) !== receipt)
671
+ console.error('start principal receipt could not be verified');
672
+ }
673
+ catch (error) {
674
+ console.error('start principal receipt could not be verified', error);
675
+ }
676
+ }
677
+ async #startPrincipalReceipt(workflowId, runId) {
678
+ const unavailable = () => json({ error: 'run not found' }, 404);
679
+ const storage = this.state?.storage;
680
+ if (!storage || this.state?.id?.name !== `${workflowId}:${runId}`)
681
+ return unavailable();
682
+ try {
683
+ const raw = await storage.get(START_PRINCIPAL_RECEIPT_KEY);
684
+ if (typeof raw !== 'string')
685
+ return unavailable();
686
+ const parsed = JSON.parse(raw);
687
+ if (parsed === null ||
688
+ typeof parsed !== 'object' ||
689
+ Array.isArray(parsed))
690
+ return unavailable();
691
+ const receipt = parsed;
692
+ if (receipt.version !== 1 ||
693
+ receipt.owner === null ||
694
+ typeof receipt.owner !== 'object' ||
695
+ Array.isArray(receipt.owner) ||
696
+ receipt.principal === null ||
697
+ typeof receipt.principal !== 'object' ||
698
+ Array.isArray(receipt.principal))
699
+ return unavailable();
700
+ const execution = normalizeD1RunExecutionIdentity(receipt.execution);
701
+ const owner = receipt.owner;
702
+ const principal = decodeExecutionPrincipal(JSON.stringify(receipt.principal));
703
+ if (!isExecutionPrincipalKind(owner.kind) ||
704
+ !isExecutionPrincipalId(owner.id) ||
705
+ !principal ||
706
+ execution.workflowId !== workflowId ||
707
+ execution.runId !== runId ||
708
+ owner.kind !== principal.kind ||
709
+ owner.id !== principal.id)
710
+ return unavailable();
711
+ const canonical = {
712
+ version: 1,
713
+ execution,
714
+ owner: { kind: owner.kind, id: owner.id },
715
+ principal,
716
+ };
717
+ if (JSON.stringify(canonical) !== raw)
718
+ return unavailable();
719
+ const state = await this.#ensureRuntime().authoritativeStartState(workflowId, runId);
720
+ const identity = state?.provenance.startIdentity;
721
+ if (state?.storage !== 'd1' ||
722
+ state.execution.tablePrefix !== execution.tablePrefix ||
723
+ state.execution.workflowId !== execution.workflowId ||
724
+ state.execution.runId !== execution.runId ||
725
+ state.execution.startToken !== execution.startToken ||
726
+ state.provenance.startToken !== execution.startToken ||
727
+ identity?.target.kind !== 'workflow' ||
728
+ identity.target.id !== workflowId ||
729
+ identity.owner.kind !== owner.kind ||
730
+ identity.owner.id !== owner.id ||
731
+ state.provenance.agentStart !== undefined)
732
+ return unavailable();
733
+ return json(canonical);
734
+ }
735
+ catch {
736
+ return unavailable();
737
+ }
738
+ }
632
739
  #matchingRunState(recovery, state) {
633
740
  const execution = recovery.execution;
634
741
  if (!state ||
@@ -1921,6 +2028,9 @@ export class DurableObjectRunner {
1921
2028
  frame.unwound = true;
1922
2029
  }
1923
2030
  summary = await this.#finishRunOwner(recovery, summary);
2031
+ const preparedExecution = preparedRunExecution(recovery);
2032
+ if (scheduleId === undefined && preparedExecution)
2033
+ await this.#recordStartPrincipal(preparedExecution, owner, principal);
1924
2034
  this.#broadcastRunSummary(summary);
1925
2035
  return json(await this.#withSuspensionTimers(startWorkflowId, summary));
1926
2036
  }
@@ -1961,6 +2071,15 @@ export class DurableObjectRunner {
1961
2071
  this.#assertRunIdentity(workflowId, runId);
1962
2072
  return json({ live: this.#isStartLive(workflowId, runId) });
1963
2073
  }
2074
+ if (request.method === 'GET' &&
2075
+ segments.length === 4 &&
2076
+ action === 'start-principal' &&
2077
+ workflowId &&
2078
+ runId) {
2079
+ if (!isPathSafeId(workflowId) || !isPathSafeId(runId))
2080
+ return json({ error: 'run not found' }, 404);
2081
+ return this.#startPrincipalReceipt(workflowId, runId);
2082
+ }
1964
2083
  if (request.method === 'GET' &&
1965
2084
  segments.length === 3 &&
1966
2085
  workflowId &&
@@ -2042,6 +2161,136 @@ export class DurableObjectRunner {
2042
2161
  webSocket: client,
2043
2162
  });
2044
2163
  }
2164
+ if (request.method === 'POST' &&
2165
+ segments.length === 4 &&
2166
+ action === 'remote-step-resume' &&
2167
+ workflowId &&
2168
+ runId) {
2169
+ this.#assertRunIdentity(workflowId, runId);
2170
+ const principal = this.#trustedExecutionPrincipal(encodedPrincipal);
2171
+ const body = await readBoundedBody(request, 1_024);
2172
+ if (!body.ok)
2173
+ return json({ error: 'invalid request body' }, 400);
2174
+ let parsed;
2175
+ try {
2176
+ parsed = JSON.parse(body.text);
2177
+ }
2178
+ catch {
2179
+ return json({ error: 'invalid request body' }, 400);
2180
+ }
2181
+ if (parsed === null ||
2182
+ typeof parsed !== 'object' ||
2183
+ Array.isArray(parsed) ||
2184
+ Object.keys(parsed).length !== 1 ||
2185
+ !('invocationId' in parsed) ||
2186
+ !isPathSafeId(parsed.invocationId) ||
2187
+ new URL(request.url).search)
2188
+ return json({ error: 'invalid request body' }, 400);
2189
+ const invocationId = parsed.invocationId;
2190
+ return this.#withOperationLock(async () => {
2191
+ const runtime = this.#ensureRuntime();
2192
+ const reader = this.#workflowRemoteReader ??
2193
+ (await this.workflowRemoteSteps(this.env, runtime));
2194
+ if (!reader)
2195
+ return json({ error: 'remote steps are unavailable' }, 503);
2196
+ this.#workflowRemoteReader = reader;
2197
+ const invocation = await reader.getWorkflow(invocationId);
2198
+ const deploymentId = this.env &&
2199
+ typeof this.env === 'object' &&
2200
+ 'DEPLOYMENT_TENANT' in this.env
2201
+ ? this.env.DEPLOYMENT_TENANT
2202
+ : undefined;
2203
+ if (invocation?.targetKind !== 'workflow' ||
2204
+ invocation.invocationId !== invocationId ||
2205
+ invocation.deploymentId !== reader.deploymentId ||
2206
+ invocation.deploymentId !== deploymentId ||
2207
+ invocation.tablePrefix !== reader.tablePrefix ||
2208
+ invocation.workflowId !== workflowId ||
2209
+ invocation.runId !== runId ||
2210
+ !samePrincipal(invocation.principal, principal))
2211
+ return json({ error: 'invocation not found' }, 404);
2212
+ const state = await runtime.authoritativeStartState(workflowId, runId);
2213
+ const identity = state?.provenance.startIdentity;
2214
+ if (state?.storage !== 'd1' ||
2215
+ state.kind !== 'result' ||
2216
+ state.execution.tablePrefix !== invocation.tablePrefix ||
2217
+ state.execution.workflowId !== workflowId ||
2218
+ state.execution.runId !== runId ||
2219
+ state.execution.startToken !== invocation.startToken ||
2220
+ identity?.target.kind !== 'workflow' ||
2221
+ identity.target.id !== workflowId ||
2222
+ !isOwnedBy(identity.owner, principal) ||
2223
+ state.provenance.agentStart !== undefined)
2224
+ return json({ error: 'remote step run changed' }, 409);
2225
+ const owner = await this.runOwnership(this.env).owner('run', runId);
2226
+ if (owner && !isOwnedBy(owner, principal))
2227
+ return json({ error: 'run not found' }, 404);
2228
+ if (invocation.status === 'settled' &&
2229
+ invocation.settlementOutcome === 'applied') {
2230
+ if (!owner) {
2231
+ const receipt = await this.#startPrincipalReceipt(workflowId, runId);
2232
+ if (receipt.status !== 200)
2233
+ return json({ error: 'run not found' }, 404);
2234
+ const value = (await receipt.json());
2235
+ if (!samePrincipal(value.principal, principal))
2236
+ return json({ error: 'run not found' }, 404);
2237
+ }
2238
+ return json({ kind: 'already-applied', invocationId });
2239
+ }
2240
+ if (!owner)
2241
+ return json({ error: 'run not found' }, 404);
2242
+ if (invocation.status === 'resuming')
2243
+ return json({ error: 'remote step resume outcome is unresolved' }, 503);
2244
+ if (invocation.status !== 'result-retained')
2245
+ return json({ error: 'remote step result is unavailable' }, 409);
2246
+ await runtime.assertExistingRunAllowed(workflowId, runId);
2247
+ const leaseOwner = await reader.claimWorkflowResume(invocationId, 60_000, mutationEpoch);
2248
+ const retained = await reader.readRetainedResult(invocationId);
2249
+ if (!retained || retained.invocationId !== invocationId)
2250
+ return json({ error: 'remote step result is unreadable' }, 503);
2251
+ const resumeData = {
2252
+ [WORKFLOW_REMOTE_STEP_RESULT_KEY]: {
2253
+ version: 1,
2254
+ invocationId,
2255
+ requestDigest: invocation.requestDigest,
2256
+ resultJson: retained.resultJson,
2257
+ resultDigest: retained.resultDigest,
2258
+ },
2259
+ };
2260
+ const summary = await this.#withLeg(workflowId, runId, 'resume', () => runtime.resume(workflowId, runId, {
2261
+ step: [...invocation.stepPath],
2262
+ resumeData,
2263
+ requestedBy: principal.id,
2264
+ requestedByKind: principal.kind,
2265
+ expectedSuspension: {
2266
+ suspendedAt: invocation.suspendedAt,
2267
+ ...(invocation.resumeCount === undefined
2268
+ ? {}
2269
+ : { resumeCount: invocation.resumeCount }),
2270
+ },
2271
+ }), false);
2272
+ const outcome = await reader.settleWorkflowAfterResume(invocationId, leaseOwner, summary);
2273
+ await this.#reconcileApprovalsBestEffort(workflowId, runId);
2274
+ if (await this.#reconcileSuspensionDeadlinesBestEffort(workflowId, runId, summary)) {
2275
+ try {
2276
+ await this.#armNextAlarm();
2277
+ }
2278
+ catch (error) {
2279
+ console.error('remote step resume boundary re-arm failed', error);
2280
+ }
2281
+ }
2282
+ this.#broadcastRunSummary(summary);
2283
+ if (outcome === 'unresolved')
2284
+ return json({ error: 'remote step resume outcome is unresolved' }, 503);
2285
+ if (outcome !== 'applied')
2286
+ return json({ error: 'remote step result was not applied' }, 409);
2287
+ return json({
2288
+ kind: 'applied',
2289
+ invocationId,
2290
+ summary: await this.#withSuspensionTimers(workflowId, summary),
2291
+ });
2292
+ });
2293
+ }
2045
2294
  if (request.method === 'POST' &&
2046
2295
  segments.length === 4 &&
2047
2296
  action === 'resume' &&