t8y2/dbx · error

agent session already exists: %s

Error message

agent session already exists: %s

What it means

oracle-go's runtimeServer.openSession registers agent sessions by id and rejects a second registration with the same id. The id check runs under r.mu before a runtime is acquired, so a duplicate connect fails fast without consuming runtime resources. Sessions must be closed before their ids can be reused.

Source

Thrown at agents/drivers/oracle-go/main.go:744

}

func (r *runtimeServer) withSession(agentSessionID, method string, params map[string]json.RawMessage) (any, bool, error) {
	session, err := r.session(agentSessionID)
	if err != nil {
		return nil, false, err
	}
	// Oracle connection state, transactions, and cursors are session-scoped;
	// serialize one session while allowing separate sessions to run in parallel.
	session.mu.Lock()
	defer session.mu.Unlock()
	return session.server.dispatch(method, params)
}

func (r *runtimeServer) openSession(agentSessionID string, params connectParams) error {
	r.mu.Lock()
	if _, exists := r.sessions[agentSessionID]; exists {
		r.mu.Unlock()
		return fmt.Errorf("agent session already exists: %s", agentSessionID)
	}
	if len(r.sessions) >= maxAgentSessions {
		r.mu.Unlock()
		return fmt.Errorf("agent session limit reached: %d", maxAgentSessions)
	}
	session := &agentSession{server: newServer()}
	r.sessions[agentSessionID] = session
	r.mu.Unlock()

	// Reserve the id under the registry lock, then connect outside it so unrelated
	// sessions can establish database connections concurrently.
	session.mu.Lock()
	err := session.server.connect(params)
	session.mu.Unlock()
	if err != nil {
		r.mu.Lock()
		if r.sessions[agentSessionID] == session {
			delete(r.sessions, agentSessionID)

View on GitHub (pinned to c0390bff16)

Solutions

  1. Disconnect/close the existing session with the same id, then reconnect
  2. Use unique ids per client (UUID) so collisions cannot happen
  3. Handle the error as 'already connected' and keep using the current session
  4. Restart the agent process if stale sessions can no longer be addressed

Example fix

// before
connect(id) // retried on every network error
// after
if err := connect(id); err != nil && strings.Contains(err.Error(), "already exists") {
    disconnect(id)
    connect(id)
}
Defensive patterns

Strategy: try-catch

Validate before calling

if id in self._open_session_ids:
    raise ValueError(f"session {id} is already open; disconnect first")

Try / catch

try:
    open_session(agent_session_id, params)
except AgentRPCError as e:
    if "agent session already exists" in str(e):
        close_session(agent_session_id)
        open_session(agent_session_id, params)
    else:
        raise

Prevention

When it happens

Trigger: Calling openSession (connect RPC) with an agentSessionID that is already present in r.sessions — a repeat connect from the same client, or two clients configured with the same id.

Common situations: Client auto-reconnect re-sends connect after a timeout without disconnecting first; identical session id hardcoded in multiple worker configs; restart of client code while the agent still holds the old session.

Related errors


AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05). Data as JSON: /api/errors/e4daaedab90fff0c. Report an issue: GitHub.