t8y2/dbx · error

agent session already exists: %s

Error message

agent session already exists: %s

What it means

openSession enforces unique session IDs in the runtime server's session map. If a session with the given id already exists, it refuses to create a duplicate and returns this error. This is a protocol-level duplicate-registration guard, not a resource exhaustion problem.

Source

Thrown at agents/drivers/cassandra-go/main.go:242

		if err != nil {
			return nil, false, err
		}
		session.mu.Lock()
		defer session.mu.Unlock()
		release, err := session.server.runtime.acquire(isMetadataOperation(method))
		if err != nil {
			return nil, false, err
		}
		defer release()
		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()

	runtime, key, err := r.acquireRuntime(cp)
	if err != nil {
		return err
	}
	s := newServer(runtime, cp)
	if err := s.validateConnection(); err != nil {
		r.releaseRuntime(key)
		return err
	}

	r.mu.Lock()

View on GitHub (pinned to c0390bff16)

Solutions

  1. Generate a fresh unique session id (UUID) for each connect instead of a fixed one.
  2. Call the session close/disconnect method before reconnecting with the same id.
  3. On receiving this error, treat the existing session as yours and reuse it rather than re-connecting.

Example fix

// before
connect(sessionID: "agent-1") // retried after timeout, session still alive
// after
connect(sessionID: uuid.NewString()) // unique per attempt, or closeSession("agent-1") first
Defensive patterns

Strategy: try-catch

Validate before calling

knownSessionsMu.Lock()
_, alreadyOpen := knownSessions[id]
knownSessionsMu.Unlock()
if alreadyOpen { reuseExisting(id); return nil }

Try / catch

if err != nil && strings.Contains(err.Error(), "agent session already exists") {
    return r.session(id) // reuse the live session instead of failing
}

Prevention

When it happens

Trigger: Calling the 'connect' RPC with a session id that is already registered in r.sessions (double handshake, client retrying connect with the same id after a lost response).

Common situations: Client retry logic reusing the same session id without closing the old session; two workers sharing one agent client both issuing connect with the same id; reconnect logic that skips closeSession after a network drop where the server still holds the session.

Related errors


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