← Back to Pull requests

feat(rules): expired evidence streams #627

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Dec 02, 2026 11:04 UTC
Author

What

Evidence streams expire when their latest evidence expires (decision on PoC follow-up 9, "silent streams"). The status value is expired (it was closed in the first version of this PR; renamed on review: expired reads better in the UI).

  • Subject document. Built as of the evaluation time. When the latest evidence has expires and now >= expires, status is "expired". The new field (CEL reported_status, JSON reported-status, like every other subject field: snake_case in CEL, kebab-case in JSON) always holds the evidence's own state. Before expiry, or without expires, status is the evidence state as before. expires is unchanged.

  • Timing. Whenever the engine evaluates a subject (change evaluation, backfill, now sweep) and its latest evidence's expires is still ahead, it asks for a rules.evaluate-expiry job at expires. The request goes through the outbox like the other engine jobs (new outbox kind subject.expiry, payload {source, at}), written in the evaluation's transaction and enqueued after commit or by the dispatcher.

  • One job per subject. EvaluateExpiryArgs is unique on (source, subject_id) (River river:"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 default expires (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 expires it 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.Flush now marks processed only the rows it enqueued, and the dispatcher folds a batch's expiry rows to one per subject (earliest).
  • Effects. At expiry the evaluation sees expired: rules on status == "not-satisfied" stop matching, so the subject leaves its effects (cleared or updated as usual), and rules on status == "expired" match. New evidence gives the stream back its own status.

  • Editor. GET /api/rules/sources describes reported_status and the expired value. Preview builds documents as of its now, 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

  • Evidence that is already expired when it arrives expires the stream at once and schedules nothing.

  • A stream whose evidence has no expires never expires and keeps its last status. Through ingest that only happens for evidence stored before defaults existed: ingest sets end + 1 month by default, so with this PR a stream that stops reporting expires a month after its last evidence.

  • Nothing is stored for "expired": it's computed per evaluation. A stream is only evaluated (and its expiry job only asked for) while its source has enabled rules; a rule created later backfills every stream and asks for their expiry jobs then.

  • The effector tests that ingest through the evidence service now configure EvidenceDefaultExpiryMonths: 1; with the zero config their evidence expired at its own end at once.
  • Tests

  • Unit: subject builder before/at/after expiry, reported_status, no expires, CEL sees both fields and the JSON key is reported-status; subject.expiry outbox rows become scheduled jobs; duplicate handling (scheduled later → bring forward, running → later, otherwise nothing).

  • Integration (effects): a failing stream with expires 30 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 on status == "expired" && reported_status == "not-satisfied" (match document shows expired); 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, no expires, no evidence. Flush leaves only an expiry it must retry later.

  • Integration (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 test pass; make swag no diff; go mod tidy no diff; go test -tags integration -p 1 on internal/service/{effects,rules,worker,outbox} and internal/api/handler pass.

    Size

    Counted: 776 lines (added + removed, tests included; docs/docs.go and docs/swagger.* excluded).

    🤖 Generated with Claude Code

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: gusfcarvalho Review duration: 4290m
    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
    0.57
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 57% (MEDIUM) · Higher = larger blast radius
    57%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 30.4% · Safe to merge
    30.4%