Skip to content

fix(proxy): own cancellable usage refresh sessions - #1

Closed
mastertyko wants to merge 1 commit into
mainfrom
fix/proxy-usage-refresh-owned-sessions
Closed

fix(proxy): own cancellable usage refresh sessions#1
mastertyko wants to merge 1 commit into
mainfrom
fix/proxy-usage-refresh-owned-sessions

Conversation

@mastertyko

Copy link
Copy Markdown
Owner

Problem

Client-cancellable rate-limit refreshes used caller-bound repositories while running singleflight work, and joined owned refreshes could leave account state stale.

Solution

  • Run rate-limit refreshes with owned background repositories and joined owned-session singleflight.
  • Release the request repository scope before the owned refresh, then reopen it for payload reads.
  • Fresh-sync account state after joined refreshes.
  • Add cancellation, join-policy, account-sync, and rate-limit seam coverage.

Verification

  • uv run pytest tests/unit/test_usage_updater.py tests/unit/test_proxy_rate_limit.py -q -p no:cacheprovider — 119 passed
  • ruff check app/modules/proxy/_service/rate_limit.py tests/unit/test_proxy_rate_limit.py — passed

OpenSpec: existing database-backends/session-lifecycle requirements; no new delta required.

@mastertyko

Copy link
Copy Markdown
Owner Author

@codex review

@mastertyko

Copy link
Copy Markdown
Owner Author

Superseded by upstream PR Soju06#1887.

@mastertyko mastertyko closed this Aug 22, 2026

@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: 23a487b10d

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

await updater.refresh_accounts(
accounts,
latest_usage,
own_singleflight_sessions=True,

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 Release the usage session before refreshing an expired token

When PostgreSQL uses CODEX_LB_DATABASE_POOL_SIZE=1 with zero overflow and the usage API returns 401, this owned path deadlocks until the pool timeout: _refresh_account_if_stale_with_owned_session retains its background session while AuthManager.ensure_fresh opens refresh_repo_factory, which requires a second connection from the same background pool. Thus the newly enabled rate-limit path cannot refresh expired credentials in the exact single-connection configuration the preceding comment promises to support; close the usage read session before the upstream/token-refresh phase or otherwise avoid the nested checkout.

AGENTS.md reference: AGENTS.md:L109-L113

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.

1 participant