Repository navigation
fix(insights): restrict the scoped feature bulk read to the requested blocks' types - #1399
Merged
Merged
Conversation
2 tasks done
…cannot starve sparse ones The bulk measurement reads behind the insight features, the Coach snapshot timelines, the mood cross-metric pairing, the correlation windows and the weight and blood pressure status cards read newest-first across all their types under a single row cap. On an account with a wearable heart rate stream the cap filled within hours, and every weight, blood pressure or other sparse reading fell out of the read, so blocks reported no data for metrics with years of it. All of them now go through one read that descends the live partial index once per type, each type stopping at its own cap. The feature extraction and the Coach snapshot cap each type at 6000, so a block built from one type's read equals the block the full read builds (worst case 72,000 rows for the twelve feature types). The mood, correlation and status reads keep their old totals and share them fairly: each type keeps at least its share, a sparse one all of its window. The feature context's data span now comes from index probes over every type in the window rather than from the capped rows, and its measurement count is the readings the blocks were built from. Refs MBombeck#1398
Owner
|
@mailuminatti Thanks again for this, the diagnosis was spot on. I pushed one commit on top of your branch: the full build and the Coach snapshot used the same all-type cap, so on an account like yours they missed weight and blood pressure too. The bulk reads now cap per type, which also keeps the scoped block identical to the full build's, as the comments promise. Your commits stay as they are. There's an integration test with a dense pulse stream and sparse weight and BP now. I'll merge once CI is green. |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1398.
Problem
get_metric_series(and the single-metric Coach read behind it) returned{ present: false, reason: "unavailable_in_scope" }for sparse metrics on an account with a dense PULSE stream, on every window. The scoped snapshot builds its section viaextractFeatures(userId, { only }), whose bulk measurement read is newest-first across all types withtake: FEATURE_MEASUREMENT_ROW_CAP(6,000). On the reporting account (~824,000 PULSE rows in 30 days) the newest 6,000 rows span only a few hours, sobyType("WEIGHT")saw zero rows, no weight block was built, and the availability probe — which uses uncapped aggregates and sees the data — classified the miss asunavailable_in_scope.Change
When
extractFeaturesis called withonly, the bulk read now also filters on the requested blocks' own measurement types (SCOPED_BLOCK_TYPES, via the already-computedallTimeTypes), under the same newest-first cap. The cap's purpose is unchanged — it still bounds the read at 6,000 rows — but the rows are the block's own, so a dense type can no longer starve a sparse one out of a scoped read. Unscoped reads (noonly) are byte-for-byte the same query as before. The two comments that described the all-type behaviour are updated to match.Testing
Deployed on a self-hosted v1.47.1 instance carrying this change (the affected code is identical between v1.47.1 and current main):
get_metric_seriesfor weight returnedunavailable_in_scopeforlast7days,last30days,last90days,lastYearandallTime.present: true(server-side durations 0.4–1.2 s), with aggregates matching the availability probe's figures (351 readings, 2021-01-23 to 2026-11-11).get_metric_seriesfor pulse andget_medication_scheduleverified unchanged and working.