feat(automation): card_due_reached trigger + in-process scheduler#69
Merged
Conversation
Completes the v1 automation engine (ADR 0010) — the last deferred trigger. No new process / systemd unit: the scheduler is an in-process per-minute setInterval started from instrumentation.ts, mirroring the webhook worker. - Scheduler (`due-scheduler.ts`): scans cards whose `dueAt` passed in a 7-day look-back on boards that have an active card_due_reached rule, claims each card once via Redis `SET NX` (30d TTL), publishes a content-free `AUTOMATION_DUE_FIRED` board tick. Server only reads the already-plaintext `dueAt`; never decrypts enc_rule. - Client: on the tick, board-client builds the card_due_reached event from its current card state and runs the normal evaluator/executor. Every online client races; idempotent actions converge and post_comment is SETNX-deduped, so duplicates don't happen. - DSL: card_due_reached added to TRIGGER_TYPES. - Evaluator: TriggerEvent variant + columnId/milestoneId accessors + eventToken. - Rule builder: trigger label + column-scope condition. - Ops: `AUTOMATION_DUE_WORKER_DISABLED=1` to drive externally; both background workers now documented in .env.example. Tests: evaluator card_due_reached (column + milestone scoping, unconditioned) + eventToken; DSL trigger count → 5. 43 automation cases green. CLAUDE.md + CHANGELOG updated. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Signed-off-by: Moritz Kohm <moritz.kohm@gmail.com> Signed-off-by: Musiker15 <info@musiker15.de>
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.
Summary
Completes the v1 automation engine (ADR 0010) —
card_due_reached, the last deferred trigger. The fourth and final automation item from the v0.2.0-beta Deferred list.No new process or systemd unit. Despite ADR 0010 saying "BullMQ", the project's actual worker pattern is an in-process
setInterval(see the webhook worker). I followed that: the scheduler starts frominstrumentation.tsand runs inside the Next.js server process — single-container deployment story preserved.How it works
Every online client races on the tick; idempotent actions converge and
post_commentis SETNX-deduped, so no duplicates.Changes
src/lib/automation/due-scheduler.ts(new):runDueScan()(exported, also drivable by external cron) +startDueScheduler()/stopDueScheduler().instrumentation.ts: starts the scheduler alongside the webhook worker.card_due_reachedadded toTRIGGER_TYPES.TriggerEventvariant (columnId+milestoneId),FIELD_ACCESSORSfor both,eventToken.AUTOMATION_DUE_FIREDtick.AUTOMATION_DUE_WORKER_DISABLED=1; both workers documented in.env.example.Zero-knowledge / safety notes
Card.dueAt(already plaintext + indexed) and the rule's plaintexttrigger_type. It never decryptsenc_rule.Tests
automation-evaluator.test.ts—card_due_reachedcolumn + milestone scoping, unconditioned match,eventToken.automation-dsl.test.ts— trigger count → 5. 43 automation cases green. Full suite 168 green locally (pnpm typecheck+pnpm lintclean).Test plan
Overdue!"; set a card's due date to ~1 min in the future; wait; confirm the comment appears once🤖 Generated with Claude Code