@@ -192,25 +192,26 @@ export const makeManagedServerProvider = Effect.fn("makeManagedServerProvider")(
192192 const applySnapshot = ( nextSettings : Settings , options ?: { readonly forceRefresh ?: boolean } ) =>
193193 refreshSemaphore . withPermits ( 1 ) ( applySnapshotBase ( nextSettings , options ) ) ;
194194
195- const applyUsageLimits : ManagedServerProvider [ "applyUsageLimits" ] = Effect . fn (
196- "managedProvider.applyUsageLimits" ,
197- ) ( function * ( update ) {
198- const snapshotToPublish = yield * Ref . modify ( snapshotStateRef , ( state ) => {
199- const usageLimits = applyUsageLimitsUpdate ( {
200- previous : state . snapshot . usageLimits ,
201- update,
202- checkedAt : update . checkedAt ,
195+ // Providers call this on every token-usage tick, usually without changing the snapshot.
196+ const applyUsageLimits : ManagedServerProvider [ "applyUsageLimits" ] = Effect . fnUntraced (
197+ function * ( update ) {
198+ const snapshotToPublish = yield * Ref . modify ( snapshotStateRef , ( state ) => {
199+ const usageLimits = applyUsageLimitsUpdate ( {
200+ previous : state . snapshot . usageLimits ,
201+ update,
202+ checkedAt : update . checkedAt ,
203+ } ) ;
204+ if ( usageLimits === state . snapshot . usageLimits ) {
205+ return [ null , state ] as const ;
206+ }
207+ const snapshot = withUsageLimits ( state . snapshot , usageLimits ) ;
208+ return [ snapshot , { ...state , snapshot } ] as const ;
203209 } ) ;
204- if ( usageLimits === state . snapshot . usageLimits ) {
205- return [ null , state ] as const ;
210+ if ( snapshotToPublish !== null ) {
211+ yield * PubSub . publish ( changesPubSub , snapshotToPublish ) ;
206212 }
207- const snapshot = withUsageLimits ( state . snapshot , usageLimits ) ;
208- return [ snapshot , { ...state , snapshot } ] as const ;
209- } ) ;
210- if ( snapshotToPublish !== null ) {
211- yield * PubSub . publish ( changesPubSub , snapshotToPublish ) ;
212- }
213- } ) ;
213+ } ,
214+ ) ;
214215
215216 const refreshSnapshot = Effect . fn ( "refreshSnapshot" ) ( function * ( ) {
216217 const nextSettings = yield * input . getSettings ;
0 commit comments