fix(workflow): address ready review findings
This commit is contained in:
@@ -289,6 +289,8 @@ export function apply(ctx: Context, config: Config): void {
|
||||
signal: exec.signal,
|
||||
})
|
||||
const recordsRun = exec.parent === undefined
|
||||
// The shipped worker-thread engine publishes member events from later
|
||||
// worker messages, after start() returns and this run record is active.
|
||||
if (recordsRun) recorder.start(parent.session, run)
|
||||
|
||||
// Bridge the tool's abort signal to the run: if the parent step is aborted while the
|
||||
@@ -317,8 +319,11 @@ export function apply(ctx: Context, config: Config): void {
|
||||
// Keep member listeners alive through disposal: an engine may
|
||||
// synthesize cancelled member endings while reaching quiescence.
|
||||
await run.dispose()
|
||||
/* v8 ignore next -- WorkflowRun.result never rejects by contract, so result is assigned before finally. */
|
||||
if (recordsRun && result !== undefined) recorder.finish(run.id, result.stopReason)
|
||||
if (recordsRun) {
|
||||
/* v8 ignore next -- WorkflowRun.result never rejects by contract, so result is assigned before finally. */
|
||||
if (result === undefined) throw new Error('workflow run settled without a result')
|
||||
recorder.finish(run.id, result.stopReason)
|
||||
}
|
||||
} finally {
|
||||
if (recordsRun) recorder.abandon(run.id)
|
||||
}
|
||||
|
||||
@@ -128,11 +128,6 @@ function applyEvent(trace: WorkflowTrace, event: SessionEvent, fail: InvariantFa
|
||||
}
|
||||
}
|
||||
|
||||
/** Apply one cold-load or live-append candidate through the package reporter. */
|
||||
function applyChecked(trace: WorkflowTrace, event: SessionEvent, fail: InvariantFailure): void {
|
||||
applyEvent(trace, event, fail)
|
||||
}
|
||||
|
||||
/** Install an independent incremental fold over every attached Session. */
|
||||
const install: InvariantInstaller = Object.assign((ctx: Context, fail: InvariantFailure) => {
|
||||
const traces = new WeakMap<Session, WorkflowTrace>()
|
||||
@@ -140,7 +135,7 @@ const install: InvariantInstaller = Object.assign((ctx: Context, fail: Invariant
|
||||
|
||||
const seed = (session: Session): WorkflowTrace => {
|
||||
const trace: WorkflowTrace = new Map()
|
||||
for (const event of session.events.filter(isWorkflowRecordEvent)) applyChecked(trace, event, fail)
|
||||
for (const event of session.events.filter(isWorkflowRecordEvent)) applyEvent(trace, event, fail)
|
||||
traces.set(session, trace)
|
||||
return trace
|
||||
}
|
||||
@@ -152,7 +147,7 @@ const install: InvariantInstaller = Object.assign((ctx: Context, fail: Invariant
|
||||
if (!isWorkflowRecordEvent(event)) return
|
||||
// session/event dispatch follows list() or session/created seeding.
|
||||
const trace = cloneTraceForEvent(traces.get(session) as WorkflowTrace, event, fail)
|
||||
applyChecked(trace, event, fail)
|
||||
applyEvent(trace, event, fail)
|
||||
staged.set(event, { session, trace })
|
||||
}, { global: true })
|
||||
ctx.on('session/event', (session, event) => {
|
||||
|
||||
Reference in New Issue
Block a user