@@ -39,6 +39,7 @@ const state = vi.hoisted(() => ({
3939 enqueue : vi . fn ( async ( ) => undefined ) ,
4040 freshPending : false ,
4141 compactModel : null as string | null ,
42+ compactDueAt : "" ,
4243 setFreshPending : vi . fn ( ) ,
4344 clearDraft : vi . fn ( ) ,
4445 approve : vi . fn ( ) ,
@@ -79,8 +80,10 @@ vi.mock("react", () => ({
7980vi . mock ( "expo-crypto" , ( ) => ( { randomUUID : ( ) => "uuid" } ) ) ;
8081vi . mock ( "@t3tools/client-runtime/state/context-window" , async ( importOriginal ) => ( {
8182 ...( await importOriginal < typeof import ( "@t3tools/client-runtime/state/context-window" ) > ( ) ) ,
82- compactBeforeSendTokens : ( input : { readonly selection : ModelSelection } ) =>
83- input . selection . model === state . compactModel ? 248_000 : null ,
83+ compactBeforeSendTokens : ( input : { readonly selection : ModelSelection ; readonly now : string } ) =>
84+ input . selection . model === state . compactModel && input . now >= state . compactDueAt
85+ ? 248_000
86+ : null ,
8487} ) ) ;
8588vi . mock ( "../lib/clock" , ( ) => ( { useNowMinuteMs : ( ) => 0 } ) ) ;
8689vi . mock ( "../lib/attachmentUpload" , ( ) => ( { prepareTurnAttachments : vi . fn ( ) } ) ) ;
@@ -206,6 +209,7 @@ beforeEach(() => {
206209 } ;
207210 state . freshPending = false ;
208211 state . compactModel = null ;
212+ state . compactDueAt = "" ;
209213 state . thread . latestRun = null ;
210214 state . projection = null ;
211215 state . serverConfig = {
@@ -316,29 +320,32 @@ describe("mobile task permissions", () => {
316320 visibleTurnItems : [ ] ,
317321 updatedAt : DateTime . makeUnsafe ( 0 ) ,
318322 } as unknown as OrchestrationV2ThreadProjection ;
319- const due : ModelSelection = { instanceId : ProviderInstanceId . make ( "codex" ) , model : "gpt-5.5" } ;
320- state . compactModel = due . model ;
323+ state . compactModel = "gpt-5.4" ;
324+ // The notice's minute clock (the epoch here) trails a deadline the send's exact time has passed.
325+ state . compactDueAt = "2026-01-01T00:00:00.000Z" ;
321326 const unannounced = useThreadComposerState ( NO_SIDE_CHATS ) ;
322327 expect ( unannounced . compactBeforeSend ) . toBeNull ( ) ;
323- // Due at send time but not at the last render, as when the minute clock trails the deadline.
324- state . draft = { ...state . draft , modelSelection : due } ;
325328 await unannounced . onSendMessage ( ) ;
326329 expect ( state . enqueue ) . toHaveBeenLastCalledWith (
327330 expect . not . objectContaining ( { compactBeforeSend : true } ) ,
328331 ) ;
332+ state . compactDueAt = "" ;
329333 const composer = useThreadComposerState ( NO_SIDE_CHATS ) ;
330334 expect ( composer . compactBeforeSend ?. tokens ) . toBe ( 248_000 ) ;
331335 await composer . onSendMessage ( ) ;
332336 expect ( state . enqueue ) . toHaveBeenLastCalledWith (
333337 expect . objectContaining ( { compactBeforeSend : true } ) ,
334338 ) ;
335339 // A model picked after the last render still decides the send.
336- state . draft = { ...state . draft , modelSelection : undefined } ;
340+ state . draft = {
341+ ...state . draft ,
342+ modelSelection : { instanceId : ProviderInstanceId . make ( "codex" ) , model : "gpt-5.5" } ,
343+ } ;
337344 await composer . onSendMessage ( ) ;
338345 expect ( state . enqueue ) . toHaveBeenLastCalledWith (
339346 expect . not . objectContaining ( { compactBeforeSend : true } ) ,
340347 ) ;
341- state . draft = { ...state . draft , modelSelection : due } ;
348+ state . draft = { ...state . draft , modelSelection : undefined } ;
342349 composer . compactBeforeSend ?. keepFullHistory ( ) ;
343350 const kept = useThreadComposerState ( NO_SIDE_CHATS ) ;
344351 expect ( kept . compactBeforeSend ) . toBeNull ( ) ;
0 commit comments