fix: bound evidence batches by size and release flushed evidence #34
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 396 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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.358
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #34"
general
weight: 0.35
gusfcarvalho
Fixes #33.
Problem
Every evidence carries a JSON copy of the Rego input it was evaluated against (
PolicyEvaluation.Input), and that input includes every collected resource in the fleet.Evalheld up to 100 evidences before sending them, so a batch could hold 100 × (full fleet JSON). After a flush,clusterEvidences[:0]also kept the sent evidence reachable through the slice's backing array.Changes
PolicyEvaluation, so it's counted once.CCF_K8S_EVIDENCE_BATCH_MAX_BYTES: overrides the 64 MiB default. It's read inConfigureand logged at startup. Invalid or non-positive values log a warning and fall back to the default. The agent passes its environment through to plugins, so it's set on the agent.clear(clusterEvidences)before reslicing.oom_repro_test.go, build tagoomrepro, excluded from the normal test run): runs the realEvalloop and agent policy evaluator against a synthetic fleet and writes a heap profile at each flush. Usage is in the file header.Verification
Unit tests cover byte-limit flushing, shared evaluations counted once, the count limit still applying, flushed evidence no longer being reachable, and env var parsing. With the
clear()removed, the reachability test fails with 95 stale evidences, matching what pprof showed.The repro harness, run with
plugin-k8s-opres-policiesv0.2.0 and the reported config (2 clusters; 750 pods, 30 nodes and 110 deployments per cluster):| | Before | After |
|---|---|---|
| Peak RSS | 4.66 GB | 1.51 GB |
| Heap obtained from OS | 5.9 GiB | 1.37 GiB |
| Live heap after GC at flushes | 1,949–2,555 MiB | 194–536 MiB |
| Input JSON held per batch | 1,790 MiB (100 evidences) | 71.6 MiB (4 evidences) |
| Run time | 4m05s | 3m55s |
Not addressed
Peak memory now grows with the size of one input rather than 100. Each evaluation still allocates about 800 MB of short-lived memory converting the input for OPA, and each evidence's full input is still uploaded by the agent. Reducing the input itself is tracked in #33.
🤖 Generated with Claude Code
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->
Summary by CodeRabbit
New Features
Evidence batches now flush when they reach either 100 items or the configured data-size limit, whichever comes first. This can help prevent large batches from using excessive memory.
The batch-size limit can be set with
CCF_K8S_EVIDENCE_BATCH_MAX_BYTES. It defaults to 64 MiB; invalid or non-positive values use the default, with a warning for invalid entries.Documentation
* Clarified that each evidence item includes a copy of its policy input, which contains collected fleet resources.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->