{"record":{"id":"e4daaedab90fff0c","repo":"t8y2/dbx","slug":"agent-session-already-exists-s-e4daae","errorCode":null,"errorMessage":"agent session already exists: %s","messagePattern":"agent session already exists: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/oracle-go/main.go","lineNumber":744,"sourceCode":"}\n\nfunc (r *runtimeServer) withSession(agentSessionID, method string, params map[string]json.RawMessage) (any, bool, error) {\n\tsession, err := r.session(agentSessionID)\n\tif err != nil {\n\t\treturn nil, false, err\n\t}\n\t// Oracle connection state, transactions, and cursors are session-scoped;\n\t// serialize one session while allowing separate sessions to run in parallel.\n\tsession.mu.Lock()\n\tdefer session.mu.Unlock()\n\treturn session.server.dispatch(method, params)\n}\n\nfunc (r *runtimeServer) openSession(agentSessionID string, params connectParams) error {\n\tr.mu.Lock()\n\tif _, exists := r.sessions[agentSessionID]; exists {\n\t\tr.mu.Unlock()\n\t\treturn fmt.Errorf(\"agent session already exists: %s\", agentSessionID)\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\tsession := &agentSession{server: newServer()}\n\tr.sessions[agentSessionID] = session\n\tr.mu.Unlock()\n\n\t// Reserve the id under the registry lock, then connect outside it so unrelated\n\t// sessions can establish database connections concurrently.\n\tsession.mu.Lock()\n\terr := session.server.connect(params)\n\tsession.mu.Unlock()\n\tif err != nil {\n\t\tr.mu.Lock()\n\t\tif r.sessions[agentSessionID] == session {\n\t\t\tdelete(r.sessions, agentSessionID)","sourceCodeStart":726,"sourceCodeEnd":762,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/oracle-go/main.go#L726-L762","documentation":"oracle-go's runtimeServer.openSession registers agent sessions by id and rejects a second registration with the same id. The id check runs under r.mu before a runtime is acquired, so a duplicate connect fails fast without consuming runtime resources. Sessions must be closed before their ids can be reused.","triggerScenarios":"Calling openSession (connect RPC) with an agentSessionID that is already present in r.sessions — a repeat connect from the same client, or two clients configured with the same id.","commonSituations":"Client auto-reconnect re-sends connect after a timeout without disconnecting first; identical session id hardcoded in multiple worker configs; restart of client code while the agent still holds the old session.","solutions":["Disconnect/close the existing session with the same id, then reconnect","Use unique ids per client (UUID) so collisions cannot happen","Handle the error as 'already connected' and keep using the current session","Restart the agent process if stale sessions can no longer be addressed"],"exampleFix":"// before\nconnect(id) // retried on every network error\n// after\nif err := connect(id); err != nil && strings.Contains(err.Error(), \"already exists\") {\n    disconnect(id)\n    connect(id)\n}","handlingStrategy":"try-catch","validationCode":"if id in self._open_session_ids:\n    raise ValueError(f\"session {id} is already open; disconnect first\")","typeGuard":null,"tryCatchPattern":"try:\n    open_session(agent_session_id, params)\nexcept AgentRPCError as e:\n    if \"agent session already exists\" in str(e):\n        close_session(agent_session_id)\n        open_session(agent_session_id, params)\n    else:\n        raise","preventionTips":["Assign a unique id per client (UUID) at startup","Disconnect in a finally/defer cleanup path","Throttle automatic reconnects to avoid overlapping connects","Do not share one id string across worker replicas"],"tags":["oracle","session","duplicate-id","rpc"],"backgroundTag":"session-already-exists","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"}