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:
世界
2026-03-26 12:33:53 +08:00
parent 4592164a7a
commit 6721dff48a

View File

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