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:
@@ -311,13 +311,21 @@ async def enter_project(project_id: int) -> dict:
|
||||
out["systems_bootstrap"] = systems_bootstrap
|
||||
# Family canon: counts only, attached when one is
|
||||
# non-zero. A readout must never fail the handshake it rides on.
|
||||
family_failed = False
|
||||
try:
|
||||
family = await family_adoption_svc.family_readout(uid, project_id)
|
||||
except Exception:
|
||||
logger.warning("family readout failed for project %s", project_id, exc_info=True)
|
||||
family = None
|
||||
family_failed = True
|
||||
if family:
|
||||
out["family"] = family
|
||||
# Every entry is recorded, with or without the line, so a later review
|
||||
# can say whether a project's sessions saw what it owes
|
||||
# (retrieval_telemetry's `family_line`). In the background, so the
|
||||
# handshake never waits on its own telemetry.
|
||||
spawn(family_adoption_svc.record_entry(uid, project_id, family, failed=family_failed),
|
||||
site="family_entry_record")
|
||||
if inception_ask:
|
||||
out["inception"] = inception_ask
|
||||
# The core reply shape: for a client with no prompt hook,
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -361,7 +361,7 @@ async def search(
|
||||
|
||||
|
||||
async def retrieval_telemetry(
|
||||
days: int = 30, near_miss_samples: int = 0,
|
||||
days: int = 30, near_miss_samples: int = 0, since: str = "", until: str = "",
|
||||
) -> dict:
|
||||
"""What the retrieval telemetry says about YOUR surfaces, over a window.
|
||||
|
||||
@@ -659,16 +659,41 @@ async def retrieval_telemetry(
|
||||
from an empty window, which would otherwise read as every counter at
|
||||
zero.
|
||||
|
||||
`family_line` — how often each project was entered and how often the
|
||||
entry carried the family line, from the `enter_project` rows: per
|
||||
project, `entries`, `entries_with_line`, the first and last time the line
|
||||
was shown, and the counts it showed most recently. It answers "did this
|
||||
project's sessions see the family canon it owes", which no other block
|
||||
can.
|
||||
|
||||
A CLOSED WINDOW FOR A REVIEW READ LATE. `days` counts back from now, so
|
||||
a review read two weeks after its period also counts whatever shipped
|
||||
since. Pass `since` and `until` to fix both ends to the period under
|
||||
review; the response's `since` and `until` name the window that was used.
|
||||
|
||||
Args:
|
||||
days: window size, default 30. Clamped to at least 1.
|
||||
days: window size, default 30. Clamped to at least 1. Ignored when
|
||||
`since` is given.
|
||||
near_miss_samples: 0-20, default 0. How many of each source's highest
|
||||
scoring DECLINES to list by record, with the query that asked.
|
||||
Pass it when you are about to move a threshold; leave it off
|
||||
otherwise. See the near-miss section above for why a percentile
|
||||
alone cannot settle a bar.
|
||||
since: start of the window, an ISO date or datetime (UTC when no
|
||||
zone is given). Empty = `days` before `until`.
|
||||
until: end of the window, exclusive. A bare date covers that whole
|
||||
day. Empty = now. An unparseable bound, or `since` not before
|
||||
`until`, is refused with `error`.
|
||||
"""
|
||||
from grimoire.services.retrieval_telemetry import resolve_window
|
||||
|
||||
try:
|
||||
start, end = resolve_window(days, since or None, until or None)
|
||||
except ValueError as exc:
|
||||
return {"error": str(exc)}
|
||||
return await retrieval_summary(
|
||||
current_user_id(), days=days, near_miss_samples=near_miss_samples,
|
||||
since=start, until=end,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user