Skip to content

Fix: Update git remote URL with current PAT on agent restart #208

Closed

Description

@vybe

Problem

When an agent restarts and its workspace volume already has a .git directory, startup.sh skips cloning and runs git fetch. However, the git remote URL still has the old PAT embedded from the original clone:

# startup.sh line 88 (only runs on first clone)
git remote set-url origin "https://oauth2:${GITHUB_PAT}@github.com/${GITHUB_REPO}.git"

On restart (line 16-27), the remote URL in .git/config is never updated, so git operations use the stale PAT even if the Docker env var has been updated.

Solution

In the "repo already exists" branch of startup.sh (line 16-27), update the remote URL with the current GITHUB_PAT env var before fetching:

if [ -d "/home/developer/.git" ]; then
    # Update remote URL with current PAT (may have changed since last start)
    if [ -n "${GITHUB_PAT}" ]; then
        git remote set-url origin "https://oauth2:${GITHUB_PAT}@github.com/${GITHUB_REPO}.git"
    fi
    git fetch origin 2>&1 || echo "Note: Could not fetch from remote"
fi

Files

  • docker/base-image/startup.sh (lines 16-27)

Acceptance Criteria

  • On agent restart, git remote URL is updated with current GITHUB_PAT env var
  • Git fetch/pull/push operations use the updated PAT
  • No regression when GITHUB_PAT is empty or unset
  • Base image rebuild required after change
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority-p1type-bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions