Skip to content

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

Closed

Description

@thiras

Summary

e2e_onchain_payment_channel_settlement (crates/node/tests/anvil_settlement_e2e.rs) intermittently fails during contract deployment in a way the existing retry logic does not recover from. This is a follow-up to the now-closed #785 (unbounded deploy hang → bounded timeout + retry): #785 made stalls retryable, but a transient non-zero exit during the forge broadcast phase is still treated as a hard, non-retryable failure and fails the whole test.

Observed on CI for an unrelated node-crate PR (#882): run 27443826381, job anvil e2e. The PR touches only the node→node buyer-side pull reputation path; it does not touch contracts, PaymentChannel settlement, or anvil, so the failure is purely infrastructural.

What happened

WARN anvil_settlement_e2e: forge script DeployProtocol attempt 1/2 stalled, retrying after 45s
Error: forge script DeployProtocol exited non-zero:
No files changed, compilation skipped
Script ran successfully.
== Return ==
d: struct BaseProtocolDeploy.Deployment Deployment({ token: 0x959…, …, paymentChannel: 0x4ed…, … })

## Setting up 1 EVM.
  • Attempt 1 hit DEPLOY_TIMEOUT (45s) and was killed — the Flaky anvil-e2e: forge script deploy subprocess hangs unbounded, freezing the test for minutes #785-handled stall path, correctly retried.
  • Attempt 2 ran ~27s and exited non-zero, but its stdout shows the Solidity script body completed: Script ran successfully, a full Deployment { … } struct was returned, and output then cut off at ## Setting up 1 EVM. — i.e. the failure was in the broadcast/transaction-submission phase, not the script logic.
  • run_deploy_script (anvil_settlement_e2e.rs:~1240) classifies any non-zero exit as deterministic and bail!s immediately:
// A *non-zero exit* (revert, script bug, RPC rejection) is almost always
// deterministic, so it fails fast ... rather than retrying a guaranteed-
// identical failure.
Ok(out) => anyhow::bail!("forge script DeployProtocol exited non-zero:\n{}\n{}", …),

The test failed at ~72s, well under OVERALL_TIMEOUT (780s), so the overall guard never engaged.

Root cause

The "non-zero exit is deterministic" assumption does not hold for the broadcast phase: once the script body has produced a Deployment, a non-zero exit is almost always a transient RPC/nonce/anvil hiccup under CPU contention (the same contention #785 cites for stalls), not a revert or script bug. Those transient broadcast failures are exactly the ones worth retrying, but the loop only retries the Err(timeout) (stall) arm.

Impact

Blocks merges on unrelated PRs (the only fix today is a manual re-run), and silently re-tars the test's reliability for changes that have nothing to do with on-chain settlement.

Possible directions (not yet decided)

  1. Retry broadcast-phase non-zero exits too, distinguished from genuine reverts. A real revert/script bug surfaces a Revert/Error line or omits the Script ran successfully / Return block; a broadcast hiccup shows the script succeeded then failed during Setting up … EVM / broadcast. Retry only when the script-success markers are present (so true reverts still fail fast with full output).
  2. Reduce broadcast contention — e.g. --slow on the forge broadcast, or a small inter-tx delay, to cut the RPC-races that produce these non-zero exits.
  3. Treat any forge deploy failure (stall or non-zero) as retryable up to DEPLOY_ATTEMPTS, surfacing the last attempt's full output. Simpler but loses the fast-fail on genuine reverts — acceptable since DEPLOY_ATTEMPTS is small (2).
  4. Fix the misleading log: retrying after {timeout:?} prints the stall duration (DEPLOY_TIMEOUT), implying a 45s sleep that doesn't happen (the loop retries immediately). Minor, but it confused diagnosis here.

Not caused by

PR #882 — included only as the run where this surfaced.

Activity

  1. added
    prio:medium
    rust
    kind:test
    on Jun 12, 2026
  2. added
    kind:bug
    on Jun 12, 2026
  3. github-actions commented on Jun 12, 2026

    @github-actions

    🎯 Triage report

    A second mode of forge deploy flakiness in anvil_settlement_e2e — transient non-zero exits during the broadcast phase — slips through the retry logic introduced in #785, which only retried on stall/timeout. The issue provides a concrete CI failure trace (run 27443826381), identifies the exact line in run_deploy_script (~L1240) where the hard bail happens, and proposes four concrete fix directions with clear tradeoffs. Actively blocks merges of unrelated PRs, requiring manual re-runs.

    📊 Assessment

    Dimension Value Reasoning
    Type Bug Infrastructure reliability regression; CI flakiness blocking PR merges
    Labels bug added; existing technical, medium, rust, testing retained bug was absent but clearly applicable; medium priority is consistent with the author's assessment (blocks PRs but has a manual workaround — re-run)
    Coding agent Suitable Root cause pinned to a specific function and file, multiple concrete fix options described, clear pass/fail criteria (broadcast-phase non-zero → retry; genuine revert → bail), and the change is self-contained to the test helper

    🔗 Similar issues

    💡 Notes and suggestions

    Key diagnostic signal (for the fix author): the difference between a transient broadcast failure and a genuine revert can be reliably detected via stdout content:

    • Transient broadcast failure: stdout contains Script ran successfully. + a Return ==/Deployment { ... } block, then cuts off at ## Setting up 1 EVM.
    • Genuine revert / script bug: Revert/Error line present, or the Script ran successfully. / Return block is absent entirely

    Recommended approach — direction 1 (smartest retry):
    In run_deploy_script, on a non-zero exit, inspect stdout for the script-success markers before deciding whether to bail or retry. Pseudocode:

    Ok(out) => {
        let stdout = String::from_utf8_lossy(&out.stdout);
        let script_succeeded = stdout.contains("Script ran successfully.")
            && stdout.contains("== Return ==");
        if script_succeeded && attempt < DEPLOY_ATTEMPTS {
            warn!("broadcast-phase failure on attempt {attempt}, retrying");
            continue; // retry loop
        }
        bail!("forge script DeployProtocol exited non-zero:\n...");
    }

    This preserves fast-fail on genuine reverts while making broadcast hiccups retryable.

    Direction 3 (simpler): If the marker-inspection approach feels fragile, treating all non-zero exits as retryable up to DEPLOY_ATTEMPTS (already small at 2) is a safe fallback — worst case you see one extra attempt on a real revert, which still fails with the full output.

    Direction 4 (quick win, independent): Fix the misleading retrying after {timeout:?} log — it implies a 45s sleep but the loop retries immediately. This is a one-line fix and should be done regardless of which retry strategy is chosen.

    Also consider: adding --slow to the forge script --broadcast invocation (direction 2) as defense-in-depth; it reduces inter-tx RPC races that cause these broadcast hiccups without changing retry logic.

    Sub-task checklist:

    • Fix run_deploy_script to retry broadcast-phase non-zero exits (directions 1 or 3)
    • Fix misleading retrying after {timeout:?} log message (direction 4, independent)
    • (Optional) Add --slow to forge broadcast invocation to reduce RPC contention
    • Verify the fix against the failure pattern from run 27443826381

    Generated by Agentic Triage for issue #883 · ◷

    Add this agentic workflows to your repo

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/issue-triage.md@94ec5db57374c5b04a4b8eef8b4413f9af44d63f
    
  4. yigitdot commented on Jun 13, 2026

    @yigitdot
    Contributor

    Recurred on CI for PR #886 (a node-only region-accounting change that touches no contracts/anvil — purely infrastructural): stall on deploy attempt 1, then a broadcast-phase non-zero exit on attempt 2 (Failed to send transaction after 4 attempts … replacement transaction underpriced / nonce too low, error -32003), with the script body itself having completed (Script ran successfully + a full Deployment { … } returned).

    On re-running: it's a real but unreliable workaround. Because the failure is driven by runner CPU contention, a re-run often clears it — but not always. The retry budget is only DEPLOY_ATTEMPTS = 2, and both the stall path and the broadcast-race path draw from it; this run burned attempt 1 on a stall and attempt 2 on a broadcast hiccup, so the whole test failed with no attempts left. A fresh CI re-run can land in the same contention and fail again. So 'just re-run it' sometimes works, sometimes doesn't, and it always costs a manual round-trip on PRs unrelated to on-chain settlement.

    Suggestion (durable fix, in run_deploy_script):

    1. Add --slow to the forge broadcast so transactions are submitted sequentially and each receipt is awaited before the next — removes the concurrent-send nonce too low / replacement transaction underpriced class at the source (negligible wall-clock on instant-mining anvil).
    2. Make broadcast-phase non-zero exits retryable, distinguished from genuine reverts by the Script ran successfully marker (present → script body completed → transient broadcast failure → retry; absent → real revert/script bug → fail fast with full output, as today).
    3. Bump DEPLOY_ATTEMPTS to 3 for headroom, since stalls and broadcast hiccups now share one budget.

    Until that lands, re-running remains the only mitigation and is not guaranteed to pass.

  5. self-assigned this
    on Jun 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind:bugkind:testprio:mediumrust

Type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions