{"record":{"id":"b5c2881c8e23e59c","repo":"Hmbown/CodeWhale","slug":"this-browser-session-is-not-authenticated-restart","errorCode":null,"errorMessage":"This browser session is not authenticated. Restart `codewhale web` to open a fresh one-time session.","messagePattern":"This browser session is not authenticated\\. Restart `codewhale web` to open a fresh one-time session\\.","errorType":"exception","errorClass":"Error","httpStatus":401,"severity":"error","filePath":"crates/tui/src/runtime_web/app.mjs","lineNumber":956,"sourceCode":"    }\n    const response = await fetch(path, {\n      ...options,\n      headers,\n      credentials: \"same-origin\",\n      cache: \"no-store\",\n    });\n    if (!response.ok) {\n      let message = `${response.status} ${response.statusText}`.trim();\n      try {\n        const body = await response.json();\n        message = body?.error?.message || body?.message || message;\n      } catch (_error) {\n        // The status line is enough when the response is not JSON.\n      }\n      if (response.status === 401) {\n        message = \"This browser session is not authenticated. Restart `codewhale web` to open a fresh one-time session.\";\n      }\n      throw new Error(message);\n    }\n    if (response.status === 204) return null;\n    const contentType = response.headers.get(\"content-type\") || \"\";\n    return contentType.includes(\"application/json\") ? response.json() : response.text();\n  }\n\n  function renderThreadList() {\n    dom.threadList.replaceChildren();\n    if (app.summaries.length === 0) {\n      const empty = element(\"p\", \"thread-preview\", \"No matching threads\");\n      empty.style.padding = \"8px 10px\";\n      dom.threadList.append(empty);\n      return;\n    }\n\n    const groups = groupThreadSummaries(app.summaries);\n    if (groups.needsYou.length > 0) {\n      appendThreadGroup(\"Needs you\", \"needs-you\", groups.needsYou);","sourceCodeStart":938,"sourceCodeEnd":974,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/runtime_web/app.mjs#L938-L974","documentation":"The web client's api() wrapper replaces the error message with this text when the Runtime answers HTTP 401, because browser sessions are one-time tokens minted by `codewhale web` at startup. A 401 means that token is no longer valid and the page cannot authenticate itself to the Runtime.","triggerScenarios":"Any api() call returns response.status === 401: the one-time session token expired or was invalidated, the Runtime restarted (issuing new tokens), or the request was made from a page whose token was never issued.","commonSituations":"Keeping the browser tab open across a `codewhale web` restart; copying the URL to a second browser/device (one-time session); long-lived tab outliving the token lifetime; sharing the URL in chat after the token was consumed.","solutions":["Stop and rerun `codewhale web`, then open the freshly printed one-time URL in the same tab","Reload only from the new URL emitted by the latest `codewhale web` invocation","Close stale tabs pointing at old sessions and use one tab per session","Check that no proxy strips the session credentials/cookies on the way to the Runtime"],"exampleFix":"// before: retrying requests against a dead session\nawait api('/v1/providers');\n// after: detect 401 and prompt the user to re-open a fresh session URL\ntry { await api('/v1/providers'); }\ncatch (e) {\n  if (String(e.message).includes('not authenticated')) location.href = await promptForFreshSessionUrl();\n}","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try { await api(path); } catch (e) { if (String(e.message).includes('not authenticated')) { showToast('Restart `codewhale web` and open the new URL.'); } }","preventionTips":["Open only the URL printed by the latest `codewhale web` run","Use one browser tab per one-time session","Expect session loss after Runtime restarts; do not retry through it","Check proxies preserve session credentials"],"tags":["authentication","http-401","browser-session"],"backgroundTag":"authentication-required","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}