{"record":{"id":"52a25db36bd4a662","repo":"t8y2/dbx","slug":"agent-session-limit-reached-d-52a25d","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/kingbase-go/main.go","lineNumber":293,"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, 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\ts := newServer()\n\tif err := s.connect(cp); err != nil {\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\treturn fmt.Errorf(\"agent session already exists: %s\", id)\n\t}\n\tr.sessions[id] = &agentSession{server: s}\n\treturn nil\n}\n\nfunc (r *runtimeServer) session(id string) (*agentSession, error) {","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/kingbase-go/main.go#L275-L311","documentation":"Returned by runtimeServer.openSession in the kingbase-go driver when the number of open sessions is already at maxAgentSessions. New sessions are refused (after the duplicate-id check) to bound resource usage; existing sessions remain usable.","triggerScenarios":"Opening more than maxAgentSessions distinct session ids without closing any — e.g. a workload that creates a session per request and never calls close/shutdown.","commonSituations":"Long-running agents leaking sessions on error paths (connect fails after reservation is skipped, or close is never called); parallel test suites each opening sessions; tight maxAgentSessions configured for large fan-out workloads.","solutions":["Ensure every opened session is closed (defer closeSession) including on error paths","Raise maxAgentSessions if the workload legitimately needs more concurrent sessions","Audit for session leaks: log open/close pairs and count active sessions","Reuse/pool sessions instead of opening one per operation"],"exampleFix":"// before: no close on error\ns, err := rt.OpenSession(id, cp)\nif err != nil { return err }\n// after: guarantee cleanup\ns, err := rt.OpenSession(id, cp)\nif err != nil { return err }\ndefer rt.CloseSession(id)","handlingStrategy":"retry","validationCode":"// Go: check current session count against cap before opening\nif len(rt.ListSessionIDs()) >= maxAgentSessions {\n    return fmt.Errorf(\"at session cap; close sessions before opening more\")\n}","typeGuard":null,"tryCatchPattern":"err := rt.OpenSession(id, cp)\nif err != nil && strings.Contains(err.Error(), \"limit reached\") {\n    rt.CloseOldestIdleSession() // reclaim capacity\n    err = rt.OpenSession(id, cp)\n}","preventionTips":["defer closeSession on every open","Pool and reuse sessions instead of one-per-operation","Monitor active session count; alert before hitting maxAgentSessions","Size maxAgentSessions to your real concurrency"],"tags":["kingbase","agent-runtime","session-limit","resource-exhaustion","go"],"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"}