Skip to content

fix(swe-smith): parse pytest statuses that include ANSI color - #599

Merged
Zhiyuan He (hzy46) merged 2 commits into
microsoft:mainfrom
xccElephant:fix/smith-agent-ansi-status-parser
Sep 17, 2026
Merged

Zhiyuan He (hzy46) merged 2 commits into
microsoft:mainfrom
xccElephant:fix/smith-agent-ansi-status-parser

Conversation

@xccElephant

@xccElephant Xiang Chucheng (xccElephant) commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Summary

SmithAgent grades SWE-smith rollouts by regex-matching PASSED/FAILED in pytest -rA output. When pytest emits ANSI color (a repo addopts = --color=yes, PY_COLORS=1, or a TTY), those codes glue themselves to the status token:

ESC[32mPASSEDESC[0m tests/test_demo.py::test_ok

parse_test_statuses() never sees a bare PASSED, so a fully green suite is scored 0/N. This is a false negative in the reward, not a failed test.

This PR:

  • strips ANSI escape sequences before parsing status lines
  • runs pytest with --color=no so the evaluator does not depend on TTY or repo color settings

This does not change SWE-bench Verified scoring, which uses the official swebench harness rather than this parser.

Validation

PYTHONPATH=. python -m pytest tests/examples/test_swe_smith_agent.py -q
# 27 passed
uvx ruff check examples/swe_smith/agents/smith_agent.py tests/examples/test_swe_smith_agent.py
uvx ruff format --check examples/swe_smith/agents/smith_agent.py tests/examples/test_swe_smith_agent.py

Reproduced locally on cantools SWE-smith instances whose pytest log showed 185 passed while the parser reported FAIL_TO_PASS 0/60. After stripping ANSI, all 185 nodes parse as PASSED.

AI assistance: Cursor Grok 4.6 helped investigate, implement, and validate this change. I reviewed the diff and ran the checks above.

Pytest color codes glue themselves to PASSED, so the reward parser
misses every passing node and scores a green suite as 0/N.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copilot AI balanced review requested due to automatic review settings September 16, 2026 14:14

Copilot AI 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.

🟢 Approval recommended

The reviewed changes address the parsing issue and include regression coverage.

Pull request overview

Fixes SWE-smith pytest status parsing when ANSI color codes surround test results.

Changes:

  • Strip ANSI escape sequences before parsing statuses.
  • Force pytest color output off during evaluation.
  • Add regression tests.
File summaries
File Description
tests/examples/test_swe_smith_agent.py Tests ANSI parsing and pytest command construction.
examples/swe_smith/agents/smith_agent.py Implements ANSI stripping and disables pytest colors.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite (auto)

Note

Copilot is running an experiment and ran this review at Lite.


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@xccElephant

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@hzy46

Copy link
Copy Markdown
Contributor

Thank you for this contribution.

Please remove the test here as we have already had a lot of tests.

I am checking with our team member about this issue. If confirmed, we will merge your PR.

Co-authored-by: Cursor <cursoragent@cursor.com>
@xccElephant

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I have removed the extra tests as requested.

The remaining change is only in examples/swe_smith/agents/smith_agent.py: strip ANSI before parsing pytest statuses, and run pytest with --color=no.

@ldemon2333 Ldemon (ldemon2333) 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.

accept pr for --color=no

@hzy46
Zhiyuan He (hzy46) merged commit ff94575 into microsoft:main Sep 17, 2026
6 checks passed
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.

4 participants