Skip to content

Count text limits in UTF-16 units, as the API does - #11

Merged
hedge-waleed merged 2 commits into
mainfrom
claude/project-thread-rk7bdz
Nov 10, 2026
Merged

hedge-waleed merged 2 commits into
mainfrom
claude/project-thread-rk7bdz

Conversation

@hedge-waleed

Copy link
Copy Markdown
Contributor

Summary

This fixes a bug found in a pre-release check of #10, before 0.5.0 was published.

The SDK counted text limits (agent name 128, framework 64, descriptions 256) in Python characters. The API and the Node.js and Go SDKs count UTF-16 code units, and most emoji take 2. So an agent name with emoji could pass the SDK's own validation and then be rejected by the API, which loses the payment record.

  • New module halvorai_ingest/text.py adds utf16_len and cut. cut works like JavaScript's slice(0, n), except it drops a character rather than splitting a surrogate pair.
  • validate.py now checks all S16 to S500 limits in UTF-16 units.
  • The Stripe mapper and tag helpers, and the x402 mapper, which has had the same issue since 0.3, now use cut.
  • An empty shared_payment_token in metadata is now kept, the same as the Node.js ??.
  • The CHANGELOG entry is added under 0.5.0, which hasn't been released yet.

Tests and verification

  • New parity cases in expected.json were generated from the Node.js mapStripeEvent and tagIssuingCard: emoji names, frameworks and merchant names, plus an empty SPT. Python's output matches them exactly.
  • tests/test_text.py covers UTF-16 length, the cut, and validation at 64 emoji (passes) and at 65 emoji (rejected).
  • New test: a name of 127 characters plus an emoji signs and validates, and the emoji is dropped rather than split.
  • pytest: 194 passed. mypy --strict: clean.

Brain update

  • What changed: the Python SDK now counts APE text limits in UTF-16 code units, matching the API and the Node.js and Go SDKs.
  • Why: names with emoji could get past the SDK and then be rejected by the API, so the event was lost.
  • Affected APIs, schemas, SDKs, integrations, or behavior: halvorai-ingest validation and the Stripe and x402 mappers. No public API changes.
  • Verification performed: parity tests against the Node.js output, and unit tests.
  • Deployment status (merged code is not necessarily deployed): not merged. 0.5.0 will be published to PyPI after this merges.
  • Known limitations and follow-up: none.

Generated by Claude Code

Names, frameworks and descriptions were cut and validated by Python characters, while the API
and the Node.js and Go SDKs count UTF-16 code units. An agent name with emoji could pass the
SDK's checks at 128 characters and then be rejected by the API, losing the payment record.
Adds halvorai_ingest.text (utf16_len, cut) and uses it in validation and in the Stripe and
x402 mappers. An empty shared_payment_token in metadata is now kept, as in the Node.js SDK.
New parity cases are generated from the Node.js mapper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CpycUZtFJDZbpUr3cUnE6Y
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CpycUZtFJDZbpUr3cUnE6Y
@hedge-waleed hedge-waleed self-assigned this Nov 10, 2026
@hedge-waleed
hedge-waleed merged commit 561f72c into main Nov 10, 2026
1 check passed
@hedge-waleed
hedge-waleed deleted the claude/project-thread-rk7bdz branch November 10, 2026 10:01
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.

2 participants