Skip to content

[Bug]: WorkflowRuntime.execute() crashes at parse time due to duplicate const declarations #38

@rishab11250

Description

@rishab11250

Bug Description

The execute() method in packages/core/src/lib/runtime.ts has two sets of const declarations in the same function scope. JavaScript const cannot be redeclared, so calling WorkflowRuntime.execute() throws a SyntaxError at parse time. This makes the entire workflow execution system non-functional.

This bug was introduced by PR #34 ("fix runtime tenant tracing events") which added a new execution loop (lines 81-129) but kept the existing retry-enabled loop (lines 132+) instead of replacing it. Both loops now declare const state and const results in the same scope.

Prerequisites

  • I have verified that this issue has not already been reported.
  • I have checked the documentation and believe this is a genuine malfunction, not a configuration error.
  • I am using the latest stable release or the main branch of PulseStack.

Steps to Reproduce

  1. Clone the repository and install dependencies with pnpm install.
  2. Start the PulseStack runtime service.
  3. Send a POST /api/runtime/executions request with any valid workflow payload:
{
  "workflow": {
    "id": "wf_test",
    "name": "Test Workflow",
    "version": "1.0.0",
    "tenantId": "tenant_prod",
    "correlationId": "corr_prod",
    "metadata": {},
    "steps": [
      { "id": "step1", "name": "Step 1", "kind": "tool", "dependsOn": [], "input": {} }
    ]
  },
  "input": {},
  "initiatedBy": "test"
}
  1. Observe the server crash with: SyntaxError: Identifier 'state' has already been declared

Expected Behavior

The workflow should execute successfully and return { executionId, traceId, output } containing the execution results.

Actual Behavior

The server throws a parse-time SyntaxError before any code executes. The method has two pairs of duplicate const declarations:

Lines 81-82 (first loop):

const state: Record<string, unknown> = { ...request.input };
const results: StepResult[] = [];

Lines 132-134 (second loop — same function scope):

const state: Record<string, unknown> = { ...request.input };
const retryState: Record<string, unknown> = {};
const results: StepResult[] = [];

Additionally, lines 84-129 contain ~50 lines of dead code from a prior implementation draft that is unreachable because the duplicate declarations cause a parse error first.

Diagnostic Information

Environment Details

System Logs & Stack Traces

SyntaxError: Identifier 'state' has already been declared
    at wrapSafe (<node_internal/modules/cjs/loader>:1378:20)
    at Module._compile (<node_internal/modules/cjs/loader>:1420:41)

Additional Context

The bug was introduced by the fix for issue #31 (PR #34). The developer added a new implementation block at lines 81-129 but neglected to remove the original block at lines 132+ that contains the same variable declarations. The fix is to delete lines 80-131 entirely, keeping only the retry-enabled version.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions