Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/root/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ func (f *apiFlags) runAPICommand(cmd *cobra.Command, args []string) error {
if err != nil {
return fmt.Errorf("creating session store: %w", err)
}
defer func() {
if err := sessionStore.Close(); err != nil {
slog.Error("Failed to close session store", "error", err)
}
}()

sources, err := config.ResolveSources(agentsPath, f.runConfig.EnvProvider())
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions cmd/root/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ func (f *runExecFlags) runOrExec(ctx context.Context, out *cli.Printer, args []s
if err := loadResult.Team.StopToolSets(cleanupCtx); err != nil {
slog.Error("Failed to stop tool sets", "error", err)
}
if err := rt.Close(); err != nil {
slog.Error("Failed to close runtime", "error", err)
}
}
}
defer cleanup()
Expand Down
1 change: 1 addition & 0 deletions pkg/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func (m *mockRuntime) UpdateSessionTitle(_ context.Context, sess *session.Sessio
return nil
}
func (m *mockRuntime) TitleGenerator() *sessiontitle.Generator { return nil }
func (m *mockRuntime) Close() error { return nil }
func (m *mockRuntime) Stop() {}

// Verify mockRuntime implements runtime.Runtime
Expand Down
1 change: 1 addition & 0 deletions pkg/runtime/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func (m *mockRuntime) UpdateSessionTitle(context.Context, *session.Session, stri
return nil
}
func (m *mockRuntime) TitleGenerator() *sessiontitle.Generator { return nil }
func (m *mockRuntime) Close() error { return nil }

func (m *mockRuntime) RegenerateTitle(context.Context, *session.Session, chan Event) {
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/runtime/remote_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,4 +452,9 @@ func (r *RemoteRuntime) TitleGenerator() *sessiontitle.Generator {
return nil
}

// Close is a no-op for remote runtimes.
func (r *RemoteRuntime) Close() error {
return nil
}

var _ Runtime = (*RemoteRuntime)(nil)
11 changes: 11 additions & 0 deletions pkg/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ type Runtime interface {
// TitleGenerator returns a generator for automatic session titles, or nil
// if the runtime does not support local title generation (e.g. remote runtimes).
TitleGenerator() *sessiontitle.Generator

// Close releases resources held by the runtime (e.g., session store connections).
Close() error
}

// PermissionsInfo contains the allow and deny patterns for tool permissions.
Expand Down Expand Up @@ -671,6 +674,14 @@ func (r *LocalRuntime) SessionStore() session.Store {
return r.sessionStore
}

// Close releases resources held by the runtime, including the session store.
func (r *LocalRuntime) Close() error {
if r.sessionStore != nil {
return r.sessionStore.Close()
}
return nil
}

// UpdateSessionTitle persists the session title via the session store.
func (r *LocalRuntime) UpdateSessionTitle(ctx context.Context, sess *session.Session, title string) error {
sess.Title = title
Expand Down
8 changes: 8 additions & 0 deletions pkg/session/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ type Store interface {

// UpdateSessionTitle updates only the title
UpdateSessionTitle(ctx context.Context, sessionID, title string) error

// Close releases any resources held by the store (e.g., database connections).
Close() error
}

type InMemorySessionStore struct {
Expand Down Expand Up @@ -350,6 +353,11 @@ func (s *InMemorySessionStore) UpdateSessionTitle(_ context.Context, sessionID,
return nil
}

// Close is a no-op for in-memory stores.
func (s *InMemorySessionStore) Close() error {
return nil
}

// NewSQLiteSessionStore creates a new SQLite session store
func NewSQLiteSessionStore(path string) (Store, error) {
store, err := openAndMigrateSQLiteStore(path)
Expand Down