Skip to content

feat(api): add warmup endpoint - #768

Closed
Komzpa wants to merge 16 commits into
Soju06:mainfrom
Komzpa:revive/pr-506
Closed

Komzpa wants to merge 16 commits into
Soju06:mainfrom
Komzpa:revive/pr-506

Conversation

@Komzpa

@Komzpa Komzpa commented May 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

Revives #506 on a maintainer-owned branch because the original PR head has maintainerCanModify=false.

Credit: original implementation by @huzky-v in #506; this branch rebases and updates that work on current main.

  • Adds /v1/warmup support with warmup request logging, account-scope handling, aggregate exclusions, settings, and OpenSpec coverage.
  • Fixes the Codex needs-work blocker by enforcing and releasing API-key usage reservations before each warmup upstream request, so limited keys cannot generate upstream traffic for free.

Validation

  • uv run pytest tests/integration/test_proxy_warmup.py tests/integration/test_warmup_accounting_exclusions.py -q passed: 9 passed
  • uv run ruff check app/modules/proxy/service.py tests/integration/test_proxy_warmup.py passed
  • uv run ty check app/modules/proxy/service.py app/modules/proxy/api.py tests/integration/test_proxy_warmup.py passed
  • git diff --check passed

OpenSpec

  • add-v1-warmup-endpoint remains included and updated.

Revives #506

@Komzpa Komzpa added the db migration PR changes Alembic database migrations; maintainer must coordinate merge order label May 21, 2026
@Komzpa Komzpa mentioned this pull request May 21, 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: 7b67bcf729

ℹ️ 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 thread app/modules/proxy/service.py Resolved
Comment thread app/modules/proxy/service.py Resolved
@Soju06 Soju06 added the 🤖 codex: needs work [@codex review] raised an issue label May 21, 2026
@Komzpa Komzpa removed the 🤖 codex: needs work [@codex review] raised an issue label May 21, 2026
@Soju06 Soju06 added the 🤖 codex: needs work [@codex review] raised an issue label May 21, 2026
@Komzpa Komzpa removed the 🤖 codex: needs work [@codex review] raised an issue label May 21, 2026
@Soju06 Soju06 added the 🤖 codex: needs work [@codex review] raised an issue label May 21, 2026
@Komzpa Komzpa removed the 🤖 codex: needs work [@codex review] raised an issue label May 21, 2026
@Soju06 Soju06 added the 🤖 codex: needs work [@codex review] raised an issue label May 21, 2026
@Komzpa Komzpa removed the 🤖 codex: needs work [@codex review] raised an issue label May 21, 2026
@Soju06

Soju06 commented May 21, 2026

Copy link
Copy Markdown
Owner

@codex review

@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: 87b9b54db0

ℹ️ 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 thread app/modules/proxy/service.py Resolved
@Soju06 Soju06 added 🤖 codex: needs work [@codex review] raised an issue and removed 🤖 codex: needs work [@codex review] raised an issue labels May 21, 2026
@Soju06

Soju06 commented May 21, 2026

Copy link
Copy Markdown
Owner

@codex review

@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: d86131981a

ℹ️ 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 thread app/modules/proxy/service.py Resolved
@Komzpa Komzpa added the 🤖 codex: needs work [@codex review] raised an issue label May 21, 2026
@Soju06 Soju06 removed the 🤖 codex: needs work [@codex review] raised an issue label May 21, 2026
@Komzpa

Komzpa commented May 21, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@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: 76acdbccd5

ℹ️ 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 thread app/modules/proxy/service.py Resolved
@Komzpa Komzpa added the 🤖 codex: needs work [@codex review] raised an issue label May 21, 2026
@Soju06 Soju06 removed the 🤖 codex: needs work [@codex review] raised an issue label May 21, 2026
@Soju06

Soju06 commented May 21, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

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

@Soju06 Soju06 added 🤖 codex: ok [@codex review] says no issues found. and removed 🤖 codex: ok [@codex review] says no issues found. labels May 21, 2026
@Soju06

Soju06 commented May 22, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

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

@Komzpa Komzpa removed the 🤖 codex: needs work [@codex review] raised an issue label May 24, 2026
@Soju06

Soju06 commented Jun 1, 2026

Copy link
Copy Markdown
Owner

Hermes owner-review blocker found after the clean Codex/CI pass.

The OpenSpec delta promises that the new normal warmup model is operator-editable from the dashboard settings UI:

  • openspec/changes/add-v1-warmup-endpoint/specs/proxy-warmup/spec.md:65-74 says warmup_model is readable/updatable through the existing settings APIs and dashboard settings UI, and that updates affect subsequent warmup requests.

The implementation only adds schema/payload preservation, not a UI control:

  • frontend/src/features/settings/schemas.ts:16,36 accepts warmupModel.
  • frontend/src/features/settings/payload.ts:14 preserves the current value during unrelated saves.
  • But the settings components only expose the legacy limit warm-up model/prompt fields (frontend/src/features/settings/components/routing-settings.tsx:30-52,172-216) and there is no dashboard input/save path for settings.warmupModel itself.

So an operator cannot perform the spec-required UI update; changing the normal /v1/warmup model currently requires API/direct backend access. Please either add the dashboard UI + tests for editing warmupModel, or narrow the OpenSpec requirement if UI editability is intentionally out of scope.

One adjacent spec/code mismatch to settle while touching this: the delta says each upstream warmup uses the configured warmup_model (spec.md:54-59), but the service replaces it with an API key's enforced_model when present (app/modules/proxy/service.py:2856-2859). If enforced-model precedence is intended, please make that explicit in OpenSpec and add a regression test; otherwise use the configured model with the appropriate access check.

@Soju06 Soju06 added the hermes: needs-followup Hermes left a blocker/comment that needs follow-up observation label Jun 1, 2026
@Komzpa Komzpa removed hermes: needs-followup Hermes left a blocker/comment that needs follow-up observation 🤖 codex: ok [@codex review] says no issues found. labels Jun 1, 2026
@Soju06

Soju06 commented Jun 1, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

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

@Soju06 Soju06 added the 🤖 codex: ok [@codex review] says no issues found. label Jun 1, 2026
@Soju06 Soju06 added the hermes: needs-followup Hermes left a blocker/comment that needs follow-up observation label Jun 2, 2026
@Soju06

Soju06 commented Jun 2, 2026

Copy link
Copy Markdown
Owner

Hermes owner-review blocker on current head f85b62e.

This branch now fixes the earlier dashboard warmupModel UI blocker, but the API-key accounting contract is still internally contradictory.

OpenSpec says warmup must be excluded from API-key usage counters/accounting:

  • openspec/changes/add-v1-warmup-endpoint/specs/api-keys/spec.md:3-24 changes weekly token tracking to non-warmup proxy requests and says warmup rows are excluded from weekly token usage increments.
  • openspec/changes/add-v1-warmup-endpoint/specs/proxy-warmup/spec.md:83-92 says warmup traffic is excluded from API-key usage accounting, including key summaries/trends.
  • openspec/changes/add-v1-warmup-endpoint/proposal.md:15-24 says warmup is excluded from key usage counters and derived summaries.

But successful /v1/warmup still finalizes the API-key usage reservation:

  • app/modules/proxy/service.py:2986-3016 reserves API-key usage, sends the upstream warmup request, then calls _settle_compact_api_key_usage(...) on success.
  • app/modules/proxy/service.py:9581-9621 finalizes successful compact reservations via ApiKeysService.finalize_usage_reservation(...), which leaves the actual token delta in the key limit counters.
  • tests/integration/test_proxy_warmup.py:153-188 locks this in by asserting a warmup request against a total_tokens limit leaves limit.current_value == 2.

That means warmup is not excluded from live API-key usage counters despite the OpenSpec delta. If the intended policy is “warmup checks/reserves key headroom but does not consume post-success quota/accounting,” then the success path needs to release/zero-settle the reservation while preserving preflight enforcement. If the intended policy is “warmup consumes API-key quota,” then the OpenSpec/proposal/tasks need to be narrowed and the aggregate-exclusion wording should stop claiming counter/accounting exclusion.

One adjacent gap in the same area: app/modules/api_keys/repository.py:777-800 (usage_7d_by_account) still lacks _exclude_warmup_clause(), unlike the nearby key summary/trend usage queries, so warmup cost rows can leak into that API-key account-cost aggregate if/when used.

Also please clean up the active OpenSpec artifacts before merge: proposal.md:8-11 and tasks.md:13-14 still advertise default / all-or-none / force-update, while the normative delta and implementation expose normal / strict / force (proxy-warmup/spec.md:31-35, app/modules/proxy/api.py:239, app/modules/proxy/service.py:367).

@Komzpa

Komzpa commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator Author

Folded into #870, which is now rebuilt on main at 640b219487f2946ca25a5124d179c290d7a0fe84.

Current #870 status:

  • CI is green for the current head.
  • The current-head Codex review is clean.
  • The folded proxy-runtime branch now carries this PR's reviewable scope together with the related proxy-runtime repairs.

Closing this PR to keep the remaining merge queue main-based and non-overlapping.

@Komzpa Komzpa closed this Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🤖 codex: ok [@codex review] says no issues found. db migration PR changes Alembic database migrations; maintainer must coordinate merge order hermes: needs-followup Hermes left a blocker/comment that needs follow-up observation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants