Skip to content

fix(release): release pushes run git with the person's environment, so the configured credential helper answers instead of "could not read Username", and a failed push stops release pr before it opens a PR #1124

Closed

Description

@dan-petty

Problem

devops release pr (also reached through release prepare --create-pr) failed to push the release branch with this output, while git push from the same shell worked:

Warning: Could not push branch to remote: fatal: could not read Username for 'https://github.com': No such device or address

Checked offline at release/v0.2.25 (d37120b; every cited line is the same at 132ecc5), with GitPython 3.1.62 as pinned in pyproject.toml, on 2026-10-03. No push was run and no credential was read.

Cause: the push runs in run_subprocess's sanitized environment, which drops everything git's credential helpers need.

  • The push is run_subprocess(["git", "push", "-u", "origin", <branch>]) (src/devops_cli/commands/release.py:822-824). release tag --push pushes the same way (:1577). run_subprocess builds the child environment from an allowlist (src/devops_cli/core/process.py:27-84), removes names that match the deny patterns (:86-94), and puts tokens back only for a gh argv (_inject_gh_credentials, :206-215, called at :247-248).
  • The devcontainer sets GIT_CONFIG_COUNT, GIT_CONFIG_KEY_<n> and GIT_CONFIG_VALUE_<n> (.devcontainer/devcontainer.json:47-55, src/devops_cli/templates/devcontainer.json.j2:47-55). They give https://github.com an empty helper, which drops inherited helpers, and then !gh auth git-credential. GIT_CONFIG_COUNT and GIT_CONFIG_VALUE_<n> are not on the allowlist, and GIT_CONFIG_KEY_<n> matches *KEY*, so the child git never sees that helper.
  • That leaves the system and global helper. In the devcontainer it is VS Code's remote-containers helper, which reads REMOTE_CONTAINERS_IPC to reach the editor. That variable is not on the allowlist either, so the helper returns nothing.
  • Restoring the helper would not be enough. gh auth git-credential reads gh's token from the keyring over the session bus, which is why _move_plaintext_gh_tokens passes DBUS_SESSION_BUS_ADDRESS (with GH_CONFIG_DIR and XDG_CONFIG_HOME) to gh (src/devops_cli/commands/devcontainer.py:1451-1452). None of them is on the allowlist, and GH_TOKEN and GITHUB_TOKEN match *TOKEN*. SSH remotes fail too: SSH_AUTH_SOCK matches *AUTH*, and GIT_ASKPASS and SSH_ASKPASS are not on the allowlist.
  • When no helper answers, git prompts on /dev/tty. Without a controlling terminal (an agent, CI, a scheduled job), opening it fails with ENXIO, the "No such device or address" above. In a terminal, git stops in the middle of the command to ask for a username and password, and GitHub does not accept a password over HTTPS.
  • A call site cannot fix this with extra_allowed_env. Deny patterns are applied first (core/process.py:145), so GIT_CONFIG_KEY_<n>, SSH_AUTH_SOCK and GH_TOKEN cannot be allowed by name.
  • Observed in the devcontainer by listing credential.*helper with git config --show-scope --get-regexp, once in the shell and once under build_subprocess_env():
    • The shell has the VS Code helper at system and global scope, then, at command scope, the reset and !gh auth git-credential for github.com and gist.github.com.
    • The sanitized child has only the VS Code helper at system and global scope.
    • GIT_CONFIG_COUNT, GIT_CONFIG_KEY_0, GIT_CONFIG_VALUE_1, REMOTE_CONTAINERS_IPC, DBUS_SESSION_BUS_ADDRESS and XDG_RUNTIME_DIR are all set in the shell, and none of them reaches the child.
  • The rest of the code reaches remotes another way. clone_repo, fetch_all and pull_tracking (src/devops_cli/git/operations.py:195-221) go through GitPython, which starts git from a copy of the full process environment, and feat(repos): Add a gitea remote to every clone under repos/ #1090 plans its Gitea push through GitPython's Remote.push. The release pushes are the only exception.
  • feat(release): production service image for scheduled jobs and webhook handlers #753 already records the gap for the service image (run_subprocess withholds the token from git, so this push has no credential) and works around it there with a system-scope helper plus refactor(github): one github session per identity owning token, quota and transport #767's token pin. Neither reaches the devcontainer, whose helper lives in the GIT_CONFIG_* variables.

A failed push is only a warning. _commit_and_push_release_branch (release.py:825-829) prints the warning above, and release_pr goes on to run gh pr create --head release/vX.Y.Z (:1178-1207, --head at :1047). Item PRs merge into the release branch, so it already exists on the remote. The PR therefore opens against the remote tip, without the bump commit that was just made locally. release tag --push already exits 1 when its push fails (:1578-1582). #982 makes the whole release path fail closed (its step 4 and its pre-receive criterion). In this item the push raises an exception, which has the same effect at today's call site.

A working credential would not make today's branch push succeed. The release ruleset (23059172, read with gh api on 2026-10-03) targets refs/heads/release*/**/* with a pull_request rule and lists no bypass actor, so GitHub refuses a direct push of a new commit to release/vX.Y.Z. After this item, today's release pr stops with GitHub's refusal instead of opening a PR. #982 moves the push to chore/cut-vX.Y.Z, which no ruleset covers; that push and release tag --push are the ones this item makes work.

Acceptance criteria

  • src/devops_cli/git/operations.py gains two functions built on GitPython's Remote.push:

    • push_branch(repo_dir, branch, *, remote="origin", set_upstream=True);
    • push_tags(repo_dir, *, remote="origin").

    Both run git with the process environment plus GIT_TERMINAL_PROMPT=0 (Git.custom_environment), and pass kill_after_timeout=DEFAULT_SUBPROCESS_TIMEOUT_SECONDS, the bound run_subprocess applies today.

  • A failed push raises GitOperationError naming the remote, the ref and git's message, passed through mask_secrets. It covers all three ways GitPython reports a failure:

    • Remote.push raises GitCommandError itself when git reports no ref at all, which is this bug's case (no credential, unreachable remote);
    • PushInfoList.raise_if_error() raises when git exited non-zero after reporting refs;
    • a PushInfo carries ERROR, which GitPython sets for every ! line: rejected, remote rejected, remote failure and no match.
  • _commit_and_push_release_branch and _push_git_tag call these functions. rg -n '"push",' src/devops_cli/commands finds nothing.

  • Environment test, with real git on tmp_path and no network:

    • Setup: a working repository with a bare origin. The working repository's pre-push hook writes what it sees to a file.
    • Environment: the test sets its own GIT_CONFIG_COUNT=1, GIT_CONFIG_KEY_0=credential.https://example.com.helper and GIT_CONFIG_VALUE_0=!fake-helper, and dummy values for DBUS_SESSION_BUS_ADDRESS, REMOTE_CONTAINERS_IPC, SSH_AUTH_SOCK and GH_TOKEN. GIT_CONFIG_GLOBAL and GIT_CONFIG_SYSTEM point at empty files.
    • Pass: push_branch succeeds, and the hook saw !fake-helper from git config --get-all credential.https://example.com.helper, each of those variables, and GIT_TERMINAL_PROMPT=0.
    • Fail on today's code: a run_subprocess(["git", "push", ...]) hook sees none of them.
  • Rejection test: the bare remote's pre-receive hook exits 1. push_branch raises GitOperationError naming the branch, and the remote ref does not move. With tags, push_tags raises the same way.

  • No-ref test: a remote whose path does not exist makes push_branch raise GitOperationError, not GitCommandError.

  • Call sites:

  • src/devops_cli/core/process.py does not change. Every other subprocess keeps the sanitized environment, and tests/test_subprocess_env_boundary.py passes unchanged.

  • The tests stay offline: local bare remotes, no socket, no real helper, and a dummy GH_TOKEN only. Together they add under 1 s. uv run devops ci passes.

  • Pending a person: in the devcontainer, from a shell with no controlling terminal (setsid -w uv run python -c "from pathlib import Path; from devops_cli.git.operations import push_branch; push_branch(Path('.'), 'try/push-check')" < /dev/null on a local branch try/push-check), the push succeeds without a prompt and git ls-remote origin try/push-check shows the local commit; then git push origin --delete try/push-check. Once fix(release): one fail-closed release path: cut branch from the remote release tip, uv.lock bump, draft flag, required label and milestone #982 has landed, its first cut run from an agent's shell pushes chore/cut-vX.Y.Z the same way.

Key questions

Strategic alignment

Update 2026-10-08: delivered scope

Delivered on fix/1124-release-push-person-environment. Where the delivered scope differs from the body above:

Activity

  1. added
    type/bug
    priority/p1-high
    on Oct 3, 2026
  2. added
    scope/release
    on Oct 3, 2026
  3. added this to the v0.2.29 milestone on Oct 8, 2026
  4. dan-petty commented on Oct 8, 2026

    @dan-petty
    OwnerAuthor

    Moved to v0.2.29: v0.2.29 started with fewer than its 12 items and was topped up to 12 from Ready items, critical fixes and P0 features first. (devops roadmap reprioritize)

  5. dan-petty-bot commented on Oct 8, 2026

    @dan-petty-bot
    Collaborator

    What changed

    #1402, merged into release/v0.2.29 as 8f287b5.

    Closes #1124

    • Person's environment: the release command's remote git calls (the release-branch fetch, the cut push and the tag push) now run through one helper, _run_remote_git_or_exit. It runs git with the person's environment plus GIT_TERMINAL_PROMPT=0, so their configured credential helper answers instead of "could not read Username". refactor(github): one github session per identity owning token, quota and transport #767's token rule still holds: GH_TOKEN is pinned to the session token, no GITHUB_TOKEN is passed, and no token at all without a gh login. core/process.py and git/operations.py are unchanged.
    • Fail closed: a failed fetch, cut push or tag push exits 1 with git's reason, masked and printed as written. Before, Rich read git's text as markup, so [remote rejected] vanished and a [/bold] in a remote message crashed. release pr and release prepare --create-pr stop before gh is called, and a failed fetch stops the cut before any checkout, so a stale origin/release/vX.Y.Z is never cut.
    • Narrower tag push: release tag --push pushes refs/tags/v<version> instead of --tags.
    • Limits, documented: an askpass program you configured (GIT_ASKPASS, such as VS Code's) still runs; whether to clear it is left to the owner. An exported GIT_DIR would redirect these calls; that is fix(release): an exported GIT_DIR never redirects the release command's push and fetch #1397.

    The tests are offline, using local bare remotes with pre-receive and pre-push hooks. The environment test records only the variables it asserts. uv run devops ci passes locally (3m 6s).

    This delivers #1366's "the cut's branch ch…

    5 file(s) changed.

    How it was verified

    Check runs at 3dd673d:

    • Prune PR DevContainer Images: pass
    • CodeQL: pass
    • Static Analysis: pass
    • Analyze (python): pass
    • Tests & Coverage: pass
    • Analyze (actions): pass
    • DevContainer Image: skipping
    • Service Image: skipping
    • Dependency Freshness: skipping

    Acceptance Criteria of docs/agent/tasks/task-1124-release-push-person-environment.md:

    • The cut branch push (_commit_and_push_cut_branch), the tag push (_push_git_tag) and the release-branch fetch (_fetch_remote_release_tip) run run_subprocess with isolate_env=False and GIT_TERMINAL_PROMPT=0. No other git call does (test_release_pr_command, test_release_notes_tag_and_check_extended).

    • Environment test with real git on tmp_path, a local bare origin and no network (test_release_pr_pushes_in_the_persons_git_environment). The clone's pre-push hook, run by devops release pr, writes only the variables the test checks, and sees:

      • !fake-helper from git config --get-all credential.https://example.com.helper;
      • GIT_CONFIG_COUNT, GIT_CONFIG_KEY_0, GIT_CONFIG_VALUE_0, DBUS_SESSION_BUS_ADDRESS, REMOTE_CONTAINERS_IPC and SSH_AUTH_SOCK as the test set them;
      • GIT_TERMINAL_PROMPT=0, GH_TOKEN equal to the session's pinned token, and no GITHUB_TOKEN, although the environment set both to other values;
      • with no gh login (fail_the_github_lookup), neither GH_TOKEN nor GITHUB_TOKEN.

      On the previous code the hook saw none of the person's variables and no prompt setting.

    • A rejected push exits 1 and never calls gh. The error names release/v0.2.26 and carries git's reason as written, with the token in it masked (test_release_cut_rejected_push_stops_before_gh):

      • release prepare --create-pr, refused by the bare remote's pre-receive hook. The error keeps git's [remote rejected].
      • release pr, whose push repeats the remote tip, refused by the clone's pre-push hook, which git runs even for an up-to-date push.
    • A failed fetch stops the cut (test_release_cut_stops_when_the_release_branch_fetch_fails). The remote has deleted release/v0.2.26 and the clone still holds origin/release/v0.2.26. release pr exits 1 with "Failed to fetch origin/release/v0.2.26" and git's reason, creates no cut branch, leaves the checkout on its branch, and never calls gh. A fetch that succeeds but writes no origin/release/v<version> still stops with "does not exist" (test_release_cut_stops_when_the_fetch_writes_no_tracking_ref).

    • release tag --push pushes git push origin refs/tags/v<version> and nothing else (test_release_notes_tag_and_check_extended). A refused tag push exits 1 with git's reason, the token in it masked, and closes no Release. A [/bold] in the reason is printed as text instead of raising MarkupError (test_release_tag_push_and_errors).

    • src/devops_cli/core/process.py and src/devops_cli/git/operations.py do not change, and tests/test_subprocess_env_boundary.py passes unchanged.

    • The new cases use local bare remotes, run no real helper and open no socket. Each takes well under 1 s. uv run devops ci passes.

    • Pending a person: in the devcontainer, on a local branch try/push-check (git switch -c try/push-check), run setsid -w uv run python -c "from pathlib import Path; from devops_cli.commands.release import _commit_and_push_cut_branch; _commit_and_push_cut_branch(Path('.'), 'try/push-check', '', commit=False)" < /dev/null. The push runs this repository's pre-commit pre-push stage: when try/push-check carries commits origin does not have yet, that stage runs uv run devops ci, and the push takes several minutes. The push succeeds without a prompt, and git ls-remote origin try/push-check shows git rev-parse HEAD. Then run git push origin --delete try/push-check, git switch - and git branch -D try/push-check.

  6. added a commit that references this issue on Oct 8, 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/p1-highscope/releasetype/bug

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions