JuliusBrussee/caveman · error · Error

caveman: remote session revocation failed

Error message

caveman: remote session revocation failed (HTTP ${response.status}); credentials kept — retry `caveman logout`

What it means

Thrown during `caveman logout` when the remote session revocation endpoint (`/api/v1/auth/logout`) responds with a non-2xx HTTP status. Local credentials are intentionally kept so the user can retry rather than clearing tokens with the session still live.

Solutions

  1. Check the HTTP status; for 401 the session is likely already dead — re-run `caveman logout` or login fresh.
  2. Retry `caveman logout` after transient 5xx / rate limits clear.
  3. Verify only one device rotates the refresh token at a time.
  4. If persistent, inspect gateway logs for why logout is rejected.
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await logout();
} catch (e) {
  if (e instanceof Error) {
    const m = e.message.match(/session revocation failed \(HTTP (\d+)\)/);
    if (m && m[1] === "401") console.error("Session likely already expired — safe to discard local credentials.");
    else if (m) console.error(`Transient logout failure (HTTP ${m[1]}) — retry later.`);
    else throw e;
  }
}

Prevention

When it happens

Trigger: `caveman logout` when the server returns 401 (refresh token already expired/rotated elsewhere), 403, 500, or any other error status for the logout call.

Common situations: Refresh token invalidated by a concurrent login on another device; auth server 5xx during deploy; rate limiting; clock skew making token validation fail.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/d2dd57c51f555aeb. Report an issue: GitHub.

Appendix: source

Thrown at packages/cli/src/index.ts:9838

	    "x-cave-client": "cli",
	  };
	  const request: RequestInit = {
	    method: "POST",
	    redirect: "manual",
	    headers,
	    signal: AbortSignal.timeout(5000),
	  };
	  if (cfg.refreshToken) {
	    headers["content-type"] = "application/json";
	    request.body = JSON.stringify({ refresh_token: cfg.refreshToken });
	  }
	  let response: Response;
	  try {
	    response = await fetch(`${cfg.baseURL}/api/v1/auth/logout`, request);
	  } catch {
	    throw new Error("caveman: remote session revocation was unavailable; credentials kept — retry `caveman logout`");
	  }
	  if (!response.ok) throw new Error(`caveman: remote session revocation failed (HTTP ${response.status}); credentials kept — retry \`caveman logout\``);
	}
	if (externalToken) {
	  console.error("caveman: remote session revoked; CAVE_TOKEN remains set by the parent environment — unset it before the next command");
	  print({ logged_out: true, remote_session_revoked: true, external_token_cleared: false, external_token_source: "CAVE_TOKEN" });
	  return;
	}
	// Persist remote completion before deleting the only local credential. If
	// Keychain/file cleanup fails, the next logout safely retries cleanup without
	// trying to authenticate with the now-revoked session.
	await saveConfig({ ...cfg, logoutPendingLocalCleanup: true });
  clearToken(cfg.tokenStore);
  await saveConfig({ baseURL: "", token: "" });
  print({ logged_out: true });
}

function sleep(ms: number) {
  return new Promise((resolve) => setTimeout(resolve, ms));
}

View on GitHub (pinned to 3ee70a1026)