Skip to content

Finish AssistActivity when it is stopped - #7756

Draft
gustavomorozi wants to merge 3 commits into
home-assistant:mainfrom
gustavomorozi:fix/assist-finish-on-stop
Draft

gustavomorozi wants to merge 3 commits into
home-assistant:mainfrom
gustavomorozi:fix/assist-finish-on-stop

Conversation

@gustavomorozi

@gustavomorozi gustavomorozi commented Nov 1, 2026 •

Copy link
Copy Markdown

Summary

Some ways of leaving the Assist screen only stop AssistActivity without finishing it: pressing Home, switching apps or opening recents, and locking the screen. (Tapping outside the sheet is not one of them: HAModalBottomSheet forwards that to onDismissRequest, and the activity already calls finish() there.) After one of those, its own wake word listener and pipeline keep running without a visible screen. On my device (Galaxy S25 Ultra, Android 37) the next "Hey Jarvis" was then often ignored (the first or second attempt did nothing and the third worked), and the background listener was not resumed, because the resume is only requested from onDestroy.

In the logcat, after leaving Assist this way, the engine inside the hidden screen kept running and detected the wake word with no Assist UI shown.

This finishes the activity in onStop, except on configuration changes, when it is already finishing, or when the microphone permission is missing (the permission dialog also stops the activity).

What I know and what I don't:

  • Tested by hand on the device: after the change, leaving Assist and saying "Hey Jarvis" again works, and the background listener is back in about 40 ms. A maintainer also confirmed this on a Pixel 6 for Home, app switch, recents and screen lock.
  • There is no unit test for AssistActivity and I did not add one.
  • Side effect: any stop (screen lock, switching apps) now closes Assist and its conversation. A maintainer noted this matches what Gemini does when the screen is locked.

This is separate from #7746 (a different 20 to 25 s Assist stall in the websocket queue, whose cause I could not confirm); this PR does not claim to fix it.

Checklist

  • New or updated tests have been added to cover the changes following the testing guidelines.
  • The code follows the project's code style and best_practices.
  • The changes have been thoroughly tested, and edge cases have been considered.
  • Changes are backward compatible whenever feasible. Any breaking changes are documented in the changelog for users and/or in the code for developers depending on the relevance.
  • I have read the Open Home Foundation AI Policy.

Select exactly one option that describes AI usage in this contribution:

  • I have not used AI for this contribution.
  • AI assistance was used for this contribution.
  • AI fully generated the code for this contribution, but I've reviewed and understood it before submitting and will respond without AI during review.

Screenshots

Link to pull request in documentation repositories

User Documentation: home-assistant/companion.home-assistant#

Contributor Documentation: home-assistant/contributors.home-assistant.io#

Any other notes

Verification: ktlint, detekt and the whole Pull Request workflow (lint, builds, unit, screenshot and automotive/Wear OS instrumentation tests) pass on my fork. The related wake word changes (an idempotent resume of the listener and a warm-up of a new engine) will follow as separate PRs, each independent of this one.

AI disclosure: I used an AI assistant (Claude Code) to help write this change and the description. I tested it myself on a Galaxy S25 Ultra.

Copilot AI balanced review requested due to automatic review settings November 1, 2026 23:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Ending conversations on all non-configuration stops requires UX-policy confirmation and broader validation of permission, app-switch, screen-lock, and wake-word transitions than the single-device testing provides.

No open issues 🎉

What changed in this PR

This PR finishes hidden Assist activities so their wake-word listener and pipeline do not keep running, allowing the background listener to resume. It does not address the separate stall reported in #7746.

Changes:

  • Calls finish() from onStop(), closing Assist when dismissed or otherwise hidden.
  • Skips finishing during configuration changes, when already finishing, or when microphone permission is missing.
File Description
app/​src/​main/​kotlin/​io/​homeassistant/​companion/​android/​assist/​AssistActivity.kt Adds guarded onStop() cleanup and documents its purpose.

Review effort: Balanced

@TimoPtr

TimoPtr commented Nov 3, 2026

Copy link
Copy Markdown
Member

I think it is ok to close when locking the screen that's the current behavior of Gemini.

@TimoPtr

TimoPtr commented Nov 3, 2026

Copy link
Copy Markdown
Member

Thanks for the fix. I tested it on a Pixel 6 and the change does what we need: pressing Home, switching apps through recents, or locking the screen now destroys the activity, the screen's own wake word engine is closed, and the background listener restarts about half a second later. The next "Hey Jarvis"
is picked up again.

One correction on the trigger though. Tapping outside the sheet does not go through this path. HAModalBottomSheet forwards scrim taps and back presses to onDismissRequest, which AssistSheet maps to onHide, and the activity already calls finish() there. On my device the activity is destroyed on
a scrim tap before onStop even runs. What this PR really fixes are the dismissals that stop the activity without going through the sheet: Home, app switch, recents, and screen lock.

Could you update the PR description and the comment in onStop to name those paths instead of "tapping outside"?

@TimoPtr
TimoPtr marked this pull request as draft November 3, 2026 13:17

@home-assistant home-assistant Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hello @gustavomorozi,

When attempting to inspect the commits of your pull request for CLA signature status among all authors we encountered commit(s) which were not linked to a GitHub account, thus not allowing us to determine their status(es).

The commits that are missing a linked GitHub account are the following:

Unfortunately, we are unable to accept this pull request until this situation is corrected.

Here are your options:

  1. If you had an email address set for the commit that simply wasn't linked to your GitHub account you can link that email now and it will retroactively apply to your commits. The simplest way to do this is to click the link to one of the above commits and look for a blue question mark in a blue circle in the top left. Hovering over that bubble will show you what email address you used. Clicking on that button will take you to your email address settings on GitHub. Just add the email address on that page and you're all set. GitHub has more information about this option in their help center.

  2. If you didn't use an email address at all, it was an invalid email, or it's one you can't link to your GitHub, you will need to change the authorship information of the commit and your global Git settings so this doesn't happen again going forward. GitHub provides some great instructions on how to change your authorship information in their help center.

    • If you only made a single commit you should be able to run
      git commit --amend --author="Author Name <email@address.com>"
      
      (substituting "Author Name" and "email@address.com" for your actual information) to set the authorship information.
    • If you made more than one commit and the commit with the missing authorship information is not the most recent one you have two options:
      1. You can re-create all commits missing authorship information. This is going to be the easiest solution for developers that aren't extremely confident in their Git and command line skills.
      2. You can use this script that GitHub provides to rewrite history. Please note: this should be used only if you are very confident in your abilities and understand its impacts.
    • Whichever method you choose, I will come by to re-check the pull request once you push the fixes to this branch.

We apologize for this inconvenience, especially since it usually bites new contributors to Home Assistant. We hope you understand the need for us to protect ourselves and the great community we all have built legally. The best thing to come out of this is that you only need to fix this once and it benefits the entire Home Assistant and GitHub community.

Thanks, I look forward to checking this PR again soon! ❤️

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants