{"record":{"id":"a0aecccbf2834df3","repo":"t8y2/dbx","slug":"agent-session-not-found-s-a0aecc","errorCode":null,"errorMessage":"agent session not found: %s","messagePattern":"agent session not found: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/vastbase-go/main.go","lineNumber":336,"sourceCode":"\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\tr.releaseConnectionRuntime(runtimeKey)\n\t\treturn fmt.Errorf(\"agent session already exists: %s\", id)\n\t}\n\tr.sessions[id] = &agentSession{server: s, runtimeKey: runtimeKey}\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\terr := session.server.disconnect()\n\tr.releaseConnectionRuntime(session.runtimeKey)\n\treturn err","sourceCodeStart":318,"sourceCodeEnd":354,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/vastbase-go/main.go#L318-L354","documentation":"session(id) looks up a registered agent session under a read lock; if no session with that id exists it returns this error. It means an operation was attempted against a session id that was never opened or has already been closed.","triggerScenarios":"Calling session(id) (and any operation on the returned session) with an id that was never passed to openSession; operating on a session after closeSession(id) succeeded; a typo'd or stale id from a previous process lifetime.","commonSituations":"Clients caching session ids across server restarts; using a session after its close/disconnect; id mismatch from serialization (e.g. trimming, encoding differences) when passing ids around.","solutions":["Open the session with openSession(id, cp) before using it, or verify existence first with session(id) and handle the not-found case.","Check whether closeSession(id) was called earlier in the flow and avoid reuse afterwards.","Use the session object returned at open time rather than re-looking it up by id, where possible.","Log and compare the exact id strings on both sides to catch encoding/whitespace mismatches."],"exampleFix":"// before\nsess, err := r.session(\"agent-1\") // never opened -> error\nsess.server.doThing()\n// after\nsess, err := r.session(\"agent-1\")\nif err != nil {\n    if openErr := r.openSession(\"agent-1\", cp); openErr != nil {\n        return openErr\n    }\n    sess, err = r.session(\"agent-1\")\n}\nsess.server.doThing()","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"sess, err := r.session(id)\nif err != nil {\n    if strings.HasPrefix(err.Error(), \"agent session not found\") {\n        // lazily reopen, or surface a clear session-expired state to the user\n        return r.openSession(id, cp)\n    }\n    return err\n}","preventionTips":["Keep the *agentSession handle from openSession instead of re-looking up by id.","Invalidate cached ids whenever closeSession is called or the server restarts.","Treat not-found as reopen-and-retry in long-lived clients.","Log id values end-to-end to catch encoding/whitespace mismatches."],"tags":["session-management","not-found","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-14T05:17:10.506Z"}