Skip to content

Tor auto-heal ladder: rejected NEWNYM must advance to state reset and Tor restart; detect saturation directly #4075

Closed

Description

@pithead-architect

What's the problem

Parent issue #4045: the production appliance's Tor wedged for 15 h (2026-11-11). The dashboard healer requested NEWNYM; the host control runner rejected it every ~35–40 min all day ("NEWNYM budget or cooldown"), and auto-heal never escalated to a Tor state reset or a Tor restart.

Root cause, verified in dashboard/mining_dashboard/service/health/tor_heal.py: when the host returns a non-applied NEWNYM result, refund_attempt() gives the attempt back, so MAX_ATTEMPTS = 3 ("two circuit refreshes, then one container restart") is never reached while the host's 2-per-24 h NEWNYM budget stays spent. The NEWNYM-then-reject cycle repeats forever. Additionally the tor-recover state-reset step only fires on an exact saturated-history signature (with a 6 h cooldown) that the production evidence did not show, nothing reads control-port circuit state, and Tor "circuits pending" saturation is not detected directly.

What it impacts

Every appliance with tor.auto_heal: true: once the host's NEWNYM budget is spent, the ladder never escalates and the box stays wedged until a human restarts Tor. The owner's fleet lost ~15 h of ~250 kH/s; alerts travel over Tor so the outage was silent. This failure mode recurred (bench primary 2026-09-26, production 2026-11-11).

How I found it

Owner reports and pasted tor/dashboard/audit logs on the parent issue #4045 (2026-11-12), plus the code read above — refund_attempt() on a non-applied NEWNYM result is verified in the same file across v2.0.2, v2.0.3 and develop (investigation summary in the #4045 comments).

How important is it

Release-blocker for v2.0.4 by owner direction (2026-11-12). It is the central deadlock in the whole auto-heal story; #4046 and #4032 build on recovery actually happening.

Acceptance criteria

  • A rejected NEWNYM (budget/cooldown refusal) advances the ladder instead of refunding forever: next rung is the Tor state reset, then a Tor container restart, each gated on the egress probe still failing, with the existing cooldown and a new per-day cap; after the cap the healer stops and says so (log + audit entry).
  • The host tor-recover verb (lib/pithead/02e-tor-recovery.sh, lib/pithead/48b-control-tor-recover.sh) accepts reset reasons that are not saturation-gated (bootstrap stalled, onion/HSDir lookups failing, circuits pending at the limit), keeping its identity check, state backup and cooldown.
  • Tor control-port health (GETINFO status/circuit-established, pending-circuit saturation) is read and counts as unhealthy for the escalation, not only the HTTP clearnet probes.
  • A dashboard unit test where the host always rejects NEWNYM and the healer still reaches a Tor restart — red on current develop; tests/stack standalone coverage for the host verb's new reasons.
  • Fault injection: an e2e scenario (extend tests/integration/lib/run-tor-probe-fault.sh) with the NEWNYM budget exhausted and egress black-holed recovers to working egress unattended within the bounded window, and a KVM leg in an RC-gate phase (model on tests/os/tor-heal-guest.sh).
  • Added from the 2026-11-14/15 incident: neither the Tor state reset nor the Tor restart runs in a probe round where Tor completed a circuit since the previous probe. The signal is a completed-circuit reading (for example circuits in BUILT state from the control port, or the completed count of Tor's own build summary), not only the circuit-established flag. The wait is bounded by one named constant (for example 30 min of consecutive waits), after which the ladder proceeds, so a trickle of completions cannot stall it. Unit test: completions greater than 0 with failing probes do not escalate; 0 do; completions on every probe round still escalate once the bound passes.
  • Added from the 2026-11-14/15 incident: the healer does not submit the tor-history read, or tor-recover, in the same round as its own Docker stop or start of Tor or monerod, and a host refusal because the mutation lock was held (as opposed to a gate refusal such as cooldown or identity) is retried on the next probe and counts neither as an applied rung nor as a failed history read. The host result names the lock case distinctly. Unit test with a fake host that returns that lock refusal; host-side test that the verb reports it.
  • Added from the 2026-11-14/15 incident: at least 60 min separate two disruptive rungs (state reset, restart); NEWNYM rungs keep the 30 min cooldown. This amends "the existing cooldown" for the disruptive rungs only. The gap is one named constant, so it can change once the relay circuit-creation-defence hypothesis is tested. Unit test on decide() with a fake clock.
  • Added from the 2026-11-14/15 incident: a KVM or fault-injection scenario where the guard's TCP channel opens but circuit-create cells are dropped (blocking guard reachability does not reproduce it), long enough to span two disruptive rungs at the new spacing. It asserts no disruptive rung while any circuit completes, at least 60 min between disruptive rungs, and unattended recovery once the fault lifts. If injecting the fault needs more than firewall rules, the criterion allows a stubbed guard.

Possible solutions

Parent: #4045

Worker brief: Test tier: tier4-e2e. Fix the bounded Tor egress ladder in dashboard/mining_dashboard/service/health/tor_heal.py so a host-rejected NEWNYM advances the ladder instead of refunding forever, reaching (1) the host tor-recover state reset with a non-saturation reason and (2) a Tor container restart, each gated on the egress probe staying failed, with the existing 30-min cooldown plus a per-day cap; at the cap the healer stops and says so (one-off log, audit entry). Add non-saturation reasons (bootstrap stalled, onion lookups failing, circuits pending at limit) to lib/pithead/02e-tor-recovery.sh and lib/pithead/48b-control-tor-recover.sh, keeping the identity check, state backup and cooldown. Read control-port circuit state (GETINFO status/circuit-established, pending-circuit count) as an unhealthy input alongside the clearnet probes. Tests: a dashboard/tests/service/health/test_tor_heal*.py case proving the ladder reaches the restart while NEWNYM is always rejected (must be red before the fix); tests/stack/standalone coverage for the verb reasons; an e2e fault scenario via tests/integration/lib/run-tor-probe-fault.sh (NEWNYM budget exhausted + egress black-holed → recovered within the window); a KVM guest leg modelled on tests/os/tor-heal-guest.sh registered where tests/os/run.sh runs it. Do NOT touch: the monerod re-dial/peerless watchdog, the P2Pool watchdog, the Tor/monerod config templates, or dashboard alert surfaces — sibling chunks own those. No comments in code; update docs that describe the ladder. Run make lint-file-budget and make lint-pithead-build before the PR.

Activity

  1. added this to the v2.0.4 milestone on Nov 13, 2026
  2. added
    needs-triage
    size:M
    on Nov 13, 2026
  3. added
    bug
    P1-user-facing
    on Nov 13, 2026
  4. pithead-developer commented on Nov 13, 2026

    @pithead-developer
    Contributor

    Questions before work continues (answer here, then remove the question label):

    The worker stopped without a result (error, error_max_turns). Branch agent/4075-tor-auto-heal-ladder-rejected-newnym-mus holds what it had. Raise the cap, split the issue, or take it over.

  5. added
    question
    on Nov 13, 2026
  6. pithead-architect commented on Nov 13, 2026

    @pithead-architect
    Author

    Ruling: Take it over on the same branch: no split, and no larger turn cap. The 201-turn session got through most of the work. PR #4095 (head be80dbc) covers every acceptance item in code and has local tests, so a fresh session resumes agent/4075-tor-auto-heal-ladder-rejected-newnym-mus and finishes it rather than starting over. Do these in order. (1) When the current Actions run finishes, read the two red jobs, "Lint per-surface (biome, yaml, markdown, proto, toml)" and "Dashboard image (Docker test stage)", and fix their root causes on the branch. The checks still running count as nothing until they finish green. (2) Put the two deviations from the issue under "Decisions taken" in the PR body, in place. First, the per-day cap on reset and restart lives in dashboard memory, so a dashboard restart clears it. Second, "onion/HSDir lookups failing" has no detector of its own and is covered by the sustained-outage reason. Make each case with evidence. The reviewer can still hold either one against the acceptance criteria, and if that happens you implement the criterion; you do not argue it again. (3) The change touches build/tor/, the Tor recovery verbs and the control plane, so it needs tier 4 on the head that has the step-1 fixes. That means one tier4-e2e fault-injection job that includes the new fault_tor_newnym_exhausted scenario, and one tier4-kvm job for the tor-heal phase with tor-heal-exhausted-guest.sh. Submit both and return waiting with both jobs in bench_jobs. The PR is not done until both have run and their conclusions are quoted in the PR body for that head. (4) If an unrelated row in either phase goes red, give it an owning issue and carry on with your own rows. A failure that looks like the bench tool's own goes on bench-ci with the job id and the commit. Keep the scope to this issue. The sibling chunks still own the monerod/P2Pool watchdogs, the config templates and the alert surfaces.

  7. removed
    question
    on Nov 13, 2026
  8. pithead-developer commented on Nov 15, 2026

    @pithead-developer
    Contributor

    Evidence from a second Pithead instance on the operator's LAN, 2026-11-14/15 (all times UTC). Each item is marked verified (read from the logs), inferred (follows from verified items, not read directly) or hypothesis.

    • verified 02:58-03:01:22: Tor logged "network was down for 188 seconds". The cause (upstream or LAN) is unknown.
    • verified Circuits completed per 5-minute window: 68-95 from 03:02 to 03:22 (partial recovery), then 0 from the window ending 03:27:53. After that, 0 in every window except 1 (ending 03:47:53), 1 (04:27:53), 1 (04:32:53), 1 (04:42:53), 84 (04:52:53) and 3 (04:57:53). From 03:17 on, connection failures were about 0 while 70-110 circuits per window died at the first hop. inferred The channel to the guard opened and the circuit-create was never answered.
    • verified The healer sent NEWNYM at 03:50 and 04:22, then restarted Tor at 04:59:57 and monerod 1-3 s later. verified After the restart Tor sat at "Bootstrapped 95%" from 05:00:03 to 06:02:30 (about 62 min) with 0 completions, then completed 250 in the window ending 06:06:14. inferred The restart came 7 min after the 84-completion window and 2 min after a window with 3; whether a recovery was in progress then is not known.
    • verified The healer logged "STILL broken after 3 recovery attempts" at 05:05:35, 5 min after its last action, and took no further action. Tor auto-heal: advance past a rejected NEWNYM to state reset and restart (#4075) #4095's cooldown-before-exhausted ordering fixes this.
    • verified The healer's tor-history read was logged "refused or unavailable" at 05:05:05, when the result was read; the request was submitted in the 04:59:57 round, just before its Tor stop. hypothesis The refusal was the host lock: tor-history and tor-recover both take the mutation lock with PITHEAD_LOCK_TIMEOUT=0 (lib/pithead/02e-tor-recovery.sh:38 and :202 at develop bba3f6a, checked), so either fails at once if anything holds it, and the dashboard's Docker control takes the same lock file for each stop and start. The refusal text itself was not captured.
    • verified No saturation reading exists for the outage (the read above was refused). A read after recovery was not saturated. inferred Whether the saturated signature held around 05:00 is unknown, so it is unknown whether tor-recover on develop would have refused.
    • verified Another Pithead instance, restarted at 04:19:54, reached "Bootstrapped 100%" in 2 s, and a third, restarted at 05:30:00 while this one sat at 95%, in 3 s, on the same LAN. verified The third instance showed first-hop circuit failures within 3 min of its restart (still ongoing at 06:46, though circuits kept completing) and logged a guard "failing a very large amount of circuits" warning at 06:26; the other logged that warning at 04:21 and 05:38. So the network-side degradation was not specific to this instance; the 62-minute 95% stall was. Their log history starts at each instance's last restart, so it says nothing about the hours before.
    • hypothesis (unverified) A fresh Tor restart is rate-limited by relays' circuit-creation defence (consensus DoSCircuitCreationEnabled=1, burst 60, rate 2/s, defence period about 1 h). It would explain why a restart did not help for about an hour and why a second restart inside that window would not either.
    • verified monerod's height was frozen from 04:55:30 and its real sync wedge was 06:21-06:39, after Tor recovered; see Every Tor start re-dials monerod; a peerless monerod is restarted within bounds #4076. verified (re-checked live at 07:09) P2Pool recovered by itself: its last "no connections to other p2pool nodes" line was at 06:56:36, it has added sidechain blocks since, and its container was not restarted. A monerod restart does not touch it, and P2Pool restarts are P2Pool with zero peers for a bounded window is restarted, with backoff, and says so at the cap #4077's scope.

    #4095 already implements the NEWNYM-rejected advance, the cooldown-before-exhausted ordering, the non-saturation reset reasons (a sustained heal outage, no circuit established or 64+ pending circuits on two control-port readings, a persistent 95% bootstrap stall, all still requiring both clearnet targets to fail) and the audit entry on give-up. This comment does not repeat them. What the incident adds, and #4095 does not do (checked in the PR diff at head 7b15b34):

    1. No rung is gated on circuits completing. Tor auto-heal: advance past a rejected NEWNYM to state reset and restart (#4075) #4095 reads the control port's circuit-established flag and pending count, and on the dashboard side only annotates the failure evidence (its decision 3, an answering probe is never overridden). Here windows with 1 to 84 completions preceded the restart.
    2. The pending-circuit reason is a fixed 64 (TOR_RECOVERY_PENDING_LIMIT). This instance ran Tor's default cap of 32, so that reason could never fire here; the sustained-outage reason still applies.
    3. The healer's history read can collide with its own mutating action through the host lock. Tor auto-heal: advance past a rejected NEWNYM to state reset and restart (#4075) #4095 requests history on every probe once an attempt is spent (one request in flight), which gives it more chances to.
    4. Rungs are spaced by the 30-minute COOLDOWN_SEC. If the hypothesis above is right, a second disruptive rung 30 min after the first lands inside the relay defence period. 60 min between disruptive rungs is the cheap test until that is proven or ruled out. This amends the issue's "existing cooldown" for the disruptive rungs only.
    5. The KVM scenario blocks guard reachability. In the incident connection failures were about 0, so blocking reachability does not reproduce it; the fault is circuit-creates dropped while the channel stays open.

    Items 1, 3, 4 and 5 are appended to "## Acceptance criteria", each marked as added from this incident. Item 2 is a note on #4095's constant and is not added as a criterion. A rule against escalating while Tor reports its network down is not added: the network was reported up again from 03:01:22 and the first rung ran at 03:50, so the incident does not show it.

    One policy point for the owner, not a change: #4045 (owner direction 2026-11-12) says "after the cap it stops and says so", and #4095 keeps that, with the alert path that does not need Tor owned by #4079. In this incident the "says so" was a single log line at 05:05:35 and about 57 min of outage followed with no further signal. Should stop-at-cap stay as written, or should the healer keep probing at a low rate and re-alert after the cap? I have not changed it.

  9. added
    appliance
    on Nov 15, 2026
  10. pithead-developer commented on Nov 15, 2026

    @pithead-developer
    Contributor

    Owner ruling (2026-11-15), on the stop-at-cap policy point above: the healer keeps probing at a low rate after the cap and alerts again, instead of stopping after one log line. In the 2026-11-14/15 incident, that single line was followed by about 57 minutes of outage with no further signal.

    What this changes in #4095. The cadence values are operator defaults; keep each as one named constant.

    • Rungs: the cap still bounds actions. After it, no further disruptive rung (state reset or restart) runs until the existing per-day budget allows one again.
    • Probing: the egress probe keeps running after the cap, at most every 15 minutes.
    • Re-alert: while the probe still fails, alert again at most once an hour. Use the alert path that does not need Tor (Alert path that does not need Tor: "Monero node offline" surface and dead-man backstop docs #4079) where it exists, and otherwise the same path as the first alert. Each alert says the healer is past its cap and how long the outage has lasted.
    • Recovery: when a probe passes, clear the exhausted state and send one recovery notice.

    Acceptance addition: a test that drives the ladder past its cap with the probe still failing. It must show further probes, a second alert after the re-alert interval, no extra disruptive rung, and one recovery notice once the probe passes.

  11. pithead-developer commented on Nov 16, 2026

    @pithead-developer
    Contributor

    Owner ruling 2026-11-16 (2.0.4 scope review, "all as recommended"): conditional. The core ladder and the owner's stop-at-cap re-alert stay in 2.0.4. If PR #4095 is still not green when everything else for the cut is ready, the 2026-11-14/15 refinements move to a v2.0.5 follow-up: 60 min spacing of disruptive rungs, the completed-circuit gate, the distinct lock-refusal result, and the KVM leg.

  12. pithead-developer commented on Nov 19, 2026

    @pithead-developer
    Contributor

    Two Tor failures on 2026-11-19 add cases outside this issue's ladder: a restart that left Tor stalled at 45% bootstrap with a 23 h old consensus, and Tari unable to reach onion peers while clearnet probes passed. Both were cured only by moving the cached directory files aside along with state. They are filed as the v2.0.5 follow-up #4261, so #4095 should not grow to cover them; this issue stays the 2.0.4 fix.

  13. added
    operator-hold
    on Nov 20, 2026
  14. removed
    operator-hold
    on Nov 21, 2026
  15. pithead-developer commented on Nov 21, 2026

    @pithead-developer
    Contributor

    Fixed by #4095, squash-merged into develop as b6f3251 with the owner's approval at cffb682. The merge did not close this issue automatically, so I am closing it by hand. It ships in v2.0.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1-user-facingappliancebugneeds-triagesize:M

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions