Skip to content

feat: add paid-route error taxonomy for analytics and CLI output (#83)#95

Open
Micheal-Blessed wants to merge 11 commits into
emrekayat:mainfrom
Micheal-Blessed:feature/paid-route-error-taxonomy-83
Open

feat: add paid-route error taxonomy for analytics and CLI output (#83)#95
Micheal-Blessed wants to merge 11 commits into
emrekayat:mainfrom
Micheal-Blessed:feature/paid-route-error-taxonomy-83

Conversation

@Micheal-Blessed

Copy link
Copy Markdown
Contributor

Resolves #83

Description

When a paid route fails, reviewers and operators need to know whether it was a payment issue, provider issue, validation issue, or internal error. This PR introduces a stable failure code to paid-route responses, maps it to persisted analytics records, prints it in the CLI, and adds tests for validation and provider failure paths.

Taxonomy Mapping

  • payment_required: Returned when no payment proof was sent (402 status code).
  • payment_invalid: Returned when payment proof is invalid, failed verification, or user rejected (400 status code).
  • provider_timeout: Returned when provider execution times out (504 status code).
  • provider_failed: Returned when the provider returns an error or execution fails (502 status code).
  • invalid_query: Returned when input validation fails, such as missing queries or invalid scrape URLs (400 status code).
  • internal_error: Returned for other unhandled exceptions (500 status code).

Acceptance Criteria Met

  • Paid-route failures return a stable errorCode without leaking secrets.
  • Analytics can store the code for failed paid attempts when available (added error_code column via database migration version 3).
  • CLI prints the code in a compact, human-readable line.
  • Tests cover at least validation failure and provider failure paths (added test cases to protected.validation.test.ts).
  • Existing API and agent-client tests pass.

@vercel

vercel Bot commented Jun 29, 2026

Copy link
Copy Markdown

@Micheal-Blessed is attempting to deploy a commit to the emrekayat's projects Team on Vercel.

A member of the Team first needs to authorize it.

@emrekayat

Copy link
Copy Markdown
Owner

Thanks for the PR. I checked this from the emrekayat account.

I cannot run a proper merge-ref review or merge it yet because GitHub reports the branch as CONFLICTING / DIRTY, and refs/pull/95/merge is not available. Please rebase or merge the latest main and resolve the conflicts first.

Once it is mergeable, I will recheck the paid-route error taxonomy, analytics persistence, CLI output, and the API/agent-client test coverage.

@drips-wave

drips-wave Bot commented Jun 30, 2026

Copy link
Copy Markdown

@Micheal-Blessed Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Micheal-Blessed Micheal-Blessed force-pushed the feature/paid-route-error-taxonomy-83 branch from 1ea9a59 to 25d5510 Compare June 30, 2026 07:20
@Micheal-Blessed

Copy link
Copy Markdown
Contributor Author

@emrekayat resolved, please review and merge.

@emrekayat

Copy link
Copy Markdown
Owner

Rechecked this one from emrekayat. The implementation passes the functional checks on the PR merge ref:

  • npm run test --workspace @query402/shared
  • npm run test --workspace @query402/api -- src/routes/protected.idempotency.test.ts src/routes/protected.validation.test.ts
  • npm run typecheck --workspace @query402/api
  • npm run typecheck --workspace @query402/agent-client
  • full npm run test --workspace @query402/api

However, the PR is currently not mergeable against latest main. GitHub reports CONFLICTING, and a local merge of 25d5510 into current main conflicts in:

  • apps/agent-client/src/cli.ts
  • apps/api/src/lib/storage/serialization.ts
  • apps/api/src/lib/storage/sqlite/repository.ts
  • packages/shared/src/types.ts

Please rebase/merge latest main and keep the error taxonomy changes integrated with the recent payment evidence and CLI summary updates. After that this should be ready for another pass.

Seunfunmi-319509 and others added 8 commits June 30, 2026 20:31
…queries (emrekayat#112)

When a paid query price exceeds the configured provider price by more
than 10%, mark it as a priceOutlier in the usage event with a safe
reason string explaining the discrepancy.

Changes:
- Add priceOutlier and priceOutlierReason fields to UsageEvent type
- Implement computePriceOutlier detection in buildUsageEvent
- Add SQLite migration v4 for the new columns
- Update serialization layer (usageEventToRow / rowToUsageEvent)
- Update INSERT_USAGE query in SQLite repository
- Show compact warning icon on outlier rows in the dashboard
- Add tests for normal and outlier price scenarios

Closes emrekayat#78
…rs (emrekayat#48)

* docs: add demo-mode payment evidence documentation and fix build errors

- Add comprehensive documentation explaining demo vs real payment evidence
- Document demo request flow with 402 challenge and retry semantics
- Include minimal curl example using x-query402-demo-paid header
- Link documentation from README
- Fix TypeScript build errors:
  - Add PaymentPayload type import and assertion in x402.ts
  - Replace Node.js Buffer with browser-compatible base64 encoding in web/sponsorship.ts
  - Exclude test files from web app typecheck to avoid node:test import errors
  - Fix Windows path separator issue in memory.test.ts

All CI checks pass: typecheck, build, test, lint, format, source-artifacts

* fix: correct API port to 3001 and /api/usage response structure in demo payment docs

---------

Co-authored-by: Emoji-dot <[email protected]>
…emrekayat#99)

* test(api): add x402 payment requirement snapshot for protected routes

Add a deterministic snapshot-style test that pins the 402 payment
requirement shape (scheme, network, price, payTo, facilitator) and
provider-aware price behavior for /x402/search, /x402/news, and
/x402/scrape. Failure messages name the route and provider that
drifted so SCF reviewers and agents can spot pricing regressions
before demos.

- Export resolveRoutePrice from lib/x402.ts for direct testing.
- Add apps/api/src/routes/protected.test.ts covering HTTP 402 shape,
  protectedRouteBasePrices, resolveRoutePrice across all providers
  and fallback cases, plus a provider-catalog price snapshot.
- No live Stellar wallet or facilitator credentials required.

* style: apply prettier formatting

Resolve prettier --check CI failure introduced by the snapshot test
commit (apps/api/src/routes/protected.test.ts had multi-line
expect().toBe() chains that did not fit printWidth 100, and a couple
of pre-existing files in the repo were already out of compliance
with the repo prettier config and are now normalized).

* style: fix prettier formatting on upstream main files

After rebasing onto upstream/main, the base branch files had
pre-existing prettier drift that caused the CI format:check
to fail on the merge commit. Apply prettier --write to normalize
them so the CI gate is green.
…yat#98)

* Add API response trace correlation to dashboard evidence view

Paid route responses now include a top-level traceId alongside the
existing result.traceId, making it easier to correlate dashboard
results, CLI output, and API logs.

Changes:
- Add paidQueryResponseSchema + related Zod schemas to shared package
- Add traceId to top level of buildPaidResponse in x402 handler
- Add traceId to safe failure (502) response in demo/sponsored route
- Update web PaidQueryResponse type with traceId and correct evidence
  shape (removed stale paymentResponseHeader field)
- Redesign dashboard trace-box: show full traceId with copy button,
  display evidence status instead of broken paymentResponseHeader ref
- Add trace-row/trace-copy-btn CSS styles with hover/active states
- Update idempotency and demo tests to assert top-level traceId

Closes emrekayat#85

* Fix prettier formatting

* Fix prettier formatting across the codebase
emrekayat#51)

* feat: add provider catalog sorting and payment header redaction tests (emrekayat#35, emrekayat#39)

* style: format files with Prettier

* chore: revert package-lock.json to main version

---------

Co-authored-by: temitopehannahbolarin-beep <[email protected]>
…pt job (emrekayat#70)

Verified from emrekayat before merge.

Checks run locally on Node 22.16.0:
- `git diff --check main...pr-70-merge`
- `npm run typecheck --workspace @query402/agent-client`
- `npm run build --workspace @query402/agent-client`
- full `npm run build`
- CI-style demo flow with placeholder env: API start, `/health`, `npm run demo:transcript --workspace @query402/agent-client`, transcript artifact creation, and secret-pattern scan

This completes emrekayat#60 with a deterministic DEMO_MODE transcript artifact path.
@Micheal-Blessed Micheal-Blessed force-pushed the feature/paid-route-error-taxonomy-83 branch from a84be90 to 0f7f44f Compare June 30, 2026 20:44
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.

Add paid-route error taxonomy for analytics and CLI output

8 participants