{"record":{"id":"23b463dd71f11127","repo":"t8y2/dbx","slug":"hive-agent-session-already-exists-s","errorCode":null,"errorMessage":"Hive Agent session already exists: %s","messagePattern":"Hive Agent session already exists: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/argo-go/main.go","lineNumber":247,"sourceCode":"\t}\n\tsession, err := runtimeServer.session(sessionID)\n\tif err != nil {\n\t\treturn nil, false, err\n\t}\n\tsession.mu.Lock()\n\tdefer session.mu.Unlock()\n\treturn session.server.dispatch(method, params)\n}\n\nfunc (runtimeServer *runtimeServer) openSession(id string, params connectParams) error {\n\truntimeServer.mu.Lock()\n\tif len(runtimeServer.sessions) >= maxAgentSessions {\n\t\truntimeServer.mu.Unlock()\n\t\treturn fmt.Errorf(\"maximum Hive Agent sessions reached (%d)\", maxAgentSessions)\n\t}\n\tif _, exists := runtimeServer.sessions[id]; exists {\n\t\truntimeServer.mu.Unlock()\n\t\treturn fmt.Errorf(\"Hive Agent session already exists: %s\", id)\n\t}\n\truntimeServer.mu.Unlock()\n\n\tserver, err := newServer(params)\n\tif err != nil {\n\t\treturn err\n\t}\n\truntimeServer.mu.Lock()\n\tdefer runtimeServer.mu.Unlock()\n\tif _, exists := runtimeServer.sessions[id]; exists {\n\t\t_ = server.disconnect()\n\t\treturn fmt.Errorf(\"Hive Agent session already exists: %s\", id)\n\t}\n\tif len(runtimeServer.sessions) >= maxAgentSessions {\n\t\t_ = server.disconnect()\n\t\treturn fmt.Errorf(\"maximum Hive Agent sessions reached (%d)\", maxAgentSessions)\n\t}\n\truntimeServer.sessions[id] = &agentSession{server: server}","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/argo-go/main.go#L229-L265","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Close the existing session (close_session with the same agentSessionId) before reopening.","Use a unique agentSessionId per logical client.","Treat the error as idempotent: if the existing session is healthy, reuse it (validate_session) instead of reopening.","Serialize session setup in the client to avoid duplicate concurrent open_session calls."],"exampleFix":"// before\nopenSession(\"agent-1\", params) // fails if exists\n// after\ncloseSession(\"agent-1\")\nopenSession(\"agent-1\", params)","handlingStrategy":"validation","validationCode":"// preflight: skip open if the session already exists locally\nif openedSessions[id] {\n    return nil // session already established; reuse it\n}","typeGuard":null,"tryCatchPattern":"err := rpc(\"open_session\", map[string]any{\"agentSessionId\": id, ...})\nif err != nil && strings.Contains(err.Error(), \"session already exists\") {\n    // idempotent path: verify and reuse the existing session\n    return rpc(\"validate_session\", map[string]any{\"agentSessionId\": id})\n}","preventionTips":["Generate a unique agentSessionId per client instance (UUID).","Make open_session idempotent client-side: on 'already exists', validate_session and continue.","Never share a fixed session ID across processes or goroutines.","Close a session explicitly before re-opening the same ID."],"tags":["session-management","duplicate-key","go","agent"],"backgroundTag":"duplicate-session-id","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}