✨ feat: auto_reauth goes proactive-first (session_expires_at margin) #160

Merged
mat merged 1 commit from feat/proactive-reauth into main 2026-10-27 10:14:40 +00:00
Owner

Summary

 _request (auto_reauth=True, default)
+  before sending: now() >= session_expires_at - 30 s → re-authenticate first
   on 401 (unchanged): re-authenticate → retry once   # fallback, keeps covering
                                                      # early revocation, unknown
                                                      # expiry, clock skew

auto_reauth now means "keep the session alive", in one flag — no new public option. When the expiry is known (from #159's session_expires_at) and within 30 s, the client re-authenticates before the request instead of eating a 401 + retry. The reactive 401 path is kept as the fallback for expiry-unknown logins (header absent), early server-side revocation and clock skew. auto_reauth=False disables both, as before.

Long-lived WebSocket streams remain out of scope — tracked in #158.

Evidence

  • Before (this branch's base): an expired session on every request eats 401 → re-login → retry (3 round-trips).
  • After: 5 new tests — proactive fires when expired / inside the 30 s margin, stays silent when expiry is >30 s away, auto_reauth=False opts out of proactive too, no-op without stored credentials. Existing test_reauth.py reactive tests pass unchanged (fallback intact); pytest = 197 passed; mypy clean.

Merge Danger

Door: two-way — single semantic flag, revert restores reactive-only.

Blast Radius: low — default-on clients now fire one login POST ~30 s before expiry they'd have eaten a 401 for anyway; observable only as fewer 401s. auto_reauth=False users: unchanged.

Closes #99 (stacked on #159 — merge that first, then retarget to main)

## Summary ```diff _request (auto_reauth=True, default) + before sending: now() >= session_expires_at - 30 s → re-authenticate first on 401 (unchanged): re-authenticate → retry once # fallback, keeps covering # early revocation, unknown # expiry, clock skew ``` `auto_reauth` now means "keep the session alive", in one flag — no new public option. When the expiry is known (from #159's `session_expires_at`) and within 30 s, the client re-authenticates *before* the request instead of eating a 401 + retry. The reactive 401 path is kept as the fallback for expiry-unknown logins (header absent), early server-side revocation and clock skew. `auto_reauth=False` disables both, as before. Long-lived WebSocket streams remain out of scope — tracked in #158. ## Evidence - **Before (this branch's base):** an expired session on every request eats 401 → re-login → retry (3 round-trips). - **After:** 5 new tests — proactive fires when expired / inside the 30 s margin, stays silent when expiry is >30 s away, `auto_reauth=False` opts out of proactive too, no-op without stored credentials. Existing `test_reauth.py` reactive tests pass unchanged (fallback intact); `pytest` = **197 passed**; `mypy` clean. ## Merge Danger **Door:** two-way — single semantic flag, revert restores reactive-only. **Blast Radius:** low — default-on clients now fire one login POST ~30 s before expiry they'd have eaten a 401 for anyway; observable only as fewer 401s. `auto_reauth=False` users: unchanged. Closes #99 (stacked on #159 — merge that first, then retarget to main)
✨ feat: auto_reauth goes proactive-first (session_expires_at margin)
Some checks failed
Tests / forgejo-pytest (pull_request) Successful in 43s
Tests / forgejo-pytest (push) Has been cancelled
570b1b1f75
mat changed target branch from feat/session-expires-at to main 2026-10-27 10:13:41 +00:00
mat changed title from WIP: ✨ feat: auto_reauth goes proactive-first (session_expires_at margin) to ✨ feat: auto_reauth goes proactive-first (session_expires_at margin) 2026-10-27 10:13:51 +00:00
mat force-pushed feat/proactive-reauth from 570b1b1f75
Some checks failed
Tests / forgejo-pytest (pull_request) Successful in 43s
Tests / forgejo-pytest (push) Has been cancelled
to 5270a4d385
All checks were successful
Tests / forgejo-pytest (push) Successful in 43s
Tests / forgejo-pytest (pull_request) Successful in 43s
2026-10-27 10:14:19 +00:00
Compare
mat merged commit 34aa10097b into main 2026-10-27 10:14:40 +00:00
mat deleted branch feat/proactive-reauth 2026-10-27 10:14:40 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
mat/python-comwatt-client!160
No description provided.