## TL;DR

The Expensify session died mid-run. Detect the session failure, re-authenticate through the normal sign-in flow, and resume the audit from the checkpoint; do not restart the whole run.

## Error

```text
expensify session expired mid-run for the audit agent
```

## Steps

1. Detect session expiry: watch for authentication failures or redirect-to-login responses. Expected: the agent identifies the session death.
2. Re-authenticate using the stored sign-in flow (credentials from the secure store, never hard-coded). Expected: a fresh authenticated session.
3. Verify the new session with a lightweight API call before resuming work. Expected: confirmed authentication.
4. Resume from the last checkpoint. Expected: the audit continues where it stopped.
5. Shorten the gap: refresh the session proactively on long runs before the known session lifetime ends. Expected: fewer mid-run expiries.

## When to use

- An agent's Expensify session expires during a run.
- The failure appears as logouts or auth errors mid-run.

## When not to use

- Login fails at the start (check the stored credentials).
- The account is locked (resolve with the Expensify admin).

## Tool compatibility

- Expensify API and session handling; custom audit agents.

## Variant phrasings

### Expensify logged the agent out mid-run

Same failure, plain wording.

### Session invalid during expense audit

The generic phrasing.

## Why it happens

Expensify sessions have finite lifetimes for security. Agents that hold one session across a multi-hour audit will see it die underneath them.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_un8wVPdUeP6COp2G_3e7ag
