Skip to content

Support step context from Python Workflows SDK#5634

Merged
Caio-Nogueira merged 1 commit into
mainfrom
caio/WOR-1049
Jan 22, 2026
Merged

Support step context from Python Workflows SDK#5634
Caio-Nogueira merged 1 commit into
mainfrom
caio/WOR-1049

Conversation

@Caio-Nogueira

@Caio-Nogueira Caio-Nogueira commented Dec 3, 2025

Copy link
Copy Markdown
Contributor

We're adding support for context within step.do's callback. This means adding a new optional parameter to the decorated step method, in a way that doesn't break existing Python Workflows.

This solution introspects the signature of the callback and checks for the size of the parameters list given (without *args and **kwargs). If there are more arguments than resolved dependencies, then the context parameter is injected into the user workflow.

EDIT:

We're also making a bigger change in the sdk regarding dependency resolution. We're following pytest fixtures' approach with a name based approach for steps. This means that we implicitly resolve dependencies based on the param names. Since we're already introspecting the signature for each decorated step, this ensures a consistent approach for declarations. Everything is based on the param name, instead of relying on param positions like previously

Related types PR:

#5625

@Caio-Nogueira
Caio-Nogueira requested review from a team as code owners December 3, 2025 16:10
@Caio-Nogueira Caio-Nogueira self-assigned this Dec 3, 2025
@Caio-Nogueira
Caio-Nogueira force-pushed the caio/WOR-1049 branch 2 times, most recently from 9c12971 to 70cc713 Compare December 3, 2025 17:02
@Caio-Nogueira
Caio-Nogueira requested a review from dom96 December 3, 2025 17:10

@dom96 dom96 left a comment

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.

LGTM but should you maybe also add some tests which verify what's inside ctx?

@Caio-Nogueira
Caio-Nogueira force-pushed the caio/WOR-1049 branch 2 times, most recently from 02e449c to 183d2c0 Compare December 4, 2025 16:01
@Caio-Nogueira Caio-Nogueira changed the title Support step context from Python Workflows SDK (Do not merge yet) Support step context from Python Workflows SDK Dec 4, 2025
@hoodmane

hoodmane commented Dec 4, 2025

Copy link
Copy Markdown
Contributor

I think determining this positionally is likely to confuse people. How are people to remember whether context is at the end or at the beginning? What if we want to add one more argument like this?

I think it would be a good idea to shift to a design where we look at the argument names, like the way that fixtures work in pytest. So then you could do:

        @step.do(concurrent=False)
        async def step_3(step_1, step_2, context):
             ...

and it could look at the names of the arguments to determine what should go there. We could also get the name of the step from func.__name__ so that it isn't necessary to pass the step name unless people want it to be different from the name of the function.

@Caio-Nogueira

Caio-Nogueira commented Dec 4, 2025

Copy link
Copy Markdown
Contributor Author

I think determining this positionally is likely to confuse people. How are people to remember whether context is at the end or at the beginning? What if we want to add one more argument like this?

We needed one way of consistently determining where the context parameter is. That was my initial solution, but then there is the possibility of this somehow breaking existing workflows:

        @step.do(concurrent=False, depends=[context])
        async def step_3(context):
            return "done"

If we search the context param by name instead of by position, then we would possibly run into these name collision edge cases. This would probably need a compat flag.

I think it would be a good idea to shift to a design where we look at the argument names, like the way that fixtures work in pytest. So then you could do:

        @step.do(concurrent=False)
        async def step_3(step_1, step_2, context):
             ...

and it could look at the names of the arguments to determine what should go there. We could also get the name of the step from func.__name__ so that it isn't necessary to pass the step name unless people want it to be different from the name of the function.

Yes this is cleaner, but then how would users get the result of step_1 and step_2, since those are just callables? We also want to avoid encouraging nested steps.

@codspeed-hq

codspeed-hq Bot commented Dec 15, 2025

Copy link
Copy Markdown

CodSpeed Performance Report

Merging this PR will degrade performance by 11.43%

Comparing caio/WOR-1049 (e81187f) with main (f111a58)

Summary

⚡ 1 improved benchmark
❌ 1 regressed benchmark
✅ 68 untouched benchmarks
⏩ 129 skipped benchmarks1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
jsonResponse[Response] 42.6 µs 34.9 µs +22.2%
simpleStringBody[Response] 19.2 µs 21.7 µs -11.43%

Footnotes

  1. 129 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.

Comment thread src/pyodide/internal/metadata.ts Outdated
Comment thread src/pyodide/internal/workers-api/src/workers/_workers.py Outdated
Comment thread src/pyodide/internal/workers-api/src/workers/_workers.py Outdated
@Caio-Nogueira
Caio-Nogueira force-pushed the caio/WOR-1049 branch 6 times, most recently from 702c09e to bf6dfdc Compare January 8, 2026 11:15
@Caio-Nogueira
Caio-Nogueira requested a review from a team January 8, 2026 11:38
Comment thread src/pyodide/internal/workers-api/src/workers/_workers.py Outdated
Comment thread src/pyodide/internal/workers-api/src/workers/_workers.py Outdated
Comment thread src/pyodide/internal/workers-api/src/workers/_workers.py Outdated
@Caio-Nogueira
Caio-Nogueira force-pushed the caio/WOR-1049 branch 3 times, most recently from 6b2119d to b75fa73 Compare January 12, 2026 15:49
Comment thread src/pyodide/internal/workers-api/src/workers/_workers.py Outdated
Comment thread src/pyodide/internal/workers-api/src/workers/_workers.py Outdated
@Caio-Nogueira
Caio-Nogueira force-pushed the caio/WOR-1049 branch 4 times, most recently from 91b98c3 to 05bb2c8 Compare January 19, 2026 12:30
Comment thread src/pyodide/internal/workers-api/src/workers/_workers.py
Comment thread src/pyodide/internal/workers-api/src/workers/_workers.py Outdated
@Caio-Nogueira
Caio-Nogueira force-pushed the caio/WOR-1049 branch 2 times, most recently from 7b36a96 to f5b0102 Compare January 19, 2026 14:25
@pombosilva

Copy link
Copy Markdown
Contributor

Approved from the Workflows team 👍

@Caio-Nogueira Caio-Nogueira changed the title (Do not merge yet) Support step context from Python Workflows SDK Support step context from Python Workflows SDK Jan 19, 2026
@Caio-Nogueira
Caio-Nogueira merged commit 406a592 into main Jan 22, 2026
33 of 36 checks passed
@Caio-Nogueira
Caio-Nogueira deleted the caio/WOR-1049 branch January 22, 2026 11:08
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.

4 participants