Repository navigation
feat(effects): state machine - #610
Open
ccf-lisa[bot] wants to merge 2 commits into
Open
ccf-lisa[bot] wants to merge 2 commits into
ccf-lisa[bot] wants to merge 2 commits into
Conversation
|
Important Review skippedBot user detected. To trigger a single review, invoke the
|
ccf-lisa
Bot
force-pushed
the
effectors/15b-effect-machine
branch
from
December 1, 2026 18:49
cf1afcc to
34e5bc5
Compare
ccf-lisa
Bot
force-pushed
the
effectors/15b-effect-machine
branch
from
December 2, 2026 12:07
34e5bc5 to
6ca641c
Compare
This was referenced Dec 2, 2026
internal/service/effects: the effect state machine and the engine that drives it (triggers.md, Grouping and deduplication; LLD Effect state machine). - EvaluateSubject evaluates every enabled rule of a source against one subject in one transaction: a share lock on each rule row, then an advisory lock on the subject; the match and its document are saved with matched_since kept from the first match, now-dependent matches flagged and now-dependent non-matches watched; evaluation errors are recorded; each action's targets are reconciled with its effects. - The machine: a subject joins the effect of each target and leaves the others; it enters once for + delay has elapsed (a tick is scheduled otherwise); activated, updated, repeated, finished (the repeat that reaches max_repeats), cleared; every entry resets the repeat count. A subject leaving a finished effect while others still match delivers updated and the effect stays finished (PoC follow-up 4). Each delivered transition bumps the generation, records history, and enqueues a delivery through the outbox. - Tick re-runs the machine for one effect at its scheduled time, and does nothing for a deleted or repointed action or a disabled rule. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A trigger subject's id is the evidence stream UUID, but its url pointed at
/evidence/{id}, the UI page that loads GET /api/evidence/:id by record id,
so every "View evidence" link (e.g. {{.Subject.URL}} in Slack) showed
"Error loading evidence". Link /evidence/history/{id}, the UI's stream route.
ccf-lisa
Bot
force-pushed
the
effectors/15b-effect-machine
branch
from
December 2, 2026 14:45
6ca641c to
3fb423d
Compare
This was referenced Dec 2, 2026
gusfcarvalho
approved these changes
Dec 2, 2026
gusfcarvalho
left a comment
Contributor
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
This was referenced Dec 2, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The effect state machine and the engine that drives it (triggers, grouping and deduplication; API LLD, effect state machine).
Engine.EvaluateSubject(source, subject)(therules.evaluate-subjectjob), one transaction: a share lock on each enabled rule of the source (so a disable or delete serializes with it), then an advisory lock on the subject; the subject document is built once; per rule:when(errors count as no match and are recorded), the match saved withmatched_sincekept from the first match and its document,now-dependent matches flagged andnow-dependent non-matches watched (for the sweep, next PR); per action: targets (errors and rejected identities recorded), then the machine.Machine:matched_since + for + delayhas passed; otherwise a tick is scheduled and the effect ispending;activated(from inactive/pending, or a subject entering a finished effect),updated(subjects entered or left),repeatedeveryrepeat,finished(the repeat that reachesmax_repeats, with that repeat count),cleared(no subject left). Every entry resets the repeat count.finishedeffect while others still match deliversupdatedand the effect stays finished (no repeats).Engine.Tick(effect)re-runs the machine at its scheduled time and does nothing for a deleted or repointed action or a disabled rule.Not here: backfill and the now sweep (16), rule and action changes (16b). A raised
max_repeatsdoes not resume a finished effect (open question in the plan).Why
Plan: stack 2, PR 15.
Size exception: one package: the machine and the engine that drives it, with their tests. The machine is only driven through
EvaluateSubjectandTick, and the tests that pin each transition go through them; splitting the machine from the engine would mean testing it twice. The plan marks this PR SE.Test evidence
engine_integration_test.go(Postgres): a full lifecycle (pending insidefor, activated, repeated, a second subject joining and resetting repeats, finished atmax_repeats, no repeats after, finished + left → updated and still finished, cleared; history and delivered generations), a finished effect acting again when a subject enters, flapping insidefornever delivers, a target change moves the subject, per-action delay, errors recorded (missing key, rejected identity, failingwhen), disabled rules aren't evaluated, jobs written to the outbox (and left there when enqueuing fails), ticks for deleted/repointed actions and disabled rules, a gone subject leaves, now-dependent subjects recorded.Gate on this branch:
go build ./...pass;go vet -tags integration ./...pass;make lint(golangci-lint v2.15.0, CI config) 0 new issues;make testpass;make swagno diff;go mod tidyno diff;go test -tags integration -p 1on./internal/service/effects/pass.Size
Counted: 1120 lines (size exception, above).
🤖 Generated with Claude Code