Skip to content

fix(node): retry forge DeployProtocol broadcast-phase non-zero exits (#883) - #897

Merged
thiras merged 2 commits into
mainfrom
fix/883-retry-broadcast-phase-deploy
Jun 13, 2026
Merged

thiras merged 2 commits into
mainfrom
fix/883-retry-broadcast-phase-deploy

Conversation

@thiras

@thiras thiras commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #883. The anvil-e2e forge DeployProtocol deploy retry loop (crates/node/tests/anvil_settlement_e2e.rs) only retried stalls (timeouts, #785). A transient non-zero exit during forge's broadcast / tx-submission phase — where the script body already completed (Script ran successfully printed, full Deployment struct returned) but tx submission hit a nonce/RPC/anvil hiccup under CPU contention — was misclassified as a deterministic failure and bailed immediately, flaking unrelated PRs (observed on #882, which touches no contracts).

The observed flake was stall-then-broadcast-hiccup: attempt 1 stalled (correctly retried), attempt 2 hit a broadcast-phase non-zero exit. With only 2 attempts both transient classes were exhausted and the test failed at ~72s, far under OVERALL_TIMEOUT (780s).

Changes

  • Classify non-zero exits via a new pure forge_script_body_completed(stdout) -> bool helper (keys on forge's Script ran successfully marker): present ⇒ transient broadcast hiccup ⇒ retry; absent ⇒ genuine revert/script bug ⇒ fail fast with full output.
  • Bump DEPLOY_ATTEMPTS 2 → 3 — the two now-retryable classes (stall + broadcast hiccup) can each consume an attempt, so 2 couldn't recover the observed sequence. Worst case 3×45s = 135s, safely inside OVERALL_TIMEOUT.
  • Fix the misleading log (Flaky anvil-e2e: forge DeployProtocol broadcast-phase non-zero exit isn't retried (only stalls are) #883 note 4): "retrying after {timeout}" implied a 45s sleep that never happens → "stalled (killed after {timeout}), retrying immediately".
  • 3 classifier unit tests (marker present / genuine revert / empty), running as plain #[test] fns in the anvil e2e CI binary — no anvil/forge needed.

Why not the other directions in the issue

  • Direction 2 (--slow / inter-tx delay): would lengthen every deploy and risk tripping DEPLOY_TIMEOUT; not needed once retries cover the hiccup.
  • Direction 3 (retry all non-zero exits): loses fast-fail on genuine reverts; the marker-based classifier keeps real bugs surfacing immediately.

Known limitation

The retry-loop decision matrix (the stall-then-broadcast-hiccup last-attempt bail) is exercised only against live forge, not unit-tested — run_deploy_script invokes forge inline, so making the loop unit-testable would require unix-only std::process::Output construction or splitting decision from message-formatting (a worse abstraction for CI test infra). The genuinely-new logic (the classifier) is extracted and unit-tested; the loop is 4 plain arms. Deferred deliberately.

Verification

cargo clippy -p decdn-node --tests --features anvil-e2e -- -D warnings   # clean
cargo fmt -- --check                                                     # clean
cargo nextest run -p decdn-node --features anvil-e2e \
  -E 'test(/retryable|fails_fast/)'                                      # 3 passed

The full live e2e (needs foundry) relies on CI; the flake is non-deterministic, so the fix is pinned by the unit-tested classifier rather than by forcing a live broadcast failure.

🤖 Generated with Claude Code

…883)

The anvil-e2e deploy retry loop only retried *stalls* (timeouts, #785); a
transient non-zero exit during the forge broadcast / tx-submission phase —
where the script body already completed (`Script ran successfully`) but tx
submission hit a nonce/RPC/anvil hiccup under CPU contention — was treated as
a deterministic failure and bailed immediately, flaking unrelated PRs.

- Classify non-zero exits via `forge_script_body_completed` (success-marker
  present ⇒ transient broadcast hiccup ⇒ retry; absent ⇒ genuine revert/script
  bug ⇒ fail fast with full output).
- Bump DEPLOY_ATTEMPTS 2 → 3: the observed flake was stall-then-broadcast-hiccup,
  two now-retryable classes that each consumed an attempt, so 2 was insufficient.
- Fix the misleading "retrying after {timeout}" log (#883 note 4) that implied a
  45s sleep that never happens — the retry is immediate.
- Unit-test the classifier (retryable broadcast failure, genuine revert, empty).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings June 13, 2026 17:23
@thiras thiras self-assigned this Jun 13, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request improves the resilience of the end-to-end anvil settlement tests by handling transient forge script failures during the broadcast phase. It increases the deployment attempts to 3 and introduces a helper function forge_script_body_completed to detect if a non-zero exit occurred after the script body successfully completed (indicating a transient broadcast/RPC issue rather than a deterministic revert). It also adds unit tests for this classification logic. The reviewer suggested optimizing the forge_script_body_completed function to perform a zero-allocation byte search on the stdout slice instead of allocating a new string via String::from_utf8_lossy.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reduces flakiness in the anvil-e2e integration test by retrying forge script DeployProtocol when it exits non-zero after the Solidity script body has already completed (i.e., failures in the broadcast/tx-submission phase), and by increasing deploy attempts to accommodate both stalls and broadcast hiccups.

Changes:

  • Add forge_script_body_completed(stdout) classifier (based on the Script ran successfully marker) and unit tests for the classifier.
  • Update the deploy retry loop to retry broadcast-phase non-zero exits, and bump DEPLOY_ATTEMPTS from 2 → 3.
  • Improve retry logging for stall timeouts to clarify that retries are immediate (no sleep).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…review)

The last-attempt bail messages claimed all attempts shared one failure mode
("…in the broadcast phase on all attempts" / "stalled on all attempts"), but
with mixed retryable modes (e.g. the stall-then-broadcast-hiccup sequence this
PR targets) only the final attempt's mode is known. Reword both to describe the
final attempt rather than asserting uniformity across attempts.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@github-actions

Copy link
Copy Markdown

Coverage report

Total: 86.01% (was 86.01%, ● 0.00%) — 35598/41387 lines

No coverage data for changed Rust files.

History
Commit Total Δ vs base
af3471e (HEAD) 86.01% ● 0.00%

@thiras
thiras merged commit 862b35f into main Jun 13, 2026
20 checks passed
@thiras
thiras deleted the fix/883-retry-broadcast-phase-deploy branch June 13, 2026 17:36
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.

Flaky anvil-e2e: forge DeployProtocol broadcast-phase non-zero exit isn't retried (only stalls are)

2 participants