{"record":{"id":"2330b564604a1c35","repo":"iOfficeAI/AionUi","slug":"webui-api-auth-status-returned-statusres-stat","errorCode":null,"errorMessage":"[WebUI] /api/auth/status returned ${statusRes.status}","messagePattern":"\\[WebUI\\] /api/auth/status returned (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/desktop/src/process/bridge/webuiBridge.ts","lineNumber":59,"sourceCode":"  }\n}\n\n/**\n * On first Enable-WebUI click after a fresh install, the backend's users table\n * holds the seeded `system_default_user` row with an empty password_hash.\n * Probe /api/auth/status; if `needs_setup === true`, ask backend to generate\n * and persist a random password, then stash the plaintext for Settings to show\n * once. When the backend already has credentials (upgrade path handled by\n * ensureAdminUser, or a prior Enable-WebUI), this is a no-op.\n */\nasync function maybeSeedInitialPassword(): Promise<void> {\n  const port = getBackendPort();\n  if (!port) {\n    throw new Error('[WebUI] Cannot start: aioncore is not running (globalThis.__backendPort unset)');\n  }\n  const statusRes = await fetch(`http://127.0.0.1:${port}/api/auth/status`);\n  if (!statusRes.ok) {\n    throw new Error(`[WebUI] /api/auth/status returned ${statusRes.status}`);\n  }\n  const statusJson = (await statusRes.json()) as { needs_setup?: boolean; data?: { needs_setup?: boolean } };\n  const needsSetup = statusJson.needs_setup ?? statusJson.data?.needs_setup ?? false;\n  if (!needsSetup) {\n    setDesktopWebUIInitialPassword(undefined);\n    return;\n  }\n  const resetRes = await fetch(`http://127.0.0.1:${port}/api/webui/reset-password`, { method: 'POST' });\n  if (!resetRes.ok) {\n    throw new Error(`[WebUI] /api/webui/reset-password returned ${resetRes.status}`);\n  }\n  const resetJson = (await resetRes.json()) as { data?: { new_password?: string }; new_password?: string };\n  const newPassword = resetJson.data?.new_password ?? resetJson.new_password;\n  if (!newPassword) {\n    throw new Error('[WebUI] /api/webui/reset-password returned no new_password');\n  }\n  setDesktopWebUIInitialPassword(newPassword);\n}","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/iOfficeAI/AionUi/blob/711aa0550ee183ea495dc33e2c05c7943b70a60a/packages/desktop/src/process/bridge/webuiBridge.ts#L41-L77","documentation":"Thrown when the aioncore backend's /api/auth/status endpoint responds with a non-2xx status during WebUI initial-password seeding. The HTTP status code is included in the message.","triggerScenarios":"GET http://127.0.0.1:{port}/api/auth/status returns 4xx/5xx — backend auth routes not yet mounted, backend still initializing, or an internal backend error.","commonSituations":"Backend listening but still booting its HTTP routes, auth subsystem failure, or a backend version where the endpoint was renamed/removed.","solutions":["Retry once after a short delay — the backend may still be mounting routes when the port is already bound","curl the endpoint directly to see the status and body: curl -i http://127.0.0.1:PORT/api/auth/status","Check backend logs for errors around auth initialization","Confirm the backend version exposes /api/auth/status (not renamed)"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"const health = await fetch(`http://127.0.0.1:${port}/api/auth/status`).catch(() => null);\nif (!health?.ok) { /* backend not ready; wait and retry */ }","typeGuard":null,"tryCatchPattern":"catch (err) {\n  if (/\\/api\\/auth\\/status returned/.test(err.message)) {\n    await delay(1000); return retry();\n  }\n  throw err;\n}","preventionTips":["Probe endpoint health with retries before the real call","Log backend readiness transitions","Version-gate endpoints used by the desktop client"],"tags":["webui","auth","http-status","backend"],"backgroundTag":"backend-endpoint-unhealthy","analyzedSha":"711aa0550ee183ea495dc33e2c05c7943b70a60a","analyzedAt":"2026-08-28T07:56:06.558Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}