← Back to Pull requests

feat(#384): a shared research cache whose failure modes are disclosure, not staleness #389

Open
unknown opened this pull request with 301 lines diff across 3 files
View on GitHub
unknown unknown commented on Nov 30, 2026 13:52 UTC
Author

feat(#384): a shared research cache whose failure modes are disclosure, not staleness

Two clients asking the same question within 24 hours should cost one retrieval and one generation. The
client contract already carried cached, refresh and answered_at; nothing implemented the cache
behind them, so this adds it as a library with an explicit store protocol — Mongo/Redis adapters and the
request handler stay with the service that owns retrieval.

What it is careful about, because each item is a way a cache corrupts a research answer:

  • Scope is in the key. A researcher's private answer does not exist for a demo user or another

  • principal. Serving across scopes is a disclosure, not a staleness bug.
  • Normalisation is case and whitespace only. "Does the left support the AI Act" and "…oppose…" differ

  • by one token and by everything that matters; no stemming, no synonym folding.
  • Negative answers expire early and name their dependency. An insufficient_evidence entry lives 6 h

  • instead of 24 h and records the pending_task_ids it waits on; the finishing task invalidates it, so a
    user is not told "unknown" after the evidence arrived.
  • Single flight. 120 s reservation per key; concurrent identical requests do not launch two agent

  • jobs, different questions never block each other, and a dead worker's reservation is reclaimable.
  • The cache is never load-bearing. A store that raises is a miss: a Mongo or Redis outage degrades to

  • the normal retrieval path rather than failing the chat.

    Cached rag.retrieve results and generated research.answer results are kept separately, so retrieved
    evidence is never presented as a generated answer or the reverse.

    Evidence

    18 offline tests (tests/test_issue_384_research_cache.py) and 18 existing transport/assistant tests still
    pass; scripts/check_public_tree.py passes; ruff clean.

    Also: the Research Assistant skill now states the answer-side rules — label a cached answer with its
    original timestamp and revisions, honour refresh, and never repeat a negative answer whose named task has
    succeeded — and docs/AI26_RESEARCH_CACHE.md records the contract and what is deliberately not built here.

    Not in this PR: the chat page and its authorization, the service that stores these entries, and the
    dispatcher that carries fire-and-forget collection.discover requests (shared transport, Analysis-owned).

    Diff: 301 lines (+225 / -76) across 3 files Reviewer: chatgpt-codex-connector[bot] Review duration: 2m
    All Vouch review confidence checks passed
    Residual risk 0.30 = Change Risk (0.40) × (1 − Review Confidence (0.25)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 301 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 30% · Reviewer familiarity: 35%
    24%
    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.344
    Diff Size diff_size
    0.342
    Real PR Conversation Timeline
    1 comments
    "Review active on #389"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 24.8% 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: 40.1% (MEDIUM) · Higher = larger blast radius
    40.1%
    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: 24.8% · Lower = rushed or shallow review
    24.8%
    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: 30.1% · Safe to merge
    30.1%