Skip to content

fix(auth): touch Explorer sessions at most once a minute instead of on every request - #20

Merged
jzhao234 merged 1 commit into
mainfrom
fix/one-minute-session-touch
Sep 14, 2026
Merged

jzhao234 merged 1 commit into
mainfrom
fix/one-minute-session-touch

Conversation

@jzhao234

Copy link
Copy Markdown
Contributor

TLDR

get_identity no longer takes the SQLite write lock and rewrites last_seen_at/idle_expires_at on every request. It reads first and writes only when the previous touch is more than a minute old, so a page load's burst costs one write and the 60-minute idle limit stays accurate to the minute (never longer). One minute is the convention across Auth, Explorer, and Lens (ElcanoTek/auth PR "one-minute session touch" records it in docs/AUTH_V2_IMPLEMENTATION.md).

Tests

New test covers no-write inside the interval, one write past it, and idle enforcement at the boundary. pytest, ruff check, ruff format all green.

…n every request

TL;DR: Validating an Explorer session no longer writes to SQLite on every request. The last-seen and idle-expiry columns are rewritten only when the previous touch is more than a minute old, which turns a page load's burst of requests into a single write and keeps the stated 60-minute idle limit accurate to the minute. One minute is the convention across Auth, Explorer, and Lens.

Problem:
get_identity opened every check with BEGIN IMMEDIATE and issued an UPDATE, so each authenticated request took the SQLite write lock and flushed a transaction to record a timestamp that carried no new information. Explorer's inbox page fires several requests per load; with a few dozen users that is hundreds of write transactions per minute against the access-list database.

Fix:
- SESSION_TOUCH_SECONDS = 60, documented as the Elcano convention for service sessions and deliberately a constant.
- get_identity reads first without taking the write lock, then writes only if timestamp - last_seen_at is at least the interval; the UPDATE is guarded with revoked_at IS NULL. Expiry and revocation checks are unchanged, so the idle limit behaves as "60 minutes minus at most one minute", never longer.
- README notes the behaviour.

Tests:
- New: two validations inside the interval leave last_seen_at and idle_expires_at untouched; the first validation past the interval writes once and moves the idle clock forward from the request; a request at idle_expires_at is rejected.
- Ran: pytest -q, ruff check, ruff format --check.
@jzhao234
jzhao234 merged commit 42ad0b7 into main Sep 14, 2026
4 checks passed
@jzhao234
jzhao234 deleted the fix/one-minute-session-touch branch September 14, 2026 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant