Repository navigation
Log text as plain text, and post buffered comments in the run step - #2122
Conversation
Text that the action logs, such as a prompt, a comment or a file name, could contain workflow commands. Console output now shows them as plain text, and git's output goes through console. The prompt input is no longer logged. Buffered inline comments are posted at the end of the run step instead of in a step of their own, so they aren't posted when a run is cancelled or times out. The issue triage recipe passes only the issue's number. Co-authored-by: mhegazy <mhegazy@anthropic.com>
|
|
||
| // Last, because the step that revokes the app token needs the outputs. This isn't a | ||
| // step of its own, so that only the run step is given the API key. | ||
| if (hadSession && context?.inputs.classifyInlineComments && githubToken) { |
There was a problem hiding this comment.
🟡 (optional) Reviews that hit timeout-minutes, are cancelled or crash mid-session now silently lose every buffered inline comment; the base branch still posted them. Posting moved into the finally block at src/entrypoints/run.ts:583, and the cancel handler leaves through process.exit(130) (base-action/src/cancel.ts:142) without reaching it. Nothing is logged about the dropped comments. Fix: keep the buffer recoverable whenever the run step does not reach its end, for example an always() step with no API key that posts the buffer unclassified when the run step did not post it.
Why this was flagged
Trigger: a pull request review with the default classify_inline_comments (true, src/github/context.ts:156) where Claude calls create_inline_comment without confirmed: true, so each comment is only appended to /tmp/inline-comments-buffer.jsonl (src/mcp/github-inline-comment-server.ts:111-124). The job then reaches timeout-minutes or is cancelled while runClaude is awaited (src/entrypoints/run.ts:488). onCancel runs its synchronous steps and calls process.exit(130) (base-action/src/cancel.ts:142), so run.ts:583-591 never runs. On the base branch the removed action.yml step Post buffered inline comments had if: always() && inputs.classify_inline_comments != 'false' and posted them after the cancel. The trade-off is documented (docs/security.md:148), but the dismissal's claim that no fix fits the purpose does not hold: the poster already has a keyless path that posts all unconfirmed comments (src/entrypoints/post-buffered-inline-comments.ts:51-56), so a fallback step needs only the GitHub token and the API key stays in the run step.
Verification: Trigger: a PR review with default classify_inline_comments is cancelled or hits timeout-minutes while runClaude is awaited. The only remaining post site is src/entrypoints/run.ts:583-591, inside the finally block. The cancel handler never reaches it. Base behaviour differed. Consequence: a review that times out now posts none of its inline comments, and nothing in the log says how many were dropped.
Finding ID: f-59503fea
| text | ||
| .replaceAll("##[", "##[\\") | ||
| // The runner skips spaces first. This skips all that isn't visible ASCII. | ||
| .replace(/^([^\x21-\x7e\r\n]*)::/gm, "$1\\::") |
There was a problem hiding this comment.
🟡 (optional) Logging text with a long run of U+2028 or U+2029 now stalls the run step for seconds to hours; the base branch logs it instantly. In escapeWorkflowCommands (base-action/src/log.ts:10) ^ with the m flag matches after each U+2028/U+2029, and the class [^\x21-\x7e\r\n] also consumes them, so every position rescans the rest of the run. Fix: keep the scan linear for every line terminator ^ honours, e.g. exclude from the class as \r\n already are; ^ still matches after them, so :: there stays escaped. Untrusted text reaches it at src/create-prompt/index.ts:1004 and src/github/operations/branch.ts:166.
Why this was flagged
An issue, PR or comment body of 65,536 U+2028 characters is fetched in tag mode. stripInvisibleCharacters (src/github/utils/sanitizer.ts:1-10) does not remove U+2028/U+2029, and createPrompt logs the whole prompt with console.log(promptContent) (src/create-prompt/index.ts:1004). The patched console (base-action/src/log.ts:19-26) runs /^([^\x21-\x7e\r\n]*)::/gm over it. At each of the N positions the group consumes the rest of the run, fails on :: and backtracks, about N*N steps: roughly 4e9 for one body, again for each comment. A commit subject has no size cap and reaches the same regex through execGit (src/github/operations/branch.ts:165-166) when git checkout prints Previous HEAD position was ...; a few million such characters keep the synchronous replace busy until the job times out, and the onCancel signal handler cannot run meanwhile. The base branch passed these strings to console.log or inherited stdio with no regex. No length cap guards the replace. Timing was not measured here; the step count follows from the pattern.
Verification: Triggers when a logged string contains a long unbroken run of U+2028/U+2029. base-action/src/log.ts:10 is .replace(/^([^\x21-\x7e\r\n]*)::/gm, "$1\\::"). src/github/utils/sanitizer.ts:2-8 strips U+202A-202E; U+2028/U+2029 survive. log.ts is a new file, so the base branch logs the same text with no regex pass.
Finding ID: f-2a1b5540
| // step of its own, so that only the run step is given the API key. | ||
| if (hadSession && context?.inputs.classifyInlineComments && githubToken) { | ||
| try { | ||
| await postBufferedInlineComments({ context, githubToken }); |
There was a problem hiding this comment.
🟡 (optional) A cancel or timeout that arrives after the session ends, while cleanup is posting, leaves a review with only some of its inline comments; the base branch posted all of them. Once isFinishing is true SIGINT is ignored (base-action/src/cancel.ts:131), and the SIGTERM 7.5 seconds later exits the process (cancel.ts:142). The block at src/entrypoints/run.ts:585 now also awaits a classification call with no timeout and one request per comment in sequence. Fix: bound posting to that window (fetch deadline, concurrent posts) or keep a fallback that posts what remains after the run step is stopped.
Why this was flagged
Trigger: the runner's cancel or timeout-minutes signal lands after runClaude has returned, while the finally block at src/entrypoints/run.ts:530-591 is running. isFinishing is true (run.ts:532), so the SIGINT is ignored (base-action/src/cancel.ts:131) and the SIGTERM about 7.5 seconds later runs process.exit(130) (cancel.ts:142). In that window the block must finish updateCommentLink (run.ts:548), the Haiku fetch that has no timeout (src/entrypoints/post-buffered-inline-comments.ts:63), pulls.get (:226) and a sequential createReviewComment per comment (:231-236). A review with a few dozen comments does not fit, so the pull request gets the first few and the rest are dropped with no log line. On the base branch posting was a separate always() step that ran in full after the run step was stopped. No safeguard applies: postComment catches per-comment errors, not process exit.
Verification: base-action/src/cancel.ts:131 ignores only SIGINT, so the runner's later SIGTERM still reaches process.exit(130) at cancel.ts:142. run.ts:583-585 now awaits postBufferedInlineComments inside that same finally. The base action.yml had a separate Post buffered inline comments step with if: always() && inputs.classify_inline_comments != 'false', which this diff deletes.
Finding ID: f-e29cc7ed
| let raw: string; | ||
| try { | ||
| raw = readFileSync(BUFFER_PATH, "utf8"); | ||
| raw = readFileSync(bufferPath, "utf8"); |
There was a problem hiding this comment.
🟣 pre-existing, not blocking: pre-existing: A second run of the action in the same job, or on a reused self-hosted runner, posts the earlier run's buffered inline comments again. postBufferedInlineComments reads /tmp/inline-comments-buffer.jsonl at post-buffered-inline-comments.ts:161 and never removes it. The MCP server only appends to that file. Fix: make each run see only its own buffered comments, for example delete the buffer before the session starts and after it is read, on every return path of the function.
A small fix can ride a push you are already making; otherwise a short reply is enough.
Why this was flagged
A job has two anthropics/claude-code-action steps on a pull request, or a non-ephemeral self-hosted runner handles two runs. src/mcp/github-inline-comment-server.ts:112 uses appendFileSync(BUFFER_PATH, ...) and nothing in the repo deletes /tmp/inline-comments-buffer.jsonl; clearSessionState (src/github/operations/session-guard.ts:353) only removes SESSION_STATE_FILES. The second run's call at src/entrypoints/run.ts:585 reads the whole file, so the first run's comments are classified and posted a second time, and on a reused runner comments written for another pull request are posted with commit_id set to this PR's head SHA. The base branch behaves the same way: the removed Post buffered inline comments step read the same file and did not delete it. No safeguard applies: the hadSession check at run.ts:583 only tells whether this run started a session, not which run wrote the lines.
Verification: pre-existing — triggers when a second run of the action shares /tmp with an earlier run that buffered unconfirmed inline comments. src/entrypoints/post-buffered-inline-comments.ts:161 raw = readFileSync(bufferPath, "utf8"); has no unlink/truncate on any return path. The base fails the same way by the same route.
Finding ID: f-530712a9
| async function git(...args: string[]): Promise<void> { | ||
| const result = await $`git ${args}`.quiet().nothrow(); | ||
| const output = `${result.stdout}${result.stderr}`.trim(); | ||
| if (output) console.log(output); |
There was a problem hiding this comment.
🟣 pre-existing, not blocking: CLAUDE.md says never to print tokens or environment variables in workflow logs: the new git() helper captures git's stdout and stderr and writes them to the log with console.log(output) unredacted, and its content is not bounded by this code (the push here uses an origin URL that can embed the GitHub token). The same bytes reached the log before via inherited stdio, so this is unchanged in substance, but the text is now in hand. Fix: pass captured git output through redactSecrets() before logging, which covers the 2 sites listed. Same instruction at 2 sites (src/github/operations/branch-cleanup.ts:10, src/github/operations/branch.ts:166).
A small fix can ride a push you are already making; otherwise a short reply is enough.
Why this was flagged
Nothing is known to fail at runtime today. The instruction guards against credentials reaching the job log. At this spot the logged value is raw git subprocess output (push, lfs push, commit, add in branch-cleanup.ts; fetch and checkout in branch.ts execGit), whose content the code cannot bound. It bites only if git (or a hook, LFS, or a trace setting such as GIT_TRACE/GIT_CURL_VERBOSE in the job env) emits a credential: configureGitAuth (src/github/operations/git-config.ts:149) sets origin to https://x-access-token:@ host/... on the default path, and checkAndCommitOrDeleteBranch pushes to that remote.
Verification: Instruction: root CLAUDE.md (base 4a461cb), last line of "Security hardening for GitHub Actions": "Keep each workflow's permissions: block minimal, and never print tokens or environment variables in workflow logs." It is there verbatim; the clause on logs names no file type, so I read it as reaching action code that writes to the job log, though the section around it is mostly about workflow YAML and a maintainer could read it more narrowly.
Finding ID: f-7c710aee
Human: @mhegazy
Requested by Mohamed · project thread
consoleis shown as plain text, also where it contains workflow commands. Git's output from checkouts and the auto-commit goes throughconsoletoo. The action's own annotations use@actions/coreand are unchanged.promptinput is no longer logged again before the run starts. The runner already shows it with the step's inputs.Tests: the full suite passes (1,525), with new tests for the log output, the git output, the buffered comments and
action.yml.Generated by Claude Code