Skip to content

SOW 2 week 2: the payment tier on test networks, with its guards (draft, stacked on #23) - #30

Merged
dzakwannajmi merged 28 commits into
mainfrom
sow2/s2-payment
Nov 20, 2026
Merged

dzakwannajmi merged 28 commits into
mainfrom
sow2/s2-payment

Conversation

@dzakwannajmi

@dzakwannajmi dzakwannajmi commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Draft. Waits for the pre-release 0.8.0-beta.1; do not merge before it.

What this branch adds on top of #23:

  • Paid requests never follow a redirect; a 3xx to a paid request gives that check no verdict and the payment is not sent again (x402 and MPP charge).
  • Before any request to the target, the RPC must serve the run's network (Stellar passphrase, EVM chain id, Solana genesis hash).
  • Every x402 signature is held to $1.00, to the run's cap of $5.00 (lower with maxRunUsd), to the pinned payTo and asset, and to the plan read before the run; the SDK is handed the one option checked, and what it signed is compared before sending. wasit run --dry-run prints the plan without a key.
  • wasit run without --read-only is the payment tier, on test networks only. In GitHub Actions it pays only on a push to the default branch, a schedule and workflow_dispatch; a pull request runs the read-only checks and says so; a payer key given to a run that may not pay is refused before the service starts.
  • On a GitHub-hosted runner, when a payer key is set, the service runs as a separate user, wasit-service.
  • The Action takes tier: payment. "Changed since main" compares with the last green run on main and names it; the recent-failures line counts every finished run on main.
  • A canary test: a random key in every key variable and a key in the RPC url never reach any output or file of wasit run and wasit ci-report.
  • The new check X402-11, "Rejected Request Not Settled": for an endpoint with a reject case, Wasit sends a valid payment with the request the service must refuse, then reads the chain until that payment's authorization has expired. Unused (read with getLedgerEntries, in the same call as X402-06's used nonce) and no transfer is a pass; used, or the request served, is a fail. The payer's balance and the transfer events are second readings; a disagreement is no verdict. A lifetime of at most 300 s is waited out (hard stop 360 s); a longer one is not signed. Stellar only in this version.
  • The mainnet opt-in switches exist only to refuse, exit 2, with "the mainnet opt-in is not part of this version": wasit run --mainnet (before the config is read), the Action input mainnet (in the input check, before the install; written to the job summary), and the MCP start-up settings WASIT_MAINNET_OPT_IN, WASIT_MAINNET_CONFIG and --mainnet (the server does not start). A property test drives random flags, variables, events and config values for a payment on stellar:pubnet: no request is paid and nothing is signed.
  • MCP: WASIT_RPC_URL at start-up fixes the RPC of every tool call, and the rpcUrl argument is then refused before anything is sent. A result that reads the chain names its RPC by origin, where it came from, and when it is not the default (text and a structured rpc field).

Tests: build and typecheck clean; core 799, cli 245, server 24, action 172 (2026-11-16, local). Live, stellar:testnet: wasit run payment tier on our own x402 fixture, 10/10; X402-11 on a fixture with three routes (refuses: pass; settles then refuses, and serves: fail, each naming the transaction); X402-11 in the Action on the example project's main, 11/11 (2026-11-16).

Not in this branch: anything that pays on mainnet; the opt-in itself is never in this pull request.

fetch follows a redirect and keeps a custom header such as
PAYMENT-SIGNATURE on the way, so a route that redirects a paid request
delivered the signed payment to a second URL, another host or a second
handler of the same service, which could settle it while the check
graded the first. The verdict was then about the wrong URL.

fetchTarget now refuses a redirect answer by default ("never"): nothing
is sent to the Location and the check gets no verdict, naming the origin.
The old "follow" mode is gone, so a call that forgets to choose cannot
leak a payment. The read-only checks keep the same-origin rule.

The payment checks read their fresh challenge with fetchPaymentChallenge:
one redirect inside the origin is followed when it keeps the request (a
POST turned into a GET is refused), and X402-06 to X402-10 pay at the URL
that challenge came from; the replay goes to X402-06's URL. MPP charge
gives mppx a fetch that refuses redirects, and the MPP reads and channel
credentials use the default, since MPP pays at the URL it reads.
The network a run is labelled with and the RPC it is given are separate
inputs (--rpc-url, the MCP tool argument rpcUrl), and nothing tied them
together: a run labelled stellar:testnet and pointed at a mainnet RPC
builds its payment and reads its settlement on the wrong chain.

Before any request to the target, the x402 payment checks, MPP charge
and the MPP channel suite now ask the RPC which network it serves:
Stellar getNetwork (the passphrase), EVM eth_chainId, Solana
getGenesisHash (its first 32 characters are the CAIP-2 reference). A
mismatch, no answer, a redirect or an unreadable answer refuses the run
with nothing sent or signed; a network with no rule is refused too. The
message names the RPC's origin only, since its path may hold an API key.

The test stand-ins answer the identity method; the MPP charge tests,
whose https RPC nothing can serve, use a test-only transport, so the
connections they count are still the SDK's own.
…nd the plan

The payment checks paid whatever the SDK client allowed: its default $1
cap on its default assets, and its own pick among the challenge's options.
That is an accident of the SDK, not a guard of Wasit's, and the mainnet
opt-in needs caps of its own (spec B3, B4).

- guard/budget.ts: $1 a payment and $5 a run, fixed; maxRunUsd only lowers
  the run cap. Each signature is charged before it is made and never
  credited back; once the cap refuses, the run signs nothing more. Only
  USDC on the four test networks is valued; any other asset is refused.
- x402/plan.ts (L1): reads each endpoint's unpaid challenge, plans what the
  checks would sign (3.5 times the price), refuses a run whose worst case
  is above its cap before anything is signed.
- preparePayment (L2): on every signature, the pin over every exact
  option, the plan, the caps; the SDK is handed the one option checked,
  and a payload whose accepted field differs is discarded unsent.
- L3: the SDK's spend controls are set explicitly to $1, and its policy
  keeps only the pinned payee and asset.
- setPaymentChainsForTesting: a recording chain for the worst-case property
  test; not in the package index.

A price above $1 now gets Wasit's own refusal, as a setup error with
nothing sent, where it got the SDK's before. Run live on testnet on all
four chains, Permit2 included, before this commit.
A builder should see what a paying run would sign before it signs
anything (spec B5, safety rule 5). The dry run is L0 and L1 only: it
reads each x402 endpoint's unpaid challenge and prints, per endpoint, the
payee, the asset, the amount of each signature and the worst case,
against the caps ($1 a payment, $5 a run, lower with maxRunUsd), and the
pin when the config sets one.

It uses no key, sends no payment and signs nothing. It exits 2 when a
paying run would be refused: a worst case above the cap, an endpoint the
guard refuses, a network that is not a test network, or operatedByMe not
set. MPP endpoints are named as not planned. It takes neither --read-only
nor --json, --out or --baseline.
…hecks a tier did not run

The payment tier must run only where merged code runs (D-022a): a push to
the default branch, a schedule, workflow_dispatch on the default branch.
paymentEventGate refuses every pull request event and every other event,
and a push or a dispatch whose event file does not name the default branch.
payerKeyVariables names the key variables that hold a value, so a run can
refuse a key given to a run that may not pay; a fork's empty secrets do not
count.

A pull request runs the read-only tier while main may pay, so diffReports
no longer reports a check that either run skipped by tier (read-only, no
payer key) as a change or as fixed.

paymentChecksSkipped lets a front end word why the payment checks did not
run, and an L2 refusal against the plan now ends with the plan's reason.
… its own user on hosted runners

Without --read-only and --dry-run, wasit run is the payment tier. It pays
only when the GitHub event may pay, the network is a test network (L0,
checked before the service starts), the environment is operatedByMe, the
chain's key variable is set and the plan (L1) fits the caps. Then one
budget is shared by every endpoint, and each endpoint's checks get its
entry of the plan, the pin and the RPC url, so L2 holds every signature to
what was planned. The first line says it pays, on which network, from
which payer and up to how much; the report's note says what was charged.

On a pull request the run is the read-only tier and says why. A payer key
set on a run that may not pay is refused before the service starts: the
service of a pull request would run in the same job as the key (D-022a,
Najmi 2026-11-16). The payment tier asked for and not paid (no key, or
operatedByMe not true) exits 2 instead of green.

On a GitHub-hosted runner, when a payer key is set, --start runs the
service as the user wasit-service: made with passwordless sudo, given the
working directory by ACL and nothing on .git, started with sudo -E so no
value lands on a command line, and stopped by user. When sudo, useradd or
setfacl fails the run stops; it never falls back to the runner's user.
…dule and dispatch

tier: payment reaches the CLI as wasit run without --read-only; whether
the event may pay is the CLI's decision, so one workflow serves pull
requests (read-only, with the reason) and main (payment). The baseline is
uploaded on a schedule and on workflow_dispatch on the default branch as
well as on a push, and baseline.mjs takes runs of those three events,
never a pull request, merge_group or workflow_run run.

The template workflow shows the payment tier in comments: a dedicated
testnet payer, the key on the Wasit step only and only for events that
may pay, and what the separate service user does and does not keep from
the key.
…lures from every run

D-022b option 2: "Changed since main" compares with the last green run on
main, and the recent-failures line counts every finished run there, failed
ones included. The comment now says which run it compares with ("Compared
with the last green run on main: run <id>, started <time> UTC"), so a FAIL
that main has now is not read as the pull request's. renderComment takes
the history of every run and the run id as inputs; without them it keeps
the baseline's own history.
…nary test over run and ci-report

wasit ci-report --history reads the baseline file of the newest finished
run on main and counts the recent failures from its history, which the
next baseline then carries on, so the history survives red runs. A history
from another environment, or one that cannot be read, is not used and the
log says so. --baseline-run names the compared run in the comment; only a
whole number is used.

The canary test (spec B6) sets a fresh random Stellar key as every key
variable and a made-up key in the RPC url, drives wasit run (payment tier
as text and JSON, read-only, dry run, every refusal, an unreachable
target, --start) and wasit ci-report, and searches everything printed and
written for the key, its seed in hex and base64, and the RPC key.
…istory from the newest finished one

The baseline step now chooses two runs of this workflow on the default
branch, each by run id: the last successful one, for "Changed since main",
and the newest one that finished with success or failure, for the history
(D-022b option 2). It downloads once when they are the same run and writes
path=, run= and history= to its output. The report step hands the history
file (only inside the runner's temp directory) and the run id (digits only)
to wasit ci-report.
@vercel

vercel Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
wasit Ready Ready Preview Nov 20, 2026 10:26pm UTC

…t through sudo -E

On a GitHub-hosted runner the sudo that starts the service as
wasit-service ignored -E ("preserving the entire environment is not
supported, '-E' is ignored", run 43815743541 of the example repository),
so the service started with an environment sudo had reset: none of the
builder's own variables reached it.

The service is now started as sudo -n -u wasit-service -- node -e
<launcher>, and the command and the scrubbed environment go to the
launcher as JSON on stdin. The launcher runs the command with sh -c and
exactly that environment, passes signals on and exits with its code.
Nothing but the launcher's own code is on a command line, which any user
can read; the payer key is still never in that environment. The sudo
stand-in of the tests now refuses -E, as the runner's does.
…efuse must not settle

The new check of SOW 2 (spec B7 as D-032 changed it). For an endpoint with
a reject case in wasit.config.json, Wasit signs a payment for the advertised
terms, through the same plan, pin and caps as the other payment checks, and
sends it with the request the service must refuse. It then reads the chain
once a ledger: the nonce of that payment's authorization must still be
unused after its expiration ledger, read with getLedgerEntries in the same
call as X402-06's used nonce, which must be found. The payer's balance and
the token's transfer events are second readings; when they disagree with
the nonce, or cannot be read, there is no verdict.

A served invalid request fails whatever the chain shows; a refused one whose
nonce is found fails and names the transaction. A lifetime of at most 300 s
is waited out, with a hard stop 360 s after sending; a longer lifetime, a
chain Wasit cannot read, X402-06 not passed, or a service that refuses the
request before asking for payment is skipped with nothing signed. The plan
counts X402-11, so an endpoint with a reject case plans 4.5 times its price.

wasit run hands the endpoint's reject case to the plan and the check, and
prints one line before the wait so a CI log does not look stuck. The testnet
RPC sends events without inSuccessfulContractCall, so only an event marked
false is left out (found by the live check on the testnet fixture).
… names

This version has no mainnet opt-in, and must have no code path that allows a
payment on stellar:pubnet. The switches a later opt-in would read exist only to
refuse, so a run or a server that asks for mainnet is stopped and told why
instead of running on what else it was given: refuseMainnetSwitch always
throws, with "the mainnet opt-in is not part of this version", and adds the
workflow_dispatch rule for --mainnet on any other GitHub event.
mainnetStartupSwitches finds the MCP start-up settings that ask for it.

An RPC of the right network that lies about a settlement is a false pass the
identity check cannot see, so a result can now name the RPC it read through:
rpcInUse gives its origin only, where it came from and whether it is the
default for the network; readRpcLock reads WASIT_RPC_URL, the MCP server's
start-up lock, without ever quoting the value.

The no-allow-path property test drives random option sets for a pubnet payment
against a chain that opens every gate but Wasit's own, and asserts no request
and no signature; a control run on testnet shows the recorder sees one.
The mainnet opt-in switch of wasit run exists in this version only to refuse.
It is checked first, before the config is read, so a run that asks for mainnet
starts nothing, sends nothing and signs nothing, whatever else it was given: a
pubnet environment with operatedByMe and a pin, a payer key, --dry-run or
--read-only. Exit 2. In GitHub Actions on an event other than
workflow_dispatch the message also says that rule. The flag is never read from
the config or the environment, and the older commands do not take it.

The no-allow-path property test drives wasit run with random flags, key
variables (the mainnet payer variable included), start-up variables, GitHub
events and config values on stellar:pubnet: no signature, no paid request, and
--mainnet sends no request at all.
The Action now has the mainnet input of the opt-in, and in this version it only
refuses. mainnet: true stops the job in the step that checks the inputs, before
the install and before the service starts, with "the mainnet opt-in is not part
of this version", the workflow_dispatch rule on any other event, and the same
text in the job summary, so a run that asked for mainnet says so where it is
read. Any value but true or false is refused without being quoted. The run
step checks it again, and the CLI is never handed --mainnet.
…at start-up

Mainnet is never a tool argument. The start-up settings a later opt-in would
read, WASIT_MAINNET_OPT_IN, WASIT_MAINNET_CONFIG and --mainnet, now stop the
server before any tool is registered, exit 2, with the reason on stderr: this
version has no opt-in. The tool list has no mainnet tool.

WASIT_RPC_URL, read once at start-up, fixes the RPC of every tool call, and a
call that names an RPC is refused before anything is sent, so an agent cannot
point a run at another RPC. A value that is not an http(s) URL stops the server
without being echoed. A result that reads the chain names its RPC by origin,
where it came from, and when it is not the default, in the text and in a new
structured field, since every chain read of the run is that RPC's word.
… earlier where the review found gaps

An independent review of the payment tier found that X402-11 checked the
advertised lifetime on its first unpaid read of the reject request, while
the payment is signed from a second read: a service that answered 60 s
and then a longer lifetime got a signed payment that stayed valid that
long. The copy that is signed is now held to 300 s before signing, and
an authorization the client signs to outlive it is discarded unsent.

The other points of the review:
- a refusal after signing no longer says "Nothing was signed";
- X402-09 under a plan at a price of 1 base unit is skipped, as without
  a plan, instead of an error;
- the RPC identity check is exported, and its messages say no payment
  was sent, which holds wherever the check runs;
- the X402-11 watch stops at its hard stop while a read is in flight;
- in a CI that is not GitHub Actions the payment tier is not allowed,
  any non-empty GITHUB_ACTIONS counts as GitHub Actions, and a schedule
  whose payload names no repository needs a branch ref;
- `--mainnet` says the config was not read, since a local .env is;
- tests for refusing lines no test covered: terms changed by the
  chain's expired signing, a reused or already used nonce, the control
  missing right before sending, another payer, a cut event list.
…ment tier in another CI

`wasit run` read every challenge for its plan, and ran the read-only
checks, before the RPC identity check, while the check is meant to come
before any request to the target. A run that will pay now checks its RPC
before the service starts, and stops with exit 2 when the RPC serves
another network.

In a CI that is not GitHub Actions (CI set), the service of the run
would share its job with the payer key, and nothing keeps them apart
there. The payment tier is refused there with exit 2 and points to
--read-only; a read-only run beside a payer key is refused as well, as
on a pull request.

The canary test now covers X402-11, and a test that held a key-shaped
literal uses a random key.
…he RPC lock

A random key in every key variable and an RPC key in the lock's path and
query must never reach a tool result or the server's stderr, on the
paths most likely to echo them: an RPC that drops connections, one of
another network, the lock refusing an rpcUrl argument, an agent's own
rpcUrl, stellar:pubnet, and a server that refuses to start.

The close tool's refusal of rpcUrl under WASIT_RPC_URL had no test.
A payment valid for a few seconds can expire before a service that
settles refused requests has it on chain, so its unused authorization
says nothing about the service, and X402-11 passed on it. The check now
skips before signing when the advertised lifetime is below 30 s, on the
first read and on the read the payment is signed from; the plan does not
count X402-11 there; and a signed authorization with fewer than 3
ledgers left when it would be sent is discarded unsent. The CLI help and
the check's row in docs/CHECKS.md say so.
The env a workflow puts on the action reaches every one of its steps, so
the payer key was in the environment of Wasit's own install, its build
(third-party build tools), the baseline lookup, the report and the
comment, none of which needs it. Each of those steps now sets the six
key variables empty; only Run Wasit gets the key as the workflow gives
it. A test holds the list to the key variables core keeps from the
service.
The previous commit blanked the key variables in every step that runs a
command, but the baseline upload uses another action, and it runs on
exactly the events that pay, when the workflow gives the key. It now
gets the six variables empty as well, and the test covers every step
but Run Wasit, the steps that use another action included.
At a terminal, `wasit test` now shows its checks in Wasit's own look:
a header, two blocks (challenge, payment), and one line per check with
a mark and a badge that agree (PASS on green, FAIL on red, SKIP on
yellow, ERROR on magenta) and its duration.
A spinner line says what the check in flight is doing, and the verdict,
the counts and the run's duration come at the end. On a network that is
not a test network, the payment block says the checks are refused,
never that funds move. A skip that gives
the same reason as the skip above it does not repeat it. The colours are
the site's and the dashboard's, exact on a terminal with 24-bit colour,
and a badge's ink is given as exact black or white, since a terminal that
draws bold text in bright colours turns bold black into grey.
Every line is cut or wrapped to the terminal's width, so the spinner
line never wraps and is always rewritten in place. `wasit mpp-charge`
and `wasit mpp-channel` mark their results the same way.

Colour is a layer over the same text: every line is sanitised and its
secrets redacted before it is styled, so the only escape sequences on
screen are Wasit's own. A pipe, CI, --json and NO_COLOR get the plain
output exactly as before (compared over every kind of result), and
FORCE_COLOR=1 colours a pipe without moving the cursor.
…heck

A pull request got one comment, written at the end, with the counts of
each endpoint. A builder could not see that Wasit was running, nor which
check failed, without opening the job log.

- The comment has a table of the checks of each endpoint, with a mark for
  each result (PASS, FAIL, SKIP, ERROR), and the detail of every check
  folded into one <details> block at the end, so a long report is cut
  there and not in the verdict. Under an endpoint on stellar:testnet whose
  X402-06 passed, it links that payment's transaction on Stellar Expert.
  The link is built from the settlement the check read back from the
  chain (a new `reference` field on a PASS, in core, the JSON output and
  the MCP tools' output), and only when it is a 64-hex hash.
- A new step after Install, "Announce the run", writes "Wasit is running"
  into the same comment on a pull request from this repository; the
  result replaces it. When Run Wasit is skipped after it (a cancelled
  job), the report and comment steps still run and say no verdict, so the
  running comment never stays.
- With `checks: write`, the same step starts a check run, "Wasit
  conformance", on the commit under test, and a last step completes it
  with the verdict and the job summary (`wasit ci-report --check-run
  <file>`), or with a neutral text when the report step did not succeed.
  The steps that hold the token never hold the payer key and Run Wasit
  never holds the token, so the check run is completed at the end, not
  check by check. A pull request from a fork gets neither the running
  comment nor the check run. Nothing in these steps fails the job.
- NODE_OPTIONS is set empty in every step of the action: an earlier step
  of the workflow can write `--require <file>` into GITHUB_ENV, and Node
  would then load that file in the steps that hold the token or the key.
  A service Wasit starts no longer inherits options set that way; they
  go in its service.start command.
- The example workflow asks for `checks: write` (optional) and has one
  concurrency group per pull request, with cancel-in-progress, so two
  quick pushes do not write the comment over each other. Any other run
  has a group of its own: a run that may pay is never queued or cancelled.
f62a09c said an earlier step could put NODE_OPTIONS into GITHUB_ENV. On a
GitHub-hosted runner it cannot: runner 2.338.2 refuses it ("Can't store
NODE_OPTIONS output parameter using '$GITHUB_ENV' command.", run
44644150278 of the example project, 2026-11-20). The path that remains is
the workflow's own env, which reaches every step of a composite action.
With a --require in the env of the step that uses the action (run
44644486275), every step of the action showed NODE_OPTIONS empty, and the
file loaded in none of them nor in the service Wasit started, while a
control step with the same env loaded it.

The comment in action.yml and the test's name now say so. Nothing else
changes.
…y chain

The reason said the exact scheme on Stellar exists for v2 only. A v1
service on an EVM chain got the same text, which did not tell its builder
why Wasit does not grade it. It now says what was seen (an x402 v1
challenge, x402Version 1, in the body), that Wasit grades only x402 v2 on
every chain and what that means (the challenge in a PAYMENT-REQUIRED
header, CAIP-2 networks, the v2 exact scheme; Stellar is v2 only), and the
fix. It points at docs/CHECKS.md, whose note on x402 v1 links the x402
specification, and names no URL: the pull request comment's sanitiser
removes links from check text. With "Skipped: " it is 291 characters, so
the comment shows it uncut.
All three packages move to 0.8.0-beta.1, the CLI and the MCP server
depending on core ^0.8.0-beta.1, and the CHANGELOG gains the entry for
the pre-release: what can change on upgrade, the two MPP defects of
0.7.0 it fixes with a link to their advisory, and what is new (the
config file, wasit run with its read-only and payment tiers, wasit
ci-report, the GitHub Action, X402-11, the mainnet switches that refuse,
the run on the pull request with its running comment and check run,
the MCP server's RPC lock, and the coloured, live output of wasit test).

docs/CHECKS.md, which the MCP server's package carries, marks X402-11 as
new in this version instead of not yet released, and gains the revision
note held for the release: an x402 v1 service is reported as unsupported,
and a paid request or an MPP request follows no redirect.

The package READMEs describe the beta: the payment checks pay on test
networks only (the CLI README listed stellar:pubnet as paid), wasit run,
wasit ci-report and the Action, the MCP server's RPC lock, and seventeen
checks. The repository README's status and install lines say the same.
docs/CHECKS.md's note on the networks of 0.7.0 says the beta refuses
stellar:pubnet.

It is published under the npm tag beta; latest stays at 0.7.0. The
guides on the site still describe 0.7.0 until 0.8.0.
@dzakwannajmi
dzakwannajmi marked this pull request as ready for review November 20, 2026 22:29
@dzakwannajmi
dzakwannajmi merged commit cae11f1 into main Nov 20, 2026
5 checks passed
@dzakwannajmi
dzakwannajmi deleted the sow2/s2-payment branch November 21, 2026 09:55

This branch was successfully deployed

1 active deployment
Preview — 4397b089 Deployed Nov 20, 2026 by vercel[bot]
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.

1 participant