Skip to content

bug: platform GitHub PAT not used as fallback when deploying agent from private GitHub template #735

Closed

Description

@vybe

Summary

When deploying an agent from a private GitHub repository template, Trinity fails with a PAT authentication error if no per-agent GitHub PAT is configured. Trinity should fall back to the platform-level GitHub PAT (set via `PUT /api/settings/api-keys/github`) for the template clone step, but it does not — the deploy fails instead of using the available platform credential.

Component

Backend / Agent Deploy / Git Template Clone

Priority

P2 — feature impaired, workaround available (set a per-agent PAT or configure the platform PAT before deploying)

Error

Error: GitHub PAT is not valid or does not have access to the repository

Observed during agent deploy from a private GitHub template when no per-agent PAT is set.

Root Cause

The agent deploy flow (template clone from github:ORG/REPO) checks for a per-agent GitHub PAT but does not fall back to the platform PAT when none is configured for the (not-yet-created) agent. The platform PAT stored via PUT /api/settings/api-keys/github is available in the backend but is not injected into the template clone operation.

Evidence: GITHUB_PAT env var is present in the backend container environment (confirming the field is wired up in compose) but can be empty if not set in .env. When empty, there is no fallback to the DB-stored platform PAT set via the API endpoint.

Reproduction Steps

  1. Stand up a Trinity instance without GITHUB_PAT set in the instance .env
  2. Optionally set a platform PAT via PUT /api/settings/api-keys/github (DB-stored path)
  3. In the Trinity UI or via MCP, create a new agent using a private GitHub repo as the template (e.g. github:ORG/private-repo)
  4. Observe: deploy fails with PAT authentication error
  5. Expected: Trinity uses the platform PAT (env var or DB-stored) to authenticate the template clone

Expected Behaviour

The fallback chain for GitHub authentication during agent deploy should be:

  1. Per-agent PAT (from agent_git_config.github_pat_encrypted) — if the agent already exists
  2. Platform PAT (from GITHUB_PAT env var or DB-stored via settings API)
  3. Unauthenticated (public repos only)

Currently step 2 is skipped, causing private repo deploys to fail when no per-agent PAT exists.

Suggested Fix

In the agent template clone / deploy code path, after checking for a per-agent PAT, fall back to the platform PAT:

# Pseudocode — in the template fetch / git clone helper
pat = get_agent_pat(agent_name)  # per-agent encrypted PAT
if not pat:
    pat = settings.github_pat    # platform PAT (env var or DB)

clone_url = inject_pat_into_url(template_repo_url, pat) if pat else template_repo_url

The same fallback logic should apply consistently to: template clone at deploy time, git sync operations, and any other GitHub API calls made on behalf of an agent.

Environment

  • Trinity version: f7450cab
  • Docker version: 29.3.0
  • OS: Ubuntu 22.04

Related

  • PUT /api/settings/api-keys/github — platform PAT storage endpoint
  • PUT /api/agents/{name}/github-pat — per-agent PAT endpoint
  • agent_git_config.github_pat_encrypted — per-agent PAT in DB
  • GET /api/agents/{name}/github-pat response includes has_global: true field, suggesting the platform PAT concept is already modelled — but not used in deploy path

Activity

  1. vybe commented on May 8, 2026

    @vybe
    ContributorAuthor

    /claim

  2. added
    status-in-progress
    on May 8, 2026
  3. github-actions commented on May 8, 2026

    @github-actions

    Claimed by @vybe. Label status-in-progress added.

    Next steps:

    1. Create branch: feature/735-<short-slug>
    2. Implement the feature
    3. Open a PR with Fixes #735
  4. added
    status-in-dev
    and removed
    status-in-progress
    on May 8, 2026
  5. vybe commented on May 10, 2026

    @vybe
    ContributorAuthor

    Fixed in PR #739 (3c00d76 on dev). Per-agent PAT fallback now applied in github_sync, helpers, and lifecycle; platform-level PAT used when agent-specific one is absent.

  6. reopened this on May 10, 2026
  7. vybe commented on Jun 1, 2026

    @vybe
    ContributorAuthor

    Shipped in v0.6.0 (released via #998).

  8. removed
    status-in-dev
    on Jun 1, 2026
  9. added a commit that references this issue on Jun 12, 2026
  10. added 4 commits that reference this issue on Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

priority-p2type-bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions