Skip to content

Skip Google rawSignals when the export also has semanticSegments - #3279

Open
Freika wants to merge 2 commits into
devfrom
fix/google-takeout-rawsignals-overlap
Open

Skip Google rawSignals when the export also has semanticSegments#3279
Freika wants to merge 2 commits into
devfrom
fix/google-takeout-rawsignals-overlap

Conversation

@Freika

@Freika Freika commented Aug 1, 2026

Copy link
Copy Markdown
Owner

Reported by a user whose 204 MB Google phone Timeline export produced "ghost tracks": opening 4 July showed bike commutes from 2 and 3 July, days he was home all day.

Cause

Google switched on the rawSignals stream around mid-June 2026 and now emits both formats in the same export. In the reported file:

Section Coverage Size
semanticSegments 2011-02-13 → 2026-07-15 38,900 segments
rawSignals 2026-06-15 → 2026-07-15 64,556 positions

These are not duplicate rows — only 739 of 64,556 raw positions share an exact (timestamp, lat, lon) with a timelinePath point, so the unique index legitimately cannot dedupe them (timelinePath is minute-snapped to :00 seconds; rawSignals land on arbitrary seconds).

The damage is temporal density, not row count. Track segmentation splits only on time gaps (minutes_between_routes, default 30). The two sources are sampled independently, so their gaps do not coincide and merging them cancels nearly all of them. Measured on the reporter's real 28 Jun – 7 Jul data:

Input Gaps > 30 min Tracks
semanticSegments only 22 23
both merged (current behaviour) 1 2

Tracks::IndexQuery returns any track overlapping the requested range and the serializer emits its full unclipped geometry, so one 10-day mega-track paints its entire path onto every day it touches.

Fix

Skip rawSignals when semanticSegments is present. The decision comes from a chunked byte scan, because Oj's SAJ streaming cannot know a later key exists and JSON key order is not guaranteed. The section is discarded at array_start, so its entries are never materialised into hashes.

Presence of the key does not guarantee usable data — Google's server-side aggregation can lag behind fresher on-device signals. Skipping on key presence alone would make an export with an empty semanticSegments array import nothing at all while still reporting success, so the skipped signals are replayed when the aggregated pass yields no points.

The user is told how many signals were skipped. Dropping most of a file silently is indistinguishable from data loss, and the count is free — the handler counts entries of the discarded section without building them.

Verification

Real-data behaviour, reporter's export:

real slice (both formats)      points=  9928  tracks= 23  notified=yes
empty semantic + rawSignals    points=     2  tracks=  1  notified=no
rawSignals only                points=     2  tracks=  1  notified=no
key straddling scan boundary   points=     2  tracks=  1  notified=yes

Before this change the same slice imported 31,276 points as 2 tracks; it now imports 9,928 as 23.

Also covered: a "semanticSegments" literal appearing inside a value does not false-positive, and a key straddling the 1 MB scan boundary is still found.

1202 examples, 0 failures (three consecutive runs). RuboCop clean on changed files.

Notes

  • Exports carrying only rawSignals are unaffected and still import.
  • Existing imports already contain merged mega-tracks; re-running Tracks::Reprocessor for affected users is not part of this PR.
  • The second commit repairs google_phone_takeout_invalid_utf8_spec.rb:40, which stubbed download_with_verification while the importer calls download_to_temp_file — it fails on dev today.

Freika added 2 commits August 1, 2026 17:00
Exports taken after mid-June 2026 ship the raw signal stream alongside the
aggregated timeline for the same period. The two are sampled independently, so
their gaps do not coincide; merging them erased the pauses track segmentation
splits on and welded whole weeks into one track, which then drew journeys onto
every day that track overlapped.

Skip rawSignals when semanticSegments is present, decided by a chunked byte scan
so key order in the document does not matter. The section is discarded at
array_start, so its entries are never materialized.

Presence of the key does not guarantee usable data, so replay the skipped signals
when the aggregated pass yields no points — otherwise an export with an empty
semanticSegments array would import nothing at all and still report success.
Report the skipped count to the user, since dropping most of a file silently is
indistinguishable from data loss.
The storage-download example stubbed download_with_verification while the
importer calls download_to_temp_file, so the spec failed on any run.
@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 96c3a64b-0ee3-4d7e-ac70-a4972d10815f

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

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

Comment @coderabbitai help to get the list of available commands.

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.

1 participant