fix: clear stale claude-prompts dir before each write#1288
Open
kyungilpark wants to merge 1 commit intoanthropics:mainfrom
Open
fix: clear stale claude-prompts dir before each write#1288kyungilpark wants to merge 1 commit intoanthropics:mainfrom
kyungilpark wants to merge 1 commit intoanthropics:mainfrom
Conversation
Previously, prompt files at `${RUNNER_TEMP}/claude-prompts/` from a prior
invocation could persist on non-ephemeral self-hosted runners (where the
documented `RUNNER_TEMP` cleanup contract is not reliably honored). In
particular, `claude-user-request.txt` is only written by `create-prompt`
when a user request exists; an `agent`-mode invocation does not overwrite
it, so a stale value left by an earlier mention-mode job in another repo
would leak into a later agent-mode job's effective context on the same
runner agent.
Fix: `rm -rf` the directory before `mkdir` in both write sites
(`src/create-prompt/index.ts`, `src/modes/agent/index.ts`). Idempotent,
safe on hosted runners (where the dir is already empty), and self-heals
on self-hosted runners.
Closes anthropics#1287
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1287.
Problem
${RUNNER_TEMP}/claude-prompts/is shared across jobs on non-ephemeral self-hosted runners — the documentedRUNNER_TEMPcleanup contract is not honored there. In particular,claude-user-request.txtis only written bycreate-promptwhen a user request exists; inagentmode it is left untouched, so a stale value left by an earlier mention-mode job in repo A leaks into a later agent-mode job in repo B running on the same runner agent.We observed this happen on ~40% of
agent-mode review jobs landing on an affected runner agent over a 5-day window — every affected review surfaced an unrelated stale question from a much-earlier mention-mode job in another repo.Issue #1287 has the full reproducer, evidence, and root-cause analysis.
Fix
Add
await rm(dir, { recursive: true, force: true })before eachawait mkdir(...)in both write sites:src/create-prompt/index.ts(tag/comment mode — writesclaude-prompt.txtandclaude-user-request.txt)src/modes/agent/index.ts(agent mode — writesclaude-prompt.txt)Each invocation now starts with a guaranteed-clean directory.
Side effect: extracted the shared path into a
promptDirlocal in both files, eliminating four duplicated\${process.env.RUNNER_TEMP || "/tmp"}/claude-promptsliterals.Why this approach
Considered alternatives (per #1287):
${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}-${GITHUB_JOB}.Cleaner isolation but requires changes at every consumer (
src/entrypoints/run.ts:269reads${RUNNER_TEMP}/claude-prompts/claude-prompt.txt), bigger blast radius.claude-user-request.txt(sentinel). Fixes the specific leak but leaves the general cross-job staleness intact for any future file added to the directory.Option 2 is the smallest, least invasive change and self-heals on every invocation.
Tests
The fs writes here are not covered by existing tests (
test/create-prompt.test.ts,test/modes/agent.test.tsneither mock nor exercise the mkdir/writeFile path). I did not add new tests to keep the patch focused; happy to add an integration-style test that:claude-user-request.txtinRUNNER_TEMP/claude-prompts/createPromptwith a context that does not produce a user request— if reviewers want it.
Verification
Manual reproducer from #1287 was used to confirm the leak exists on v1.0.67. After applying this patch in a downstream wrapping composite (mirroring the same
rm-then-mkdirshape via shell), the leak no longer manifests.