fix(agent): Refresh egress token and retry on sandbox git auth failure#1426
Open
srtab wants to merge 1 commit into
Open
fix(agent): Refresh egress token and retry on sandbox git auth failure#1426srtab wants to merge 1 commit into
srtab wants to merge 1 commit into
Conversation
The sandbox's in-git operations authenticate via an egress-proxy token minted at turn start with a fixed ~1h TTL (GitHub installation tokens). On a turn that outlives the TTL — e.g. a dependency bump that runs the test suite repeatedly — the turn-end publish push was rejected with a 401 and the agent's work was lost (Sentry DAIV-1V). When an in-sandbox remote git op (ls-remote/push/fetch) is auth-rejected, GitManager now invokes an injected callback that re-mints the platform token onto the live session and retries the op once. Bounded to one refresh per manager and scoped to remote ops on a non-zero exit, so it never loops or masks a real permission failure. GitLab (3-day tokens) and local mode are unaffected.
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
Sentry DAIV-1V (
GitPushPermissionError): in sandbox-mode runs, in-git operations authenticate via a git-platform token that the egress proxy injects. That token is minted once at turn start with a fixed ~1h TTL (GitHub installation tokens). The publish push runs at turn end, so a turn that runs longer than the TTL — e.g. a dependency-bump task that runs the test suite repeatedly — fails to push with a 401 (could not read Username), and the agent's work is lost.The existing
_arefresh_egressonly refreshes at turn start (on session reuse), which never covered a single turn outliving its own token. Local mode is immune (it fetches a fresh credential per publish); GitLab is immune (clone tokens live 3 days). This is GitHub-specific.Fix
Reactive refresh-and-retry, wired sandbox-mode only:
GitManagergains anon_auth_failurecallback. A new_run_sandbox()chokepoint (used by both single commands and batches) invokes it and retries once when an in-sandbox remote git op (ls-remote/push/fetch/pull) is rejected with an auth marker.GitChangePublisher._refresh_sandbox_egress()is the callback: it re-mints the platform token and delivers it to the live session viaSandboxFileBackend.refresh_egress()→update_egress.sandbox_envs.services.refresh_platform_egress()swaps only the platform secret value (no duplicate egress rule), and returns the config unchanged when the re-mint yields the same token (GitLab's day-cached case) so the one-shot retry isn't wasted.The retry is deliberately narrow: scoped to remote ops (a local
diffmentioning "permission denied" won't trigger it), gated on a non-zero exit, and bounded to one refresh per manager spanning thels-remote → pushsequence — so it never loops or masks a genuine permission failure. A distinct warning is logged when an op is still auth-rejected after a real refresh (→ branch protection / token scope, not expiry).Why retry over a longer TTL
GitHub installation-token lifetime isn't configurable, and a longer-lived write token injected into every sandbox request is a security regression. Refreshing at the failing op decouples credential freshness from turn duration for a turn of any length.
Testing
refresh_platform_egressunit tests: token swap without duplicate rule, no-op onNone/ token-less / identical-token.automation/agent,sandbox_envs,core/sandbox);make lintclean;make lint-typingintroduces no new errors.