Skip to content

Commit 6bd6951

Browse files
fix(review): stop attempting a cache save a comment run cannot make (#86)
GitHub hands a run triggered by issue_comment a read-only cache token. The save is refused with "cache write denied: token has no writable scopes", which the cache action reports as "Unable to reserve cache with key ..., another job may be creating this cache" followed by "Cache save failed". Nothing is wrong, but every /codeboarding run ended with two warnings that read like a broken action, and the real reason was buried. Confirmed by running the same job both ways in this repository: identical permissions and action version, a pull_request run saves, a comment run is denied. Reads are unaffected either way, and a comment run restores sync's shared base entry normally. So the saves are skipped for that event, and the documentation stops claiming /codeboarding publishes a shared entry. Two consequences are written down instead: a repository reviewed only through the command never builds a chain, and /codeboarding refresh improves the comment it posts rather than what later runs start from. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 2546d08 commit 6bd6951

4 files changed

Lines changed: 35 additions & 8 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Each review seeds the head analysis from this pull request's own previous run, s
7171

7272
Caching is best-effort: a cache miss, an unavailable cache service, or a GitHub Enterprise Server without one falls back to analyzing the merge base directly, exactly as before.
7373

74-
Actions cache entries are scoped to the ref that wrote them. Automatic `pull_request` runs therefore reuse each other's analysis and the shared base entry, while a `/codeboarding` command — which runs on the default branch ref — reuses the base entry but not a chain built by automatic runs, so it costs one base-seeded incremental. The action also accepts `pull_request_target`, which runs on the base branch ref and lets both share one chain; that trigger has its own trade-offs (a PR that adds this workflow will not run it until merged, and the fork gate becomes load-bearing), so `pull_request` remains the recommended default.
74+
Actions cache entries are scoped to the ref that wrote them, and GitHub gives comment-triggered runs a read-only cache token. So automatic `pull_request` runs reuse each other's analysis and build the chain, `sync` publishes the base entry everyone shares, and a `/codeboarding` command reads both but writes neither — it costs one base-seeded incremental, and `/codeboarding refresh` improves the comment it posts rather than what later runs start from. The action also accepts `pull_request_target`, which runs on the base branch ref and lets both share one chain; that trigger has its own trade-offs (a PR that adds this workflow will not run it until merged, and the fork gate becomes load-bearing), so `pull_request` remains the recommended default.
7575

7676
## Authentication and providers
7777

‎action.yml‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,13 @@ runs:
324324

325325
# Saved before the review is rendered: the analysis is the expensive part, so
326326
# a later rendering or posting failure must not throw it away.
327+
#
328+
# Skipped for issue_comment, where GitHub hands the run a read-only cache
329+
# token: the save is refused with "token has no writable scopes" and the
330+
# cache action reports it as a failure, so attempting it only prints a
331+
# warning that suggests something is broken. Reads still work there.
327332
- name: Save pull request analysis
328-
if: steps.guard.outputs.skip != 'true' && steps.guard.outputs.mode == 'review' && steps.cache_keys.outputs.chain_key != ''
333+
if: steps.guard.outputs.skip != 'true' && steps.guard.outputs.mode == 'review' && github.event_name != 'issue_comment' && steps.cache_keys.outputs.chain_key != ''
329334
continue-on-error: true
330335
uses: actions/cache/save@v4
331336
with:
@@ -335,7 +340,7 @@ runs:
335340
# Only trusted runs publish a base entry: it is restorable repository-wide,
336341
# so a fork's run must never be able to place state there.
337342
- name: Save base analysis
338-
if: steps.guard.outputs.skip != 'true' && steps.guard.outputs.mode == 'review' && steps.review_analyze.outputs.save_base == 'true' && steps.guard.outputs.is_fork != 'true' && steps.cache_keys.outputs.base_key != ''
343+
if: steps.guard.outputs.skip != 'true' && steps.guard.outputs.mode == 'review' && github.event_name != 'issue_comment' && steps.review_analyze.outputs.save_base == 'true' && steps.guard.outputs.is_fork != 'true' && steps.cache_keys.outputs.base_key != ''
339344
continue-on-error: true
340345
uses: actions/cache/save@v4
341346
with:

‎docs/COMMIT_STRATEGY.md‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,20 @@ cache entry is only visible to the ref that wrote it and to the default branch:
6868
commit it analyzed and the baseline commit it creates, because a pull request
6969
branched just before that baseline landed has the earlier commit as its merge
7070
base.
71-
- **`/codeboarding`**, which runs on the default branch, also writes a shared
72-
entry.
7371
- **an automatic `pull_request` run** writes into `refs/pull/<n>/merge`, so its
7472
entry serves only later runs of that same pull request. Another pull request
7573
with the identical merge base still computes its own.
76-
77-
So review runs warm themselves, and sync is what warms everybody.
74+
- **`/codeboarding` writes nothing.** GitHub gives a comment-triggered run a
75+
read-only cache token, so a save is refused with "token has no writable
76+
scopes" no matter what the workflow grants. Reads work normally: a slash
77+
command restores sync's shared base entry like anything else.
78+
79+
So sync warms everybody, pull request runs warm themselves, and slash commands
80+
only consume. Two consequences follow. A repository reviewed exclusively through
81+
`/codeboarding` never builds a chain, so every command re-derives the head from
82+
the base. And `/codeboarding refresh` cannot persist what it recomputes: it
83+
fixes the comment it posts, while the next run still restores the analysis it
84+
was asked to replace.
7885

7986
**Head**
8087

‎tests/test_action_cache.py‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ def _cache_steps(self) -> list[dict[str, str]]:
416416
steps.append(current)
417417
elif current is not None:
418418
stripped = line.strip()
419-
for field in ("uses", "path", "key", "restore-keys"):
419+
for field in ("uses", "path", "key", "restore-keys", "if"):
420420
if stripped.startswith(f"{field}:"):
421421
current[field] = stripped.split(":", 1)[1].strip()
422422
return [step for step in steps if step.get("uses", "").startswith("actions/cache/")]
@@ -434,6 +434,21 @@ def test_the_chain_is_restored_by_prefix_so_a_refresh_survives(self) -> None:
434434
# base's own analysis, a prefix hit is only a warm seed.
435435
self.assertNotEqual(base["key"], base["restore-keys"])
436436

437+
def test_reviews_do_not_attempt_a_save_a_comment_run_cannot_make(self) -> None:
438+
# GitHub hands an issue_comment run a read-only cache token, so the save
439+
# is refused with "token has no writable scopes" and surfaces as a
440+
# warning that reads like a broken action. Reads are unaffected.
441+
for step in self._cache_steps():
442+
if not step["uses"].startswith("actions/cache/save"):
443+
continue
444+
if "review" not in step.get("if", ""):
445+
continue
446+
self.assertIn(
447+
"github.event_name != 'issue_comment'",
448+
step.get("if", ""),
449+
f"{step['name']} would attempt a save that a comment-triggered run cannot make",
450+
)
451+
437452
def test_every_saved_path_is_a_restored_path(self) -> None:
438453
steps = self._cache_steps()
439454
self.assertTrue(steps, "no cache steps found in action.yml")

0 commit comments

Comments
 (0)