feat(profile): event-driven invalidation (#81 phase B.2)

Features now declare invalidatedBy subjects in the registry; the new
profile/subscriber.ts subscribes to each unique subject and drops
matching stored rows for the userId in the payload. Next getProfile
call recomputes from current data instead of waiting up to ttlSec.

Wiring:
  completion_rate_30d, dismiss_rate_30d, mean_dwell_ms_30d,
  preferred_hour  ← signals.tip.feedback
  tip_volume_30d  ← signals.tip.served

TTL stays as a safety net for clock drift and dropped events.
Registration validates each declared subject against KNOWN_SUBJECTS
(mirror of EventMap) so typos throw at startup, not silently.

ADR-0011 updated.

Refs #81.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-04-25 00:38:45 +00:00
parent 4a42a6aabf
commit ee4eb15022
5 changed files with 219 additions and 6 deletions

View File

@@ -60,13 +60,18 @@ Initial features: `completion_rate_30d`, `dismiss_rate_30d`,
Phase B replaces this with event-driven incremental updates subscribing to
`signals.tip.feedback`.
## Phase B (deferred)
## Phase B
- Subscribe to `signals.tip.feedback` for incremental updates instead of TTL.
- Extend the bandit feature vector to include profile features (deliberate
`D` change with state-migration plan).
- Admin page: per-user profile view + manual rebuild button.
- Staleness/data-quality alerts in `/admin/data-quality`.
- **B.1** — Per-user profile view + rebuild action in `/admin/users/:id`.
- **B.2** — Event-driven invalidation: features declare `invalidatedBy`
subjects in the registry; `profile/subscriber.ts` deletes the affected stored
rows on publish so the next `getProfile` call recomputes immediately rather
than waiting up to `ttlSec`. TTL stays as a safety net for clock drift /
dropped events.
-**B.4** — Staleness panel in `/admin/data-quality` (counts missing + stale
per feature across eligible users).
-**B.3** — Extend the bandit feature vector to include profile features
(deliberate `D` change with state-migration plan + shadow rollout per ADR-0002).
## Alternatives considered