Repository navigation
Conversation
The vulnerability details response listed advisories in whatever order the database returned them, so advisories sharing a document ID (for example a CSAF VEX and a CVE record) could swap between requests. Order them by document ID, then advisory type, then advisory UUID - the same tie-break consumers such as trustify-ui apply client-side. VulnerabilityContext::advisories gets the equivalent SQL ordering so the ingestor path is stable too. Implements TC-7641 Assisted-by: Claude Code
Reviewer's GuideImplementationSort vulnerability advisory summaries by document ID, advisory type, and UUID, and apply the same ordering in the ingestor query.
TestsTest that endpoint and service responses keep the expected advisory order across forward and reverse ingestion orders.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="modules/ingestor/src/graph/vulnerability/mod.rs" line_range="264" />
<code_context>
advisory_vulnerability::Column::VulnerabilityId.eq(self.vulnerability.id.clone()),
)
+ .order_by_asc(advisory::Column::DocumentId)
+ .order_by_asc(Expr::cust(r#""advisory"."labels" ->> 'type'"#))
+ .order_by_asc(advisory::Column::Id)
.all(connection)
</code_context>
<issue_to_address>
**Advisories appear in different orders**
When advisories sharing a document ID include one without a `type` label and another with a nonempty type, the SQL ordering treats the missing type as `NULL`, which PostgreSQL places after non-NULL values in ascending order, while `advisory_type` maps it to `""` and sorts it before nonempty types. The ingestor and endpoint therefore return different advisory sequences.
Use `COALESCE` in the SQL ordering expression so a missing type sorts like `""` and the UUID tie-break applies consistently.
Also at `modules/fundamental/src/vulnerability/model/details/vulnerability_advisory.rs:526`, `modules/fundamental/src/vulnerability/model/details/vulnerability_advisory.rs:535`, `modules/fundamental/src/vulnerability/model/details/vulnerability_advisory.rs:539-540`.
</issue_to_address>
### Comment 2
<location path="modules/ingestor/src/graph/vulnerability/mod.rs" line_range="263-264" />
<code_context>
.filter(
advisory_vulnerability::Column::VulnerabilityId.eq(self.vulnerability.id.clone()),
)
+ .order_by_asc(advisory::Column::DocumentId)
+ .order_by_asc(Expr::cust(r#""advisory"."labels" ->> 'type'"#))
+ .order_by_asc(advisory::Column::Id)
.all(connection)
</code_context>
<issue_to_address>
**Locale changes advisory order**
When the database has a locale-sensitive default collation and linked advisories have text keys ordered differently by that collation than by Rust string comparison, postgreSQL orders these text keys using the database collation, while the endpoint uses Rust string ordering. The ingestor result can therefore disagree with the endpoint for document IDs or type labels whose locale order differs from byte order.
Apply `COLLATE "C"` to the SQL text sort keys so their order matches the endpoint.
Also at `modules/fundamental/src/vulnerability/model/details/vulnerability_advisory.rs:521-527`.
</issue_to_address>
### Comment 3
<location path="modules/fundamental/src/vulnerability/service/test.rs" line_range="1391-1398" />
<code_context>
+ .iter()
+ .map(|advisory| {
+ (
+ advisory.head.head.document_id.clone(),
+ advisory
+ .head
+ .head
+ .labels
+ .get("type")
+ .cloned()
+ .unwrap_or_default(),
+ )
+ })
</code_context>
<issue_to_address>
**UUID ordering regressions go undetected**
When the UUID tie-break is removed or implemented incorrectly, the ordering tests compare only document ID and type, so both tests still pass when advisories with matching keys are returned in the wrong UUID order.
Include UUIDs in both test projections and assert their ordering.
Also at `modules/fundamental/src/vulnerability/endpoints/test.rs:718-728`.
</issue_to_address>Sourcery assessment
Approval pending. 3 findings to address first.
Blocking findings: modules/ingestor/src/graph/vulnerability/mod.rs:264, modules/ingestor/src/graph/vulnerability/mod.rs:264, modules/fundamental/src/vulnerability/service/test.rs:1398
| advisory_vulnerability::Column::VulnerabilityId.eq(self.vulnerability.id.clone()), | ||
| ) | ||
| .order_by_asc(advisory::Column::DocumentId) | ||
| .order_by_asc(Expr::cust(r#""advisory"."labels" ->> 'type'"#)) |
There was a problem hiding this comment.
🟡 Medium · Advisories appear in different orders
When advisories sharing a document ID include one without a type label and another with a nonempty type, the SQL ordering treats the missing type as NULL, which PostgreSQL places after non-NULL values in ascending order, while advisory_type maps it to "" and sorts it before nonempty types. The ingestor and endpoint therefore return different advisory sequences.
Use COALESCE in the SQL ordering expression so a missing type sorts like "" and the UUID tie-break applies consistently.
Also at modules/fundamental/src/vulnerability/model/details/vulnerability_advisory.rs:526, modules/fundamental/src/vulnerability/model/details/vulnerability_advisory.rs:535, modules/fundamental/src/vulnerability/model/details/vulnerability_advisory.rs:539-540.
Prompt for AI agents
In `modules/ingestor/src/graph/vulnerability/mod.rs` at line 264:
**Advisories appear in different orders**
When advisories sharing a document ID include one without a `type` label and another with a nonempty type, the SQL ordering treats the missing type as `NULL`, which PostgreSQL places after non-NULL values in ascending order, while `advisory_type` maps it to `""` and sorts it before nonempty types. The ingestor and endpoint therefore return different advisory sequences.
Use `COALESCE` in the SQL ordering expression so a missing type sorts like `""` and the UUID tie-break applies consistently.
Also at `modules/fundamental/src/vulnerability/model/details/vulnerability_advisory.rs:526`, `modules/fundamental/src/vulnerability/model/details/vulnerability_advisory.rs:535`, `modules/fundamental/src/vulnerability/model/details/vulnerability_advisory.rs:539-540`.| .order_by_asc(advisory::Column::DocumentId) | ||
| .order_by_asc(Expr::cust(r#""advisory"."labels" ->> 'type'"#)) |
There was a problem hiding this comment.
🟡 Medium · Locale changes advisory order
When the database has a locale-sensitive default collation and linked advisories have text keys ordered differently by that collation than by Rust string comparison, postgreSQL orders these text keys using the database collation, while the endpoint uses Rust string ordering. The ingestor result can therefore disagree with the endpoint for document IDs or type labels whose locale order differs from byte order.
Apply COLLATE "C" to the SQL text sort keys so their order matches the endpoint.
Also at modules/fundamental/src/vulnerability/model/details/vulnerability_advisory.rs:521-527.
Prompt for AI agents
In `modules/ingestor/src/graph/vulnerability/mod.rs` at lines 263-264:
**Locale changes advisory order**
When the database has a locale-sensitive default collation and linked advisories have text keys ordered differently by that collation than by Rust string comparison, postgreSQL orders these text keys using the database collation, while the endpoint uses Rust string ordering. The ingestor result can therefore disagree with the endpoint for document IDs or type labels whose locale order differs from byte order.
Apply `COLLATE "C"` to the SQL text sort keys so their order matches the endpoint.
Also at `modules/fundamental/src/vulnerability/model/details/vulnerability_advisory.rs:521-527`.| advisory.head.head.document_id.clone(), | ||
| advisory | ||
| .head | ||
| .head | ||
| .labels | ||
| .get("type") | ||
| .cloned() | ||
| .unwrap_or_default(), |
There was a problem hiding this comment.
🟡 Medium · UUID ordering regressions go undetected
When the UUID tie-break is removed or implemented incorrectly, the ordering tests compare only document ID and type, so both tests still pass when advisories with matching keys are returned in the wrong UUID order.
Include UUIDs in both test projections and assert their ordering.
Also at modules/fundamental/src/vulnerability/endpoints/test.rs:718-728.
Prompt for AI agents
In `modules/fundamental/src/vulnerability/service/test.rs` at lines 1391-1398:
**UUID ordering regressions go undetected**
When the UUID tie-break is removed or implemented incorrectly, the ordering tests compare only document ID and type, so both tests still pass when advisories with matching keys are returned in the wrong UUID order.
Include UUIDs in both test projections and assert their ordering.
Also at `modules/fundamental/src/vulnerability/endpoints/test.rs:718-728`.
Summary
document_id, then advisory type (labels.type), then advisory UUID soGET /v3/vulnerability/{id}no longer depends on database row order.VulnerabilityContext::advisoriesin the ingestor so that path is stable too.document_id(different types) plus an unrelated advisory, asserting the exact sequence for both forward and reverse ingestion order.Notes
VulnerabilityAdvisorySummary::from_entities), which keeps the tie-break portable instead of relying on PostgreSQL JSON ordering. The ingestor query uses the same three keys as anORDER BY.Implements TC-7641
Summary by Sourcery
Make vulnerability advisory ordering deterministic across all retrieval paths.
Bug Fixes:
Enhancements:
Tests: