{"record":{"id":"c685a76c23a4dfbd","repo":"t8y2/dbx","slug":"maximum-hive-agent-sessions-reached-d-c685a7","errorCode":null,"errorMessage":"maximum Hive Agent sessions reached (%d)","messagePattern":"maximum Hive Agent sessions reached \\((.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/hive-go/main.go","lineNumber":243,"sourceCode":"\n\tsessionID := stringParam(params, \"agentSessionId\")\n\tif sessionID == \"\" {\n\t\tsessionID = legacyAgentSessionID\n\t}\n\tsession, err := runtimeServer.session(sessionID)\n\tif err != nil {\n\t\treturn nil, false, err\n\t}\n\tsession.mu.Lock()\n\tdefer session.mu.Unlock()\n\treturn session.server.dispatch(method, params)\n}\n\nfunc (runtimeServer *runtimeServer) openSession(id string, params connectParams) error {\n\truntimeServer.mu.Lock()\n\tif len(runtimeServer.sessions) >= maxAgentSessions {\n\t\truntimeServer.mu.Unlock()\n\t\treturn fmt.Errorf(\"maximum Hive Agent sessions reached (%d)\", maxAgentSessions)\n\t}\n\tif _, exists := runtimeServer.sessions[id]; exists {\n\t\truntimeServer.mu.Unlock()\n\t\treturn fmt.Errorf(\"Hive Agent session already exists: %s\", id)\n\t}\n\truntimeServer.mu.Unlock()\n\n\tserver, err := newServer(params)\n\tif err != nil {\n\t\treturn err\n\t}\n\truntimeServer.mu.Lock()\n\tdefer runtimeServer.mu.Unlock()\n\tif _, exists := runtimeServer.sessions[id]; exists {\n\t\t_ = server.disconnect()\n\t\treturn fmt.Errorf(\"Hive Agent session already exists: %s\", id)\n\t}\n\tif len(runtimeServer.sessions) >= maxAgentSessions {","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/hive-go/main.go#L225-L261","documentation":"The runtime server enforces a hard cap (maxAgentSessions) on concurrent Hive Agent sessions. openSession checks the session count under the lock before creating anything and rejects new sessions once the cap is reached.","triggerScenarios":"Calling openSession (via dispatch of a new-session request, or replaceSession) when len(runtimeServer.sessions) >= maxAgentSessions.","commonSituations":"Clients leaking sessions (never closing them), many concurrent agents sharing one runtime process, an undersized maxAgentSessions setting for the workload.","solutions":["Close idle/finished sessions with closeSession so slots free up.","Raise maxAgentSessions in the runtime configuration to match expected concurrency.","Fix client code to close sessions deterministically (defer close / lifecycle hooks) instead of leaking them.","Check for replaceSession flows accidentally creating new sessions instead of replacing."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := rt.openSession(id, params); err != nil {\n    if strings.Contains(err.Error(), \"maximum Hive Agent sessions reached\") {\n        // free a slot then retry\n        rt.closeSession(oldestSessionID())\n        err = rt.openSession(id, params)\n    }\n    if err != nil { return err }\n}","preventionTips":["Always close sessions when work completes (defer closeSession)","Set maxAgentSessions above peak concurrency with headroom","Track session counts client-side before opening new ones","Alert when session usage approaches the cap"],"tags":["session-limit","capacity","hiveserver2"],"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"}