Skip to content

Fix background location updates not reaching the server - #6240

Open
bgoncal wants to merge 5 commits into
mainfrom
bgoncal/background-location-url-fallback
Open

bgoncal wants to merge 5 commits into
mainfrom
bgoncal/background-location-url-fallback

Conversation

@bgoncal

@bgoncal bgoncal commented Nov 5, 2026

Copy link
Copy Markdown
Member

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.

Summary

Background location updates could run out of background time before reaching the server. Requests sent while in the background now time out after 10 seconds, and when the internal URL can't be reached they are retried on the remote URL.

Fixes #6127

Screenshots

Link to pull request in Documentation repository

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

Any other notes

Copilot AI balanced review requested due to automatic review settings November 5, 2026 20:54

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.

🟡 Changes recommended

Unredacted webhook URLs and error details can expose secret tokens in exported diagnostics, and the background fallback can reuse an unreachable endpoint after a network change.

2 open issues
What changed in this PR

This PR aims to improve background location delivery by shortening webhook request timeouts and retrying unreachable internal endpoints through a remote URL.

Changes:

  • Limits regular-session webhook requests to a 10-second timeout.
  • Adds remote URL or cloudhook retries before falling back to the background session.
  • Adds tests for timeout behavior, endpoint selection, and retry failures.
File Description
Tests/​Shared/​Webhook/​WebhookManager.test.swift Adds coverage for background timeouts and remote fallback behavior.
Sources/​Shared/​API/​Webhook/​Networking/​WebhookManager.swift Implements shorter timeouts, remote retries, and fallback diagnostics.

Review effort: Balanced

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Unused L10n strings detected

Found 2 unused localization strings in the codebase.

Click to see details
Parsing Strings.swift...
Found 3119 L10n strings

Reading all Swift source code...
Read 16574654 characters of Swift code

Checking for unused strings...
Checked 100/3119 strings...
Checked 200/3119 strings...
Checked 300/3119 strings...
Checked 400/3119 strings...
Checked 500/3119 strings...
Checked 600/3119 strings...
Checked 700/3119 strings...
Checked 800/3119 strings...
Checked 900/3119 strings...
Checked 1000/3119 strings...
Checked 1100/3119 strings...
Checked 1200/3119 strings...
Checked 1300/3119 strings...
Checked 1400/3119 strings...
Checked 1500/3119 strings...
Checked 1600/3119 strings...
Checked 1700/3119 strings...
Checked 1800/3119 strings...
Checked 1900/3119 strings...
Checked 2000/3119 strings...
Checked 2100/3119 strings...
Checked 2200/3119 strings...
Checked 2300/3119 strings...
Checked 2400/3119 strings...
Checked 2500/3119 strings...
Checked 2600/3119 strings...
Checked 2700/3119 strings...
Checked 2800/3119 strings...
Checked 2900/3119 strings...
Checked 3000/3119 strings...
Checked 3100/3119 strings...

================================================================================
UNUSED STRINGS REPORT
================================================================================

Found 2 unused strings:


SETTINGS:
  - L10n.Settings.ConnectionSection.cloudOverridesExternal
    Key: settings.connection_section.cloud_overrides_external
    Line: 5496

TABBAR:
  - L10n.TabBar.More.homeAssistantSettings
    Key: tab_bar.more.home_assistant_settings
    Line: 8292

================================================================================
Total unused: 2
================================================================================

================================================================================
Copy-paste these keys into the "Lokalise: Delete Keys" workflow (keys input):
================================================================================
settings.connection_section.cloud_overrides_external,tab_bar.more.home_assistant_settings

To remove them, run the
Lokalise: Delete Keys
workflow — it deletes the keys from Lokalise and opens a PR removing them from
Localizable.strings and regenerating Strings.swift. Copy-paste these keys into the keys input:

settings.connection_section.cloud_overrides_external,tab_bar.more.home_assistant_settings

@codecov

codecov Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.01%. Comparing base (3ae70df) to head (bd2cd4f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6240      +/-   ##
==========================================
- Coverage   88.02%   88.01%   -0.02%     
==========================================
  Files        1307     1307              
  Lines       86638    86693      +55     
==========================================
+ Hits        76265    76300      +35     
- Misses      10373    10393      +20     
Files with missing lines Coverage Δ
...Shared/API/Webhook/Networking/WebhookManager.swift 93.31% <100.00%> (+1.19%) ⬆️

... and 11 files with indirect coverage changes

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

🟡 Changes recommended

The 10-second timeout can trigger remote and background retries after an action has already reached the server, potentially executing scripts or toggles up to three times.

4 open issues
2 resolved since last review

Review effort: Max

filesToRemove = [temporaryFile]
} else {
var urlRequest = urlRequest
urlRequest.timeoutInterval = Self.regularSessionTimeout
Comment on lines +355 to +356
Task {
await seal.fulfill(server.webhookURL())
Comment on lines 381 to +382
if Current.isBackgroundRequestsImmediate() {
promise = sendBackground()
} else {
Current.Log.info("in background, choosing to not use background session")
promise = sendRegular().recover(on: dataQueue) { error -> Promise<Void> in
Current.Log.error("in-background non-background failed: \(error)")
if error is HomeAssistantAPI.APIError {
// not worth retrying, since we got a real response that we didn't like
throw error
} else {
return sendBackground()
return sendBackground()
))

return sendRegular(remoteURL).get {
Current.connectivity.updateLastKnownNetworkState(NetworkState())
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.

Background location updates only occur after opening app, device_tracker remains home

2 participants