{"record":{"id":"52bf9ef7722be645","repo":"t8y2/dbx","slug":"agent-session-already-exists-s","errorCode":null,"errorMessage":"agent session already exists: %s","messagePattern":"agent session already exists: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/cassandra-go/main.go","lineNumber":242,"sourceCode":"\t\tif err != nil {\n\t\t\treturn nil, false, err\n\t\t}\n\t\tsession.mu.Lock()\n\t\tdefer session.mu.Unlock()\n\t\trelease, err := session.server.runtime.acquire(isMetadataOperation(method))\n\t\tif err != nil {\n\t\t\treturn nil, false, err\n\t\t}\n\t\tdefer release()\n\t\treturn session.server.dispatch(method, params)\n\t}\n}\n\nfunc (r *runtimeServer) openSession(id string, cp connectParams) error {\n\tr.mu.Lock()\n\tif _, exists := r.sessions[id]; exists {\n\t\tr.mu.Unlock()\n\t\treturn fmt.Errorf(\"agent session already exists: %s\", id)\n\t}\n\tif len(r.sessions) >= maxAgentSessions {\n\t\tr.mu.Unlock()\n\t\treturn fmt.Errorf(\"agent session limit reached: %d\", maxAgentSessions)\n\t}\n\tr.mu.Unlock()\n\n\truntime, key, err := r.acquireRuntime(cp)\n\tif err != nil {\n\t\treturn err\n\t}\n\ts := newServer(runtime, cp)\n\tif err := s.validateConnection(); err != nil {\n\t\tr.releaseRuntime(key)\n\t\treturn err\n\t}\n\n\tr.mu.Lock()","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/cassandra-go/main.go#L224-L260","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Generate a fresh unique session id (UUID) for each connect instead of a fixed one.","Call the session close/disconnect method before reconnecting with the same id.","On receiving this error, treat the existing session as yours and reuse it rather than re-connecting."],"exampleFix":"// before\nconnect(sessionID: \"agent-1\") // retried after timeout, session still alive\n// after\nconnect(sessionID: uuid.NewString()) // unique per attempt, or closeSession(\"agent-1\") first","handlingStrategy":"try-catch","validationCode":"knownSessionsMu.Lock()\n_, alreadyOpen := knownSessions[id]\nknownSessionsMu.Unlock()\nif alreadyOpen { reuseExisting(id); return nil }","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"agent session already exists\") {\n    return r.session(id) // reuse the live session instead of failing\n}","preventionTips":["Generate session ids with uuid.NewString() per connection.","Always disconnect in a defer/finally on error paths.","Do not retry connect with the same id after a timeout without closing first."],"tags":["session","protocol","duplicate"],"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-14T00:17:10.932Z"}