Skip to content

fix(git): the branch-current hook refuses a push on a slow fetch #4969

Closed

Description

@dan-petty

Bug Description

The pre-push hook branch-current (.pre-commit-config.yaml) runs timeout 20 git fetch --quiet --no-tags origin main. On a loaded devcontainer the fetch takes longer than 20 seconds, so the hook refuses the push with "The hook cannot fetch main from origin". Origin is available, and the branch holds origin/main.

Steps to Reproduce

  1. Run many agents at one time in the devcontainer (load average about 70 on 2026-11-12).
  2. Push a branch that holds origin/main: git push --force-with-lease -u origin <branch>.
  3. Run the fetch of the hook by hand: time (timeout 20 git fetch --quiet --no-tags origin main).

Expected Behavior

The hook checks the branch, and a push of a current branch passes. A slow fetch is no proof that origin is not available.

Actual Behavior

  • The push fails with "The hook cannot fetch main from origin, so it cannot check the branch."
  • The timed fetch exits 124 after 20.2 s. The same fetch with no timeout passes in 15.7 s, at a load average of 67.
  • A second push of the same branch passed.

Proposed fix

Take the fetch limit from a measured history of the fetch time, or give the fetch a longer limit that stays inside the pre-push hook limit (nested timeouts: the inner limit ends first). When the fetch runs out of time, the message names the time limit and not an unavailable origin.

Environment

devops-cli 0.117.x, pre-push hook of #4879, devcontainer on rootless Podman.

Source: #4966

Alternatives check of 2026-11-15: none.
Tool: none found.

Proposed design

Problem statement

The branch-current pre-push hook stops its fetch of origin/main after 20 seconds. A loaded devcontainer needs longer, so the hook refuses a push of a current branch and says that origin is unavailable. The hook must give the fetch more time inside the pre-push budget, and name the time limit when the fetch runs out of time.

Acceptance criteria

Requirement: Fetch limit of the branch-current hook

The branch-current pre-push hook SHALL bound its fetch of origin main with a 45 second limit.

Scenario: The hook bounds the fetch

  • WHEN the branch-current entry of .pre-commit-config.yaml is read
  • THEN the entry runs timeout 45 git fetch --quiet --no-tags origin main

Requirement: Pre-push timeout budget

The pre-push hooks SHALL keep the sum of their time limits below the 120 second limit of the agent shell.

Scenario: The time limits add up

  • WHEN the time limits of the pre-push hooks are summed
  • THEN the sum is less than 120 seconds

Requirement: Timeout message

The branch-current hook SHALL name the 45 second limit when its fetch runs out of time, and SHALL NOT report origin as unavailable.

Scenario: The fetch runs out of time

  • WHEN the fetch exits with status 124
  • THEN the hook prints a message that names 45 seconds and exits 1, and the message does not say that origin is unavailable

Requirement: Fetch failure message

The branch-current hook SHALL report an unavailable origin when the fetch fails with a status other than 124.

Scenario: The fetch fails

  • WHEN the fetch exits with status 128
  • THEN the hook prints the origin-unavailable message and exits 1

Requirement: Current branch passes

The branch-current hook SHALL accept a push of a branch that holds origin/main.

Scenario: The branch holds origin main

  • WHEN the fetch succeeds and origin/main is an ancestor of the pushed ref
  • THEN the hook exits 0

Requirement: Stale branch is refused

The branch-current hook SHALL refuse a push of a branch that does not hold origin/main.

Scenario: The branch is behind origin main

  • WHEN the fetch succeeds and origin/main is not an ancestor of the pushed ref
  • THEN the hook prints the rebase message and exits 1

Existing Tool Considered

The alternatives check of 2026-11-15 gave the verdict none: no open, maintained tool or library covers the need. The check found only hook-runner images and generic git and timeout documentation. No tool supplies a fetch deadline from a measured history, and none supplies a time-limit message. The change stays in the repository's own branch-current hook script and its .pre-commit-config.yaml entry. Cost to build that code: about 4,000 tokens to write the shell change and its test. Cost to keep and fix it: about 1,000 tokens per later fix. Elapsed time: less than one hour.

Key questions

  • Should the fetch limit come from a measured history of fetch times, or be a fixed limit?: Use a fixed 45 second limit. It is deterministic and keeps no state. It gives about three times the measured 15.7 s fetch. (best practice) [sources: .pre-commit-config.yaml]
    • Chosen: Fixed 45 second limit. It is deterministic, keeps no state, and fits the pre-push budget. It gives about three times the measured 15.7 s fetch.
    • Rejected: Limit from a measured history. It needs a state file and a cold-start policy. A slow first fetch or a lost state file gives a wrong limit.
  • What fetch limit fits the pre-push hook budget?: 45 seconds. The agent shell stops the whole push at 120 s, and the other pre-push hooks hold 40 s and 30 s. The fetch can take at most 50 s, so 45 s leaves 5 s of slack. (best practice) [sources: .pre-commit-config.yaml]
    • Chosen: 45 seconds. 120 - (40 + 30) = 50. 45 s leaves 5 s of slack.
    • Rejected: 50 seconds. The sum equals 120 s, and the config keeps the sum below 120 s.
    • Rejected: 20 seconds. This is the current value. The fetch took 15.7 s at a load average of 67 and more than 20 s at 70.
  • How does the hook tell a timeout from a fetch failure?: timeout exits with status 124 when the command runs out of time. The hook captures the exit status of the fetch and prints the time-limit message only for 124. [sources: .pre-commit-config.yaml]
  • Should the hook set git's low-speed limits to stop a stalled fetch?: No. http.lowSpeedLimit and http.lowSpeedTime stop a stalled transfer only. A slow transfer that still makes progress reaches the wall-clock limit, and the message names that limit. (best practice) [sources: .pre-commit-config.yaml]
    • Chosen: Wall-clock limit only. It covers a slow transfer and a stalled one, and the message names the limit.
    • Rejected: Git low-speed limits. They stop a stalled transfer only. A slow transfer that makes progress still needs the wall-clock limit.
  • Where does the test of the hook live?: In a pytest test under tests/. The test reads the branch-current entry of .pre-commit-config.yaml, puts a stub git on PATH, and runs the hook script with sh -c. (best practice) [sources: .pre-commit-config.yaml, docs/adr/0004-ci-is-the-authoritative-gate.md]
    • Chosen: pytest test with a stub git. It tests the hook's behaviour offline and fast. Tests & Coverage runs it as a required check.
    • Rejected: A devops ci row. The rule for rows covers static checks of committed files. This test runs a program, and a row adds a registry entry, a bound and a help text for one small check.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/bug
    scope/git
    status/new
    value/medium
    effort/low
    on Nov 12, 2026
  2. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor
  3. added
    priority/p2-medium
    on Nov 12, 2026
  4. devops-cli-service commented on Nov 15, 2026

    @devops-cli-service
    Contributor

    Alternatives check: none

    Reason: Searches for pre-push hook timeouts, pre-commit hook timeout settings and git fetch timeout/retry helpers turned up only hook-runner container images and generic git/timeout documentation; none of them offers a fetch deadline derived from measured history or an error that names the time limit instead of an unavailable origin. The change belongs in the repository's own branch-current hook script and its .pre-commit-config.yaml entry, so no external tool covers the need.

    Tool: none found

    Lacks:

    • A fetch deadline taken from a measured history of fetch times, or a longer inner limit that stays inside the pre-push hook limit
    • An error message that names the time limit when the fetch runs out of time, rather than reporting origin as unavailable
    • No off-the-shelf hook runner or git helper found that supplies either behaviour

    Searches run:

    • git fetch timeout retry configurable tool, results: 5
    • adaptive timeout for git fetch in pre-push hook, results: 5
    • pre-commit framework hook timeout setting, results: 5
    • git http.lowSpeedLimit lowSpeedTime fetch stall timeout, results: 5
    • bash git fetch with timeout and retry script, results: 5
    • github pre-commit hook timeout configuration, results: 5
    • git pre-push hook fetch origin main timeout, results: 5
    • pre-commit, results: 5
    • git hook runner timeout per hook lefthook overcommit, results: 5
    • pre-commit.com hook configuration options timeout, results: 5

    Sources:

    Checked on 2026-11-15. A person decides what this means for the item. The check changes no label and closes no issue.

  5. added
    status/ready
    and removed
    status/new
    on Nov 16, 2026
  6. devops-cli-service commented on Nov 16, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 0cdf3e4 (see proposed design in issue body).

  7. added
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 17, 2026
  8. removed
    status/in-review
    on Nov 17, 2026
  9. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-17 19:36 UTC

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

    effort/lowpriority/p2-mediumscope/gitsource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions