{"record":{"id":"6edff78c5c64fc51","repo":"t8y2/dbx","slug":"agent-session-limit-reached-d-6edff7","errorCode":null,"errorMessage":"agent session limit reached: %d","messagePattern":"agent session limit reached: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/neo4j-go/main.go","lineNumber":268,"sourceCode":"\t\tsession, err := r.session(id)\n\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\treturn session.server.dispatch(method, params)\n\t}\n}\n\nfunc (r *runtimeServer) openSession(id string, params 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(params)\n\tif err != nil {\n\t\treturn err\n\t}\n\tserver := newServer(runtime, params)\n\tif err := server.validateConnection(); err != nil {\n\t\tr.releaseRuntime(key)\n\t\treturn err\n\t}\n\n\tr.mu.Lock()\n\tdefer r.mu.Unlock()\n\tif _, exists := r.sessions[id]; exists {\n\t\tr.releaseRuntime(key)\n\t\treturn fmt.Errorf(\"agent session already exists: %s\", id)","sourceCodeStart":250,"sourceCodeEnd":286,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/neo4j-go/main.go#L250-L286","documentation":"The runtime server caps concurrent agent sessions at maxAgentSessions. openSession checks len(r.sessions) before acquiring a runtime and returns this error when the registry is full, protecting the process from unbounded runtime/memory growth.","triggerScenarios":"Calling openSession when maxAgentSessions sessions are already registered. The check runs under r.mu right after the duplicate-id check and before acquireRuntime.","commonSituations":"Long-lived sessions never closed by clients so the registry fills up; a load test opening many parallel sessions; a leaked-session bug on the client side exhausting the fixed cap.","solutions":["Close idle sessions (closeSession/disconnect) to free slots","Raise maxAgentSessions if the host can support more concurrent runtimes","Reuse existing sessions instead of opening one per request","Audit clients for leaked sessions (opened but never disconnected)"],"exampleFix":"// before\nfor _, w := range workers { openSession(fmt.Sprintf(\"worker-%d\", i)) } // one session per query\n// after\nsess := getOrCreateSharedSession() // reuse one session across queries, close on shutdown","handlingStrategy":"validation","validationCode":"if activeSessionCount() >= maxAgentSessions {\n    return fmt.Errorf(\"client-side guard: would exceed %d agent sessions\", maxAgentSessions)\n}","typeGuard":null,"tryCatchPattern":"err := openSession(id, params)\nif err != nil && strings.Contains(err.Error(), \"session limit reached\") {\n    // back off, close an idle session, then retry once\n    closeOldestIdleSession()\n    err = openSession(id, params)\n}\nreturn err","preventionTips":["Track session lifecycle and close sessions deterministically","Size client pools at or below maxAgentSessions","Monitor len(sessions) via agent metrics/logs","Reuse a shared session for low-volume workloads"],"tags":["neo4j","session","limit","resource-exhaustion"],"backgroundTag":"session-limit-reached","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"}