Skip to content

feat(codex): scope model discovery to pinned PTY accounts - #13270

Closed
rp0927 wants to merge 3 commits into
stablyai:mainfrom
rp0927:feat/codex-pty-account-model-discovery
Closed

rp0927 wants to merge 3 commits into
stablyai:mainfrom
rp0927:feat/codex-pty-account-model-discovery

Conversation

@rp0927

@rp0927 rp0927 commented Aug 8, 2026

Copy link
Copy Markdown

Summary

Codex model discovery can now resolve the managed account pinned to a PTY and run the existing model probe with that account's effective CODEX_HOME. Native-chat enrichment scopes its cache by host and pinned account so switching accounts does not reuse another account's discovered model catalog.

The new ptyId field is optional throughout the renderer, preload, main-process, and runtime Git path. Older callers and runtimes continue to use the existing global Codex environment.

This PR is stacked on #13183. Please review it after that PR lands; the shared runtime model-discovery changes will disappear from this diff once the base is merged.

Screenshots

No visual layout change. The existing native Codex model and reasoning controls receive account-scoped choices when a PTY has a managed Codex account pinned.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm build
  • Added or updated high-quality tests that would catch regressions

Focused validation:

  • Focused Vitest suite covering runtime-home resolution, IPC, runtime Git, commit-message environments, native-chat enrichment, renderer runtime Git, and the shared Codex catalog — 353 tests passed, 1 skipped.
  • pnpm run build:desktop — passed.
  • git diff --check — passed.
  • Conflict scan against the current origin/main — no conflicts found.

Local environment note: the repository requests Node 24, while this workstation currently exposes Node 25.8.1. The desktop build completed; its development CLI install step reported the expected permission warning for /usr/local/bin/orca-dev without failing the build.

AI Review Report

The review covered optional-field compatibility, PTY-to-account resolution, account-scoped cache identity, main-process ownership of managed account paths, commit-message discovery, and fallback behavior when no account is pinned.

Regression tests cover account-specific environment selection, unknown PTYs, IPC forwarding, runtime Git forwarding, and cache separation without changing the existing unscoped path.

Cross-platform review:

  • Managed account homes remain resolved by the existing main-process service; renderer code receives no credential paths.
  • Local, WSL, SSH, and remote runtime ownership remains in the existing discovery path.
  • The wire addition is optional so older callers retain the current behavior.

Security Audit

  • Renderer and preload code pass only the opaque PTY identifier; they do not receive CODEX_HOME, auth files, tokens, or managed-home paths.
  • Main validates the PTY lookup through the existing Codex pane-account registry before applying an account environment.
  • Unknown or deleted account references fail safely to the existing unscoped environment.
  • No user-controlled shell command is introduced; the fixed Codex model probe remains unchanged.
  • Dependencies and persistent credential formats are unchanged.

Notes

@rp0927

rp0927 commented Aug 13, 2026

Copy link
Copy Markdown
Author

Rebased onto current origin/main (392 commits). Conflict resolutions kept main’s usage-provider IPC/lifecycle and PTY cwd prevalidation, and ported account-filter / managed-home behavior onto those paths. Localization keys were merged rather than dropped. Stack branches were force-pushed with --force-with-lease. GitHub will not accept another fork branch as the base, so these PRs still target main and still contain the full stack below them — review bottom-up starting at #13183.

@rp0927
rp0927 marked this pull request as ready for review August 13, 2026 14:19
@coderabbitai

coderabbitai Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Codex model discovery now resolves PTY-specific homes and prepares the matching environment. PTY identifiers flow through preload, IPC, runtime RPC, and local or remote discovery paths. Codex model-list output is parsed with shared validation and normalized metadata. Native chat enrichment stores and publishes discovered Codex models by agent, host, and PTY scope, including model-specific reasoning options and defaults.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the change and testing, but it omits required template sections and does not provide the required issue link or exact visual-proof format. Add the required ELI5, What Changed, Why, Linked Issue with a valid issue reference, Visual Proof using N/A if applicable, Review, Checklist, and Author sections.
Docstring Coverage ⚠️ Warning Docstring coverage is 4.55% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes scoping Codex model discovery to accounts pinned to PTYs.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/renderer/src/runtime/runtime-git-client.ts (1)

694-713: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Require the remote PTY owner to match the selected runtime.

Line 713 forwards only remotePty.handle. It discards remotePty.environmentId. If the selected runtime changes while a PTY ID from another runtime remains available, the other runtime receives that handle. This can resolve an unrelated PTY and managed account.

Only forward a parsed handle when its owner is absent or equals target.environmentId. Otherwise omit ptyId. Add a mismatch test for a PTY owned by env-1 with env-2 selected.

Proposed fix
   if (target.kind === 'local' || !context.worktreeId) {
     return window.api.git.discoverCommitMessageModels({
       agentId,
       worktreePath: resolveLocalWorktreePath(context),
       connectionId: context.connectionId,
       ...(!remotePty && ptyId ? { ptyId } : {})
     }) as Promise<RuntimeDiscoverCommitMessageModelsResult>
   }
+  const ptyIdForRuntime =
+    remotePty === null
+      ? ptyId
+      : remotePty.environmentId === null || remotePty.environmentId === target.environmentId
+        ? remotePty.handle
+        : undefined
   return callRuntimeRpc<RuntimeDiscoverCommitMessageModelsResult>(
     target,
     'git.discoverCommitMessageModels',
     {
       worktree: toRuntimeWorktreeSelector(context.worktreeId),
       agentId,
-      ...(ptyId ? { ptyId: remotePty?.handle ?? ptyId } : {}),
+      ...(ptyIdForRuntime ? { ptyId: ptyIdForRuntime } : {}),
🧹 Nitpick comments (4)
src/shared/agent-session-option-catalog-claude-codex.ts (1)

223-228: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

One effort-label mapping is duplicated across two Codex model surfaces. Both files label the same parseCodexModelList reasoning levels, and they disagree on the xhigh casing, so one discovered level renders two ways.

  • src/shared/agent-session-option-catalog-claude-codex.ts#L223-L228: replace labelCodexEffort with a shared helper exported from src/shared/codex-model-list-probe.ts.
  • src/shared/commit-message-agent-spec.ts#L176-L186: import that shared helper instead of the inline effort === 'xhigh' ? 'Extra High' : labelFromModelId(effort) expression.
src/main/codex-accounts/runtime-home-service.test.ts (1)

420-437: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a lane-mismatch case next to the removed-account case.

The added tests cover account-home, real-home, wsl-home, and a removed account. The lane check at the top of resolveCodexHomeForPaneModelDiscovery has no test. A pane recorded as wsl:Ubuntu that is probed with { runtime: 'host' } must throw. That case pins the fail-closed contract for the shared-home and custom-home routes as well.

💚 Proposed test
it('fails closed when the recorded PTY lane differs from the discovery runtime', async () => {
  writePaneRegistry({
    'pty-wsl-lane': { selectionKey: 'wsl:Ubuntu', accountId: null, homeRoute: 'wsl-home' }
  })
  const store = createStore(createSettings())

  const { CodexRuntimeHomeService } = await import('./runtime-home-service')
  const service = new CodexRuntimeHomeService(store as never)

  expect(() =>
    service.resolveCodexHomeForPaneModelDiscovery('pty-wsl-lane', { runtime: 'host' })
  ).toThrow('no longer matches')
})
src/main/text-generation/commit-message-agent-environment.test.ts (1)

146-161: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover the null result of prepareForCodexPtyLaunch.

The added cases cover a scoped path and undefined. The contract also treats null as an authoritative real-home route. In that case the env must strip the Orca-owned CODEX_HOME override and prepareForCodexLaunch must not run. Add that case so the null versus undefined distinction cannot regress silently.

src/main/index.ts (1)

1432-1433: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

The PTY discovery resolver is registered twice as an identical inline arrow. Both copies assert codexRuntimeHome!, and only the first site has a proven initialization guard.

  • src/main/index.ts#L1432-L1433: define one module-level function, for example resolveCodexPtyModelDiscoveryHome, and pass it here.
  • src/main/index.ts#L2668-L2669: pass the same function and confirm the guard, or make the helper return undefined when codexRuntimeHome is unset so discovery falls back to legacy resolution instead of throwing.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d817242c-1575-452e-a7b9-3381941cc4b3

📥 Commits

Reviewing files that changed from the base of the PR and between 9a81874 and 20e2e8f5eddcc294b5751ed4d3ee6f6d50ca60fe.

📒 Files selected for processing (25)
  • src/main/codex-accounts/runtime-home-service.test.ts
  • src/main/codex-accounts/runtime-home-service.ts
  • src/main/index.ts
  • src/main/ipc/filesystem.test.ts
  • src/main/ipc/filesystem.ts
  • src/main/runtime/orca-runtime-git.ts
  • src/main/runtime/rpc/methods/git-params.ts
  • src/main/runtime/rpc/methods/git.test.ts
  • src/main/runtime/rpc/methods/git.ts
  • src/main/text-generation/commit-message-agent-environment.test.ts
  • src/main/text-generation/commit-message-agent-environment.ts
  • src/preload/api-types.ts
  • src/preload/index.ts
  • src/renderer/src/components/native-chat/native-chat-session-option-discovery.ts
  • src/renderer/src/components/native-chat/native-chat-session-option-enrichment.test.ts
  • src/renderer/src/components/native-chat/native-chat-session-option-enrichment.ts
  • src/renderer/src/components/native-chat/use-native-chat-session-options.ts
  • src/renderer/src/runtime/runtime-git-client.test.ts
  • src/renderer/src/runtime/runtime-git-client.ts
  • src/shared/agent-session-option-catalog-claude-codex.ts
  • src/shared/agent-session-option-catalog.test.ts
  • src/shared/agent-session-option-catalog.ts
  • src/shared/codex-model-list-probe.test.ts
  • src/shared/codex-model-list-probe.ts
  • src/shared/commit-message-agent-spec.ts

@AmethystLiang
AmethystLiang requested a review from OrcaWin August 13, 2026 16:51
@rp0927
rp0927 force-pushed the feat/codex-pty-account-model-discovery branch from 20e2e8f to 49f6381 Compare August 14, 2026 03:32
@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@rp0927
rp0927 force-pushed the feat/codex-pty-account-model-discovery branch 4 times, most recently from 90d9142 to b6e8961 Compare August 14, 2026 10:56
@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7ff2d70d-cd36-471c-94da-221244255850

📥 Commits

Reviewing files that changed from the base of the PR and between cb42b60 and b6e8961013a0a769cf51013db6110e30828499a5.

📒 Files selected for processing (25)
  • src/main/codex-accounts/runtime-home-service.test.ts
  • src/main/codex-accounts/runtime-home-service.ts
  • src/main/index.ts
  • src/main/ipc/filesystem.test.ts
  • src/main/ipc/filesystem.ts
  • src/main/runtime/orca-runtime-git.ts
  • src/main/runtime/rpc/methods/git-params.ts
  • src/main/runtime/rpc/methods/git.test.ts
  • src/main/runtime/rpc/methods/git.ts
  • src/main/text-generation/commit-message-agent-environment.test.ts
  • src/main/text-generation/commit-message-agent-environment.ts
  • src/preload/api/git-inspection-api.ts
  • src/preload/index.ts
  • src/renderer/src/components/native-chat/native-chat-session-option-discovery.ts
  • src/renderer/src/components/native-chat/native-chat-session-option-enrichment.test.ts
  • src/renderer/src/components/native-chat/native-chat-session-option-enrichment.ts
  • src/renderer/src/components/native-chat/use-native-chat-session-options.ts
  • src/renderer/src/runtime/runtime-git-client.test.ts
  • src/renderer/src/runtime/runtime-git-client.ts
  • src/shared/agent-session-option-catalog-claude-codex.ts
  • src/shared/agent-session-option-catalog.test.ts
  • src/shared/agent-session-option-catalog.ts
  • src/shared/codex-model-list-probe.test.ts
  • src/shared/codex-model-list-probe.ts
  • src/shared/commit-message-agent-spec.ts
🚧 Files skipped from review as they are similar to previous changes (24)
  • src/main/index.ts
  • src/main/codex-accounts/runtime-home-service.test.ts
  • src/main/runtime/rpc/methods/git-params.ts
  • src/main/ipc/filesystem.ts
  • src/main/runtime/rpc/methods/git.ts
  • src/shared/codex-model-list-probe.test.ts
  • src/main/runtime/orca-runtime-git.ts
  • src/main/runtime/rpc/methods/git.test.ts
  • src/shared/commit-message-agent-spec.ts
  • src/main/text-generation/commit-message-agent-environment.test.ts
  • src/shared/agent-session-option-catalog-claude-codex.ts
  • src/preload/index.ts
  • src/renderer/src/components/native-chat/native-chat-session-option-enrichment.ts
  • src/shared/agent-session-option-catalog.test.ts
  • src/shared/agent-session-option-catalog.ts
  • src/renderer/src/components/native-chat/use-native-chat-session-options.ts
  • src/main/ipc/filesystem.test.ts
  • src/renderer/src/runtime/runtime-git-client.ts
  • src/renderer/src/components/native-chat/native-chat-session-option-enrichment.test.ts
  • src/renderer/src/components/native-chat/native-chat-session-option-discovery.ts
  • src/renderer/src/runtime/runtime-git-client.test.ts
  • src/shared/codex-model-list-probe.ts
  • src/main/codex-accounts/runtime-home-service.ts
  • src/main/text-generation/commit-message-agent-environment.ts

Comment thread src/preload/api/git-inspection-api.ts Resolved
@rp0927
rp0927 force-pushed the feat/codex-pty-account-model-discovery branch 2 times, most recently from 2a5d556 to 0b45daa Compare August 15, 2026 06:37
@coderabbitai

coderabbitai Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@rp0927
rp0927 force-pushed the feat/codex-pty-account-model-discovery branch from 0b45daa to d2750b3 Compare August 15, 2026 08:47
@coderabbitai

coderabbitai Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: cd274369-e912-41de-bece-4306b5065bf4

📥 Commits

Reviewing files that changed from the base of the PR and between 5b7f442 and d2750b3afbad2ee2ed97a017096a0dca93dbadae.

📒 Files selected for processing (23)
  • src/main/codex-accounts/runtime-home-service.ts
  • src/main/index.ts
  • src/main/ipc/filesystem.ts
  • src/main/runtime/orca-runtime-git.ts
  • src/main/runtime/rpc/methods/git-params.ts
  • src/main/runtime/rpc/methods/git.test.ts
  • src/main/runtime/rpc/methods/git.ts
  • src/main/text-generation/commit-message-agent-environment.test.ts
  • src/main/text-generation/commit-message-agent-environment.ts
  • src/preload/api/git-inspection-api.ts
  • src/preload/index.ts
  • src/renderer/src/components/native-chat/native-chat-session-option-discovery.ts
  • src/renderer/src/components/native-chat/native-chat-session-option-enrichment.test.ts
  • src/renderer/src/components/native-chat/native-chat-session-option-enrichment.ts
  • src/renderer/src/components/native-chat/use-native-chat-session-options.ts
  • src/renderer/src/runtime/runtime-git-client.test.ts
  • src/renderer/src/runtime/runtime-git-client.ts
  • src/shared/agent-session-option-catalog-claude-codex.ts
  • src/shared/agent-session-option-catalog.test.ts
  • src/shared/agent-session-option-catalog.ts
  • src/shared/codex-model-list-probe.test.ts
  • src/shared/codex-model-list-probe.ts
  • src/shared/commit-message-agent-spec.ts
🚧 Files skipped from review as they are similar to previous changes (22)
  • src/main/runtime/rpc/methods/git.ts
  • src/renderer/src/runtime/runtime-git-client.ts
  • src/preload/index.ts
  • src/main/runtime/rpc/methods/git.test.ts
  • src/main/runtime/orca-runtime-git.ts
  • src/main/index.ts
  • src/main/ipc/filesystem.ts
  • src/main/runtime/rpc/methods/git-params.ts
  • src/shared/codex-model-list-probe.ts
  • src/renderer/src/components/native-chat/use-native-chat-session-options.ts
  • src/renderer/src/runtime/runtime-git-client.test.ts
  • src/main/codex-accounts/runtime-home-service.ts
  • src/preload/api/git-inspection-api.ts
  • src/shared/codex-model-list-probe.test.ts
  • src/main/text-generation/commit-message-agent-environment.ts
  • src/shared/agent-session-option-catalog.test.ts
  • src/renderer/src/components/native-chat/native-chat-session-option-enrichment.test.ts
  • src/shared/agent-session-option-catalog.ts
  • src/shared/commit-message-agent-spec.ts
  • src/renderer/src/components/native-chat/native-chat-session-option-discovery.ts
  • src/renderer/src/components/native-chat/native-chat-session-option-enrichment.ts
  • src/shared/agent-session-option-catalog-claude-codex.ts

@rp0927
rp0927 force-pushed the feat/codex-pty-account-model-discovery branch 2 times, most recently from d6446b6 to 89177cd Compare August 15, 2026 13:23
@rp0927

rp0927 commented Aug 15, 2026

Copy link
Copy Markdown
Author

Restacked onto current origin/main (c0a775454); force-pushed with --force-with-lease. New head: 89177cda5.

The stack was also restructured so each PR is green on its own head — previously every follow-up fix landed on the tip (#13276), which meant ancestor heads failed typecheck/oxlint standalone and reviewers (including CodeRabbit) were reading a snapshot without the fixes. Details in #13276 (comment).

This head was verified standalone: typecheck:node, typecheck:web, typecheck:cli, oxlint all pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants