The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.
fix(agent-payment-x402): reserve session budget before awaiting confirmation
Notorious D.E.Vec879062f937
diff --git a/docs/ja-JP/skills/agent-payment-x402/SKILL.md b/docs/ja-JP/skills/agent-payment-x402/SKILL.mdindex dccb57688..bf0e13f03 100644--- a/docs/ja-JP/skills/agent-payment-x402/SKILL.md+++ b/docs/ja-JP/skills/agent-payment-x402/SKILL.md@@ -186,17 +186,21 @@ let sessionApproved = false;async function payOnce(url: string, init?: RequestInit): Promise<Response> {// Reserve the worst case the policy allows. Settlement responses do not// carry an amount, so counting MAX_AMOUNT per call is a deliberate- // over-estimate — it can stop early, never late.+ // over-estimate — it can stop early, never late. Reserve before any await,+ // so concurrent calls cannot all pass the check.if (sessionSpent + MAX_AMOUNT > SESSION_CAP) {throw new Error("Session budget exhausted — blocked");}+ sessionSpent += MAX_AMOUNT;if (!sessionApproved) {sessionApproved = await confirmWithUser(`Allow paid requests up to ${SESSION_CAP} atomic units this session?`,);- if (!sessionApproved) throw new Error("User declined — no payment attempted");+ if (!sessionApproved) {+ sessionSpent -= MAX_AMOUNT; // nothing was signed+ throw new Error("User declined — no payment attempted");+ }}- sessionSpent += MAX_AMOUNT;return fetchWithPayment(url, init);}diff --git a/docs/zh-CN/skills/agent-payment-x402/SKILL.md b/docs/zh-CN/skills/agent-payment-x402/SKILL.mdindex 2be21ce7b..e2095d78c 100644--- a/docs/zh-CN/skills/agent-payment-x402/SKILL.md+++ b/docs/zh-CN/skills/agent-payment-x402/SKILL.md@@ -186,17 +186,21 @@ let sessionApproved = false;async function payOnce(url: string, init?: RequestInit): Promise<Response> {// Reserve the worst case the policy allows. Settlement responses do not// carry an amount, so counting MAX_AMOUNT per call is a deliberate- // over-estimate — it can stop early, never late.+ // over-estimate — it can stop early, never late. Reserve before any await,+ // so concurrent calls cannot all pass the check.if (sessionSpent + MAX_AMOUNT > SESSION_CAP) {throw new Error("Session budget exhausted — blocked");}+ sessionSpent += MAX_AMOUNT;if (!sessionApproved) {sessionApproved = await confirmWithUser(`Allow paid requests up to ${SESSION_CAP} atomic units this session?`,);- if (!sessionApproved) throw new Error("User declined — no payment attempted");+ if (!sessionApproved) {+ sessionSpent -= MAX_AMOUNT; // nothing was signed+ throw new Error("User declined — no payment attempted");+ }}- sessionSpent += MAX_AMOUNT;return fetchWithPayment(url, init);}diff --git a/skills/agent-payment-x402/SKILL.md b/skills/agent-payment-x402/SKILL.mdindex fbf3fa7e0..f32efb687 100644--- a/skills/agent-payment-x402/SKILL.md+++ b/skills/agent-payment-x402/SKILL.md@@ -187,17 +187,21 @@ let sessionApproved = false;async function payOnce(url: string, init?: RequestInit): Promise<Response> {// Reserve the worst case the policy allows. Settlement responses do not// carry an amount, so counting MAX_AMOUNT per call is a deliberate- // over-estimate — it can stop early, never late.+ // over-estimate — it can stop early, never late. Reserve before any await,+ // so concurrent calls cannot all pass the check.if (sessionSpent + MAX_AMOUNT > SESSION_CAP) {throw new Error("Session budget exhausted — blocked");}+ sessionSpent += MAX_AMOUNT;if (!sessionApproved) {sessionApproved = await confirmWithUser(`Allow paid requests up to ${SESSION_CAP} atomic units this session?`,);- if (!sessionApproved) throw new Error("User declined — no payment attempted");+ if (!sessionApproved) {+ sessionSpent -= MAX_AMOUNT; // nothing was signed+ throw new Error("User declined — no payment attempted");+ }}- sessionSpent += MAX_AMOUNT;return fetchWithPayment(url, init);}