mirror of
https://github.com/SagerNet/sing-box.git
synced 2026-04-12 18:17:18 +10:00
fix(ocm): send rate limit status immediately on WebSocket connect
Codex CLI ignores x-codex-* headers in the WebSocket upgrade response and only reads rate limits from in-band codex.rate_limits events. Previously, the first synthetic event was gated by firstRealRequest (after warmup), delaying usage display. Now send aggregated status right after subscribing, so the client sees rate limits before the first turn begins.
This commit is contained in:
@@ -570,8 +570,11 @@ func (s *Service) pushWebSocketAggregatedStatus(ctx context.Context, clientConn
|
||||
}
|
||||
defer s.statusObserver.UnSubscribe(subscription)
|
||||
|
||||
var last aggregatedStatus
|
||||
hasLast := false
|
||||
last := s.computeAggregatedUtilization(provider, userConfig)
|
||||
err = writeWebSocketAggregatedStatus(clientConn, clientWriteAccess, last)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
@@ -582,13 +585,6 @@ func (s *Service) pushWebSocketAggregatedStatus(ctx context.Context, clientConn
|
||||
case <-sessionClosed:
|
||||
return
|
||||
case <-firstRealRequest:
|
||||
current := s.computeAggregatedUtilization(provider, userConfig)
|
||||
err = writeWebSocketAggregatedStatus(clientConn, clientWriteAccess, current)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
last = current
|
||||
hasLast = true
|
||||
firstRealRequest = nil
|
||||
case <-subscription:
|
||||
for {
|
||||
@@ -599,9 +595,6 @@ func (s *Service) pushWebSocketAggregatedStatus(ctx context.Context, clientConn
|
||||
}
|
||||
}
|
||||
drained:
|
||||
if !hasLast {
|
||||
continue
|
||||
}
|
||||
current := s.computeAggregatedUtilization(provider, userConfig)
|
||||
if current.equal(last) {
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user