🟡 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
🟡 medium - bug
File:
cmd/root/run.go(line 269)Code
Problem
The
session.Storecreated bysession.NewSQLiteSessionStore(sessionDB)is passed toruntime.Newbut is not explicitly closed increateLocalRuntimeAndSession. ThelocalRt(which receivessessStore) is eventually closed bydefer rt.Close()inrunOrExec. Ifrt.Close()does not internally close thesession.Store, this would lead to an unclosed database connection and a resource leak.Suggested Fix
Ensure that the
runtime.Runtimeimplementation'sClose()method explicitly closes thesession.Storeit was initialized with. Alternatively, thesession.Storeshould be closed increateLocalRuntimeAndSession(e.g., using adeferstatement) or the ownership of thesession.Storeshould be clearly defined to ensure proper cleanup. Ifruntime.Newtakes 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