Skip to content

x402 inspect: fallback to on-chain gateway balance when API balance is stale#49

Merged
Abiorh001 merged 1 commit into
omnuron:mainfrom
ahmadghoniem:fix/x402-onchain-gateway-fallback
Apr 22, 2026
Merged

x402 inspect: fallback to on-chain gateway balance when API balance is stale#49
Abiorh001 merged 1 commit into
omnuron:mainfrom
ahmadghoniem:fix/x402-onchain-gateway-fallback

Conversation

@ahmadghoniem
Copy link
Copy Markdown
Contributor

Summary

  • add on-chain fallback in _choose_x402_route when API gateway balance is insufficient
  • keep existing API-first behavior; only use on-chain �vailableBalance when API balance appears stale
  • surface explicit reason when fallback path is used

Why

In real runs, Gateway API /v1/balances can lag after deposit while on-chain �vailableBalance is already funded. This causes false �uyer_ready=false in /api/v1/x402/inspect.

Changes

  • src/omniclaw/agent/routes.py

    • when get_gateway_balance is below required amount, call get_gateway_onchain_balance
    • if on-chain is sufficient, set:
      • gateway_ready=true
      • gateway_available_balance from on-chain value
      • reason: Gateway on-chain balance is sufficient (API balance appears stale)
  • ests/test_x402_sdk_adapter.py

  • update existing route-selection tests to mock get_gateway_onchain_balance

  • add est_choose_x402_route_uses_onchain_fallback_when_api_balance_is_stale

Verification

  • uv run pytest tests/test_x402_sdk_adapter.py -q
  • result: 9 passed

@Abiorh001 Abiorh001 self-requested a review April 22, 2026 09:31
@Abiorh001 Abiorh001 merged commit 1f908c5 into omnuron:main Apr 22, 2026
5 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