Skip to content

Fix git commit author attribution in sandbox #342

Closed

Description

@sentry-junior

Bug

Commits made by Junior are attributed to a random GitHub user junior ([email protected], user ID MDQ6VXNlcjU1MTAwNw==) instead of the sentry-junior[bot] app account. This affects all PRs Junior creates — example: getsentry/sentry#113900.

Root cause: No git config user.name / user.email is set in the sandbox environment. When git commits with a GitHub App installation token and no explicit identity, GitHub resolves the author from the token's associated slug. Since the app slug is junior, GitHub matches it to an unrelated existing user account named "junior".

Desired fix

Set the git author identity to the bot's proper noreply address before any commits:

git config --global user.name "sentry-junior[bot]"
git config --global user.email "{app-user-id}+sentry-junior[bot]@users.noreply.github.com"

The {app-user-id} is the numeric GitHub user ID for the sentry-junior[bot] account (retrievable via gh api /users/sentry-junior%5Bbot%5D --jq .id).

Open question

A global git identity config baked into the sandbox would fix this, but it's unclear how to make that configurable across different GitHub App installations or plugin configurations. Ideally the git identity would derive from the active GitHub plugin credentials rather than being hardcoded.

Reported by Nick Meisenheimer. Action taken on behalf of David Cramer.

Activity

  1. sentry-junior commented on May 13, 2026

    @sentry-junior
    ContributorAuthor

    Research findings

    Root cause detail

    noninteractive-command.ts sets GIT_CONFIG_NOSYSTEM=1 and GIT_CONFIG_COUNT=2 (for credential isolation), but never configures user.name / user.email. Git falls back to the installation token's associated slug, which GitHub resolves to an unrelated user account named "junior" (MDQ6VXNlcjU1MTAwNw==).

    The correct bot identity is:

    • Name: sentry-junior[bot]
    • User ID: 264270552
    • Email: 264270552+sentry-junior[bot]@users.noreply.github.com

    Recommended long-term fix: Dynamic broker-derived lease env (A3)

    Inject GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, GIT_COMMITTER_NAME, GIT_COMMITTER_EMAIL from github-app-broker.ts into the CredentialLease.env.

    Why this approach:

    • Commit identity is credential-scoped (sandbox is reused across turns, so persistent git config --global is unsafe)
    • Dynamic — derives identity from the GitHub App via GET /app + GET /users/{slug}[bot], works for any app installation
    • No conflicts with existing GIT_CONFIG_COUNT mechanism — these are separate git env vars
    • All plumbing already exists: lease env flows through inject-credentials.ts → buildNonInteractiveShellScript() → sandbox bash. Only github-app-broker.ts needs changes.

    Implementation: At broker creation, call GET /app (JWT) to get app slug, call GET /users/{slug}[bot] to get bot user ID, cache both, add the four env vars to every lease.

    Interim fix deployed

    https://github.com/getsentry/junior-prod/pull/71 — patches the @sentry/junior-github plugin.yaml via pnpm patch to add static command-env with the four git identity env vars. This is junior-prod-only and hardcoded for the sentry-junior app. It should be removed once the dynamic broker fix lands.

    Alternatives evaluated

    Approach Verdict
    A1: Hardcode in NON_INTERACTIVE_ENV Wrong layer — generic shell policy, not provider-specific
    A2: Static command-env in plugin.yaml ✅ Used as interim fix via pnpm patch
    A3: Dynamic broker lease env ✅ Recommended long-term fix
    B: Extend GIT_CONFIG_COUNT Fragile — multiple layers can't independently add git config
    C: git config --global at sandbox boot Wrong scope — sandbox outlives credentials

    Key files

    • packages/junior/src/chat/plugins/auth/github-app-broker.ts — add identity to lease env
    • packages/junior/src/chat/sandbox/noninteractive-command.ts — existing NON_INTERACTIVE_ENV (no changes needed)
    • packages/junior/src/chat/tools/execution/inject-credentials.ts — existing env injection (no changes needed)
  2. added 2 commits that reference this issue on May 14, 2026
    d1da5ba
    3e992bf
  3. added 2 commits that reference this issue on May 14, 2026
    b30d26e
    3b405a7
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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions