Skip to content

Commit d5ad786

Browse files
committed
improvement(workflow-code): one pause shape for execute and resume, and simplify the clean-slate removals
Execute and resume both return the run's pause through runPauseOf, the one rule for the run a pause is recorded under, and present it through one presenter. The primer rides only on the create scaffold, refusesApply is inlined, and the remaining unversioned base fixtures carry version 1.
1 parent c907775 commit d5ad786

20 files changed

Lines changed: 83 additions & 74 deletions

File tree

‎apps/sim/app/api/v2/workflows/[workflowId]/execute/route.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,7 @@ function presentRun(result: ExecuteWorkflowServiceRun) {
140140
executionTimeoutSeconds: executionTimeoutSeconds(result.executionTimeoutMs),
141141
output: result.output ?? null,
142142
blockOutputs: result.blockOutputs ?? null,
143-
paused:
144-
result.status === 'paused'
145-
? presentV2RunPause(result.executionId, result.pausePoints ?? [])
146-
: null,
143+
paused: presentV2RunPause(result.paused),
147144
}
148145
}
149146

‎apps/sim/app/api/v2/workflows/[workflowId]/runs/[runId]/resume/route.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,7 @@ export const POST = withRouteHandler(
118118
output: result.output ?? null,
119119
// Resume has no request body to name selectors in, so selection never applies here.
120120
blockOutputs: null,
121-
paused: result.paused
122-
? presentV2RunPause(result.paused.runId, result.paused.points)
123-
: null,
121+
paused: presentV2RunPause(result.paused),
124122
},
125123
{ headers }
126124
)

‎apps/sim/hooks/queries/workflow-source.test.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ function sourceServer() {
2121
workspaceId: 'ws-1',
2222
files: { 'workflow.ts': state.text },
2323
lock: { version: 1, blocks: {}, variables: {} },
24-
base: { workflowId: WORKFLOW_ID, workspaceId: 'ws-1', fingerprint: 'f', catalogHash: 'c' },
24+
base: {
25+
version: 1,
26+
workflowId: WORKFLOW_ID,
27+
workspaceId: 'ws-1',
28+
fingerprint: 'f',
29+
catalogHash: 'c',
30+
},
2531
canonicalHash: 'h',
2632
sdkMajor: 1,
2733
blockTypes: [],

‎apps/sim/lib/api/contracts/v2/workflows.ts‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,6 @@ export const v2WorkflowRunIdSchema = runIdSchema
8686
.describe('Unique workflow run identifier.')
8787
.meta({ examples: ['run_8f14e45f-ceea-467f-a'] })
8888

89-
/**
90-
* The run a pause is recorded under, which Resume workflow run names. A resumed run that pauses
91-
* again records the pause under the run it resumed, not under the resume attempt's own id.
92-
*/
9389
const v2PausedRunIdSchema = z
9490
.string()
9591
.describe(

‎apps/sim/lib/workflows/api/run-pause.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import type { V2ExecuteWorkflowData } from '@/lib/api/contracts/v2/workflows'
2-
import type { PausePoint } from '@/executor/types'
2+
import type { RunPause } from '@/lib/workflows/executor/run-pause'
33

44
/**
5-
* The v2 wire shape of where a run waits, shared by the execute and resume results: the run the
6-
* pause is recorded under (which Resume workflow run names) and each of its points.
5+
* The v2 wire shape of where a run waits, shared by the execute and resume results; null when it
6+
* is not paused.
77
*/
88
export function presentV2RunPause(
9-
runId: string,
10-
points: readonly PausePoint[]
11-
): NonNullable<V2ExecuteWorkflowData['paused']> {
9+
pause: RunPause | null | undefined
10+
): V2ExecuteWorkflowData['paused'] {
11+
if (!pause) return null
1212
return {
13-
runId,
14-
points: points.map((point) => ({
13+
runId: pause.runId,
14+
points: pause.points.map((point) => ({
1515
contextId: point.contextId,
1616
kind: point.pauseKind,
1717
status: point.resumeStatus,

‎apps/sim/lib/workflows/executor/execute-service.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
releaseExecutionIdClaim,
3333
} from '@/lib/workflows/executor/execution-id-claim'
3434
import { handlePostExecutionPauseState } from '@/lib/workflows/executor/pause-persistence'
35+
import { type RunPause, runPauseOf } from '@/lib/workflows/executor/run-pause'
3536
import {
3637
loadDeployedWorkflowState,
3738
loadWorkflowDeploymentVersionState,
@@ -52,7 +53,7 @@ import { workflowHasResponseBlock } from '@/lib/workflows/utils'
5253
import { normalizeName } from '@/executor/constants'
5354
import { ExecutionSnapshot } from '@/executor/execution/snapshot'
5455
import type { ExecutionMetadata, SerializableExecutionState } from '@/executor/execution/types'
55-
import type { BlockLog, NormalizedBlockOutput, PausePoint } from '@/executor/types'
56+
import type { BlockLog, NormalizedBlockOutput } from '@/executor/types'
5657
import {
5758
classifyExecutionError,
5859
hasExecutionResult,
@@ -183,8 +184,8 @@ export interface ExecuteWorkflowServiceRun {
183184
durationMs?: number
184185
/** The execution timeout applied to the run in milliseconds; `0` means untimed. */
185186
executionTimeoutMs: number
186-
/** Where a `paused` run waits, recorded under its `executionId`. */
187-
pausePoints?: PausePoint[]
187+
/** Where a `paused` run waits; absent otherwise. */
188+
paused?: RunPause | null
188189
}
189190

190191
/** A run's result before the applied timeout is stamped onto it. */
@@ -866,7 +867,7 @@ export async function executeWorkflowService(
866867
startedAt: result.metadata?.startTime,
867868
endedAt: result.metadata?.endTime,
868869
durationMs: result.metadata?.duration,
869-
...(status === 'paused' ? { pausePoints: result.pausePoints ?? [] } : {}),
870+
paused: runPauseOf(result, executionId),
870871
}
871872
} catch (error: unknown) {
872873
const errorMessage = getErrorMessage(error, 'Unknown error')

‎apps/sim/lib/workflows/executor/human-in-the-loop-manager.ts‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import {
5959
normalizeAutomaticResumeWaitingReason,
6060
resolveAutomaticResumeAdmissionFailure,
6161
} from '@/lib/workflows/executor/resume-policy'
62+
import { pausedRunIdOf } from '@/lib/workflows/executor/run-pause'
6263
import {
6364
forwardAgentStreamToExecutionEvents,
6465
shouldForwardAnswerTextFromSink,
@@ -175,14 +176,6 @@ class ResumeAdmissionError extends Error {
175176
export type FailedResumeOutcome = 'pause_retained' | 'execution_failed' | 'execution_completed'
176177

177178
/** Matches the paused execution mode to the deployment recorded on its durable root log. */
178-
/**
179-
* The run a resumed attempt's pause is recorded under: the execution the resumed engine ran as,
180-
* else the attempt's own id. Resume workflow run names this run to resume the pause.
181-
*/
182-
export function pausedRunIdOf(result: ExecutionResult, resumeExecutionId: string): string {
183-
return result.metadata?.executionId ?? resumeExecutionId
184-
}
185-
186179
export function requireResumeDeploymentVersion(
187180
useDraftState: unknown,
188181
deploymentVersionId: string | null

‎apps/sim/lib/workflows/executor/resume-execution.ts‎

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@ import type { OrchestrationRequestContext } from '@/lib/core/orchestration/types
1414
import { generateRequestId } from '@/lib/core/utils/request'
1515
import { preprocessExecution } from '@/lib/execution/preprocessing'
1616
import { RESUME_EXECUTION_JOB_ID_PREFIX } from '@/lib/workflows/executor/enqueue-execution'
17-
import {
18-
PauseResumeManager,
19-
pausedRunIdOf,
20-
} from '@/lib/workflows/executor/human-in-the-loop-manager'
17+
import { PauseResumeManager } from '@/lib/workflows/executor/human-in-the-loop-manager'
18+
import { type RunPause, runPauseOf } from '@/lib/workflows/executor/run-pause'
2119
import { createStreamingResponse } from '@/lib/workflows/streaming/streaming'
2220
import { executeResumeJob, type ResumeExecutionPayload } from '@/background/resume-execution'
2321
import { ExecutionSnapshot } from '@/executor/execution/snapshot'
24-
import type { ExecutionResult, PausePoint } from '@/executor/types'
22+
import type { ExecutionResult } from '@/executor/types'
2523
import {
2624
classifyExecutionError,
2725
hasExecutionResult,
@@ -90,8 +88,8 @@ export type ResumeWorkflowExecutionResult =
9088
startTime?: string
9189
endTime?: string
9290
}
93-
/** Where a run that paused again waits: the run the pause is recorded under, and its points. */
94-
paused: { runId: string; points: PausePoint[] } | null
91+
/** Where a run that paused again waits. */
92+
paused: RunPause | null
9593
}
9694
| {
9795
kind: 'async'
@@ -359,12 +357,7 @@ export async function executeResumeWorkflow({
359357
}
360358
: undefined,
361359
paused:
362-
status === 'paused'
363-
? {
364-
runId: pausedRunIdOf(result, enqueueResult.resumeExecutionId),
365-
points: result.pausePoints ?? [],
366-
}
367-
: null,
360+
runFailure === undefined ? runPauseOf(result, enqueueResult.resumeExecutionId) : null,
368361
}
369362
}
370363

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import type { ExecutionResult, PausePoint } from '@/executor/types'
2+
3+
/** Where a paused run waits: the run its pause is recorded under, and each pause point. */
4+
export interface RunPause {
5+
runId: string
6+
points: PausePoint[]
7+
}
8+
9+
/**
10+
* The run a pause is recorded under, which Resume workflow run names: the execution the engine ran
11+
* as, else `runId`, the id the run was started or resumed with. A resumed run that pauses again
12+
* records the pause under the run it resumed, not the resume attempt's own id.
13+
*/
14+
export function pausedRunIdOf(result: ExecutionResult, runId: string): string {
15+
return result.metadata?.executionId ?? runId
16+
}
17+
18+
/** Where `result` waits when it paused, else null. */
19+
export function runPauseOf(result: ExecutionResult, runId: string): RunPause | null {
20+
if (result.status !== 'paused') return null
21+
return { runId: pausedRunIdOf(result, runId), points: result.pausePoints ?? [] }
22+
}

‎packages/sim-cli/src/commands/protocol/source-tree.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -535,16 +535,14 @@ export interface SourceTree {
535535
workspaceTypes: boolean
536536
/** The agent guide to read before editing. */
537537
guide: typeof SOURCE_AGENTS_FILE
538-
/** The primer atop the guide (`source-primer.ts`), printed so an agent needs no other read. */
539-
primer: string
540538
}
541539

542540
/** Reports a `tsconfig.json` the CLI left alone and summarizes a tree write. */
543541
export function finishTree(
544542
dir: string,
545543
written: number,
546544
workspaceTypes: WorkspaceTypes | null,
547-
tree: { ownsTsconfig: boolean; primer: string }
545+
tree: { ownsTsconfig: boolean }
548546
): SourceTree {
549547
if (!tree.ownsTsconfig) {
550548
printError(
@@ -555,14 +553,13 @@ export function finishTree(
555553
files: written,
556554
workspaceTypes: workspaceTypes !== null,
557555
guide: SOURCE_AGENTS_FILE,
558-
primer: tree.primer,
559556
}
560557
}
561558

562559
/**
563560
* Prints a tree write's result: the fields, then the primer as text when the result carries one
564-
* (in JSON or YAML it is the document's `primer` field). A get leaves the primer out: it is
565-
* already the top of `.sim/AGENTS.md`.
561+
* (in JSON or YAML it is the document's `primer` field). Only a new directory's starter prints
562+
* it; a get leaves it at the top of `.sim/AGENTS.md`.
566563
*/
567564
export function printTreeResult(
568565
format: OutputFormat,

0 commit comments

Comments
 (0)