@@ -40,12 +40,18 @@ func (e *failOnceStreamExecutor) ExecuteStream(context.Context, *coreauth.Auth,
4040 },
4141 }
4242 close (ch )
43- return & coreexecutor.StreamResult {Chunks : ch }, nil
43+ return & coreexecutor.StreamResult {
44+ Headers : http.Header {"X-Upstream-Attempt" : {"1" }},
45+ Chunks : ch ,
46+ }, nil
4447 }
4548
4649 ch <- coreexecutor.StreamChunk {Payload : []byte ("ok" )}
4750 close (ch )
48- return & coreexecutor.StreamResult {Chunks : ch }, nil
51+ return & coreexecutor.StreamResult {
52+ Headers : http.Header {"X-Upstream-Attempt" : {"2" }},
53+ Chunks : ch ,
54+ }, nil
4955}
5056
5157func (e * failOnceStreamExecutor ) Refresh (ctx context.Context , auth * coreauth.Auth ) (* coreauth.Auth , error ) {
@@ -134,7 +140,7 @@ func (e *authAwareStreamExecutor) Execute(context.Context, *coreauth.Auth, coree
134140 return coreexecutor.Response {}, & coreauth.Error {Code : "not_implemented" , Message : "Execute not implemented" }
135141}
136142
137- func (e * authAwareStreamExecutor ) ExecuteStream (ctx context.Context , auth * coreauth.Auth , req coreexecutor.Request , opts coreexecutor.Options ) (<- chan coreexecutor.StreamChunk , error ) {
143+ func (e * authAwareStreamExecutor ) ExecuteStream (ctx context.Context , auth * coreauth.Auth , req coreexecutor.Request , opts coreexecutor.Options ) (* coreexecutor.StreamResult , error ) {
138144 _ = ctx
139145 _ = req
140146 _ = opts
@@ -160,12 +166,12 @@ func (e *authAwareStreamExecutor) ExecuteStream(ctx context.Context, auth *corea
160166 },
161167 }
162168 close (ch )
163- return ch , nil
169+ return & coreexecutor. StreamResult { Chunks : ch } , nil
164170 }
165171
166172 ch <- coreexecutor.StreamChunk {Payload : []byte ("ok" )}
167173 close (ch )
168- return ch , nil
174+ return & coreexecutor. StreamResult { Chunks : ch } , nil
169175}
170176
171177func (e * authAwareStreamExecutor ) Refresh (ctx context.Context , auth * coreauth.Auth ) (* coreauth.Auth , error ) {
@@ -235,7 +241,7 @@ func TestExecuteStreamWithAuthManager_RetriesBeforeFirstByte(t *testing.T) {
235241 BootstrapRetries : 1 ,
236242 },
237243 }, manager )
238- dataChan , _ , errChan := handler .ExecuteStreamWithAuthManager (context .Background (), "openai" , "test-model" , []byte (`{"model":"test-model"}` ), "" )
244+ dataChan , upstreamHeaders , errChan := handler .ExecuteStreamWithAuthManager (context .Background (), "openai" , "test-model" , []byte (`{"model":"test-model"}` ), "" )
239245 if dataChan == nil || errChan == nil {
240246 t .Fatalf ("expected non-nil channels" )
241247 }
@@ -257,6 +263,10 @@ func TestExecuteStreamWithAuthManager_RetriesBeforeFirstByte(t *testing.T) {
257263 if executor .Calls () != 2 {
258264 t .Fatalf ("expected 2 stream attempts, got %d" , executor .Calls ())
259265 }
266+ upstreamAttemptHeader := upstreamHeaders .Get ("X-Upstream-Attempt" )
267+ if upstreamAttemptHeader != "2" {
268+ t .Fatalf ("expected upstream header from retry attempt, got %q" , upstreamAttemptHeader )
269+ }
260270}
261271
262272func TestExecuteStreamWithAuthManager_DoesNotRetryAfterFirstByte (t * testing.T ) {
@@ -367,7 +377,7 @@ func TestExecuteStreamWithAuthManager_PinnedAuthKeepsSameUpstream(t *testing.T)
367377 },
368378 }, manager )
369379 ctx := WithPinnedAuthID (context .Background (), "auth1" )
370- dataChan , errChan := handler .ExecuteStreamWithAuthManager (ctx , "openai" , "test-model" , []byte (`{"model":"test-model"}` ), "" )
380+ dataChan , _ , errChan := handler .ExecuteStreamWithAuthManager (ctx , "openai" , "test-model" , []byte (`{"model":"test-model"}` ), "" )
371381 if dataChan == nil || errChan == nil {
372382 t .Fatalf ("expected non-nil channels" )
373383 }
@@ -431,7 +441,7 @@ func TestExecuteStreamWithAuthManager_SelectedAuthCallbackReceivesAuthID(t *test
431441 ctx := WithSelectedAuthIDCallback (context .Background (), func (authID string ) {
432442 selectedAuthID = authID
433443 })
434- dataChan , errChan := handler .ExecuteStreamWithAuthManager (ctx , "openai" , "test-model" , []byte (`{"model":"test-model"}` ), "" )
444+ dataChan , _ , errChan := handler .ExecuteStreamWithAuthManager (ctx , "openai" , "test-model" , []byte (`{"model":"test-model"}` ), "" )
435445 if dataChan == nil || errChan == nil {
436446 t .Fatalf ("expected non-nil channels" )
437447 }
0 commit comments