← Back to Pull requests

feat(ymax-planner): fall back to another Agoric RPC when the preferred one is down #12975

Open
unknown opened this pull request with 555 lines diff across 6 files
View on GitHub
unknown unknown commented on Nov 19, 2026 11:09 UTC
Author

refs: AGO-1591

Description

The ymax planner used the single Agoric RPC from AGORIC_NET for everything, so an outage or stall of the dedicated follower stopped the planner. It now falls back to other RPCs and returns to the preferred one when that recovers.

  • Selection at startup (src/agoric-rpc.ts, new): the planner tries the first RPC from AGORIC_NET, then each one in the new AGORIC_RPC_FALLBACKS setting, and uses the first healthy one. If none is healthy (as during a chain halt, when no node has a recent block), it uses the first that serves the expected chain, logs a 🚨 error, and waits.

  • Health check: within 15 s, the node must open a websocket, report the expected chain in status, not be catching up, have a block from the last 60 s, and answer a vstorage query. The query is there because a degraded node can answer status promptly while its queries take minutes.

  • Wrong chain: an endpoint that serves another chain is a configuration error. It fails startup and does not trigger a fallback.

  • One endpoint for everything: the chosen RPC is used for block following, queries, vstorage reads and transaction broadcasts.

  • Switching while running (waitForAgoricRpcSwitch): once a minute, the planner checks the RPC it is using over a separate connection, and whether its subscription got a new block since the previous check. It exits so that a restart selects again if that RPC fails 3 checks in a row or stalls, but only while another RPC passes the check. During a chain halt every node fails, so the planner stays.

  • Running on a fallback: the planner logs a 🚨 error at startup. Once the preferred RPC passes 5 health checks in a row, the planner exits so that the restart returns to it.

  • Config (src/config.ts): AGORIC_RPC_FALLBACKS is a comma-separated list of URLs, empty by default on every cluster.

  • Fix: unsubscribe no longer sends a request on a closed socket, which left an unhandled "already closed" rejection after a socket failure.
  • CosmosRPCClient no longer fails a quiet subscription itself; it exposes notificationCount() so the caller can tell a stalled subscription apart. Its WebSocket option is typed structurally (RpcWebSocket), listing only what it uses, so tests can supply a fake without casts.

    Most critical to review: src/agoric-rpc.ts and the startup and shutdown changes in src/main.ts.

    Security Considerations

    When fallbacks are configured, the planner may read chain state from, and broadcast through, those RPCs as well as the preferred one. Each endpoint's chain ID is checked before use.

    Scaling Considerations

    When a fallback is configured, one short-lived websocket connection with a status request and a small query per minute to the RPC in use, and while on a fallback, another to the preferred RPC. While the RPC in use is stalled or failing, the others are also probed once a minute. A startup scan of vstorage on a public fallback is subject to that endpoint's rate limits.

    Documentation Considerations

    services/ymax-planner/README.md documents AGORIC_RPC_FALLBACKS. To use main-a as a fallback on mainnet, the deployment must set AGORIC_RPC_FALLBACKS=https://main-a.rpc.agoric.net:443.

    Testing Considerations

    Unit tests cover endpoint selection (including no healthy endpoint), health criteria (including a node whose queries hang), the wrong-chain failure, the wait for a better RPC, a stalled subscription, staying through a chain halt, switching back to the preferred RPC, the client's notification count, and config parsing. An earlier version of the health check was run by hand against the mainnet follower and main-a (both pass in about 1 s) and a devnet endpoint (fails with the chain ID mismatch); the current version has not been run against live nodes.

    Upgrade Considerations

    Switching endpoints happens by process exit, so it relies on the planner's container being restarted, as existing websocket-failure handling already does. Each restart rescans vstorage from the newly selected endpoint. Individual HTTP requests to the RPC still have no timeout of their own; a node that stalls them is left through the once-a-minute check.

    🤖 Generated with Claude Code

    https://claude.ai/code/session_01Pb54yMwxzGY6S1JgByrAR4

    Diff: 555 lines (+416 / -139) across 6 files Reviewer: gibson042 Review duration: 16008m
    All Vouch review confidence checks passed
    Residual risk 0.26 = Change Risk (0.48) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 555 lines diff across 6 files
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.378
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #12975"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 48.1% (MEDIUM) · Higher = larger blast radius
    48.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 25.7% · Safe to merge
    25.7%