Skip to content

Conversation

@dmmulroy
Copy link

@dmmulroy dmmulroy commented Jan 2, 2026

Summary

Adds TypeScript type definitions for the Workflows saga rollback API and terminate options.

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

Changed Files

  • types/defines/rpc.d.ts - added RollbackHandler<T>, RollbackStepConfig, RollbackAllOptions, and withRollback/rollbackAll methods
  • types/defines/workflows.d.ts - added rollingBack status, TerminateOptions, updated terminate() signature

Types Added

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

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

export type RollbackAllOptions = {
  continueOnError?: boolean;
};

// Added to WorkflowStep class:
withRollback<T>(name: string, handler: RollbackHandler<T>, config?: RollbackStepConfig): Promise<T>;
rollbackAll(error?: unknown, options?: RollbackAllOptions): Promise<void>;

// workflows.d.ts
type TerminateOptions = {
  rollback?: boolean;
};

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

Snapshot Regeneration Needed

The check-snapshot CI job fails because type snapshots need to be regenerated. Running just generate-types on macOS causes a segfault.

Could a maintainer with Linux access help regenerate the snapshots?


Note

This PR was written with AI assistance.

Add withRollback/rollbackAll for compensating transactions in Python.
@dmmulroy dmmulroy requested review from a team as code owners January 2, 2026 00:09
@dmmulroy dmmulroy marked this pull request as draft January 2, 2026 00:20
@codspeed-hq
Copy link

codspeed-hq bot commented Jan 2, 2026

Merging this PR will not alter performance

Summary

✅ 129 untouched benchmarks
⏩ 49 skipped benchmarks1


Comparing dmmulroy:dmmulroy/workflows-python-rollback-api (28aacc0) with main (613091c)

Open in CodSpeed

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.

@danlapid
Copy link
Collaborator

danlapid commented Jan 2, 2026

If this is a new feature then ideally we should add support for JS Workflows at the same time as Python Workflows.

though admittedly I don’t know if it is or not so feel free to educate me.

@Caio-Nogueira
Copy link
Contributor

Caio-Nogueira commented Jan 5, 2026

Seems like we're duplicating the engine logic for this feature. Would it be possible to call into withRollback and rollbackAll from the workflow engine and avoid leaking internals? Seems like a cleaner approach. Although we would probably need to figure out type translations between js errors and python exceptions...

…on-side undo stack

- Remove Python-side _UndoStackEntry and _undo_stack
- Add _withRollback_call() to wrap Python callbacks for JS engine
- Add continue_on_error parameter to rollback_all()
- Update tests for engine-delegated behavior and ExceptionGroup handling
@dmmulroy dmmulroy changed the title feat(python): add saga rollback API to Python Workflows SDK feat(types): add workflow rollback types (withRollback, rollbackAll, TerminateOptions) Jan 6, 2026
- Remove step.rollback_all() method (now handled by engine auto-rollback)
- Update with_rollback docstring to describe auto-rollback behavior
- Simplify tests to only test with_rollback decorator registration

Rollback is now triggered automatically by the engine when workflow
throws an uncaught error (if rollback config enabled at instance creation).
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