WaitSessionAttached blocks until a runtime is attached for sessionID (i.e. the session is ready to accept follow-ups and produce events), the timeout elapses, or ctx is cancelled. It returns true once the session is attached. Unlike WaitReady, which fires as soon as *any* session is ready, this is
(ctx context.Context, sessionID string, timeout time.Duration)
| 230 | // session-scoped: a client that launched a specific run can wait for exactly |
| 231 | // that session instead of racing the server's startup. |
| 232 | func (sm *SessionManager) WaitSessionAttached(ctx context.Context, sessionID string, timeout time.Duration) bool { |
| 233 | if _, ok := sm.runtimeSessions.Load(sessionID); ok { |
| 234 | return true |
| 235 | } |
| 236 | |
| 237 | ctx, cancel := context.WithTimeout(ctx, timeout) |
| 238 | defer cancel() |
| 239 | |
| 240 | ticker := time.NewTicker(20 * time.Millisecond) |
| 241 | defer ticker.Stop() |
| 242 | for { |
| 243 | select { |
| 244 | case <-ctx.Done(): |
| 245 | _, ok := sm.runtimeSessions.Load(sessionID) |
| 246 | return ok |
| 247 | case <-ticker.C: |
| 248 | if _, ok := sm.runtimeSessions.Load(sessionID); ok { |
| 249 | return true |
| 250 | } |
| 251 | } |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | // GetSessionStatus returns a lightweight snapshot of the session's current |
| 256 | // runtime state. Designed for late-joining SSE consumers that need to know |
no test coverage detected