fix(x402-buyer): persist consumed-nonce state to PVC instead of emptyDir#522
Closed
bussyjd wants to merge 1 commit into
Closed
fix(x402-buyer): persist consumed-nonce state to PVC instead of emptyDir#522bussyjd wants to merge 1 commit into
bussyjd wants to merge 1 commit into
Conversation
Today the x402-buyer sidecar's /state directory is an emptyDir. When
the litellm pod restarts (rollout, OOM, node drain), consumed.json is
gone. The pre-signed auth pool reloads from the ConfigMap the
controller manages, and the buyer treats every auth as unconsumed —
attempting to spend nonces that the facilitator already marked used.
Cascade: facilitator returns 400 "nonce already used" -> buyer 402
back to LiteLLM -> caller retry -> same 400 -> eventually buyer pool
exhausted -> 503 until manual `buy.py process --all` reseeds.
Fix: convert /state to a PVC backed by local-path-provisioner (the
storage class already deployed via base/templates/local-path.yaml).
50Mi request; consumed.json is tiny but room left for log growth.
Deployment strategy switched to Recreate because a RWO PVC can't
be co-mounted during a RollingUpdate surge. Litellm is replicas: 1
so this just means rollouts have a ~5s gap instead of an overlap —
acceptable.
What this does NOT solve:
- Multi-replica litellm. RWO PVC works only for replicas: 1; would
need RWX (which local-path doesn't support — needs NFS/Longhorn)
or per-replica state via StatefulSet. Out of scope; litellm has
no current scaling need.
- Hard node loss. local-path PVCs are node-local; if the k3d node
is destroyed, state is gone (along with the rest of the cluster).
For local-only operator that's the expected blast radius.
PSS compatibility note: the PVC mount works under PSS Restricted as
long as the buyer container runs with appropriate fsGroup. PR #12
(Restricted PSS sweep) handles that separately and will verify mount
permissions when it lands.
6 tasks
Collaborator
Author
|
Superseded by bundle PR #536 — closing in favor of the consolidated merge target. Original branch and history preserved. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Today
/stateon the x402-buyer sidecar isemptyDir: {}. Pod restart losesconsumed.json→ buyer treats every pre-signed auth as fresh → tries to spend already-consumed nonces → facilitator 400 cascade → buyer pool exhausted → 503 until manualbuy.py process --all.Before
After
What changed
llm.yaml— new PVCx402-buyer-state(50Mi, local-path, RWO); volume entry on litellm Deployment swaps fromemptyDir: {}→persistentVolumeClaimllm.yamlDeployment strategy →Recreate(RWO PVC requires no surge)internal/embed/embed_buyer_state_test.go— regression test pinning the PVC + Recreate invariantsWhat this does NOT solve
PSS compatibility
PR #12 (Restricted PSS sweep) will need to verify the buyer can read/write the PVC mount under
runAsUser: 65532. Local-path creates files at 0777 by default which is permissive. Cross-PR coordination noted.Test plan
go build ./...cleango test ./internal/embed/... ./internal/x402/buyer/...greenkubectl rollout restart deploy/litellm -n llm→ spend 3rd auth → facilitator settles cleanly (no 400)