← Back to Pull requests

feat(remediation): the machine-principal progress door #416

Closed
unknown closed this pull request without merging on Nov 10, 2026 20:37 UTC
View on GitHub
unknown unknown commented on Nov 10, 2026 17:15 UTC
Author

What

Merged and abandoned had no REST write path. The ask-B design proposed machine-principal doors for record_progress; what landed was the person-only PR door (POST /v1/remediations/{work_item_id}/pull-request → record_pull_request, verified humans only, pr_opened only). record_progress itself — merged/abandoned, where a PR-filing loop's tracking ends an attempt — had no route, so SCI's auto-filing loop (a machine, outside any order lease) could never drain its pending outbox for the terminal statuses. This adds the machine-principal half of that door:

  • Route (rest/remediation/remediations.py): POST /v1/remediations/{work_item_id}/progress, body the new core model ProgressReport (status: merged | abandoned, optional merge_sha, optional actor), responding with the moved WorkItem — the same shape as the sibling PR door.

  • Authorization (OpsService.authorize_write, new beside authorize_request): a verified person, or a verified machine inside a recording.start grant naming remediate_finding on the work item's repository — the same grant/allowlist the scheduling door and the record doors key on (_may_request, one rule now with two doors). Unverified, ungranted, and out-of-scope machines are refused (403); filing happens outside order leases, so no lease is bound.

  • Service (RemediationService.record_outcome): locks the item's findings, then record_progress (which now accepts a rationale) moves the fold — one decision per finding, merged/abandoned as its reason, the merge SHA and actor as its rationale, resolution still open (remediation progress never establishes that a finding is fixed). Replays are no-ops (statement-key idempotency); a status the forward-only state machine refuses answers 409; a retry after an ended attempt is a new work item, as before.

  • ProgressReport refuses a run's own statuses (patched, forked, … — those come from the report) and a merge_sha that is not a full git SHA or that rides an abandoned report.
  • SCI's consumption is the follow-up, deliberately not here: once this merges, traust-sdk regenerates from the OpenAPI and SCI's filing loop drains its pending outbox through the door (RecordPRMerged/RecordPRClosed in internal/filing/recorder.go, today UnavailableRecorder). Noted in the companion SCI PR (source-code-intelligence docs/remediation-retirement-slice).

    Checklist

  • Targets development

  • Only this domain's service and its section's repositories changed; other domains reached through their services (OpsService.authorize_write extends the existing grant owner)

  • No new tables, columns or row models (model gaps are raised, not worked around) — the merge SHA and actor ride the decisions' existing rationale; a dedicated column is a contracts question, not worked around silently

  • New SQL is a named query on the owning table's repository (no new SQL)

  • 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 (authorize_write shares _may_request with authorize_request rather than restating the grant rule)

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

  • Legacy code deleted only with a parity diff attached (nothing deleted)

  • 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 (12,766 passed / 2 skipped at both heads; pre-push lint+coverage gate passed on each push)
  • Changed tests

    New coverage only, no existing test changed: ProgressReport model tests (terminal-status-only, sha/actor validation, rationale) in tests/v1/models/test_remediation.py; the door's authorization matrix (person, unverified, machine-without-grant, machine-granted-on-another-repository, machine-with-grant) and the merged-with-sha / abandoned transitions with the decision fold and replay idempotency in tests/v1/services/test_remediation.py; the same matrix plus body validation (422s), 404/409 answers and the reads' fold (GET /v1/remediations/{id}, listing at status=merged) over a real HTTP client in tests/v1/rest/remediation/test_remediations.py.

    Qodo corrections — 1eadc537

  • A late run can record past an ended item — refuted, no change. The fold is furthest() over the decisions' reasons, so a terminal status is never displaced by a run's own (merged ranks above every run status); _reported_item refuses a terminal item whenever it reads after the outcome; and in the read-before-outcome window a late-attaching report leaves an ended attempt showing its full life (report + terminal status), which is the domain's answer, not an inconsistency. The same interleaving already exists with the person-only PR door; re-locking the run path is out of scope for this slice.

  • Scheduled fixes can fail after an early end — refuted as the designed rule, no change. An ended attempt accepts no further reports ("nothing after merged or abandoned"; _reported_item refuses), so a run whose attempt ended records its refusal and completes — the identical behavior the in-process record_progress (CLI) path has always had. Retiring a queued or leased order from a data door is a scheduling/ops concern with its own races, deliberately not smuggled into this door.

  • Later merge details cannot be recorded — documented, no change. The ending decision is write-once by statement key (record_resolution's own contract: "Restating the same step changes nothing"): the first accepted report's rationale (merge SHA, forge actor) is what persists; a richer later delivery is a no-op, exactly like every other decision restatement. Requiring the SHA up front would break the door's optional body; enrichment would fight append-only decisions. SCI's loop reports merged carrying the SHA it polled.

  • Terminal decisions omit the real caller — attempted, then refuted by the contract. Implementing Decision.actor on the ending decisions fails the contracts rule CHECK (assessment_id IS NULL OR actor IS NULL): a decision is either a person's statement (actor, no assessment) or an attempt's (assessment, no actor) — the attempt is the author of its own statuses, by design. Reverted; the tests now state that rule where they read the ending decisions (1eadc537). The caller is not lost: the door's authorization names them and the REST access log carries the caller on every request; the forge actor rides the rationale as an explicit claim.
  • Review fixes — a1e3154f, cef97c51 (the changes-requested findings): ProgressReport.actor is capped at intake at the verification rationale's bound (ACTOR_CAP = 500, refused with the door's usual 422 for a bad body), and the caller is gated before the work item is read — OpsService.authorize_recorder: a verified person, or a machine holding a remediate_finding grant somewhere, so an ungranted machine hears a uniform 403 and learns nothing about existence; the repository scope still follows the read, since it lives on the item. Regression tests at the model, service and REST levels.

    Verification: make lint-fix and make test green at cef97c51 (12,768 passed / 2 skipped; coverage 95.2%); CI green on all four commits (lint, test 3.11/3.12, postgres, api-check, ratchet). Qodo re-review at cef97c51 raises the same four findings — answered in the Qodo corrections section above — plus one new against the review fixes (a granted machine's residual 404-vs-403 across repositories), refuted in the thread: the repository scope cannot precede the read it depends on, and what it would distinguish is fully enumerable by any verified caller through GET /v1/remediations.

    💘 Generated with Crush

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: gurnben Review duration: 202m
    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 #416"
    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%