Skip to content

feat(rules): expired evidence streams - #627

Open
ccf-lisa[bot] wants to merge 3 commits into
effectors/26-effectors-e2efrom
effectors/27-closed-streams
Open

ccf-lisa[bot] wants to merge 3 commits into
effectors/26-effectors-e2efrom
effectors/27-closed-streams

Conversation

@ccf-lisa

@ccf-lisa ccf-lisa Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

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

@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 3c2ddd1f-ceb7-4e31-bf25-ff13ac5972f2

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@ccf-lisa
ccf-lisa Bot added this pull request to stack #604 December 2, 2026 11:08
ccf-lisa Bot added a commit that referenced this pull request Dec 2, 2026
Stack 3 as built (#619-#626) with counted lines, #613's count, and the
two decided follow-ups (#627 closed streams, #628 resumed repeats).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ccf-lisa
ccf-lisa Bot force-pushed the effectors/27-closed-streams branch from 6ed0cd1 to 02f9086 Compare December 2, 2026 12:07

@gusfcarvalho gusfcarvalho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ccf-review: REQUEST_CHANGES

1 Must-fix.

Stack (gh stack 604): #592 → #593 → #594 → #595 → #596 → #597 → #598 → #599 → #600 → #601 → #602 → #603 → #605 → #606 → #607 → #608 → #609 → #610 → #611 → #612 → #613 → #614 → #615 → #616 → #617 → #618 → #619 → #620 → #621 → #622 → #623 → #624 → #625 → #626 → #627 → #628 → #629 → #630

Comment thread internal/service/rules/subject.go Resolved
ccf-lisa Bot and others added 3 commits December 2, 2026 11:04
A stream whose latest evidence expired is closed: the subject document's
status is "closed" and the new reported_status keeps the evidence's own
state. Evaluations ask for a rules.evaluate-expiry job at the latest
expiry (one per subject, through the outbox), which evaluates the stream
once it expires so effects clear on time. New evidence reopens it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The subject document's JSON keys are kebab-case (triggers.md, wire-interface.md);
only CEL uses snake_case. ReportedStatus is now tagged json:"reported-status"
(CEL keeps reported_status), the type comment says so again, and the subject
document test asserts the JSON key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
"expired" says what happened and reads better in the UI. StatusClosed is
now StatusExpired = "expired"; the rules code, tests, expiry job docs and
CEL examples follow (subject.status == "expired" &&
subject.reported_status == "not-satisfied"), and triggers.md notes the
field is reported-status in JSON.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@gusfcarvalho gusfcarvalho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ccf-review: APPROVE

no findings.

Stack (gh stack 604): #592 → #593 → #594 → #595 → #596 → #597 → #598 → #599 → #600 → #601 → #602 → #603 → #605 → #606 → #607 → #608 → #609 → #610 → #611 → #612 → #613 → #614 → #615 → #616 → #617 → #618 → #619 → #620 → #621 → #622 → #623 → #624 → #625 → #626 → #627 → #628 → #629 → #630

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant