Repository navigation
fix(policies): return no references when discover finds no node - #3851
Conversation
The chainloop.discover builtin failed when no node of the graph had the requested digest yet, for example a material that no workflow run has attested. The control plane answers that case with a gRPC NotFound, the builtin returned it as an error, and because policies are evaluated with strict builtin errors the whole policy evaluation failed. Adding the material with chainloop att add failed, even with gate: false, instead of the policy reporting that the material has no upstream run. DiscoverService.Discover now turns a NotFound on the first page into a result with no references and truncated false. This covers both the Rego and the WASM builtins. A nil result still means no connection to the control plane. Every other error, and a NotFound on a later page, still fails as before. Fixes PFM-8307 Assisted-by: Claude Code Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev> Chainloop-Trace-Sessions: 0e3b127c-259e-426a-bf46-54e6f073f9c3
PR validation — ✅ 3 passing
AI Session Checks — 🟡 80% · ✅ 0 failing
|
| Status | Attribution | File | Lines |
|---|---|---|---|
| modified | ai | pkg/policies/engine/builtins/discover_test.go |
+142 / -13 |
| modified | ai | pkg/policies/engine/builtins/discover.go |
+31 / -0 |
Policies (4)
| Status | Policy | Material | Messages |
|---|---|---|---|
| ✅ Passed | ai-config-ai-agents-allowed |
ai-coding-session-0e3b12 |
- |
| ✅ Passed | ai-config-no-dangerous-commands |
ai-coding-session-0e3b12 |
- |
| ✅ Passed | ai-config-no-secrets |
ai-coding-session-0e3b12 |
- |
| ✅ Passed | ai-config-mcp-servers-allowed |
ai-coding-session-0e3b12 |
- |
Security Checks — ✅ 6 passing
✅ AI Security Analysis
Nothing this change touches re-opens a recorded security fix.
View in Chainloop ↗ · How this works ↗
✅ secret-scan
| Status | Policy | Messages |
|---|---|---|
| ✅ Passed | secrets-detection |
- |
✅ sast-scan
| Status | Policy | Messages |
|---|---|---|
| ✅ Passed | owasp-top10-2025 |
- |
| ✅ Passed | sast |
- |
| ✅ Passed | cwe-top25 |
- |
| ✅ Passed | cwe-top26-40-cusp |
- |
Scans not applied (3)
| Scan | Reason |
|---|---|
vulnerability-scan |
no manifest/lockfile changed |
github-actions-scan |
no workflow files changed |
iac-scan |
no IaC files changed |
Powered by Chainloop and Chainloop Trace
There was a problem hiding this comment.
All reported issues were addressed across 2 files
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
The discover result embeds the proto ReferrerItem, whose references field is omitted from JSON when empty. A policy that checks count(discovered.references) == 0 then got an undefined value and the rule never fired, both for a digest with no node and for a node with no references. DiscoverResult now marshals references as an array, an empty one when there are none. The WASM builtin returns this JSON and Rego converts the result through it, so both see "references": []. A result of null still means no connection to the control plane. Assisted-by: Claude Code Signed-off-by: Miguel Martinez Trivino <miguel@chainloop.dev> Chainloop-Trace-Sessions: 0e3b127c-259e-426a-bf46-54e6f073f9c3
Fixes PFM-8307
The
chainloop.discoverpolicy builtin now returns an empty result when no node of the graph has the requested digest yet. Before, it failed the whole policy evaluation.For example, a material that no upstream workflow run has attested has no node. The control plane answers that case with a gRPC
NotFound. Before this change, the builtin returned that as an error. Policies are evaluated with strict builtin errors, so the evaluation failed andchainloop att adddid not add the material, even withgate: false. Policies such asupstream-checkcould not report their "No run" violation.Now a
NotFoundon the first discover request gives a result with"references": []andtruncated: false. The result always hasreferencesas an array, also for a node that has no references, so a check such ascount(discovered.references) == 0is true and not undefined. This applies to Rego and WASM policies, because both use the same discover service. The other cases do not change:nullresult still means that there is no connection to the control plane.Unavailable,PermissionDenied,UnauthenticatedorInternal) still fails the evaluation.NotFoundon a later pagination page still fails, because the node existed for the first page.This is related to PFM-8294 and #3843, a separate fix for the same
upstream-checkpolicy. After this change, the comment abovediscoveredinpolicies/upstream-check/upstream-check.regoin chainloop-dev/compliance-manifests becomes outdated. That comment says the whole evaluation fails when no node has the digest.This PR was written with the help of Claude Code.
🤖 Posted by Maximus bot (Claude Code) on behalf of @migmartri