t8y2/dbx · error
agent session already exists: %s
Error message
agent session already exists: %s
What it means
The agent runtime server refuses to open a session whose ID is already registered in r.sessions. This check happens before any connection work, under the runtime mutex, so duplicate openSession calls with the same id fail fast.
Source
Thrown at agents/drivers/kingbase-go/main.go:289
id := stringParam(params, "agentSessionId")
if id == "" {
id = legacyAgentSessionID
}
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}View on GitHub (pinned to c0390bff16)
Solutions
- Use a unique session id for each open request (e.g. UUID)
- Call closeSession/'close' for the existing id before reopening
- Treat the error as a duplicate and reuse the existing session instead of opening a new one
- If the old session is stale, call 'shutdown' or restart the runtime to clear r.sessions
Example fix
// before: fixed id reused every run
id := "main"
if err := rt.OpenSession(id, cp); err != nil { return err }
// after: close-then-open or unique id
if err := rt.CloseSession(id); err != nil { /* ignore not-found */ }
if err := rt.OpenSession(id, cp); err != nil { return err } Defensive patterns
Strategy: try-catch
Validate before calling
// Go: check id availability client-side if the runtime exposes listing
ids := rt.ListSessionIDs() // or track locally
for _, existing := range ids {
if existing == id {
return fmt.Errorf("session %s already open; close it first", id)
}
} Try / catch
err := rt.OpenSession(id, cp)
if err != nil && strings.Contains(err.Error(), "already exists") {
// idempotent: reuse the existing session
return rt.Session(id)
} Prevention
- Generate UUID session ids per open
- Always close sessions, including on error paths
- Track session lifecycle client-side to avoid duplicate opens
When it happens
Trigger: Calling the runtime's session-open method (e.g. 'open' JSON-RPC method) with an id that was previously opened and not yet closed; a client retrying an open request after a timeout while the first session is still alive.
Common situations: Agent orchestrators that reuse fixed session ids across reconnects without closing the old session; concurrent workers racing to open the same session id; stale sessions left open after a crashed client.
Related errors
- agent session not found: %s
- agent session limit reached: %d
- unknown method: %s
- Hive Agent session already exists: %s
- Hive Agent session not found: %s
AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05).
Data as JSON: /api/errors/0534a9607d13feed.
Report an issue: GitHub.