Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion open-sse/handlers/chatCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2104,7 +2104,7 @@ export async function handleChatCore({
model,
requestedModel,
provider,
connectionId,
connectionId: connectionId || credentials?.connectionId || undefined,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While adding a fallback for connectionId in saveCallLog is helpful, applying this fallback locally only fixes call logging. Many other critical systems in handleChatCore rely on connectionId and will still receive undefined if the parameter is not provided. These include:

  1. Usage Persistence: persistFailureUsage (line 1702) and saveRequestUsage (line 5200)
  2. Quota Tracking: persistCodexQuotaState (lines 1771, 1825, 1830) which updates the provider connection in the database
  3. Request Logging & Pending Tracking: trackPendingRequest and appendRequestLog calls throughout the handler

If connectionId is undefined, updateProviderConnection(connectionId, ...) will be called with undefined, failing to persist the quota state.

Recommendation:
Resolve the fallback once at the very beginning of handleChatCore by reassigning the parameter:

connectionId = connectionId || credentials?.connectionId || undefined;

This ensures that all downstream logging, tracking, and database persistence systems automatically and consistently benefit from the fallback.

duration: Date.now() - startTime,
tokens: tokens || {},
requestBody: cloneBoundedChatLogPayload(
Expand Down