{"record":{"id":"5a5459e9001ac729","repo":"vxcontrol/pentagi","slug":"assistant-not-found","errorCode":null,"errorMessage":"assistant not found","messagePattern":"assistant not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/controller/aslogs.go","lineNumber":80,"sourceCode":"\t}\n\n\treturn flows, nil\n}\n\nfunc (aslc *assistantLogController) GetFlowAssistantLog(\n\tctx context.Context, flowID, assistantID int64,\n) (FlowAssistantLogWorker, error) {\n\taslc.mx.Lock()\n\tdefer aslc.mx.Unlock()\n\n\tflw, ok := aslc.flows[flowID]\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"flow not found\")\n\t}\n\n\taslw, ok := flw[assistantID]\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"assistant not found\")\n\t}\n\n\treturn aslw, nil\n}\n","sourceCodeStart":62,"sourceCodeEnd":85,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/controller/aslogs.go#L62-L85","documentation":"GetFlowAssistantLog looks up an in-memory FlowAssistantLogWorker by (flowID, assistantID) in the assistantLogController's flows map. When the flow map exists but the assistantID key is absent, it returns 'assistant not found'. This means the flow is tracked but no log worker has been registered for that assistant ID.","triggerScenarios":"Calling GetFlowAssistantLog with an assistantID that was never added to the flow's log map — e.g. an assistant that was never started, was deleted (map entry removed), belongs to a different flow, or the caller passes a stale/invalid assistant ID.","commonSituations":"A GraphQL/REST consumer requests assistant logs for an assistant created in another flow; a race where the assistant log worker registration hasn't completed yet; a client retries with an assistant ID after flow restart wiped in-memory workers.","solutions":["Verify the assistantID actually belongs to flowID (query the DB assistants table for that flow before calling).","Call ListFlowAssistantLogs for the flow first and pick an assistantID from the returned set.","Ensure AddAssistant/assistant log worker registration completed before fetching its logs.","Treat the error as not-found (HTTP 404) rather than a server fault, and refresh the client's assistant list."],"exampleFix":"// before\naslw, err := aslc.GetFlowAssistantLog(ctx, flowID, assistantID) // panics path on unknown IDs\nlog.Println(aslw)\n// after\nlogs, err := aslc.ListFlowAssistantLogs(ctx, flowID)\nif err != nil { return err }\nfor _, l := range logs {\n    if l.GetAssistantID() == assistantID { return use(l) }\n}\nreturn fmt.Errorf(\"assistant %d not found in flow %d\", assistantID, flowID)","handlingStrategy":"validation","validationCode":"logs, err := aslc.ListFlowAssistantLogs(ctx, flowID)\nif err != nil { return err }\nvar target FlowAssistantLogWorker\nfor _, l := range logs {\n    if l.GetAssistantID() == assistantID { target = l; break }\n}\nif target == nil { return ErrAssistantNotFound }","typeGuard":"func hasAssistant(logs []FlowAssistantLogWorker, id int64) bool {\n    for _, l := range logs { if l.GetAssistantID() == id { return true } }\n    return false\n}","tryCatchPattern":"aslw, err := aslc.GetFlowAssistantLog(ctx, flowID, assistantID)\nif err != nil {\n    if strings.Contains(err.Error(), \"not found\") { return http.StatusNotFound }\n    return http.StatusInternalServerError\n}","preventionTips":["Always fetch the flow's assistant log list before targeting a specific assistant ID","Treat not-found map lookups as 404, not 500","Refresh client-side assistant IDs after flow reloads or server restarts"],"tags":["go","not-found","in-memory-store","assistant-log"],"backgroundTag":"entity-not-found","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}