Skip to content

docs(workflow): add deterministic execution requirement#81

Closed
Mistat wants to merge 1 commit into
mainfrom
docs/workflow-deterministic-execution
Closed

docs(workflow): add deterministic execution requirement#81
Mistat wants to merge 1 commit into
mainfrom
docs/workflow-deterministic-execution

Conversation

@Mistat

@Mistat Mistat commented Apr 9, 2026

Copy link
Copy Markdown

Summary

  • Document that .trigger() uses a suspend/resume execution model and job code must be deterministic
  • Add concrete examples of correct and incorrect usage patterns (loops, timestamps, external API calls)
  • Explain that non-deterministic arguments (e.g., Date.now(), external API responses) cause argument hash mismatch errors

Background

The Rust runtime (service/function/runtime/src/engine/ops/job.rs in platform-core-services) enforces deterministic execution by verifying arg_hash on resume. This critical constraint was not documented, risking users encountering unclear errors.

Test plan

  • Verify documentation builds and renders correctly
  • Confirm code examples are consistent with existing documentation style

🤖 Generated with Claude Code

Document the suspend/resume execution model and the requirement that
job code must be deterministic when using .trigger(). Include examples
of correct and incorrect usage patterns (loops, timestamps, external
API calls) to help users avoid argument hash mismatch errors.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Mistat
Mistat requested a review from a team as a code owner April 9, 2026 02:57
Comment on lines +135 to +146
```typescript
// ❌ Bad: non-deterministic — argument changes between executions
await processJob.trigger({ timestamp: Date.now() });
```

```typescript
// ❌ Bad: non-deterministic — external data may change between executions
const items = await fetch("https://api.example.com/items").then((r) => r.json());
for (const item of items) {
await processItem.trigger({ id: item.id });
}
```

@toiroakr toiroakr Apr 9, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it might be even better if there were examples of how to rewrite the "bad" examples.

// ❌ Bad: non-deterministic — argument changes between executions
await processJob.trigger({ timestamp: Date.now() });

// ✅ OK: call Date.now() in separated job
const timestamp = await timestampJob.trigger();
await processJob.trigger({ timestamp });
// ❌ Bad: non-deterministic — external data may change between executions
const items = await fetch("https://api.example.com/items").then((r) => r.json());
for (const item of items) {
  await processItem.trigger({ id: item.id });
}

// ✅ OK: call fetch("https://api.example.com/items").then((r) => r.json()); in separated job
const items = await fetchItemsJob.trigger();
for (const item of items) {
  await processItem.trigger({ id: item.id });
}

@anukiransolur

Copy link
Copy Markdown
Contributor

This change will be added in SDK repository 945

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants