Add persistent background webhook uploads - #5703
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The reconciliation path cancels duplicate/background tasks without resolving any attached resolvers, which can leave callers waiting on promises/tasks that will never complete.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds an explicit “persisted background upload” path for webhook event delivery so background wakes can synchronously hand work off to URLSession, persist stable identifiers/metadata, and re-adopt/reconcile in-flight tasks after relaunch.
Changes:
- Introduces
startPersistedBackground+reconcilePersistedBackgroundinWebhookManagerwith request identifier tracking/adoption and stable background webhook URL selection. - Extends persisted task metadata (
WebhookPersisted) to include a stablerequestIdentifier, and adds a small public state enum for reconciliation results. - Adds targeted unit tests covering synchronous task creation, main-thread enforcement, URL selection, adoption, and HAAPI integration.
File summaries
| File | Description |
|---|---|
| Tests/Shared/Webhook/WebhookManager.test.swift | Adds tests for synchronous persisted background start, main-thread failure, URL preference, and reconciliation/adoption behavior. |
| Tests/Shared/Webhook/FakeWebhookManager.swift | Extends the fake to record calls and to support the new persisted-background API for tests. |
| Tests/Shared/HAAPIPersistentEvent.test.swift | Adds coverage ensuring HomeAssistantAPI.startPersistentEvent uses the persisted background path (not send). |
| Sources/Shared/API/Webhook/Networking/WebhookManager.swift | Implements persisted background start + reconciliation/adoption logic and tracks active/restored/completed persisted requests. |
| Sources/Shared/API/Webhook/Networking/URLSessionTask+WebhookPersisted.swift | Persists a stable requestIdentifier onto background tasks for adoption/reconciliation. |
| Sources/Shared/API/Webhook/Networking/PersistedBackgroundRequestState.swift | Adds a small public enum to represent reconciliation outcomes. |
| Sources/Shared/API/HAAPI.swift | Exposes startPersistentEvent / reconcilePersistentEvent wrappers over the new webhook manager APIs. |
| Sources/HANetworking/Sources/Server.swift | Adds a synchronous “preferred background webhook URL” accessor. |
| Sources/HANetworking/Sources/ConnectionInfo.swift | Implements URL selection that prefers remote endpoints for time-critical background delivery. |
Review details
Suppressed comments (1)
Sources/Shared/API/Webhook/Networking/WebhookManager.swift:532
- When cancelling duplicate persisted tasks, any existing
resolverForTaskentries should be resolved/rejected before callingcancel(). Otherwise the cancellation is ignored indidCompleteWithErrorand leaves unresolved promises hanging.
for duplicate in matchingTasks where duplicate != task {
duplicate.cancel()
}
- Files reviewed: 9/9 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
🟡 Changes recommended
Background execution protection currently starts after the asynchronous response-handling chain is already running.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 9/9 changed files
- Comments generated: 4
- Review effort level: Balanced
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5703 +/- ##
==========================================
+ Coverage 42.72% 42.89% +0.17%
==========================================
Files 1124 1124
Lines 77886 78346 +460
==========================================
+ Hits 33273 33609 +336
- Misses 44613 44737 +124
☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
AI Policy
Select exactly one option that describes AI usage in this contribution:
Summary
This PR adds a persistent background upload path for webhook events.
The changes:
This is the transport foundation split from #5629 at the maintainer's request. It does not change iBeacon detection or zone transition behavior by itself.
Screenshots
N/A — no user-interface changes.
Link to pull request in Documentation repository
Documentation: N/A — this adds internal delivery infrastructure and no new user-facing configuration.
Any other notes
This is the first independent foundation PR split from #5629.
Testing:
git diff --checkbundle exec fastlane lintbundle exec fastlane testApp-Debugsimulator buildThe remaining testing boxes will be checked after the corresponding Mac/Xcode commands complete successfully.