{"record":{"id":"73322c523a580e73","repo":"t8y2/dbx","slug":"hive-agent-session-not-found-s-73322c","errorCode":null,"errorMessage":"Hive Agent session not found: %s","messagePattern":"Hive Agent session not found: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/hive-go/main.go","lineNumber":274,"sourceCode":"\tdefer runtimeServer.mu.Unlock()\n\tif _, exists := runtimeServer.sessions[id]; exists {\n\t\t_ = server.disconnect()\n\t\treturn fmt.Errorf(\"Hive Agent session already exists: %s\", id)\n\t}\n\tif len(runtimeServer.sessions) >= maxAgentSessions {\n\t\t_ = server.disconnect()\n\t\treturn fmt.Errorf(\"maximum Hive Agent sessions reached (%d)\", maxAgentSessions)\n\t}\n\truntimeServer.sessions[id] = &agentSession{server: server}\n\treturn nil\n}\n\nfunc (runtimeServer *runtimeServer) session(id string) (*agentSession, error) {\n\truntimeServer.mu.RLock()\n\tsession := runtimeServer.sessions[id]\n\truntimeServer.mu.RUnlock()\n\tif session == nil {\n\t\treturn nil, fmt.Errorf(\"Hive Agent session not found: %s\", id)\n\t}\n\treturn session, nil\n}\n\nfunc (runtimeServer *runtimeServer) closeSession(id string) error {\n\tif id == \"\" {\n\t\tid = legacyAgentSessionID\n\t}\n\truntimeServer.mu.Lock()\n\tsession := runtimeServer.sessions[id]\n\tdelete(runtimeServer.sessions, id)\n\truntimeServer.mu.Unlock()\n\tif session == nil {\n\t\treturn nil\n\t}\n\tsession.mu.Lock()\n\tdefer session.mu.Unlock()\n\treturn session.server.disconnect()","sourceCodeStart":256,"sourceCodeEnd":292,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/hive-go/main.go#L256-L292","documentation":"session(id) looks up a registered agent session under a read lock; if no session with that id is registered it returns this error. Callers (dispatch, closeSession helpers, withSession) use it to route per-session work, so it signals an unknown/stale session handle.","triggerScenarios":"Any dispatch or close/withSession call referencing a session id that was never opened or was already closed via closeSession.","commonSituations":"Client caches a session id after the server restarted (in-memory sessions lost); double-close of a session; a typo'd or misrouted session id between worker components; load balancer routing requests to a different runtime instance than the one holding the session.","solutions":["Re-open the session (openSession) when this error occurs and retry the request.","Ensure clients close sessions explicitly and stop using ids after close.","After a runtime restart, have clients renegotiate sessions instead of reusing old ids.","If behind a load balancer, enable sticky routing so all requests for a session hit the same runtime instance."],"exampleFix":"// before\nsession, err := rt.session(id)\nif err != nil { return err }\n// after\nsession, err := rt.session(id)\nif err != nil {\n    if strings.Contains(err.Error(), \"session not found\") {\n        if oerr := rt.openSession(id, params); oerr != nil { return oerr }\n        session, err = rt.session(id)\n    }\n    if err != nil { return err }\n}","handlingStrategy":"try-catch","validationCode":"// Track session lifecycle client-side; never call after close\nif closedSessions[id] {\n    return errors.New(\"session already closed locally\")\n}","typeGuard":null,"tryCatchPattern":"session, err := rt.session(id)\nif err != nil {\n    if strings.Contains(err.Error(), \"session not found\") {\n        // re-establish and retry once\n        if oerr := rt.openSession(id, params); oerr == nil {\n            session, err = rt.session(id)\n        }\n    }\n    if err != nil { return err }\n}","preventionTips":["Handle runtime restarts by re-opening sessions","Stop using session ids after closeSession","Enable sticky routing behind load balancers","Log session ids consistently to avoid misrouted references"],"tags":["session","not-found","state-management"],"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"}