← Back to Pull requests

feat(portfolio,findings): the three doors that retire the database-reaching backfills #513

Closed
unknown closed this pull request without merging on Nov 19, 2026 16:46 UTC
View on GitHub
unknown unknown commented on Nov 18, 2026 18:08 UTC
Author

What

The three core doors the interaction boundary audit sequenced (traust-security/traust-foundry#97, Wave 2) — the doors that retire SCI's three backfill scripts that reached the traust_core database over psql, the audit's Class 4 "shouldn't-exist" findings. The boundary they close is the SDK contract's own principle (the read-side plan, stable-platform): a consumer keeps only its own extension data, joined to traust by id — a missing endpoint is a core change first, an SDK regen second, a rewire third, never a psql prefix. Every door here is batch-shaped from birth, per the perf-coverage plan's statement-bound discipline: one bounded statement per batch, never a per-item fan-out.

1. ResolveRepositories — the batch identity resolution door (S1)

POST /v1/repositories:resolve — the read-side plan's step 1, its S1 shape verbatim: ResolveRepositories(urls) answering, per spelling, the id core already knows.

  • The answer per spelling: the repository's own id, never a neighbor's, the registered spelling, and the upstream edge as the alias_of hint when the matched row carries one — a fork or a mirror is the caller's judgement, not the door's (S1's open question — the URL's own id with an aliasOf hint, or the canonical? Probably both, in one response — answered as designed).

  • A URL correction's vacated spelling follows its edge to the repository that moved — the identity that survived the move (the repo-unreachable design's resolved decision 4).

  • The canonicalizer is core's own, exported once: whitespace, trailing slash and .git stripped, git@ ssh folded to https, host lowercased; scheme and www preserved — deliberately nothing broader. Distinct records a wider fold would collapse meet only as candidates.

  • GitHub's case-insensitive owner/repo folds through one batched case-folded lookup (find_by_urls_casefold); several rows under one folded spelling answer as the candidates, oldest first — the retired script's review list, made the door's honest answer, never a script-side guess.

  • Batch bounds: a page's worth of spellings per request (500), no set is a refusal — never a firehose of the universe.

  • Every verified caller resolves — a machine principal as freely as a person (the reads policy).
  • 2. The default-ref observation door

    POST /v1/repositories/{repository_id}/refs/default — mark_default_branch exposed as the door the retired script's survey half feeds: the forge's default-branch answer (branch + head commit) recorded exactly the way the repo_state observation records it — the get_or_add that adds the line when absent and names the new line the default (a named line is immutable once recorded; earlier flags stay, the naming time orders the default line).

  • The auth is the observation lane's own discipline: every verified caller names one — the engine's machine principals (the lane) and a person's deliberate verify alike, the same policy register_ref carries. Not the person-only gate the disposition doors carry: this door moves no disposition.

  • The route sits beside register_ref and answers its sibling's semantics for the unknown-repository case (the insert's own constraint refusal).
  • 3. The occurrence-claim door

    POST /v1/occurrence-claims — the person-gated write path for the CVSS claims occurrences' reports stated, retiring the backfill that wrote traust.occurrence.cvss_score/cvss_vector in core's DB with the append-only reject_mutation trigger disabled inside each transaction — the sharpest boundary violation in the estate.

  • The write is append-only, absolutely: occurrence rows are one per finding and assessment by contracts constraint, mutation is refused by the guard trigger, and the door never touches the trigger. The claim lands as a governed statement — the data-error decision the claim-audit pattern appends (append_occurrence_claim, beside append_claim: a verified person, a ticket, a meaningful rationale, the ledger's audit append, nothing in the disposition fold).

  • The claim validates through core's own CVSS discipline (models.cvss.score_of — never a guess at a malformed one: a vector without a version prefix, a malformed metric, an uncomputable base score are refused and listed), the finding resolves by fingerprint (the identity both sides share), and the occurrence binds (the assessment must have reported the finding — the same binding the claim-correction path enforces).

  • The honest answers, per claim: recorded, already_recorded (idempotent), already_carried (the occurrence's own columns state it — the fixed intake's FindingCandidate.cvss_* → Occurrence write), conflicting (the review list, never an overwrite — the retired script's own never-overwrite rule), unknown_finding, unreported, invalid. The response carries the coverage counts — the report shape the retired script produced, answered from the door's own responses.

  • Batched: a page's worth of claims per request, processed in a deterministic order (the append locks each finding's row; sorted they queue).
  • What this does not do

    The historical NULL-CVSS occurrence columns are not rewritten: occurrence rows keep what they said, by the append-only design's own choice (the intake fix's own words). The claims are recorded as governed statements under a person's authority; serving them through the read models is the read-side plan's own sequencing (S3's generic query, S4's typed accessors), not this wave's.

    Checklist

  • Targets development

  • Only this domain's service and its section's repositories changed; other domains reached through their services

  • No new tables, columns or row models (model gaps are raised, not worked around)

  • New SQL is a named query on the owning table's repository (find_by_urls, find_by_urls_casefold)

  • No reads of files or databases outside the contract tables and ObjectStore; no in-memory stand-ins in src/

  • Duplicated responsibility touched by this change moved to its owner, copy deleted

  • Tests: behaviour on SQLite (+ Postgres for new queries) via uow / seed

  • Legacy code deleted only with a parity diff attached (nothing deleted — the retirement is SCI-side)

  • Comments only for non-obvious whys; docstrings one or two lines, none on private helpers

  • No reinvented functions (searched src/); shared logic is one helper

  • Tests cover edge cases; integration tests use sanitized copies of real data

  • Diff is as small as it can be

  • make lint-fix && make test green
  • Tests

  • tests/v1/rest/portfolio/test_resolution.py — the registered spelling; the drift folds (trailing slash, .git, git@, host case); the GitHub case drift and the folded collision (candidates, oldest first); the vacated-spelling follow; the fork's own id with the upstream hint; the honest absences; batch order; machine equals person; the empty/oversized refusals; 401; the operation id the SDK generates.

  • tests/v1/rest/portfolio/test_default_ref.py — naming the line; the new-answer semantics (earlier flags stay, current-default orders by naming time); the get_or_add beside the observation lane's own records; machine equals the lane; the unknown-repository 409; the malformed 422; 401; the operation id.

  • tests/v1/rest/findings/test_occurrence_claims.py — the recorded statement (the audit trail, and the append-only proof: the occurrence keeps what it said); idempotency; already-carried; conflicting-never-overwrites; the per-claim refusals; batch order + counts; the machine principal refused (403); the weak authority 422; empty/oversized; 401; the operation id.
  • Gates

  • make lint green.

  • Full unit suite: 14969 passed, 2 skipped.

  • Integration (make test-integration, Postgres): 4246 passed, 6 skipped, with the same two failures origin/development itself carries (test_renders_through_context[postgres], test_repository_display_search_and_sort_fall_back_to_ids[postgres] — reproduced on a pristine base checkout side-by-side) and the same parallel-run error flakiness this host's local Postgres shows identically for my branch and the pristine base (every erroring test passes in isolation).

  • make api-check: 91 paths (was 88).
  • The chain

    The door pattern (foundry#88): core (this PR) → traust-sdk regen at this ref (ResolveRepositories, MarkDefaultBranch, RecordOccurrenceClaims) → source-code-intelligence (the three scripts' retirement). Routed for review — not to be merged before the review lands.

    💘 Generated with Crush

    Assisted-by: Crush:rits/zai-org/glm-5-3

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: gurnben Review duration: 1357m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    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%
    60%
    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
    Real PR Conversation Timeline
    1 comments
    "Review active on #513"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.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: 52% (MEDIUM) · Higher = larger blast radius
    52%
    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: 60.5% · Lower = rushed or shallow review
    60.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: 20.5% · Safe to merge
    20.5%