-
Notifications
You must be signed in to change notification settings - Fork 282
Description
🟡 medium - bug
File: cmd/root/run.go (line 269)
Code
sessStore, err := session.NewSQLiteSessionStore(sessionDB)
if err != nil {
return nil, nil, fmt.Errorf("creating session store: %w", err)
}
// Create model switcher config for runtime model switching support
modelSwitcherCfg := &runtime.ModelSwitcherConfig{
Models: loadResult.Models,
Providers: loadResult.Providers,
ModelsGateway: f.runConfig.ModelsGateway,
EnvProvider: f.runConfig.EnvProvider(),
AgentDefaultModels: loadResult.AgentDefaultModels,
}
localRt, err := runtime.New(t,
runtime.WithSessionStore(sessStore),
runtime.WithCurrentAgent(f.agentName),
runtime.WithTracer(otel.Tracer(AppName)),
runtime.WithModelSwitcherConfig(modelSwitcherCfg),
)Problem
The session.Store created by session.NewSQLiteSessionStore(sessionDB) is passed to runtime.New but is not explicitly closed in createLocalRuntimeAndSession. The localRt (which receives sessStore) is eventually closed by defer rt.Close() in runOrExec. If rt.Close() does not internally close the session.Store, this would lead to an unclosed database connection and a resource leak.
Suggested Fix
Ensure that the runtime.Runtime implementation's Close() method explicitly closes the session.Store it was initialized with. Alternatively, the session.Store should be closed in createLocalRuntimeAndSession (e.g., using a defer statement) or the ownership of the session.Store should be clearly defined to ensure proper cleanup. If runtime.New takes ownership and ensures closure, then this is not an issue, but it's not immediately apparent from the current code.
Found by nightly codebase scan