Skip to content

Conversation

@dmmulroy
Copy link

@dmmulroy dmmulroy commented Jan 2, 2026

Summary

Adds workflow rollback/saga support:

  • TypeScript types: RollbackHandler<T>, RollbackStepConfig, withRollback method, TerminateOptions, rollingBack status
  • Python SDK: step.with_rollback() decorator with undo=, depends=, concurrent= support

Note: Depends on internal gitlab workflows!750 which adds the underlying engine support.

TypeScript Types (types/defines/)

// rpc.d.ts
export type RollbackHandler<T> = {
  do: () => Promise<T>;
  undo: (err: unknown, value: T) => Promise<void>;
};

export type RollbackStepConfig = WorkflowStepConfig & {
  undoConfig?: WorkflowStepConfig;
};

// Added to WorkflowStep class:
withRollback<T>(name: string, handler: RollbackHandler<T>, config?: RollbackStepConfig): Promise<T>;

// workflows.d.ts - InstanceStatus.status now includes 'rollingBack'
// WorkflowInstance.terminate(options?: TerminateOptions)

Python SDK (src/pyodide/)

# Pattern A: Chained decorator
@step.with_rollback("create order")
async def create_order():
    return await db.insert(...)

@create_order.undo
async def _(err, order):
    await db.delete(order["id"])

# Pattern B: undo= parameter
@step.with_rollback("charge", undo=refund_handler, depends=[create_order])
async def charge_payment():
    return await stripe.charge(...)

API: step.with_rollback(name, *, undo=None, depends=None, concurrent=False, config=None, undo_config=None)

  • Undo handler required (raises ValueError if missing)
  • Supports DAG dependencies via depends= and concurrent=

Changed Files

  • types/defines/rpc.d.ts - rollback types
  • types/defines/workflows.d.ts - TerminateOptions, rollingBack status
  • src/pyodide/internal/workers-api/src/workers/_workers.py - RollbackStep class
  • src/pyodide/internal/workers-api/src/workers/__init__.py - exports
  • src/workerd/server/tests/python/workflow-rollback/ - tests

Snapshot Regeneration Needed

Type snapshots need regeneration (just generate-types segfaults on macOS).


Note

This PR consolidates #5809 (Python SDK) and was written with AI assistance.

@dmmulroy dmmulroy requested a review from a team as a code owner January 2, 2026 02:01
@dmmulroy dmmulroy marked this pull request as draft January 2, 2026 02:15
@anonrig
Copy link
Member

anonrig commented Jan 2, 2026

Can you run "just generate-types" and push the changes files?

@dmmulroy dmmulroy force-pushed the dillon/workflow-rollback-types branch from a52b78a to b0f5322 Compare January 9, 2026 23:12
@dmmulroy dmmulroy changed the title feat: add workflow rollback types (withRollback, rollbackAll) feat: workflow rollback types + Python SDK (withRollback, saga pattern) Jan 9, 2026
@codspeed-hq
Copy link

codspeed-hq bot commented Jan 9, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing dmmulroy:dillon/workflow-rollback-types (dbc23bb) with main (1d41f31)

Summary

✅ 129 untouched benchmarks
⏩ 49 skipped benchmarks1

Footnotes

  1. 49 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@dmmulroy
Copy link
Author

@anonrig I keep getting a segfaul trying to run just generate-types 😅 any chance you could pull/push that for me until i figure out what's going on? (will try in docker this weekend if i get time)

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.

2 participants