fix(7733): a rule with triggers holds or refuses only the acts they match
CI & Build / TypeScript typecheck (push) Successful in 35s
CI & Build / Plugin hooks (push) Failing after 19s
CI & Build / Python lint (push) Successful in 2s
CI & Build / Python tests (push) Successful in 2m31s
CI & Build / integration (push) Successful in 2m18s
CI & Build / Build & push image (push) Canceled after 27s

Rules 2, 4, 10 and 153 are set to hold and mounted on work.deliver. A
push to dev therefore stopped four times in a row, once for each of them,
although none of them governs a push to dev: their triggers (git push
origin main, git tag, pytest, pull_request_write) name the acts they do
govern.

A rule that has triggers now stops an act only when one of them matched it.
Reached by its moment alone, it is a line beside the work. A rule with no
triggers still holds wherever it is mounted, because the mount is all that
says where it applies. A mounted rule whose unscoped trigger also matched
now counts as reached by the trigger, so it ranks as triggered and may
stop the act.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-23 15:53:36 -05:00
co-authored by Claude Opus 5.5
parent e0621713d4
commit 738bd24d6e
4 changed files with 48 additions and 4 deletions
+13 -3
View File
@@ -1748,10 +1748,13 @@ async def run_moment_arm(
by_moment = {hit["moment"]: hit for hit in reached}
# (rule, at, where, specificity) for every candidate line.
cands = []
# A mounted rule whose unscoped trigger also matched this act was
# reached by its trigger: it ranks, and may stop the act, as one.
fired_ids = {rule.id for rule, _trig in fired}
for rule, at in pairs or []:
if board is not None and (rule.id, at) in board.gated:
continue
met = board is not None and (rule.id, at) in board.matched
met = board is not None and ((rule.id, at) in board.matched or rule.id in fired_ids)
cands.append((rule, at, f"at {at}, reached by {_reached_by(by_moment.get(at, {}))}",
rule_order.BY_TRIGGER if met else rule_order.BY_MOUNT))
taken = {c[0].id for c in cands}
@@ -1762,9 +1765,16 @@ async def run_moment_arm(
cands.append((rule, trig.key, f"its trigger {trig.describe()} matched this act",
rule_order.BY_TRIGGER))
# Read before retirement: a rule that enforces does so on every act it
# reaches, however often this session has been shown it.
# reaches, however often this session has been shown it. A rule with
# triggers of its own stops only an act one of them matched: its
# triggers name the acts it governs, and its moment is broader (a
# rule about pushing to `main` mounted on work.deliver would hold
# every push to `dev`). Reached by the mount alone, it is a line.
triggered = board.triggered if board is not None else set()
decision = act_decision(
[(rule, at, where) for rule, at, where, _s in cands], held=moment.held,
[(rule, at, where) for rule, at, where, spec in cands
if spec == rule_order.BY_TRIGGER or rule.id not in triggered],
held=moment.held,
)
gone = await _retired(io, moment, [rule for rule, _a, _w, _s in cands])
if gone:
+6
View File
@@ -247,11 +247,15 @@ class Board:
condition this act did not meet: not delivered. `matched` — conditional
mounts this act met: delivered as triggered. `fired` — rules an unscoped
trigger delivers on this act, each with the trigger that fired.
`triggered` — every in-scope rule that has a trigger at all, whether or
not this act met it: such a rule names the acts it governs, so a mount
alone shows it beside the work and only its trigger can stop an act.
"""
gated: set[tuple[int, str]] = field(default_factory=set)
matched: set[tuple[int, str]] = field(default_factory=set)
fired: list[tuple[object, Trigger]] = field(default_factory=list)
triggered: set[int] = field(default_factory=set)
async def board(
@@ -261,6 +265,8 @@ async def board(
"""Check every in-scope trigger against this act (or this text)."""
out = Board()
for rule, triggers in await _in_scope(user_id, project_id):
if triggers:
out.triggered.add(rule.id)
first_unscoped = None
for trig in triggers:
hit = matches(trig, tool, tool_input, text)