t8y2/dbx · error

Hive Agent session already exists: %s

Error message

Hive Agent session already exists: %s

What it means

openSession rejects an ID that is already present in the sessions map, checked under the lock before any server is created. A session ID must be unique; re-registering the same ID without closing the previous session is refused. This is the fast pre-creation duplicate check.

Source

Thrown at agents/drivers/argo-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. Close the existing session (close_session with the same agentSessionId) before reopening.
  2. Use a unique agentSessionId per logical client.
  3. Treat the error as idempotent: if the existing session is healthy, reuse it (validate_session) instead of reopening.
  4. Serialize session setup in the client to avoid duplicate concurrent open_session calls.

Example fix

// before
openSession("agent-1", params) // fails if exists
// after
closeSession("agent-1")
openSession("agent-1", params)
Defensive patterns

Strategy: validation

Validate before calling

// preflight: skip open if the session already exists locally
if openedSessions[id] {
    return nil // session already established; reuse it
}

Try / catch

err := rpc("open_session", map[string]any{"agentSessionId": id, ...})
if err != nil && strings.Contains(err.Error(), "session already exists") {
    // idempotent path: verify and reuse the existing session
    return rpc("validate_session", map[string]any{"agentSessionId": id})
}

Prevention

When it happens

Trigger: dispatch of open_session (or connect after clearing the legacy ID) with an agentSessionId that already maps to a live session — e.g. a client retries open_session without close_session, or two workers share the same ID.

Common situations: Client retry logic re-sending open_session after a slow first attempt; multiple processes using the same hardcoded agentSessionId; connect flow racing when legacyAgentSessionID was not yet closed.

Related errors


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