Skip to content

Fix workflow action argument size limit error (18 MiB exceeds 16 MiB limit) #171

Closed

Description

@larryro

Problem Statement

When running workflows with multiple steps or steps that produce large outputs, the executeActionNode internalAction fails with:

Error: Uncaught Error: Arguments for workflow/nodes.js:executeActionNode are too large (actual: 18.56 MiB, limit: 16 MiB)

Convex actions have a strict 16 MiB argument size limit. The workflow engine currently passes the entire execution state (including accumulated outputs from all previous steps) as arguments to each action node, causing this limit to be exceeded.

Current State

The workflow engine accumulates all step outputs in a steps object that grows with each executed step:

Step 1 → steps = { step1: {output: ...500KB...} }
Step 2 → steps = { step1, step2: {output: ...2MB...} }
...
Step N → steps object exceeds 16 MiB → ERROR

In execute_step_by_type.ts, the buildVariablesForAction() function only trims loop nesting but passes the full steps object unchanged to every action call.

Actions that commonly produce large outputs:

  • crawler_action: Web page content, HTML, extracted text
  • document_action: Document content and metadata
  • conversation_action: Full conversation history
  • rag_action: Search results with document chunks

Proposed Solution

Implement a lazy loading pattern for step outputs:

  1. Exclude full step outputs from action arguments - Pass only step metadata (type, slug, status)
  2. Store large step outputs separately - Use Convex storage for outputs exceeding threshold
  3. Provide on-demand access - Actions that need previous step data fetch it explicitly via helper function

This mirrors the existing pattern in serialize_variables.ts that stores large variables in Convex storage.

Affected Components

  • convex/workflow/helpers/step_execution/execute_step_by_type.ts - Trim steps from action args
  • convex/workflow/helpers/step_execution/build_steps_map.ts - Add minimal steps builder
  • convex/workflow/helpers/serialization/serialize_step_output.ts - New: step output storage
  • convex/workflow/helpers/step_execution/get_step_output.ts - New: on-demand fetcher
  • convex/workflow/helpers/step_execution/persist_execution_result.ts - Integrate step storage
  • convex/workflow/actions/* - Review for steps dependency

Acceptance Criteria

  • Workflows with 10+ steps producing large outputs execute without argument size errors
  • Step outputs remain accessible to actions that need them via helper function
  • Workflow UI still displays step outputs correctly
  • No regression in existing workflow functionality
  • Backwards compatible with in-progress workflow executions

🤖 Generated with Claude Code

Activity

  1. larryro commented on Jan 11, 2026

    @larryro
    ContributorAuthor

    Implementation Plan

    Step 1: Add Step Output Storage Helper

    Create a helper to store large step outputs in Convex storage and return a reference.

    New file: convex/workflow/helpers/serialization/serialize_step_output.ts

    export interface StepOutputRef {
      _stepOutputRef: true;
      storageId: Id<'_storage'>;
      stepSlug: string;
    }
    
    export async function serializeStepOutput(
      ctx: ActionCtx,
      stepSlug: string,
      output: unknown,
    ): Promise<{ serialized: unknown; storageId?: Id<'_storage'> }>;

    Step 2: Create Minimal Steps Map Builder

    Modify build_steps_map.ts to add a companion function that returns minimal step references:

    function buildMinimalStepsMap(steps: Record<string, unknown>): Record<string, unknown> {
      const minimal: Record<string, unknown> = {};
      for (const [slug, step] of Object.entries(steps)) {
        if (step && typeof step === 'object') {
          const s = step as Record<string, unknown>;
          minimal[slug] = {
            stepType: s.stepType,
            name: s.name,
            hasOutput: s.output !== undefined,
            // Exclude full output
          };
        }
      }
      return minimal;
    }

    Step 3: Enhance buildVariablesForAction to Exclude Steps

    Modify: execute_step_by_type.ts

    function buildVariablesForAction(variables: Record<string, unknown>): Record<string, unknown> {
      const result: Record<string, unknown> = {};
      for (const [key, value] of Object.entries(variables)) {
        if (key === 'loop') {
          result.loop = trimLoop(value, 0);
        } else if (key === 'steps') {
          // Only pass step metadata, not full outputs
          result.steps = buildMinimalStepsMap(value as Record<string, unknown>);
        } else {
          result[key] = value;
        }
      }
      return result;
    }

    Step 4: Add Step Output Query Function

    New file: convex/workflow/helpers/step_execution/get_step_output.ts

    export async function getStepOutput(
      ctx: ActionCtx,
      executionId: string,
      stepSlug: string,
    ): Promise<unknown> {
      // Fetch execution variables from storage
      // Extract and return specific step output
    }

    Step 5: Update Actions That Need Previous Step Data

    Review and update actions that depend on variables.steps[stepSlug].output:

    • Update them to use the new getStepOutput() helper
    • Or pass specific required outputs in action config parameters

    Step 6: Preserve Full Steps for Persistence

    The steps map with full outputs should still be persisted (via storage serialization) for:

    • Workflow UI display
    • Debugging
    • Step output references

    Only the action arguments should be trimmed.


    Files to Modify

    File Changes
    convex/workflow/helpers/step_execution/execute_step_by_type.ts Add buildMinimalStepsMap(), update buildVariablesForAction() to trim steps
    convex/workflow/helpers/step_execution/build_steps_map.ts Add minimal steps map builder
    convex/workflow/helpers/serialization/serialize_step_output.ts New: Step output serialization helper
    convex/workflow/helpers/step_execution/get_step_output.ts New: On-demand step output fetcher
    convex/workflow/helpers/step_execution/persist_execution_result.ts Integrate step output storage
    convex/workflow/actions/* Review for variables.steps dependencies

    Potential Risks

    Risk Mitigation
    Breaking actions that access variables.steps directly Audit all action files before implementation
    Performance impact from additional queries Only actions needing step outputs will fetch them
    Backwards compatibility with running workflows Add fallback logic for both formats
    Storage growth from separate step outputs Clean up after workflow completion

    Testing Strategy

    1. Unit Tests

      • Test serializeStepOutput correctly stores and references large outputs
      • Test buildVariablesForAction produces arguments under 16 MiB
      • Test getStepOutput retrieves correct data
    2. Integration Tests

      • Run workflow with 10+ steps producing large outputs
      • Verify no argument size errors
      • Verify step outputs accessible when needed
      • Verify workflow UI still shows step outputs
    3. Edge Cases

      • Very large single step output (>16 MiB)
      • Deeply nested loops with many iterations
      • Actions referencing multiple previous steps

    🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions