agent's session expired mid-export and it kept querying unauthenticated: auth error
Stops an agent that keeps querying after its session expired: check auth on every batch, halt on 401, and re-authenticate before continuing. Use when exports continue unauthenticated. Not for valid sessions.
TL;DR
The session expired and the agent kept firing queries that all failed with 401, wasting time and log space. Check the response status on every batch; on 401, stop querying, re-authenticate, and resume. An unauthenticated loop is pure waste.
Error
Auth error: thousands of 401 responses logged; the export made no progress after the session expired.Steps
- Add a status check on every batch response. Expected: 401s are caught immediately.
- On 401, halt the query loop at once; do not finish the batch plan unauthenticated. Expected: the waste stops.
- Re-authenticate and verify with a cheap call. Expected: a confirmed-good session.
- Resume the export from the last successful page. Expected: no gaps, no repeats.
- Add a circuit breaker: N consecutive 401s halt the run even if the check is missed. Expected: defense in depth.
When to use
- Exports log masses of 401s.
- An agent ignores auth failures and continues.
- After session timeout changes.
When not to use
- Single 401s handled correctly (that is the good path).
- 403s (permissions, different handling).
Tool compatibility
- Any session-based API client.
- Agent loop guards.
Variant phrasings
querying unauthenticated
Halt on 401; re-auth; resume.
401 storm in logs
The loop never checked auth.
Why it happens
Query loops often check errors only at the end. Auth expiry mid-loop then produces thousands of failed calls before anyone notices.
Edge cases
- Distinguish 401 (re-auth) from 403 (stop and escalate); the handling differs.
- Resume needs the last good page persisted; without it you restart.
- Proactive refresh before long exports avoids the whole class.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_OgTgLWI6vPnDanNyf2iPLA