{"record":{"id":"d2dd57c51f555aeb","repo":"JuliusBrussee/caveman","slug":"caveman-remote-session-revocation-failed-http","errorCode":null,"errorMessage":"caveman: remote session revocation failed (HTTP ${response.status}); credentials kept — retry `caveman logout`","messagePattern":"caveman: remote session revocation failed \\(HTTP (.+?)\\); credentials kept — retry `caveman logout`","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":9838,"sourceCode":"\t    \"x-cave-client\": \"cli\",\n\t  };\n\t  const request: RequestInit = {\n\t    method: \"POST\",\n\t    redirect: \"manual\",\n\t    headers,\n\t    signal: AbortSignal.timeout(5000),\n\t  };\n\t  if (cfg.refreshToken) {\n\t    headers[\"content-type\"] = \"application/json\";\n\t    request.body = JSON.stringify({ refresh_token: cfg.refreshToken });\n\t  }\n\t  let response: Response;\n\t  try {\n\t    response = await fetch(`${cfg.baseURL}/api/v1/auth/logout`, request);\n\t  } catch {\n\t    throw new Error(\"caveman: remote session revocation was unavailable; credentials kept — retry `caveman logout`\");\n\t  }\n\t  if (!response.ok) throw new Error(`caveman: remote session revocation failed (HTTP ${response.status}); credentials kept — retry \\`caveman logout\\``);\n\t}\n\tif (externalToken) {\n\t  console.error(\"caveman: remote session revoked; CAVE_TOKEN remains set by the parent environment — unset it before the next command\");\n\t  print({ logged_out: true, remote_session_revoked: true, external_token_cleared: false, external_token_source: \"CAVE_TOKEN\" });\n\t  return;\n\t}\n\t// Persist remote completion before deleting the only local credential. If\n\t// Keychain/file cleanup fails, the next logout safely retries cleanup without\n\t// trying to authenticate with the now-revoked session.\n\tawait saveConfig({ ...cfg, logoutPendingLocalCleanup: true });\n  clearToken(cfg.tokenStore);\n  await saveConfig({ baseURL: \"\", token: \"\" });\n  print({ logged_out: true });\n}\n\nfunction sleep(ms: number) {\n  return new Promise((resolve) => setTimeout(resolve, ms));\n}","sourceCodeStart":9820,"sourceCodeEnd":9856,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L9820-L9856","documentation":"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.","triggerScenarios":"`caveman logout` when the server returns 401 (refresh token already expired/rotated elsewhere), 403, 500, or any other error status for the logout call.","commonSituations":"Refresh token invalidated by a concurrent login on another device; auth server 5xx during deploy; rate limiting; clock skew making token validation fail.","solutions":["Check the HTTP status; for 401 the session is likely already dead — re-run `caveman logout` or login fresh.","Retry `caveman logout` after transient 5xx / rate limits clear.","Verify only one device rotates the refresh token at a time.","If persistent, inspect gateway logs for why logout is rejected."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await logout();\n} catch (e) {\n  if (e instanceof Error) {\n    const m = e.message.match(/session revocation failed \\(HTTP (\\d+)\\)/);\n    if (m && m[1] === \"401\") console.error(\"Session likely already expired — safe to discard local credentials.\");\n    else if (m) console.error(`Transient logout failure (HTTP ${m[1]}) — retry later.`);\n    else throw e;\n  }\n}","preventionTips":["Avoid concurrent logins on multiple devices rotating the same refresh token.","Retry after transient 5xx/429 rather than force-deleting local credentials.","Keep machine clocks synced (large skew breaks token validation)."],"tags":["http","logout","session","api"],"backgroundTag":"http-error-response","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}