File tree Expand file tree Collapse file tree
web/src/server/free-session Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -827,6 +827,32 @@ describe('getSessionState', () => {
827827 } )
828828 } )
829829
830+ test ( 'active session only fetches quota for its own model' , async ( ) => {
831+ deps . _tick ( new Date ( '2026-04-17T16:00:00Z' ) )
832+ let listRecentAdmitsCalls = 0
833+ const originalListRecentAdmits = deps . listRecentAdmits
834+ deps . listRecentAdmits = async ( params ) => {
835+ listRecentAdmitsCalls ++
836+ return originalListRecentAdmits ( params )
837+ }
838+
839+ await requestSession ( { userId : 'u1' , model : 'moonshotai/kimi-k2.6' , deps } )
840+ const row = deps . rows . get ( 'u1' ) !
841+ row . status = 'active'
842+ row . admitted_at = deps . _now ( )
843+ row . expires_at = new Date ( deps . _now ( ) . getTime ( ) + SESSION_LEN )
844+ listRecentAdmitsCalls = 0
845+
846+ const state = await getSessionState ( {
847+ userId : 'u1' ,
848+ claimedInstanceId : row . active_instance_id ,
849+ deps,
850+ } )
851+
852+ expect ( state . status ) . toBe ( 'active' )
853+ expect ( listRecentAdmitsCalls ) . toBe ( 1 )
854+ } )
855+
830856 test ( 'omitted claimedInstanceId on active session returns active (read-only)' , async ( ) => {
831857 // Polling without an id (e.g. very first GET before POST has resolved)
832858 // must not be classified as superseded — only an explicit mismatch is.
Original file line number Diff line number Diff line change @@ -392,6 +392,11 @@ async function attachRateLimit(
392392 deps : SessionDeps ,
393393) : Promise < SessionStateResponse > {
394394 if ( view . status !== 'queued' && view . status !== 'active' ) return view
395+ if ( view . status === 'active' ) {
396+ const snapshot = await fetchRateLimitSnapshot ( userId , view . model , deps )
397+ return snapshot ? { ...view , rateLimit : snapshot . info } : view
398+ }
399+
395400 const allRateLimitsByModel = await fetchRateLimitSnapshotsByModel (
396401 userId ,
397402 deps ,
You can’t perform that action at this time.
0 commit comments