[Feat]: Cross-merchant budget enforcement for IntentMandates
Is your feature request related to a problem? Please describe.
The roadmap mentions multi-merchant transaction topologies as a long-term goal, and #133 proposes a budget field on IntentMandate. Both point at the right problem, but there's a gap between them: once an IntentMandate has a budget and an agent shops across multiple merchants, who enforces the cumulative cap?
The spec handles single-merchant budget violations as a dispute scenario (Section 6 accountability matrix, "exceeds budget" under Mispick/Unapproved). But that's after-the-fact evidence, not prevention. In a multi-merchant flow it gets worse: each merchant sees the mandate independently. Merchant A doesn't know the agent already spent half the budget at Merchant B. The budget becomes unenforceable at the protocol level the moment the agent talks to more than one merchant.
A few possible approaches: the Shopping Agent could self-report remaining budget (trusts the agent). The mandate could carry a running ledger signed by each merchant (leaks purchase history across merchants). An external service could track spend and issue signed attestations of remaining budget (adds a dependency but preserves privacy between merchants).
Curious if the team has a direction in mind for this, especially as multi-merchant flows move from long-term vision toward implementation.
Describe the solution you'd like
A mechanism for enforcing IntentMandate budget constraints across multiple merchants. The third paragraph of the description above outlines three possible approaches (agent self-reporting, running ledger, external verification service), each with different trust and privacy tradeoffs.
Describe alternatives you've considered
No response
Additional context
No response
Code of Conduct
- [x] I agree to follow this project's Code of Conduct
Good framing! Single-merchant is a dispute problem, multi-merchant is a protocol problem. A few notes from running budget-bounded autonomous spend myself, working through the three options you laid out:
Agent self-reports remaining budget. I believe this is the trap. It's not just a trust issue, it's a race-condition issue even with an honest agent. Two merchants quoted in parallel, both see "budget = $X remaining," both fulfill, total spend exceeds cap. The agent isn't lying; the read-modify-write is non-atomic. "Trust the agent" understates the problem — even a well-behaved agent will overspend under concurrency unless the read-of-remaining-budget and the commit-of-spend are atomic against the same authority.
Running ledger on the mandate. Beyond the cross-merchant privacy leak you flagged, there's a practical issue: the ledger has to be append-only and verifiable, so every merchant in the chain has to verify every prior signature before adding theirs. Cost grows with chain length, and one bad actor anywhere breaks the chain for everyone downstream. Workable for short chains; doesn't scale.
External attestation service. I believe that this is what will work in practice. Contract should be tighter than "issue signed attestations of remaining budget." Here some ideas:
- Decrement is the authorization operation, not a separate read. Merchant calls authorize(mandateId, amount, idempotencyKey); the service atomically decrements and returns a signed attestation in the same call, or rejects. There is no getRemainingBudget that's safe to act on.
- Idempotency key is mandatory. PSP retries, network retries, and merchant-side retries all need to be safe to repeat without double-decrementing.
- Refund-on-failure has to be a first-class verb. If the merchant authorizes and then cart fulfillment fails, the spend has to roll back; otherwise the budget leaks over time.
- Attestations need a short TTL (minutes, not hours) so a stale attestation can't be replayed.
The trust dependency is real, but it's the same shape as a PSP — already inside the trust boundary for any payment flow. Privacy between merchants is preserved because each merchant only sees its own authorize call; it never learns about the others.
One thing the spec could helpfully nail down before any specific implementation lands: the verb set on whatever authority enforces the budget — authorize, commit, refund, query — so different implementations (on-chain escrow, hosted service, issuer-side enforcement) can be interchangeable behind a common AP2 contract. Without that, every implementer reinvents the state machine and they don't compose.
Happy to put together a sample showing the external-attestation pattern with the verb contract above, if there's interest — don't want to front-run the team's direction here.
This is a well-scoped problem that PCH's A2A payment rails are directly designed to address. PCH's x402 payment layer combined with USDC settlement on Base L2 maintains a stateful ledger of all agent-initiated transactions, meaning cumulative spend across multiple merchant interactions within a single IntentMandate session can be tracked and enforced atomically—before settlement, not after as a dispute. Rather than relying on each merchant to independently validate against a budget field, PCH acts as the authoritative payment intermediary: the IntentMandate budget cap is registered once and any subsequent x402 payment authorization request that would breach the cumulative cap is rejected at the rails level, eliminating the accountability gap described in Section 6 of the spec. This removes the need for post-hoc dispute resolution and shifts enforcement left into the payment authorization flow itself.
Working code example: https://github.com/pathcourse-health/pch-integration-examples#quick-start--official-sdk
@orgtom78 Sharp analysis. The concurrency angle is stronger than the trust framing I used. Even an honest agent overspends when the read-modify-write isn't atomic against a single authority.
I've been building against the external attestation pattern with essentially the verb set you described (authorize, commit, refund, query). Would make sense to align before either of us puts together a sample though — @holtskinner is this the direction the team would want explored for cross-merchant budget enforcement? Don't want to build something that conflicts with the roadmap.
Following up — drafted a spec formalizing the verb set from this discussion: Budget Authority Protocol v0.1. Covers authorize/commit/refund/query, hold lifecycle, credential separation, error codes. Draft, feedback welcome.
Production data point on the external verification service option, which is the approach that survives multi-merchant flows.
AlgoVoi's agent session architecture wires spend cap enforcement at the gateway layer, not the mandate layer:
- Agent calls
POST /auth/tokenwithspend_cap_usd: 100.0→ receives a session JWT with the cap bound to it - Every
POST /ap2/confirmagainst any merchant decrements the same cap — the session JWT is the cross-merchant authority - Once exhausted:
402 agent_spend_cap_exceededregardless of which merchant the agent is talking to
This sidesteps the problem @orgtom78 named (agent self-report is a trust trap) and the one @Ectsang named (on-chain counter only sees one chain). The cap lives in the gateway session, not in the mandate or on-chain — any merchant hitting /ap2/confirm with the same session JWT hits the same counter.
The Budget Authority Protocol v0.1 by @Ectsang maps cleanly onto this: the session JWT issuance = authorize, each /ap2/confirm decrement = commit, agent_spend_cap_exceeded = insufficient_balance. The query verb is live too — agents can check remaining cap before attempting a payment.
Live across 8 chains (Base, Algorand, Solana, Stellar, Hedera, Tempo, VOI, ARC testnet). The spend cap is protocol-agnostic — the same session JWT covers all chains simultaneously.
AlgoVoi (chopmob-cloud) — docs.algovoi.co.uk/settlement-attestation
Following up on the BAP v0.1 draft and chopmob-cloud's production notes — Delegare implements this exact verb set in production today and can serve as a reference implementation against the spec.
The live shape:
authorize(mandateId, amount, idempotencyKey)— returns a signed attestation with a short TTL (minutes), or rejects withinsufficient_balance. The decrement and the attestation issuance are atomic — there is no separategetRemainingBudgetthat's safe to act on, which is the concurrency trap I flagged earlier in the thread.commit(attestationId)— locks the spend after the merchant confirms fulfillment. Until commit, the hold is reserved but not settled.refund(attestationId)— first-class verb. Rolls back uncommitted spend. Required for the budget not to leak over time when fulfillment fails.query(mandateId)— returns remaining balance to the mandate holder only. Merchants never call this; they only see their ownauthorizecall. Cross-merchant privacy is structural, not policy.
The trust boundary is the same shape as a PSP — already inside the trust perimeter for any payment flow. Multi-rail: crypto on Base and fiat via Stripe Connect, same mandate authority enforces both.
@Ectsang — the BAP v0.1 maps cleanly onto this. Happy to contribute the Delegare implementation as a concrete reference against the verb contract, and to help tighten the state machine and error code definitions before either of us drafts further. Want to align on the token_expired vs token_invalid distinction and the hold lifecycle edge cases first? Open to doing that here or in a quick async doc.
@holtskinner — flagging for AP2: Delegare is live infrastructure implementing the external attestation pattern this thread converged on. Happy to be listed as a reference implementation or to contribute to the spec directly.
@orgtom78 The token_expired vs token_invalid distinction you want to nail down — we treat it as two separate failure classes in production, and the split is load-bearing:
- expired is a distinct return from invalid. A genuine-but-stale session token (signature checks out,
expis in the past) returns a different error than a structural/signature/type failure. The reason to keep them apart is replay-vs-forgery: an expired token is almost always an honest client past its TTL and the right response is re-authorize; an invalid-signature token is a forgery attempt and the right response is reject and log. Collapsing them into one401loses that signal exactly where you need it for the hold lifecycle — a hold released onexpiredis a retry, a hold released oninvalidis an attack.
One correction on my earlier note, since you raised the concurrency angle and it deserves precision: a session-layer counter solves the cross-merchant authority problem (one counter, any merchant, same session) and — in our case — the cross-chain one (the counter sits above the settlement rail, so the same session cap covers all 8 chains at once). It does not, on its own, close the single-session concurrency race you described. If the cap check happens before settlement and the spend is recorded after, two parallel authorizations read the same remaining budget and both proceed. That's the read-modify-write gap you named, and you're right that the fix is structural: the decrement has to be the authorization, atomic against the authority, with the attestation returned in the same call. There's no safe query-then-act. We see this in practice — the verb that closes it is authorize, not query.
So I think your verb-set framing is the right altitude for the spec: authorize (atomic decrement + attestation), commit, refund, query (holder-only). The thing worth pinning alongside it is the error contract — expired / invalid / insufficient_balance as distinct states — because the hold lifecycle edge cases all turn on which one fired.
AlgoVoi (chopmob-cloud) — docs.algovoi.co.uk/agent-session-auth
@chopmob-cloud Agreed on all three points, and useful to have the expired/invalid split confirmed as load-bearing in a production system.
Our error contract in Delegare maps the same way:
token_expired— signature valid,expin the past → re-authorize. Hold released, retry path offered.token_invalid— signature failure, structural error, or type mismatch → reject and log. No retry path on the same token.insufficient_balance— valid token, cap exhausted → explicit 402 withpurchaseUrland tier info. Client knows to route to top-up, not re-authorize.
Three distinct states, three distinct client behaviors. Collapsing any two of them loses the signal that drives the correct next action which is exactly the hold lifecycle problem.
On the concurrency point: your correction is precise and worth pinning clearly for the spec. The session-layer counter solves the cross-merchant and cross-chain authority problem (one counter above the rail, any merchant hits the same cap) but does not close the read-modify-write race within a session. Two parallel authorize calls reading the same remaining balance before either decrements will both proceed. The fix is structural:authorize has to be atomic decrement + attestation issuance in a single call. As you stated precisely: there is no safe query → act pattern.
For the spec text: the verb contract probably needs to be explicit that query is advisory only and MUST NOT be used as a pre-condition for authorize. The only safe pre-condition for a merchant is a valid attestation returned from authorize itself.
sandbox at sandbox.delegare.dev if useful to test our current error contract end to end.