Skip to content

Subscription exhaustion race causes deployment key cost unrecorded in baseline failover #538

Description

@rohith500

Problem

When a Claude subscription is healthy at the pre-dispatch exhaustion check (line 1794) but becomes exhausted during the primary OSS model dispatch (concurrent request burns the plan window), the baseline failover path has a race that causes the deployment key cost to be absorbed silently with no billing record.

Execution trace of the race:

Line Action ctx suppressed?
1794 claudeSubscriptionExhausted = false → suppression NOT applied to ctx No
2051 Primary OSS dispatch fails; concurrent request flips snapshot to exhausted No
2097 claudeSubscriptionExhausted = true — only baselineCtx suppressed, not ctx ctx: No
2109 Baseline dispatch succeeds on Weave's deployment key
2147 ctx = resolveAndInjectCredentials(ctx, ProviderAnthropic)subscription token injected No ← bug
2200 servedOnSubscription(ctx)truedelta = 0deployment key cost unrecorded

Three attributes are misattributed:

  • cost.subscription_served OTel attribute — reports true instead of false
  • SubscriptionServed billing field — causes delta = 0 instead of full cost debit
  • credentialKeyPrefix/Suffix/credSource telemetry — attributes the turn to the subscription token instead of the deployment key

Fix

Add ctx = withSuppressedClaudeSubscription(ctx) alongside baselineCtx at the baseline exhaustion check (line 2097) so the re-resolution at line 2147 falls through to the deployment key correctly.

Fix available in PR #533.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions