From e049b398ef6e08c2fb78988f0e00a6d88b641f06 Mon Sep 17 00:00:00 2001 From: Andrew Halberstadt Date: Wed, 7 Oct 2026 16:24:21 -0400 Subject: [PATCH] fix: ensure 'github-issue-comment' tasks use PR cache namespaces --- src/taskgraph/util/cached_tasks.py | 16 ++++++++++++---- test/test_util_cached_tasks.py | 15 +++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/taskgraph/util/cached_tasks.py b/src/taskgraph/util/cached_tasks.py index 5c050745b..525ba880f 100644 --- a/src/taskgraph/util/cached_tasks.py +++ b/src/taskgraph/util/cached_tasks.py @@ -63,9 +63,14 @@ def add_optimization( # Pull requests use a different target cache index route. This way we can # be confident they won't be used by anything other than the pull request # that created the cache in the first place. - if config.params["tasks_for"] == "github-pull-request" and config.graph_config[ - "taskgraph" - ].get("cache-pull-requests", True): + # + # Comments on a pull request run against the PR's head, so they use the + # same cache namespace as the PR itself. + tasks_for = config.params["tasks_for"] + if tasks_for in ( + "github-pull-request", + "github-issue-comment", + ) and config.graph_config["taskgraph"].get("cache-pull-requests", True): subs["head_ref"] = config.params["head_ref"] if subs["head_ref"].startswith("refs/heads/"): subs["head_ref"] = subs["head_ref"][11:] @@ -76,7 +81,10 @@ def add_optimization( # ... and cache at the lowest level. subs["level"] = config.params["level"] - if config.params["tasks_for"].startswith("github-pull-request"): + if ( + tasks_for.startswith("github-pull-request") + or tasks_for == "github-issue-comment" + ): if config.graph_config["taskgraph"].get("cache-pull-requests", True): taskdesc.setdefault("routes", []).append( f"index.{TARGET_PR_CACHE_INDEX.format(**subs)}" diff --git a/test/test_util_cached_tasks.py b/test/test_util_cached_tasks.py index 3ab2fa67f..a07a56d1c 100644 --- a/test/test_util_cached_tasks.py +++ b/test/test_util_cached_tasks.py @@ -107,6 +107,10 @@ def assert_pull_request_nocache(task): } +def assert_issue_comment(task): + assert_pull_request(task) + + @pytest.mark.parametrize( "extra_params,extra_graph_config,digest,digest_data", ( @@ -176,6 +180,17 @@ def assert_pull_request_nocache(task): None, id="pull_request_nocache", ), + pytest.param( + # extra_params + {"tasks_for": "github-issue-comment"}, + # extra_graph_config + None, + # digest + "abc", + # digest_data + None, + id="issue_comment", + ), ), ) def test_add_optimization(