Skip to content

[leas code] Deduplicate account rate-limit target selection - #13428

Merged
nwparker merged 1 commit into
stablyai:mainfrom
nwparker:nwparker/leas-code-rate-limit-target
Aug 10, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
nwparker:nwparker/leas-code-rate-limit-target

Conversation

@nwparker

Copy link
Copy Markdown
Contributor

Summary

Centralize the duplicated Codex and Claude startup rate-limit target policy behind their existing provider-specific entry points. The shared policy preserves explicit, automatic, and legacy runtime precedence; the mirrored test suites become one provider-crossed table; and the now-redundant project-runtime adapter is removed.

Net reduction: 249 lines across seven files.

Screenshots

No visual change.

Testing

  • pnpm lint
  • pnpm run typecheck:node
  • Focused Vitest suite: 3 files, 35 tests
  • pnpm test
  • pnpm build
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed
  • pnpm run check:code-quality:changed
  • oxfmt and git diff --check

AI Review Report

The review traced every old Codex and Claude decision branch through the shared policy: explicit host and WSL behavior, trimmed configured distros, automatic global-runtime selection, legacy unset settings, provider-specific selection fields, default WSL keys, and the unusual single-WSL fallback on non-Windows hosts. It found no correctness or API blocker. Two low-risk findings were addressed by restoring lazy provider-selection lookup and retaining a concise migration comment.

Cross-platform review explicitly covered macOS, Linux, and Windows. Explicit WSL remains host-only outside Windows, the legacy non-Windows fallback is preserved, and no shortcuts, labels, paths, shell behavior, Electron boundary, SSH execution, folder-workspace assumption, Git command, or remote wire shape changed.

Security Audit

No command execution, path handling, authentication, secrets, dependencies, IPC, or external input surface changed. The patch only consolidates pure settings-to-target selection and keeps the existing provider-specific adapters and return shapes.

Notes

Independent cleanup based on current main. Public provider function names, import paths, default process.platform behavior, and target types remain compatible; the deleted internal project-target module had no other consumers.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Added shared account rate-limit target resolution for Claude and Codex. The resolver handles explicit host and WSL settings, platform compatibility, configured targets, normalized selections, and single-account WSL fallback. Provider functions now supply provider-specific adapters to the shared resolver. Added parameterized tests for runtime, platform, legacy, stale-selection, distro, and multi-selection scenarios. Removed the previous provider-specific test files and project-runtime targeting module logic.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: centralizing duplicated account rate-limit target selection.
Description check ✅ Passed The description covers all required sections, explains the change, documents testing status, and includes AI review, security, and platform notes.
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.

🧹 Nitpick comments (1)
src/main/rate-limits/initial-account-rate-limit-target.ts (1)

44-53: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Express the legacy unset runtime in the parameter type.

GlobalSettings.localAccountRuntime is a required 'auto' | 'host' | 'wsl'. After the 'host' and 'wsl' returns, TypeScript narrows the value to 'auto', so the check on Line 46 is always true by type and Lines 50-53 look unreachable to the compiler and to no-unnecessary-condition-style lint rules. The fallback is only reachable for legacy profiles that omit the field at runtime, which the tests simulate by deleting the property.

Widen the parameter type so the legacy case is visible to the type system and cannot be removed by a later cleanup.

♻️ Proposed refactor
+type AccountRateLimitSettings = Omit<GlobalSettings, 'localAccountRuntime'> & {
+  /** Legacy profiles saved before the account-runtime policy omit this field. */
+  localAccountRuntime?: GlobalSettings['localAccountRuntime']
+}
+
 export function getInitialAccountRateLimitTarget(
-  settings: GlobalSettings,
+  settings: AccountRateLimitSettings,
   provider: AccountRuntimeSelectionProvider,
   platform: NodeJS.Platform = process.platform
 ): AccountRateLimitRuntimeTarget {

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 49919024-85e3-4d19-a86b-68aa602f59c9

📥 Commits

Reviewing files that changed from the base of the PR and between 8a38e2f and e7dc8c6.

📒 Files selected for processing (7)
  • src/main/rate-limits/claude-rate-limit-target.test.ts
  • src/main/rate-limits/claude-rate-limit-target.ts
  • src/main/rate-limits/codex-rate-limit-target.test.ts
  • src/main/rate-limits/codex-rate-limit-target.ts
  • src/main/rate-limits/initial-account-rate-limit-target.test.ts
  • src/main/rate-limits/initial-account-rate-limit-target.ts
  • src/main/rate-limits/project-runtime-rate-limit-target.ts
💤 Files with no reviewable changes (3)
  • src/main/rate-limits/codex-rate-limit-target.test.ts
  • src/main/rate-limits/claude-rate-limit-target.test.ts
  • src/main/rate-limits/project-runtime-rate-limit-target.ts

@nwparker
nwparker merged commit f3ea376 into stablyai:main Aug 10, 2026
44 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
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.

1 participant