← Back to Pull requests

security: finalize interview-readiness RAG trust boundaries and repository truth #25

Closed
unknown closed this pull request without merging on Oct 03, 2026 19:30 UTC
View on GitHub
unknown unknown commented on Oct 03, 2026 07:26 UTC
Author

Refs #24

Why

This PR is the integration surface for Issue #24: a bounded enterprise-RAG security hardening pass plus repository-truth reconciliation. The documentation/evidence layer has now had its final cross-file audit, and CI status is established on the branch head, so it is ready for review.

Implemented on this branch

  • explicit untrusted retrieved-context boundary in prompt construction;

  • reserved trust-boundary marker encoding (RESERVED_TRUST_BOUNDARY_MARKERS, six structural markers) across retrieved evidence, current user input, replayed conversation history and continuation assistant prefixes;

  • explicit precedence of the current user query over stale historical instructions;

  • application-owned continuation-instruction boundary;

  • fail-closed uint32 mask validation at both permission boundaries (identity ingress and cache I/O);

  • access-token issuance refuses to let extra_claims shadow the claims it owns (_ACCESS_TOKEN_RESERVED_CLAIMS);

  • Redis L2 cache physical partitioning by role/dept masks (rag:l2:rm:{role}:dm:{dept}:{key}), with no fallback read of legacy unscoped keys — tests/test_cache.py::test_no_legacy_unscoped_fallback;

  • stronger repository consistency guards around observability/evidence wording.
  • These controls are defense-in-depth. They do not claim prompt injection is solved, the model is jailbreak-proof, or RBAC is fully validated in production. docs/security-regression-coverage.md states each control's boundary and the gap that remains open, and no guardrail framework was added to satisfy the checklist.

    Reconciled before Ready for Review

  • Unified the evidence vocabulary used by docs/interview-evidence-map.md and docs/repository-truth-audit.md; docs/README.md carries an inventory that must equal the canonical taxonomy.

  • Reconciled Qdrant evidence wording: the PR #6/#7 real local container run is preserved as development lineage, kept apart from the current in-memory QdrantClient(":memory:") coverage, and neither direction is asserted alone.

  • Fixed audit lineage: #22 is completed by merged PR #23; #24 / this PR is the current reconciliation scope. Lineage is anchored on the tracking issue, never on a PR number, so no "latest PR" invariant can go stale.

  • Re-audited README, PRD, docs index, architecture baseline, evidence map, truth audit, operations/pre-launch/security-facing docs and CHANGELOG for stale Jaeger/OTLP, Milvus/Qdrant, performance/quality and v2.5/2.3.0 wording.

  • Verified the poisoned-document, indirect-prompt-injection, cross-role retrieval/cache leakage, malformed-JWT-claim and deletion/stale-chunk cases are either covered by deterministic tests or explicitly recorded as bounded gaps.

  • Ran repository consistency, full pytest, Ruff check/format check, compileall, git diff --check and Compose validation on the final head.

  • Established GitHub CI status on the final head.
  • Final cross-file audit corrections (documentation only, no code and no number changed)

  • docs/security-regression-coverage.md row B no longer claims byte fidelity for ingested text; the cited normalizer rewrites newlines and strips, and ingestion size-caps.

  • same file, row D no longer records a remaining gap that tests/test_retrieval_authorization_contract.py:28 already covers.

  • PRD.md labels the KV per-token figure a model estimate rather than a measurement; no benchmark artifact exists and the vLLM topology has never been executed here.

  • docs/slo-runbook.md no longer points the SLO-3 follow-up at closed Issue #20; it points at the audit's open external-validation tracker map.
  • Reconciliation lineage guard, and the parser bug that made it self-satisfying

    COMPLETED_RECONCILIATION_ISSUES = (16, 20, 22) and CURRENT_RECONCILIATION_ISSUE = 24 were already present on this branch, together with the "Reconciliation lineage invariants" section in the audit. What was not equivalent was the tracker-bullet parser those guards read through.

    _tracker_bullets() split the ## External validation tracker map section at list markers only. The section also contains three closing notes (Closing #20 being completed records ..., Closing #16 records ..., Closing #22 likewise records ...) as trailing prose paragraphs, so all three were glued onto whichever bullet preceded them — the #12 row.

    That made the lineage guard satisfiable by the note it was meant to police. Deleting the - [#22] ... reconciliation: completed, delivered by PR #23. row left the glued note Closing #22 likewise records only that ... was delivered as the only bullet mentioning #22. It contains neither a _COMPLETED_MARKER_RE token (closed|completed|merged|resolved) nor a _CURRENT_SCOPE_RE match, so audit_tracker_errors() returned [] — a tracker map that had lost a completed reconciliation row passed the check written to catch exactly that. Measured on the pre-fix head:

    baseline errors:                          []
    drop the #22 completed row   -> NO #22 ERROR     <- guard silently passed
    drop the #24 current-scope row -> misattributed "#24 is recorded as completed but is still the current scope"
    

    The fix is in the parser, not the guard: a bullet is the contiguous run of non-blank lines that starts at a list marker, so trailing prose belongs to no bullet (scripts/check_repo_consistency.py:_tracker_bullets). Both rows are now caught with their intended messages:

    baseline:                                  clean
    drop #22 row -> completed reconciliation issue #22 is no longer recorded in the tracker map; ...
    drop #24 row -> current reconciliation issue #24 is not recorded in the tracker map; ...
    

    Five tests pin the behaviour: test_audit_tracker_keeps_completed_reconciliation_off_the_current_scope, test_audit_tracker_requires_the_current_reconciliation_issue_to_be_recorded, test_reconciliation_lineage_is_not_pinned_to_a_pr_number, test_completed_reconciliation_issues_must_stay_in_the_tracker_map, test_audit_tracker_bullets_stop_at_a_blank_line.

    Only that parser change and its tests were taken from chore/governance-lineage-22-24; no other commit from that branch is on this one. _BULLET_SPLIT_RE also matching at the \n before a bullet is pre-existing and left alone.

    Verification on final head 336e325

    All rows below were executed on this head, not carried over from an earlier candidate.

    | Gate | Result |
    |---|---|
    | python scripts/check_repo_consistency.py | Repository consistency check passed. |
    | python -m pytest --collect-only -q | 1724 collected |
    | python -m pytest tests/ -q | 1709 passed, 15 skipped (1724 total) |
    | ruff check . | All checks passed! |
    | ruff format --check . | 259 files already formatted |
    | python -m compileall -q . | clean (exit 0) |
    | git diff --check (worktree and main...HEAD) | clean |
    | Compose: docker-compose.yml alone | valid |
    | Compose: base + each of gpu / cpu / microservices / observability | valid (all 4) |
    | Compose: base + all four overlays together | valid |
    | Compose: observability overlay is purely additive | passes CI's own assertion — added grafana jaeger prometheus, removed none |
    | frontend: npm ci + npm run build | 149 packages installed; build succeeded, 188 modules, index.js 282.60 kB (gzip 88.00 kB) |
    | GitHub Actions on 336e325 | CI — 测试 success, Security — 依赖安全扫描 success, Lint — 代码风格 success |

    Compose was validated with the .env.example variables exported; without them every stack fails fast on a required variable (SERVICE_AUTH_TOKEN, MINIO_ACCESS_KEY, ...), which is intended. The gpu, cpu and microservices overlays are not valid standalone — they need the base file for the app service and rag-network — while observability.yml happens to validate alone. That matches CI, which only ever layers it.

    npm ci still reports the 4 advisories already disclosed in docs/repository-truth-audit.md — 1 moderate baseline-browser-mapping, 3 high (browserslist, nanoid, postcss) — confirmed against npm audit on this head. Remediation is open work, not a gate.

    Evidence boundaries that must remain unchanged without new external evidence

  • #8 stays open: real BGE / CLIP / PaddleOCR / Airflow / real benchmark artifact remain pending.

  • #12 stays open: real RAGAS and real 4B/14B vLLM GPU topology remain pending.

  • #18 stays open: real retrieval benchmark still needs a production-code executor path and an independent corpus with no label leakage.

  • Historical production scale, QPS, traffic, hardware, gray migration and award remain HISTORICAL_PRODUCTION; they are not repository benchmark results.

  • OTLP exporter implementation is not an OTLP closed-loop result.

  • Performance artifact framework is not a measured performance result.
  • Scope guard

    No Kubernetes/Helm, Kafka, GraphRAG, Agent/MCP feature addition, microservice rewrite, vector-store migration, SSO/OIDC platform build, or invented benchmark/quality/performance result in this PR.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: Xander-Xai Review duration: 724m
    All Vouch review confidence checks passed
    Residual risk 0.32 = Change Risk (0.75) × (1 − Review Confidence (0.58)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.75 · 650 lines diff across 8 files
    0.75
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    57%
    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
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.075
    Real PR Conversation Timeline
    1 comments
    "Review active on #25"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 58.0% reviewed sensitive_module
    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: 75.2% (HIGH) · Higher = larger blast radius
    75.2%
    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: 58.0% · Lower = rushed or shallow review
    58.0%
    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: 31.6% · Safe to merge
    31.6%