Repository navigation
Sync body measurements from NutriTrace - #123
Open
kgenerozov wants to merge 2 commits into
Open
kgenerozov wants to merge 2 commits into
kgenerozov wants to merge 2 commits into
Conversation
kgenerozov
marked this pull request as draft
September 26, 2026 16:50
kgenerozov
force-pushed
the
feat/nutritrace-body-sync
branch
from
September 26, 2026 17:25
bf66885 to
043996b
Compare
kgenerozov
marked this pull request as ready for review
September 26, 2026 17:30
kgenerozov
marked this pull request as draft
September 29, 2026 14:09
kgenerozov
force-pushed
the
feat/nutritrace-body-sync
branch
from
September 29, 2026 14:35
49c68da to
b1b7497
Compare
kgenerozov
marked this pull request as ready for review
September 30, 2026 04:17
kgenerozov
force-pushed
the
feat/nutritrace-body-sync
branch
from
October 5, 2026 04:20
b1b7497 to
1d23e1a
Compare
kgenerozov
force-pushed
the
feat/nutritrace-body-sync
branch
from
November 13, 2026 06:37
1d23e1a to
1f6612f
Compare
NutriTrace already records weight and body fat from a scale or Health Connect, so the same numbers can fill LiftTrace's body stats without being typed again. The import is opt-in, reads only through NutriTrace's body-composition API, and asks for one exact source: measurements from two providers are never combined. The source is fixed on the server by the first import and every imported write carries it, so a second tab, a connection switch or an older client cannot move the history to another provider. Manual circumference values and every other field the user keeps in LiftTrace are left as they are.
A connection test saved its URL, token and verified flag through the debounced settings store, so opening the Diary or another tab within 600 ms could read the old values: a body import could be attributed to the connection that was replaced, or a workout could go to the wrong instance. A tested connection is now written one key at a time, disabled first and enabled last, and the save is awaited before the page reports success. Connection changes and the body import share one queue, and every write re-checks the signed-in account, so neither can act on the other's state or on the next account's settings.
kgenerozov
force-pushed
the
feat/nutritrace-body-sync
branch
from
November 13, 2026 06:43
1f6612f to
0a42225
Compare
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.
Summary
NutriTrace already records weight and body fat from a scale or Health Connect, so the same numbers can fill LiftTrace's body stats without being typed again. This adds an opt-in import from one exact NutriTrace source and hardens the connection and persistence around it: a connection is one atomic server transition with a monotonic compare-and-set version, the import provenance is server-owned, and a device, tab or offline queue can no longer leave the two half-saved.
Two commits, rebased onto
dev@97b5da1(v1.5.0-dev01-4-g97b5da1):48d436bSync body measurements from NutriTrace0a42225Persist NutriTrace federation state immediatelyWhat changes
Body-measurement import (opt-in)
GET /api/nt/body-compositionis a narrow proxy to NutriTrace's native read API (mcp:read, NutriTrace must run withPUBLIC_API_ENABLED=1). Onlystart,endandsourceare forwarded; the bearer token stays on the server.X-LT-Nt-Read-Id(10 minutes, per account, in-process). The import must present it when it claims the provenance.BEGIN IMMEDIATE). A later different source or connection is refused with the fixed pair.null, an empty string, booleans, structures,0, and out-of-range numbers — are never written as0 kgor0%.Connection persistence
PUT /api/nt/federation-connectionverifies the address and token and writes URL, token, identity, scopes andenabledin one SQLite transaction. Either the server holds the whole new connection or the whole previous one — two tabs can no longer interleave into one Save's address with another's identity, and a failed step cannot leave a new token behind an old address.GET /api/nt/federation-connectionreturns the saved connection without the token, for the Settings page and for a client whose Save answer was lost.fingerprint(address + write-only token + identity) says whether the stored identity still belongs to the stored credentials. The token never reaches the client, so a separate settings write cannot forge it; the connection fails closed until it is saved again.versionis a monotonic, server-owned counter bumped by every transition, including OFF and A -> B -> A. It is the compare-and-set value: a Save names the version it started from (ifVersion), so a tab that still shows an older connection is refused instead of turning federation back on or replacing a newer Save. Because the counter is server-owned, a settings write cannot rewind it.409 connection-changedcarries the current connection. The page reconciles throughGETon a 409 or any indeterminate answer (lost reply, timeout, offline ambiguity), publishing what the server actually saved instead of assuming failure. The token is never rolled back locally: the server never sends it, so the page keeps the placeholder.ifVersion) is still accepted, for compatibility._flushQueue()deletes oldntFederationEnabled/ntBodySyncEnabledwrites instead of sending them, so an upgrade cannot replay a decision the user was told had failed.GET /api/sync/pullcarriesnt_body_provenanceas its own field,nullincluded. An Android foreground pull therefore rebuilds the device cache from the server, or clears the markers and the six-hour throttle when Clear Data on another device released the claim. Clear Data also deletes the throttle row on the server.ntConnectionVersionandntConnectionScopesare server-owned:403 reserved-settingon the generic settings API and never device-pushed.Historical safety
ntBodyProvenanceand the legacy pair) are refused by the generic settings API (403 reserved-setting) and are not device-synced.nutritrace_body_composition_syncand the one-way alias normalisation (bodyFat/body_fat) are unchanged.Validation
On the rebased tree (
97b5da1+ two commits):npm test— 2000 tests, 1999 pass, 1 skipped (SQLite driver), 0 failnpm run i18n:check— OK (English source has 2304 keys; other locales remain informational)npm run build— OK (Vite + PWA precache)git diff --check— cleangit apply --checkof the artifact on a clean97b5da1— OK; the focused federation/offline/secret tests on that clean apply — 184 pass, 0 fail.scripts/nt-federation-routes.test.jsagainst the real server and a NutriTrace stub:enabled, and refuses body reads until it is verified againntFederationEnabled/ntBodySyncEnabledis dropped, not replayed, after the updateNot covered / still consciously limited:
ntBodySyncedSource/ntBodySyncedConnectionIdentityrows from earlier revisions of this PR are still adopted as the first claim. Removing that would drop the safety net for anyone who ran an earlier build; it can be a follow-up once the branch has shipped.GET /api/settingsremains readable for the connection identity/version; only writes, device sync and receipts are guarded. A client can read the current identity, but the fingerprint cannot be forged without the write-only token.connection-unverified/connection-mismatch/read-identity-mismatch) rather than using a mixed pair; only the failure mode is racy, not the attribution.enabled(plus an identity), not by comparing the typed token or a revision. This is the known minor noted by review and was left untouched.409carriesconnectionand the API client propagates it, but the page still reconciles with a freshGETrather than using that body directly. This is the known minor noted by review and was left untouched.