Commit 2660430
Normalize (or refuse) in publish_task's raw-apply fallback (#58)
## Problem
Observed on transformers PR
[#47281](huggingface/transformers#47281): a
serge task fixed a `glm46v` integration failure by editing
`modular_glm4v.py` (the modular *source*), but the opened PR contained
**only** that one file — the regenerated `modeling_glm4v.py` /
`modeling_glm46v.py` were missing. So the fix never reached the
generated file that actually runs, and the PR trips transformers' own
`repo-consistency` / `modular_conversion` CI.
## Root cause
The task ran the normalizer (`… utils/checkers.py …,modular_conversion,…
--fix`) inside the in-loop validation gate (`_validate_patch`), which
regenerates the `modeling_*.py` files into the worktree. But that task
exhausted its correction budget (`TASK_NORMALIZE_MAX_RETRIES`) without a
passing validation, so:
1. `prepare_task` saw `outcome["prepared"] == False` and **reset the
worktree** (discarding the regenerated files), and
2. `publish_task` took its **raw-apply fallback** — re-applying
`plan.patch` to a pristine checkout **without running the normalizer** —
so `collect_changes` saw only the one hand-edited file (`Change touches
1 file(s)`).
The fallback existed for "no normalizer configured / validation
abandoned", but for a repo with a modular/generated-file invariant it
silently shipped a repo-inconsistent patch.
## Fix
In `publish_task`'s fallback path, when a normalizer **is** configured:
- run it after applying the patch so any regenerated files are staged
into the commit, and
- **refuse** (return `no_change`) rather than open a PR the normalizer
rejects — never commit a raw, repo-inconsistent patch.
The shared `run_normalize` invocation is extracted into
`_run_repo_normalizer` (returncode `None` = infrastructure failure →
best-effort accept, preserving prior behavior) and reused from both
`_validate_patch` and `publish_task`.
## Tests
`PublishFallbackNormalizeTests` covers:
- normalizer regenerates a file → **both** patched + generated files
ride along in the commit;
- normalizer exits non-zero → **no PR**, worktree reset;
- no normalizer configured → raw patch committed unchanged (no
regression).
`pytest tests/test_tasks.py` → 34 passed. `ruff format` + `ruff check`
clean.
## Follow-ups (not in this PR)
- The task also burned its entire input-token budget *exploring* before
writing a patch, leaving no room to iterate — worth guarding.
- Consider bumping `TASK_NORMALIZE_MAX_RETRIES` so genuinely-fixable
patches converge before the budget runs out.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent f936ee1 commit 2660430
2 files changed
Lines changed: 194 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
316 | 316 | | |
317 | 317 | | |
318 | 318 | | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
319 | 358 | | |
320 | 359 | | |
321 | 360 | | |
| |||
366 | 405 | | |
367 | 406 | | |
368 | 407 | | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | | - | |
377 | | - | |
378 | | - | |
379 | | - | |
380 | | - | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
390 | 412 | | |
391 | 413 | | |
392 | 414 | | |
| |||
756 | 778 | | |
757 | 779 | | |
758 | 780 | | |
759 | | - | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
760 | 784 | | |
761 | 785 | | |
762 | 786 | | |
| |||
780 | 804 | | |
781 | 805 | | |
782 | 806 | | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
783 | 831 | | |
784 | 832 | | |
785 | 833 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
521 | 521 | | |
522 | 522 | | |
523 | 523 | | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
524 | 648 | | |
525 | 649 | | |
526 | 650 | | |
| |||
0 commit comments