Skip to content

Publish the github_token output as soon as the token is set up - #2116

Open
0xABCD01 wants to merge 1 commit into
anthropics:mainfrom
0xABCD01:fix/2111-cancel-token-revoke
Open

0xABCD01 wants to merge 1 commit into
anthropics:mainfrom
0xABCD01:fix/2111-cancel-token-revoke

Conversation

@0xABCD01

Copy link
Copy Markdown

Summary

Publishes the github_token output as soon as the token is set up in src/entrypoints/run.ts, instead of only in the finally block.

The "Revoke app token" step keys off steps.run.outputs.github_token. When a run was cancelled, the runner signalled the step's bash rather than Bun, Bun kept running past the end of the step, and the finally block — whose last statement was the only setOutput("github_token", …) on the session path — never ran. The output stayed empty, the revoke step was skipped, and the app token stayed valid.

core.setOutput appends to $GITHUB_OUTPUT synchronously, so writing the token right after setupGitHubToken() succeeds puts it on disk before anything later can be interrupted. The finally block still sets it again, so it remains the last value written on every path that completes — including over anything the session itself wrote to $GITHUB_OUTPUT during the run.

This is fix direction (1) from #2111. It is a one-call move in one file, plus tests.

Fixes the token-revocation half of #2111.

Not covered

  • Stopping the session itself on cancel (fix direction (2) in Cancelled run leaves Bun/Claude running and skips 'Revoke app token' (github_token output only set in finally) #2111: exec, signal handling, process-tree cleanup). This PR does not stop Claude or its MCP servers from running past a cancel; it only makes sure the token output exists so the token gets revoked.
  • On a cancelled run, a session that deliberately appends a bogus github_token entry to $GITHUB_OUTPUT could shadow the early value (the runner takes the last value for a repeated key). Every path that completes is covered by the finally re-write.

Disclosure

PR #2112 by @mhegazy already works on this issue and takes the other direction: both actions start Bun with exec, a SIGINT/SIGTERM handler stops the process tree, restores files, and writes the outputs. It covers more of the issue than this PR does. If the maintainers prefer #2112, closing this PR is the right call — I'm opening it because the early output is a smaller, independently useful change, not because it supersedes #2112.

Test plan

  • New test/github-token-output.test.ts, following the subprocess pattern of test/agent-mode-moderation.test.ts: it runs the real entrypoint against a local fake GitHub API with a real $GITHUB_OUTPUT file, leaves the first API call after token setup unanswered (the process is alive mid-run and can never reach its finally, the local shape of an orphaned cancelled run), then SIGKILLs it.
    • On main: the test fails — the output file stays empty for the full 10 s poll, because the token output only exists in the unreachable finally.
    • With this change: the output is on disk in under a second and survives the SIGKILL; a run that completes still ends with the minted token as the last github_token value.
  • bun test: 1484 pass, 0 fail. tsc --noEmit and prettier --check clean.
  • Not tried: an end-to-end cancel on a live GitHub Actions runner. The local test proves the mechanism (synchronous output write at setup time, durable across a hard kill before finally); the runner-side behaviour it relies on — outputs of a cancelled step being read by the always() revoke step — is the same mechanism the finally write already depended on.

The "Revoke app token" step keys off steps.run.outputs.github_token,
but run.ts only set that output in its finally block. A cancelled run
can leave Bun running past the end of its step without ever reaching
the finally, so the output was never written, revocation was skipped,
and the app token stayed valid.

setOutput appends to $GITHUB_OUTPUT synchronously, so publishing the
token right after setupGitHubToken() succeeds puts it on disk before
anything later can be interrupted. The finally block still sets it
again, keeping it the last value written on paths that complete.

Fixes part of anthropics#2111 (the token-output half; stopping the session on
cancel is not covered here).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants