Skip to content

feat(accounts): explicit health-gated resume, and login that clears an automatic pause - #8515

Merged
lidge-jun merged 4 commits into
devfrom
codex/8398-resume-if-healthy
Nov 11, 2026
Merged

lidge-jun merged 4 commits into
devfrom
codex/8398-resume-if-healthy

Conversation

@lidge-jun

Copy link
Copy Markdown
Owner

Summary

A paused account stayed paused until someone ran ocx account resume by hand, even after the provider-side cause was fixed (#8398). An unattended supervisor had no safe way to resume, and a re-login after renewing a subscription did not clear the pause. The owner chose explicit resume only, with no background auto-resume.

ocx account resume <provider> <id> --if-healthy

The server resumes only after a fresh read of that account's own usage succeeds:

  • Codex pool account: a forced WHAM quota read; healthy means a fresh quota read by a still-live credential generation.
  • Anthropic OAuth account: the bare /api/oauth/usage read with the stored, unexpired token. It publishes no quota or routing evidence for the still-paused account.

What it refuses or never does:

  • oauth_organization_disabled and account_permission_denied are refused without a read.
  • A paused OAuth credential is never refreshed (every refresh path refuses a paused row on purpose), so an expiring token reports credential_expired and a new login is the way back.
  • Other OAuth providers and the main Codex account report health_check_unsupported; the CLI rejects the flag for API-key pools.

Race protection:

  • The OAuth resume commits under a guard inside the store mutation (credential generation and pause revision). Codex rechecks inside the pause-group callback right before the write.
  • An account that is not paused when checked gets a 200 unchanged with no write.
  • A permanent reason on any linked Codex account refuses the whole resume.

A refusal is 409 { code: "resume_refused", reason }. The CLI prints <provider>: <id> not resumed: <reason> (or { "ok": false, "resumed": false, "reason": ... } with --json) and exits 3, so a supervisor can tell "still unhealthy" from a failed command.

An explicit login clears an automatic pause

An explicit login (saveCredentialWithReceipt) or reauthentication of a paused account clears a pause that auto-pause recorded (one with pauseDetails), because that evidence described the credential the login replaced. It then publishes the pause change, so Anthropic routing drops its quorum cache and session affinity and generic failover its presence count. It also takes over a selection parked on a paused row. The Codex reauthentication branch does the same. A pause an operator set by hand stays. saveAccountCredential clears only with clearAutomaticPause, which only runLogin's reauthentication branch sets, so Kiro's pre-login identity binding leaves a pause alone.

Review notes left as follow-ups (non-blocking, from the final review):

  • A Codex reauthentication clears the automatic pause only on the account that logged in, not on its linked duplicates, which stay paused (the cautious side).
  • A permanent reason on a linked Codex account is found after the named account's quota read rather than before it.
  • The Codex read uses explicitRefresh, which can refresh a paused pool credential. That is the existing explicit-refresh behavior, used only on an operator command.
  • A login also clears an automatic pause with a permanent reason; if the organization is still disabled, auto-pause trips again.

Closes #8398

Verification

  • Failing-first: each new case was run against the code before its fix. The OAuth and Codex route cases, the CLI flag cases, the Codex reauthentication case, the pause-change publication, the four security-review cases (Kiro binding, not-paused no-op on both routes, linked permanent reason) and the local-cli handoff all failed before and pass after. The race tests (credential replaced mid-read, stale guard, Codex re-pause mid-read, needs_reauth) cover guards that already existed.
  • bun test tests/oauth tests/codex-integration/codex-auth-api.test.ts tests/codex-integration/codex-resume-if-healthy.test.ts tests/codex-integration/codex-linked-account-pause.test.ts tests/cli/cli-account-pool-verbs.test.ts tests/cli/cli-account-alias-target.test.ts tests/server/anthropic2-management.test.ts tests/providers/api-key-auto-pause-distribution.test.ts tests/responses/responses-account-auto-pause-wire-owner.test.ts: 1,665 pass, 1 skip, 0 fail (67 files) on the final head.
  • bun run typecheck: no type errors in 2,399 files. bun run structure:check, bun run skill:surface:check, bun run privacy:scan: pass. Layout guards, the file-size ratchet (codex-auth-api.test.ts stays at its 6,549-line cap), the Lab core boundary and skill-ocx: 78 pass.
  • Reviews: correctness (APPROVE), security (SECURITY_REQUEST_CHANGES, all findings fixed), and a fresh final review of ed56753 (APPROVE, SECURITY_APPROVE).
  • NOT RUN: bun run test:changed to completion. Two delegated lanes were running their own suites in parallel worktrees and the run did not finish in reasonable time, so the import-connected coverage above was run on the final head instead. Full bun run test and macOS/Windows CI were also not run (the latter is a manual dev batch only). The PR's Ubuntu CI covers the rest.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

cpa added 4 commits November 11, 2026 10:24
… automatic pause

Owner decision on #8398: resume stays explicit. `ocx account resume <provider> <id> --if-healthy`
resumes a paused Codex pool or Anthropic OAuth account only after a fresh read of that account's
own usage succeeds, refuses the two permanent reasons without a read, never refreshes a paused
credential, and commits only if the probed credential and pause revision are unchanged. A refused
resume is 409 resume_refused with a closed reason and exits 3.

An explicit login or reauthentication now clears a pause that auto-pause recorded (one with
pauseDetails) for the account whose credential it replaced; an operator pause stays.

Closes #8398
…c pause

Anthropic routing drops its quorum cache and session affinity, and generic failover its presence
count, on a pause change. A login that cleared an automatic pause changed eligibility without
that publication, so routing could keep treating the account as paused until its cache aged out.

Refs #8398
…rity review)

- Only an explicit reauthentication clears an automatic pause: saveAccountCredential takes
  clearAutomaticPause, which runLogin's reauth branch sets; Kiro's pre-login identity binding,
  which writes without the operator naming the account, now leaves the pause in place.
- --if-healthy on an account that is not paused when checked answers 200 unchanged without a
  write, so a pause that lands meanwhile is never cleared without a health read.
- A Codex resume also resumes linked accounts; a permanent reason on any of them refuses it.

Refs #8398
…n to a cleared import (#8398 review)

- The Codex health-gated resume rechecks the pause and its revision inside the pause-group
  callback, right before the write, so an operator re-pause during the claim wait is kept.
- A local-cli Anthropic import that clears an automatic pause takes a selection parked on a
  paused row, as reauthentication already did.
- Tests for a credential replaced mid-read, a stale resume guard, a Codex re-pause mid-read and
  a Codex needs_reauth verdict; the operator-pause relogin case now asserts the revision is kept.

Refs #8398
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner November 11, 2026 01:40
@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@lidge-jun

Copy link
Copy Markdown
Owner Author

Maintainer judgment

  • Value: unattended pools can recover from a remotely fixed subscription or plan state without a hand resume, and a re-login after renewing no longer leaves the account paused ([Feature]: Auto-resume a pauseDetails account after the upstream recovers #8398). Both are within the owner decision: explicit resume only, no background auto-resume, and an operator pause is never cleared.
  • UX change scope: one new CLI flag (--if-healthy on ocx account resume), one optional request field (ifHealthy) on the two existing pause routes, and a new 409 resume_refused shape that is returned only when the flag is set. Without the flag, every request and response is unchanged. Login now clears only pauses that auto-pause recorded (pauseDetails present).
  • Regression evidence for existing users: auto-pause is opt-in, so users without it have no pauseDetails and see no login behavior change. Existing pause/resume, OAuth account, Codex auth API and auto-pause suites pass on the final head (1,665 pass, 0 fail). codex-auth-api.test.ts stayed at its cap through a line-neutral helper registration.
  • Security: the OAuth health read sends the stored token only to the hardcoded Anthropic usage endpoint and never refreshes a paused credential. Permanent reasons are refused before any read. Commits are guarded against concurrent pause or credential changes. Management auth is unchanged. A separate security review found one medium issue (Kiro pre-login binding could clear a pause) and two low ones, all fixed, and a fresh final review approved both correctness and security on ed56753.
  • Windows impact: none expected; no filesystem, process or path handling changed.
  • Validation scope: failing-first tests for every behavior and review finding, typecheck, structure, skill surface, privacy, layout, ratchet and Lab guards, and the import-connected suites listed in the PR.
  • NOT RUN: test:changed to completion (contention with two parallel lane suites); full bun run test; macOS/Windows CI (manual dev batch only).
  • Reviewed head = merge head: ed56753 (dev had not moved, so there was no merge commit).

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T01:43:53.841813Z ed56753 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions github-actions Bot added the enhancement New feature or request label Nov 11, 2026
@lidge-jun
lidge-jun merged commit 10bf0d2 into dev Nov 11, 2026
29 checks passed
@lidge-jun
lidge-jun deleted the codex/8398-resume-if-healthy branch November 11, 2026 01:40
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ed567532f6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +137 to +139
runtimeConfig = getRuntimeConfig(config);
if (!isCodexAccountPaused(runtimeConfig, id) || runtimeConfig.codexAccountPauseState?.[id]?.revision !== healthPauseRevision) {
return jsonResponse({ error: "account was not resumed: account_changed", code: "resume_refused", reason: "account_changed", id }, 409);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Recheck the probed credential generation before resuming Codex

If the pool credential changes after the health probe succeeds but before the pause-group callback runs, this check still permits the resume because it verifies only the pause revision. withCodexAccountPauseGroup crosses an asynchronous native-main claim boundary, while concurrent account-list probes can refresh pool credentials without changing their pause revisions. The successful verdict discards freshCredentialGeneration, so the endpoint can return success and unpause a credential other than the one whose usage read succeeded. Carry the probed generation in the verdict and recheck isCodexAccountGenerationLive here immediately before clearing the pause, returning account_changed if it moved.

Useful? React with 👍 / 👎.

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Auto-resume a pauseDetails account after the upstream recovers

1 participant