@@ -199,6 +199,42 @@ describe("same-provider OAuth account fallback", () => {
199199 assert . equal ( logger . entries . find ( ( entry ) => entry . meta ?. event === "accounts_exhausted" ) . meta . status , 400 ) ;
200200 } ) ;
201201
202+ it ( "does not lock accounts when a context failure is thrown while preparing a stream" , async ( ) => {
203+ const store = createStore ( tmpConfig ( ) ) ;
204+ store . seed ( {
205+ providers : [
206+ chatgptAccount ( "prov_a" , "token-a" , 100 ) ,
207+ chatgptAccount ( "prov_b" , "token-b" , 200 ) ,
208+ ] ,
209+ } ) ;
210+ const calls = [ ] ;
211+ const router = createRouter ( {
212+ store,
213+ logger : captureLogger ( ) ,
214+ fetchImpl : async ( _url , options ) => {
215+ calls . push ( authToken ( options ) ) ;
216+ throw new Error (
217+ "Your input exceeds the context window of this model. Please adjust your input and try again."
218+ ) ;
219+ } ,
220+ } ) ;
221+
222+ const result = await router . chatCompletions ( {
223+ body : {
224+ model : "chatgpt/gpt-5.4" ,
225+ messages : [ { role : "user" , content : "oversized request" } ] ,
226+ stream : true ,
227+ } ,
228+ } ) ;
229+
230+ assert . equal ( result . ok , false ) ;
231+ assert . equal ( result . status , 400 ) ;
232+ assert . deepEqual ( calls , [ "token-a" , "token-b" ] ) ;
233+ for ( const provider of store . load ( ) . providers ) {
234+ assert . equal ( provider . modelLocks ?. [ "gpt-5.4" ] , undefined ) ;
235+ }
236+ } ) ;
237+
202238 it ( "assigns monotonic oauth aliases and advertises only shared model ids" , ( ) => {
203239 const configPath = tmpConfig ( ) ;
204240 const store = createStore ( configPath ) ;
0 commit comments