@@ -25,6 +25,50 @@ pub fn system_time_to_rfc3339(time: SystemTime) -> String {
2525 offset_datetime. format ( & Rfc3339 ) . unwrap_or_else ( |_| "1970-01-01T00:00:00Z" . to_string ( ) )
2626}
2727
28+ fn normalize_optional_name ( name : Option < String > ) -> Option < String > {
29+ name. and_then ( |name| {
30+ let trimmed = name. trim ( ) ;
31+ ( !trimmed. is_empty ( ) ) . then ( || trimmed. to_string ( ) )
32+ } )
33+ }
34+
35+ fn fnv1a_64 ( input : & str ) -> u64 {
36+ const FNV_OFFSET_BASIS : u64 = 0xcbf2_9ce4_8422_2325 ;
37+ const FNV_PRIME : u64 = 0x0100_0000_01b3 ;
38+
39+ let mut hash = FNV_OFFSET_BASIS ;
40+ for byte in input. as_bytes ( ) {
41+ hash ^= u64:: from ( * byte) ;
42+ hash = hash. wrapping_mul ( FNV_PRIME ) ;
43+ }
44+ hash
45+ }
46+
47+ fn generate_session_name ( session_id : & str ) -> String {
48+ // Deterministic "docker-style" name derived from the session id.
49+ // This keeps names consistent across clients without requiring additional storage or APIs.
50+ const ADJECTIVES : & [ & str ] = & [
51+ "ancient" , "brave" , "calm" , "clever" , "dapper" , "eager" , "fancy" , "gentle" , "happy" ,
52+ "jolly" , "kind" , "lively" , "mighty" , "noble" , "proud" , "quick" , "quiet" , "shiny" , "silly" ,
53+ "swift" , "wise" ,
54+ ] ;
55+
56+ const NOUNS : & [ & str ] = & [
57+ "antelope" , "badger" , "beaver" , "bison" , "cougar" , "dolphin" , "dragon" , "eagle" , "falcon" ,
58+ "fox" , "gecko" , "heron" , "ibis" , "koala" , "lemur" , "lynx" , "otter" , "panther" , "puma" ,
59+ "raven" , "tiger" , "yak" ,
60+ ] ;
61+
62+ let hash = fnv1a_64 ( session_id) ;
63+ let adjective_idx = usize:: try_from ( hash % ADJECTIVES . len ( ) as u64 ) . unwrap_or ( 0 ) ;
64+ let noun_idx = usize:: try_from ( ( hash >> 8 ) % NOUNS . len ( ) as u64 ) . unwrap_or ( 0 ) ;
65+ let adjective = ADJECTIVES [ adjective_idx] ;
66+ let noun = NOUNS [ noun_idx] ;
67+ let suffix = ( hash >> 16 ) & 0xffff ;
68+
69+ format ! ( "{adjective}-{noun}-{suffix:04x}" )
70+ }
71+
2872fn timestamp_us_to_rfc3339 ( timestamp_us : u64 ) -> String {
2973 system_time_to_rfc3339 ( UNIX_EPOCH + Duration :: from_micros ( timestamp_us) )
3074}
@@ -134,6 +178,8 @@ impl Session {
134178 created_by : Option < String > ,
135179 ) -> Result < Self , String > {
136180 let session_id = Uuid :: new_v4 ( ) . to_string ( ) ;
181+ let name =
182+ normalize_optional_name ( name) . or_else ( || Some ( generate_session_name ( & session_id) ) ) ;
137183 let display_name = name. as_deref ( ) . unwrap_or ( & session_id) ;
138184 tracing:: info!( session_id = %session_id, name = %display_name, "Creating new dynamic session" ) ;
139185
0 commit comments