From 8a33bf946192963da5bea9439d33ef500197af88 Mon Sep 17 00:00:00 2001 From: rishab11250 Date: Wed, 3 Jun 2026 22:46:50 +0530 Subject: [PATCH] fix: resolve runStep broken method signature and swapped arguments - Removed duplicate return type declaration in runStep method (Bug A) - Fixed runStepWithRetry passing args.correlationId as tenantId and attempt as correlationId (Bug B) - Removed first-draft dead code left inside execute() callback - Added missing tenantId to startSpan call in retry loop - Fixed runtime.test.ts: closed unclosed describe/it blocks, removed duplicate imports, added missing type imports Closes #40 --- packages/core/src/lib/runtime.test.ts | 19 +++++++------- packages/core/src/lib/runtime.ts | 38 ++------------------------- 2 files changed, 11 insertions(+), 46 deletions(-) diff --git a/packages/core/src/lib/runtime.test.ts b/packages/core/src/lib/runtime.test.ts index f169521..51d0574 100644 --- a/packages/core/src/lib/runtime.test.ts +++ b/packages/core/src/lib/runtime.test.ts @@ -1,6 +1,12 @@ import { describe, expect, it } from 'vitest'; -import type { EventEnvelope, WorkflowDefinition } from '@pulsestack/contracts'; +import type { + EventEnvelope, + ExecutionSnapshot, + TraceSpan, + WorkflowDefinition, +} from '@pulsestack/contracts'; +import type { PulseInfra } from './infra.js'; import { WorkflowRuntime } from './runtime.js'; class RuntimeInfraMock { @@ -43,15 +49,8 @@ describe('WorkflowRuntime', () => { ); expect(tenantEvents.length).toBeGreaterThan(0); expect(tenantEvents.every((event) => event.tenantId === workflow.tenantId)).toBe(true); - -import type { - EventEnvelope, - ExecutionSnapshot, - TraceSpan, -} from '@pulsestack/contracts'; -import { describe, expect, it } from 'vitest'; -import type { PulseInfra } from './infra.js'; -import { WorkflowRuntime } from './runtime.js'; + }); +}); function createRuntimeHarness() { const events: EventEnvelope[] = []; diff --git a/packages/core/src/lib/runtime.ts b/packages/core/src/lib/runtime.ts index e2bceda..18b077b 100644 --- a/packages/core/src/lib/runtime.ts +++ b/packages/core/src/lib/runtime.ts @@ -78,39 +78,6 @@ export class WorkflowRuntime { input: request.input, }); - const state: Record = { ...request.input }; - const results: StepResult[] = []; - - for (const [index, step] of request.workflow.steps.entries()) { - const span = await this.startSpan({ - traceId, - executionId, - workflowId: request.workflow.id, - tenantId: request.workflow.tenantId, - step, - state, - }); - - const result = await this.runStep(step, state, request.workflow.tenantId, request.workflow.correlationId); - Object.assign(state, { [step.id]: result.output }); - results.push(result); - - await this.snapshot({ - id: createId('snap'), - executionId, - workflowId: request.workflow.id, - sequence: index, - state: structuredClone(state), - sideEffects: [ - { - type: step.kind, - key: step.id, - response: result.output, - }, - ], - createdAt: new Date().toISOString(), - }); - await publishEvent( this.infra, createEvent({ @@ -157,6 +124,7 @@ export class WorkflowRuntime { traceId, executionId, workflowId: request.workflow.id, + tenantId: request.workflow.tenantId, parentSpanId: workflowSpanId, step, state, @@ -303,6 +271,7 @@ export class WorkflowRuntime { const result = await this.runStep( args.step, args.state, + args.tenantId, args.correlationId, attempt, ); @@ -368,9 +337,6 @@ export class WorkflowRuntime { tenantId: string, correlationId: string, - ): Promise { - - correlationId: string, attempt: number, ): Promise> {