Skip to content

Fix existing-repo auto-pull path used by mlcrr - #261

Merged
arjunsuresh merged 26 commits into
devfrom
copilot/fix-mlcrr-script
Jul 18, 2026
Merged

Fix existing-repo auto-pull path used by mlcrr#261
arjunsuresh merged 26 commits into
devfrom
copilot/fix-mlcrr-script

Conversation

Copilot AI commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

✅ PR Checklist

  • Target branch is dev

📌 Note: PRs must be raised against dev. Do not commit directly to main.

  • Problem

    • mlcrr can fail while auto-pulling mlcommons@mlperf-automations from an existing checkout because RepoAction.pull_repo() uses a bare git pull, which is sensitive to local pull/rebase configuration and can error with Cannot rebase onto multiple branches.
  • Change

    • Repo pull behavior
      • Route existing-repo pulls through an explicit fast-forward-only command.
      • When a branch is requested, pull that branch explicitly from origin instead of relying on local branch/upstream state.
    • Regression coverage
      • Add a focused test for the existing-repo + branch="dev" path used by the automation auto-pull flow.
  • Example

    # before
    git -C <repo> pull
    
    # after
    git -C <repo> pull --ff-only origin dev

✅ Testing & CI

  • Have tested the changes in my local environment, else have properly conveyed in the PR description
  • The change includes a GitHub Action to test the script(if it is possible to be added).
  • No existing GitHub Actions are failing because of this change.

📚 Documentation

  • README or help docs are updated for new features or changes.
  • CLI help messages are meaningful and complete.

📁 File Hygiene & Output Handling

  • No unintended files (e.g., logs, cache, temp files, pycache, output folders) are committed.

🛡️ Safety & Security

  • No secrets or credentials are committed.
  • Paths, shell commands, and environment handling are safe and portable.

🙌 Contribution Hygiene

  • PR title and description are concise and clearly state the purpose of the change.
  • Related issues (if any) are properly referenced using Fixes # or Closes #.
  • All reviewer feedback has been addressed.

Copilot AI linked an issue Jul 16, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix issue with mlcrr script automation Fix existing-repo auto-pull path used by mlcrr Jul 16, 2026
Copilot AI requested a review from arjunsuresh July 16, 2026 21:30
@github-actions

Copy link
Copy Markdown

MLCommons CLA bot All contributors have signed the MLCommons CLA ✍️ ✅

@github-actions

Copy link
Copy Markdown

🤖 AI PR Review Summary\n\nThis PR refactors the git pull command construction in RepoAction to enforce fast-forward-only pulls and adds a test to verify that pulling an existing repo with a specified branch uses the explicit '--ff-only' option. The design improves safety by preventing unintended merge commits during pulls. Risks are minimal but include potential breakage if other parts of the code expect the default pull behavior without '--ff-only'.

@arjunsuresh
arjunsuresh requested a review from anandhu-eng July 16, 2026 21:33
@arjunsuresh

Copy link
Copy Markdown
Contributor

@copilot is the newly added test used in github action?

@arjunsuresh

Copy link
Copy Markdown
Contributor

@copilot the AI PR review is not very useful - can you clean and make it professional?

AI PR Review Summary\n\nThis PR refactors the git pull command construction in RepoAction to enforce fast-forward-only pulls and adds a test to verify that pulling an existing repo with a specified branch uses the explicit '--ff-only' option. The design improves safety by preventing unintended merge commits during pulls. Risks are minimal but include potential breakage if other parts of the code expect the default pull behavior without '--ff-only'.

Copilot AI commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

@copilot is the newly added test used in github action?

Yes. It is run explicitly in GitHub Actions from /home/runner/work/mlcflow/mlcflow/.github/workflows/test-mlc-core-actions.yaml under Test 3b - pull repo --force handling, which executes python .github/scripts/test_repo_pull_force.py. It is not picked up by the default pytest discovery; the workflow invokes it directly.

Copilot AI commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

@copilot the AI PR review is not very useful - can you clean and make it professional?

AI PR Review Summary\n\nThis PR refactors the git pull command construction in RepoAction to enforce fast-forw...

Use this instead:

This change makes existing-repository pulls deterministic by using git pull --ff-only. When a branch is specified, it now pulls origin <branch> explicitly instead of relying on local pull/rebase configuration. The PR also adds regression coverage for the mlcrr auto-pull path. Risk is low and limited to cases that previously depended on implicit git pull behavior; the new behavior intentionally avoids unexpected merges or rebases.

@arjunsuresh

Copy link
Copy Markdown
Contributor

@copilot fix the corresponding AI peer review gh action too

@arjunsuresh
arjunsuresh changed the base branch from main to dev July 18, 2026 00:51

Copilot AI commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

@copilot fix the corresponding AI peer review gh action too

Updated in 24fd2c0. The AI peer review workflow now asks for a professional 2-4 sentence engineering summary, plain risk language, and actionable inline comments only, and it posts the summary under the cleaner AI Peer Review heading.

@arjunsuresh

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

Copilot AI commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

@copilot resolve the merge conflicts in this pull request

Resolved in 4bd47d6.

Copilot AI commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

@copilot address the remaining concerns in the above comment

Addressed in fb72cf0.

This updates the strict pull path so branch checkout only falls back to fetch-and-track for Git’s missing-branch case, preserves stash-recovery guidance if strict branch preparation fails during --force, clarifies the --branch behavior in the repo pull help text, and makes strict ff-only failures return a more actionable message. I also added regression coverage for the checkout and strict-pull failure edge cases.

@github-actions

Copy link
Copy Markdown

🤖 AI PR Review Summary\n\nThis PR adds enhanced unit tests and error handling for the RepoAction class's pull_repo method, focusing on branch checkout, pull commands with fast-forward options, and stash recovery scenarios. It introduces a helper method to build git pull commands and refines error messages for better user guidance. Risks are low as changes are mostly additive tests and improved error handling, but care should be taken to ensure subprocess calls handle all edge cases correctly.

@github-actions

Copy link
Copy Markdown

🤖 AI PR Review Summary\n\nThis PR enhances the RepoAction class and its tests by improving git pull behavior with explicit fast-forward options, better error handling during branch checkout, and more informative error messages on pull failures. It introduces helper methods to build pull commands and checkout branches robustly, including fallback fetch-and-track logic. The risks are low as changes are well-covered by unit tests, but care is needed to ensure error message parsing remains accurate and that subprocess calls handle all edge cases correctly.

@anandhu-eng anandhu-eng left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Claude Code Follow-up Review #3 (requested by @anandhusooraj)

Reviewed by Claude (claude-sonnet-4-6) after the 9 follow-up commits (05cdaef4bc15be).


Round-2 issues — all five are now resolved ✅

Round-2 issue Status
_checkout_pull_branch fallback triggered on any checkout error ✅ Fixed — now guards on "pathspec" + GIT_MISSING_BRANCH_PHRASE before falling through to fetch+create
Stash rescue hint lost when RuntimeError fires in force path ✅ Fixed — force path now has a dedicated except RuntimeError block that calls _format_pull_error with stash_created context
pull_repo docstring still said --branch is clone-only ✅ Fixed — docstring updated to mention strict fast-forward path
No-changes path sent git output to stdout ✅ Fixed — capture_output=True, text=True added
--ff-only failure gave a generic error ✅ Fixed — _format_pull_error detects GIT_FAST_FORWARD_FAILURE_PHRASE and appends divergence guidance

The _format_pull_error and _format_stash_restore_guidance helpers are clean centralisations. The new tests — particularly test_checkout_pull_branch_does_not_mask_non_pathspec_checkout_errors, test_pull_force_checkout_error_mentions_stash_recovery, and test_pull_existing_repo_ff_only_failure_returns_actionable_error — close all the coverage gaps called out in round 2.


One remaining issue

🔴 Class constants placed before the docstring silently null out RepoAction.__doc__

class RepoAction(Action):
    GIT_MISSING_BRANCH_PHRASE = "did not match any file(s) known to git"   # ← first statement
    GIT_FAST_FORWARD_FAILURE_PHRASE = "not possible to fast-forward"        # ← second statement

    """                                                                     # ← NOT the docstring
    Repo Action
    ...
    """

In Python, a class docstring is only recognised when a string literal is the first statement in the class body. Because the two constants come first, RepoAction.__doc__ is None — confirmed by running python3 -c "from mlc.repo_action import RepoAction; print(repr(RepoAction.__doc__))".

The main.py commit (actions.__doc__ or "") prevents the TypeError in the help output, but it treats the symptom rather than the cause. Any other code that introspects RepoAction.__doc__ directly (e.g. help(), documentation generators, future tooling) will silently get None.

Fix: move the two constants to after the docstring:

class RepoAction(Action):
    """
    Repo Action
    ...
    """
    GIT_MISSING_BRANCH_PHRASE = "did not match any file(s) known to git"
    GIT_FAST_FORWARD_FAILURE_PHRASE = "not possible to fast-forward"

The or "" guard in main.py is still a sensible defensive fix to keep regardless (other action classes could legitimately have no docstring), so it does not need to be reverted.


Minor observations (no action required)

  • GIT_FAST_FORWARD_FAILURE_PHRASE = "not possible to fast-forward" covers the standard git message reliably; the lowercase + .lower() approach is correct.
  • The _is_git_status_porcelain_command test helper is a nice touch — removes the duplicated multi-condition check across all test fake runners.
  • The main.py or "" fix is correct and worthwhile to keep even after the docstring placement is corrected.

Summary

The PR is in very good shape. The single remaining fix — moving the two class constants below the docstring — is a one-line change. Once that is done this is ready to merge.

@arjunsuresh

Copy link
Copy Markdown
Contributor

@copilot please address the concern in the last comment

Copilot AI commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

@copilot please address the concern in the last comment

Fixed in the latest commit. The two class constants (GIT_MISSING_BRANCH_PHRASE and GIT_FAST_FORWARD_FAILURE_PHRASE) are now moved to after the docstring, so RepoAction.__doc__ is correctly set. Verified with python3 -c "from mlc.repo_action import RepoAction; print(repr(RepoAction.__doc__))" and all 13 tests pass.

@anandhu-eng anandhu-eng left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Claude Code Follow-up Review #4 (requested by @anandhusooraj)

Reviewed by Claude (claude-sonnet-4-6) after commits 1722270, 5983da8, c7de22c.


Round-3 issue — resolved ✅

Round-3 issue Status
Class constants before docstring silently nullified RepoAction.__doc__ ✅ Fixed — constants moved to after the docstring; RepoAction.__doc__ confirmed non-None

AI review workflow fixes (ai-pr-review.yml) — all correct

The three workflow commits address real fragility in the OpenAI response parsing:

  • extract_response_text(data) — handles multiple response shapes: the top-level output_text field, the nested output[].content[].text string path, and the Assistants-API variant where text is a dict with a value key. Much safer than the previous hardcoded data["output"][0]["content"][0]["text"].

  • strip_code_fences(text) — correctly handles models that wrap JSON output in ```json ... ```. The edge cases (empty body after stripping, unclosed fence) behave reasonably.

  • response.raise_for_status() — correct; previously a 4xx/5xx response would silently fall through to json.loads and produce a confusing KeyError.

  • timeout=60 — good defensive practice for an external API call in CI.

  • RuntimeError on empty extracted text — surfaces the raw response (truncated to 1000 chars) instead of a silent empty-string parse failure.

One minor observation: if extract_response_text collects text from multiple content blocks it joins them with "\n", which would produce invalid JSON when json.loads is called on the result. In practice the model returns a single block, so this is not a realistic problem, but a texts[0] / take-first approach would be slightly more explicit about that assumption.


Overall

All issues raised across all three prior review rounds are now resolved. The PR is in good shape and ready to merge from a code-quality perspective.

@github-actions

Copy link
Copy Markdown

🤖 AI PR Review Summary\n\nThis PR enhances the test coverage of the RepoAction pull functionality by adding multiple unit tests that verify different pull scenarios, including fast-forward-only pulls, error handling during branch checkout, and stash recovery messaging. It also refactors test code to reduce duplication by introducing a helper method for identifying git status commands. Additionally, the AI PR review GitHub workflow is improved to better extract and clean the model's response text, handle errors more robustly, and clarify the PR comment message. Minor code fixes in mlc/main.py address potential NoneType docstring concatenation issues. Overall, the changes are low risk, focused on improving test robustness and CI workflow reliability, with no major design changes introduced.

@arjunsuresh
arjunsuresh merged commit 428f3ef into dev Jul 18, 2026
63 checks passed
@arjunsuresh
arjunsuresh deleted the copilot/fix-mlcrr-script branch July 18, 2026 18:56
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Need fix for mlcrr script

3 participants