t8y2/dbx · error

Hive Agent session already exists: %s

Error message

Hive Agent session already exists: %s

What it means

Returned by runtimeServer.openSession in the hive-go driver when a session with the requested id is already registered. Session ids must be unique per agent runtime; the guard fires after the max-session check and prevents an openSession call from silently replacing a live session.

Source

Thrown at agents/drivers/hive-go/main.go:247

	}
	session, err := runtimeServer.session(sessionID)
	if err != nil {
		return nil, false, err
	}
	session.mu.Lock()
	defer session.mu.Unlock()
	return session.server.dispatch(method, params)
}

func (runtimeServer *runtimeServer) openSession(id string, params connectParams) error {
	runtimeServer.mu.Lock()
	if len(runtimeServer.sessions) >= maxAgentSessions {
		runtimeServer.mu.Unlock()
		return fmt.Errorf("maximum Hive Agent sessions reached (%d)", maxAgentSessions)
	}
	if _, exists := runtimeServer.sessions[id]; exists {
		runtimeServer.mu.Unlock()
		return fmt.Errorf("Hive Agent session already exists: %s", id)
	}
	runtimeServer.mu.Unlock()

	server, err := newServer(params)
	if err != nil {
		return err
	}
	runtimeServer.mu.Lock()
	defer runtimeServer.mu.Unlock()
	if _, exists := runtimeServer.sessions[id]; exists {
		_ = server.disconnect()
		return fmt.Errorf("Hive Agent session already exists: %s", id)
	}
	if len(runtimeServer.sessions) >= maxAgentSessions {
		_ = server.disconnect()
		return fmt.Errorf("maximum Hive Agent sessions reached (%d)", maxAgentSessions)
	}
	runtimeServer.sessions[id] = &agentSession{server: server}

View on GitHub (pinned to c0390bff16)

Solutions

  1. Generate a unique session id per client connection instead of reusing a constant id.
  2. Close the existing session (closeSession) before re-opening with the same id.
  3. Use replaceSession if the intent is to swap an existing session's connection.
  4. Add client-side handling of this error to treat it as 'already connected' rather than retrying.

Example fix

// before
openSession("agent-1", params) // again after reconnect
// after
id := fmt.Sprintf("agent-%s", uuid.NewString())
openSession(id, params)
Defensive patterns

Strategy: validation

Validate before calling

// Ensure the id is fresh before opening
if existingIDs[id] {
    id = fmt.Sprintf("agent-%s", uuid.NewString())
}
err := rt.openSession(id, params)

Try / catch

if err := rt.openSession(id, params); err != nil {
    if strings.Contains(err.Error(), "already exists") {
        // treat as already connected, or replace intentionally
        session, err = rt.session(id)
    }
    if err != nil { return err }
}

Prevention

When it happens

Trigger: Calling openSession (via dispatch or replaceSession) with an id already present in runtimeServer.sessions — e.g. a client reconnecting with the same session id without closing the old one.

Common situations: Client retry logic re-sending a session-open request after a timeout while the first session is still alive; two processes using the same fixed session id; replaceSession racing with a concurrent open.

Related errors


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