t8y2/dbx · error
agent session limit reached: %d
Error message
agent session limit reached: %d
What it means
Returned by runtimeServer.openSession in the kingbase-go driver when the number of open sessions is already at maxAgentSessions. New sessions are refused (after the duplicate-id check) to bound resource usage; existing sessions remain usable.
Source
Thrown at agents/drivers/kingbase-go/main.go:293
session, err := r.session(id)
if err != nil {
return nil, false, err
}
session.mu.Lock()
defer session.mu.Unlock()
return session.server.dispatch(method, params)
}
}
func (r *runtimeServer) openSession(id string, cp connectParams) error {
r.mu.Lock()
if _, exists := r.sessions[id]; exists {
r.mu.Unlock()
return fmt.Errorf("agent session already exists: %s", id)
}
if len(r.sessions) >= maxAgentSessions {
r.mu.Unlock()
return fmt.Errorf("agent session limit reached: %d", maxAgentSessions)
}
r.mu.Unlock()
s := newServer()
if err := s.connect(cp); err != nil {
return err
}
r.mu.Lock()
defer r.mu.Unlock()
if _, exists := r.sessions[id]; exists {
_ = s.disconnect()
return fmt.Errorf("agent session already exists: %s", id)
}
r.sessions[id] = &agentSession{server: s}
return nil
}
func (r *runtimeServer) session(id string) (*agentSession, error) {View on GitHub (pinned to c0390bff16)
Solutions
- Ensure every opened session is closed (defer closeSession) including on error paths
- Raise maxAgentSessions if the workload legitimately needs more concurrent sessions
- Audit for session leaks: log open/close pairs and count active sessions
- Reuse/pool sessions instead of opening one per operation
Example fix
// before: no close on error
s, err := rt.OpenSession(id, cp)
if err != nil { return err }
// after: guarantee cleanup
s, err := rt.OpenSession(id, cp)
if err != nil { return err }
defer rt.CloseSession(id) Defensive patterns
Strategy: retry
Validate before calling
// Go: check current session count against cap before opening
if len(rt.ListSessionIDs()) >= maxAgentSessions {
return fmt.Errorf("at session cap; close sessions before opening more")
} Try / catch
err := rt.OpenSession(id, cp)
if err != nil && strings.Contains(err.Error(), "limit reached") {
rt.CloseOldestIdleSession() // reclaim capacity
err = rt.OpenSession(id, cp)
} Prevention
- defer closeSession on every open
- Pool and reuse sessions instead of one-per-operation
- Monitor active session count; alert before hitting maxAgentSessions
- Size maxAgentSessions to your real concurrency
When it happens
Trigger: Opening more than maxAgentSessions distinct session ids without closing any — e.g. a workload that creates a session per request and never calls close/shutdown.
Common situations: Long-running agents leaking sessions on error paths (connect fails after reservation is skipped, or close is never called); parallel test suites each opening sessions; tight maxAgentSessions configured for large fan-out workloads.
Related errors
- maximum Hive Agent sessions reached (%d)
- agent session already exists: %s
- agent session not found: %s
- unknown method: %s
- list custom types in schema %q: %w
AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05).
Data as JSON: /api/errors/52a25db36bd4a662.
Report an issue: GitHub.