feat(mcp): sweep expired codes and tokens on a timer #112
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/YT-54-sweep-expired-timer"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
db::sweep_expireddeletes spent authorization codes and expired access and refresh tokens, and its doc comment said it was "intended to run on a timer", but that timer was never wired up: the only callers were a unit test and the module doc. Spent codes and expired tokens therefore accumulated for the lifetime of a deployment. Expiry is enforced at lookup time so the stale rows were never honored, but they meant unbounded database growth, retention of token hashes long past their usefulness, and index bloat on the hot lookup paths.yt mcp servenow spawns a background task that sweeps at startup and every hour thereafter. An hour sits well under the 3600s access-token TTL, so the backlog between ticks stays small, and the sweep is three indexed DELETEs against a local SQLite file. The startup tick also prunes whatever expired while the service was down, and the task is aborted when the server stops. A failing sweep is transient, so it is logged at warn and the loop keeps its schedule rather than propagating and taking the service down.The sweep covers only the tables
sweep_expiredalready covered.hub_tokensstays excluded: a row pastexpires_atis still needed because its refresh token mints the replacement, so sweeping those would log every user out every hour. Clearing them is deliberate recovery, not hygiene. A test asserts an expired Hub token survives the sweep, so the exclusion fails loudly if anyone adds it tosweep_expired.yt mcp stdioholds no database and spawns no sweep.#YT-54