Skip to content

fix(antseed): narrow attempted to what provably never broadcast - #97

Merged
jmlago merged 2 commits into
mainfrom
fix/keeper-definitive-failure
Aug 12, 2026
Merged

fix(antseed): narrow attempted to what provably never broadcast#97
jmlago merged 2 commits into
mainfrom
fix/keeper-definitive-failure

Conversation

@MuncleUscles

@MuncleUscles MuncleUscles commented Aug 10, 2026

Copy link
Copy Markdown
Member

Context. The wallet keeper was enabled in prod for the first time today. Its top-up produced:

op=topup amount=5.0 outcome=unknown
detail: ✖ Deposit failed: server response 403 Forbidden (requestUrl=https://base.publicnode.com,
        "Archive requests require a personal token", code=SERVER_ERROR)

wallet_op_spend_since then read {'spent_usdc': 5.0} — $5 of a $10 daily cap consumed by a transaction that never landed.

What this PR does NOT do

It does not narrow that case. The obvious rule — "no tx hash in the output + a transport-level error ⇒ nothing broadcast" — is unsound, and implementing it would have been a money bug.

buyer deposit prints only err.message on failure (deposit.js:32-34). The hash lives inside depositsClient.deposit() and is never attached to the thrown error, so a 403 hit while polling for a receipt — after broadcast — is byte-identical to a 403 hit before signing. That rule would have recorded a live, money-moving deposit as costing nothing: the one error direction the attempted contract exists to prevent. The incident's own shape still classifies unknown, and the module documents why.

Two further reasons the naive rule fails: 403 is a bad key (the FallbackProvider rewrites a single-endpoint 403 into quorum not met, also SERVER_ERROR), and connection reset is not pre-broadcast — only refused and DNS failure are, and neither is affirmatively recognisable here.

What it does do

antseed/broadcast.jsclassifyCliFailure({code, killed, stdout, stderr}), first match wins, affirmative not residual: attempted: false requires a recognised pre-RPC shape, so silence, drift, and anything unrecognised stay unknown.

  1. killed ⇒ attempted
  2. on-chain step marker (depositing usdc, …) ⇒ attempted, unconditionally
  3. tx-hash-shaped token (deliberately over-matching) ⇒ attempted, unconditionally
  4. wording that only exists once a transaction does (nonce, already known, execution reverted, …) ⇒ attempted
  5. any stdout at all ⇒ attempted (the Wallet:/Amount: preamble precedes the deposits client)
  6. spawn errno with both streams empty ⇒ not attempted
  7. recognised pre-RPC signature (Amount must be a positive number, Cannot find module) ⇒ not attempted
  8. default ⇒ attempted

It lives in the sidecar, not the keeper, on evidence grounds: the keeper receives (r.stderr || r.stdout) truncated to 600 chars — one stream. ora writes the failure to stderr; the hash is console.log'd to stdout. On the failure path the keeper is handed the stream that cannot contain a hash and never sees the one that can.

The real bug this surfaced

failed was already safe. The hole was on the unknown side: every unknown consumes the cap, so at the shipped knobs (cap 10, amount 5) exactly two rows fit in 24h — while the error breaker waits for three. The third row can never be written. The cap silently absorbs the failure and the keeper goes quiet for a day: no halt, nothing above WARNING, nobody told.

That is exactly what prod did today. TOPUP_ERROR_STRIKES_TO_HALT_CAPPED = 2 halts the shorter run once the cap can no longer admit an attempt, converting a silent day-long stall into a persisted, operator-cleared alarm. A cap reached by deposits that worked still just returns daily_cap, pinned by its own test.

Tests

6 Python + 16 node. 4 fail before the change, verified by stashing the source. Classifier fixtures are the real prod wallet_ops detail, byte for byte.

732 passed, 2 skipped          (baseline 726 + 2; +6 = the new Python tests)
broadcast.test.js  pass 16 fail 0

Honest scope

This does not stop the prod failure recurring — it stops it being invisible. The actual fix is genlayerlabs/devexp-argocd-apps#534, which gives the CLI a keyed Base RPC; ANTSEED_BASE_RPC_URL is unset, so it has been transacting through free public endpoints. Resolving unknown rows from on-chain evidence (escrow delta, or a nonce witness) is the only sound path to the incident class and wants a design pass first.

Summary by CodeRabbit

  • Bug Fixes

    • Wallet operations now distinguish confirmed pre-broadcast failures from failures where broadcast status is uncertain.
    • Pre-broadcast failures no longer consume daily spending capacity.
    • Unrecognized or post-RPC failures are conservatively treated as potentially broadcast.
    • Repeated inconclusive failures can now halt further top-ups when the daily cap is exhausted.
  • Documentation

    • Clarified outcome meanings, transaction-hash limitations, and spending-cap behavior.
  • Tests

    • Added comprehensive coverage for failure classification and breaker interactions.

The keeper's first armed top-up burnt $5 of a $10 daily cap on a deposit
that failed with an RPC 403. `_outcome_for` only reaches `failed` (which
consumes neither cap nor cooldown) on `attempted: false`, and control.js
marked every non-zero CLI exit `attempted: true` — correct, but blunt.

Narrow it in the SIDECAR, not the keeper. The keeper is handed
`(stderr || stdout)[:600]`: one stream, truncated, and @antseed/cli prints
its transaction hash with console.log while ora writes the failure line to
stderr — so on the failure path the keeper gets the stream that cannot
carry the hash and never sees the one that can. Any judgement made there
would be made on strictly less evidence than the sidecar already had.

New antseed/broadcast.js (dependency-free, like amount.js / ids.js) answers
`attempted: false` only for a RECOGNISED pre-RPC failure: a process that
never spawned (execFile ENOENT/EACCES/...), a module graph that would not
load, the CLI's own argument guard — and only with an empty stdout, since
`buyer deposit` prints its Wallet:/Amount: preamble before the deposits
client exists. Everything else stays `attempted: true`, including silence
and every unrecognised shape, so a future CLI degrades toward the safe
answer.

The 403 that prompted this deliberately still classifies `unknown`, and
the module documents why at length. `buyer deposit` broadcasts TWICE
(unconditional approve, then the deposit) and polls for a receipt after
each; the CLI drops the TransactionResponse before rethrowing, so a
receipt poll that 403s prints exactly what a 403 before signing prints —
no hash, same message. The suggested "no tx hash + transport-level error"
heuristic would call that `failed` and move real USDC with the ledger
recording nothing. Resolving that class needs evidence from outside the
CLI's stdio (nonce around the run, or the escrow delta a cycle later).

Also closes a hole the incident exposed: every `unknown` consumes the cap,
so at the shipped knobs (cap 10, amount 5) only two deposits fit in 24h and
the error breaker's third strike could never be written. The cap silently
absorbed the failure and the keeper went quiet for a day with no halt and
nothing above WARNING. It now halts on two strikes once the cap can no
longer admit an attempt — forfeiting nothing it could still have done.

Every comment asserting the old "did the CLI run" contract is updated;
`failed` now means "no transaction could have reached Base mainnet".
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 2816f1ab-c2e5-404c-b364-d6b7031f82ff

📥 Commits

Reviewing files that changed from the base of the PR and between 8342b66 and 7997dac.

📒 Files selected for processing (2)
  • tests/test_wallet_keeper.py
  • wallet_keeper.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • wallet_keeper.py

📝 Walkthrough

Walkthrough

The sidecar classifies CLI failures by broadcast evidence. The control layer returns this classification. The wallet keeper uses attempted to distinguish failed from unknown and adds a capped error halt when daily-cap limits prevent normal breaker progress.

Changes

Broadcast outcome classification

Layer / File(s) Summary
Sidecar failure classifier
antseed/broadcast.js, antseed/broadcast.test.js
Adds conservative detection for transaction hashes, on-chain markers, broadcast phrases, process-start errors, and recognized pre-RPC failures.
Control response classification
antseed/control.js, tests/test_antseed_node.py
Uses the classifier for non-timeout CLI failures and returns attempted: false only for recognized pre-broadcast failures.
Keeper outcomes and capped error halt
wallet_keeper.py, tests/test_wallet_keeper.py, docs/PROVIDERS.md, host_store.py
Maps only explicit attempted: false to failed, maps other failures to unknown, and persists a halt when the daily cap limits breaker progress.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant WalletKeeper
  participant AntseedControl
  participant classifyCliFailure
  WalletKeeper->>AntseedControl: Submit wallet operation
  AntseedControl->>classifyCliFailure: Classify failed CLI result
  classifyCliFailure-->>AntseedControl: Return attempted and why
  AntseedControl-->>WalletKeeper: Return operation response
  WalletKeeper->>WalletKeeper: Map attempted false to failed
  WalletKeeper->>WalletKeeper: Map other failures to unknown
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: narrowing attempted status to failures proven not to have broadcast.
Docstring Coverage ✅ Passed Docstring coverage is 92.86% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/keeper-definitive-failure

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@wallet_keeper.py`:
- Around line 909-923: Derive the capped halt threshold in the top-up handling
flow around _error_strikes and _halt_topups from knobs.topup_daily_cap_usdc
divided by knobs.topup_amount_usdc, limiting it to TOPUP_ERROR_STRIKES_TO_HALT
and ensuring a minimum threshold of one. Use this derived threshold instead of
the fixed TOPUP_ERROR_STRIKES_TO_HALT_CAPPED value so a one-attempt cap halts
after its first unknown result, and add coverage for that one-attempt daily-cap
scenario.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6eae452d-1bb2-4a04-9ba8-78049dcbeb5e

📥 Commits

Reviewing files that changed from the base of the PR and between 1a38df9 and 8342b66.

📒 Files selected for processing (8)
  • antseed/broadcast.js
  • antseed/broadcast.test.js
  • antseed/control.js
  • docs/PROVIDERS.md
  • host_store.py
  • tests/test_antseed_node.py
  • tests/test_wallet_keeper.py
  • wallet_keeper.py

Comment thread wallet_keeper.py
@jmlago
jmlago merged commit 3085c1e into main Aug 12, 2026
4 checks passed
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