Skip to content

Downloads: real failure codes on iOS, one start per download, ends after restart and text finishes reported - #785

Draft
posthog-eu[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixdownloads-report-ios-failure-reasons-a5b40a
Draft

posthog-eu[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixdownloads-report-ios-failure-reasons-a5b40a

Conversation

@posthog-eu

@posthog-eu posthog-eu Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Summary

Problem

  • People who download a model hit failures that we cannot diagnose. Model download is the first-run flow.
  • iOS DownloadError events have no reasonCode, so most iOS failures report error_code: error.
  • Text failures also lose their code on Android: the per-download watchDownload listener runs before the global one and marks the row failed without the native code.
  • The failures within 100 ms of the start are not caused by the duplicate start events. In the failure data, nearly all of them are on phones with less free space than the model plus the 0.5 GB margin. The pre-download free-space check refuses the start with disk_full, but startModelDownload, Whisper and the image path drop the code.
  • The duplicate starts a few ms apart are an analytics artifact: the queued placeholder row reports a start, and retryEntry with the native id reports a second start. This doubles starts for text and speech models.
  • A finished text download never sends model_download_finished: finalize removes the row without marking it complete. This is most of the low finish rate in the report.
  • A download that ends after an app restart reports nothing.
  • A failed AsyncStorage write (ENOSPC) from a zustand store change is an unhandled rejection.

Changes

  • iOS: reasonCode on both DownloadError events, with the same codes as Android DownloadReason (network_lost, network_timeout, disk_full, http_4xx, server_unavailable, user_cancelled, …).
  • iOS: an HTTP status ≥ 400 now fails the download with its code. Before, URLSession treated it as a finished download and the error page was saved as the model file.
  • JS: errors carry the native reasonCode, and failure paths pass known codes to setStatus (new downloadReasonCode() helper).
  • retryEntry from a queued: placeholder does not report a second start.
  • reportEnd reports only a change into the end status. A row from an earlier session reports its end from the row facts, without duration_ms. A user_cancelled from before the restart is skipped, because iOS re-queues interrupted downloads that way.
  • Text finalize calls setCompleted before the row is removed, so the finish is reported.
  • hydrationGatedStorage.setItem logs a failed write. Callers that await the promise still get the rejection.
Metric effect Expected direction
error_code = error share of failures Down sharply (iOS and Android text)
model_download_started count Down (about half for text and speech)
model_download_finished for text Up from almost zero
Failures without duration_ms New: ends after a restart

Warning

User-visible: iOS rows now get a reason code, the same as Android. For codes that are not retryable (disk_full, http_404, …), the Download Manager shows the code message and hides Retry. A 4xx/5xx response on iOS now fails the download and does not save the error page as the model.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (code change that neither fixes a bug nor adds a feature)
  • Chore (build process, CI, dependency updates, etc.)

Screenshots / Screen Recordings

No layout change. The failed-row text and the Retry button follow the new codes (see the warning above). No device check was done.

Checklist

General

  • My code follows the project's coding style and conventions
  • I have performed a self-review of my code
  • I have added/updated comments where the logic isn't self-evident
  • My changes generate no new warnings or errors

Testing

  • I have tested on Android (physical device or emulator)
  • I have tested on iOS (physical device or simulator)
  • I have tested in light mode and dark mode
  • Existing tests pass locally (npm test)
  • I have added tests that prove my fix is effective or my feature works

React Native Specific

  • No new native module without corresponding platform implementation (Android + iOS)
  • New native modules are added to the Xcode project build target (project.pbxproj)
  • No hardcoded pixel values — uses SPACING / TYPOGRAPHY constants from the theme
  • Styles use useThemedStyles pattern (not inline or static StyleSheet.create)
  • Animations/gestures work smoothly on both platforms
  • Large lists use FlatList / FlashList (not .map() inside ScrollView)
  • No unnecessary re-renders introduced (check with React DevTools Profiler if unsure)

Performance & Models

  • Downloads / long-running tasks report progress to the UI
  • File paths are resolved correctly on both platforms (no hardcoded / vs \\)
  • Large files (models, assets) are not committed to the repository

Security

  • No secrets, API keys, or credentials are included in the code
  • User input is validated/sanitized where applicable

Related Issues

None.

Additional Notes

Tests

  • New: hydrationGatedStorage (no unhandled rejection; it fails without the fix), downloadErrors (downloadReasonCode), analyticsOwner (one start for a queued row, restored ends reported once; it fails without the fix), Swift DownloadReasonCodeTests.
  • Checks I could not run in this sandbox:
    • The @offgrid/* packages come from the private ../shared checkout, which is not available here. I ran Jest with local stub packages. Across 248 download, store, hook, model and onboarding suites, the pass/fail results are identical before and after this change. The failures that remain come from the stubs.
    • tsc shows errors only for the missing packages. ESLint on the changed files shows no new problems.
    • Swift tests (npm run test:ios), Android tests and device checks need macOS or a device. Not run.

Agent context

  • The report hypothesis was that duplicate starts cause the ms failures. The event timelines do not support it: a fast failure usually follows a single start, and it matches low free space.
  • Interrupted — app closed failures for speech and image after a restart still have no code (error). They have no duration_ms, so a query can separate them.

Created with PostHog Desktop from this inbox report.

🤖 Generated with Claude Code

Origin

  • Error tracking: issue
  • Scout: signals-scout-first-report
  • First signal: 2026-11-04
  • Inbox report: open
  • Task started by: auto-start, after the report was rated P1 and ready to fix

…rt and text finishes are reported

- iOS DownloadError events send a reasonCode (network, disk full, HTTP status, cancelled). An HTTP error status fails the download instead of being saved as the model file.
- JS failure paths keep the reason code of the error (the free-space check sends disk_full).
- A queued placeholder row and its native id count as one start.
- A download that ends after an app restart reports its end, once, without a duration.
- A finished text download reports model_download_finished.
- A failed storage write from a store change is logged, not an unhandled rejection.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Generated-By: PostHog Desktop
Task-Id: eed443ce-b4a2-4988-811b-bedbdd221129
@posthog-eu
posthog-eu Bot requested a review from alichherawalla November 8, 2026 02:14
@coderabbitai

coderabbitai Bot commented Nov 8, 2026

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@sonarqubecloud

sonarqubecloud Bot commented Nov 8, 2026

Copy link
Copy Markdown

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants