Skip to content

Fix the Android freeze after the timeline loads - #327

Merged
WillieCubed merged 2 commits into
mainfrom
claude/project-thread-mimk93
Nov 28, 2026
Merged

WillieCubed merged 2 commits into
mainfrom
claude/project-thread-mimk93

Conversation

@WillieCubed

Copy link
Copy Markdown
Collaborator

Requested by Willie · project thread

TL;DR

The app became unresponsive right after the timeline loaded. Every timeline day card rebuilt that day's location history from raw samples (added in a4d7129), and stay detection was quadratic: for each new sample it copied and sorted the accuracy of every earlier sample in the stay. The timeline also rebuilds its cards on any note, caption or transcript change, so the phone kept redoing that work on every core with heavy garbage collection.

Changes

  • fix(location-timeline): StayDetector.grow keeps a running sorted list of anchor accuracies (SortedAccuracies) and reads the median directly. That picks the same element as dynamicCoreRadius, so stays and visits are unchanged. StayDetectionCostTest reconstructs a 43,200-sample day (0.19s on the Studio) and checks that the running median matches the per-anchor radius on random inputs.
  • fix(timeline): TimelineDayHistory (a Koin single) reconstructs each day's history at most once every 5 minutes, holding up to 64 days, and shares it across timeline rebuilds and older pages. Tradeoff: places on a day card can lag new location samples by up to 5 minutes. Covered by TimelineDayHistoryTest.

Verification

This ran on the Studio, because this container gets HTTP 429 from Maven Central.

  • :client:domain:jvmTest passed: 1,406 tests, 0 failures. GoldenLocationBenchmarkTest, ReconstructLocationDayTest and the new tests all pass.
  • :client:domain:ktlintCheck and :app:android-main:assembleDebug passed.
  • Heavy-corpus run on the flagshipPhoneApi37 Gradle Managed Device: 2,000 notes with media, 172k location samples and Places beta on. The multi-core reconstruction burst after launch dropped from about 9s to under 3s. GCs in that window fell from 106 to 14. Max main-thread ping fell from 875ms to 292ms, with 0 skipped frames or Davey reports. There were no ANRs before or after the change.

Follow-ups and Next Work

  • At startup, one thread spends about 18s reading 90 days of location_logs. The suspect is LocationChangeMilestoneDetector. It's unrelated to the freeze and isn't changed here.
  • The test fixture OnboardingTestFixture(hasCloudAccount = true) crashes with "Session authorization changed".

Generated by Claude Code

…pegging the phone

Stay detection copied and sorted the reported accuracy of every sample in
a stay each time it checked the next sample, so a day spent in one place
cost time and memory that grew with the square of its samples. A phone
with months of background location spent minutes of CPU and constant
garbage collection rebuilding days after the timeline loaded, and the app
stopped responding while it did.

A growing stay now keeps its accuracies in order as it adds them and reads
the median directly, which picks the same value as before, so every stay
and visit comes out unchanged. A whole day sampled every two seconds now
reconstructs in well under the test's ten second budget.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QRSSFdu7yRMwr8c9upd3o3
… timeline loads

Since day cards started listing places from location history, building a
day read every location sample around it and reran stay detection. The
timeline rebuilds its days whenever a note, caption or transcript in its
window changes, and each rebuild reconstructed every visible day again,
so the phone stayed busy for as long as anything kept changing.

Each day's history is now reconstructed once and reused for five minutes
across rebuilds and older pages, for up to 64 days. A day card's places
can trail new location samples by up to five minutes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QRSSFdu7yRMwr8c9upd3o3
@WillieCubed WillieCubed self-assigned this Nov 28, 2026
@WillieCubed
WillieCubed marked this pull request as ready for review November 28, 2026 15:54

Copy link
Copy Markdown
Collaborator Author

The failure in Managed native restore (contracts) doesn't come from this PR. The emulator pair never started: managed-native-pair.py raised "The managed pair stopped before both drivers were ready" before any app code ran. The Native Android restore acceptance workflow has also failed on each of the last five PRs before this one (#322 through #326), and all of them have since merged. This PR only touches client/domain timeline and location-history code, which that harness doesn't reach before it fails.


Generated by Claude Code

@WillieCubed
WillieCubed added this pull request to the merge queue Nov 28, 2026
Merged via the queue into main with commit 1b5976c Nov 28, 2026
11 of 24 checks passed
@WillieCubed
WillieCubed deleted the claude/project-thread-mimk93 branch November 28, 2026 16:18

Copy link
Copy Markdown
Collaborator Author

The other "Managed native restore" jobs (work-restart, widget, missing-keys, d2d, publication, data-only, privacy, archive) failed the same way as contracts: RuntimeError: The managed pair stopped before both drivers were ready while the emulator pair was starting, before any test ran. This is the runner problem that also failed this workflow on #322-#326. This PR only changes client/domain (stay detection and timeline day history). Unit tests, static analysis, the release artifact, the server e2e tests and the iOS/Wasm checks all passed. The PR is now in the merge queue.


Generated by Claude Code

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.

2 participants