fix(7733): a rule's open rate counts only deliveries whose plugin reports opens
CI & Build / TypeScript typecheck (push) Canceled after 0s
CI & Build / Plugin hooks (push) Canceled after 0s
CI & Build / Python lint (push) Canceled after 0s
CI & Build / Python tests (push) Canceled after 0s
CI & Build / integration (push) Canceled after 0s
CI & Build / Build & push image (push) Canceled after 0s

Each rule line a hook delivers now records the plugin version that asked for
it (the X-Grimoire-Plugin header every hook request sends). The open rate
used to order rules, and the delivery history the weighing pass reads,
count only deliveries that carry one.

A plugin before 2026.11.22.2312 never reported an open of a rule a hook had
just named, so every delivery made to such a session read as unopened. The
server shipped delivery recording from dev on 2026-11-22. The plugin ships
from main, and a running session keeps the plugin it started with, so those
sessions kept arriving. They are why opens read about 1 in 600. Existing
rows have no version and drop out of the rate; nothing is deleted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-23 15:52:42 -05:00
co-authored by Claude Opus 5.5
parent 3a11c11543
commit e0621713d4
24 changed files with 150 additions and 17 deletions
+12
View File
@@ -28,6 +28,16 @@ class RuleDelivery(Base):
(`repeat`). Repeats are recorded too: they are deliveries a session can
open, and the case for retiring a rule rests on how rarely they are.
`plugin` is the version of the plugin that asked for the line, from the
request's `X-Grimoire-Plugin` header. Only a plugin that sends it reports
every open (`grimoire_record_opened.sh`), so a delivery without one was
made to a session whose opens never reach the server, and its unstamped
`opened_at` says nothing about whether it was read. The open-rate readers
count only deliveries that carry it. The server and the plugin ship on
different channels (the server from `dev`, the plugin from `main`, and a
running session keeps the plugin it started with), so rows from an older
plugin keep arriving for as long as such a session lives.
FK-free on `rule_id` and `user_id`, like the other telemetry tables: the
evidence that a rule was delivered forty times and opened never outlives
the rule, because it is the case for having deleted it.
@@ -46,6 +56,7 @@ class RuleDelivery(Base):
DateTime(timezone=True), nullable=False, server_default=func.now(),
)
opened_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
plugin: Mapped[str | None] = mapped_column(Text, nullable=True)
__table_args__ = (
# Stamping an open: this session's latest delivery of this rule.
@@ -66,4 +77,5 @@ class RuleDelivery(Base):
"form": self.form,
"delivered_at": iso(self.delivered_at),
"opened_at": iso(self.opened_at),
"plugin": self.plugin,
}