Skip to content

registerFromOrigin: 191/191 resources fail "database: Resource failed to upsert" for agenthustle.ai (multi-chain x402 v2) #782

@decentraliser

Description

@decentraliser

Hi Merit team — focused repro after hitting 191/191 upsert failures on a clean multi-chain x402 v2 implementation. Filing this hoping a log dive on your side surfaces the underlying Prisma error that's currently masked by the generic Resource failed to upsert string.

Repro

curl -X POST 'https://www.x402scan.com/api/trpc/public.resources.registerFromOrigin?batch=1' \
  -H 'Content-Type: application/json' \
  -d '{"0":{"json":{"origin":"https://agenthustle.ai"}}}'

Response (trimmed):

{
  "success": true,
  "source": "well-known",
  "total": 191,
  "registered": 0,
  "failed": 191,
  "siwx": 0,
  "skipped": 0,
  "deprecated": 0,
  "failedDetails": [
    { "url": "https://agenthustle.ai/api/tools/execute/unified/wallet",
      "error": "database: Resource failed to upsert" },
    "... 190 more, all identical ..."
  ]
}

Discovery of /.well-known/x402 succeeds (source: "well-known"). All 191 resources fail at the upsert step. The string comes from apps/scan/src/lib/resources.ts:135 when upsertResource returns undefined.

Reproduced against the single-resource path too

Same error on public.resources.register with a per-token URL that emits a clean single-accept body:

curl -X POST 'https://www.x402scan.com/api/trpc/public.resources.register?batch=1' \
  -H 'Content-Type: application/json' \
  -d '{"0":{"json":{"url":"https://agenthustle.ai/api/tools/execute/BASE_USDC/birdeyeTrendingTokens"}}}'

{"error":{"type":"parseErrors","parseErrors":["{\"type\":\"database\",\"upsertErrors\":[\"Resource failed to upsert\"]}"]}}

Live 402 shape (confirmed spec-compliant)

POST https://agenthustle.ai/api/tools/execute/BASE_USDC/birdeyeTrendingTokens returns:

{
  "x402Version": 2,
  "error": "Payment required",
  "resource": {
    "url": "https://agenthustle.ai/api/tools/execute/unified/birdeyeTrendingTokens",
    "description": "Get trending tokens from Birdeye...",
    "mimeType": "application/json"
  },
  "accepts": [{
    "scheme": "exact",
    "network": "eip155:8453",
    "amount": "94350",
    "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
    "payTo": "0x742d35Cc6634C0532925a3b844Bc9e7595f1dC16",
    "maxTimeoutSeconds": 300,
    "extra": { "name": "USD Coin", "version": "2", "decimals": 6, "tokenSymbol": "BASE_USDC", "tokenPriceUsd": 1, "priceUsd": 0.094349 },
    "resource": "https://agenthustle.ai/api/tools/execute/unified/birdeyeTrendingTokens",
    "mimeType": "application/json",
    "description": "Get trending tokens from Birdeye...",
    "maxAmountRequired": "94350",
    "outputSchema": {
      "input": {
        "type": "http", "method": "POST", "discoverable": true,
        "bodyType": "json", "body": {},
        "bodyFields": { "chain": {...}, "sortBy": {...}, "...": "7 fields total" }
      },
      "output": { "...": "standard output schema with example" },
      "authRequired": false
    }
  }],
  "extensions": { "bazaar": { "info": {...}, "schema": {...} }, "payment-identifier": {...} }
}

All 5-accept multi-chain variants also reproduce — but since single-accept Base-only reproduces the same error, this isn't about Stacks/Solana getting mixed in.

What I've already walked

  • normalizeChainId transforms in apps/scan/src/lib/x402/index.ts correctly map our values: eip155:8453base, solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpsolana
  • SUPPORTED_CHAINS = [Chain.BASE, Chain.SOLANA] — our Stacks entries filter out cleanly in registerResource, leaving Base + Solana as valid upsert candidates
  • Our payTo is a standard EVM address; our asset is the canonical USDC contract on Base; maxAmountRequired is a valid stringified integer
  • The error surfaces after upsertResource(...) returns undefined at apps/scan/src/services/db/resources/resource.ts:76 (schema safeParse failure) or from a thrown transaction error

Two candidate root causes I can't isolate without your logs:

  1. @agentcash/discovery advisory shape — something in the probe output doesn't map cleanly into upsertResourceSchema. The transform chains in resources.ts:79-97 may be producing values that fail the Zod validation silently.
  2. A Prisma constraint — possibly on the custom outputSchema type, an enum check on AcceptsNetwork, or a length/format check I can't see from the schema definitions alone.

Possible issue on our end

Our /.well-known/x402 resources array uses verb-prefixed strings:

{
  "version": 1,
  "x402Version": 2,
  "resources": [
    "POST /api/tools/execute/unified/wallet",
    "POST /api/tools/execute/unified/getAllBalances",
    "..."
  ],
  "routes": [
    { "method": "POST", "path": "/api/tools/execute/unified/wallet",
      "url": "https://agenthustle.ai/api/tools/execute/unified/wallet", "..." }
  ]
}

The richer routes array has bare url fields, but @agentcash/discovery likely reads resources and does new URL("POST /api/...", origin) which may produce garbage before anything reaches the DB. Happy to patch our emission to bare URLs in the resources list — but the single-resource public.resources.register test above bypasses /.well-known/x402 entirely and still fails, so the legacy-format hypothesis doesn't fully explain things.

Asks

  1. Log dive: can you grep server logs for agenthustle.ai around 2026-04-15 05:35 UTC and surface the actual exception being swallowed by the return undefined path in upsertResource? Even the raw error.code + error.meta from Prisma would unblock us.
  2. Stricter error reporting: would you consider replacing the generic 'Resource failed to upsert' string in apps/scan/src/lib/resources.ts:135 with the actual error's message/code? Would help every future multi-chain provider hitting the same wall.
  3. Stacks support: EmblemAI ships a native ExactStacksScheme adapter (STX, sBTC, USDCx) — upstreamed as part of Add EmblemAI to ecosystem directory x402-foundation/x402#2018. Any appetite for a PR that adds Chain.STACKS to apps/scan/src/types/chain.ts and the Zod network union in the upsert schema? Happy to do the work if you're receptive.

Context

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions