← Back to Pull requests

[ENH] Add LLM provider interface, Ollama provider and retries #48

Closed
unknown closed this pull request without merging on Nov 28, 2026 23:06 UTC
View on GitHub
unknown unknown commented on Nov 28, 2026 23:06 UTC
Author

Related


Closes #14

Summary


Add src/crosstrace/autoannotate/provider.py.
  • Provider is a small interface: system prompt and user message in, text out.

  • classify() parses the text into a Verdict and retries. Transient errors

  • (429, 5xx, timeout) wait 2 s, 4 s, and so on, up to 60 s. Invalid output is
    also retried. After all attempts it returns None, and the pair goes to
    review as invalid_output.
  • Permanent errors (Ollama not running, model missing) stop the run with a

  • clear message.
  • OllamaProvider uses a local model. It needs no API key. The host comes

  • from OLLAMA_HOST. Temperature 0, seed 42, context 8192 tokens.
  • The JSON schema of Verdict is sent to Ollama. Pydantic checks the answer

  • again.

    How I tested it


  • uv run pytest, uv run ruff check .

  • Tests use a fake provider and a mock HTTP transport. No real call in tests.

  • I ran one real pair with llama3.1:8b by hand.
  • Diff: 115 lines (+86 / -29) across 1 files Reviewer: aashoday Review duration: 0m
    All Vouch review confidence checks passed
    Residual risk 0.27 = Change Risk (0.36) × (1 − Review Confidence (0.26)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.36 · 115 lines diff across 1 files
    0.36
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 13% · Reviewer familiarity: 35%
    26%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Shallow Review Depth shallow_review_depth
    0.289
    Diff Size diff_size
    0.284
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #48"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 26.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 36.4% (MEDIUM) · Higher = larger blast radius
    36.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 26.5% · Lower = rushed or shallow review
    26.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 26.8% · Safe to merge
    26.8%