Skip to content

Performance: Large diffs can exceed model token limits without proper handling #79

Description

@12britz

Issue

When processing large diffs (many files or large changes), the token counting and truncation logic may not properly account for all providers' token limits, leading to API errors.

Current Behavior

  • src/gac/diff_scoring.py implements smart_truncate_diff but uses a fixed model (anthropic:claude-3-haiku-latest) for token counting
  • Different providers have vastly different context windows:
    • OpenAI GPT-4o: 128k tokens
    • Anthropic Claude: 200k tokens
    • Some local models (Ollama): 4k-8k tokens
    • Gemini: 1M+ tokens
  • The max_tokens parameter in CLI defaults to 4000 but isn't validated against the selected model's limits

Risk

  • Users with local models (Ollama, LM Studio) will hit token limit errors on moderately large diffs
  • No clear error message when token limit is exceeded - just generic API errors
  • Grouped commits (-g flag) multiply token usage but scaling is arbitrary (multiplier = min(5, 2 + (num_files // 10)))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions