AttachRuntime registers a pre-built runtime + session under sessionID so that subsequent calls (RunSession, Steer, Resume...) reuse it instead of building one from agentFilename. This is what lets a single in-process runtime be shared between the TUI and an HTTP control plane. The internal cancella
(ctx context.Context, sessionID string, rt runtime.Runtime, sess *session.Session)
| 203 | // SSE streams and other lifetime-bound consumers use it (via |
| 204 | // [SessionManager.StreamEvents]) to terminate when the session is detached. |
| 205 | func (sm *SessionManager) AttachRuntime(ctx context.Context, sessionID string, rt runtime.Runtime, sess *session.Session) { |
| 206 | ctx, cancel := context.WithCancel(context.WithoutCancel(ctx)) |
| 207 | sm.runtimeSessions.Store(sessionID, &activeRuntimes{ |
| 208 | runtime: rt, |
| 209 | done: ctx.Done(), |
| 210 | cancel: cancel, |
| 211 | session: sess, |
| 212 | }) |
| 213 | sm.markReady() |
| 214 | } |
| 215 | |
| 216 | // GetSession retrieves a session by ID. |
| 217 | func (sm *SessionManager) GetSession(ctx context.Context, id string) (*session.Session, error) { |