@workbasehq/core 0.2.15 → 0.3.1
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/package.json +18 -3
- package/src/access-evaluator.ts +72 -0
- package/src/access-guards.ts +35 -0
- package/src/access-inputs.ts +62 -0
- package/src/access-lock/cli.ts +34 -0
- package/src/access-lock.ts +183 -0
- package/src/access.ts +209 -0
- package/src/account-action-conditions.ts +27 -0
- package/src/account-command.ts +8 -0
- package/src/admin-ui.tsx +3 -2
- package/src/app.ts +3 -3
- package/src/canonical.ts +6 -0
- package/src/capabilities.ts +5 -3
- package/src/commands.ts +14 -8
- package/src/config.ts +105 -69
- package/src/console-build.ts +37 -0
- package/src/console-contract.ts +4 -0
- package/src/console-model.ts +2 -0
- package/src/console.ts +3 -3
- package/src/crud.ts +13 -7
- package/src/dev-mailbox.ts +35 -0
- package/src/display-identity.ts +12 -0
- package/src/execution/atomic.ts +17 -3
- package/src/execution/policies.ts +14 -6
- package/src/execution/policy-receipts.ts +6 -5
- package/src/execution/post-commit.ts +11 -0
- package/src/execution/types.ts +1 -1
- package/src/index.ts +2 -0
- package/src/infra/README.md +39 -3
- package/src/infra/d1-migrations.ts +4 -3
- package/src/infra/instance-migrations.ts +26 -5
- package/src/infra/provision-config-main.mjs +3 -3
- package/src/infra/provision-diagnostics.ts +4 -0
- package/src/infra/provision-plan.ts +34 -5
- package/src/infra/provision.ts +26 -4
- package/src/infra/schema.ts +1 -1
- package/src/kernel/invitation-mail-port.ts +26 -0
- package/src/kernel/mail-outbox-port.ts +4 -2
- package/src/kernel/migrations.ts +38 -15
- package/src/kernel/plugin.ts +2 -0
- package/src/kernel/predicate.ts +15 -3
- package/src/kernel/registry.ts +69 -12
- package/src/member-bootstrap.ts +65 -0
- package/src/member-identities.ts +42 -0
- package/src/migrations/diagnostics.ts +6 -1
- package/src/migrations/model-b.ts +2 -1
- package/src/migrations/operational-evidence.ts +51 -0
- package/src/migrations/planner.ts +12 -1
- package/src/migrations/rebuild.ts +17 -12
- package/src/migrations/reset-era.ts +29 -0
- package/src/migrations/schema-bundle.ts +43 -0
- package/src/migrations/schema-cli.ts +74 -0
- package/src/migrations/schema-git.ts +36 -0
- package/src/migrations/schema-lock.ts +159 -0
- package/src/migrations/schema-plan.ts +94 -0
- package/src/migrations/schema.ts +73 -48
- package/src/migrations/sdk-baseline.ts +35 -0
- package/src/migrations/system-schema.ts +39 -0
- package/src/model-inputs.ts +25 -0
- package/src/openapi/cli.ts +72 -0
- package/src/openapi/generate.ts +166 -0
- package/src/openapi/input-projection.ts +131 -0
- package/src/openapi/public-paths.ts +80 -0
- package/src/openapi/routes.ts +29 -0
- package/src/ops.ts +4 -2
- package/src/organization-name.ts +35 -0
- package/src/organization-permissions.ts +10 -0
- package/src/organizations.ts +72 -3
- package/src/policies.ts +22 -6
- package/src/public-projection.ts +108 -0
- package/src/public-schema.ts +5 -43
- package/src/query/input-schema.ts +89 -0
- package/src/query/limits.ts +1 -1
- package/src/query/schema.ts +11 -89
- package/src/record-action-routes.ts +87 -0
- package/src/record-actions-data.ts +17 -0
- package/src/record-actions.ts +61 -0
- package/src/record-read.ts +20 -0
- package/src/row-access.ts +11 -0
- package/src/row-invitations.ts +29 -0
- package/src/schema/README.md +323 -0
- package/src/schema/declaration.ts +5 -0
- package/src/schema/load.ts +423 -0
- package/src/schema/lock-format.ts +117 -0
- package/src/schema/physical-names.ts +30 -0
- package/src/schema/revision.ts +16 -0
- package/src/schema/source-location.ts +3 -0
- package/src/schema-compatibility.ts +2 -2
- package/src/schema.ts +171 -0
- package/src/types.ts +1 -1
- package/src/user-link-eligibility.ts +36 -0
- package/src/user-links.ts +27 -16
- package/src/worker-access-actions.ts +89 -0
- package/src/worker-access.ts +61 -0
- package/src/workflow-runtime.ts +109 -22
- package/src/bootstrap.ts +0 -23
package/src/workflow-runtime.ts
CHANGED
|
@@ -9,19 +9,44 @@ import { requestHash } from './idempotency'
|
|
|
9
9
|
import { ulid } from './crypto'
|
|
10
10
|
import { coreExecutionContext, assertLivePermission, infrastructure, holdReleaseContext } from './execution/context'
|
|
11
11
|
import { D1AtomicStore, D1AtomicReader } from './execution/d1'
|
|
12
|
-
import { PermissionRevoked } from './execution/errors'
|
|
12
|
+
import { PermissionRevoked, RuleFailed } from './execution/errors'
|
|
13
13
|
import type { ExecutionContext, GuardedStatement, AtomicStore } from './execution/types'
|
|
14
14
|
import type { WorkflowDefinition, WorkflowRuntime, WorkflowStatus, WorkflowStep } from './execution/workflow'
|
|
15
15
|
export type WorkflowRegistry = ReadonlyMap<string, WorkflowDefinition<any>>
|
|
16
|
+
export interface WorkflowContinuationBudget {
|
|
17
|
+
/** Advancement passes, including recovery, retries, undo and terminal completion. Capped at 32. */
|
|
18
|
+
maxSteps?: number
|
|
19
|
+
/** Stop starting passes after this elapsed time. Capped at 5 seconds; an in-flight
|
|
20
|
+
* pass retains its existing step timeout (at most 10 seconds). */
|
|
21
|
+
maxDurationMs?: number
|
|
22
|
+
/** Reference clock, matching tick's deterministic recovery clock. */
|
|
23
|
+
now?: number
|
|
24
|
+
}
|
|
25
|
+
// Shared by every quantum in one tick; standalone continuations keep their own caps.
|
|
26
|
+
interface WorkflowInvocationBudget { remainingSteps: number; deadline: number }
|
|
27
|
+
const continuationSteps = 32
|
|
28
|
+
const continuationDurationMs = 5000
|
|
29
|
+
export type WorkflowReadiness =
|
|
30
|
+
| { status: 'terminal' }
|
|
31
|
+
| { status: 'paused' }
|
|
32
|
+
| { status: 'due_at'; dueAt: number }
|
|
33
|
+
| { status: 'budget_exhausted' }
|
|
34
|
+
| { status: 'lease_lost' }
|
|
35
|
+
export type WorkflowContinuationResult = WorkflowReadiness & { claimed: boolean }
|
|
16
36
|
interface Run {
|
|
17
37
|
id: string; organization_id: string; actor_id: string; actor_type: 'user' | 'agent'; token_id: string | null
|
|
18
38
|
definition_name: string; definition_version: string; definition_signature: string; input_json: string
|
|
19
|
-
cancel_actor_id: string | null; status: WorkflowStatus; resume_status: WorkflowStatus | null; correlation_id: string; lease_token: string; last_error_code: string | null
|
|
39
|
+
cancel_actor_id: string | null; status: WorkflowStatus; resume_status: WorkflowStatus | null; correlation_id: string; lease_token: string | null; lease_until: number | null; next_attempt_at: number; last_error_code: string | null
|
|
20
40
|
}
|
|
21
41
|
interface Step {
|
|
22
42
|
step_id: string; status: string; attempts: number; compensation_attempts: number; deadline_at: number | null
|
|
23
43
|
compensation_deadline_at: number | null; compensation_checkpoint_json: string | null; last_error_code: string | null; checkpoint_json: string | null; next_attempt_at: number
|
|
24
44
|
}
|
|
45
|
+
function serializeCheckpoint(result: unknown): string {
|
|
46
|
+
const serialized = JSON.stringify(result)
|
|
47
|
+
if (serialized === undefined) throw new TypeError('Workflow checkpoint must be JSON serializable')
|
|
48
|
+
return serialized
|
|
49
|
+
}
|
|
25
50
|
function publicCheckpoint(serialized: string) {
|
|
26
51
|
const value = JSON.parse(serialized)
|
|
27
52
|
if (!value || typeof value !== 'object' || Array.isArray(value)) return value
|
|
@@ -87,6 +112,17 @@ export class D1WorkflowRuntime implements WorkflowRuntime {
|
|
|
87
112
|
const event = makeEvent(this.config, scope, code, 'workflows', id, {}, {}, { run_id: id, ...(stepId ? { step_id: stepId } : {}), ...(errorCode ? { code: errorCode } : {}) })
|
|
88
113
|
return outboxInsert(event)
|
|
89
114
|
}
|
|
115
|
+
// Snapshot budgets before the fenced commit; a stolen lease rolls back both
|
|
116
|
+
// the transition and its audit event. Keep the Queue envelope identical to D1.
|
|
117
|
+
private async evidence(statement: GuardedStatement, id: string, status: WorkflowStatus) {
|
|
118
|
+
const event = statement.outboxEvent
|
|
119
|
+
if (!event) return statement
|
|
120
|
+
const stepId = event.details?.step_id
|
|
121
|
+
const counts = await this.env.DB.prepare(`SELECT coalesce(sum(attempts),0) AS attempts,coalesce(sum(compensation_attempts),0) AS compensation_attempts FROM workflow_steps WHERE run_id=? AND (? IS NULL OR step_id=?)`)
|
|
122
|
+
.bind(id, stepId ?? null, stepId ?? null).first<{ attempts: number; compensation_attempts: number }>()
|
|
123
|
+
return outboxInsert({ ...event, details: { ...event.details, state: status, ...counts } })
|
|
124
|
+
}
|
|
125
|
+
|
|
90
126
|
private scope(run: Run): Scope {
|
|
91
127
|
if (run.cancel_actor_id) return { organizationId: run.organization_id, actor: { type: 'user', id: run.cancel_actor_id }, role: '', correlationId: run.correlation_id }
|
|
92
128
|
return { organizationId: run.organization_id, actor: { type: run.actor_type, id: run.actor_id, ...(run.token_id ? { tokenId: run.token_id } : {}) }, role: '', correlationId: run.correlation_id }
|
|
@@ -96,10 +132,12 @@ export class D1WorkflowRuntime implements WorkflowRuntime {
|
|
|
96
132
|
return { sql: `UPDATE workflow_runs SET updated_at=? WHERE id=? AND lease_token=? AND lease_until>max(?,CAST((julianday('now')-2440587.5)*86400000 AS INTEGER))${run.cancel_actor_id ? " AND EXISTS(SELECT 1 FROM memberships WHERE user_id=? AND organization_id=workflow_runs.organization_id AND role='owner')" : ''}`, bindings: [new Date(now).toISOString(), run.id, run.lease_token, now, ...(run.cancel_actor_id ? [run.cancel_actor_id] : [])], expectRows: 1 }
|
|
97
133
|
}
|
|
98
134
|
private async transition(run: Run, now: number, status: WorkflowStatus, event: string, code: string | null = null, statements: GuardedStatement[] = [], stepId?: string, nextAt = now) {
|
|
135
|
+
statements = await Promise.all(statements.map(statement => this.evidence(statement, run.id, status)))
|
|
136
|
+
const audit = await this.evidence(this.audit(this.scope(run), run.id, event, stepId, code ?? undefined), run.id, status)
|
|
99
137
|
await this.submit([this.fence(status === 'needs_attention' ? { ...run, cancel_actor_id: null } : run, now), ...statements, {
|
|
100
138
|
sql: 'UPDATE workflow_runs SET status=?,resume_status=?,last_error_code=?,next_attempt_at=?,lease_until=NULL,lease_token=NULL WHERE id=?',
|
|
101
139
|
bindings: [status, status === 'needs_attention' ? (run.status === 'compensating' ? 'compensating' : 'running') : null, code, nextAt, run.id], expectRows: 1,
|
|
102
|
-
},
|
|
140
|
+
}, audit])
|
|
103
141
|
}
|
|
104
142
|
async resume(id: string, context: ExecutionContext) {
|
|
105
143
|
if (infrastructure(context).workflowRuntime !== this || context.config.id !== this.config.id || context.config.revision !== this.config.revision) throw new ApiError(403, 'workflow_context_mismatch')
|
|
@@ -113,7 +151,7 @@ export class D1WorkflowRuntime implements WorkflowRuntime {
|
|
|
113
151
|
if (run.status !== 'needs_attention') throw new ApiError(409, 'workflow_not_paused')
|
|
114
152
|
const definition = this.definitions.get(run.definition_name)
|
|
115
153
|
if (!definition || definition.version !== run.definition_version || workflowSignature(definition) !== run.definition_signature) {
|
|
116
|
-
await this.submit([{ sql: "UPDATE workflow_runs SET last_error_code='workflow.definition_mismatch' WHERE id=? AND status='needs_attention'", bindings: [id], expectRows: 1 }, this.audit(this.scope(run), id, 'workflow.needs_attention', undefined, 'workflow.definition_mismatch')])
|
|
154
|
+
await this.submit([{ sql: "UPDATE workflow_runs SET last_error_code='workflow.definition_mismatch' WHERE id=? AND status='needs_attention'", bindings: [id], expectRows: 1 }, await this.evidence(this.audit(this.scope(run), id, 'workflow.needs_attention', undefined, 'workflow.definition_mismatch'), id, 'needs_attention')])
|
|
117
155
|
throw new ApiError(409, 'workflow.definition_mismatch')
|
|
118
156
|
}
|
|
119
157
|
const saved = (await this.env.DB.prepare('SELECT * FROM workflow_steps WHERE run_id=? ORDER BY position').bind(id).all<Step>()).results
|
|
@@ -204,24 +242,69 @@ export class D1WorkflowRuntime implements WorkflowRuntime {
|
|
|
204
242
|
}
|
|
205
243
|
async tick(options: { now?: number; limit?: number } = {}) {
|
|
206
244
|
const started = Date.now(); const scanNow = options.now ?? started
|
|
245
|
+
const invocation = { remainingSteps: continuationSteps, deadline: started + continuationDurationMs }
|
|
207
246
|
const limit = Math.max(0, Math.min(Math.trunc(options.limit ?? 20), 100))
|
|
208
247
|
const released = await this.sweepHolds(scanNow, limit)
|
|
209
248
|
const rows = await this.env.DB.prepare(`SELECT id FROM workflow_runs WHERE status IN (${active}) AND next_attempt_at<=? AND (lease_until IS NULL OR lease_until<=?) ORDER BY next_attempt_at,id LIMIT ?`).bind(scanNow, scanNow, limit).all<{ id: string }>()
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
249
|
+
const claimed = new Set<string>()
|
|
250
|
+
let pending = rows.results
|
|
251
|
+
// One pass per run per sweep. Short chains can still finish in one tick,
|
|
252
|
+
// while long chains share a single work allowance and elapsed deadline.
|
|
253
|
+
while (pending.length && invocation.remainingSteps > 0 && Date.now() < invocation.deadline) {
|
|
254
|
+
const next: typeof pending = []
|
|
255
|
+
for (const row of pending) {
|
|
256
|
+
if (invocation.remainingSteps <= 0 || Date.now() >= invocation.deadline) break
|
|
257
|
+
const result = await this.continueRun(row.id, { now: scanNow + Date.now() - started, maxSteps: 1 }, invocation)
|
|
258
|
+
if (result.claimed) claimed.add(row.id)
|
|
259
|
+
if (result.claimed && result.status === 'budget_exhausted') next.push(row)
|
|
260
|
+
}
|
|
261
|
+
pending = next
|
|
262
|
+
}
|
|
263
|
+
return { claimed: claimed.size, released }
|
|
264
|
+
}
|
|
265
|
+
private readiness(run: Run | null, now: number): WorkflowReadiness | null {
|
|
266
|
+
// A deleted/stale wake has no work, just like a terminal run.
|
|
267
|
+
if (!run) return { status: 'terminal' }
|
|
268
|
+
if (run.status === 'needs_attention') return { status: 'paused' }
|
|
269
|
+
if (!['pending', 'running', 'waiting_external', 'compensating'].includes(run.status)) return { status: 'terminal' }
|
|
270
|
+
if (run.next_attempt_at > now) return { status: 'due_at', dueAt: run.next_attempt_at }
|
|
271
|
+
if (run.lease_until !== null && run.lease_until > now) return { status: 'lease_lost' }
|
|
272
|
+
return null
|
|
273
|
+
}
|
|
274
|
+
async continueRun(runId: string, budget: WorkflowContinuationBudget = {}, invocation?: WorkflowInvocationBudget): Promise<WorkflowContinuationResult> {
|
|
275
|
+
const started = Date.now(); const referenceNow = budget.now ?? started
|
|
276
|
+
const maxSteps = budget.maxSteps ?? continuationSteps; const maxDurationMs = budget.maxDurationMs ?? continuationDurationMs
|
|
277
|
+
if (![maxSteps, maxDurationMs, referenceNow].every(Number.isFinite) || maxSteps < 0 || maxDurationMs < 0) throw new RangeError('invalid_workflow_continuation_budget')
|
|
278
|
+
const time = () => referenceNow + Date.now() - started
|
|
279
|
+
const load = () => this.env.DB.prepare('SELECT * FROM workflow_runs WHERE id=?').bind(runId).first<Run>()
|
|
280
|
+
let claimed = false
|
|
281
|
+
for (let passes = 0; ; passes++) {
|
|
282
|
+
if (invocation && (invocation.remainingSteps <= 0 || Date.now() >= invocation.deadline)) return { status: 'budget_exhausted', claimed }
|
|
283
|
+
// Every committed transition releases its lease. Never carry the old snapshot
|
|
284
|
+
// or token into another pass: D1 decides readiness and ownership again.
|
|
285
|
+
const readiness = this.readiness(await load(), time())
|
|
286
|
+
if (readiness) return { ...readiness, claimed }
|
|
287
|
+
if (passes >= Math.min(continuationSteps, Math.trunc(maxSteps)) || Date.now() - started >= Math.min(continuationDurationMs, maxDurationMs)) return { status: 'budget_exhausted', claimed }
|
|
288
|
+
// Storage reads also consume elapsed time; do not start a pass after them
|
|
289
|
+
// if the invocation deadline has already passed. Count claim attempts too.
|
|
290
|
+
if (invocation) {
|
|
291
|
+
if (Date.now() >= invocation.deadline) return { status: 'budget_exhausted', claimed }
|
|
292
|
+
invocation.remainingSteps--
|
|
293
|
+
}
|
|
294
|
+
const now = time()
|
|
295
|
+
const run = await this.env.DB.prepare(`UPDATE workflow_runs SET lease_token=?,lease_until=? WHERE id=? AND status IN (${active}) AND next_attempt_at<=? AND (lease_until IS NULL OR lease_until<=?) RETURNING *`).bind(crypto.randomUUID(), now + 60000, runId, now, now).first<Run>()
|
|
296
|
+
if (!run) return { ...(this.readiness(await load(), time()) ?? { status: 'lease_lost' as const }), claimed }
|
|
297
|
+
claimed = true
|
|
298
|
+
try { await this.advance(run, time()) }
|
|
217
299
|
catch (error) {
|
|
218
|
-
//
|
|
219
|
-
//
|
|
220
|
-
|
|
221
|
-
|
|
300
|
+
// Only an atomic rejection with lost/expired ownership is an expected
|
|
301
|
+
// fencing race. Expiry alone cannot explain an unrelated storage fault.
|
|
302
|
+
if (!(error instanceof RuleFailed)) throw error
|
|
303
|
+
const owner = await this.env.DB.prepare("SELECT lease_token,lease_until>max(?,CAST((julianday('now')-2440587.5)*86400000 AS INTEGER)) AS lease_live FROM workflow_runs WHERE id=?").bind(time(), runId).first<{ lease_token: string | null; lease_live: number }>()
|
|
304
|
+
if (owner?.lease_token !== run.lease_token || !owner.lease_live) return { status: 'lease_lost', claimed }
|
|
305
|
+
throw error
|
|
222
306
|
}
|
|
223
307
|
}
|
|
224
|
-
return { claimed, released }
|
|
225
308
|
}
|
|
226
309
|
private async advance(run: Run, now: number) {
|
|
227
310
|
// Include permission/checkpoint reads in elapsed time, not only the effect.
|
|
@@ -265,7 +348,7 @@ export class D1WorkflowRuntime implements WorkflowRuntime {
|
|
|
265
348
|
context = coreExecutionContext(this.config, live, store, new D1AtomicReader(this.env.DB), key, undefined, { policyReceipt: !compensating })
|
|
266
349
|
// If an atomic effect committed before a crash, recover its receipt without repeating it or spending another attempt.
|
|
267
350
|
const receipt = compensating ? saved.compensation_checkpoint_json : saved.checkpoint_json
|
|
268
|
-
if (receipt)
|
|
351
|
+
if (receipt) return this.finishStep(run, optionsNow(), step, compensating, serializeCheckpoint(JSON.parse(receipt)))
|
|
269
352
|
if (optionsNow() >= deadline) throw new ApiError(408, 'workflow.deadline_exceeded')
|
|
270
353
|
if (count >= step.policy.maxAttempts && !compensating && step.kind === 'external' && step.recover) {
|
|
271
354
|
const controller = new AbortController()
|
|
@@ -273,7 +356,7 @@ export class D1WorkflowRuntime implements WorkflowRuntime {
|
|
|
273
356
|
const result = await Promise.race([step.recover(Object.freeze({ context, runId: run.id, input: JSON.parse(run.input_json), checkpoints: Object.fromEntries(rows.filter(s => s.checkpoint_json).map(s => [s.step_id, publicCheckpoint(s.checkpoint_json!)])), signal: controller.signal })), new Promise<never>((_, reject) => {
|
|
274
357
|
timer = setTimeout(() => { controller.abort(); reject(new ApiError(408, 'workflow.external_timeout')) }, Math.min(step.policy.timeoutMs, deadline - optionsNow()))
|
|
275
358
|
})]).finally(() => clearTimeout(timer))
|
|
276
|
-
if (result !== null && optionsNow() < deadline)
|
|
359
|
+
if (result !== null && optionsNow() < deadline) return this.finishStep(run, optionsNow(), step, false, serializeCheckpoint(result))
|
|
277
360
|
}
|
|
278
361
|
if (count >= step.policy.maxAttempts) throw new ApiError(408, 'workflow.attempts_exhausted')
|
|
279
362
|
await this.submit([this.fence(run, optionsNow()), {
|
|
@@ -289,10 +372,14 @@ export class D1WorkflowRuntime implements WorkflowRuntime {
|
|
|
289
372
|
})]).finally(() => clearTimeout(timer))
|
|
290
373
|
// No late response can checkpoint after the deadline or a newer runner's lease.
|
|
291
374
|
if (optionsNow() >= deadline) throw new ApiError(408, 'workflow.deadline_exceeded')
|
|
292
|
-
|
|
375
|
+
// Validate the checkpoint inside the step failure boundary, then return
|
|
376
|
+
// the finalization promise without catching its storage errors as
|
|
377
|
+
// step failures. Retrying a transition could mask the original fault with
|
|
378
|
+
// a fence rejection after expiry; the committed receipt enables recovery.
|
|
379
|
+
return this.finishStep(run, optionsNow(), step, compensating, serializeCheckpoint(result ?? null))
|
|
293
380
|
} catch (error) {
|
|
294
381
|
const time = optionsNow()
|
|
295
|
-
if (error instanceof PermissionRevoked) { await this.transition(run, time, 'needs_attention', 'workflow.needs_attention', 'permission_revoked'); return }
|
|
382
|
+
if (error instanceof PermissionRevoked) { await this.transition(run, time, 'needs_attention', 'workflow.needs_attention', 'permission_revoked', [], step.id); return }
|
|
296
383
|
let code = error instanceof ApiError && ['workflow.external_timeout', 'workflow.deadline_exceeded', 'workflow.attempts_exhausted', 'rule_failed', 'workflow.external_not_configured', 'workflow.external_transport_failed', 'workflow.external_forbidden', 'workflow.external_rejected', 'workflow.external_invalid_receipt'].includes(error.code) ? error.code : 'workflow.step_failed'
|
|
297
384
|
const uncertainCodes = ['workflow.external_timeout', 'workflow.external_transport_failed']
|
|
298
385
|
const waitForDeadline = !compensating && step.kind === 'external' && time < deadline
|
|
@@ -312,13 +399,13 @@ export class D1WorkflowRuntime implements WorkflowRuntime {
|
|
|
312
399
|
], step.id, exhausted ? time : next)
|
|
313
400
|
}
|
|
314
401
|
}
|
|
315
|
-
private finishStep(run: Run, now: number, step: WorkflowStep, undo: boolean,
|
|
402
|
+
private finishStep(run: Run, now: number, step: WorkflowStep, undo: boolean, serialized: string) {
|
|
316
403
|
const checkpoint = undo ? 'compensation_checkpoint_json' : 'checkpoint_json'
|
|
317
404
|
return this.transition(run, now, undo ? 'compensating' : 'running', undo ? 'workflow.step.compensated' : 'workflow.step.completed', undo ? run.last_error_code : null, [{
|
|
318
405
|
// Keep the execution-owned policy receipt committed with an atomic effect.
|
|
319
406
|
// The public return value has already stripped the affected-row metadata.
|
|
320
407
|
sql: `UPDATE workflow_steps SET status=?,${checkpoint}=COALESCE(${checkpoint},?),last_error_code=NULL,next_attempt_at=0 WHERE run_id=? AND step_id=?`,
|
|
321
|
-
bindings: [undo ? 'compensated' : 'completed',
|
|
408
|
+
bindings: [undo ? 'compensated' : 'completed', serialized, run.id, step.id], expectRows: 1,
|
|
322
409
|
}], step.id)
|
|
323
410
|
}
|
|
324
411
|
}
|
package/src/bootstrap.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { App, RuntimeEnv, RuntimeOptions } from './types'
|
|
2
|
-
import type { KernelRegistry } from './kernel/registry'
|
|
3
|
-
import { capabilities } from './capabilities'
|
|
4
|
-
import { publicSchema } from './public-schema'
|
|
5
|
-
import { meDocument } from './organizations'
|
|
6
|
-
import { scopeMiddleware } from './authorization'
|
|
7
|
-
import { buildInfo } from './console'
|
|
8
|
-
|
|
9
|
-
/** Session-local QueryClient caching only: never share actor/org projections in HTTP caches. */
|
|
10
|
-
export function bootstrapRoutes(app: App, kernel: KernelRegistry, env: RuntimeEnv, options: RuntimeOptions) {
|
|
11
|
-
app.get('/o/:org/bootstrap', scopeMiddleware(env, kernel.config, kernel), async c => c.json({
|
|
12
|
-
schema: publicSchema(kernel.config, options),
|
|
13
|
-
capabilities: capabilities(kernel, c.get('scope')),
|
|
14
|
-
console: kernel.providers.get('console')?.[0]?.consoleRegistry?.(kernel.config, c.get('scope')),
|
|
15
|
-
me: meDocument(c.get('resolvedActor'), kernel.config),
|
|
16
|
-
build: await buildInfo(kernel.config, env, c.req.url),
|
|
17
|
-
}, 200, { 'Cache-Control': 'private, no-store', Vary: 'Cookie, Authorization, X-Organization-Id' }))
|
|
18
|
-
app.get('/bootstrap', async c => c.json({
|
|
19
|
-
schema: publicSchema(kernel.config, options),
|
|
20
|
-
me: meDocument(await kernel.requireActor(c.req.raw, env), kernel.config),
|
|
21
|
-
build: await buildInfo(kernel.config, env, c.req.url),
|
|
22
|
-
}, 200, { 'Cache-Control': 'private, no-store', Vary: 'Cookie, Authorization' }))
|
|
23
|
-
}
|