← Back to Pull requests

feat(rest): the remediation record door, POST /v1/remediation-records #369

Merged
gurnben merged 10 files (766 lines) on Nov 06, 2026 17:48 UTC
View on GitHub
gurnben gurnben commented on Nov 04, 2026 23:17 UTC
Author

What

RemediationService.record was reachable only in-process, so a runner executing a remediation order could not hand its patch report back — SCI's remediation pipeline had no way to record a report at all. This adds POST /v1/remediation-records, mirroring the verification-records door:

  • Route (rest/remediation/remediation_records.py): the report artifact as the payload (validated against the contracts remediation schema), provenance with run_id == run_order_id, and the caller's leased run_order_id; responds with the recorded work item.

  • Service (RemediationService.record_order): wraps record in OpsService.recording authorization — verified machine principal, live lease held by that principal, repository scope (resolved from doc.metadata.repository), asset allowlist, provenance source — exactly the VerificationService.record_order pattern.

  • The report then attaches to the work item, its Jira keys link, and the item moves to its status; re-recording is a no-op (verified by replay tests).
  • Deviation from the verification door, and why: contracts has neither a remediation_report source type nor a recording.remediation config section (checked: not on the pinned pin, not on contracts development either), and tests/v1/context/test_traust_yaml.py pins RecordingConfig's keys to the contracts traust schema both ways. So the door records under the triage source and authorizes under the triage asset allowlist — matching what the in-process flow already uses for remediation provenance (SourceType.TRIAGE_REPORT) — with NEED(contracts: …) markers in services/operations.py and context/context.py. When contracts grows both, the flip is: a source-type value in _RECORDING_SOURCES and reading the door's own config section in Context._wire. A second, smaller deviation: no run_order_id is stored on the work item's assessment (verification stores one on the assessment it creates; remediation attaches to a pre-existing work-item assessment opened outside the order, so there is nothing to rebind — the door's replay test asserts the no-op instead).

    Unblocks progress-tracker followups 2026-11-02 ask A (plans traust-standardization/9-validation-remediation/03, SCI filing provider lane 5). SDK half: traust-security/traust-sdk feat/remediation-record-template.

    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

  • 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

  • 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
  • Changed tests

    Real Context/store tests exercise SQLite and PostgreSQL: native scheduled order recording, exact-byte preservation and replay, named-item isolation across findings and abandoned attempts, identical-byte retries, explicit starts without a named item, rejected obsolete assets, and unchanged rows/object bytes on authorization or payload refusal. Triage exclusion and remediation fixtures now use the scheduler-owned remediate_finding asset.

    💘 Generated with Crush

    Qodo corrections — ef49d242

  • Scheduled runners rejected: recording and triage exclusion now use the scheduler-owned remediate_finding asset. Both scheduled leases and explicitly started native leases are supported. The unmerged remediation asset is refused even if allowlisted; no alias or second asset definition remains.

  • Wrong/stale work item and retry replay: pass the leased order's work_item_id into the existing recorder. It scopes both finding-set selection and digest replay, so an abandoned attempt cannot mutate a newer item, another same-repository finding set cannot be substituted, and identical bytes on a named retry record against that retry. Orders with no named work item retain the existing finding-based behavior.

  • Cross-repository finding: the current branch already contains the repository guard. The exact inverse-mismatch attack (metadata names leased A, finding belongs to B) was exercised on SQLite/PostgreSQL and over a real HTTP server: 403, with all SQL rows/object bytes unchanged. No guard was weakened or bypass added to appease a stale review listing.
  • All four new failing-before scenarios now pass. Existing replay, explicit-start, lease-owner, provenance, default-deny and triage/remediation separation coverage remains exercised.

    Verification: make lint-fix passed; focused SQLite/PostgreSQL service/REST suite 397 passed; make test 11,500 passed / 1 skipped; normal pre-push lint/coverage 95.34% (same 11,500 tests); OpenAPI builds with 69 paths. A throwaway real HTTP server additionally proved schedule → claim → report, identical-byte named retry/replay, stale-order refusal and cross-repository refusal without writes.

    The README documents the native asset, temporary triage config/source mapping, and named versus unbound order semantics. Current-head Qodo re-review is being requested; this is verification evidence, not a premature zero-findings claim.

    Diff: 766 lines (+761 / -5) across 10 files Reviewer: chubirka Review duration: 2550m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.56) × (1 − Review Confidence (0.69)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.56 · 766 lines diff across 10 files
    0.56
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.58 · 5 substantive comment(s)
    0.58
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    69%
    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.397
    Real PR Conversation Timeline
    12 items
    qodo-code-review[bot] qodo-code-review[bot] commented on Nov 04, 2026 23:21 UTC
    Bot

    <h3>Code Review by Qodo</h3>

    <code>🐞 Bugs (1)</code> <code>📘 Rule violations (0)</code> <code>📜 Skill insights (0)</code>

    <img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">

    <br/>

    <img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">

    <details>
    <summary> 1. <s>Scheduled runners cannot submit reports</s> <code>✓ Resolved</code></summary>

    <br/>

    <p><b>Resolving commit:</b> <a href="https://github.com/traust-security/traust-core/commit/ef49d242fb889cc119e794e7936f4620ffd22d69"><code>ef49d24</code></a></p>

    <details>

    ><summary>Resolution reason</summary>
    ><br/>
    ><pre>

    >The recording check in RemediationService.record_order now compares order.asset against
    >REMEDIATE_FINDING (the scheduler&#x27;s asset) instead of the removed REMEDIATION_RECORD constant, so
    >orders created by POST /v1/remediations are accepted. The triage door&#x27;s exclusion in decisions.py
    >was also switched to REMEDIATE_FINDING, and the test suite gained a test that schedules via the
    >native remediation flow, claims the order, and records its report successfully. The legacy
    >&#x27;remediation&#x27; asset is explicitly refused (test case &#x27;obsolete remediation asset&#x27;), which is a
    >deliberate decision that the finding asked to be made explicit.
    ></pre>
    ></details>

    <!-- qodo-finding-reference
    <code>↗ src/traust_core/v1/services/remediation.py[R563]</code>
    -->

    <details>

    ><summary>Description</summary>
    ><br/>
    ><pre>

    ><b><i>record_order</i></b> requires an order asset named <b><i>remediation</i></b>, but
    ><b><i>RemediationSchedulingService.create</i></b> submits the work item’s order with the asset
    ><b><i>remediate_finding</i></b>. A runner claiming an order created by <b><i>POST /v1/remediations</i></b> receives a 403
    >from the new recording door, even if that asset is added to the shared recording allowlist.
    ></pre>
    ></details>

    <hr/>
    </details>

    <details>
    <summary> 2. <s>A stale runner can resolve a newer work item</s> <code>✓ Resolved</code></summary>

    <br/>

    <p><b>Resolving commit:</b> <a href="https://github.com/traust-security/traust-core/commit/ef49d242fb889cc119e794e7936f4620ffd22d69"><code>ef49d24</code></a></p>

    <details>

    ><summary>Resolution reason</summary>
    ><br/>
    ><pre>

    >The diff changes record_order so that it now returns self.record(doc, provenance,
    >work_item_id=order.work_item_id), passing the leased order&#x27;s named work item into recording instead
    >of relying on finding-based selection. It also enforces the native REMEDIATE_FINDING asset on the
    >order. The added tests (test_named_order_cannot_record_another_work_item, parametrized for &quot;another
    >finding&quot; and &quot;newer attempt&quot;) cover the stale-order scenario where a still-leased order must not
    >modify a newer item, matching the suggested regression test.
    ></pre>
    ></details>

    <!-- qodo-finding-reference
    <code>↗ src/traust_core/v1/services/remediation.py[R579]</code>
    -->

    <details>

    ><summary>Description</summary>
    ><br/>
    ><pre>

    ><b><i>record_order</i></b> calls <b><i>record</i></b> without the leased order’s <b><i>work_item_id</i></b>, so <b><i>_reported_item</i></b> selects
    >an open item matching the report’s findings instead of the item named by the order. If the named
    >item has been abandoned and another is opened for those findings, a still-leased order can attach
    >its report and record resolutions against the newer item.
    ></pre>
    ></details>

    <hr/>
    </details>

    <details>
    <summary> 3. <s>Remediation runners can change triage</s> <code>✓ Resolved</code></summary>

    <br/>

    <p><b>Resolving commit:</b> <a href="https://github.com/traust-security/traust-core/commit/9773d1c416f424b074798f95a3de3d37cd1cdb4d"><code>9773d1c</code></a></p>

    <details>

    ><summary>Resolution reason</summary>
    ><br/>
    ><pre>

    >The triage door (FindingDecisions.record_triage) now checks the leased order&#x27;s asset and refuses
    >with ForbiddenError when it is the remediation asset, so a remediation lease cannot record triage. A
    >regression test posts a triage report under a remediation lease and expects 403 with no writes.
    ></pre>
    ></details>

    <!-- qodo-finding-reference
    <code>↗ src/traust_core/v1/context/context.py[R777]</code>
    -->

    <details>

    ><summary>Description</summary>
    ><br/>
    ><pre>

    ><b><i>Context._wire</i></b> gives remediation recording the triage allowlist, but <b><i>record_triage</i></b> also accepts
    >every asset on that list without excluding remediation orders. When <b><i>remediation</i></b> is added to
    ><b><i>recording.triage</i></b> to enable the new door, a runner holding a remediation lease can submit a triage
    >report for that repository and record triage decisions.
    ></pre>
    ></details>

    <hr/>
    </details>

    <details><summary><ins><strong>View high (2)</strong></ins></summary><br/>
    <details>
    <summary> 4. <s>Triage runners can resolve work items</s> <code>✓ Resolved</code></summary>

    <br/>

    <p><b>Resolving commit:</b> <a href="https://github.com/traust-security/traust-core/commit/88d53b52dc4d6651ae8d9e3229b5e883683f1129"><code>88d53b5</code></a></p>

    <details>

    ><summary>Resolution reason</summary>
    ><br/>
    ><pre>

    >N/A
    ></pre>
    ></details>

    <!-- qodo-finding-reference
    <code>↗ src/traust_core/v1/context/context.py[R777]</code>
    -->

    <details>

    ><summary>Description</summary>
    ><br/>
    ><pre>

    ><b><i>record_order</i></b> accepts any leased order whose asset appears in the triage recording allowlist,
    >because that list is also used for remediation and no check requires a remediation order. When an
    >operator allows a triage asset, its lease holder can submit a valid same-repository remediation
    >report that attaches to an open work item and records finding resolutions without holding a
    >remediation lease.
    ></pre>
    ></details>

    <hr/>
    </details>

    <details>
    <summary> 5. Runners can alter other repositories <code>🐞 Bug</code> <code>⛨ Security</code></summary>

    <br/>

    <details open>

    ><summary>Description</summary>
    ><br/>
    ><pre>

    ><b><i>record_order</i></b> authorizes the lease against <b><i>doc.metadata.repository</i></b>, but <b><i>record</i></b> chooses the work
    >item from <b><i>doc.source_findings</i></b> without checking that those findings belong to the authorized
    >repository. A runner leased to repository A can submit a report naming A while referencing an open
    >work item’s findings in repository B, causing the report, Jira links, and resolutions to be written
    >for B.
    ></pre>
    ></details>

    <details>

    ><summary>Code</summary>
    ><br/>
    ><code>[src/traust_core/v1/services/remediation.py[515]](https://github.com/traust-security/traust-core/pull/369/files#diff-121ba6e02fa43c531f8660c422c27b3b075f3e4d890c049e467fe6e559222f9eR515-R515)</code>

    >
    >+        repository = self._inventory.find_repository(doc.metadata.repository)
    >

    ></details>

    <details>

    ><summary>Evidence</summary>
    ><br/>
    ><pre>

    >The new authorization input comes solely from report metadata. The lease check compares the order
    >with that supplied repository ID, whereas the unchanged recorder independently selects and updates a
    >work item by the findings’ repository. The new wrong-repository test changes metadata rather than
    >exercising the inverse mismatch.
    ></pre>
    > <code>[src/traust_core/v1/services/remediation.py\[515-525\]](https://github.com/traust-security/traust-core/blob/ef49d242fb889cc119e794e7936f4620ffd22d69/src/traust_core/v1/services/remediation.py/#L515-L525)</code>

    <code>[src/traust_core/v1/services/operations.py\[365-378\]](https://github.com/traust-security/traust-core/blob/ef49d242fb889cc119e794e7936f4620ffd22d69/src/traust_core/v1/services/operations.py/#L365-L378)</code>

    <code>[src/traust_core/v1/services/operations.py\[407-415\]](https://github.com/traust-security/traust-core/blob/ef49d242fb889cc119e794e7936f4620ffd22d69/src/traust_core/v1/services/operations.py/#L407-L415)</code>

    <code>[src/traust_core/v1/services/remediation.py\[539-573\]](https://github.com/traust-security/traust-core/blob/ef49d242fb889cc119e794e7936f4620ffd22d69/src/traust_core/v1/services/remediation.py/#L539-L573)</code>

    <code>[src/traust_core/v1/services/remediation.py\[808-819\]](https://github.com/traust-security/traust-core/blob/ef49d242fb889cc119e794e7936f4620ffd22d69/src/traust_core/v1/services/remediation.py/#L808-L819)</code>

    <code>[tests/v1/rest/remediation/test_remediation_records.py\[227-235\]](https://github.com/traust-security/traust-core/blob/ef49d242fb889cc119e794e7936f4620ffd22d69/tests/v1/rest/remediation/test_remediation_records.py/#L227-L235)</code>

    ></details>

    <details>

    ><summary>Agent prompt</summary>
    ><br/>
    >
    >The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
    >
    >## Issue description
    >The recording lease is checked against the report metadata, while the target work item is selected from finding IDs that may belong to another repository.
    >
    >## Fix Focus Areas
    >- src/traust_core/v1/services/remediation.py[505-525]
    >- src/traust_core/v1/services/remediation.py[808-819]
    >- tests/v1/rest/remediation/test_remediation_records.py[214-258]
    >
    >## Recommended Fix
    >Before recording, require the repository of every referenced finding and the selected work item to match the repository authorized by the leased order. Add a regression test with metadata naming the leased repository and findings belonging to a second repository; assert refusal and no changed rows or objects.
    >

    <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>

    ></details>

    Dismiss ↗ | View ↗

    <hr/>
    </details>

    </details>

    <img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">

    <!-- qodo-self-review-slot -->

    <!-- qodo-context:start -->
    <details><summary><strong>Context sources</strong></summary>

    <div>Review mode: <code>Auto: ⚖️ Balanced</code>: Lease authorization and work-item scoping changes touch high-risk auth and concurrency areas; logic is modest.</div>
    <!-- qodo-context:end -->
    </details>

    <img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">

    <!-- qodo-daily-tip:start -->

    <details>
    <summary><strong>Tip of the day</strong></summary>

    <br/>

    <pre>💡 Did you know, you can switch off images and animations for a plain-text comment</pre>

    <a href="https://docs.qodo.ai/tips-and-tricks">More tips ↗</a> | <a href="https://app.qodo.ai/configurations?tab=display-preferences">Customize Qodo ↗</a> | <a href="https://docs.qodo.ai">Qodo docs ↗</a>

    </details>

    <img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
    <!-- qodo-daily-tip:end -->

    <!-- https://github.com/traust-security/traust-core/commit/ef49d242fb889cc119e794e7936f4620ffd22d69 -->

    <!-- qodo-previous-reviews:start -->
    <!-- FOLDED_SECTION_START -->

    <details>
    <summary><strong>Previous reviews</strong></summary>

    <br/>

    Review updated until commit <a href="https://github.com/traust-security/traust-core/commit/ef49d242fb889cc119e794e7936f4620ffd22d69">ef49d24</a>

    <details><summary>Results up to commit 98d5f0d <code>⚖️ Balanced</code></summary>

    <br><code>🐞 Bugs (1)</code> <code>📘 Rule violations (0)</code> <code>📎 Requirement gaps (0)</code> <code>🎨 UX issues (0)</code> <code>🔗 Cross-repo conflicts (0)</code> <code>📜 Skill insights (0)</code>

    <br/>

    <img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">

    <details>
    <summary> 1. Runners can alter other repositories <code>🐞 Bug</code> <code>⛨ Security</code></summary>

    <br/>

    <details open>

    ><summary>Description</summary>
    ><br/>
    ><pre>

    ><b><i>record_order</i></b> authorizes the lease against <b><i>doc.metadata.repository</i></b>, but <b><i>record</i></b> chooses the work
    >item from <b><i>doc.source_findings</i></b> without checking that those findings belong to the authorized
    >repository. A runner leased to repository A can submit a report naming A while referencing an open
    >work item’s findings in repository B, causing the report, Jira links, and resolutions to be written
    >for B.
    ></pre>
    ></details>

    <details>

    ><summary>Code</summary>
    ><br/>
    ><code>[src/traust_core/v1/services/remediation.py[515]](https://github.com/traust-security/traust-core/pull/369/files#diff-121ba6e02fa43c531f8660c422c27b3b075f3e4d890c049e467fe6e559222f9eR515-R515)</code>

    >
    >+        repository = self._inventory.find_repository(doc.metadata.repository)
    >

    ></details>

    <details>

    ><summary>Evidence</summary>
    ><br/>
    ><pre>

    >The new authorization input comes solely from report metadata. The lease check compares the order
    >with that supplied repository ID, whereas the unchanged recorder independently selects and updates a
    >work item by the findings’ repository. The new wrong-repository test changes metadata rather than
    >exercising the inverse mismatch.
    ></pre>
    > <code>[src/traust_core/v1/services/remediation.py\[515-525\]](https://github.com/traust-security/traust-core/blob/ef49d242fb889cc119e794e7936f4620ffd22d69/src/traust_core/v1/services/remediation.py/#L515-L525)</code>

    <code>[src/traust_core/v1/services/operations.py\[365-378\]](https://github.com/traust-security/traust-core/blob/ef49d242fb889cc119e794e7936f4620ffd22d69/src/traust_core/v1/services/operations.py/#L365-L378)</code>

    <code>[src/traust_core/v1/services/operations.py\[407-415\]](https://github.com/traust-security/traust-core/blob/ef49d242fb889cc119e794e7936f4620ffd22d69/src/traust_core/v1/services/operations.py/#L407-L415)</code>

    <code>[src/traust_core/v1/services/remediation.py\[539-573\]](https://github.com/traust-security/traust-core/blob/ef49d242fb889cc119e794e7936f4620ffd22d69/src/traust_core/v1/services/remediation.py/#L539-L573)</code>

    <code>[src/traust_core/v1/services/remediation.py\[808-819\]](https://github.com/traust-security/traust-core/blob/ef49d242fb889cc119e794e7936f4620ffd22d69/src/traust_core/v1/services/remediation.py/#L808-L819)</code>

    <code>[tests/v1/rest/remediation/test_remediation_records.py\[227-235\]](https://github.com/traust-security/traust-core/blob/ef49d242fb889cc119e794e7936f4620ffd22d69/tests/v1/rest/remediation/test_remediation_records.py/#L227-L235)</code>

    ></details>

    <details>

    ><summary>Agent prompt</summary>
    ><br/>
    >
    >The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
    >
    >## Issue description
    >The recording lease is checked against the report metadata, while the target work item is selected from finding IDs that may belong to another repository.
    >
    >## Fix Focus Areas
    >- src/traust_core/v1/services/remediation.py[505-525]
    >- src/traust_core/v1/services/remediation.py[808-819]
    >- tests/v1/rest/remediation/test_remediation_records.py[214-258]
    >
    >## Recommended Fix
    >Before recording, require the repository of every referenced finding and the selected work item to match the repository authorized by the leased order. Add a regression test with metadata naming the leased repository and findings belonging to a second repository; assert refusal and no changed rows or objects.
    >

    <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>

    ></details>

    Dismiss ↗ | View ↗

    <hr/>
    </details>

    <!-- qodo-self-review-slot -->

    </details>
    <details><summary>Results up to commit eefa6d9 <code>⚖️ Balanced</code></summary>

    <br><code>🐞 Bugs (0)</code> <code>📘 Rule violations (0)</code> <code>📎 Requirement gaps (0)</code> <code>🎨 UX issues (0)</code> <code>🔗 Cross-repo conflicts (0)</code> <code>📜 Skill insights (0)</code>

    <br/>

    <img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">

    <details>
    <summary> 1. <s>Triage runners can resolve work items</s> <code>✓ Resolved</code></summary>

    <br/>

    <p><b>Resolving commit:</b> <a href="https://github.com/traust-security/traust-core/commit/88d53b52dc4d6651ae8d9e3229b5e883683f1129"><code>88d53b5</code></a></p>

    <details>

    ><summary>Resolution reason</summary>
    ><br/>
    ><pre>

    >N/A
    ></pre>
    ></details>

    <!-- qodo-finding-reference
    <code>↗ src/traust_core/v1/context/context.py[R777]</code>
    -->

    <details>

    ><summary>Description</summary>
    ><br/>
    ><pre>

    ><b><i>record_order</i></b> accepts any leased order whose asset appears in the triage recording allowlist,
    >because that list is also used for remediation and no check requires a remediation order. When an
    >operator allows a triage asset, its lease holder can submit a valid same-repository remediation
    >report that attaches to an open work item and records finding resolutions without holding a
    >remediation lease.
    ></pre>
    ></details>

    <hr/>
    </details>

    <!-- qodo-self-review-slot -->

    </details>
    <details><summary>Results up to commit 88d53b5 <code>⚖️ Balanced</code></summary>

    <br><code>🐞 Bugs (0)</code> <code>📘 Rule violations (0)</code> <code>📎 Requirement gaps (0)</code> <code>🎨 UX issues (0)</code> <code>🔗 Cross-repo conflicts (0)</code> <code>📜 Skill insights (0)</code>

    <br/>

    <img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">

    <details>
    <summary> 1. <s>Remediation runners can change triage</s> <code>✓ Resolved</code></summary>

    <br/>

    <p><b>Resolving commit:</b> <a href="https://github.com/traust-security/traust-core/commit/9773d1c416f424b074798f95a3de3d37cd1cdb4d"><code>9773d1c</code></a></p>

    <details>

    ><summary>Resolution reason</summary>
    ><br/>
    ><pre>

    >The triage door (FindingDecisions.record_triage) now checks the leased order&#x27;s asset and refuses
    >with ForbiddenError when it is the remediation asset, so a remediation lease cannot record triage. A
    >regression test posts a triage report under a remediation lease and expects 403 with no writes.
    ></pre>
    ></details>

    <!-- qodo-finding-reference
    <code>↗ src/traust_core/v1/context/context.py[R777]</code>
    -->

    <details>

    ><summary>Description</summary>
    ><br/>
    ><pre>

    ><b><i>Context._wire</i></b> gives remediation recording the triage allowlist, but <b><i>record_triage</i></b> also accepts
    >every asset on that list without excluding remediation orders. When <b><i>remediation</i></b> is added to
    ><b><i>recording.triage</i></b> to enable the new door, a runner holding a remediation lease can submit a triage
    >report for that repository and record triage decisions.
    ></pre>
    ></details>

    <hr/>
    </details>

    <!-- qodo-self-review-slot -->

    </details>
    <details><summary>Results up to commit efef41b <code>⚖️ Balanced</code></summary>

    <br><code>🐞 Bugs (0)</code> <code>📘 Rule violations (0)</code> <code>📎 Requirement gaps (0)</code> <code>🎨 UX issues (0)</code> <code>🔗 Cross-repo conflicts (0)</code> <code>📜 Skill insights (0)</code>

    <br/>

    <img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">

    <details>
    <summary> 1. <s>A stale runner can resolve a newer work item</s> <code>✓ Resolved</code></summary>

    <br/>

    <p><b>Resolving commit:</b> <a href="https://github.com/traust-security/traust-core/commit/ef49d242fb889cc119e794e7936f4620ffd22d69"><code>ef49d24</code></a></p>

    <details>

    ><summary>Resolution reason</summary>
    ><br/>
    ><pre>

    >The diff changes record_order so that it now returns self.record(doc, provenance,
    >work_item_id=order.work_item_id), passing the leased order&#x27;s named work item into recording instead
    >of relying on finding-based selection. It also enforces the native REMEDIATE_FINDING asset on the
    >order. The added tests (test_named_order_cannot_record_another_work_item, parametrized for &quot;another
    >finding&quot; and &quot;newer attempt&quot;) cover the stale-order scenario where a still-leased order must not
    >modify a newer item, matching the suggested regression test.
    ></pre>
    ></details>

    <!-- qodo-finding-reference
    <code>↗ src/traust_core/v1/services/remediation.py[R579]</code>
    -->

    <details>

    ><summary>Description</summary>
    ><br/>
    ><pre>

    ><b><i>record_order</i></b> calls <b><i>record</i></b> without the leased order’s <b><i>work_item_id</i></b>, so <b><i>_reported_item</i></b> selects
    >an open item matching the report’s findings instead of the item named by the order. If the named
    >item has been abandoned and another is opened for those findings, a still-leased order can attach
    >its report and record resolutions against the newer item.
    ></pre>
    ></details>

    <hr/>
    </details>

    <details>
    <summary> 2. <s>Scheduled runners cannot submit reports</s> <code>✓ Resolved</code></summary>

    <br/>

    <p><b>Resolving commit:</b> <a href="https://github.com/traust-security/traust-core/commit/ef49d242fb889cc119e794e7936f4620ffd22d69"><code>ef49d24</code></a></p>

    <details>

    ><summary>Resolution reason</summary>
    ><br/>
    ><pre>

    >The recording check in RemediationService.record_order now compares order.asset against
    >REMEDIATE_FINDING (the scheduler&#x27;s asset) instead of the removed REMEDIATION_RECORD constant, so
    >orders created by POST /v1/remediations are accepted. The triage door&#x27;s exclusion in decisions.py
    >was also switched to REMEDIATE_FINDING, and the test suite gained a test that schedules via the
    >native remediation flow, claims the order, and records its report successfully. The legacy
    >&#x27;remediation&#x27; asset is explicitly refused (test case &#x27;obsolete remediation asset&#x27;), which is a
    >deliberate decision that the finding asked to be made explicit.
    ></pre>
    ></details>

    <!-- qodo-finding-reference
    <code>↗ src/traust_core/v1/services/remediation.py[R563]</code>
    -->

    <details>

    ><summary>Description</summary>
    ><br/>
    ><pre>

    ><b><i>record_order</i></b> requires an order asset named <b><i>remediation</i></b>, but
    ><b><i>RemediationSchedulingService.create</i></b> submits the work item’s order with the asset
    ><b><i>remediate_finding</i></b>. A runner claiming an order created by <b><i>POST /v1/remediations</i></b> receives a 403
    >from the new recording door, even if that asset is added to the shared recording allowlist.
    ></pre>
    ></details>

    <hr/>
    </details>

    <!-- qodo-self-review-slot -->

    </details>

    </details>

    <img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
    <!-- qodo-previous-reviews:end -->

    <a href="https://www.qodo.ai"><img src="https://www.qodo.ai/wp-content/uploads/2025/03/qodo-logo.svg" width="80" alt="Qodo Logo"></a>

    qodo-code-review[bot] qodo-code-review[bot] commented on Nov 05, 2026 23:51 UTC
    Bot
    qodo-code-review[bot] qodo-code-review[bot] commented on Nov 06, 2026 02:59 UTC
    Bot
    gurnben gurnben commented on Nov 06, 2026 14:48 UTC
    Author

    9773d1c (amending 88d53b5 into the branch's single commit) takes Qodo's new finding and the mirror it implies:

  • Remediation runners can change triage: record_triage now requires the leased order to be a triage order (src/traust_core/v1/services/findings/decisions.py) — the same guard record_order got on the remediation side. The shared triage allowlist (the NEED(contracts) shape smith-xyz asked about) cuts both ways: once an operator adds the remediation asset to recording.triage to enable this door, the allowlist alone would have admitted a remediation lease at the triage door too. Both doors now check the leased order's asset, so the borrow is safe in both directions until contracts lands a recording.remediation section. Regression case: remediation lease in test_triage_authority_and_provenance_refusals_precede_all_report_mutations (fails on 88d53b5).

  • Runners can alter other repositories is fixed at 88d53b5 and unchanged since: record_order refuses the report when its findings' single repository is not the repository the lease names (src/traust_core/v1/services/remediation.py, the covered check), with the findings of another repository regression case in test_order_authorization_refusals_leave_rows_and_objects_unchanged (fails on eefa6d9). The re-review's description for this still quotes the pre-fix code, so it reads as a stale listing rather than an open finding — happy to walk through the scenario if you see a path the guard misses.

  • Triage runners can resolve work items — resolved at 88d53b5, thanks.
  • Suite: 11,353 passed.

    qodo-code-review[bot] qodo-code-review[bot] commented on Nov 06, 2026 14:56 UTC
    Bot
    qodo-for-traust-sci[bot] qodo-for-traust-sci[bot] commented on Nov 06, 2026 16:26 UTC
    Bot

    <h3>Code Review by Qodo</h3>

    <br/>

    <img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">

    _Nice, no open findings for this group_

    <br/>

    <img src="https://img.shields.io/badge/Medium-634FD1?style=flat-square" height="20px" alt="Remediation recommended">

    _Nice, no open findings for this group_

    <br/>

    <img src="https://img.shields.io/badge/Low-634FD1?style=flat-square" height="20px" alt="Informational">

    _Nice, no open findings for this group_

    <br/>

    <!-- qodo-self-review-slot -->
    <!-- https://github.com/traust-security/traust-core/commit/ef49d242fb889cc119e794e7936f4620ffd22d69 -->

    qodo-code-review[bot] qodo-code-review[bot] commented on Nov 06, 2026 16:29 UTC
    Bot
    chubirka chubirka commented on Nov 06, 2026 16:51 UTC
    Contributor

    Qodo corrections — ef49d242

  • Scheduled runners rejected: recording and triage exclusion now use the scheduler-owned remediate_finding asset. Both scheduled leases and explicitly started native leases are supported. The unmerged remediation asset is refused even if allowlisted; no alias or second asset definition remains.

  • Wrong/stale work item and retry replay: pass the leased order's work_item_id into the existing recorder. It scopes both finding-set selection and digest replay, so an abandoned attempt cannot mutate a newer item, another same-repository finding set cannot be substituted, and identical bytes on a named retry record against that retry. Orders with no named work item retain the existing finding-based behavior.

  • Cross-repository finding: the current branch already contains the repository guard. The exact inverse-mismatch attack (metadata names leased A, finding belongs to B) was exercised on SQLite/PostgreSQL and over a real HTTP server: 403, with all SQL rows/object bytes unchanged. No guard was weakened or bypass added to appease a stale review listing.
  • All four new failing-before scenarios now pass. Existing replay, explicit-start, lease-owner, provenance, default-deny and triage/remediation separation coverage remains exercised.

    Verification: make lint-fix passed; focused SQLite/PostgreSQL service/REST suite 397 passed; make test 11,500 passed / 1 skipped; normal pre-push lint/coverage 95.34% (same 11,500 tests); OpenAPI builds with 69 paths. A throwaway real HTTP server additionally proved schedule → claim → report, identical-byte named retry/replay, stale-order refusal and cross-repository refusal without writes.

    The README documents the native asset, temporary triage config/source mapping, and named versus unbound order semantics. Current-head Qodo re-review is being requested; this is verification evidence, not a premature zero-findings claim.

    chubirka chubirka commented on Nov 06, 2026 16:51 UTC
    Contributor

    /agentic_review

    qodo-code-review[bot] qodo-code-review[bot] commented on Nov 06, 2026 16:54 UTC
    Bot
    chubirka chubirka commented on Nov 06, 2026 17:00 UTC
    Contributor

    Qodo's current-head cross-repository listing is a false positive for the scenario described, not an unimplemented fix:

  • The guard resolves the actual referenced finding IDs before record: remediation.py lines 567–578. A sole foreign repository raises ForbiddenError; mixed-repository payloads are rejected by the existing recorder before publication.

  • The inverse-mismatch regression deliberately keeps metadata and lease on A while substituting B's finding: test_remediation_records.py lines 444–455. The earlier "wrong repository" case is not the only coverage.

  • Both backend variants passed in the 397-case run. The real HTTP smoke independently submitted that exact payload, observed 403, and compared every contract-table row and object byte before/after: unchanged.
  • The scheduler-asset and named-work-item findings are fixed in ef49d242. The remaining cross-repository item should be dismissed/re-evaluated against this guard and counterexample; I am not claiming Qodo's displayed bug count is zero.

    Reviewers
    Assignees
    gurnben gurnben
    Labels
    risk: low confidence: 69.2% 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: 55.9% (MEDIUM) · Higher = larger blast radius
    55.9%
    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: 69.2% · Lower = rushed or shallow review
    69.2%
    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: 17.2% · Safe to merge
    17.2%