feat(mobile): add safe Codex rate-limit resets (#9394)

* feat(mobile): add safe Codex rate-limit resets

* fix(mobile): address reset credit review feedback

* review: purge removed-account reset attempts, shared capability constant, rebase test mocks

* review: preserve host compatibility and reset durability

* fix(mobile): recover reset capability after cutover

* fix(mobile): validate runtime capability payloads

* fix(mobile): enforce capability payload contract

* fix(mobile): route mock terminals to selected worktree

* test(mobile): pin malformed probe retry behavior

---------

Co-authored-by: Brennan Benson <79079362+brennanb2025@users.noreply.github.com>
This commit is contained in:
kazu-42
2026-07-24 14:42:04 -07:00
committed by GitHub
co-authored by Brennan Benson
parent 402b5a1cc8
commit 4a71a0ecb2
49 changed files with 5920 additions and 122 deletions
+55 -2
View File
@@ -892,11 +892,16 @@ import { detectRepoIconAndUpstream } from '../repo-icon-autodetect'
import { enrichMissingRepoGitRemoteIdentities } from '../repo-git-remote-identity-enrichment'
import { githubAvatarIcon } from '../../shared/repo-icon'
import type { ClaudeAccountService } from '../claude-accounts/service'
import type { CodexAccountService } from '../codex-accounts/service'
import type {
CodexAccountService,
CodexResetCreditRejectedBeforeProviderReason
} from '../codex-accounts/service'
import type { CodexAccountSelectionTarget } from '../codex-accounts/runtime-selection'
import type { RateLimitService } from '../rate-limits/service'
import type { ClaudeRateLimitAccountsState, CodexRateLimitAccountsState } from '../../shared/types'
import { applyPRBotAuthorOverride } from '../../shared/pr-bot-author-overrides'
import type { RateLimitState } from '../../shared/rate-limit-types'
import type { CodexRateLimitResetOutcome, RateLimitState } from '../../shared/rate-limit-types'
import type { CodexResetCreditExpectedScope } from '../../shared/codex-reset-credit-scope'
import type { VoiceSettings } from '../../shared/speech-types'
import { getSpeechModelManager, getSpeechSttService } from '../speech/speech-runtime-service'
import { getCatalogModel, isLocalSpeechModel, SPEECH_MODEL_CATALOG } from '../speech/model-catalog'
@@ -938,6 +943,18 @@ export type AccountsSnapshot = {
rateLimits: RateLimitState
}
export type CodexRateLimitResetRpcResult = {
scope: CodexResetCreditExpectedScope
snapshot: AccountsSnapshot
} & (
| { outcome: CodexRateLimitResetOutcome }
| {
status: 'rejectedBeforeProvider'
retryDisposition: 'discardAttempt'
reason: CodexResetCreditRejectedBeforeProviderReason
}
)
type RuntimeStore = {
getRepos: Store['getRepos']
getRepo: Store['getRepo']
@@ -10346,6 +10363,42 @@ export class OrcaRuntimeService {
return this.requireAccountServices().codexAccounts.selectAccount(accountId)
}
selectCodexAccountForTarget(
accountId: string | null,
target: CodexAccountSelectionTarget
): Promise<CodexRateLimitAccountsState> {
return this.requireAccountServices().codexAccounts.selectAccountForTarget(accountId, target)
}
async consumeCodexRateLimitResetCredit(
idempotencyKey: string,
expectedScope: CodexResetCreditExpectedScope
): Promise<CodexRateLimitResetRpcResult> {
const { claudeAccounts, codexAccounts } = this.requireAccountServices()
const result = await codexAccounts.consumeRateLimitResetCredit(idempotencyKey, expectedScope)
// Why: Codex selection and usage were captured before its mutation queue
// advanced. Re-reading them here could pair scope A with queued selection B.
const snapshot = {
claude: claudeAccounts.listAccounts(),
codex: result.codex,
rateLimits: result.rateLimits
}
if ('status' in result) {
return {
status: result.status,
retryDisposition: result.retryDisposition,
reason: result.reason,
scope: result.scope,
snapshot
}
}
return {
outcome: result.outcome,
scope: result.scope,
snapshot
}
}
removeClaudeAccount(accountId: string): Promise<ClaudeRateLimitAccountsState> {
return this.requireAccountServices().claudeAccounts.removeAccount(accountId)
}