{"record":{"id":"5b846e2cc4eb1baf","repo":"t8y2/dbx","slug":"agent-session-not-found-s","errorCode":null,"errorMessage":"agent session not found: %s","messagePattern":"agent session not found: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/cassandra-go/main.go","lineNumber":275,"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\tr.releaseRuntime(key)\n\t\treturn fmt.Errorf(\"agent session already exists: %s\", id)\n\t}\n\tr.sessions[id] = &agentSession{server: s, runtimeKey: key}\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\tsession.server.disconnect()\n\tsession.mu.Unlock()\n\tr.releaseRuntime(session.runtimeKey)\n\treturn nil","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/cassandra-go/main.go#L257-L293","documentation":"session looks up an existing agent session by id; if no session is registered under that id it returns this error. Any RPC that requires a live session (query, metadata, ddl, disconnect, etc.) fails with it when the session was never opened or has already been closed.","triggerScenarios":"Calling any dispatch method other than connect with a session id that is not present in r.sessions — typically after closeSession/disconnect or before any connect succeeded.","commonSituations":"Client using a stale session id after a server restart (in-memory sessions are lost); double-disconnect; the session being closed by a concurrent worker while another still uses it; typo'd or truncated session id in a multi-session client.","solutions":["Reconnect with the connect method to create a new session before issuing further RPCs.","Ensure only one owner closes the session; remove double-disconnect paths.","After a server restart, discard cached session ids and re-handshake.","Treat this error as 'reconnect required' in client recovery logic."],"exampleFix":"// before\nquery(sessionID: oldID) // server restarted; session lost\n// after\nif sessionGone(err) { id = connect(); query(id) }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"func isSessionNotFound(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"agent session not found\")\n}","tryCatchPattern":"if isSessionNotFound(err) {\n    id, err = reconnect() // open a fresh session, then retry the RPC once\n    if err == nil { return retryOriginal(id) }\n}","preventionTips":["Cache session ids with a generation counter tied to the server lifetime.","Centralize disconnect so no double-close occurs.","Implement automatic re-handshake on session-not-found before surfacing errors."],"tags":["session","not-found","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"}