[bug-hunter] ready-to-make-pr skips committed diff when upstream tracking is unset

Open Beginner friendly
#2,114 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
85/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
github-actions, python
Domain
ci-cd

Research direction

Start in .github/workflows/gh-aw-fragments/safe-output-create-pr.md, especially lines 17-21 and 33-37, 43-47. Trace how upstream_sha is resolved and compare that with the diff and stat commands using @{upstream}; reproduce the no-tracking-branch case from the issue. Done means committed changes against origin/main produce a nonzero diff/stat and include the self-review checklist item.

Written by the indexing model from the issue text.

Description

Impact

ready-to-make-pr can return status: ok with diff_line_count: 0 even when there are committed local changes that should be reviewed.

This happens when a repo has an origin/main remote available but no local upstream tracking branch (@{upstream} is unset). In that case, the script successfully computes upstream_sha from origin/main, but still builds diff/stat only from @{upstream} and HEAD. The self-review checklist item is skipped, so users can create a PR without the intended pre-PR diff review context.

Reproduction Steps

  1. Save and run this script:
import json
import subprocess
import tempfile
from pathlib import Path

repo_root = Path('/home/runner/work/ai-github-actions/ai-github-actions')
fragment = repo_root / '.github/workflows/gh-aw-fragments/safe-output-create-pr.md'
text = fragment.read_text()
start = text.index('    py: |')
end = text.index('safe-outputs:')
block = text[start:end].splitlines()[1:]
py_lines = []
for line in block:
    if line.startswith('      '):
        py_lines.append(line[6:])
    elif line.strip() == '':
        py_lines.append('')
py_code = '\n'.join(py_lines).rstrip() + '\n'

with tempfile.TemporaryDirectory() as td:
    base = Path(td)
    repo = base / 'repo'
    remote = base / 'remote.git'
    repo.mkdir()

    def run(cmd, cwd=repo):
        p = subprocess.run(cmd, cwd=cwd, capture_output=True, text=True)
        if p.returncode != 0:
            raise RuntimeError(f"cmd failed: {' '.join(cmd)}\nstdout={p.stdout}\nstderr={p.stderr}")
        return p

    run(['git', 'init', '-b', 'main'])
    run(['git', 'config', 'user.email', 'test@example.com'])
    run(['git', 'config', 'user.name', 'Test'])
    (repo / 'file.txt').write_text('hello\n')
    run(['git', 'add', 'file.txt'])
    run(['git', 'commit', '-m', 'init'])

    subprocess.run(['git', 'clone', '--bare', str(repo), str(remote)], capture_output=True, text=True, check=True)
    run(['git', 'remote', 'add', 'origin', str(remote)])
    run(['git', 'fetch', 'origin'])

    # Local committed change; no upstream tracking configured.
    (repo / 'extra.txt').write_text('extra line\n')
    run(['git', 'add', 'extra.txt'])
    run(['git', 'commit', '-m', 'add extra'])

    p = subprocess.run(['python3', '-c', py_code], cwd=repo, capture_output=True, text=True, check=True)
    output = json.loads(p.stdout.strip())
    expected = run(['git', 'diff', '--merge-base', 'origin/main']).stdout

    print('status=', output.get('status'))
    print('diff_line_count_reported=', output.get('diff_line_count'))
    print('expected_diff_lines_against_origin_main=', len(expected.splitlines()))
    print('script_stdout_json=', json.dumps(output, indent=2))
  1. Run: python3 repro_ready_to_make_pr_diff_bug.py

Expected vs Actual

Expected: when upstream_sha resolves from origin/main, the script should produce a non-empty diff/stat for committed local changes and include the self-review checklist item.

Actual: script reports diff_line_count: 0 and omits self-review checklist despite committed changes.

Observed output:

status= ok
diff_line_count_reported= 0
expected_diff_lines_against_origin_main= 8
script_stdout_json= {
  "status": "ok",
  "checklist": [
    "Confirm the requested task is fully completed and validated before creating or pushing PR changes."
  ],
  "contributing_guide": null,
  "pr_template": null,
  "diff_line_count": 0
}

Failing Test

A minimal failing assertion equivalent to the script above:

assert output['status'] == 'ok'
assert output['diff_line_count'] > 0  # Fails: reports 0 despite committed changes

Evidence

  • .github/workflows/gh-aw-fragments/safe-output-create-pr.md:17-21 computes upstream_sha from fallback refs (@{upstream}, origin/HEAD, origin/main).
  • .github/workflows/gh-aw-fragments/safe-output-create-pr.md:33-37 and 43-47 still run diff/stat only against @{upstream} and HEAD, never using upstream_sha.
  • The reproduction above shows a deterministic mismatch: expected_diff_lines_against_origin_main=8 while diff_line_count_reported=0.

What is this? | From workflow: Trigger Bug Hunter

Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not.

  • expires on Sep 24, 2026, 11:26 AM UTC
Dominant language
Python
Stars
11
Forks
16
Avg merge
11h 16m
Merged PRs (30d)
29

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from elastic/ai-github-actions

All issues in elastic/ai-github-actions

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.