{"record":{"id":"f0ddda69267603ce","repo":"t8y2/dbx","slug":"agent-session-limit-reached-d-f0ddda","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/etcd-go/main.go","lineNumber":263,"sourceCode":"\t\tdefer session.mu.Unlock()\n\t\tresult, err := session.state.handle(method, params)\n\t\treturn result, false, err\n\t}\n}\n\nfunc requiredSessionID(params map[string]json.RawMessage) string {\n\treturn strings.TrimSpace(stringParam(params, \"agentSessionId\"))\n}\n\nfunc (r *runtimeServer) openSession(id string, params map[string]json.RawMessage) (any, bool, error) {\n\tr.mu.Lock()\n\tif _, exists := r.sessions[id]; exists {\n\t\tr.mu.Unlock()\n\t\treturn nil, false, fmt.Errorf(\"Agent session already exists: %s\", id)\n\t}\n\tif len(r.sessions) >= maxAgentSessions {\n\t\tr.mu.Unlock()\n\t\treturn nil, false, fmt.Errorf(\"Agent session limit reached: %d\", maxAgentSessions)\n\t}\n\tsession := &agentSession{state: newEtcdSession()}\n\tr.sessions[id] = session\n\tr.mu.Unlock()\n\n\tif _, err := session.state.connect(params); err != nil {\n\t\tr.mu.Lock()\n\t\tdelete(r.sessions, id)\n\t\tr.mu.Unlock()\n\t\tsession.state.close()\n\t\treturn nil, false, err\n\t}\n\treturn map[string]bool{\"ok\": true}, false, nil\n}\n\nfunc (r *runtimeServer) session(id string) (*agentSession, error) {\n\tr.mu.RLock()\n\tsession := r.sessions[id]","sourceCodeStart":245,"sourceCodeEnd":281,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/etcd-go/main.go#L245-L281","documentation":"openSession enforces a hard cap (maxAgentSessions) on concurrent sessions held by the runtime server. When the number of live sessions equals or exceeds the limit, no new sessions are admitted and the server returns this error instead of exhausting resources. The caller must free an existing session or raise the configured limit.","triggerScenarios":"Calling openSession (runtime 'open' method) when len(r.sessions) >= maxAgentSessions.","commonSituations":"Leaked sessions from clients that never call close/shutdown; long-lived daemons accumulating stale sessions; test suites opening many sessions without cleanup; a maxAgentSessions value set too low for fleet size.","solutions":["Close stale/idle sessions via the close or shutdown method to free slots","Raise maxAgentSessions if the workload legitimately needs more concurrent sessions","Audit clients for leaked sessions (open without close) and fix the leak"],"exampleFix":"// before\nfor i := 0; i < 1000; i++ {\n    open(fmt.Sprintf(\"agent-%d\", i)) // hits session cap\n}\n\n// after\nfor i := 0; i < 1000; i++ {\n    id := fmt.Sprintf(\"agent-%d\", i)\n    open(id)\n    defer close(id) // always release the slot\n}","handlingStrategy":"fallback","validationCode":"// before opening, ensure you are under the cap if you know the configured limit\n// (server enforces the real cap; this only avoids obvious overflow)\nif activeSessions >= maxAgentSessions {\n    closeOldestIdleSession()\n}","typeGuard":null,"tryCatchPattern":"_, err := runtime.Call(\"open\", map[string]any{\"id\": id})\nif err != nil && strings.Contains(err.Error(), \"session limit reached\") {\n    evictStaleSessions()\n    _, err = runtime.Call(\"open\", map[string]any{\"id\": id})\n    if err != nil { return ErrCapacity }\n}","preventionTips":["Always close sessions when done (defer close)","Monitor session counts and alert near the configured limit","Set maxAgentSessions appropriately for the workload"],"tags":["go","etcd","resource-limit","capacity"],"backgroundTag":"resource-limit-exceeded","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"}