-
Notifications
You must be signed in to change notification settings - Fork 272
Description
What happens
get_current_branch.cjs runs git rev-parse --abbrev-ref HEAD via execSync without suppressing stderr. When called in a context where the working directory isn't a git repository (or the .git directory is inaccessible), git prints fatal: not a git repository (or any of the parent directories): .git to stderr before the function catches the error and falls back to GITHUB_REF_NAME.
The fallback works correctly — the function returns the right branch name. But the stderr output leaks into the Actions log, adding confusing noise to failure reports.
This function is called in the failure reporting path (handle_agent_failure.cjs:742), so the stderr noise appears specifically in runs that are already failing — the worst time to add confusing log output.
What should happen
The execSync call should suppress stderr so that the fallback is silent. The function already has a try/catch; the issue is purely that stderr is inherited from the parent process rather than piped.
Where in the code
All references are to main at 99b2107.
The leaky call:
get_current_branch.cjs:18-23:Noconst branch = execSync("git rev-parse --abbrev-ref HEAD", { encoding: "utf8", cwd: cwd, }).trim();
stdiooption — defaults to"pipe"for stdout but inherits stderr from the parent process.
Call site in failure path:
handle_agent_failure.cjs:18—const { getCurrentBranch } = require("./get_current_branch.cjs");handle_agent_failure.cjs:742—const currentBranch = getCurrentBranch();
Evidence
Local reproduction:
- Set
GITHUB_WORKSPACE=/tmpandGITHUB_REF_NAME=main - Ran the function — stderr printed
fatal: not a git repository (or any of the parent directories): .git - Return value was correctly
main(fromGITHUB_REF_NAMEfallback)
Source-level verification (2026-03-03):
- Confirmed
execSyncat line 19 has nostdioconfiguration - Node.js
execSyncdefaults: stdout is"pipe"(captured), stderr is inherited (printed to console) - The try/catch at lines 18/24 catches the thrown error but stderr has already been written
Proposed fix
Add stdio: ["pipe", "pipe", "pipe"] (or stdio: "pipe") to the execSync options:
const branch = execSync("git rev-parse --abbrev-ref HEAD", {
encoding: "utf8",
cwd: cwd,
stdio: ["pipe", "pipe", "pipe"],
}).trim();This suppresses stderr while still capturing stdout. The existing try/catch handles the error path.
Impact
Frequency: Every failure-path invocation where GITHUB_WORKSPACE doesn't point to a valid git repository.
Cost: Low — purely cosmetic noise, but it appears in failure logs where clarity matters most. One-line fix.