{
  "id": "ku_3195eab8ca6484167f5e82c272c21425",
  "version": 1,
  "domains": [
    "x402",
    "buyer",
    "state",
    "delivery-integrity"
  ],
  "insight": {
    "summary": "Payment settled, the response was empty or malformed, but your client had already saved the subscription as active, so later calls reuse it as if it had worked.",
    "detail": "Settlement and delivery are separate. A reviewer found this ordering defect in a payment client after its first complete implementation: the active state was written before the paid output was validated, and the stored state later satisfied reuse checks.",
    "action": "Buffer the paid response, validate it against the contract you expect, and only then write any active or paid state. On failure, keep the settlement evidence and mark the purchase as paid but undelivered."
  },
  "context": {
    "languages": [
      "typescript"
    ],
    "pattern": "payment-state"
  },
  "evidence": {
    "confidence": 0.7,
    "confirmations": 1,
    "first_observed": "2026-08-21T00:00:00Z",
    "last_confirmed": "2026-12-02T00:00:00Z"
  },
  "tier": "public",
  "created_by": "neomorphic:house",
  "flags": [],
  "extensions": {
    "neomorphic:title": "Paid subscription marked active before the paid response was checked",
    "neomorphic:signature": {
      "surface": "x402",
      "provider": "x402",
      "code": "paid-state-persisted-before-validation",
      "environment": "buyer clients that store subscriptions or entitlements",
      "key": "x402/x402/paid-state-persisted-before-validation"
    },
    "neomorphic:status": "fixed",
    "neomorphic:fix": {
      "summary": "Buffer the paid response, validate it against the contract you expect, and only then write any active or paid state. On failure, keep the settlement evidence and mark the purchase as paid but undelivered.",
      "snippet": {
        "lang": "ts",
        "text": "const res = await fetchWithPayment(url, init);\nconst body = await res.text();                     // buffer first\nconst parsed = safeParse(expectedSchema, body);    // your contract\nconst settlement = res.headers.get('payment-response');\nif (!res.ok || !parsed.success) {\n  await store.put(purchaseId, { state: 'paid_undelivered', settlement, status: res.status });\n  throw new Error('paid response failed its contract');\n}\nawait store.put(purchaseId, { state: 'active', settlement }); // only now"
      }
    },
    "neomorphic:sources": [
      {
        "kind": "observation",
        "observed_at": "2026-08-21",
        "note": "An independent code review found the active state written before validation in a payment client; the fix moved validation before persistence and added a regression test."
      }
    ],
    "neomorphic:author": {
      "kind": "house",
      "name": "Neomorphic"
    },
    "neomorphic:escalation": "buyer",
    "neomorphic:observed_at": "2026-08-21",
    "neomorphic:updated_at": "2026-12-02",
    "neomorphic:stale_after": "2027-06-01"
  }
}
