feat(web): stamp login_events on every gated request

The registration gate, once it resolves the authenticated subject to a tapir
user_id, calls StampLogin (store-throttled to one row per user per day). Best-
effort: a stamp failure is logged and swallowed so it never breaks the request.
This is what makes the read-side Stage-0 usage signal actually accrue.

Tests cover the happy-path stamp, the same-day throttle, and that an
unregistered subject (redirected to /register) is never stamped.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-03 23:46:03 +02:00
co-authored by Claude Opus 4.8
parent de54cd33b2
commit 2fac735837
3 changed files with 55 additions and 0 deletions
+7
View File
@@ -64,6 +64,13 @@ func (a *App) registrationGate(h http.Handler) http.Handler {
http.Redirect(w, r, registerPath, http.StatusFound)
return
}
// Stamp the read-side usage signal (Stage-0 gate, ADR-016): the store
// throttles this to one row per user per day, so a stamp on every gated
// request is cheap. Best-effort — a stamp failure must never break the
// request the user actually came for, so it is logged and swallowed.
if err := a.Store.StampLogin(r.Context(), userID); err != nil {
a.logger().Warn("stamp login event", "user", userID, "err", err)
}
h.ServeHTTP(w, r.WithContext(withUserID(r.Context(), userID)))
})
}