refactor(usage): address round-1 review on PR #871

- store: add optional `enabled` param to record_usage_event so hot-path
  callers (nc_semantic_search) pass the already-resolved flag instead of
  forcing a second uncached Settings build (ADR-024); falls back to
  get_settings() when None so the store stays self-gating for standalone
  use.
- hooks: thread enabled= through both call sites; bump the outer
  shared()/construction failure log from debug → warning so "metering
  enabled but no billing data" is visible at the default INFO level.
- migration: instantiate postgresql.JSONB() to match the sibling
  TIMESTAMP(timezone=True) column.
- tests: fix the misleading "asyncpg returns JSONB as a JSON string"
  comment; add occurred_at dialect round-trip test and an enabled-param
  short-circuit test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Chris Coutinho
2026-06-07 15:20:41 +02:00
co-authored by Claude Opus 4.8
parent 1c6b1a84ea
commit 702f66e6b1
6 changed files with 84 additions and 5 deletions
+8 -1
View File
@@ -534,9 +534,16 @@ def configure_semantic_tools(mcp: FastMCP):
"fusion": fusion,
"doc_types": doc_types,
},
# Pass the already-resolved flag so the store doesn't
# rebuild Settings on this hot query path (ADR-024).
enabled=settings.usage_metering_enabled,
)
except Exception:
logger.debug(
# Reached only when shared()/store construction itself
# raises (record_usage_event swallows its own write
# failures). Metering is on, so warn — a silent DEBUG line
# would hide "operator enabled metering but gets no data".
logger.warning(
"usage metering hook (embeddings_queries) skipped",
exc_info=True,
)