{"record":{"id":"4bee82a75fce8cc0","repo":"jackwener/OpenCLI","slug":"yuanbao-hy-user-cookie-missing-anonymous-session","errorCode":null,"errorMessage":"Yuanbao hy_user cookie missing — anonymous session","messagePattern":"Yuanbao hy_user cookie missing — anonymous session","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/yuanbao/auth.js","lineNumber":18,"sourceCode":"import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';\nimport { registerSiteAuthCommands } from '../_shared/site-auth.js';\nimport { hasLoginGate, ensureYuanbaoPage, YUANBAO_DOMAIN, YUANBAO_URL } from './shared.js';\n\nasync function hasYuanbaoUserCookie(page) {\n  const cookies = await page.getCookies({ url: 'https://yuanbao.tencent.com' });\n  return cookies.some(c => c.name === 'hy_user' && c.value);\n}\n\nasync function verifyYuanbaoIdentity(page) {\n  await ensureYuanbaoPage(page);\n  if (await hasLoginGate(page)) {\n    throw new AuthRequiredError(YUANBAO_DOMAIN, 'Yuanbao showed wx login gate — anonymous session');\n  }\n  const cookies = await page.getCookies({ url: 'https://yuanbao.tencent.com' });\n  const hyUser = cookies.find(c => c.name === 'hy_user')?.value || '';\n  if (!hyUser) {\n    throw new AuthRequiredError(YUANBAO_DOMAIN, 'Yuanbao hy_user cookie missing — anonymous session');\n  }\n  const probe = await page.evaluate(`\n    (() => {\n      const bodyText = document.body?.innerText || '';\n      const nickMatch = bodyText.match(/用户[a-z0-9]{4,}/i);\n      const state = window.__INITIAL_STATE__ || {};\n      const seen = new Set();\n      const stack = [state];\n      let stateNick = '';\n      while (stack.length) {\n        const node = stack.pop();\n        if (!node || typeof node !== 'object' || seen.has(node)) continue;\n        seen.add(node);\n        if (Array.isArray(node)) { stack.push(...node); continue; }\n        const u = node.userInfo || node.user;\n        if (u && typeof u === 'object' && (u.nickname || u.nick)) {\n          stateNick = String(u.nickname || u.nick);\n          break;","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/yuanbao/auth.js#L1-L36","documentation":"An AuthRequiredError thrown by verifyYuanbaoIdentity when no login gate is visible but the session's cookies for yuanbao.tencent.com contain no non-empty `hy_user` cookie — Yuanbao's user-identity cookie. The page may look logged out or half-authenticated, so the verifier treats the session as anonymous and refuses to proceed.","triggerScenarios":"Running a yuanbao command whose verify step checks cookies when the hy_user cookie is missing, empty, expired server-side, or scoped to a different URL so page.getCookies({ url: 'https://yuanbao.tencent.com' }) doesn't return it.","commonSituations":"Cookie partially expired (gate not shown yet but session invalidated); manually imported cookie set missing hy_user; cookie domain mismatch after a site domain change; privacy extensions stripping cookies.","solutions":["Re-run the yuanbao login flow to obtain a fresh complete cookie set.","Check that imported cookies include a non-empty hy_user for yuanbao.tencent.com.","Clear the session and log in again — half-valid cookies cause this state."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const cookies = await page.getCookies({ url: 'https://yuanbao.tencent.com' });\nconst hyUser = cookies.find(c => c.name === 'hy_user')?.value || '';\nif (!hyUser) throw new Error('Session lacks hy_user cookie — run yuanbao login first');","typeGuard":"const hasHyUser = (cookies) =>\n  Array.isArray(cookies) && typeof cookies.find(c => c.name === 'hy_user')?.value === 'string' && cookies.find(c => c.name === 'hy_user').value.length > 0;","tryCatchPattern":"try {\n  await run(['yuanbao', 'whoami']);\n} catch (e) {\n  if (/hy_user cookie missing/.test(e.message)) {\n    await run(['yuanbao', 'login']);\n  } else throw e;\n}","preventionTips":["When importing cookies manually, ensure hy_user is present and non-empty","Re-login when cookies are half-expired (gate not shown but session invalid)","Check cookie domain/scope matches yuanbao.tencent.com","Disable extensions/profiles that strip cookies during automation"],"tags":["yuanbao","authentication","cookies","session"],"backgroundTag":"missing-session-cookie","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}