{"record":{"id":"901a974082f06993","repo":"t8y2/dbx","slug":"agent-session-not-found-s-901a97","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/neo4j-go/main.go","lineNumber":297,"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: server, 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\terr := session.server.disconnect()\n\tsession.mu.Unlock()\n\tr.releaseRuntime(session.runtimeKey)\n\treturn err","sourceCodeStart":279,"sourceCodeEnd":315,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/neo4j-go/main.go#L279-L315","documentation":"session() looks up an agent session by id in the runtime server's registry and returns this error when no session with that id is registered. Every subsequent RPC method (query execution, fetch, disconnect) resolves through session(), so an unknown/stale/closed id causes this error instead of a nil-pointer panic.","triggerScenarios":"Calling any session-scoped method (query, fetchQueryPage, closeSession paths) with an id that was never opened via openSession, or that was already closed/disconnected, or after the agent process restarted losing its registry.","commonSituations":"Client kept a session handle across an agent restart; a typo or stale id cached in the client; calling fetch on a session that hit shutdown; double-disconnect where the second call looks up a removed id.","solutions":["Open a new session with openSession and retry the operation with the fresh id","Treat the error as 'session invalid' and re-run the connect handshake rather than retrying the same id","Check that the id you pass matches the one returned/used at openSession time","If the agent restarted, reconnect and re-establish state before issuing queries"],"exampleFix":"// before\npage, err := call(\"fetch\", map[string]any{\"session_id\": cachedID})\n// after\npage, err := call(\"fetch\", map[string]any{\"session_id\": cachedID})\nif err != nil && strings.Contains(err.Error(), \"not found\") {\n    cachedID = openNewSession()\n    page, err = call(\"fetch\", map[string]any{\"session_id\": cachedID})\n}","handlingStrategy":"try-catch","validationCode":"// keep a live set of ids known to be open\nif !knownSessions[id] {\n    id, err = openSessionAndReturnID()\n    if err != nil { return err }\n}","typeGuard":"func sessionAlive(id string, known map[string]bool) bool {\n    return known[id]\n}","tryCatchPattern":"sess, err := call(\"query\", map[string]any{\"session_id\": id})\nif err != nil && strings.Contains(err.Error(), \"agent session not found\") {\n    id, err = reopenSession() // re-handshake and get a fresh id\n    if err != nil { return err }\n    sess, err = call(\"query\", map[string]any{\"session_id\": id})\n}\nreturn err","preventionTips":["Reconnect after any agent restart before issuing commands","Never cache session ids across process restarts of the agent","Disconnect once; guard against double-disconnect by tracking state","Validate ids are passed through unchanged from open to use"],"tags":["neo4j","session","not-found","stale-state"],"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-14T00:17:10.932Z"}