Skip to content

fix(automation): retry and narrow the v4 rebalance Rebalanced log search - #3039

Merged
clement-ux merged 1 commit into
masterfrom
claude/ousd-usde-v4-getlogs-retry-0bf967
Oct 21, 2026
Merged

clement-ux merged 1 commit into
masterfrom
claude/ousd-usde-v4-getlogs-retry-0bf967

Conversation

@clement-ux

Copy link
Copy Markdown
Collaborator

Why

ousdUsdeV4Rebalance (every 2 min, --network mainnet --cap-bps 1) failed 14 of 687 runs in 24h (~2%), all in currentTokenId(): module.queryFilter(Rebalanced(poolId)) over 50,000-block chunks, no retry. The RPC is the dRPC load balancer, which routes each call to one of several upstreams:

  • 12× Temporary internal error. Please retry (HTTP 500, JSON-RPC code 19)
  • 1× query block range exceeds server limit, narrow your filter: 10000 (-32602)
  • 1× block range extends beyond current head block (lagging upstream)

A failed run sends nothing and the next one succeeds, but each failure fires a Talos alert.

What changed

New tasks/lib/logs.ts → findLatestLog() (no retry / chunked-getLogs helper existed in tasks/lib/), used by both ousdUsdeV4Rebalance and ousdSusdeV4Rebalance (same lookup):

  • Chunks ≤ 9,999 blocks (to - from + 1 <= 10000). --log-chunk default is now 9999 and any larger value is capped.
  • Head queried on its own: the newest 5 blocks are a separate first query, so only that tiny range can hit a lagging upstream. It is retried, not skipped: a Rebalanced there is our own run from 2 min ago, and missing it would read the burned position (the run would then fail on ownerOf).
  • Retry: 3 attempts per range, backoff 500 ms → 1 s, on transient errors (5xx / SERVER_ERROR, "Temporary internal error", "beyond current head", timeouts). Non-transient errors (e.g. revert) throw immediately.
  • Range-limit error halves the chunk and retries the same to instead of failing.
  • Retries log at warn; docs/ACTIONS.md documents --lookback-blocks / --log-chunk for both actions.

Tests

tasks/test/logs.js (8 cases): the three dRPC errors are classified; every query ≤ 10,000 blocks and contiguous down to the floor; event in the head range is found; retry then success (backoff 100/200); range-limit halves 9999 → 4999 → 2499 → 1249; throws after retries are exhausted; no retry on a non-transient error.

  • pnpm test:tasks: 157 passing
  • pnpm prettier:ts, eslint on touched files: clean

Mainnet dry run

$ DEPLOYER_PK=<throwaway> pnpm exec tsx tasks/run.ts ousdUsdeV4Rebalance --network mainnet --cap-bps 1 --dryrun
[ousdUsdeV4Rebalance] Running on mainnet (1)
[ousdUsdeV4Rebalance] Latest Rebalanced at block 26235102: minted 474867
[ousdUsdeV4Rebalance] Ethena redeems 50000 USDe at 0.999979 USDC (0.21 bp)
[ousdUsdeV4Rebalance] KyberSwap: 0.999873 USDC/USDe, exit 0.999881 USDC/OUSD; target 0.999879 OUSD/USDe (-1.21 bp vs par), capped at the Ethena redemption value - 1 bp -> tick 2, top bid 0.999800
[ousdUsdeV4Rebalance] Position 474867 [2, 3]: skipping (In place, holds 29860.765771475934593322 OUSD, 7.891655951176555697 USDe)
[ousdUsdeV4Rebalance] Completed in 2.6s

ousdSusdeV4Rebalance --dryrun also finds its event ~39.5k blocks back (several 9,999-block chunks): Latest Rebalanced at block 26200340: minted 463219. (Its simulation then reports Contract with a Signer cannot override from with a non-operator throwaway signer — untouched by this PR.)

🤖 Generated with Claude Code

ousdUsdeV4Rebalance failed 14/687 runs in 24h on currentTokenId's
eth_getLogs (dRPC: temporary internal error, 10000-block range limit,
lagging upstream). Move the backwards search into tasks/lib/logs.ts:
chunks capped at 9999 blocks, the newest 5 blocks queried on their own,
3 attempts with backoff on transient errors, and a range-limit error
halves the chunk. ousdSusdeV4Rebalance shares the same lookup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@clement-ux
clement-ux merged commit baa1069 into master Oct 21, 2026
8 of 10 checks passed
@clement-ux
clement-ux deleted the claude/ousd-usde-v4-getlogs-retry-0bf967 branch October 21, 2026 09:09
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.

2 participants