Skip to content
Skills Library
Programming · Building & coding

output-error-nondeterminism

/output-error-nondeterminism

Fix non-determinism errors in Output SDK workflows. Use when seeing replay failures, inconsistent results between runs, "non-deterministic" error messages, or workflows behaving differently on retry.

Repository
output ↗
Licence
Apache-2.0
Last repository change
26.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 26.10.2026, without references to retired models or APIs.

Licence

Apache-2.0, otwarta: można używać i zmieniać, z zachowaniem licencji i informacji o zmianach.

What it does and when to use it

Fix non-determinism errors in Output SDK workflows. Use when seeing replay failures, inconsistent results between runs, "non-deterministic" error messages, or workflows behaving differently on retry.

Triggers from the description

non-deterministic
Original author description

Fix non-determinism errors in Output SDK workflows. Use when seeing replay failures, inconsistent results between runs, "non-deterministic" error messages, or workflows behaving differently on retry.

How it works

  1. Overview
  2. When to Use This Skill
  3. Root Cause
  4. Common Causes and Solutions
  5. How to Find Non-Deterministic Code
  6. Verification Steps
  7. The Determinism Rule
  8. Debugging Tip
  9. Related Issues
Original SKILL.md headings · 248 lines, 928 words
SKILL.md preview
---
name: output-error-nondeterminism
description: Fix non-determinism errors in Output SDK workflows. Use when seeing replay failures, inconsistent results between runs, "non-deterministic" error messages, or workflows behaving differently on retry.
allowed-tools: [Bash, Read]
---

# Fix Non-Determinism Errors

## Overview

This skill helps diagnose and fix non-determinism errors in Output SDK workflows. Workflows must be deterministic because Temporal may replay them during recovery or retries, and the replay must produce identical results.

## When to Use This Skill

You're seeing:
- "non-deterministic" error messages
- Replay failures after workflow restart
- Inconsistent results between runs with same input
- Errors during workflow recovery
- Warnings about determinism violations

## Root Cause

Temporal workflows must be deterministic: given the same input, they must always execute the same sequence of operations. This is because Temporal replays workflow history to recover state after crashes or restarts.

Non-deterministic operations break this replay mechanism because they produce different values each time.

## Common Causes and Solutions

### 1. Math.random()

**Problem**: Random values differ on each execution.

```typescript
// WRONG: Non-deterministic
export default workflow( {
  fn: async input => {
    const id = Math.random().toString( 36 );  // Different each time!
    return await processWithId( { id } );
  }
} );
```

**Solution**: Pass random values as workflow input or generate in a step.

```typescript
// Option 1: Pass as input
export default workflow( {
  inputSchema: z.object( {
    id: z.string()  // Generate ID before calling workflow
  } ),
  fn: async input => {
    return await processWithId( { id: input.id } );
  }
} );

// Option 2: Generate in a step (steps can be non-deterministic)
export const generateId = step( {
  name: 'generateId',
  fn: async () => ( { id: Math.random().toString( 36 ) } )
} );

export default workflow( {
  fn: async input => {
    const { id } = await generateId( {} );
    return await processWithId( { id } );
  }
} );
```

### 2. Date.now() / new Date()

**Problem**: Timestamps change between executions.

```typescript
// WRONG: Non-deterministic
export default workflow( {
  fn: async input => {
    const timestamp = Date.now();  // Different each replay!
    return await logEvent( { timestamp } );
  }
} );
```

**Solution**: Pass timestamps as input or use Temporal's time API.

```typescript
// Option 1: Pass as input
export default workflow( {
  inputSchema: z.object( {
    timestamp: z.number()
  } ),
  fn: async input => {
    return await logEvent( { timestamp: input.timestamp } );
  }
} );

// Option 2: Generate in a step
export const getTimestamp = step( {
  name: 'getTimestamp',
  fn: async () => ( { timestamp: Date.now() } )
} );
```

### 3. crypto.randomUUID()

**Problem**: UUIDs differ each execution.

```typescript
// WRONG: Non-deterministic
import { randomUUID } from 'crypto';

export default workflow( {
  fn: async input => {
    const requestId = randomUUID();  // Different each time!
    return await makeRequest( { requestId } );
  }
} );
```

**Solution**: Generate UUIDs as input or in steps.

```typescript
// Correct: Generate in step
export const generateRequestId = step( {
  name: 'generateRequestId',
  fn: async () => {
    const { randomUUID } = await import( 'crypto' );
    return { requestId: randomUUID() };
  }
} );
```

### 4. Dynamic Imports

**Problem**: Dynamic imports may resolve differently.

```typescript
// WRONG: Non-deterministic import timing
export default workflow( {
  fn: async input => {
    const module = await import( `./handlers/${input.type}` );
    return module.handle( input );
  }
} );
```

**Solution**: Use static imports and conditional logic.

```typescript
// Correct: Static imports with conditional use
import { handleTypeA } from './handlers/typeA';
import { handleTypeB } from './handlers/typeB';

export default workflow( {
  fn: async input => {
    if ( input.type === 'A' ) {
      return await handleTypeA( input );
    } else {
      return await handleTypeB( input );
    }
  }
} );
```

### 5. Environment Variables

**Problem**: Environment may differ between replays.

```typescript
// WRONG: Environment can change
export default workflow( {
  fn: async input => {
    const apiUrl = process.env.API_URL;  // May differ on different workers
    return await callApi( { url: apiUrl } );
  }
} );
```

**Solution**: Pass configuration as input or use constants.

```typescript
// Correct: Pass as input
export default workflow( {
  inputSchema: z.object( {
    apiUrl: z.string()
  } ),
  fn: async input => {
    return await callApi( { url: input.apiUrl } );
  }
} );
```

## How to Find Non-Deterministic Code

### Search for Common Patterns

```bash
# Find Math.random usage
grep -rn "Math.random" src/workflows/

# Find Date.now or new Date
grep -rn "Date.now\|new Date" src/workflows/

# Find crypto random functions
grep -rn "randomUUID\|randomBytes" src/workflows/

# Find dynamic imports
grep -rn "import(" src/workflows/
```

### Review Workflow Files

Look at your workflow `fn` functions specifically. Non-deterministic code is only a problem **in workflow functions**, not in step functions.

## Verification Steps

1. **Fix the code** using solutions above
2. **Run the workflow**: `npx output workflow run <name> --input '<input>'`
3. **Run again with same input**: Result should be identical
4. **Check for errors**: No "non-deterministic" messages

## The Determinism Rule

**Workflow functions must be deterministic:**
- Same input = same execution path
- No side effects (network, filesystem, random values)
- Only orchestration logic and step calls

**Step functions can be non-deterministic:**
- Steps record their results in Temporal history
- Replays use recorded results, not re-execution
- All I/O should happen in steps

## Debugging Tip

If unsure whether code is causing issues:

```bash
# Run the workflow
npx output workflow start my-workflow --input '{"input": "test"}'

# Get the workflow ID and run debug to see replay behavior
npx output workflow debug <workflowId> --json
```

Look for errors or warnings about non-determinism in the trace.

## Related Issues

- For I/O in workflow code, see `output-error-direct-io`
- For random values needed in logic, generate them in steps or pass as input

Versions

The database has no other skills named output-error-nondeterminism.

Database snapshot: 13.11.2026 · package version 943be17f1054 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100output-error-zod-import
    Fix Zod schema import issues in Output SDK workflows. Use when seeing "incompatible schema" errors, type errors at step boundaries, schema validation failures, or when schemas don't match between steps.
  • 100output-error-missing-schemas
    Fix missing schema definitions in Output SDK steps. Use when seeing type errors, undefined properties at step boundaries, validation failures, or when step inputs/outputs aren't being properly typed.
  • 90review-workflow-determinism
    Read-only audit of existing Dapr Workflow code for non-determinism that breaks replay, with DWF-DET-NNN findings. Use for "review workflow for determinism" or "audit Dapr workflow replay safety". For guidance while writing a workflow body use the catalyst-ai plugin.
  • 100replay-buffer
    Experience replay for tool/test/build failures. Invoke IMMEDIATELY when any tool fails (non-zero exit, FAIL/error/panic in output). Looks up known fixes before debugging, records failures and fixes, promotes successful fixes. Triggers on: test failures, build errors, lint…
  • 100flaky-test
    Use when the same test alternates between pass and fail without code edits, or when a failure cannot be reproduced. Rerun to confirm, find the source of nondeterminism, and never revert working code on an unconfirmed flake.
  • 100anima-common-errors
    Diagnose and fix common Anima SDK design-to-code errors. Use when encountering Figma token errors, code generation failures, node not found issues, or output quality problems. Trigger with: "anima error", "anima not working", "anima debug", "figma to code error".

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.