Repository navigation
fix(repositories): clone every branch and authenticate gh in sessions - #372
Merged
Merged
Conversation
A session checkout was a --depth=1 single-branch clone, so `git branch -r` listed only the source branch and no agent could find or diff work already in flight on another branch without re-deriving a refspec and an unshallow by hand. Workflows that pick up an existing feature branch reported "no match" and failed. The clone is now blobless instead: every branch and the full commit history at about a shallow clone's size, with skipped blobs fetched on demand through the credential helper. Azure and anonymous public clones keep their shallow clone. Since #309 no token sits in the remote URL, which was the only place gh and REST calls found one, so `gh pr list`, `gh pr create` and the merges API stopped working in every session. A gh wrapper ahead of the real one on PATH now asks the same credential helper per call for the repository the call targets, and hands the token to that gh process only. The clone exec also gets an explicit timeout: the Kubernetes exec default of 30 s is shorter than a large repository takes to clone. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Artem Petrov <[email protected]>
Azure DevOps Services has served blobless partial clones since November 2023, and the platform only talks to the cloud service (api_host), never to an on-prem Azure DevOps Server that might not. So Azure checkouts get every branch and the full history on the same terms as GitHub and GitLab, with skipped blobs fetched through the existing Azure credential helper. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Artem Petrov <[email protected]>
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.
Problem
Agent sessions could not see branches or reach the GitHub API, and workflows built on "find the branch already in flight" failed on it. Seen on project 28, run 21276: branch discovery reported "no unmerged branches" and "GitHub PRs could not be checked due to missing credentials" and failed the step. The page it was looking for lived on
feature/offerings-factory, committed 17 minutes earlier.Two separate causes:
git clone --depth=1 --branch=<source>.--depthimplies--single-branch, so the refspec tracks only the source branch.git fetch --allnever brings in another branch, andgit branch -r --no-mergedis always empty. This has been the case since February, not since fix!: security and reliability improvements #309. A run that happened to rewrite the refspec by hand found the branch, and one that didn't failed.ghand REST.gh pr list,gh pr createandPOST /mergeshave failed in every session since the 2026-09-25 deploy, althoughdocs/user-guide/integrations.mdstill says an agent opens PRs "withghor the API".Change
--filter=blob:noneinstead of--depth=1). This brings every branch and the full commit history. Blobs of other revisions are fetched on demand through each provider's existing credential helper, which is already configured in the checkout. A full clone was ruled out because it is too heavy for large repositories at session start. Anonymous public clones keep--depth=1.api_host), not to on-prem Server. I checked this against a public Azure repo: the filter is honoured (blobs are missing after the clone), andgit log -pfetches them lazily.ghwrapper (docker/base/git/gh-aixle, installed at runtime as/usr/local/bin/gh, ahead of/usr/bin/gh). Per call, it asksgit credential fillin the matching checkout for a token for the call's repository and passes it asGH_TOKENto that oneghprocess. The repository comes from-R/--repo,GH_REPO, agh api repos/<owner>/<repo>path, the checkout the call runs in, or the only GitHub checkout. Nothing goes into the env,.git/configor disk, so fix!: security and reliability improvements #309's guarantee holds. A caller-setGH_TOKENpasses straight through. It is best effort: if the wrapper cannot be written, the clone still succeeds.kubernetes_runtime.rb), and the old clone ran under it implicitly.ghauthenticates per call.Measured
Local clone of the 107 MB repository from the incident:
.git--depth=1(before)--filter=blob:none(after)On the blobless clone,
git branch -r --no-merged,git diff --name-only main...<branch>andgit merge-baseneed no network. Checking out another branch made one credential-helper call, andgit log -p -5made two.Verification
git_credentials/,azure_devops/,context_builders/resources_test,session_context_service_test,refresh_github_token_test) ran in an isolated container: 209 runs, 0 failures. rubocop and brakeman are clean, and shellcheck is clean on both scripts.gh_wrapper_test.rbruns the script itself against real bash and git, with checkouts configured the waySessionGitSetupconfigures them.Not covered
🤖 Generated with Claude Code