fix(7735): a rule the session already read counts as opened when it arrives again
CI & Build / Python lint (push) Successful in 2s
CI & Build / Plugin hooks (push) Successful in 12s
CI & Build / TypeScript typecheck (push) Successful in 32s
CI & Build / Python tests (push) Successful in 2m2s
CI & Build / integration (push) Successful in 2m10s
CI & Build / Build & push image (push) Successful in 34s

A delivery to a session that opened the rule within the open window is
stamped opened as it is written, and migration 0135 stamps the rows already
recorded the same way. The adherence readout, the ordering open rate and the
weighing pass read one definition: a rule read early in a long session is not
counted unread each time it is delivered later.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-24 07:06:18 -05:00
co-authored by Claude Opus 5.5
parent c486524b48
commit 78fa165e67
4 changed files with 102 additions and 2 deletions
@@ -0,0 +1,43 @@
"""a delivery of a rule the session had already opened counts as opened
Revision ID: 0135
Revises: 0134
Create Date: 2026-11-24
From now on a line for a rule the session has opened in the last six hours
is stamped opened as it is written (`rule_deliveries._read_already`). This
stamps the deliveries already recorded the same way, so the open rates, the
adherence readout and the weighing pass read one definition across old and
new rows: a rule read early in a session is not counted unread each time it
arrives again. The stamp is the delivery's own time. Not reversible: the
downgrade leaves the stamps, which the earlier code reads as ordinary opens.
"""
from alembic import op
revision = "0135"
down_revision = "0134"
branch_labels = None
depends_on = None
def upgrade() -> None:
op.execute(
"""
UPDATE rule_deliveries d
SET opened_at = d.delivered_at
WHERE d.opened_at IS NULL
AND EXISTS (
SELECT 1 FROM rule_deliveries e
WHERE e.user_id = d.user_id
AND e.session_id = d.session_id
AND e.rule_id = d.rule_id
AND e.opened_at IS NOT NULL
AND e.opened_at <= d.delivered_at
AND e.opened_at >= d.delivered_at - INTERVAL '6 hours'
)
"""
)
def downgrade() -> None:
pass