{"record":{"id":"b97cc0dfa9333113","repo":"t8y2/dbx","slug":"hive-agent-session-not-found-s","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/argo-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/argo-go/main.go#L256-L292","documentation":"The runtimeServer's in-memory session registry lookup failed: `session(id)` consulted `runtimeServer.sessions[id]` under a read lock and found no entry, so it cannot return an *agentSession. This agent driver keeps named Hive sessions in a map; any dispatch or test path that addresses a session by ID will hit this when the ID was never opened or has already been closed/removed. It is a lookup-miss error, not a network error — the message interpolates the offending session ID so the caller can see which one was unknown.","triggerScenarios":"Calling `dispatch` with a method that resolves a session via `runtimeServer.session(id)` when the ID is not in `sessions` — e.g. after `closeSession(id)`/`closeAllSessions()` removed it, before `createSession` was ever called for that ID, or after the driver process restarted losing all in-memory sessions.","commonSituations":"Client keeps a stale session handle across a driver restart; a race where one caller closes the session while another is still dispatching to it; a typo'd or defaulting-empty session ID that was never registered (closeSession maps \"\" to legacyAgentSessionID but session() does not); test teardown closing sessions while assertions still reference them.","solutions":["Check the session ID in the message exists: call the create/open-session method for that ID before dispatching, and verify the ID string matches exactly what createSession registered.","If the session was closed intentionally, re-open a new session and retry the operation; do not reuse the old ID's handle.","Audit for races where closeSession/closeAllSessions runs concurrently with dispatch on the same ID; serialize shutdown after all in-flight requests complete.","If you rely on the legacy empty-ID session, pass the same ID consistently — session() does not fall back to legacyAgentSessionID the way closeSession does."],"exampleFix":"// before\nsess, err := rt.session(sessionID) // \"Hive Agent session not found: s1\" after restart\nrun(sess)\n// after\nif _, ok := rt.peekSession(sessionID); !ok {\n    if err := rt.createSession(sessionID, params); err != nil {\n        return err\n    }\n}\nsess, err := rt.session(sessionID)","handlingStrategy":"validation","validationCode":"func sessionExists(rt *runtimeServer, id string) bool {\n    rt.mu.RLock()\n    defer rt.mu.RUnlock()\n    _, ok := rt.sessions[id]\n    return ok\n}\n// call: if !sessionExists(rt, id) { recreate session before dispatch }","typeGuard":"func asSession(v any) (*agentSession, bool) {\n    s, ok := v.(*agentSession)\n    return s, ok && s != nil\n}","tryCatchPattern":"sess, err := rt.session(id)\nif err != nil {\n    var nfErr = err\n    if strings.Contains(nfErr.Error(), \"session not found\") {\n        // recreate the session, then retry once\n        if cerr := rt.createSession(id, params); cerr != nil { return cerr }\n        sess, err = rt.session(id)\n    }\n    if err != nil { return err }\n}","preventionTips":["Track session lifecycle client-side: never dispatch to an ID you have not opened or that you already closed.","Re-create sessions after any driver process restart; the registry is in-memory only.","Serialize close operations against in-flight dispatches on the same session ID.","Use one canonical non-empty session ID everywhere, since only closeSession maps \"\" to the legacy ID."],"tags":["go","session-management","state","hive-agent"],"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"}