skip to content

A note-taking phone app's new release crashes at every launch for users with one kind of local data; how should the app detect and break that crash loop?

level: seniorimportance: nice to knowfreq 40%

answer

  1. the next launch never comes
  2. a counter written before risky work
  3. a stable point resets it
  4. send the report first
  5. safe mode keeps unsynced notes

basics

~20 s

Count launches that end before reaching a stable point; after a set number, upload pending crash reports first, then start in a safe mode that skips the work that crashed while keeping every unsynced note.

solid answer

~50 s

In a launch crash loop the usual design fails twice: reports wait for an upload on the next launch, which dies too, and a remote fix fetched after the crash point never arrives. So the app keeps a **launch counter** on disk, written before any risky work and reset once the launch reaches a **stable point** — the first screen drawn and some seconds in the foreground — or the user leaves normally. When the counter passes a threshold the team sets, the app (1) uploads pending reports synchronously with a short timeout; (2) starts in **safe mode**: compiled-in configuration instead of cached remote values, rebuildable caches cleared, optional startup work skipped, and the record being processed at the last death set aside, never deleted; and (3) reports that it entered safe mode, so the loop shows up per version.

code

pseudocode · 22 lines
pseudocode
safe_mode_threshold = 2   # failed launches in a row, assumption

on_launch():
  state = disk.read("launch_state")
  if state.launch_in_progress:          # last launch never became stable or exited cleanly
    state.failed_launches = state.failed_launches + 1
  else:
    state.failed_launches = 0
  state.launch_in_progress = true
  disk.write("launch_state", state)     # before any risky work
  if state.failed_launches >= safe_mode_threshold:
    upload_pending_reports(timeout_seconds = 5)
    report_event("safe_mode_entered", app_version, suspect_record_id(state))
    start_safe_mode()
  else:
    start_normally()

on_stable_point_or_clean_exit():        # first screen + 10 s in the foreground, background work done, or user left
  state = disk.read("launch_state")
  state.launch_in_progress = false
  state.failed_launches = 0
  disk.write("launch_state", state)

go deeper

for a junior

Recall that an app crashing at every launch may never upload its own reports, and that the store cannot take an installed version back.

for a middle

Explain the launch counter: written before risky work, reset at a stable point or a clean exit, and checked against a threshold.

for a senior

Show what safe mode changes and what it must never touch, why reports are sent first, and how safe-mode entries feed per-version release health.

for a principal

Decide which recovery behaviour every team must build into the binary, and how much of a release's safety may rest on the installed app rather than on remote switches.

## Why a launch crash loop is invisible A **launch crash loop** is a version that crashes every time it starts for the users whose state triggers the bug — in a note-taking app, perhaps a note with an unusual embedded table that the new editor's restore step cannot parse, or a migration that fails half-way. Three parts of an otherwise sound design fail together: - **Reports never arrive.** The crash handler writes a report to disk and the app uploads it on the next launch — but the next launch dies at the same point, usually before the upload has started. - **Remote fixes never arrive.** If the crash comes before the app reads its remote configuration, a switch turned off on the server cannot reach it; if the cached configuration is itself the trigger, the fix is never read. - **The store cannot take the version back.** Halting or pausing a staged release limits who gets it next — on one store, anyone can still download it manually — and users who already have it keep it. So the version that hurts its users most can look quiet on the dashboards, while those users wait, with an app that will not open, for a release that fixes it. ## Detecting the loop 1. At the very start of launch, before any risky work, read the launch state from disk. If the previous launch never reached a stable point or a clean exit, add one to a **failed-launch counter**; otherwise reset it to zero. 2. Mark this launch as in progress and **write the state back** before going further. 3. When the launch reaches a **stable point** — the first screen drawn plus, say, ten seconds in the foreground, an assumption of this design — or the user leaves the app normally, clear the in-progress mark and reset the counter. 4. If the counter has reached a threshold the team sets, two failed launches in a row in this design, start in safe mode instead of normally. A background launch for sync or a widget counts as stable once its work finishes or its granted time runs out, so a widget refresh or a quick look at the app does not look like a failure. ## What safe mode does | Action | Why | Cost to accept | |---|---|---| | upload pending reports first, with a short timeout | makes the loop visible | a slightly slower launch on a poor network | | use compiled-in configuration, ignore cached remote values | the cached configuration may be the trigger | features that need remote values stay off | | clear rebuildable caches: search index, thumbnails, rendered previews | a corrupt cache is a common trigger | a slower first run while they rebuild | | skip optional startup work: restoring the last open note, deferred migrations | shortens the path to the first screen | the user lands on the note list | | set aside the record being processed at the last death | isolates one poisoned note | the note must stay recoverable | ## What safe mode must never do - **Delete unsynced notes.** Edits made offline exist only on this phone; wiping the database to start clean destroys them. Quarantine, never delete. - **Sign the user out** or wipe credentials without a reason; that adds a second problem to the first. - **Loop itself.** If safe mode also fails to reach a stable point, fall back to a minimal screen that lets the user export notes and contact support, rather than trying again. - **Stay forever.** Leave safe mode after a stable run, or when a new version is installed. ## Making the loop visible Entering safe mode is itself reported, tagged with the version and with what was set aside, so the loop appears per version even before the backlog of crash reports drains. That signal belongs in the same per-version release health as crashes and hangs. Deciding whether to halt the staged release or ship a fix is the release decision that reads it, and a remote switch helps only users whose launch gets as far as reading it — which is why the recovery has to live in the binary that is already installed.

  • Why not wipe all local data when a crash loop is detected, so the app starts clean?
    Offline edits exist only on the phone until they sync, so a wipe can destroy the only copy of a user's notes. Safe mode separates what can be rebuilt — caches, indexes, cached configuration — from user data, clears only the first, and sets suspect user records aside where they can be recovered or uploaded later.
  • How do you stop safe mode from hiding a broken release?
    Report every entry into safe mode as its own event, tagged with the version, and count it in the per-version release health beside crashes and hangs. A version that sends users into safe mode is failing, even if its crash count falls once safe mode stops the crashes.

A car's limp-home mode: after repeated faults, the engine computer starts the car with only its essential systems, so the driver can reach a garage, rather than refusing to start or erasing what it knows.

  • A crash at launch is reported on the next launch like any other crash.
  • Halting the staged rollout fixes users already stuck in the loop.
  • Safe mode should wipe local data so the app starts from a clean state.
  • A remote kill switch can always rescue users from a launch crash.
  • Any launch that ends quickly should count as a crash.