@@ -12,6 +12,7 @@ import (
1212
1313 "cdr.dev/slog/v3"
1414 "github.com/coder/aibridge/circuitbreaker"
15+ "github.com/google/uuid"
1516 aibcontext "github.com/coder/aibridge/context"
1617 "github.com/coder/aibridge/mcp"
1718 "github.com/coder/aibridge/metrics"
@@ -177,19 +178,26 @@ func newInterceptionProcessor(p provider.Provider, cbs *circuitbreaker.ProviderC
177178 // to the correct user rather than the service-level identity.
178179 if client == ClientCoderAgents {
179180 if ownerID := r .Header .Get ("X-Coder-Owner-Id" ); ownerID != "" {
180- existingActor := aibcontext .ActorFromContext (ctx )
181- var md recorder.Metadata
182- var previousActorID string
183- if existingActor != nil {
184- md = existingActor .Metadata
185- previousActorID = existingActor .ID
181+ if _ , err := uuid .Parse (ownerID ); err != nil {
182+ logger .Warn (ctx , "ignoring invalid X-Coder-Owner-Id, expected UUID" ,
183+ slog .F ("value" , ownerID ),
184+ slog .Error (err ),
185+ )
186+ } else {
187+ existingActor := aibcontext .ActorFromContext (ctx )
188+ var md recorder.Metadata
189+ var previousActorID string
190+ if existingActor != nil {
191+ md = existingActor .Metadata
192+ previousActorID = existingActor .ID
193+ }
194+ logger .Debug (ctx , "overriding initiator with X-Coder-Owner-Id" ,
195+ slog .F ("previous_actor_id" , previousActorID ),
196+ slog .F ("new_actor_id" , ownerID ),
197+ )
198+ ctx = aibcontext .AsActor (ctx , ownerID , md )
199+ r = r .WithContext (ctx )
186200 }
187- logger .Debug (ctx , "overriding initiator with X-Coder-Owner-Id" ,
188- slog .F ("previous_actor_id" , previousActorID ),
189- slog .F ("new_actor_id" , ownerID ),
190- )
191- ctx = aibcontext .AsActor (ctx , ownerID , md )
192- r = r .WithContext (ctx )
193201 }
194202 }
195203
0 commit comments