{"record":{"id":"7faf6b36e503f6ca","repo":"t8y2/dbx","slug":"agent-session-not-found-s-7faf6b","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/etcd-go/main.go","lineNumber":284,"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":266,"sourceCodeEnd":302,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/etcd-go/main.go#L266-L302","documentation":"The runtime server looked up the requested session id in r.sessions and found nothing. Every per-session method (connect, get, put, watch, close, ...) is routed through session(id), which validates the id first. It means the session was never opened, was already closed, or the id is misspelled.","triggerScenarios":"Calling any session-scoped runtime method with an id that is not currently in r.sessions — typically after closeSession/shutdown removed it or before openSession succeeded.","commonSituations":"Using a session after its close call completed; server restart wiping in-memory sessions while the client keeps the old id; typos in session ids; concurrent close racing with another call on the same id.","solutions":["Call openSession first (or re-open) with the id before issuing session-scoped methods","Check that the session id matches exactly the one returned/used at open time","If the server restarted, re-open the session and re-establish connection and watches"],"exampleFix":"// before\nserver.call(\"get\", map[string]any{\"id\": \"agent-1\", \"key\": \"foo\"}) // closed earlier\n\n// after\nif _, err := server.call(\"get\", map[string]any{\"id\": id}); err != nil && strings.Contains(err.Error(), \"not found\") {\n    server.call(\"open\", map[string]any{\"id\": id})\n    server.call(\"connect\", map[string]any{\"id\": id})\n}","handlingStrategy":"try-catch","validationCode":"// keep a local registry of ids you successfully opened\nfunc sessionKnown(id string) bool {\n    _, ok := openedSessions[id]\n    return ok\n}","typeGuard":"func isSessionNotFound(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"Agent session not found\")\n}","tryCatchPattern":"resp, err := runtime.Call(\"get\", req)\nif isSessionNotFound(err) {\n    if _, oerr := runtime.Call(\"open\", map[string]any{\"id\": id}); oerr != nil { return oerr }\n    resp, err = runtime.Call(\"get\", req)\n}","preventionTips":["Open the session before any session-scoped call","Re-open sessions after a server restart","Use one canonical id per client, stored in a struct field"],"tags":["go","etcd","session-management","missing-resource"],"backgroundTag":"session-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"}