feat(rules): expired evidence streams #627
All Vouch review confidence checks passed
Residual risk 0.30 = Change Risk (0.57) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.57 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 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.388
Shallow Review Depth
shallow_review_depth
0.344
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #627"
general
weight: 0.35
gusfcarvalho
What
Evidence streams expire when their latest evidence expires (decision on PoC follow-up 9, "silent streams"). The status value is
expired(it wasclosedin the first version of this PR; renamed on review:expiredreads better in the UI).expiresandnow >= expires,statusis"expired". The new field (CELreported_status, JSONreported-status, like every other subject field: snake_case in CEL, kebab-case in JSON) always holds the evidence's own state. Before expiry, or withoutexpires,statusis the evidence state as before.expiresis unchanged.expiresis still ahead, it asks for arules.evaluate-expiryjob atexpires. The request goes through the outbox like the other engine jobs (new outbox kindsubject.expiry, payload{source, at}), written in the evaluation's transaction and enqueued after commit or by the dispatcher.EvaluateExpiryArgsis unique on(source, subject_id)(Riverriver:"unique"tags) while the job waits or runs, so a stream evaluated on every collection has one job, not one per expiry. Ingest gives every evidence a defaultexpires(end+CCF_EVIDENCE_DEFAULT_EXPIRY_MONTHS), so one-job-per-expiry would have piled up roughly expiry/collection-interval jobs per stream.- The job runs at the earliest expiry asked for. If the latest evidence expires later by then (rolling expiries), it snoozes until that expiry instead of evaluating; if it has expired, it evaluates the subject (expired); without evidence or
expiresit does nothing.- An expiry earlier than the job's scheduled time brings the job forward (
JobRetry: available now, it then snoozes until the expiry).- An expiry asked for while the subject's job is running keeps its outbox row for the next dispatch (the running job may have read the subject before the change), like change evaluations already do.
Outcome.Flushnow marks processed only the rows it enqueued, and the dispatcher folds a batch's expiry rows to one per subject (earliest).expired: rules onstatus == "not-satisfied"stop matching, so the subject leaves its effects (cleared or updated as usual), and rules onstatus == "expired"match. New evidence gives the stream back its own status.GET /api/rules/sourcesdescribesreported_statusand theexpiredvalue. Preview builds documents as of itsnow, so it shows expired streams too.Docs:
triggers.md(subject schema, timers),events-and-states.md(expired streams, default expiry),lld/poc-followups.md(item 9 decided).Edge cases
expiresnever expires and keeps its last status. Through ingest that only happens for evidence stored before defaults existed: ingest setsend + 1 monthby default, so with this PR a stream that stops reporting expires a month after its last evidence.EvidenceDefaultExpiryMonths: 1; with the zero config their evidence expired at its ownendat once.Tests
reported_status, noexpires, CEL sees both fields and the JSON key isreported-status;subject.expiryoutbox rows become scheduled jobs; duplicate handling (scheduled later → bring forward, running → later, otherwise nothing).effects): a failing stream withexpires30 minutes out; the effect is active; the expiry job run early waits 20 minutes; at the expiry it clears the failing effect and activates a rule onstatus == "expired" && reported_status == "not-satisfied"(match document showsexpired); new evidence clears the expired effect, makes the failing rule pending again and asks for the new expiry, and the old job then waits for it. Already-expired evidence, noexpires, no evidence.Flushleaves only an expiry it must retry later.worker): dispatch makes one expiry job per subject at the earliest expiry, folds later ones, brings it forward for an earlier one, and keeps the row while the job runs.Part of the effectors plan:
docs/effectors/lld/implementation-plan.md.Gate
On this branch:
go build ./...pass;go vet -tags integration ./...pass; golangci-lint v2.15.0 (shared CI config) 0 new issues;make testpass;make swagno diff;go mod tidyno diff;go test -tags integration -p 1oninternal/service/{effects,rules,worker,outbox}andinternal/api/handlerpass.Size
Counted: 776 lines (added + removed, tests included;
docs/docs.goanddocs/swagger.*excluded).🤖 Generated with Claude Code