vibe.infrastructure.token_store

SQLite-based PASETO token replay prevention store.

Uses WAL mode for safe concurrent access across multiple gunicorn workers. Expired tokens are cleaned up inline on each insert — no background thread needed.

init_token_store

init_token_store() -> None

Create the used_tokens table if it doesn't exist.

mark_token_used

mark_token_used(token_id: str, expires_at_epoch: float) -> bool

Attempt to record a token as used.

Returns True if the token was successfully recorded (first use). Returns False if the token was already present (replay).

Also performs inline cleanup of expired tokens.

get_token_stats

get_token_stats() -> dict[str, Any]

Return statistics about stored tokens (for dev diagnostics).