Repository navigation
Answer a sentence or webhook request right away in task.wait_until() - #936
craigbarratt wants to merge 1 commit into
Conversation
task.wait_until(sentence_trigger=...) or (webhook_handler=...) woke the waiting task, but nothing answered the request, so the voice assistant or HTTP client waited for the trigger's timeout (which is the same as wait_until's timeout), and then got "timed out" handling. No function runs to give a response, so answer as if a function had returned None: the default spoken response, or an empty 200. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@craigbarratt, thanks for picking this up. Yes, I was planning to fix it, but differently: rather than making request/response triggers work in I don't think That they work at all is a side effect: What I had in mind is to make it explicit: a One more thing with the current approach: a second request that arrives while the first one is being dispatched (e.g. the webhook body is still being read) finds the future already done and isn't answered, so it waits for the full That's how I see it, but I'm open to discussing it. Happy to go another way if you or @contagon see a good use for these triggers in |
|
@dmamelin I find your reasoning sound, and I'm happy to reject this PR in favor of your approach. Let's wait for @contagon to weigh in before proceeding. I'm trying to close out remaining issues so I can do a new release, since it has so many changes already. If we simply reject them now, we can add your proposed behavior later. |
|
I'm more on the fence if it should be supported in some form or another. I think there are some contexts where ...first half of automation
task.wait_until(sentence_trigger="ok, proceed to next step")
...second half of automationwhere you could allow an automation to continue based on a voice command. It probably makes less sense for This may not be a typical usecase though, so if we don't want to support it long-term that makes sense to me as well. I imagine there's workarounds that could be done if we choose not to. |
|
@contagon, thanks, that's a valuable point, and it brought back an old idea of mine. When I first saw #672, I thought it would be great to have a flow API for this kind of trigger, something like: def choose_name(flow):
...
return f"Turned on {flow.sentence}"
def confirm(flow):
if flow.sentence == "yes":
name = flow.prev.slots.name
...
return f"Turned on {name}"
else:
return SentenceFlow("What should I turn on then?", choose_name)
@sentence_trigger("turn on {name}")
def voice_on(sentence, name):
return SentenceFlow(f"Turn on {name}?", confirm)The function answers with a question, and the user's next sentence goes to the callback. The callback returns either the final response or another I never worked out the details, because it wasn't possible with the legacy trigger system, and I moved on to building |
|
@craigbarratt, I agree, there are a lot of changes already and it's time for a release. I can't provide my I also remember the outdated error messages in |
task.wait_until(sentence_trigger=...), new with #869, wakes the waiting task with the matched slots, but nothing answers the sentence. The voice assistant then waits for the sentence trigger's timeout, which is the same aswait_until'stimeout=, sotimeout=600leaves it waiting until Home Assistant gives up. After that, pyscript logssentence_trigger ... timed outand the assistant says "Done".task.wait_until(webhook_handler=...)has the same problem: the HTTP request waits for the timeout and gets a 504.No function runs to give a response, so
WaitUntilDecoratorManager.dispatch()now answers the request as soon as it wakes the waiter, as if a function had returnedNone: the default spoken response, or an empty 200. Only the trigger that fired answers. Other triggers don't answer requests, so they're unchanged.test_sentence_trigger_wait_untilandtest_webhook_handler_wait_untilcheck that the waiter gets the slots or payload and the request is answered within a second. Both fail on master.task.wait_until()argument list now includessentence_triggerandwebhook_handlerand says how they're answered.@dmamelin, you mentioned planning a fix for this; does this match what you had in mind? @contagon, does an immediate default answer make sense for
wait_until(sentence_trigger=...), or would you rather it be rejected inwait_untilfor now?🤖 Generated with Claude Code