Skip to content

fix(code-review): short-circuit exhausted peer routes - #1344

Open
buntysomroy wants to merge 1 commit into
EveryInc:mainfrom
buntysomroy:fix/claude-session-quota-circuit
Open

fix(code-review): short-circuit exhausted peer routes#1344
buntysomroy wants to merge 1 commit into
EveryInc:mainfrom
buntysomroy:fix/claude-session-quota-circuit

Conversation

@buntysomroy

@buntysomroy buntysomroy commented Aug 7, 2026

Copy link
Copy Markdown

Fixes #1343

Problem

The code-review cross-model route treated an installed Claude CLI as available even after the account had exhausted its session quota. It discovered the known-unhealthy route only after packaging and launching the adversarial review, then repeated that late failure on later invocations.

Fix

  • preflight claude auth status --json before review payload construction;
  • classify session quota, transient rate limit, execution-context authentication, network transport, and other failures separately;
  • persist only route, failure class, observation epoch, and reset epoch in owner-private peer state;
  • run the same route-health/auth preflight in the exact pre-start shell, so an unavailable route returns before any job ID and ce-code-review retains its local adversarial reviewer;
  • repeat the preflight inside the worker immediately before egress to close the concurrency race;
  • preserve the fixed-recipient invariant: an unavailable explicit route never silently sends the diff to another provider;
  • expire the circuit at the provider-reported reset, including the current resets 3:50pm (America/New_York) diagnostic shape.

Claude exposes authentication state but no zero-cost quota-remaining endpoint. The first newly exhausted session still requires an API-bearing request; every subsequent review learns the unhealthy route before code leaves the host or a peer job displaces the local fallback.

Validation

  • focused code-review and contract suites: 125 passed;
  • exact reset-diagnostic, privacy, pre-egress, auth-preflight, expiry-retry, fixed-recipient, and local-fallback contract fixtures passed;
  • full repository suite: 2,909 tests passed; its only failure was the now-updated legacy wording assertion for the old twice-per-session quota rule;
  • release metadata validation passed;
  • strict Claude marketplace and plugin validation passed;
  • shell syntax, Python compilation, and git diff --check passed.

Security Disclosure

Security-relevant state handling changed. The circuit stores no prompt, diff, raw diagnostic, account, or credential data. Its bounded state is owner-private, symlink/ownership checked, lock-serialized, and atomically published. A state-integrity failure fails closed before provider egress.

Agent Disclosure

Codex · GPT-5.6 Sol · via Conductor authored the implementation and tests.

🤖 Generated with Codex · GPT-5.6 Sol · via Conductor

@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: 0b25a97a91

ℹ️ 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 +270 to +271
if candidate.timestamp() <= now + 60:
candidate += timedelta(days=1)

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 Keep imminent reset times on the current day

When the provider reports an absolute reset less than 60 seconds in the future, this condition advances the reset to tomorrow before adding the intended one-minute buffer. For example, at 15:49:30 a resets 3:50pm response opens the circuit for the full 24-hour cap instead of 90 seconds, unnecessarily disabling Claude peer reviews for the rest of the day; only advance the date when the reset time has actually passed.

Useful? React with 👍 / 👎.

Comment on lines +264 to +267
try:
zone = ZoneInfo(zone_name) if zone_name else datetime.now().astimezone().tzinfo
except ZoneInfoNotFoundError:
zone = datetime.now().astimezone().tzinfo

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Honor named reset zones on native Windows

On native Windows installations without the optional tzdata package, ZoneInfo("America/New_York") raises ZoneInfoNotFoundError, so this fallback silently interprets the provider's explicitly New York reset time in the machine's local timezone. A user outside that zone can therefore remain blocked for several extra hours—or, when the misinterpreted time has passed, up to the 24-hour cap—despite native Windows being a supported target; use a source that can resolve the named zone or fall back conservatively rather than changing its meaning.

AGENTS.md reference: AGENTS.md:L55-L55

Useful? React with 👍 / 👎.

Preflight Claude authentication and persist a privacy-safe, reset-aware session-quota circuit so later reviews exclude a known-exhausted route before packaging or egress. Keep transient 429, execution-context auth, and transport failures distinct while preserving fixed-recipient behavior.

Fixes EveryInc#1343

Co-Authored-By: Codex <codex@openai.com>

Agent-Provenance: host=conductor harness=codex model=gpt-5.6-sol
@buntysomroy
buntysomroy force-pushed the fix/claude-session-quota-circuit branch from 0b25a97 to 2343c6b Compare August 7, 2026 19:45

@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: 2343c6bc54

ℹ️ 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".


def _classify(text: str) -> str:
lowered = text.lower()
if "session limit" in lowered or "usage limit" in lowered:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Recognize unqualified Claude limit messages

When Claude reports quota exhaustion as You've hit your limit · resets ..., the text contains neither session limit nor usage limit, so _classify falls through to other. cmd_record then never persists a retry epoch, and every subsequent review sends another doomed API-bearing request instead of short-circuiting the route; recognize the unqualified limit form while tying it to reset or 429 evidence to avoid false positives.

Useful? React with 👍 / 👎.

MAX_QUOTA_TTL = 24 * 3600
SAFE_ROUTE = re.compile(r"^[A-Za-z0-9._-]+$")
RESET_AT = re.compile(
r"\bresets?\s+(?:at\s+)?(\d{1,2}):(\d{2})\s*(am|pm)"

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 Parse reset times that omit minutes

For round-hour diagnostics such as resets 4pm, this expression does not match because it requires :MM, so _retry_after uses the one-hour fallback rather than the provider's absolute reset. That can retry an exhausted route hours too early or suppress it after it is available; make the minute group optional and default it to 00.

Useful? React with 👍 / 👎.

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.

ce-code-review: detect exhausted peer routes before review payload egress

1 participant