Skip to content

fix(usage): enforce safe-integer token bounds in Python and reject empty/boolean cost amounts in TypeScript #103

Done

Description

@drk-ram

Summary

Two cross-language parity gaps exist between src/agentrust_telemetry/usage.py and packages/typescript/src/usage.ts:

  1. Missing RFC 8785 safe-integer and non-negative checks in Python usage.py (src/agentrust_telemetry/usage.py lines 69-72, 99-102, 134-138):

    • While TypeScript usageRecord, UsageAccumulator.add, and UsageAccumulator.rollup enforce Number.isSafeInteger(value) && value >= 0 (0 <= value <= 2**53 - 1) on every token field and on rollup sums, Python usage_record and UsageAccumulator.add only check isinstance(value, bool) or not isinstance(value, int) (allowing negative integers before schema validation and integers > 2**53 - 1), and UsageAccumulator.rollup does not check total <= 2**53 - 1.
  2. Empty/whitespace strings and booleans coerced to 0/1 by Number(this.amount) in TypeScript CostObservation (packages/typescript/src/usage.ts lines 13-15):

    • In JavaScript, Number("") === 0, Number(" ") === 0, Number(false) === 0, and Number(true) === 1. Consequently, new CostObservation("", "USD", "provider").asEventValue() or new CostObservation(true as any, "USD", "provider").asEventValue() succeeds instead of throwing, whereas Python CostObservation rejects booleans and empty/whitespace strings.

Proposed Fix

  • Enforce 0 <= value <= 9007199254740991 (2**53 - 1) on token counts and rollup totals in Python usage.py, and guard non-string currency and pricing_version in CostObservation.as_event_value.
  • Reject non-number/non-string or empty/whitespace amount values in TypeScript CostObservation.asEventValue.

Activity

  1. github-actions commented on Oct 23, 2026

    @github-actions

    🟡 Contributor Check: MEDIUM

    Check Result
    Profile MEDIUM
    Credential LOW
    Overall MEDIUM

    Automated check by AgenTrust Contributor Check.

  2. added
    needs-review:MEDIUM
    on Oct 23, 2026
  3. added a commit that references this issue on Nov 25, 2026
    2f49c53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-review:MEDIUM

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions