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

Handle multiple intents with the same name (#2921) #235

Merged
merged 3 commits into from
Dec 13, 2022
Merged

Conversation

JarbasAl
Copy link
Member

@JarbasAl JarbasAl commented Nov 26, 2022

closes #233

Description

This implements Alternative 1 from MycroftAI#2920

* It will raise a `ValueError` if two named `IntentBuilder`s with the same name is registered

* If anonymous `IntentBuilder`s are used they will be automatically given an unique name

The handling for enable-disable intent was updated to make sure that the intent was removed from the list of registered_intents, for re-enabling it's moved to a list of detached_intents

How to test

Add a second @intent_handler() decorator to a method ensure both can be used to trigger the handler and that the handler is triggered exactly once.

* Add check for duplicate adapt intents

There are two cases, duplicated named intent and duplicated anonymous intent.

A named intent will cause a ValueError exception notifying the skill
author that there is a collision.

An anonymous intent will silently derive a new name and use that
instead of the default generated one.

* Add tests for intent collisions

* Make enable/disable intent handle the new exception

The enable/disable intent did not mark an intent as detached, instead it
remained in the list of intents after disabling in the IntentServiceInterface
to be retrieved when the intent should be re-enabled.

This moves detached intents into a list of detached intents to so they
won't cause the double enable exception.

* Add move logic to find if intent is detached

MycroftSkill.enable_intent() will now check if the intent is detached
before trying to re-enable it.

* Lock updates of intents

This should avoid some race conditions that may occur if multiple
threads tries to enable / disable intents
@JarbasAl JarbasAl added bug Something isn't working mycroft-sync cherry pick from upstream labels Nov 26, 2022
@JarbasAl JarbasAl requested a review from NeonDaniel November 26, 2022 16:00
@codecov
Copy link

codecov bot commented Nov 26, 2022

Codecov Report

Merging #235 (1f8f074) into dev (6ceb058) will increase coverage by 4.55%.
The diff coverage is 43.58%.

@@            Coverage Diff             @@
##              dev     #235      +/-   ##
==========================================
+ Coverage   50.35%   54.90%   +4.55%     
==========================================
  Files         119      156      +37     
  Lines       10077     9350     -727     
==========================================
+ Hits         5074     5134      +60     
+ Misses       5003     4216     -787     
Impacted Files Coverage Δ
mycroft/audio/__main__.py 0.00% <0.00%> (ø)
mycroft/client/enclosure/__main__.py 0.00% <0.00%> (ø)
mycroft/client/enclosure/mark1/arduino.py 0.00% <0.00%> (ø)
mycroft/client/enclosure/mark1/eyes.py 0.00% <0.00%> (ø)
mycroft/client/enclosure/mark1/mouth.py 0.00% <0.00%> (ø)
mycroft/client/speech/__main__.py 0.00% <0.00%> (ø)
mycroft/client/speech/hotword_factory.py 0.00% <0.00%> (-88.89%) ⬇️
mycroft/client/speech/service.py 0.00% <0.00%> (ø)
mycroft/client/speech/silence.py 0.00% <0.00%> (-42.86%) ⬇️
mycroft/client/text/__init__.py 0.00% <0.00%> (ø)
... and 151 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@JarbasAl JarbasAl marked this pull request as ready for review November 26, 2022 16:57
@@ -21,7 +21,7 @@
from inspect import signature
from itertools import chain
from os.path import join, abspath, dirname, basename, exists, isfile
from threading import Event
from threading import Event, Lock
Copy link
Member

Choose a reason for hiding this comment

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

I've started using RLock for applications like these in case different wrappers are added/refactored; so long as only one thread is mutating things at a time, we should be okay

@JarbasAl JarbasAl merged commit 80d702f into dev Dec 13, 2022
@JarbasAl JarbasAl deleted the port/mycroft_fix branch December 13, 2022 16:31
@JarbasAl JarbasAl mentioned this pull request Jan 10, 2023
23 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mycroft-sync cherry pick from upstream
Projects
None yet
Development

Successfully merging this pull request may close these issues.

port/fix/ intent name colision
3 participants