Skip to content

feat: refine gateway routing/config and add postgres schema script#5

Open
Uuq114 wants to merge 5 commits intomainfrom
quota
Open

feat: refine gateway routing/config and add postgres schema script#5
Uuq114 wants to merge 5 commits intomainfrom
quota

Conversation

@Uuq114
Copy link
Copy Markdown
Owner

@Uuq114 Uuq114 commented Apr 4, 2026

No description provided.

@Uuq114
Copy link
Copy Markdown
Owner Author

Uuq114 commented Apr 4, 2026

@codex

Copy link
Copy Markdown

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

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: 23163a8d5a

ℹ️ 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 +123 to +124
if ok {
return ring
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 Rebuild limiter when key RPM changes

updateKeyInfo() refreshes RequestPerMinute from DB, but this helper returns the first ring forever for a key and never compares the new RPM value. If an operator tightens or relaxes a key’s rate limit, the old limit keeps being enforced until process restart, which can either allow excess traffic or incorrectly throttle valid requests.

Useful? React with 👍 / 👎.

Comment on lines +253 to +254
c.Set("skipSpend", true)
return resp.StatusCode, false, nil
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 Record spend for streamed responses

This path unconditionally marks streamed requests with skipSpend, and logSpendMiddleware returns early when that flag is set, so streamed completions never reach CreateSpendRecord/CreateKeySpendRecord. Any client using stream=true can therefore consume tokens without spend logs or balance deduction.

Useful? React with 👍 / 👎.

Comment on lines +283 to +285
if streamFlag, ok := c.Get("isStreamRequest"); ok {
if isStream, ok := streamFlag.(bool); ok && isStream {
return 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 Gate streaming mode on SSE response type

Treating stream=true in the request as sufficient to enter streaming mode means JSON error responses are also handled as streamed. Because this happens before the >=500 retry branch, a transient upstream 5xx on a streamed request will not retry other backends, reducing availability for the most common chat path.

Useful? React with 👍 / 👎.

@Uuq114
Copy link
Copy Markdown
Owner Author

Uuq114 commented Apr 5, 2026

@codex review

Copy link
Copy Markdown

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

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: 56181dd91a

ℹ️ 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 +267 to +268
if streamErr != nil {
return http.StatusBadGateway, true, streamErr
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 Stop retrying once a stream has started

In the streaming branch, streamToClient may already flush SSE bytes before returning an error, but this code returns shouldRetry=true; HandleRequest then retries another upstream and attempts to write a second response on the same gin.Context. When an upstream stream drops mid-response (e.g., broken SSE connection), clients can receive corrupted/duplicated output because headers/body have already been sent and cannot be safely retried.

Useful? React with 👍 / 👎.

ch = make(chan float64, 100)
return
}
spend := c.MustGet("spend").(float64)
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 Guard missing spend context before key spend enqueue

CreateKeySpendRecord unconditionally calls c.MustGet("spend"), but CreateSpendRecord now has multiple early-return paths (invalid/malformed upstream payload, type mismatch, missing model price) that skip setting this key. In those cases the middleware path panics during spend logging, turning an upstream-format/config issue into a 500 for the request.

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