From 17fcbfaedf2ef06665bbb20325c848c824500892 Mon Sep 17 00:00:00 2001 From: Miguel Martinez Trivino Date: Sat, 5 Dec 2026 23:27:31 +0100 Subject: [PATCH] feat(ai-security-context): add optional attempts to unresolved commits Unresolved holes can now record how many times triage tried and failed to classify the commit. The field is optional, so the schema stays at security-context-0.1 and existing contexts remain valid. Refs: https://linear.app/chainloop/issue/PFM-8486 Assisted-by: Claude Code Signed-off-by: Miguel Martinez Trivino Chainloop-Trace-Sessions: 46352acc-1770-40e5-a6f4-5c4966e2ddb9 --- .../ai-security-context-0.1.schema.json | 5 +++ .../schemavalidators/schemavalidators_test.go | 32 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/internal/schemavalidators/internal_schemas/aisecuritycontext/ai-security-context-0.1.schema.json b/internal/schemavalidators/internal_schemas/aisecuritycontext/ai-security-context-0.1.schema.json index 6f378114d..311decfd1 100644 --- a/internal/schemavalidators/internal_schemas/aisecuritycontext/ai-security-context-0.1.schema.json +++ b/internal/schemavalidators/internal_schemas/aisecuritycontext/ai-security-context-0.1.schema.json @@ -515,6 +515,11 @@ "retryable": { "type": "boolean", "description": "Whether a later run should re-examine this commit: a transient diff-load, triage, or backend/adjudication failure. Absent (false) for a deterministic hole (oversize diff) or a context written before this field existed." + }, + "attempts": { + "type": "integer", + "minimum": 0, + "description": "How many times triage tried and failed to classify this commit: the agentic large-diff triage for an oversize commit, or the one-shot triage for any other. At the cap the hole stops retrying and retryable becomes false. Absent (0) for a deterministic skip and on contexts written before this field existed." } } }, diff --git a/internal/schemavalidators/schemavalidators_test.go b/internal/schemavalidators/schemavalidators_test.go index d5cd22b0f..bebe7f4b6 100644 --- a/internal/schemavalidators/schemavalidators_test.go +++ b/internal/schemavalidators/schemavalidators_test.go @@ -668,6 +668,38 @@ func TestValidateSecurityContextTriageFields(t *testing.T) { require.NoError(t, schemavalidators.ValidateSecurityContext(payload, "")) }) + t.Run("an unresolved entry carrying a triage attempts count", func(t *testing.T) { + testCases := []struct { + name string + attempts any + wantErr string + }{ + {name: "zero attempts validates", attempts: 0}, + {name: "positive attempts validates", attempts: 2}, + {name: "negative attempts is rejected", attempts: -1, wantErr: "minimum"}, + {name: "fractional attempts is rejected", attempts: 1.5, wantErr: "integer"}, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + payload, scan := load(t) + scan["unresolved"] = []any{map[string]any{ + "sha": "8c948c742bdfc09c4aae6b3c386faeb98f925ff2", + "reason": "triage: provider error", + "retryable": true, + "attempts": tc.attempts, + }} + + err := schemavalidators.ValidateSecurityContext(payload, "") + if tc.wantErr != "" { + require.ErrorContains(t, err, tc.wantErr) + return + } + require.NoError(t, err) + }) + } + }) + t.Run("an unknown unresolved field is still rejected", func(t *testing.T) { payload, scan := load(t) scan["unresolved"] = []any{map[string]any{