{"record":{"id":"e351f9a8320e46f3","repo":"stablyai/orca","slug":"could-not-restore-replaced-cookies","errorCode":null,"errorMessage":"Could not restore replaced cookies","messagePattern":"Could not restore replaced cookies","errorType":"exception","errorClass":"AggregateError","httpStatus":null,"severity":"error","filePath":"src/main/browser/browser-cookie-import-policy.ts","lineNumber":193,"sourceCode":"        continue\n      }\n      await store.set({\n        url,\n        name: cookie.name,\n        value: cookie.value,\n        ...(cookie.hostOnly ? {} : { domain: cookie.domain }),\n        ...(cookie.path ? { path: cookie.path } : {}),\n        secure: cookie.secure,\n        httpOnly: cookie.httpOnly,\n        sameSite: cookie.sameSite,\n        ...(cookie.expirationDate ? { expirationDate: cookie.expirationDate } : {})\n      })\n    } catch (err) {\n      failures.push(err)\n    }\n  }\n  if (failures.length > 0) {\n    throw new AggregateError(failures, 'Could not restore replaced cookies')\n  }\n}\n\ntype CookieClearSession = {\n  cookies: Pick<Cookies, 'get' | 'set'>\n  clearStorageData: Session['clearStorageData']\n}\n\nasync function restoreCookieClearSnapshot(\n  store: Pick<Cookies, 'set'>,\n  snapshot: readonly Cookie[],\n  originalError: unknown,\n  rollbackMessage: string\n): Promise<never> {\n  try {\n    await restoreImportedDomainCookies(store, snapshot)\n  } catch (rollbackError) {\n    throw new AggregateError([originalError, rollbackError], rollbackMessage)","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/src/main/browser/browser-cookie-import-policy.ts#L175-L211","documentation":"Thrown as an AggregateError by restoreImportedDomainCookies when one or more store.set() calls to re-write previously-removed cookies failed. The function iterates a list of cookies, attempts to re-set each via Electron's Cookies.set(), collects failures, and if any failed, throws all collected errors aggregated. Each failure's underlying cause is an Electron cookie-set rejection (malformed cookie, invalid domain, etc.).","triggerScenarios":"restoreImportedDomainCookies is called during cookie rollback (after a failed removal in replaceCookiesForImportedDomains, or after a bulk clear in bulkClearCookiesExcept). One or more cookies in the restore list fail store.set() — e.g. a cookie whose domain is malformed after normalization, a secure cookie set on an http URL, an httpOnly constraint violation, or an expired/invalid expirationDate. The cookieRemovalUrl or normalizeCookieDomain for a given cookie produced a valid URL but set() still rejected the cookie details.","commonSituations":"Rollback after a partial cookie-domain replacement where the original cookies had attributes (sameSite, secure, domain) that Electron rejects on re-set; cookies with problematic sameSite=None+secure interplay; a cookie whose domain normalization changed between removal and restore; Electron version differences in cookie validation strictness.","solutions":["Inspect the AggregateError's errors array — each entry is a specific Electron cookie-set rejection with the cookie that failed.","Validate cookie attributes (domain, path, sameSite, secure, httpOnly, expirationDate) against Electron's Cookies.set() constraints before attempting a restore.","For sameSite=None cookies, ensure secure=true is set; for hostOnly cookies, omit the domain field.","If restore is best-effort, catch the AggregateError and log which cookies couldn't be restored rather than failing the whole import."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"import type { Cookie } from 'electron'\nfunction cookieIsValidForSet(cookie: Partial<Cookie>): boolean {\n  if (cookie.sameSite === 'no restriction' && !cookie.secure) return false\n  if (!cookie.name || cookie.name.length === 0) return false\n  return true\n}","typeGuard":"function isAggregateError(e: unknown): e is AggregateError {\n  return e instanceof AggregateError && Array.isArray(e.errors)\n}","tryCatchPattern":"try {\n  await restoreImportedDomainCookies(store, cookies)\n} catch (e) {\n  if (e instanceof AggregateError) {\n    // best-effort restore failed — log which cookies couldn't be re-set\n    for (const err of e.errors) console.error('Cookie restore failed:', err)\n    // decide whether to surface or swallow based on whether partial jar is acceptable\n  }\n  throw e\n}","preventionTips":["Validate cookie attributes against Electron's Cookies.set() constraints before restore (sameSite=None requires secure, hostOnly requires no domain)","Normalize cookie domains consistently between removal and restore","Test cookie round-trip with the target Electron version — validation strictness varies"],"tags":["cookies","rollback","aggregate-error","electron"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}