{"record":{"id":"9c692e28832e50b1","repo":"t8y2/dbx","slug":"agent-session-not-found-s-9c692e","errorCode":null,"errorMessage":"Agent session not found: %s","messagePattern":"Agent session not found: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/etcd2-go/main.go","lineNumber":255,"sourceCode":"\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]\n\tr.mu.RUnlock()\n\tif session == nil {\n\t\treturn nil, fmt.Errorf(\"Agent session not found: %s\", id)\n\t}\n\treturn session, nil\n}\n\nfunc (r *runtimeServer) closeSession(id string) any {\n\tr.mu.Lock()\n\tsession := r.sessions[id]\n\tdelete(r.sessions, id)\n\tr.mu.Unlock()\n\tif session != nil {\n\t\tsession.cancelActive()\n\t\tsession.mu.Lock()\n\t\tsession.state.close()\n\t\tsession.mu.Unlock()\n\t}\n\treturn map[string]bool{\"ok\": true}\n}\n","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/etcd2-go/main.go#L237-L273","documentation":"session() looks up an agentSession by id and returns 'Agent session not found: %s' when no session with that id is registered. Every method that operates on an existing session routes through this lookup, so a stale or wrong id fails fast.","triggerScenarios":"Calling any session-scoped method (closeSession path, RPC handlers, shutdown) with an id that was never opened or that was already closed.","commonSituations":"Using a session id after the server restarted, double-closing a session, typos in the id, id scoped to a different runtime server instance.","solutions":["Open a new session with openSession before using the id.","Confirm the id matches the one returned/stored at open time and the same server instance.","Handle this error by re-establishing the session rather than retrying the same call."],"exampleFix":"// before\nhandle(\"agent-1\", \"kv_put\", ...) // session never opened\n// after\nopenSession(\"agent-1\", connectParams)\nhandle(\"agent-1\", \"kv_put\", ...)","handlingStrategy":"type-guard","validationCode":"if _, known := knownSessionIDs[id]; !known { return fmt.Errorf(\"session %s not open; call openSession first\", id) }","typeGuard":"func sessionExists(server *runtimeServer, id string) bool {\n    server.mu.RLock(); defer server.mu.RUnlock()\n    return server.sessions[id] != nil\n}","tryCatchPattern":"if err := call(id, method, params); err != nil && strings.Contains(err.Error(), \"session not found\") {\n    // re-open and replay once\n    openSession(id, connectParams)\n    return call(id, method, params)\n}","preventionTips":["Persist the session id returned at open time; never reconstruct it","Detect server restarts and re-open all sessions","Avoid double-close: mark closed ids client-side"],"tags":["session","not-found","etcd-agent"],"backgroundTag":"resource-not-found","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"}