Skip to content

feat: add classify_orchestration_error helper - #27

Merged
vvillait88 merged 1 commit into
mainfrom
tec-302-classify-error
May 14, 2026
Merged

feat: add classify_orchestration_error helper#27
vvillait88 merged 1 commit into
mainfrom
tec-302-classify-error

Conversation

@vvillait88

Copy link
Copy Markdown
Contributor

Summary

  • Classify thrown errors that escape `process_x402_settle`. Returns the same `ClassifiedX402Error` shape that `classify_x402_settle_result` returns for tagged failures.
  • Case-insensitive substring matching: `x402version` / `invalid payment` / `unsupported x402` → 400 `payment_proof_invalid`; `stripe` / `facilitator` / `cdp` → 503 `payment_provider_unavailable`. Anything else → `None`.
  • Never swallows unknown errors — caller rethrows on `None`.
  • Exported from `agentscore_commerce.payment`.

Tests

  • 12-fixture corpus locked as the cross-language contract with `@agent-score/commerce`'s `classifyOrchestrationError`.
  • Parametrized via `pytest.mark.parametrize` so multiple drifts surface independently.
  • Invariants: status/code mapping; next_steps shape; payment_proof_invalid takes precedence on multi-match; non-string/non-Exception input returns None.

Test plan

  • `uv run pytest tests/test_classify_orchestration_error.py` — 21 tests pass
  • `uv run pytest` — full suite 1002 pass / 3 skip, coverage 95.17%
  • `uv run ruff check`, `uv run ruff format --check`, `uv run ty check` — green

🤖 Generated with Claude Code

Classify thrown errors that escape process_x402_settle (e.g. from
mppx.compose, a Stripe SDK call, or any payment-side library code
wrapped in a single try/except around the full settle flow). Returns
the same ClassifiedX402Error shape that classify_x402_settle_result
already returns for tagged failures.

Pattern matching is case-insensitive substring on the error message:
- "x402version" / "invalid payment" / "unsupported x402" →
  400 payment_proof_invalid / regenerate_payment_credential
- "stripe" / "facilitator" / "cdp" →
  503 payment_provider_unavailable / retry_or_swap_method
- Anything else → None (caller rethrows)

The helper never swallows unknown errors. Substring matchers are
intentionally narrow — new error families land here explicitly rather
than letting the helper grow opaque heuristics.

Tests lock 12 cross-language fixtures with the @agent-score/commerce
sibling. Parametrized so multiple drifts surface independently.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vvillait88
vvillait88 merged commit 5c18092 into main May 14, 2026
7 checks passed
@vvillait88
vvillait88 deleted the tec-302-classify-error branch May 14, 2026 15:50
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