@@ -23,6 +23,7 @@ type AccountRepoSuite struct {
2323
2424type schedulerCacheRecorder struct {
2525 setAccounts []* service.Account
26+ accounts map [int64 ]* service.Account
2627}
2728
2829func (s * schedulerCacheRecorder ) GetSnapshot (ctx context.Context , bucket service.SchedulerBucket ) ([]* service.Account , bool , error ) {
@@ -34,11 +35,20 @@ func (s *schedulerCacheRecorder) SetSnapshot(ctx context.Context, bucket service
3435}
3536
3637func (s * schedulerCacheRecorder ) GetAccount (ctx context.Context , accountID int64 ) (* service.Account , error ) {
37- return nil , nil
38+ if s .accounts == nil {
39+ return nil , nil
40+ }
41+ return s .accounts [accountID ], nil
3842}
3943
4044func (s * schedulerCacheRecorder ) SetAccount (ctx context.Context , account * service.Account ) error {
4145 s .setAccounts = append (s .setAccounts , account )
46+ if s .accounts == nil {
47+ s .accounts = make (map [int64 ]* service.Account )
48+ }
49+ if account != nil {
50+ s .accounts [account .ID ] = account
51+ }
4252 return nil
4353}
4454
@@ -623,6 +633,64 @@ func (s *AccountRepoSuite) TestUpdateExtra_NilExtra() {
623633 s .Require ().Equal ("val" , got .Extra ["key" ])
624634}
625635
636+ func (s * AccountRepoSuite ) TestUpdateExtra_SchedulerNeutralSkipsOutboxAndPatchesCache () {
637+ account := mustCreateAccount (s .T (), s .client , & service.Account {
638+ Name : "acc-extra-neutral" ,
639+ Platform : service .PlatformOpenAI ,
640+ Extra : map [string ]any {"codex_usage_updated_at" : "old" },
641+ })
642+ cacheRecorder := & schedulerCacheRecorder {
643+ accounts : map [int64 ]* service.Account {
644+ account .ID : {
645+ ID : account .ID ,
646+ Platform : account .Platform ,
647+ Extra : map [string ]any {
648+ "codex_usage_updated_at" : "old" ,
649+ },
650+ },
651+ },
652+ }
653+ s .repo .schedulerCache = cacheRecorder
654+
655+ updates := map [string ]any {
656+ "codex_usage_updated_at" : "2026-03-11T10:00:00Z" ,
657+ "codex_5h_used_percent" : 88.5 ,
658+ "session_window_utilization" : 0.42 ,
659+ }
660+ s .Require ().NoError (s .repo .UpdateExtra (s .ctx , account .ID , updates ))
661+
662+ got , err := s .repo .GetByID (s .ctx , account .ID )
663+ s .Require ().NoError (err )
664+ s .Require ().Equal ("2026-03-11T10:00:00Z" , got .Extra ["codex_usage_updated_at" ])
665+ s .Require ().Equal (88.5 , got .Extra ["codex_5h_used_percent" ])
666+ s .Require ().Equal (0.42 , got .Extra ["session_window_utilization" ])
667+
668+ var outboxCount int
669+ s .Require ().NoError (scanSingleRow (s .ctx , s .repo .sql , "SELECT COUNT(*) FROM scheduler_outbox" , nil , & outboxCount ))
670+ s .Require ().Zero (outboxCount )
671+ s .Require ().Len (cacheRecorder .setAccounts , 1 )
672+ s .Require ().NotNil (cacheRecorder .accounts [account .ID ])
673+ s .Require ().Equal ("2026-03-11T10:00:00Z" , cacheRecorder .accounts [account .ID ].Extra ["codex_usage_updated_at" ])
674+ }
675+
676+ func (s * AccountRepoSuite ) TestUpdateExtra_SchedulerRelevantStillEnqueuesOutbox () {
677+ account := mustCreateAccount (s .T (), s .client , & service.Account {
678+ Name : "acc-extra-mixed" ,
679+ Platform : service .PlatformAntigravity ,
680+ Extra : map [string ]any {},
681+ })
682+
683+ updates := map [string ]any {
684+ "mixed_scheduling" : true ,
685+ "codex_usage_updated_at" : "2026-03-11T10:00:00Z" ,
686+ }
687+ s .Require ().NoError (s .repo .UpdateExtra (s .ctx , account .ID , updates ))
688+
689+ var outboxCount int
690+ s .Require ().NoError (scanSingleRow (s .ctx , s .repo .sql , "SELECT COUNT(*) FROM scheduler_outbox" , nil , & outboxCount ))
691+ s .Require ().Equal (1 , outboxCount )
692+ }
693+
626694// --- GetByCRSAccountID ---
627695
628696func (s * AccountRepoSuite ) TestGetByCRSAccountID () {
0 commit comments