{"record":{"id":"419286753178b4f4","repo":"stablyai/orca","slug":"that-codex-account-belongs-to-a-different-runtime","errorCode":null,"errorMessage":"That Codex account belongs to a different runtime.","messagePattern":"That Codex account belongs to a different runtime\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/main/codex-accounts/service.ts","lineNumber":953,"sourceCode":"    return this.getSnapshot()\n  }\n\n  private async doSelectAccount(\n    accountId: string | null,\n    target?: CodexAccountSelectionTarget\n  ): Promise<CodexRateLimitAccountsState> {\n    let effectiveTarget = target\n    if (accountId !== null) {\n      const account = this.requireAccount(accountId)\n      const accountTarget = getCodexSelectionTargetForAccount(account)\n      const requestedTarget = normalizeCodexAccountSelectionTarget(target ?? accountTarget)\n      const normalizedAccountTarget = normalizeCodexAccountSelectionTarget(accountTarget)\n      if (\n        requestedTarget.runtime !== normalizedAccountTarget.runtime ||\n        (requestedTarget.wslDistro !== null &&\n          requestedTarget.wslDistro !== normalizedAccountTarget.wslDistro)\n      ) {\n        throw new Error('That Codex account belongs to a different runtime.')\n      }\n      effectiveTarget = accountTarget\n    }\n\n    const previousSettings = this.store.getSettings()\n    const selection = normalizeCodexRuntimeSelection(previousSettings)\n    const outgoingAccountId = getSelectedCodexAccountIdForTarget(previousSettings, effectiveTarget)\n    const nextSelection = setSelectedCodexAccountIdForTarget(selection, accountId, effectiveTarget)\n\n    this.store.updateSettings({\n      activeCodexManagedAccountId:\n        effectiveTarget?.runtime === 'wsl' ? nextSelection.host : accountId,\n      activeCodexManagedAccountIdsByRuntime: nextSelection\n    })\n    this.safeSyncCanonicalConfigToManagedHomes()\n    this.runtimeHome.syncForCurrentSelection(effectiveTarget)\n    if (\n      accountId === null &&","sourceCodeStart":935,"sourceCodeEnd":971,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/src/main/codex-accounts/service.ts#L935-L971","documentation":"Thrown by doSelectAccount when selecting a specific account (accountId !== null). The requested target's runtime (host vs wsl) — and, for WSL, the distro if one was explicitly requested — does not match the account's persisted selection target. An account can only be selected for the runtime it belongs to; cross-runtime selection is refused.","triggerScenarios":"Calling selectAccountForTarget(accountId, target) where target.runtime or target.wslDistro conflicts with getCodexSelectionTargetForAccount(account). Also selectAccount(accountId) on the default target when the account lives in a different runtime.","commonSituations":"UI offers an account under the wrong runtime tab (e.g. a host-runtime account shown in the WSL distro selector), or a caller hardcodes a target without checking which runtime the account was created under.","solutions":["Derive the target from the account itself via getCodexSelectionTargetForAccount and pass that (or omit target) when selecting.","Fix the UI so each account is only selectable within its own runtime/distro scope.","If you genuinely need the account in another runtime, remove and re-add it under that runtime via addAccount(target)."],"exampleFix":"// before: forcing a host account into a WSL target\nservice.selectAccountForTarget(hostAccountId, { runtime: 'wsl', wslDistro: 'Ubuntu' }) // throws [912]\n\n// after: select using the account's own target\nconst accountTarget = getCodexSelectionTargetForAccount(account)\nawait service.selectAccountForTarget(account.id, accountTarget)","handlingStrategy":"type-guard","validationCode":"// Only select the account under its own runtime target.\nconst accountTarget = getCodexSelectionTargetForAccount(account)\nconst requested = normalizeCodexAccountSelectionTarget(target ?? accountTarget)\nif (requested.runtime !== accountTarget.runtime ||\n    (requested.wslDistro && requested.wslDistro !== accountTarget.wslDistro)) {\n  throw new Error('Account belongs to a different runtime.')\n}\nawait service.selectAccountForTarget(account.id, accountTarget)","typeGuard":"const belongsToTarget = (account: CodexManagedAccount, target: CodexAccountSelectionTarget): boolean => {\n  const t = normalizeCodexAccountSelectionTarget(getCodexSelectionTargetForAccount(account))\n  const r = normalizeCodexAccountSelectionTarget(target)\n  return t.runtime === r.runtime && (r.wslDistro === null || t.wslDistro === r.wslDistro)\n}","tryCatchPattern":"try {\n  await service.selectAccountForTarget(accountId, target)\n} catch (error) {\n  if (error instanceof Error && error.message === 'That Codex account belongs to a different runtime.') {\n    // derive the target from the account and retry\n  } else throw error\n}","preventionTips":["Always derive the selection target from getCodexSelectionTargetForAccount(account).","Scope account lists in the UI per runtime/distro so cross-runtime selection is impossible."],"tags":["codex-accounts","account-selection","runtime","wsl","caller-error"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}