Repository navigation
Description
Summary
Rotating the global GitHub PAT in Settings does not reach running agents. The #211 auto-propagation reports success while updating nothing, and even on its success path it never repairs git authentication. Agents that use the global PAT keep authenticating with the revoked token — git fetch/push and the gh CLI all fail — until each container is manually restarted. Nothing in the UI signals this, so the rotation looks clean.
Observed on a fleet where a rotation left every global-PAT agent authenticating with a token that returns HTTP 401, for as long as the containers stayed up (11–13 days).
Component
Backend / Settings + GitHub PAT propagation (github_pat_propagation_service)
Priority
P1 — the documented purpose of #211 ("agents pick up the new token without a restart") is non-functional in the common configuration, and the failure is silent.
Error
No exception is raised. The endpoint returns a success payload in which nothing was updated:
{
"success": true,
"masked": "ghp_...[REDACTED]",
"propagation": {
"total_running": 12,
"updated": [],
"skipped": [
{"agent_name": "[AGENT]", "status": "skipped_no_pat"},
{"agent_name": "[AGENT]", "status": "skipped_per_agent_pat"}
],
"failed": []
}
}Downstream symptom inside an affected agent:
remote: Invalid username or token. Password authentication is not supported for Git operations.
fatal: Authentication failed for 'https://github.com/[ORG]/[REPO].git/'
Location
- File:
src/backend/services/github_pat_propagation_service.py - Functions:
propagate_github_pat(),_propagate_to_agent(),_apply_pat_to_env() - Caller:
src/backend/routers/settings.py:712(update_github_pat)
Root Cause
Three independent gaps, the first two of which each fully defeat the rotation.
1. The global path requires a pre-existing .env that most agents never have.
_propagate_to_agent() calls _apply_pat_to_env(..., add_if_missing=False). That returns skipped_no_pat when /home/developer/.env is absent, or present but without a GITHUB_PAT line:
if env_content is None:
if not add_if_missing:
return "skipped_no_pat"
elif not _env_has_github_pat(env_content) and not add_if_missing:
return "skipped_no_pat"Agents provisioned from a GitHub template ship a .env.example and no .env, so every such agent skips. The per-agent path (propagate_pat_to_single_agent, #1264) passes add_if_missing=True and does not have this problem — the asymmetry appears unintentional.
2. The global path never re-templates the git remote.
Clones are created as https://oauth2:<PAT>@github.com/<org>/<repo>.git, and that URL is persisted in .git/config on the agent's workspace volume. Git authenticates from the URL, not from GITHUB_PAT. propagate_github_pat() only rewrites .env; it never calls git_service.update_remote_pat().
The service's own docstring for the per-agent path states this explicitly:
The live git process authenticates from the remote URL (not the env var), so
remote_updatedis the load-bearing part of the immediate fix; the.envwrite only takes effect on the next restart.
So even if gap #1 were fixed, a global rotation still would not restore git access until a restart. Only propagate_pat_to_single_agent() calls update_remote_pat().
3. The propagation result is never surfaced.
update_github_pat returns a populated propagation object, but no caller displays it. A rotation in which 100% of agents were skipped is visually identical to one that succeeded.
Secondary observation
An agent whose per-agent PAT happens to hold a stale copy of the old global token is skipped as skipped_per_agent_pat on every future rotation, and its dead token is re-injected on every recreate. There is no signal that a stored per-agent PAT has been revoked. Worth considering a validity check or a "stale per-agent PAT" warning.
Note on the existing convergence path
check_github_pat_env_matches() (services/agent_service/helpers.py:549) does force a container recreate on the next start when the baked GITHUB_PAT env differs from the effective PAT, and docker/base-image/startup.sh then unconditionally runs git remote set-url origin with the fresh token. That path is correct — it just only runs on a cold start, so long-lived agents are the exposure window. The hot-propagation in #211 exists precisely to close that window, and currently does not.
Reproduction Steps
- Create an agent from a GitHub template so it is cloned over HTTPS with the global PAT embedded in the remote URL. Confirm the agent has no
/home/developer/.env(only.env.example). - Leave the agent running.
- In Settings, replace the global GitHub PAT with a different valid token.
- Inspect the API response —
propagation.updatedis empty, all agents reportskipped_no_pat. - In the container,
printenv GITHUB_PATandgit remote get-url originboth still contain the old token. - Revoke the old token; any
git fetch/pushorghcall from the agent now fails, with no indication in the UI.
Suggested Fix
a. Do not require a pre-existing .env on the global path. Either pass add_if_missing=True, or gate on "the agent has a git config" rather than "the agent already has a GITHUB_PAT line":
status = await _apply_pat_to_env(
client, agent_name, base_url, new_pat, add_if_missing=True
)b. Re-template the live remote on the global path too, mirroring propagate_pat_to_single_agent:
git_config = db.get_git_config(agent_name)
if git_config and git_config.github_repo:
await git_service.update_remote_pat(
agent_name, new_pat, git_config.github_repo
)Factoring the shared ".env write + remote rewrite" body out of propagate_pat_to_single_agent and reusing it for both paths would remove the asymmetry at its source.
c. Surface the propagation result in the Settings UI — at minimum a warning when updated is empty while total_running > 0, and a per-agent breakdown of skipped/failed.
Environment
- Trinity version:
9f766d11 - Database backend: PostgreSQL
- OS: Ubuntu 22.04
Related
src/backend/services/github_pat_propagation_service.py(feat: Auto-propagate GitHub PAT to all agents on update #211, bug: per-agent GitHub PAT (#347) never propagates to an existing container — git remote keeps an empty password, all pushes fail #1264, Wire the agent GitHub PAT for theghCLI + REST API (not just git) #1574)src/backend/routers/settings.py—update_github_patsrc/backend/routers/git.py—set_agent_github_pat/clear_agent_github_patsrc/backend/services/agent_service/helpers.py:549—check_github_pat_env_matchesdocker/base-image/startup.sh— remote re-templating on cold start
Activity
dolho commentedon Aug 4, 2026
/claim — picking this up. Branch:
fix/1967-global-pat-propagation, offdev.github-actions commentedon Aug 4, 2026
@dolho This issue is already assigned to dolho. Use
/unclaimfirst if you want to take over.dolho commentedon Aug 4, 2026
PR: #1979
Two notes on scope:
dev—Settings.vuerenders the full updated/failed/skipped breakdown with per-agent reasons. This issue was filed against9f766d11. One residual remained and is fixed in the PR:0 of N appliedrendered success-green whenever nothing outright failed, so a rotation that reached nothing looked identical to one that worked.add_if_missing=Trueunconditionally. It would inject the global token into every running container including agents that never touched GitHub — the module's own docstring says the original gate existed to prevent exactly that. Used the alternative this issue also offers (gate on the git config), which targets precisely the skipped population while leaving non-GitHub agents alone. Details and the before/after table are in the PR.The secondary observation (a per-agent PAT holding a stale copy of the old global token, skipped forever and re-injected on every recreate) is not addressed here — detecting it needs a validity probe against the GitHub API per agent, which brings network calls, rate limits and a new failure mode into a rotation path. That is a separate feature; worth its own issue rather than being folded in silently.
fix(github-pat): make a global PAT rotation actually reach running ag…
fix(github-pat): level every GITHUB_PAT line, not just the first (#2016…
fix(tests): re-point five stale mocks at the seams they claim to stub (…
feat(git): a credential helper git speaks to over stdin, not argv
docs(git): requirements, architecture and flows for credential-free r…
docs(git): correct the three comments whose premise this issue inverts
docs(learnings): two classes this issue surfaced, for the next plan t…
fix(git): the fleet PAT stops being readable inside every agent conta…