@@ -13,6 +13,7 @@ import (
1313
1414 "cdr.dev/slog/v3"
1515 "github.com/coder/aibridge/circuitbreaker"
16+ "github.com/google/uuid"
1617 aibcontext "github.com/coder/aibridge/context"
1718 "github.com/coder/aibridge/mcp"
1819 "github.com/coder/aibridge/metrics"
@@ -201,19 +202,26 @@ func newInterceptionProcessor(p provider.Provider, cbs *circuitbreaker.ProviderC
201202 // to the correct user rather than the service-level identity.
202203 if client == ClientCoderAgents {
203204 if ownerID := r .Header .Get ("X-Coder-Owner-Id" ); ownerID != "" {
204- existingActor := aibcontext .ActorFromContext (ctx )
205- var md recorder.Metadata
206- var previousActorID string
207- if existingActor != nil {
208- md = existingActor .Metadata
209- previousActorID = existingActor .ID
205+ if _ , err := uuid .Parse (ownerID ); err != nil {
206+ logger .Warn (ctx , "ignoring invalid X-Coder-Owner-Id, expected UUID" ,
207+ slog .F ("value" , ownerID ),
208+ slog .Error (err ),
209+ )
210+ } else {
211+ existingActor := aibcontext .ActorFromContext (ctx )
212+ var md recorder.Metadata
213+ var previousActorID string
214+ if existingActor != nil {
215+ md = existingActor .Metadata
216+ previousActorID = existingActor .ID
217+ }
218+ logger .Debug (ctx , "overriding initiator with X-Coder-Owner-Id" ,
219+ slog .F ("previous_actor_id" , previousActorID ),
220+ slog .F ("new_actor_id" , ownerID ),
221+ )
222+ ctx = aibcontext .AsActor (ctx , ownerID , md )
223+ r = r .WithContext (ctx )
210224 }
211- logger .Debug (ctx , "overriding initiator with X-Coder-Owner-Id" ,
212- slog .F ("previous_actor_id" , previousActorID ),
213- slog .F ("new_actor_id" , ownerID ),
214- )
215- ctx = aibcontext .AsActor (ctx , ownerID , md )
216- r = r .WithContext (ctx )
217225 }
218226 }
219227
0 commit comments