Skip to content

Commit 27092ae

Browse files
committed
chore: update comments
1 parent baeeaa7 commit 27092ae

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

internal/services/toolkit/client/completion_v2.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@ func (a *AIClientV2) ChatCompletionStreamV2(ctx context.Context, callbackStream
9898
chunk := stream.Current()
9999

100100
if len(chunk.Choices) == 0 {
101+
// Handle usage information
101102
if chunk.Usage.TotalTokens > 0 {
102-
// Record usage and log stats asynchronously to avoid blocking the response
103+
// Record usage asynchronously to avoid blocking the response
103104
go func(usage services.UsageRecord) {
104105
bgCtx := context.Background()
105106
if err := a.usageService.RecordUsage(bgCtx, usage); err != nil {

internal/services/usage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func NewUsageService(db *db.DB, cfg *cfg.Cfg, logger *logger.Logger) *UsageServi
4545
}
4646

4747
// RecordUsage updates the active session or creates a new one if none exists.
48-
// Uses retry logic to handle race conditions when multiple requests try to create a session.
48+
// Falls back to update if insert fails (handles race when another request created a session).
4949
func (s *UsageService) RecordUsage(ctx context.Context, record UsageRecord) error {
5050
now := time.Now()
5151
nowBson := bson.DateTime(now.UnixMilli())

0 commit comments

Comments
 (0)