feat(8118,8119): telemetry reads take a closed window, and every enter_project records whether it carried the family line
CI & Build / TypeScript typecheck (push) Successful in 37s
CI & Build / Python lint (push) Successful in 3s
CI & Build / Plugin hooks (push) Successful in 17s
CI & Build / integration (push) Failing after 2m15s
CI & Build / Python tests (push) Successful in 2m23s
CI & Build / Build & push image (push) Skipped

#8119: retrieval_telemetry and list_rules(with_usage) take `since` and
`until` (ISO date or datetime) besides `days`. Every windowed count is
bounded at both ends: sources, note/rule/system/moment usage, record
reach, judged lines and the floor-moved check. A review read after its
period can now keep a later deploy out of its counts. A bad bound is
refused rather than widened.

#8118: enter_project writes one AppLog row (family / enter_project) per
entry: the project, whether the family line was shown, its counts, and
whether the readout failed. It is spawned, so the handshake does not wait.
retrieval_telemetry gains a `family_line` block: per project, entries,
entries that carried the line, first and last shown, and the latest
counts. Review #5132's "did the project's sessions see the line" is now
answerable from this deploy on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-27 00:01:19 -05:00
co-authored by Claude Opus 5.5
parent 0e946ffac8
commit 577a8e8621
12 changed files with 389 additions and 29 deletions
@@ -247,6 +247,75 @@ async def test_retrieval_summary_reads_what_the_writer_wrote(_dispose_engine):
await s.commit()
@pytest.mark.integration
@pytest.mark.asyncio
async def test_a_closed_window_leaves_out_what_came_after_it(_dispose_engine):
"""A review read late passes `until`, so events after the period under
review (a later deploy's traffic) are not counted. One surfacing inside
the window and one after it: only the first is counted, and the response
names the window it used."""
from datetime import datetime, timedelta, timezone
from sqlalchemy import delete
from grimoire.models import async_session
from grimoire.models.note_usage import NoteUsageEvent
from grimoire.services.retrieval_telemetry import retrieval_summary
UID = 990006
now = datetime.now(timezone.utc)
inside, after = now - timedelta(days=10), now - timedelta(days=2)
async with async_session() as s:
s.add_all([
NoteUsageEvent(user_id=UID, note_id=1, event="surfaced", source="auto_inject",
created_at=inside),
NoteUsageEvent(user_id=UID, note_id=2, event="surfaced", source="auto_inject",
created_at=after),
])
await s.commit()
try:
bounded = await retrieval_summary(UID, since=now - timedelta(days=14),
until=now - timedelta(days=5))
assert bounded["usage"]["surfaced"] == 1
assert bounded["until"] is not None and bounded["window_days"] == pytest.approx(9)
assert (await retrieval_summary(UID, days=14))["usage"]["surfaced"] == 2
finally:
async with async_session() as s:
await s.execute(delete(NoteUsageEvent).where(NoteUsageEvent.user_id == UID))
await s.commit()
@pytest.mark.integration
@pytest.mark.asyncio
async def test_family_line_counts_entries_and_the_ones_that_carried_the_line(_dispose_engine):
"""Review #5132's question: did a project's sessions see the family line?
Three entries to one project, two carrying the line; the readout counts
the entries as the denominator and keeps the latest counts shown."""
from sqlalchemy import delete
from grimoire.models import async_session
from grimoire.models.app_log import AppLog
from grimoire.services.family_adoption import record_entry
from grimoire.services.retrieval_telemetry import retrieval_summary
UID, PID = 990007, 990107
await record_entry(UID, PID, {"unassessed": 3, "owed": 1, "needs_recheck": 0})
await record_entry(UID, PID, None)
await record_entry(UID, PID, {"unassessed": 2, "owed": 1, "needs_recheck": 0})
try:
block = (await retrieval_summary(UID, days=1))["family_line"]
assert "family_line_failed" not in block
assert block["entries"] == 3 and block["entries_with_line"] == 2
(row,) = block["by_project"]
assert row["project_id"] == PID and row["readout_failed"] == 0
assert row["last_counts"] == {"unassessed": 2, "owed": 1, "needs_recheck": 0}
assert row["first_shown_at"] <= row["last_shown_at"]
finally:
async with async_session() as s:
await s.execute(delete(AppLog).where(AppLog.user_id == UID))
await s.commit()
@pytest.mark.integration
@pytest.mark.asyncio
async def test_retrieval_summary_is_empty_not_broken_for_a_fresh_install(_dispose_engine):