{"record":{"id":"efdbebaca87176b3","repo":"t8y2/dbx","slug":"maximum-hive-agent-sessions-reached-d","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/argo-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/argo-go/main.go#L225-L261","documentation":"openSession checks the session count under the lock before creating a server and rejects new sessions once len(sessions) >= maxAgentSessions. This first (pre-creation) check exists to avoid building a connection when capacity is already exhausted. The limit is a fixed compile-time constant of the runtime.","triggerScenarios":"A dispatch of open_session (or connect) arrives while the runtime already holds maxAgentSessions live sessions; the pre-lock check fires before newServer() runs.","commonSituations":"Client leaking sessions by calling open_session repeatedly without close_session; legacy connect flow creating sessions under the same ID from multiple callers; long-running idle sessions consuming all slots.","solutions":["Call close_session for finished sessions before opening new ones.","Adopt a fixed agentSessionId per client and reuse it instead of minting new IDs.","Check the wrapped error: if it is permission/NoAuth, grant the connecting identity read access to the namespace znode (or configure zooKeeperAuthScheme/zooKeeperAuth).","Restart or shut down the agent runtime (shutdown method) to clear leaked sessions if close is impossible.","Fix client-side session lifecycle (ensure close_session on error paths) so slots are freed."],"exampleFix":"// before: new session per request\nopenSession(fmt.Sprintf(\"s-%d\", n), params)\n// after: reuse one session per client\nopenSession(clientFixedID, params) // close_session when done","handlingStrategy":"validation","validationCode":"// preflight on the client side: track active sessions locally\nif activeSessions >= maxAgentSessions {\n    return fmt.Errorf(\"refusing to open: local count says runtime is full\")\n}","typeGuard":null,"tryCatchPattern":"err := rpc(\"open_session\", params)\nif err != nil && strings.Contains(err.Error(), \"maximum Hive Agent sessions reached\") {\n    // free a slot, then retry once\n    _ = rpc(\"close_session\", map[string]any{\"agentSessionId\": oldestSessionID})\n    err = rpc(\"open_session\", params)\n}","preventionTips":["Always pair open_session with close_session, including on error paths.","Reuse one stable agentSessionId per client instead of creating new IDs.","Periodically audit for leaked sessions and call close_session on stale IDs.","Call shutdown only when the runtime should fully reset."],"tags":["session-limit","resource-exhaustion","go","agent"],"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"}