Skip to content

PR operations fail on GitHub Enterprise Server repos #242

Description

@iamroddo

agentbox-ctl git pr create fails when the workspace repo is on a GitHub Enterprise Server instance. The relay spawns gh without GH_HOST set, so gh always targets github.com regardless of where the remote actually is.

Steps to reproduce

In a box whose remote is a GHES instance (e.g. https://github.example.com/org/repo):

agentbox-ctl git pr create --title "my PR" --body ""
# → error: gh not authenticated on host

Read-only ops (pr view, pr list) fail the same way.

Root cause

runHostGh in packages/relay/src/gh.ts spawns gh with env: process.env:

const child = spawn('gh', args, {
  cwd,
  env: process.env,   // relay's host env — GH_HOST never set here
  ...
});

The relay inherits the host's login environment where GH_HOST isn't set, so gh falls back to github.com. The assertGhReady auth check is already host-agnostic (no --hostname github.com flag, any authed host passes), so the gap is just that runHostGh never tells gh which host to use.

Suggested fix

Derive the hostname from the worktree's git remote and inject it as GH_HOST:

function ghHostFromCwd(cwd: string): string | null {
  try {
    const remote = execSync('git remote get-url origin', { cwd }).toString().trim();
    const match = remote.match(/^https?:\/\/([^/]+)/) ?? remote.match(/^git@([^:]+):/);
    const host = match?.[1];
    return host && host !== 'github.com' ? host : null;
  } catch {
    return null;
  }
}

export function runHostGh(args, cwd, timeoutMs = GH_RPC_TIMEOUT_MS) {
  const ghHost = ghHostFromCwd(cwd);
  const env = ghHost ? { ...process.env, GH_HOST: ghHost } : process.env;
  const child = spawn('gh', args, { cwd, env, ... });
  ...
}

github.com repos are unaffected. GH_HOST is only injected when the remote host is something else.

Environment

  • agentbox: 0.24.6
  • Provider: docker

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions