PrefectHQ
prefect
BlogDocsChangelog

Fix `TASK_SOURCE` cache policy for remote execution with `cloudpickle`

#19926Merged
Comparing
fix/task-source-cache-policy-cloudpickle
(
84cd604
) with
main
(
7d73faa
)
CodSpeed Performance Gauge
-23%
Regressions
1
(
1
)
Untouched
1
Ignored
6

Benchmarks

Passed

bench_import_prefect_flow
benches/bench_import.py
CodSpeed Performance Gauge
0%
1.4 s1.4 s
bench_task_decorator
benches/bench_tasks.py
Regression
CodSpeed Performance Gauge
-23%
463.3 µs601.1 µs

Ignored

bench_task_call
benches/bench_tasks.py
Ignored
CodSpeed Performance Gauge
+4%
33.2 ms31.9 ms
bench_import_prefect
benches/bench_import.py
Ignored
CodSpeed Performance Gauge
0%
1.1 s1.1 s
bench_flow_call[options1]
benches/bench_flows.py
Ignored
CodSpeed Performance Gauge
+1%
107.7 ms106.9 ms
bench_task_submit
benches/bench_tasks.py
Ignored
CodSpeed Performance Gauge
-56%
8.4 ms19 ms
bench_flow_decorator
benches/bench_flows.py
Ignored
CodSpeed Performance Gauge
-7%
5.2 ms5.6 ms
bench_flow_call[options0]
benches/bench_flows.py
Ignored
CodSpeed Performance Gauge
0%
170.5 ms170.3 ms

Commits

Click on a commit to change the comparison range
Base
main
7d73faa
-23.14%
Fix TASK_SOURCE cache policy for remote execution with cloudpickle This PR fixes an issue where the `TASK_SOURCE` cache policy fails when used with remote execution decorators like `@ecs` that use cloudpickle to ship code to remote environments. The problem: `inspect.getsource()` fails on cloudpickled functions because the original source file doesn't exist on the remote machine. The previous fallback to hashing `__code__.co_code` (bytecode) led to inconsistent cache keys because bytecode varies across Python versions and the code object contains unstable attributes like `co_locals` that change between serialization/deserialization cycles. The solution: Store the function's source code on the `Task` object during initialization so it survives cloudpickle serialization. The `TaskSource.compute_key()` method now checks for this stored source code first before falling back to `inspect.getsource()`. This ensures stable, deterministic cache keys regardless of execution environment. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
02c13aa
10 hours ago
by desertaxle
+0.22%
Clean up
84cd604
8 hours ago
by desertaxle
© 2025 CodSpeed Technology
Home Terms Privacy Docs