Skip to content

fix(sdk): pass workspace git patch to critics - #4585

Open
somalice wants to merge 1 commit into
OpenHands:mainfrom
somalice:codex/fix-critic-git-patch
Open

fix(sdk): pass workspace git patch to critics#4585
somalice wants to merge 1 commit into
OpenHands:mainfrom
somalice:codex/fix-critic-git-patch

Conversation

@somalice

@somalice somalice commented Aug 23, 2026

Copy link
Copy Markdown

HUMAN:

I am submitting this initial fix for #4554 and would like maintainers to confirm whether this direction is acceptable.


AGENT:

Why

CriticMixin._evaluate_with_critic() always passed git_patch=None to CriticBase.evaluate(), which made the git_patch parameter unreachable in normal SDK usage.

This means patch-aware critics could not evaluate the actual workspace changes and had to rely on transcript contents instead.

Summary

  • Build a best-effort workspace git patch before critic evaluation.
  • Pass the generated patch to CriticBase.evaluate(..., git_patch=...).
  • Fall back to git_patch=None when there are no changes or patch collection fails.
  • Skip individual files whose diff cannot be collected while still passing available diffs.

Issue Number

Related to #4554

How to Test

I tested this locally with:

  • git diff --check
  • D:\python\python.exe -m py_compile openhands-sdk/openhands/sdk/agent/critic_mixin.py tests/sdk/agent/test_iterative_refinement.py
  • uv run --no-sync pytest tests/sdk/agent/test_iterative_refinement.py -q
    • Result: 21 passed in 1.40s
  • uv run --frozen pre-commit run --files openhands-sdk/openhands/sdk/agent/critic_mixin.py tests/sdk/agent/test_iterative_refinement.py
    • Ruff format: Passed
    • Ruff lint: Passed
    • PEP8 style check: Passed
    • Pyright: Passed
    • Import dependency rules: Passed
    • Tool subclass registration: Passed

Video/Screenshots

N/A. This is a backend SDK behavior change covered by unit tests.

Design Doc

N/A.

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

This PR does not mutate the user's git index. It only uses the existing workspace diff APIs.

The generated patch represents the workspace diff at evaluation time. If the workspace was already dirty before the agent run, pre-existing changes may be included.

Strictly scoping the patch to only agent-authored edits would require a larger follow-up change, such as capturing a baseline at conversation start.

@all-hands-bot

Copy link
Copy Markdown
Collaborator

🚦 CI is currently failing on this PR's latest commit.

Please fix the failing checks before OpenHands reviews it - this is re-checked automatically once you push a new commit. (A maintainer can also request @all-hands-bot as a reviewer to have it reviewed regardless of CI status.)

This is an automated check - no AI was used to generate this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants