{"record":{"id":"8172b0205773b79e","repo":"t8y2/dbx","slug":"agent-session-not-found-s-8172b0","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/kingbase-go/main.go","lineNumber":316,"sourceCode":"\tif err := s.connect(cp); err != nil {\n\t\treturn err\n\t}\n\tr.mu.Lock()\n\tdefer r.mu.Unlock()\n\tif _, exists := r.sessions[id]; exists {\n\t\t_ = s.disconnect()\n\t\treturn fmt.Errorf(\"agent session already exists: %s\", id)\n\t}\n\tr.sessions[id] = &agentSession{server: s}\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":298,"sourceCodeEnd":334,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/kingbase-go/main.go#L298-L334","documentation":"session(id) looks up the agent session in r.sessions under a read lock and returns this error when no session with that id is registered — i.e. the session was never opened, or was already closed/shutdown.","triggerScenarios":"Calling any per-session method ('query', 'disconnect', etc.) with an id that was never opened, was closed via closeSession, or was removed after a 'shutdown' of the runtime.","commonSituations":"Client retrying commands after the session timed out or was closed; stale id cached by the orchestrator across runtime restarts; typo'd or truncated session id passed in JSON-RPC params.","solutions":["Open the session (openSession) before calling methods on it","Verify the id matches the one returned/used at open time","Handle stale references: on this error, re-open the session and retry the operation","Check the runtime hasn't been restarted (which clears all sessions)"],"exampleFix":"// before: assumes session exists\nres, err := rt.Call(id, \"query\", args)\n// after: reopen on not-found\nres, err := rt.Call(id, \"query\", args)\nif err != nil && strings.Contains(err.Error(), \"not found\") {\n    if err := rt.OpenSession(id, cp); err != nil { return err }\n    res, err = rt.Call(id, \"query\", args)\n}","handlingStrategy":"try-catch","validationCode":"// Go: confirm session exists before use\nif _, err := rt.Session(id); err != nil {\n    if err := rt.OpenSession(id, cp); err != nil {\n        return err\n    }\n}","typeGuard":null,"tryCatchPattern":"res, err := rt.Call(id, method, args)\nif err != nil && strings.Contains(err.Error(), \"not found\") {\n    if err := rt.OpenSession(id, cp); err != nil { return err }\n    res, err = rt.Call(id, method, args)\n}","preventionTips":["Invalidate cached session handles on close/shutdown","Map errors to explicit states client-side (open/closed/unknown)","Re-open and retry once on not-found for transient runtime restarts"],"tags":["kingbase","agent-runtime","session-management","not-found","go"],"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"}