fix(pr_agent/algo/utils.py): returning an empty dict when every yaml fallback fails - #2730
Conversation
PR Summary by QodoFix load_yaml to return {} on total parse failure; harden code suggestions parsing
AI Description
Diagram
High-Level Assessment
Files changed (3)
|
Code Review by Qodo
1.
|
|
Code review by qodo was updated up to the latest commit d8de789 |
|
#2618 just landed and wrapped the |
|
Thanks for this, and sorry for the wait. #2618 just landed. #2618, #2622 and #2061 have each added Six one-line swaps to |
…seable ai prediction
…st code_suggestions value
d8de789 to
7e26d3e
Compare
Returning an empty list stopped the chunk from raising, so The-PR-Agent#2867's coverage footer counted it as successful and a partial run reported as a complete one. Record the parse failure and add it to failed_chunk_count. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Thanks for this, and for coming back with the tests this morning. One thing it was going to break: #2867 landed today and warns when only part of a run succeeded, and returning a clean empty list meant a failed chunk no longer got counted, so a partial run would have reported as a complete one. I have pushed the small fix for that with a test, rather than send it back to you over one line. Merging. |
IsmaelMartinez
left a comment
There was a problem hiding this comment.
Green on the new head. Approving.
Closes #2729.
Description
When every YAML fallback fails,
load_yamlreturnsNone; nine callers across five tools assume a dict and raise instead of taking their graceful path.Root cause
load_yamlhas noreturnon its final failure path, so it falls off the end and yieldsNone.Every caller was written against the documented contract of "a dict", and the guards they contain
(
'key' not in data,data.get(...)) are exactly the expressions that raise onNone.The fix
load_yamlreturns{}instead ofNoneon total failure, so every existing'key' not in dataand
data.get(...)guard starts working as written.pr_code_suggestions._prepare_pr_code_suggestionsgains the explicit guard its siblings alreadyhave: a non-dict or
code_suggestions-less payload is logged with the raw prediction and returns{'code_suggestions': []}.Behaviour change
TypeError/AttributeErrorinside the toolFiles changed
Testing
New regression coverage in
tests/unittest/test_load_yaml_unparseable.py— 7 tests, each written to failwithout the fix:
Proven to be a genuine regression test: with every changed
pr_agent/file reverted to itsorigin/mainversion and the new test file left in place, the suite fails. It only passeswith the fix applied.
Full pipeline, reproduced locally exactly as
.github/workflows/build-and-test.yamlruns it:on
python:3.12.13-slim— no failures.Also checked:
pytest tests/unittest— no new failures vsmainruff— no new findings vsmain;isort— clean on every file touchedRisk / compatibility
{}is falsy, soif not data:checks behave identically toNone. Callers that explicitlycompare against
Nonewere checked — there are none.Checklist