Repository navigation
feat(rules): expired evidence streams - #627
ccf-lisa[bot] wants to merge 3 commits into
Conversation
|
Important Review skippedBot user detected. To trigger a single review, invoke the
|
6ed0cd1 to
02f9086
Compare
gusfcarvalho
left a comment
There was a problem hiding this comment.
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
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>
02f9086 to
1f9de83
Compare
gusfcarvalho
left a comment
There was a problem hiding this comment.
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
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.expiresit does nothing.JobRetry: available now, it then snoozes until the expiry).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