← All articles

Your Agent's Session Expired Mid-Task. Here Is Why It Keeps Happening

TL;DR

A session expires mid-task for boring reasons: the browser profile was thrown away between runs, the idle timeout fired during a slow step, the site rotated the session on a sensitive action, or two agents shared one login and invalidated each other. Persist one profile per agent, keep the session warm, treat a sudden login page as a wall to hand off rather than an error to retry, and never share an account between agents.

The session did not expire randomly. One of four ordinary things happened, and each has a specific fix. The costly mistake is treating the surprise login page as an error and retrying into it.

The checklist

  1. The profile was not persisted. A fresh browser context each run means a fresh login each run. Give every agent its own persistent profile directory and keep it between runs.
  2. Idle timeout. The agent spent twenty minutes on a long extraction and the site logged it out at fifteen. Keep the session warm with a lightweight request during long steps, or split the work.
  3. Session rotation on a sensitive action. Many sites reissue the session when you change a payment method or export data. The agent's stored cookie is now stale by design. Read the response headers after such actions and carry the new cookie forward.
  4. Two agents, one account. The second login kicked the first out. This is the most common cause in fleets and the easiest to miss. One account per agent, always.

What to do when it happens anyway

A login page appearing where none was expected is a wall, not a bug in your code. Detect it, hand the live session to a person to sign in once, and resume. Then the profile holds the new session for the next run.

const context = await browser.launchPersistentContext(`profiles/${agentId}`);
// One profile per agent. Never share an account between two of them.

if (unexpectedLoginPage(page)) {
  const fix = await oo.requestFix({ url: page.url(), task });
  await fix.resolved();   // a person signs in; the profile keeps the session
}

Fleets that fix these four things see the surprise-login rate fall to almost nothing. The ones that do not spend their human time re-authenticating the same account every hour.

Questions people ask

Why does my agent get logged out in the middle of a task?

Usually an idle timeout during a slow step, a session rotated by the site on a sensitive action, a browser profile that was not persisted, or another agent signing in to the same account.

How do I keep an agent's session alive?

Persist one browser profile per agent, make a light request during long steps to reset idle timers, and carry forward any new session cookie the site issues after sensitive actions.

Can two agents share one login?

No. The second sign-in usually invalidates the first, so they log each other out in a loop. Give each agent its own account and profile.

What should the agent do when a login page appears unexpectedly?

Stop, treat it as a wall, and hand the live session to a person to sign in once. Retrying into a login page raises the site's automation score and can lock the account.

DoubleOh is the reliability layer for AI agents. When one gets stuck, a person fixes it once in a live browser, and the fix becomes a skill the whole fleet follows from then on.

Start free