Skip to content

feat(github): agent containers fetch a repo-scoped git token at use time (abilityai/trinity-enterprise#1278) - #4653

Open
obasilakis wants to merge 3 commits into
devfrom
feature/ent1278-agent-token-fetch
Open

obasilakis wants to merge 3 commits into
devfrom
feature/ent1278-agent-token-fetch

Conversation

@obasilakis

Copy link
Copy Markdown
Contributor

Summary

Implements the open-core half of abilityai/trinity-enterprise#1278, on top of the repo-token seam from #4624.

When a registered repo-token provider covers an agent's repo, the agent's container starts with TRINITY_GIT_TOKEN_BROKER=1 and no baked GITHUB_PAT, GH_TOKEN or GITHUB_TOKEN. It fetches a short-lived, repo-scoped token from the backend on each git or gh operation. With no provider registered, nothing changes.

Changes

  • Mode decision (services/github_token_provider.py): coverage(repo) answers True, False, or None when the provider cannot answer within 5 seconds. wants_broker(...) is shared by agent creation, the recreate matcher and the recreate env writer.
    • The flag stands only where the platform PAT would have been baked.
    • A per-agent PAT outranks the provider.
    • A container created without a credential stays without one.
    • Unknown coverage keeps the mode a container already has.
  • Token route GET /api/agents/{name}/git/token: the agent's own key only. 200 with a provider token for a broker-mode container, 204 otherwise, 503 when the mint failed or the container cannot be read. It never returns a PAT. Added to the own-runtime route allowlist so ephemeral agents and agents owned by Workspace-only people can reach it.
  • Credential helper (git-credential-trinity.sh and its backend mirror): with the flag set it asks the route first, sending the key to curl on stdin. 204 continues to the PAT sources. Any other failure yields no credential and skips them.
  • gh wrapper (/usr/local/bin/gh): in broker mode it gets a token through the helper on every gh call.
  • startup.sh: the flag counts as a resolving credential without a network call, and GitHub token lines are removed from the workspace .env in broker mode.
  • PAT rotation skips broker containers. The harvest file refuses ghs_ tokens.

Difference from the issue text

The issue describes a GH_TOKEN fetch at spawn in execution_env.py and plugins_reinstall.py, with a documented limit that a turn longer than one hour holds an expired token. The gh wrapper replaces both: the token is fetched per gh call, so that limit does not exist. Those two files are unchanged.

Known limits

  • If GitHub is unreachable while an agent is created or a missing container is rebuilt, the PAT is baked and the container converts at its next start.
  • Broker mode applies only where a platform PAT exists. Installs with a provider and no PAT are left to abilityai/trinity-enterprise#1279.
  • A converted agent's token covers one repo. Private plugin marketplaces, submodules in other repos and gh calls against other repos lose the access the platform PAT gave them.
  • Coverage is looked up once by the matcher and once by the env writer during a start.

Testing

  • tests/unit/test_ent1278_git_token_broker.py runs the real helper script, gh wrapper and startup.sh blocks against a local HTTP server, and covers the mode decision, the matcher, the route and the rotation skip.
  • tests/unit/test_ent109_git_env_seam.py::TestBrokerMode covers the env writer.
  • Fifteen mutations (PAT fallback on failure, route ignoring the flag, route returning a PAT, a person allowed in, route off the allowlist, Docker fault read as 204, stale .env lines kept, and others) each turn a named test red.
  • Local run: the 337 tests in the touched and neighbouring files pass. The full unit suite was not completed locally and runs here in CI.

Private half (integration test against the real provider, feature-flow doc): branch feature/1278-agent-token-fetch in the enterprise repo.

🤖 Generated with Claude Code

obasilakis and others added 3 commits November 19, 2026 12:17
…ime (Abilityai/trinity-enterprise#1278)

When a registered repo-token provider covers an agent's repo, the agent's
container is started with TRINITY_GIT_TOKEN_BROKER=1 and no baked GITHUB_PAT,
GH_TOKEN or GITHUB_TOKEN. With no provider registered nothing changes.

- github_token_provider: coverage() answers True, False or None (the provider
  could not answer within 5 seconds). wants_broker() is the one mode decision
  shared by agent creation, the recreate matcher and the recreate env writer.
  The flag stands only where the platform PAT would have been baked; a
  per-agent PAT outranks the provider; unknown coverage keeps the mode a
  container has.
- GET /api/agents/{name}/git/token: the agent's own key only. 200 with a
  provider token for a broker-mode container, 204 otherwise, 503 when the
  mint failed or the container cannot be read. Never returns a PAT. Added to
  the own-runtime route allowlist.
- git-credential-trinity (and its backend mirror): with the flag set, asks the
  route first, key on stdin. 204 continues to the PAT sources; any other
  failure yields no credential and skips them.
- gh wrapper at /usr/local/bin/gh: fetches a token through the helper on every
  gh call in broker mode. This replaces the spawn-time GH_TOKEN fetch the
  issue described, so a turn longer than an hour never holds an expired token.
- startup.sh: the flag counts as a resolving credential without a network
  call, and stale GitHub token lines are removed from the workspace .env.
- PAT rotation skips broker containers; the harvest file refuses ghs_ tokens.

Tests: tests/unit/test_ent1278_git_token_broker.py runs the real helper,
wrapper and startup.sh blocks against a local HTTP server. Fifteen mutations
each turn a named test red.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…token-fetch

# Conflicts:
#	tests/registry.json
…Abilityai/trinity-enterprise#1278)

Declares the route's tier as "self" in agent_route_tiers.json, gives the
self-gate identity test a request for it, and spells the agents-only refusal
the way the other agent-only routes do, so the hand-copied self-gate guard
recognises it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

⚠️ Nightly unit-suite check skipped — merge conflict against dev.

Resolve by running git merge dev locally and pushing the result. The next nightly run will re-test once the conflict is gone.

@github-actions

Copy link
Copy Markdown

⚠️ Live-instance suite skipped — merge conflict against dev.

Resolve by merging dev locally and pushing the result; the next nightly re-tests.

This branch has not been deployed

No deployments
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.

1 participant