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
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:
@@ -208,7 +208,7 @@ def _rule_summary(r, moments: list[str] | None = None) -> dict:
|
||||
|
||||
async def list_rules(
|
||||
rulebook_id: int = 0, topic_id: int = 0, project_id: int = 0,
|
||||
with_usage: bool = False, days: int = 0,
|
||||
with_usage: bool = False, days: int = 0, since: str = "", until: str = "",
|
||||
) -> dict:
|
||||
"""List rules — filter by rulebook, topic, and/or project.
|
||||
|
||||
@@ -223,6 +223,11 @@ async def list_rules(
|
||||
them.
|
||||
days: with `with_usage`, count only the last N days; 0 = everything
|
||||
recorded.
|
||||
since, until: with `with_usage`, count only events in [since, until),
|
||||
each an ISO date or datetime (a bare `until` date covers that
|
||||
whole day). They replace `days`. Use them for a review read after
|
||||
its period, so a later deploy stays out of the counts. An
|
||||
unparseable bound is refused with `error`.
|
||||
|
||||
rulebook_id and topic_id AND-combine; project_id lists a project's rules
|
||||
on its own. Ownership-scoped.
|
||||
@@ -235,6 +240,16 @@ async def list_rules(
|
||||
ones that surface and get opened.
|
||||
"""
|
||||
uid = current_user_id()
|
||||
window_since = window_until = None
|
||||
if with_usage and (since or until):
|
||||
from grimoire.services.retrieval_telemetry import resolve_window
|
||||
try:
|
||||
window_since, window_until = resolve_window(days or 30, since or None, until or None)
|
||||
except ValueError as exc:
|
||||
return {"error": str(exc)}
|
||||
if not since and not days:
|
||||
# An end with no start or count means everything up to that end.
|
||||
window_since = None
|
||||
rows = await rulebooks_svc.list_rules(
|
||||
user_id=uid,
|
||||
rulebook_id=rulebook_id or None,
|
||||
@@ -246,10 +261,12 @@ async def list_rules(
|
||||
mounted = await rulebooks_svc.list_rule_moments(ids)
|
||||
rules = [_rule_summary(r, mounted.get(r.id)) for r in rows]
|
||||
if with_usage:
|
||||
since = (
|
||||
datetime.now(timezone.utc) - timedelta(days=days) if days > 0 else None
|
||||
)
|
||||
usage = await usage_for_rules(ids, since=since)
|
||||
if window_until is not None:
|
||||
usage = await usage_for_rules(ids, since=window_since, until=window_until)
|
||||
else:
|
||||
usage = await usage_for_rules(ids, since=(
|
||||
datetime.now(timezone.utc) - timedelta(days=days) if days > 0 else None
|
||||
))
|
||||
lessons = await confirmed_lesson_counts(uid, ids)
|
||||
for row in rules:
|
||||
row["usage"] = usage.get(row["id"], empty_rule_usage())
|
||||
|
||||
Reference in New Issue
Block a user