{"record":{"id":"01a5ff70f8ef7e1f","repo":"t8y2/dbx","slug":"agent-session-limit-reached-d-01a5ff","errorCode":null,"errorMessage":"agent session limit reached: %d","messagePattern":"agent session limit reached: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/vastbase-go/main.go","lineNumber":310,"sourceCode":"\t\tdefer session.mu.Unlock()\n\t\trelease, permitErr := session.server.acquireOperationPermit(method)\n\t\tif permitErr != nil {\n\t\t\treturn nil, false, permitErr\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\tconnectionRuntime, runtimeKey := r.acquireConnectionRuntime(cp)\n\ts := newServer()\n\tif err := s.connectWithRuntime(cp, connectionRuntime); err != nil {\n\t\tr.releaseConnectionRuntime(runtimeKey)\n\t\treturn err\n\t}\n\tr.mu.Lock()\n\tdefer r.mu.Unlock()\n\tif _, exists := r.sessions[id]; exists {\n\t\t_ = s.disconnect()\n\t\tr.releaseConnectionRuntime(runtimeKey)\n\t\treturn fmt.Errorf(\"agent session already exists: %s\", id)\n\t}\n\tr.sessions[id] = &agentSession{server: s, runtimeKey: runtimeKey}\n\treturn nil","sourceCodeStart":292,"sourceCodeEnd":328,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/vastbase-go/main.go#L292-L328","documentation":"openSession enforces a hard cap of maxAgentSessions concurrent agent sessions. When len(r.sessions) already equals that limit and another open is attempted, the driver refuses the new session with this error. It protects the process from unbounded resource growth per connection runtime.","triggerScenarios":"Opening more than maxAgentSessions distinct sessions simultaneously without closing any; leaked sessions (opened but never closed) accumulating until the cap is hit; session-open retry loops creating new ids each attempt and exhausting the pool.","commonSituations":"Long-running agent hosts opening one session per client request and never closing on disconnect; monitoring fan-out creating many parallel sessions; after an upgrade, existing sessions lingering while new ones are requested.","solutions":["Close finished sessions with closeSession(id) so slots are released before opening new ones.","Enumerate and close stale/leaked sessions, then retry the open.","Increase maxAgentSessions if the workload legitimately needs more concurrent sessions (and confirm resources allow it).","Reuse an existing session via session(id) instead of opening a new one per operation."],"exampleFix":"// before\nr.openSession(newUUID(), cp) // unbounded, eventually hits limit\n// after\nif len(activeIDs) >= maxSessions {\n    r.closeSession(oldestID) // release a slot first\n}\nr.openSession(newUUID(), cp)","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"err := r.openSession(id, cp)\nif err != nil {\n    if strings.HasPrefix(err.Error(), \"agent session limit reached\") {\n        if oldest := pickOldestSessionID(); oldest != \"\" {\n            _ = r.closeSession(oldest)\n            return r.openSession(id, cp)\n        }\n    }\n    return err\n}","preventionTips":["Track open session ids in the caller and close them deterministically.","Cap your own concurrency at or below maxAgentSessions.","Pool and reuse sessions instead of opening per request.","Monitor len(sessions) and alert before hitting the cap."],"tags":["session-management","resource-limit","capacity"],"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"}