{"record":{"id":"ff2e585232c60ebd","repo":"stablyai/orca","slug":"cookie-replacement-and-rollback-failed","errorCode":null,"errorMessage":"Cookie replacement and rollback failed","messagePattern":"Cookie replacement and rollback failed","errorType":"exception","errorClass":"AggregateError","httpStatus":null,"severity":"error","filePath":"src/main/browser/browser-cookie-import-policy.ts","lineNumber":275,"sourceCode":"  const existingCookies = await store.get({})\n  const removedCookies: Cookie[] = []\n  for (const cookie of existingCookies) {\n    const domain = cookie.domain ? normalizeCookieDomain(cookie.domain) : null\n    if (!domain || !overlapsImportedDomain(cookie, domain, scopes)) {\n      continue\n    }\n    const url = cookieRemovalUrl(cookie, domain)\n    if (!url) {\n      continue\n    }\n    try {\n      await store.remove(url, cookie.name)\n      removedCookies.push(cookie)\n    } catch (err) {\n      try {\n        await restoreImportedDomainCookies(store, removedCookies)\n      } catch (restoreError) {\n        throw new AggregateError([err, restoreError], 'Cookie replacement and rollback failed')\n      }\n      throw err\n    }\n  }\n  return removedCookies\n}\n","sourceCodeStart":257,"sourceCodeEnd":282,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/src/main/browser/browser-cookie-import-policy.ts#L257-L282","documentation":"Thrown as an AggregateError by replaceCookiesForImportedDomains when a store.remove() call fails AND the subsequent rollback (restoreImportedDomainCookies to re-add already-removed cookies) also fails. This is the worst-case double-failure: the replacement couldn't remove a cookie, and the attempt to undo prior successful removals also failed — leaving the cookie jar in a partially-modified state. The AggregateError contains both the removal error and the restore error.","triggerScenarios":"replaceCookiesForImportedDomains iterates existing cookies overlapping imported domains; for each, store.remove(url, name) is called. If remove fails for one cookie after others were already removed, it calls restoreImportedDomainCookies to put back the removed ones. If THAT restore also throws (see error 797), both errors are aggregated into 'Cookie replacement and rollback failed'. The cookie jar is now in an inconsistent state — some imported-domain cookies removed, rollback incomplete.","commonSituations":"Electron's cookie store is in a degraded state (session being torn down, partition unmounted); a cookie removal fails due to a URL/domain mismatch while the rollback cookies have malformed attributes that fail re-set; concurrent cookie mutations from the page racing with the replacement; Electron version bug in remove()/set() atomicity.","solutions":["Inspect both errors in the AggregateError: the first is the removal failure, the second is the restore failure — address the root cause of the removal failure first.","After this error, re-fetch all cookies (store.get({})) and reconcile against the expected state — the jar is partially modified.","Avoid running cookie replacement during session teardown or while the page is actively setting cookies (race).","Retry the full replaceCookiesForImportedDomains operation after the store stabilizes — it is idempotent (removes overlapping cookies, skipped ones are no-ops)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isAggregateError(e: unknown): e is AggregateError {\n  return e instanceof AggregateError && Array.isArray(e.errors)\n}","tryCatchPattern":"try {\n  await replaceCookiesForImportedDomains(store, importedDomains)\n} catch (e) {\n  if (e instanceof AggregateError && /replacement and rollback/i.test(e.message)) {\n    // jar is partially modified — reconcile by re-fetching and comparing\n    const current = await store.get({})\n    // re-attempt the idempotent replacement now that store may have stabilized\n    await replaceCookiesForImportedDomains(store, importedDomains)\n  }\n  throw e\n}","preventionTips":["Don't run cookie replacement during session teardown or while the page is actively setting cookies","Treat this error as leaving the jar in an inconsistent state — always reconcile with store.get({}) after","Retry the full idempotent replacement once the store stabilizes","Avoid concurrent cookie mutations from the page during import-domain replacement"],"tags":["cookies","rollback","aggregate-error","data-integrity"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}