fix(policies): return no references when discover finds no node
Fixes PFM-8307
The chainloop.discover policy 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 and chainloop att add did not add the material, even with gate: false. Policies such as upstream-check could not report their "No run" violation.
Now a NotFound on the first discover request gives a result with "references": [] and truncated: false. The result always has references as an array, also for a node that has no references, so a check such as count(discovered.references) == 0 is true and not undefined. This applies to Rego and WASM policies, because both use the same discover service. The other cases do not change:
- A
nullresult still means that there is no connection to the control plane. - Every other discover error (for example
Unavailable,PermissionDenied,UnauthenticatedorInternal) still fails the evaluation. - A
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-check policy. After this change, the comment above discovered in policies/upstream-check/upstream-check.rego in 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