{"record":{"id":"108b21060877c15d","repo":"vxcontrol/pentagi","slug":"failed-to-get-vector-store-log-w","errorCode":null,"errorMessage":"failed to get vector store log: %w","messagePattern":"failed to get vector store log: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/controller/vslog.go","lineNumber":89,"sourceCode":"\t\tTaskID:    database.Int64ToNullInt64(taskID),\n\t\tSubtaskID: database.Int64ToNullInt64(subtaskID),\n\t})\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"failed to create vector store log: %w\", err)\n\t}\n\n\tvslw.pub.VectorStoreLogAdded(ctx, vsLog)\n\n\treturn vsLog.ID, nil\n}\n\nfunc (vslw *flowVectorStoreLogWorker) GetLog(ctx context.Context, msgID int64) (database.Vecstorelog, error) {\n\tmsg, err := vslw.db.GetFlowVectorStoreLog(ctx, database.GetFlowVectorStoreLogParams{\n\t\tID:     msgID,\n\t\tFlowID: vslw.flowID,\n\t})\n\tif err != nil {\n\t\treturn database.Vecstorelog{}, fmt.Errorf(\"failed to get vector store log: %w\", err)\n\t}\n\n\treturn msg, nil\n}\n","sourceCodeStart":71,"sourceCodeEnd":94,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/controller/vslog.go#L71-L94","documentation":"GetLog wraps errors from the GetFlowVectorStoreLog SQLC query, which selects a vector-store log row by both ID and FlowID. Most commonly this wraps sql.ErrNoRows when the message ID does not exist or belongs to a different flow; it can also wrap connectivity or context errors.","triggerScenarios":"Calling GetLog(ctx, msgID) with an ID that was never created, was deleted, or belongs to another flow (the query scopes by vslw.flowID); the DB is unreachable; ctx expired.","commonSituations":"Frontend requesting a log entry from a stale subscription after the flow was cleaned up; cross-flow ID reuse assumptions; pagination clients holding onto old IDs after data retention cleanup.","solutions":["Check errors.Is(err, sql.ErrNoRows) first and treat it as a not-found case, not a server failure.","Confirm the msgID belongs to the flow whose worker you are using.","Verify DB connectivity if the wrapped error is a connection error.","Surface a typed not-found error to the GraphQL layer instead of leaking the raw DB error."],"exampleFix":"// before\nmsg, err := worker.GetLog(ctx, msgID)\nif err != nil { return err }\n// after\nmsg, err := worker.GetLog(ctx, msgID)\nif err != nil {\n    if errors.Is(err, sql.ErrNoRows) {\n        return graphql.ErrorNotFound(\"vector store log %d not found in flow\", msgID)\n    }\n    return fmt.Errorf(\"get log: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"if msgID <= 0 {\n    return fmt.Errorf(\"invalid vector store log id %d\", msgID)\n}\n// ensure the ID came from the same flow you're querying\nif !msgBelongsToFlow(msgID, flowID) {\n    return database.Vecstorelog{}, sql.ErrNoRows\n}","typeGuard":"func isLogNotFound(err error) bool {\n    return errors.Is(err, sql.ErrNoRows) ||\n        strings.Contains(err.Error(), \"failed to get vector store log\") && errors.Is(err, sql.ErrNoRows)\n}","tryCatchPattern":"msg, err := worker.GetLog(ctx, msgID)\nswitch {\ncase err == nil:\n    use(msg)\ncase errors.Is(err, sql.ErrNoRows):\n    renderNotFound(msgID) // expected: stale ID or wrong flow\ndefault:\n    return fmt.Errorf(\"get vector store log: %w\", err) // real DB failure\n}","preventionTips":["Only pass msg IDs obtained from the same flow's PutLog/subscription events.","Treat sql.ErrNoRows as a 404, not a 500, in the API layer.","Refresh stale IDs in the frontend after flow cleanup events.","Log the wrapped cause separately for observability."],"tags":["go","database","not-found","postgres"],"backgroundTag":"record-not-found","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}