From 1e35159abdb6629308c58cca4dbd65785000675b Mon Sep 17 00:00:00 2001 From: Andrew Halberstadt Date: Wed, 14 Oct 2026 14:57:16 -0400 Subject: [PATCH] fix(cached_tasks): add worker-type to digest When a task runs on a different worker-type, the underlying environment could be completely different. Or not. It could be a simple instance type change that has no impact on the task's artifact, or it could be a different OS, a different cloud provider or even a different worker binary. Therefore it's best to include the worker-type in the cached task digest. --- src/taskgraph/transforms/cached_tasks.py | 5 +++ test/test_transforms_cached_tasks.py | 43 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/taskgraph/transforms/cached_tasks.py b/src/taskgraph/transforms/cached_tasks.py index d6668d06d..86d580e91 100644 --- a/src/taskgraph/transforms/cached_tasks.py +++ b/src/taskgraph/transforms/cached_tasks.py @@ -75,6 +75,11 @@ def cache_task(config, tasks): if task.get("worker", {}).get("chain-of-trust"): digest_data.append(str(task["worker"]["chain-of-trust"])) + # The worker type can affect the environment the task runs in (e.g + # platform or architecture), so it should influence the cache digest. + if task.get("worker-type"): + digest_data.append(task["worker-type"]) + add_optimization( config, task, diff --git a/test/test_transforms_cached_tasks.py b/test/test_transforms_cached_tasks.py index c69112a5b..3dcaa6c4b 100644 --- a/test/test_transforms_cached_tasks.py +++ b/test/test_transforms_cached_tasks.py @@ -105,6 +105,13 @@ def assert_chain_of_trust_influences_digest(tasks): assert digest_0 != digest_1 +def assert_worker_type_influences_digest(tasks): + assert len(tasks) == 3 + tasks = sorted(tasks, key=lambda t: t["label"]) # no-wt, wt-a, wt-b + digests = [t["attributes"]["cached_task"]["digest"] for t in tasks] + assert len(set(digests)) == 3 + + @pytest.mark.parametrize( "tasks, kind_config, deps", ( @@ -233,6 +240,42 @@ def assert_chain_of_trust_influences_digest(tasks): {}, id="chain_of_trust_influences_digest", ), + pytest.param( + # tasks + [ + { + "cache": { + "type": "cached-task.v2", + "name": "cache-foo", + "digest-data": ["abc"], + }, + "label": "no-wt", + }, + { + "cache": { + "type": "cached-task.v2", + "name": "cache-foo", + "digest-data": ["abc"], + }, + "label": "wt-a", + "worker-type": "a", + }, + { + "cache": { + "type": "cached-task.v2", + "name": "cache-foo", + "digest-data": ["abc"], + }, + "label": "wt-b", + "worker-type": "b", + }, + ], + # kind config + {}, + # kind deps + {}, + id="worker_type_influences_digest", + ), ), ) def test_transforms(