Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

13.8 KB
Raw Blame

01. x402 settle: clear fee_runway_exhausted and hold the rate above 90%

Read 00-INDEX.md first.

Re-measured 2026-09-25: still ok; same two owner gates, less time on the second

Live at 05:13 UTC, still on c8f10f437: x402_settle ok, 92.6% (224/242, 3h). fee_runway_exhausted is still 42,760 of 42,784 facilitator rejects because 22f1e08df is not deployed. The sponsor fell to 0.019 SOL (0.017 spendable) against 0.0276 SOL/day of burn, so it reaches its floor about 15 hours after that reading. Fixed this pass: the top rail fault (This operation was aborted) was the forge prop pipeline abandoning paid generations at 20s while the server settled them anyway (7 of 9 in 24h); payX402 now takes paidTimeoutMs and the pipeline waits 90s (fb533a6ec). Evidence in PROGRESS.md, 2026-09-25. Remaining: deploy (gate 2), then fund Wwwu...T3WwW (gate 1), about 0.4 SOL for 14 days or about 1.4 SOL to also make the DoD 3 reclaim plan non-zero.

Re-measured 2026-09-24: settle is ok; two owner gates remain

Live at 06:32 UTC on c8f10f437: x402_settle ok, 92.2% (235/255, 3h), so DoD 1 passes. The sponsor was refunded since 09-09 (0.032 SOL), so the regime is governor pacing, not the floor. fee_runway_exhausted was back on top of the facilitator's reject book (40,939 in 24h against 4,341 settles) because the caller-side admission gate cached "yes" for 20s under pacing; fixed in 22f1e08df together with a hundredfold refusal undercount in /api/x402/runway-lab and a self-contradicting at_or_below_floor reason (now below_min_sweep). Evidence in PROGRESS.md, 2026-09-24 entry. What remains, both owner-owned:

  1. Deploy 22f1e08df (gate 2), then re-read the reject book 3h later for DoD 2.
  2. Fund WwwuGbqHrwF5RG89KhUbmRWEvjnRH9k5kVM5p7T3WwW (gate 1). Burn is 0.0488 SOL/day against about 0.030 SOL spendable, so the sponsor is back at its floor within a day. About 0.7 SOL buys 14 days; about 1.39 SOL also fills the 0.3 SOL operating reserve and both treasury-topup targets, which is what turns the empty reclaim plan in DoD 3 non-zero. Lowering ECONOMY_SWEEPBACK_MIN_SOL would instead let the reclaim cron sweep 0.161 SOL of agent-wallet excess; it moves SOL, so it is also the owner's call.

Re-measured 2026-09-04: three agent-doable defects were still here

The 2026-09-02 header below said only capital remained. That was wrong in a way that mattered: capital would have landed on the wrong wallet. Fixed and shipped in the tree on 2026-09-04 (0559bc23f), evidence per item in PROGRESS.md:

  1. A thin top-up funded the wrong wallet. planTopUps ranked targets by absolute deficit, and the relayer/treasury bundle's deficit (0.983 SOL) is five times the ring payer's (0.179 SOL), so 0.1, 0.2 or even 0.5 SOL sent to the master went entirely to the bundle and left the payer under its 0.002 SOL hard floor. The x402 sponsor and payer specs now carry settleCritical and are funded first. 0.1 SOL now restarts settlement; before, nothing under ~1 SOL would have.
  2. ?dry=1 on economy-rebalance executed live swaps (its only non-signing path was being disarmed, and production is armed). It now honors the flag.
  3. The rebalancer re-planned an impossible swap every 30 minutes. The ring payer cannot fund the 1,855,569-lamport rent for the wSOL account its own usdc->sol swap creates, so it holds 4.18 USDC it cannot spend. That is now an honest below_swap_rent:<have><<need> skip instead of a failing broadcast.

Also as of 2026-09-04: /api/healthz answers HTTP 500 in production (Cannot find module '/app/services/home-relay/src/token.js'), so the outcome line of this order cannot be read at all until the next deploy. That is fixed in the tree by d668ceece, not by anything here.

What remains is capital and the deploy, both owner-owned. The body below is kept for its diagnosis method, but four of its factual claims have been overtaken; do not act on them:

  1. The two config levers are already applied in production. GET /api/x402/runway-lab reports runway_days: 1 and the 2026-08-01 entry in PROGRESS.md records ECONOMY_MASTER_OPERATING_SOL=0.3 landing with it. Do not re-apply them.
  2. Lever 2 is inert at this balance and was struck on 2026-08-02. The governor's budget is max(minBudgetLamports, spendable / runwayDays). With the sponsor at 0.0037 SOL the 10,000,000 lamport heartbeat floor already exceeds spendable, so runway days change nothing.
  3. The upstream cause is NOT a mis-tuned self-heal trigger. The deficit has been positive and the reclaim leg has been running for weeks. It cannot complete: the wallets it targets are encrypted under the WALLET_ENCRYPTION_KEY retired in the 2026-07 host migration and fail AES-GCM decryption. 0.49 SOL is stranded that way, 0.35 of it customer money. See docs/ops/wallet-key-migration.md.
  4. The numbers below are a 2026-08-01 snapshot. Re-measured 2026-09-02 at 19:00 UTC: settle is 6.1% (3 of 49 paid attempts in 3h) and down again, cause sponsor_floor, with the Solana accept WITHDRAWN from 324 challenges in the same window (sponsorKnownBelowFloor()), so the low rate now measures a suppressed rail rather than a burning one.

Every wallet in the fleet is under its own floor, so no cron can heal this. Measured on chain and in the production ledger at 19:00 UTC on 2026-09-02: the sponsor / economy master Wwwu...T3WwW holds 0.001568 SOL with spendable 0 against its 2,000,000 lamport floor; the ring payer X4o2...stML holds 0.001893 SOL plus 3.969 USDC it cannot spend for want of fee SOL; the x402 receiver wwwww...ccrU holds 0.054995 SOL under a 0.1 SOL floor; all eight registry wallets together hold 0.2045 SOL. The reclaim leg runs every 60 seconds and books blocked every time: deficit 1.4696 SOL, 110 of 112 agent wallets at_or_below_floor, 2 unreadable at stage recover, 0 SOL reclaimed. Send SOL to the economy master WwwuGbqHrwF5RG89KhUbmRWEvjnRH9k5kVM5p7T3WwW, never to per-agent wallets: 0.1 SOL lifts the sponsor back over its floors and, with the 2026-09-04 ordering fix deployed, reaches the ring payer that the refusals actually name and restarts settlement; 2 SOL clears the fleet's whole 1.47 SOL deficit with weeks of runway. That is stop-and-ask gate 1 and it is the owner's call.

Shipped against this order: the caller-side fee admission gate (assessFeeAdmission), the governor config recurrence guard (tests/x402-wallet-fee-governor.test.js), WALLET_ENCRYPTION_KEY_PREVIOUS key rotation, and the dry-run reclaim key gate plus the corrected sponsor_floor hint (afd349790, 2026-09-02). Full evidence per line is in PROGRESS.md.

What is wrong (as measured 2026-08-01)

x402_settle is at 25.9% (504 of 1948 paid attempts over 3 hours). The rail faults look external (http_502 x1180) but they are our own facilitator rejecting settles: a facilitator settle rejection maps to 502 in api/x402-facilitator/[action].js (respondError defaults to 502) and the ring records it as http_502 in api/_lib/x402/pay.js.

The reject reason is not ambiguous. Since boot the self-facilitator counters read:

settle: ok 4143, failed 85955
fail_reasons: fee_runway_exhausted 85331, broadcast_failed 562,
              signature_already_settled 56, idempotent_replay 4, not_confirmed 2

fee_runway_exhausted outnumbers every rail-shaped failure by more than 100x. That reason comes from assessWalletFeeBudget() in api/_lib/x402/wallet-fee-governor.js: the wallet's daily fee budget is its spendable SOL (balance minus the hard floor) divided by X402_WALLET_FEE_RUNWAY_DAYS, never below X402_WALLET_FEE_MIN_BUDGET_LAMPORTS. A near-floor wallet gets a budget of about 0.01 SOL/day, which at roughly 6,000 to 8,000 lamports per settle is a few thousand settles, so the budget exhausts hours after each 00:00 UTC reset and the wave resumes.

The upstream cause is a mis-tuned self-heal trigger, not an empty treasury. ECONOMY_MASTER_OPERATING_SOL in production sits below the master wallet balance (code default is 0.15), so master_deficit_sol computes as 0, the treasury-topup cron sees nothing to do, and reclaimable SOL sitting in agent wallets is never pulled back to the wallet that pays fees.

This is a config and plumbing problem. Do not open with a funding request.

Diagnose (do this first, do not skip)

# 1. The class, from outside, no credentials needed.
curl -s https://three.ws/api/healthz \
  | python3 -c "import json,sys; d=json.load(sys.stdin); print(json.dumps(d['x402']['self_facilitator'],indent=1))"

# 2. The other class. A hit here means a DIFFERENT fix (see the floor doctrine below).
npm run logs -- -s three-ws-api --grep "fee_wallet_below_floor" --since 1h

When you grep the service logs directly, use a bare quoted string, never textPayload:"...". This service logs structured JSON, so a textPayload: query returns zero rows and exits 0, which reads as "class ruled out" while the cause is live. That exact trap cost a full misdiagnosis:

gcloud logging read 'resource.type="cloud_run_revision" resource.labels.service_name="three-ws-api" "fee_runway_exhausted"' \
  --freshness=6h --project aerial-vehicle-466722-p5

Then read the treasury engine's own view, which is read-only and safe:

curl -s -X POST "https://three.ws/api/cron/treasury-topup?dry=1" \
  -H "Authorization: Bearer $CRON_SECRET"   # CRON_SECRET is in .env

Read spendable_sol, not master_sol. A reserve set close to the balance mutes the whole engine while the balance still looks healthy.

Fix

Three levers, in this order. The first two are config-only and pre-approved.

  1. Make the deficit real so reclaim self-heals.

    gcloud run services update three-ws-api --region us-central1 \
      --project aerial-vehicle-466722-p5 \
      --update-env-vars ECONOMY_MASTER_OPERATING_SOL=0.3
    

    Verify the deficit turns positive in the ?dry=1 output above.

  2. Widen the daily budget from the same balance.

    gcloud run services update three-ws-api --region us-central1 \
      --project aerial-vehicle-466722-p5 \
      --update-env-vars X402_WALLET_FEE_RUNWAY_DAYS=1
    

    This triples the budget without spending anything. Confirm the projection with /economy-lab, which runs the real governor client-side through api/_lib/x402/runway-sim.js, seeded from GET /api/x402/runway-lab. Model the change there before you apply it.

  3. Actually move the reclaimable SOL. A non-dry POST /api/cron/treasury-topup moves funds between platform wallets. That is stop-and-ask gate 1: render the source wallet, destination, and amount, and get an explicit owner yes before firing it. Never top up per-agent wallets; that strands SOL and kills the rail.

Do not do these

  • Do not lower X402_SPONSOR_SOL_FLOOR_LAMPORTS to make the symptom go away. The floor is a different guard for a different failure (fee_wallet_below_floor), and the last time it tripped the shortfall was 0.000187 SOL: the refill leg was blocked, not the floor set wrong.
  • Do not size a funding ask from remembered numbers. Measured burn is roughly 0.06 to 0.09 SOL/day from fee_lamports over successful settles. The "1 to 2 SOL/day" figure in old triage notes is off by about 10x.
  • Do not attribute this wave to the RPC lanes. They explain broadcast_failed and not_confirmed (562 and 2), which is under 1% of the failures.

Make it not recur

Config that drifts silently is how this class returns. Land at least one of:

  • A healthz-level assertion that ECONOMY_MASTER_OPERATING_SOL is above the master balance's operating point, surfaced as a degraded reason string rather than a silent zero deficit.
  • A test over the governor's config surface pinning the relationship between runway days, min budget, and the measured per-settle fee, so a future default change cannot re-create a sub-day budget unnoticed. Extend tests/x402-wallet-fee-governor.test.js.

Definition of done

  • x402_settle reports ok on https://three.ws/api/healthz, above 90%, read at least 3 hours after the change so a full budget window is covered.
  • fee_runway_exhausted is no longer the top reject class.
  • POST /api/cron/treasury-topup?dry=1 shows a non-zero deficit and a non-zero reclaim plan.
  • The recurrence guard is committed with a test, npm run gate green.
  • data/changelog.json entry (tag: fix, infra) describing the recovery in holder-readable language.
  • PROGRESS.md updated with before/after settle rates.

Retire this prompt when it is done (required)

  1. Verify every Definition of done line against actual command output in front of you. Never claim a line you did not verify.

  2. Record the outcome in this campaign's PROGRESS or INDEX file if it has one.

  3. Commit with explicit paths and a subject that describes the diff (house style: type(scope): what changed and why a reader cares), and delete this prompt file in that same commit:

    git rm prompts/finish/902-backlog-01-x402-settle-runway.md
    

    A finished order left on disk reads as open work to the next agent, so the shrinking directory is the campaign's progress ledger.

If a line genuinely cannot pass inside this session (an external party must respond, or an owner-gated action is the final step), finish everything else, leave this file in place, and state exactly which line remains and who owns it. Never delete this file on a partial.