Repository navigation
Conversation
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5701b9be79
ℹ️ 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".
|
Confirming the codex review finding at `app/modules/accounts/service.py:335` is real and worth addressing before merge. The shared client built in `app/core/clients/http.py` sets `trust_env=True` explicitly on the main session for exactly this reason — operators behind `HTTP_PROXY` / `HTTPS_PROXY` (corporate networks, Tailscale exit nodes, egress proxies, etc.) need outbound requests to honor those env vars. `aiohttp.ClientSession()` defaults to `trust_env=False`, so the bare session created in `_send_probe_request` will silently bypass the env-proxy path while every other upstream call in codex-lb (`fetch_usage`, the proxy service, etc.) still works. In those deployments the probe endpoint will appear permanently broken — always returning `probeStatusCode: 0` with the network-failure sentinel — even though the operator's other upstream traffic is fine. That makes the failure mode hard to triage. Suggested fix: route the probe through the shared client instead of a one-off session. Two reasonable shapes:
Option 1 is preferred — it matches how `fetch_usage` and the rest of the upstream surface already work, gets connection pooling for free, and means we never have to remember to set `trust_env` again on new upstream call sites. If you go this way please also drop the import of `aiohttp.ClientSession` if it becomes unused. A targeted test that asserts the probe uses the shared client (e.g. by patching `get_http_client` and verifying the patched session was called) would also prevent regression here. Otherwise the PR looks good — bypass-selection design is exactly what #677 was asking for, the audit log entry and "access token never logged" invariant are nice touches. |
|
Confirming the second codex review finding at `app/modules/accounts/service.py:262` is also real. Walked the freshness gate end-to-end. `refresh_accounts` (updater.py:211) does: ```python And `_quota_recovery_should_bypass_freshness` (updater.py:754) only returns True when `account.status == AccountStatus.QUOTA_EXCEEDED` with cooldown expired. Every other status — including the common cases `rate_limited` (the one the probe is mainly designed for) and `active` — does not bypass. So the failure mode is: any account whose primary `usage_history` row was written within `usage_refresh_interval_seconds` (default 60s, and the periodic refresh hits this aggressively) → probe call goes out fine → `refresh_accounts` skips the fetch entirely → `latest_entry_for_account` returns the same pre-probe row → the response's `primary_used_percent_after` equals `primary_used_percent_before` and `accountStatusAfter` equals `accountStatusBefore` even when the probe successfully woke the limiter upstream. For the `rate_limited` reset-event case the bot called out, that's the entire happy path — the probe will look "ineffective" to the operator most of the time. Also worth noting: even passing `latest_usage={}` doesn't fix this. The `latest is None` branch in `refresh_accounts` then checks `_last_successful_refresh.get(account.id)` (updater.py:241) and respects the same interval gate. So you can't sidestep the gate by lying about freshness either. Suggested fixThe clean way is a dedicated forced-refresh path that bypasses both gates. Two reasonable shapes:
Either works; option 2 is slightly cleaner because the probe never goes through bulk-loop bookkeeping that wasn't meant for single-account refresh, and it keeps `refresh_accounts` semantics intact (bulk + interval-gated, used by the periodic loop and the accounts service `upsert` flow). Test to pin thisWorth adding a regression test where the periodic loop has already populated `_last_successful_refresh` / a fresh primary row for the account being probed, then asserting that the probe-triggered refresh still hits `fetch_usage`. Without this test, future refactors of the freshness gate could re-introduce the same silent-skip behavior. This is more impactful than the `trust_env` finding from the other review thread, because in the proxy case the probe at least loudly returns `probeStatusCode: 0`. In this case the probe appears to succeed (`probeStatusCode: 200`) while the snapshot quietly lies, which is the worse failure mode for an operator-facing diagnostic action. |
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
* feat(accounts): add per-account force-probe admin endpoint
Adds POST /api/accounts/{account_id}/probe (dashboard auth) that sends a
single minimal responses.create directly to upstream pinned to one
account, then triggers an immediate /wham/usage refresh. This is the
operator unblock for accounts stuck in rate_limited / quota_exceeded
after OpenAI-side "team reset events" propagate lazily through
/wham/usage (parent issues #676, #677).
Endpoint contract:
- 200 with before/after usage + status snapshot on success
- 404 with code=account_not_found for unknown account
- 409 with code=account_not_probable when status is paused/deactivated
Implementation:
- AccountsService.probe_account decrypts the access token, calls a
private _send_probe_request helper (aiohttp, 30s total / 10s connect
timeout, returns the upstream HTTP status, returns 0 sentinel on
network failure), then triggers UsageUpdater.refresh_accounts so the
post-probe /wham/usage snapshot is persisted.
- Bypasses LoadBalancer.select_account entirely; the call is
intentionally pinned to the specific account.
- Access token is never logged. AuditService.log_async records
account_probed entries alongside the existing account_created /
account_deleted audit trail.
- No frontend / dashboard button in this change (follow-up PR).
OpenSpec change folder: openspec/changes/add-account-probe-endpoint/
Refs:
- Soju06/codex-lb#676
- Soju06/codex-lb#677
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
* refactor(accounts): apply Gemini probe-endpoint feedback
- probe_account / _latest_usage_percents: switch from latest_by_account
(whole-pool dict) to latest_entry_for_account (single-account row) for
per-account lookups. Cuts the DB load per probe from 3x O(N accounts)
to 3x O(1).
- _send_probe_request: drop resp.content.read(1024). Initiating the
request is enough to wake the upstream rate-limiter; the 1024-byte
read could block waiting for the connection to close under keep-alive.
- Unit-test mock updated to side_effect latest_entry_for_account.
All tests still pass; no behavior change beyond the efficiency / SSE
handling improvements.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
180a0b9 to
49cd7c9
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 49cd7c940c
ℹ️ 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".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4a46e5c04c
ℹ️ 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".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 295aca22e0
ℹ️ 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".
|
Codex Review: Didn't find any major issues. Nice work! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
Merge-gate hold: implementation, tests, OpenSpec validation, CI, and Codex review look good, but the PR body only has Because this adds a behavior-changing admin endpoint and appears to address those tracked issues, please add the appropriate |
|
@codex review |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
- Mark the account probe OpenSpec task checklist complete - Update the proposal and delta wording to match force_refresh
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 198cdf4be5
ℹ️ 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".
| access_token = self._encryptor.decrypt(account.access_token_encrypted) | ||
| probe_model = model or DEFAULT_PROBE_MODEL | ||
| probe_status = await self._send_probe_request( | ||
| access_token=access_token, | ||
| chatgpt_account_id=account.chatgpt_account_id, | ||
| model=probe_model, | ||
| ) |
There was a problem hiding this comment.
Refresh stale account tokens before probing
When the selected account's stored access token is expired or otherwise stale, this sends the probe with that token before any refresh is attempted, so upstream returns an auth error and the responses.create never wakes the limiter; the later force_refresh() can refresh tokens on a usage 401, but by then the one probe has already been spent. Existing proxy/usage flows ensure freshness before upstream calls, so this endpoint should refresh/ensure the account token before decrypting and sending the probe.
Useful? React with 👍 / 👎.
|
Hermes blocker on current head (
I verified this with the current code: a Suggested fix: after the forced usage refresh, run the same recoverable-status reconciliation for this account (or make Also note there is already an unresolved current-head Codex thread about refreshing stale account tokens before sending the probe; I am not duplicating that one here, but it remains a separate blocker. |
- Ensure account token freshness before decrypting and sending probe calls - Return the probe failure sentinel without spending an upstream request when token refresh fails - Add regression coverage and update OpenSpec wording
|
@codex review |
- Avoid assigning AsyncMock directly over service methods in tests - Keep probe test accounts fresh by default to avoid real refresh attempts
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ec2c31954d
ℹ️ 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".
| self._additional_usage_repo = additional_usage_repo | ||
| self._limit_warmup_repo = limit_warmup_repo | ||
| self._usage_updater = UsageUpdater(usage_repo, repo, additional_usage_repo) if usage_repo else None | ||
| self._auth_manager = AuthManager(repo) |
There was a problem hiding this comment.
Pass a refresh repo factory for probe refreshes
When a probe hits a stale token, probe_account() calls this AuthManager.ensure_fresh() from the dashboard request's request-scoped AccountsRepository/AsyncSession. AuthManager._run_refresh runs refreshes in a shielded task and documents that client-cancellable callers must provide a fresh repo factory; otherwise an operator disconnect during the stale-token probe can close the request session while the still-running refresh task writes token/status updates, which is the same connection-stranding/failing-refresh case other request-bound callers avoid by passing refresh_repo_factory.
Useful? React with 👍 / 👎.
|
Folded into #865, which is now rebuilt on Current #865 status:
Closing this PR to keep the remaining merge queue |
Summary
Implements the per-account force-probe action proposed in #677.
After OpenAI-side reset events, accounts can get stuck in `rate_limited` / `quota_exceeded` because `/wham/usage` propagates lazily. The selector excludes blocked accounts, so the stuck account cannot wake the upstream limiter via organic traffic — operators today have no first-class action besides waiting for the natural window roll or editing the DB.
This adds `POST /api/accounts/{account_id}/probe` (dashboard auth). The endpoint:
```json
{
"status": "probed",
"accountId": "...",
"probeStatusCode": 200,
"primaryUsedPercentBefore": 100.0,
"primaryUsedPercentAfter": 0.0,
"secondaryUsedPercentBefore": 58.0,
"secondaryUsedPercentAfter": 58.0,
"accountStatusBefore": "rate_limited",
"accountStatusAfter": "active"
}
```
Notes:
Test plan
OpenSpec change folder: `openspec/changes/add-account-probe-endpoint/` (extends the `usage-refresh-policy` capability spec).
Refs #676 / #677 / #678.
🤖 Generated with Claude Code
Part of #677 (admin API endpoint only; dashboard button remains follow-up). Refs #676 and #678.