{"record":{"id":"4072d7604e4afecf","repo":"t8y2/dbx","slug":"agent-session-not-found-s-4072d7","errorCode":null,"errorMessage":"agent session not found: %s","messagePattern":"agent session not found: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/iotdb/main.go","lineNumber":279,"sourceCode":"\t\treturn err\n\t}\n\n\tr.mu.Lock()\n\tdefer r.mu.Unlock()\n\tif _, exists := r.sessions[id]; exists {\n\t\tserver.disconnect()\n\t\treturn fmt.Errorf(\"agent session already exists: %s\", id)\n\t}\n\tr.sessions[id] = &agentSession{server: server}\n\treturn 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) error {\n\tr.mu.Lock()\n\tsession := r.sessions[id]\n\tdelete(r.sessions, id)\n\tr.mu.Unlock()\n\tif session == nil {\n\t\treturn nil\n\t}\n\tsession.server.cancelActiveQuery()\n\tsession.mu.Lock()\n\tdefer session.mu.Unlock()\n\treturn session.server.disconnect()\n}\n","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/iotdb/main.go#L261-L297","documentation":"runtimeServer.session looks up a registered agent session by ID under a read lock. If nothing is registered under that ID it returns 'agent session not found: %s', meaning the runtime holds no state for the requested session.","triggerScenarios":"Invoking any per-session operation (query, metadata, disconnect, etc.) with an ID that was never opened, or one already removed by closeSession/shutdown.","commonSituations":"Client reuses a session ID after the agent runtime restarted (in-memory sessions are lost); calling disconnect twice — the second finds nothing; a stale or typo'd ID cached on the client.","solutions":["Use exactly the session ID returned by the connect/handshake call in subsequent requests.","Re-open the session after a runtime restart before issuing per-session calls.","Handle this error by reconnecting — treat it like a closed session, not a fatal bug.","Drop cached session handles on the client after closeSession/disconnect."],"exampleFix":"// before\nsess, err := rt.session(id)\n// after\nsess, err := rt.session(id)\nif err != nil && strings.HasPrefix(err.Error(), \"agent session not found\") {\n    if err = rt.openSession(id, params); err != nil { return err }\n    sess, err = rt.session(id)\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"sess, err := rt.session(id)\nif err != nil && strings.Contains(err.Error(), \"agent session not found\") {\n    // session was lost (restart or closed); re-open and retry once\n    if oerr := rt.openSession(id, params); oerr != nil {\n        return oerr\n    }\n    sess, err = rt.session(id)\n}","preventionTips":["Keep the session ID returned by the handshake; never construct it manually.","Invalidate cached handles after closeSession/disconnect.","Expect in-memory sessions to vanish on runtime restart; implement reconnect.","Guard against double-disconnect by tracking closed state client-side."],"tags":["go","session-management","lifecycle"],"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"}