Skip to content

Fix: Update GITHUB_PAT env var on container recreation #209

Closed

Description

@vybe

Problem

When an agent container is recreated (e.g., on restart when config changes are detected), recreate_container_with_updated_config in lifecycle.py copies env vars from the old container as-is:

# lifecycle.py line 257
env_vars = {e.split("=", 1)[0]: e.split("=", 1)[1] for e in old_config.get("Env", []) if "=" in e}

It then updates ANTHROPIC_API_KEY and CLAUDE_CODE_OAUTH_TOKEN (lines 268-281), but never updates GITHUB_PAT. The PAT remains frozen at the value from agent creation time.

Solution

  1. In recreate_container_with_updated_config, add logic to update GITHUB_PAT from the current system setting (after the API key update block at line ~281):
if env_vars.get('GITHUB_PAT'):
    from services.settings_service import get_github_pat
    current_pat = get_github_pat()
    if current_pat:
        env_vars['GITHUB_PAT'] = current_pat
  1. Add a check_github_pat_matches helper in helpers.py (similar to check_api_key_env_matches) that compares the container's GITHUB_PAT env var against the current system PAT.

  2. Add this check to the needs_recreation condition in start_agent_internal (line 191-195).

Files

  • src/backend/services/agent_service/lifecycle.py (lines 191-195, 257-281)
  • src/backend/services/agent_service/helpers.py (new helper function)

Acceptance Criteria

  • Container recreation updates GITHUB_PAT env var to current system value
  • Agent restart detects stale GITHUB_PAT and triggers container recreation
  • Agents without GITHUB_PAT (non-GitHub agents) are unaffected
  • Works in combination with startup.sh git remote URL update

Activity

  1. added
    priority-p1
    type-bug
    status-in-progress
    on Mar 27, 2026
  2. removed
    status-in-progress
    on Aug 7, 2026
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