Skip to content

bug: token_spend calculation incorrect when concurrent webhooks share the same GitHub token #970

@myakove

Description

@myakove

Description

The token_spend calculation is incorrect when multiple webhooks run concurrently using the same GitHub API token.

Root Cause

The CountingRequester wrapper is shared across webhook instances when they reuse the same GitHub API client:

# In GithubWebhook.__init__()
if isinstance(requester, CountingRequester):
    # Reuse existing wrapper (SHARED across webhooks!)
    self.requester_wrapper = requester

Impact

When 2+ webhooks run concurrently with the same token:

  1. Both record initial_count = 100 at start
  2. Webhook A makes 5 calls, Webhook B makes 3 calls → shared counter = 108
  3. Both calculate token_spend = 108 - 100 = 8 (incorrect for both)

The initial_rate_limit and final_rate_limit fields are also affected.

Location

  • webhook_server/libs/github_api.py - GithubWebhook.__init__() and _update_context_metrics()

Possible Fixes

  1. Per-webhook tracking - Create a new CountingRequester per webhook instead of sharing
  2. Atomic snapshot - Track per-webhook deltas using context-based counters
  3. Rate limit delta - Use actual GitHub rate limit API at start/end (adds 2 API calls overhead)

Labels

  • bug
  • enhancement

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions