@@ -778,66 +778,18 @@ def get_or_create_session(
778778 def update_session (
779779 self ,
780780 session_key : str ,
781- input_tokens : int = 0 ,
782- output_tokens : int = 0 ,
783- cache_read_tokens : int = 0 ,
784- cache_write_tokens : int = 0 ,
785781 last_prompt_tokens : int = None ,
786- model : str = None ,
787- estimated_cost_usd : Optional [float ] = None ,
788- cost_status : Optional [str ] = None ,
789- cost_source : Optional [str ] = None ,
790- provider : Optional [str ] = None ,
791- base_url : Optional [str ] = None ,
792782 ) -> None :
793- """Update a session's metadata after an interaction."""
794- db_session_id = None
795-
783+ """Update lightweight session metadata after an interaction."""
796784 with self ._lock :
797785 self ._ensure_loaded_locked ()
798786
799787 if session_key in self ._entries :
800788 entry = self ._entries [session_key ]
801789 entry .updated_at = _now ()
802- # Direct assignment — the gateway receives cumulative totals
803- # from the cached agent, not per-call deltas.
804- entry .input_tokens = input_tokens
805- entry .output_tokens = output_tokens
806- entry .cache_read_tokens = cache_read_tokens
807- entry .cache_write_tokens = cache_write_tokens
808790 if last_prompt_tokens is not None :
809791 entry .last_prompt_tokens = last_prompt_tokens
810- if estimated_cost_usd is not None :
811- entry .estimated_cost_usd = estimated_cost_usd
812- if cost_status :
813- entry .cost_status = cost_status
814- entry .total_tokens = (
815- entry .input_tokens
816- + entry .output_tokens
817- + entry .cache_read_tokens
818- + entry .cache_write_tokens
819- )
820792 self ._save ()
821- db_session_id = entry .session_id
822-
823- if self ._db and db_session_id :
824- try :
825- self ._db .set_token_counts (
826- db_session_id ,
827- input_tokens = input_tokens ,
828- output_tokens = output_tokens ,
829- cache_read_tokens = cache_read_tokens ,
830- cache_write_tokens = cache_write_tokens ,
831- estimated_cost_usd = estimated_cost_usd ,
832- cost_status = cost_status ,
833- cost_source = cost_source ,
834- billing_provider = provider ,
835- billing_base_url = base_url ,
836- model = model ,
837- absolute = True ,
838- )
839- except Exception as e :
840- logger .debug ("Session DB operation failed: %s" , e )
841793
842794 def reset_session (self , session_key : str ) -> Optional [SessionEntry ]:
843795 """Force reset a session, creating a new session ID."""
0 commit comments