Skip to content

Add AI advisor dispatch to autorevert lambda (shadow mode)#7839

Merged
izaitsevfb merged 3 commits intomainfrom
autorevert-advisor-integration
Mar 19, 2026
Merged

Add AI advisor dispatch to autorevert lambda (shadow mode)#7839
izaitsevfb merged 3 commits intomainfrom
autorevert-advisor-integration

Conversation

@izaitsevfb
Copy link
Copy Markdown
Contributor

Summary

Adds shadow-mode AI advisor dispatch to the autorevert lambda. When a clean failure partition is detected (2+ failures, 1+ success, no unknown gap), the lambda dispatches the claude-autorevert-advisor.yml workflow (pytorch/pytorch#177404) for AI-powered failure analysis.

Shadow mode: verdicts are not consumed — dispatch is fire-and-forget for accuracy data collection.

Changes

  • DispatchAdvisor dataclass emitted from process_valid_autorevert_pattern() (pure functional)
  • SignalActionProcessor.dispatch_advisors() — shuffled dispatch with per-signal dedup and cap (8 per workflow+commit)
  • AdvisorAction enum (skip/log/run), CLI --advisor-action, env ADVISOR_ACTION
  • Logged to misc.autorevert_events_v2 as action='advisor'
  • Signal pattern JSON written to /tmp/advisor-patterns/ for debugging
  • HUD: "AI" badge on outcome cells + advisor dispatch summary table
  • State JSON: optional advisor_dispatches key (forward/backward compatible)
  • Default: AdvisorAction.RUN (lambda dispatches advisors on deploy, no gha-infra changes needed)

Test plan

  • 122 tests passing (19 new covering DispatchAdvisor, execute_advisor, dispatch_advisors, signal pattern JSON, cap/dedup)
  • Deploy and monitor shadow-mode dispatches via ClickHouse + HUD

When autorevert detects a failure pattern with a clean partition (2+
failures, 1+ success, no unknown gap), it dispatches the Claude
autorevert advisor workflow for analysis. Shadow mode: the verdict
is not consumed yet — dispatch is fire-and-forget for data collection.

- DispatchAdvisor emitted from process_valid_autorevert_pattern()
- SignalActionProcessor.dispatch_advisors() handles shuffle, dedup, cap (8/wf+commit)
- Logged to misc.autorevert_events_v2 as action='advisor'
- Signal pattern JSON written to /tmp for debugging
- HUD shows "AI" badge and advisor dispatch table
- AdvisorAction enum (skip/log/run), default: run
- 122 tests passing (19 new)
@pytorch-bot pytorch-bot bot added the ci-no-td label Mar 13, 2026
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
torchci Ignored Ignored Preview Mar 19, 2026 5:13pm

Request Review

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 13, 2026
- Cap successful+prior commits to 12 total (trim oldest prior)
- Update prior partition label to avoid misleading the advisor
  about pre-existing failures
@izaitsevfb
Copy link
Copy Markdown
Contributor Author

Evaluation Results (pytorch/pytorch, 2026-03-19)

Manually dispatched 5 advisor runs on real trunk signals. State at time of testing:

# PR Signal Verdict PR Status Correct? Links
1 #177302 inductor-test / test garbage @ 0.85 Merged NO — false positive, signal was legit advisor · failure
2 #177707 inductor-test / test not_related @ 0.95 Merged, Reverted YES — vllm pin change unrelated to inductor benchmarks advisor · failure
3 #177446 lintrunner-pyrefly-all revert @ 0.95 Merged, Reverted YES — type widening caused pyrefly errors advisor · failure
4 #177308 linux-jammy / test revert @ 0.95 Merged, Reverted YES — slice changes broke xfail expectations advisor · failure
5 #176895 test_pipeline_parallel_manual_seed revert @ 0.99 Merged YES — DTensor comparison TypeError advisor · failure

4/5 correct. Run 1 used the old prompt format (before the v3 flattened signal pattern + prior partition label fix). Runs 2-5 used the current prompt and were all correct.

@izaitsevfb izaitsevfb requested a review from jeanschmidt March 19, 2026 17:47
@izaitsevfb izaitsevfb merged commit a235b1b into main Mar 19, 2026
11 checks passed
@izaitsevfb izaitsevfb deleted the autorevert-advisor-integration branch March 19, 2026 21:09
izaitsevfb added a commit that referenced this pull request Apr 2, 2026
## Summary

Closes the loop on the AI advisor: autorevert now reads verdict results
from `misc.autorevert_advisor_verdicts` (populated via S3 ingestion from
the advisor workflow) and uses them to make faster decisions.

## Verdict Handling

| Advisor Verdict | Autorevert Action |
|----------------|-------------------|
| `revert` | Produce `AutorevertPattern` immediately — skip restarts |
| `not_related` | Early exit as `Ineligible(ADVISOR_NOT_RELATED)` |
| `garbage` | Suppress signal for 2h since verdict timestamp |
| `unsure` | Continue normal restart-to-confirm flow |

## Changes

- **`signal.py`**: `AdvisorVerdict` enum, `AIAdvisorResult` dataclass,
`SignalCommit.advisor_result` field, `_check_advisor_verdict()` method,
restructured `process_valid_autorevert_pattern()` (flakiness check moved
after advisor)
- **`signal_extraction_datasource.py`**: `fetch_advisor_verdicts()` — CH
query for verdicts by commit SHAs
- **`signal_extraction.py`**: `_attach_advisor_verdicts()` —
post-processing step that wires CH data to SignalCommit objects
- **`tests/test_signal.py`**: 8 new tests covering all verdict types, 2h
expiry, signal key matching, flaky signal handling

## Dependencies

- [#7839](#7839) (merged) —
advisor dispatch from lambda
- [#7906](#7906) (merged) — CH
table + S3 ingestion
-
[pytorch/pytorch#178810](pytorch/pytorch#178810)
(pending) — workflow S3 upload step

## Test plan

- [x] 60 tests passing (8 new)
- [x] End-to-end verified: ciforge advisor run → S3 → CH → row queryable
- [ ] Deploy and verify verdicts are read during live autorevert runs


tested locally:

```
python -m pytorch_auto_revert --dry-run autorevert-checker trunk --hours 18  --as-of "2026-03-31 18:12" --hud-html
python -m pytorch_auto_revert --dry-run autorevert-checker trunk --hours 18   --hud-html
```
example of the result:

[2026-04-01T00-11-54.124373-00-00.html](https://github.com/user-attachments/files/26392664/2026-04-01T00-11-54.124373-00-00.html)



[2026-04-01T01-22-24.845831-00-00.html](https://github.com/user-attachments/files/26393283/2026-04-01T01-22-24.845831-00-00.html)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-no-td CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants