Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace / by _ in name to avoid issue when writing the cache file. #3133

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from

Conversation

gmsoft-tuxicoman
Copy link

@gmsoft-tuxicoman gmsoft-tuxicoman commented Sep 30, 2022

Description

The latest version of homeassistant skills builds an intent file and tries to register it.
However this fails with the following error message :

FANN Error 2: Unable to open configuration file "/home/mycroft/.local/share/mycroft/intent_cache/homeassistant.mycroftai:{/tmp/mycroft/cache/HomeAssistantSkill/tracker}.intent.net" for writing.

How to test

Install the latest homeassitant skill (HEAD).

Contributor license agreement signed?

CLA (7-23-2017)

@devops-mycroft devops-mycroft added the CLA: Needed Need signed CLA from https://mycroft.ai/cla label Sep 30, 2022
@devops-mycroft
Copy link

Hello, @gmsoft-tuxicoman, thank you for helping with the Mycroft project! We welcome everyone
into the community and greatly appreciate your help as we work to build an AI
for Everyone.

To protect yourself, the project, and users of Mycroft technologies we require
a Contributor Licensing Agreement (CLA) before accepting any code
contribution. This agreement makes it crystal clear that along with your
code you are offering a license to use it within the confines of this project.
You retain ownership of the code, this is just a license.

Please visit https://mycroft.ai/cla to initiate this one-time signing. Thank
you!

@gmsoft-tuxicoman
Copy link
Author

CLA (7-23-2017)

@devops-mycroft
Copy link

devops-mycroft commented Sep 30, 2022

Voight Kampff Integration Test Succeeded (Results)

@krisgesling
Copy link
Contributor

Thanks for flagging this Guy,

Also CLA received and you've been added to our list of awesome contributors - our friendly bot will update that shortly.

Based on the error message you got I'm wondering if we should use the filename rather than entity_file that may be a full path like in this situation. It would cause an issue if a single Skill tried to register two entity files with the same name but different paths, but is that too much of an edge case to worry about?

I'm interested if others want to chime in on this too?
@JarbasAl it looks like OVOS has got the same issue.

@devs-mycroft devs-mycroft added CLA: Yes Contributor License Agreement exists (see https://github.com/MycroftAI/contributors) and removed CLA: Needed Need signed CLA from https://mycroft.ai/cla labels Oct 4, 2022
@gmsoft-tuxicoman
Copy link
Author

The only downside on using the complete path is that you might run into the maximum filename length on the OS.
Other that that, it completely avoids collision which might be more difficult to troubleshoot.

@forslund
Copy link
Collaborator

forslund commented Oct 4, 2022

Couldn't this run into collisions with files with an actual _? would it be more correct to use url-encoding or some such in the "name"? It's sort of unlikely but a file like _tmp_thing.entity in the locale folder could get the same name as a /tmp/thing.entity file...

In addition could the same issue also exist on L1022? or is the logic different enough there to not cause this issue?

@gmsoft-tuxicoman
Copy link
Author

Indeed this collision could happen too. Another option is to hash the filename but it makes it harder to identify the right cache file when looking it up in the directory.

@forslund
Copy link
Collaborator

forslund commented Oct 4, 2022

At one point there was actually a hash but it was changed for this exact reason :)

@gmsoft-tuxicoman
Copy link
Author

Then the solution is evident, filename + 8-16 bytes hash :)

@gmsoft-tuxicoman
Copy link
Author

Please review the last commit. It uses basename_<full_path_hash> so that collisions are not possible.

@forslund
Copy link
Collaborator

forslund commented Oct 9, 2022

I think it looks like a good idea. The lint tool thinks the line is too long however and I wonder if a specific hash from hashlib should be used instead of the hash() since the latter can change between python versions (afaik)

@gmsoft-tuxicoman
Copy link
Author

I'm not sure it's a big deal if hash() changes between versions since those cache files gets regenerated each time.

@forslund
Copy link
Collaborator

I was under the impression the cache files remained, at least the .intent files are cached and reused at a later date, and the files generated by the entity-files has the same date as the corresponding .intent file as far as I can see. But I'm not 100% sure on the inner workings of Precise so I may very well be wrong.

In any case, I still think it would be nice if the files guaranteed the same hash, even if the files are generated anew on each startup a change in the hash would cause a "duplicate" file.

forslund
forslund previously approved these changes Oct 16, 2022
Copy link
Collaborator

@forslund forslund left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from the linting issue (non-aligned followup row which needs to be fixed to satisfy the autobots) I think this looks great.

@forslund
Copy link
Collaborator

You should be able to check the file with flake8 locally

@gmsoft-tuxicoman
Copy link
Author

Thanks for the tip !

@gmsoft-tuxicoman
Copy link
Author

Anything else you need to get this merged ?

@forslund
Copy link
Collaborator

forslund commented Nov 10, 2022

Seems like there are some unittests failing now. Let me know if you need help with them

@forslund
Copy link
Collaborator

Seems to be a tiny lint issue now :(

@gmsoft-tuxicoman
Copy link
Author

Finally ! :)

forslund
forslund previously approved these changes Nov 10, 2022
@gmsoft-tuxicoman
Copy link
Author

Any luck getting this merged ?

@forslund
Copy link
Collaborator

I think it's good to merge, @krisgesling does the Mycroft team agree?

@krisgesling
Copy link
Contributor

Grrr - I resolved a merge conflict and now the Github Action is failing.

I'll need to fix that first :(

@gmsoft-tuxicoman
Copy link
Author

@krisgesling any luck ?

@gmsoft-tuxicoman
Copy link
Author

@krisgesling any luck merging this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA: Yes Contributor License Agreement exists (see https://github.com/MycroftAI/contributors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants