{"record":{"id":"22728f37c95b4b6d","repo":"stablyai/orca","slug":"failed-to-clean-up-claude-login-artifacts","errorCode":null,"errorMessage":"Failed to clean up Claude login artifacts.","messagePattern":"Failed to clean up Claude login artifacts\\.","errorType":"exception","errorClass":"AggregateError","httpStatus":null,"severity":"warning","filePath":"src/cli/handlers/account.ts","lineNumber":174,"sourceCode":"      errors.push(error)\n    }\n    if (restoreLegacyCredentials) {\n      try {\n        await (legacyCredentials\n          ? writeActiveClaudeKeychainCredentials(legacyCredentials)\n          : deleteActiveClaudeKeychainCredentialsStrict())\n      } catch (error) {\n        errors.push(error)\n      }\n    }\n  }\n  try {\n    rmSync(configDir, { recursive: true, force: true })\n  } catch (error) {\n    errors.push(error)\n  }\n  if (errors.length > 0) {\n    throw new AggregateError(errors, 'Failed to clean up Claude login artifacts.')\n  }\n}\n\n/** Logs into a Claude account in a temp config dir, then registers it with the local runtime. */\nasync function addClaudeAccount({ client, json }: HandlerContext): Promise<void> {\n  const configDir = mkdtempSync(join(tmpdir(), 'orca-account-add-claude-'))\n  const session: InteractiveLoginSession = {\n    child: null,\n    registering: false,\n    terminationPromise: null\n  }\n  let legacyCredentials: string | null = null\n  let restoreLegacyCredentials = false\n  const result = await withInteractiveLoginCleanup(\n    session,\n    async () => {\n      await cleanupClaudeLoginArtifacts(configDir, legacyCredentials, restoreLegacyCredentials)\n    },","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/src/cli/handlers/account.ts#L156-L192","documentation":"Thrown by cleanupClaudeLoginArtifacts as an AggregateError wrapping one or more errors collected during cleanup of a Claude login attempt (keychain credential deletion/restore and recursive removal of the temp config dir). Each subsystem is tried independently and failures are accumulated, so the AggregateError's `errors` array holds the original causes. This indicates cleanup partially or fully failed after the login flow, not that the login itself failed.","triggerScenarios":"Any of the following fail: deleteActiveClaudeKeychainCredentialsStrict(configDir), legacy credential restore/write, or rmSync(configDir, {recursive:true,force:true}). At least one push to the `errors` array occurs and errors.length > 0.","commonSituations":"macOS Keychain access denied or locked during cleanup, the temp config dir held open file handles (another process, antivirus), permission errors on removal, or partial state from an interrupted previous run.","solutions":["Inspect error.errors array for each underlying cause and address the dominant one.","On macOS, ensure keychain is unlocked and the process has keychain access; rerun cleanup manually.","Manually remove the temp dir (`rm -rf /tmp/orca-account-add-claude-*`) if rmSync failed due to locks.","Re-run the account add flow once the blocker (locked keychain, AV lock) is cleared."],"exampleFix":"// before: AggregateError from cleanup\ntry {\n  await cleanupClaudeLoginArtifacts(configDir, legacyCreds, restore)\n} catch (e) {\n  // surfaced as AggregateError, causes hidden\n}\n\n// after: surface each cause\nif (e instanceof AggregateError) {\n  for (const cause of e.errors) console.error(cause)\n}","handlingStrategy":"try-catch","validationCode":"import { accessSync, constants } from 'node:fs'\n\nfunction canRemoveDir(dir: string): boolean {\n  try {\n    accessSync(dir, constants.W_OK)\n    return true\n  } catch {\n    return false\n  }\n}","typeGuard":"function isAggregateError(e: unknown): e is AggregateError {\n  return e instanceof AggregateError\n}","tryCatchPattern":"try {\n  await addClaudeAccount(ctx)\n} catch (e) {\n  if (e instanceof AggregateError) {\n    for (const cause of e.errors) console.error('cleanup failure:', cause)\n    // login may have succeeded; treat cleanup errors as non-fatal\n  } else {\n    throw e\n  }\n}","preventionTips":["On macOS, ensure the keychain is unlocked before running account add.","Close processes/AV that may hold temp config dir handles.","Periodically clear stale /tmp/orca-account-add-* dirs."],"tags":["account","claude","cleanup","aggregate-error","keychain"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}