Skip to content

fix: use repo default branch instead of hardcoded 'main' in agent mode#1083

Open
CervEdin wants to merge 1 commit intoanthropics:mainfrom
CervEdin:fix/restore-config-default-branch
Open

fix: use repo default branch instead of hardcoded 'main' in agent mode#1083
CervEdin wants to merge 1 commit intoanthropics:mainfrom
CervEdin:fix/restore-config-default-branch

Conversation

@CervEdin
Copy link

`restoreConfigFromBase` (added in v1.0.74 via #1066) fetches config
files from the PR base branch as a security measure. In agent mode,
`baseBranch` falls back to `"main"` when neither `BASE_BRANCH` nor
the action's `baseBranch` input is set. On repos whose default branch
is `master` (or anything else), this causes `git fetch origin main`
to fail, which aborts the entire run.

Read the repo's actual default branch from the event payload
(`repository.default_branch`) instead of assuming `"main"`. The
payload includes this field on every event type GitHub fires.

Fixes #1080

restoreConfigFromBase (added in v1.0.74) fetches config files from the
PR base branch as a security measure. In agent mode, baseBranch falls
back to "main" when neither BASE_BRANCH nor the action's baseBranch
input is set. On repos whose default branch is "master" (or anything
else), this causes `git fetch origin main` to fail, which aborts the
entire run.

Read the repo's actual default branch from the event payload
(repository.default_branch) instead of assuming "main". The payload
includes this field on every event type GitHub fires.

Fixes anthropics#1080

Signed-off-by: Erik Cervin-Edin <erik.cervin-edin@einride.tech>
@CervEdin
Copy link
Author

NGL, I feel like there should be some credit compensation or whatever when I need to use CC to fix anthropics bugs 🤷

@CervEdin
Copy link
Author

CervEdin commented Mar 19, 2026

Note that this may not be a complete fix, as noted in #1080

Affected locations

File Line(s) Code
src/modes/agent/index.ts ~89, ~96 process.env.BASE_BRANCH || context.inputs.baseBranch || "main"
src/entrypoints/run.ts ~315 baseBranch || "main"
src/entrypoints/update-comment-link.ts ~256 process.env.BASE_BRANCH || "main"

Expected behavior

When base_branch is not provided, the action should detect the repository's actual default branch instead of assuming "main".

other locations might need similar handling

ping @ashwin-ant I think this regression might be related to your changes in 7057f33

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.

restoreConfigFromBase fails on repos with non-"main" default branch

1 participant