Skip to content

[DONE] feature/tokensa — implement token usage tracking and fix queue-bootstrap schema mismatches#49

Merged
Dead-Bytes merged 2 commits into
pre-releasefrom
feat/tokensa
May 18, 2026
Merged

[DONE] feature/tokensa — implement token usage tracking and fix queue-bootstrap schema mismatches#49
Dead-Bytes merged 2 commits into
pre-releasefrom
feat/tokensa

Conversation

@bharatsachya
Copy link
Copy Markdown
Collaborator

What changed

  • LLM Token Tracking:
    • Updated @bb/llm clients (jsonClient, ollama, openrouter) to return inputTokens and outputTokens in analysis responses.
    • Refactored analysis strategies (file, folder, repo summary) to bubble up token usage through the pipeline.
    • Enhanced GithubKnowledgeSource and KnowledgeInfo types to support CommitHashRecord with token metrics.
  • Queue Bootstrap Fixes (Enterprise):
    • Lint: Resolved all no-explicit-any and curly errors in packages/knowledge-server/src/queue-bootstrap.ts.
    • Bug Fix: Migrated from record.source to record.info.githubInfo to align with the enterprise schema and ensure ingestion stats are correctly synced.
    • Type Safety: Mapped OSS status.processedFiles to enterprise info.githubInfo.noOfFilesProcessed to resolve TypeScript compilation errors.
  • Persistence Layer: Updated persistIngestionRun in packages/progress to accurately record token usage by commit and increment user usage metrics in the users collection.

Why

  • Usage Granularity: We need to track LLM costs at a per-commit and per-run level for better visibility into ingestion overhead.
  • Schema Alignment: The enterprise knowledge-server was failing to sync stats because it was looking for commit IDs in the OSS-specific source field instead of the enterprise-standard info.githubInfo.
  • System Stability: Resolving these type mismatches and lint errors prevents runtime crashes during job completion.

How to test

  1. Verify Builds & Lint:
    • Run bun run lint in the root.
    • Run bun run typecheck in the root.
  2. End-to-End Ingestion:
    • Trigger a GitHub ingestion job for a repository.
    • Once completed, verify the knowledge record in MongoDB:
      • Check info.githubInfo.tokenUsageByCommit for the current commit hash.
      • Check info.githubInfo.commitHashes for the new inputTokens and outputTokens fields.
  3. Usage Metrics:
    • Verify that the user's usage field in the users collection has been incremented by the total token count (input + output) of the ingestion run.

@bharatsachya bharatsachya changed the base branch from main to pre-release May 15, 2026 00:12
@Dead-Bytes Dead-Bytes added enhancement New feature or request Ready for Review Ready for review from reviewers atomic labels May 18, 2026
@Dead-Bytes Dead-Bytes merged commit 4043b7c into pre-release May 18, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

atomic enhancement New feature or request Ready for Review Ready for review from reviewers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants