From d1fdde149ebcbb816cc95d9cad61ec5ec31c7e93 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 6 Nov 2026 23:41:59 +0000 Subject: [PATCH 01/60] Plan the 2.2.0 Open Wearables pull. Record the proposed command, decisions D198 through D202, and the 0.11.0 study. The maintainer has not approved a build. Co-authored-by: Michael Whitham --- AGENTS.md | 2 +- build-history/README.md | 5 + .../v2.2.0/appendix/open-wearables-api.md | 188 +++++++++ build-history/v2.2.0/decisions.md | 281 +++++++++++++ build-history/v2.2.0/progress.md | 19 + build-history/v2.2.0/spec.md | 397 ++++++++++++++++++ 6 files changed, 891 insertions(+), 1 deletion(-) create mode 100644 build-history/v2.2.0/appendix/open-wearables-api.md create mode 100644 build-history/v2.2.0/decisions.md create mode 100644 build-history/v2.2.0/progress.md create mode 100644 build-history/v2.2.0/spec.md diff --git a/AGENTS.md b/AGENTS.md index 6ad1674e..fde98c9c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -14,7 +14,7 @@ Read these before making decisions — they are the project's memory and outrank 2. **`build-history/v0.2.0/spec.md`** — the format revision that supersedes parts of it: sidecar series, vendor scores, per-modality distance, distinct temperature signals, and the importers. 3. **`build-history/v1.0.0/spec.md`** — the approved SQLite build plan: SQLite is the live local record and JSON is the complete portable package. D101 rejects 0.x file migration, so runtime implementation begins with the v1 domain schemas. 4. **`build-history/v2.0.0/spec.md`** — version 2.0.0. The program, the record, and the database share that version. Garmin and Strava imports and calculation skill files are described there. -5. **`build-history/v2.1.0/spec.md`** — version 2.1.0, the current version. Mapping files (`mappings/`, `ath import --mapping`), migration step 4, and `field_basis` are described there. +5. **`build-history/v2.1.0/spec.md`** — version 2.1.0, the current version. Mapping files (`mappings/`, `ath import --mapping`), migration step 4, and `field_basis` are described there. A plan for 2.2.0 lives in `build-history/v2.2.0/`. It is not the software until the maintainer approves it and a later pull request builds it. 6. **`build-history/*/decisions.md`** — every decision with the alternatives that were rejected and why (D1 onward, numbered continuously across version folders). Do not relitigate these without new information; if a decision is superseded, append a new D-number in the current version's file. Don't rewrite earlier entries. Don't create addendum files. 7. **`build-history/*/appendix/`** — the long-form studies that informed decisions. Link each study from its D-number. Do not move the decision into the appendix, and do not trim the study down to the decision line. 8. **`build-history/*/progress.md`** — what's done and what's next. diff --git a/build-history/README.md b/build-history/README.md index 173ff2bb..08acbfa0 100644 --- a/build-history/README.md +++ b/build-history/README.md @@ -40,10 +40,15 @@ build-history/ - [Version 2.1.0 specification](v2.1.0/spec.md) - [Version 2.1.0 decisions](v2.1.0/decisions.md) - [Version 2.1.0 progress](v2.1.0/progress.md) +- [Version 2.2.0 plan](v2.2.0/spec.md) +- [Version 2.2.0 decisions](v2.2.0/decisions.md) +- [Version 2.2.0 progress](v2.2.0/progress.md) Version 2.1.0 is the software now. The program, the record, and the database use that number. +Version 2.2.0 is a plan. It is not built. + ## Why Specs written in chat threads and planning sessions evaporate. Six months from now, "why is there no MCP server?" or "why TypeScript?" should be answerable by reading this folder, not by archaeology. Each version's `decisions.md` records the alternatives that were considered and rejected, because the rejected options are the part everyone forgets. Each version's `appendix/` holds the long-form research those decisions rest on. diff --git a/build-history/v2.2.0/appendix/open-wearables-api.md b/build-history/v2.2.0/appendix/open-wearables-api.md new file mode 100644 index 00000000..19d832e5 --- /dev/null +++ b/build-history/v2.2.0/appendix/open-wearables-api.md @@ -0,0 +1,188 @@ +# Open Wearables, as checked on 6 November 2026 + +This study is the evidence for the 2.2.0 plan. The rules are in +[the specification](../spec.md) and [the decisions](../decisions.md). Provider +software changes. A fact below is tied to the page or the file it came from. +Nothing here was read from a live server, and no key was used. + +## What the product is + +Open Wearables is the program in the public repository +`the-momentum/open-wearables`. The repository describes it as a self-hosted +platform that puts wearable data behind one API. The license file reported by +GitHub is MIT. The repository was created on 30 October 2025. GitHub reported +the default branch `main` pushed at 13:43 UTC on 6 November 2026. + +The newest published release on that date was `0.11.0`, published at 16:10 UTC +on 2 November 2026, at commit `183e8cc4f6de`. Its title is "0.11 - Daily +aggregates & faster summaries". The commit on `main` that day, +`7ca121dd4e48`, is "chore: update OW to 1.0 (#2065)". There was no GitHub +release named 1.0.0. + +The GitHub homepage field is `https://docs.openwearables.io`. This study did +not fetch that host. The pages it did fetch are on +`https://openwearables.io/docs`. The API introduction there says the reference +is generated from `docs/openapi.json` on every change, so the website describes +current `main`, and a self-hosted copy should be read from that copy's own +`/openapi.json`. + +Checked: + +- Repository: `https://github.com/the-momentum/open-wearables` +- Release `0.11.0`: `https://github.com/the-momentum/open-wearables/releases/tag/0.11.0` +- API introduction, fetched 6 November 2026: `https://openwearables.io/docs/api-reference/introduction` +- Integration guide, fetched the same day: `https://openwearables.io/docs/dev-guides/integration-guide` +- Doc index: `https://openwearables.io/docs/llms.txt` +- OpenAPI at the `0.11.0` tag: `docs/openapi.json`, `info.version` `0.11.0` +- OpenAPI on `main` the same day: `docs/openapi.json`, `info.version` `1.0.0` + +The integration guide says "self-hosted or cloud". In the same guide the cloud +case is a deployment the reader runs. This study did not find a separate +hosted service, in the repository description, the `0.11.0` notes, or the API +introduction, that stores data for people who do not run the server. + +Open Wearables is not Junction. Junction remains the other shipped mapping +file, and this plan does not call it. + +## The read this plan uses + +All three reads are under `/api/v1` and take a user id in the path. The user +id is an Open Wearables UUID. Dates are required. + +| Read | Path on `0.11.0` | Page shape | +|---|---|---| +| Sleep | `GET /api/v1/users/{user_id}/events/sleep` | `data`, `pagination`, `metadata` | +| Workouts | `GET /api/v1/users/{user_id}/events/workouts` | `data`, `pagination`, `metadata` | +| Timeseries | `GET /api/v1/users/{user_id}/timeseries` | `data`, `pagination`, `metadata` | + +`pagination.has_more` is required in the OpenAPI schema. `next_cursor` is +null when there is no next page. The cursor code in `0.11.0` is a URL-safe +base64 of a timestamp, an id, and an optional `prev_` prefix +(`backend/app/utils/pagination.py`). `limit` defaults to 50 and the maximum +is 1000. + +Sleep and timeseries take `filter_by_priority`, default `false`. The `0.11.0` +sleep handler passes that flag into the query. The `0.11.0` timeseries handler +does the same. On `main` (OpenAPI `1.0.0`, not a release), an omitted +`source_selection` means all devices when `filter_by_priority` is false. The +`main` workout list uses all devices when `source_selection` is omitted. The +`0.11.0` workout list has no priority flag. It returns the workouts in range. + +Timeseries `resolution` defaults to `raw`. The enum is `raw`, `1min`, `5min`, +`15min`, `1hour`, `1day`, `1week`, `1month`. The `0.11.0` service copies that +value into `metadata.resolution` (`timeseries_service.py` around the +`TimeseriesMetadata` construction). + +The `0.11.0` OpenAPI parameter `types` is an array of `SeriesType`. It omits +`style` and `explode`. For a query parameter, OpenAPI's default style is +`form`, and the default explode for `form` is true, which is one query +parameter per value. A comma-joined string is not a member of that enum. +This study did not send the request. The plan sends one parameter per type. + +The `0.11.0` release notes say day and session values are no longer samples. +They are read with `resolution=1day` or from the sleep or workout. The notes +say a sample row can carry `window_seconds`, and an aggregate can carry +`computed_by` of `provider` or `open_wearables`. The raw sample builder in +`timeseries_service.py` (the `_to_sample` call in the raw return) does not +pass `computed_by`. The field exists on the schema and can be null. + +`ComputedBy` is `provider` or `open_wearables`. The description says who +computed an aggregate. + +## Fields the mapping already names + +Sleep, from the `0.11.0` schema `SleepSession`: `id`, `start_time`, +`end_time`, `zone_offset`, `source`, `duration_seconds`, +`sleep_duration_seconds`, `time_in_bed_seconds`, `efficiency_percent`, +`stages`, `sleep_stage_intervals`, `is_nap`. Stages have `awake_minutes`, +`light_minutes`, `deep_minutes`, `rem_minutes`. `source` has `provider`, +`source`, `device`, `device_type`, `device_id`, and read-only `device_name`. + +Workouts, from `Workout`: `id`, `type`, `name`, `start_time`, `end_time`, +`zone_offset`, `source`, `entry_source`, `intensity`, the distance, heart-rate, +and elevation fields the mapping already names, plus fields it does not name. +`entry_source` is `manual`, `automatic`, or `unknown`. The schema text says +`manual` is a self-reported entry with no device measurement behind it. + +Timeseries, from `TimeSeriesSample`: `timestamp`, `zone_offset`, `type`, +`value`, `unit`, `source`, `is_daily_total`, `window_seconds`, `period_end`, +`computed_by`, `stats`. + +`start_time` and `timestamp` are schema format `date-time`. This study did not +capture a live JSON body, so it does not claim the wire format beyond that +schema. `zone_offset` is a separate string, `+01:00` or `-05:30`, or null. + +The shipped mapping file's timeseries lines do not name `heart_rate`. In +Athletic Standard, `heart_rate` is a series quantity +(`SERIES_QUANTITY_UNITS` in `src/v1/schema.ts`). It is not one of the point +quantities the mapping engine writes. A raw heart-rate stream therefore has +nowhere to go in the current mapping. + +## Time bounds + +The API introduction says a date-only start is midnight UTC and a date-only +end covers that whole UTC day. + +The `0.11.0` parser does not say UTC. `parse_query_datetime` in +`backend/app/utils/dates.py` uses `datetime.fromisoformat` after rejecting a +value that parses as a number. A date-only string becomes midnight with no +timezone. `parse_query_end_datetime` turns a date-only end into the next +midnight, also with no timezone, because the comparison is `<`. This study +did not follow those naive values into the database session, so it does not +claim which timezone PostgreSQL applies. + +A full timestamp is sent through as parsed. The docs say a value with an +explicit time is used as given, and `end_time` at midnight includes nothing +later that day. + +## Credentials + +Data routes depend on `ApiKeyDep` (`backend/app/services/api_key_service.py` +on `0.11.0`). That dependency accepts a developer login JWT or the header +`X-Open-Wearables-API-Key`. A missing or unknown key is HTTP 401, detail +"Authentication required: provide JWT token or API key" or "Invalid or +missing API key". + +The integration guide says the key is not a bearer token, and +`Authorization: Bearer` with the API key returns 401. The OpenAPI operation +security lists `OAuth2PasswordBearer` and marks the API-key header optional. +Both can be true: the header is optional in the schema because a developer +JWT is the other way in. The header is how an integration authenticates. + +`POST /api/v1/users/{user_id}/token` returns a token the `0.11.0` route text +limits to SDK endpoints. `get_current_developer` in `backend/app/utils/auth.py` +rejects a token whose scope is `sdk` on developer routes. There is no +user-scoped token for the sleep, workout, and timeseries reads. The API key +is an administrator key for the whole deployment. The integration guide and +the credentials page say that. + +`GET /api/v1/users` lists every user and uses page/limit pagination, not the +cursor used by the three data reads. `GET /api/v1/users/{user_id}/personal-record` +returns birth date, gender, and sex. + +`DELETE` exists for one sleep, one workout, one provider connection, and one +provider's stored data. Those are writes against the server. None of the +three read routes takes `updated_since` or returns a deletion list. Sync +routes (`/sync`, `/sync/historical`, `/sync/runs`, `/sync/stream`) report or +start provider sync. They are not a feed of changed records. + +`GET /api/v1/config` returns feature flags and requires a developer JWT. It +has no version field. The docs point at `/openapi.json` for the running +version. That file is the full specification (about 600 KB at `0.11.0` and +about 700 KB on `main` the day of this study). + +Health scores use `limit` and `offset`. The `0.11.0` notes say Open Wearables +stops computing its own scores on 6 November 2026. Recovery summaries are +daily objects with a `date` and no instant. They include `avg_hrv_rmssd_ms` +and `avg_hrv_sdnn_ms` as separate fields. + +No rate-limit field was in the API introduction or in the three `0.11.0` +route files. A limit may still exist in middleware this study did not open. + +## What was not checked + +- A running server's JSON, including the exact `start_time` text. +- Whether Docker tag `latest` matches release `0.11.0` or `main`. +- The database timezone applied to a date-only bound. +- Middleware rate limits. +- The host `https://docs.openwearables.io`. diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md new file mode 100644 index 00000000..10398971 --- /dev/null +++ b/build-history/v2.2.0/decisions.md @@ -0,0 +1,281 @@ +# Decisions — v2.2.0 + +D-numbers continue from [v2.1.0](../v2.1.0/decisions.md). D198 follows D197. + +These decisions are the proposal in [spec.md](spec.md). The maintainer has not +approved them. This pull request does not build them. A change of mind before +approval is an edit of the proposal. After approval, a change is a new +D-number. + +## D198. Version 2.2.0 is one manual pull, and the program and the record share that number + +`ath pull openwearables` reads sleep, workouts, and raw samples from an Open +Wearables server the person runs, for one user and one range they name. The +command is manual. The person runs it. The program does not schedule it, retry +it, or sign the person in to a device maker. + +The program, the record, and the database become `2.2.0` together. D152 made +those one number. D184 kept that rule. Migration step 5 stores `2.2.0` and +SQL schema 5. It adds no column and changes no record. Step 4 is not edited +(D165). A new database runs step 5 after step 4 and before `user_version` is +set. `applyMigrationStep` handles target 5. The migration chain, the SQL +contract generator, and the drift check gain that step. The package exports +point at `schema/2.2.0/`. `READABLE_DATABASE_VERSIONS` and +`ACCEPTED_RECORD_VERSIONS` keep `1.0.0`, `2.0.0`, and `2.1.0`, and gain +`2.2.0`. `IMPORTABLE_PACKAGE_VERSIONS` gains `2.2.0` and keeps `2.0.0` and +`2.1.0`. A `2.1.0` package still imports. A `2.1.0` database does not open +until `ath migrate`. + +The build is one pull request after this plan is approved. It is not split +into a version change, a client, and a mapping change. + +The versions named here are boundaries for this plan. They are not specs. + +- 2.2.0 is this pull. +- 2.3.0 is a Junction pull. This release does not call Junction. +- 2.4.0 is automatic incremental sync, saved sign-in refresh, retries, and + backfill. This release has none of those. +- 2.5.0 is the work of storing day aggregates and the heart-rate stream. + This release does not store them, and it does not decide to add an Open + Wearables period type. `ProviderReportingPeriodType` stays the Whoop, Oura, + and Apple values it has now. +- A connector interface that every future source would implement is later + than 2.5.0. This release adds one module for this server. + +File imports stay: Apple Health, WHOOP, Oura, Garmin, and Strava. `ath pull +garmin` stays as it is. `ath import --mapping` stays as it is. + +Evidence: [appendix/open-wearables-api.md](appendix/open-wearables-api.md). + +Rejected alternatives: + +- Leave the record at 2.1.0 while the program becomes 2.2.0. Rejected because + D152 and D184 already rejected a split. +- Ship the pull as three pull requests. Rejected because the maintainer asked + for one versioned build. +- Pull Junction, start sync jobs, or add a connector trait in this release. + Rejected because each of those is a later version, and this release has to + make one manual read reliable first. + +## D199. The pull fetches pages and the shipped mapping writes the records + +New Rust module `crates/ath-core/src/open_wearables.rs` requests the three +reads and calls `apply_mapping`. The command-line front end stays in +TypeScript (D174). New imports stay in `ath-core` (D155). The HTTP client is +the `ureq` 2.12 dependency the Garmin pull already uses. No new crate. + +The mapping file is resolved with `resolveMappingFile` in `src/skill.ts`, +name `open-wearables`. An installed copy in `.agents/mappings/` wins, which +is D179. Rust receives the absolute path. It does not grow a second rule for +what a path looks like. + +The mapping file chooses every stored field. The pull does not rename a +field, choose a unit, or decide that a value is RMSSD or SDNN. A field the +file does not name stays in `supplied_fields` under the name it arrived with +(D153, D161). `field_basis` stays whatever the file already states (D185, +D187, D192). + +Sleep and workout responses are envelopes with `data` and `metadata`. The +shipped file's page section is `timeseries`, so `apply_mapping` would leave +that envelope out. The pull passes sleep rows as `{ "sleep": [ ... ] }` and +workout rows as `{ "workout": [ ... ] }`. It passes each timeseries response +through unchanged, so `metadata.resolution` still reaches the mapping. The +pull does not drop a row before the mapping sees it. A manual workout stays +the mapping's `left_out`, and the other rows in that page are still written. + +The timeseries query's `types` list is the `type.` lines in the +resolved mapping file, read when the command runs. Each name is one repeated +`types` query parameter. A name that appears twice is sent once. +`skin_temperature` is that case. A comma-joined value is not a series type +on the 0.11.0 server and returns 422. The Rust source has no second copy of +those names. `heart_rate` is not one of those lines, and it is not a point +quantity the mapping can write. This release does not add the line and does +not store the heart-rate stream. Workout `avg_heart_rate_bpm` and +`max_heart_rate_bpm` stay as the file already maps them. + +`apply_mapping` adds counts by record type and keeps the existing `outcome` +field. The pull prints the sleep, workout, point, summary, and score counts. +It does not add `outcome` across pages. Those printed counts match the write +when each object id appears on one page. A server that repeats an id on a +later page can make the preview say new where the write says unchanged. The +write still follows D182. + +Day aggregates, recovery summaries, health scores, meals, and body summaries +are not requested. On Open Wearables 0.11.0 those day values are no longer +raw samples. Storing a date as midnight would break D88. This release leaves +`ProviderReportingPeriodType` unchanged. Whether a later version adds an Open +Wearables period is a later decision. Storing the day values is named as +2.5.0 work, and that name is a boundary, not that decision. + +Rejected alternatives: + +- Teach the pull the Open Wearables field names in Rust. Rejected because + D161 put those names in the mapping file so a second source does not become + a second record format. +- Pass the sleep envelope straight to `apply_mapping`. Rejected because the + current page rule would leave the page out. The check is `page_rows` and + `row_fits` in `crates/ath-core/src/mapping.rs`. +- Request every series type and let `left_out` drop the rest. Rejected + because the type list includes latitude, longitude, and other series the + file does not store. The pull would download them for a result that cannot + keep them. +- Map `heart_rate` samples as points, or map recovery summaries onto + midnight. Rejected because one invents a point quantity and the other + invents an instant (D88, D110). + +## D200. The key, the server, and the user id stay out of the record + +The API key is an administrator key for every user on that deployment. The +pull sends it only as the header `X-Open-Wearables-API-Key`. It is saved with +`ath key set openwearables` in the operating system password store, the same +store D75 uses. The environment name for a script is `OPEN_WEARABLES_API_KEY`. +The child process receives it as `ATH_CORE_OPEN_WEARABLES_KEY`. The key is +not a command argument. If the password store is missing, the command refuses +and does not write a file. + +`ath key clear openwearables` deletes that saved key. `ath key clear` with +no name still clears only the gateway keys. The Open Wearables key is cleared +only when it is named. `ath key` keeps its gateway lines and adds one line +that says whether an Open Wearables key is saved or set in the environment. +The line does not include the key. Garmin's key command is unchanged. + +The server is `--base-url` or `OPEN_WEARABLES_BASE_URL`. The user id is +`--user` or `OPEN_WEARABLES_USER_ID`. Neither is written into the database, +the export, a config file, or a log line. The pull never calls `GET /users` +and never calls the personal-record route. One command reads one user. + +`--base-url` is an origin: scheme, host, and optional port. No user name, no +password, no path other than empty or `/`, no query, and no fragment. `http` +is allowed only for `localhost`, `127.0.0.1`, and `::1`. Any other host +requires `https`. The pull appends `/api/v1` itself. Redirects are not +followed. A timeout, a non-JSON body, or an HTTP error becomes the page +failure in D201. The printed error is the status and, when the body is +problem JSON, the `code`. It does not include the request path. The path +contains the user id. The response body is checked for the key before +`apply_mapping`. A body that contains the key is not written. The key is +removed from any text the command prints. A result that still contains the +key is replaced with a fixed refusal, as the Garmin pull already does for +its own key. + +The shell history can contain the server and the user id when they are +passed as flags. The key is not a flag. `ath key set openwearables`, or +`OPEN_WEARABLES_API_KEY` already held by the shell, keeps the key off the +command line. Putting the key on the same line as the command would store +it in shell history. Do not do that. + +Rejected alternatives: + +- Store the server and the user id on the source row so the next pull can + omit them. Rejected because the export would carry them, and agents read + the export. +- Remember them in a file beside the database. Rejected because that file is + easy to commit and easy to copy into a backup by mistake. +- Accept a bearer token or a user-scoped SDK token for these reads. Rejected + because the 0.11.0 server does not accept the API key as a bearer token, + and the SDK token is limited to SDK routes. See the appendix. +- List users and pull every user the key can see. Rejected because the key + sees the whole deployment, and this record is one athlete. + +## D201. A page is atomic, a missing row is not a deletion, and the same command is safe to repeat + +Each response page is one `apply_mapping` call. D189 still makes that call +one transaction: a failure rolls the page back, and a preview rolls the page +back after counting. The pull itself is a series of those calls. Sleep pages +finish before workout pages, then timeseries pages. + +The command previews unless `--yes` is present. `--json` is a preview and +does not write, matching `ath import --mapping`. `--yes` writes each page as +that page succeeds. If a later page fails, pages already written stay. The +message names the read. When at least one page was written, it says those +pages are kept. It says to run the same command again. An empty range is a +successful pull with zero records. A repeat uses the +match key from D181 and the replace from D182, so an unchanged row is not +written again. + +`has_more: false` is the only successful end of a read. A repeated cursor, +a null cursor while `has_more` is true, the 1000-page cap, and a body over +8 MiB fail that read. The failed page is not written. The success line is +not printed. A cursor with the `prev_` prefix is not sent. +`limit` is 1000. One attempt is made per request. There is no retry. The +connect timeout is 10 seconds and the read timeout is 30 seconds. + +A row that this range did not return is left where it is. The pull does not +call `DELETE`. There is no deletion feed on the three reads. Absence can be +a short range, a failed page, or a server filter. D190 still applies: a +source the person has deleted stays deleted, and its rows are left out. A +record the person has deleted stays deleted, and that object is left out +(D182). + +`--from` and `--to` are sent unchanged. Both are dates `YYYY-MM-DD`, or both +are timestamps with an offset. A mix is refused. The command prints one line +that a date-only bound is interpreted by Open Wearables, and that Athletic +Standard did not convert it to the athlete's timezone (D88). The appendix +records the disagreement between the docs and the 0.11.0 parser. + +Queries that are sent: + +- Sleep: `start_date`, `end_date`, `limit`, `cursor` after the first page, + `filter_by_priority=false`. `is_nap` is omitted, so naps and main sleep + both return. `include` is omitted. +- Workouts: `start_date`, `end_date`, `limit`, `cursor` after the first page. + No priority flag, because 0.11.0 has none and current `main` already + returns every device when the flag is absent. +- Timeseries: `start_time`, `end_time`, `limit`, `resolution=raw`, + `filter_by_priority=false`, `types` from the mapping file, and `cursor` + after the first page. + +`source_selection` is not sent. On 0.11.0 the parameter does not exist. On +current `main`, omitting it returns every device when the priority flag is +false. + +Rejected alternatives: + +- One transaction for the whole range. Rejected because a raw range can be + large, and a failure at the end would discard pages that had already + succeeded. Each page is still atomic. +- Store a resume cursor in the database. Rejected because the same command + finds the same rows by their match keys, so a stored cursor would be a + second copy of progress. +- Delete local rows missing from the response. Rejected because the read has + no tombstone, and a partial range would hide history the server still has. +- Retry, refresh a token, or start a historical sync. Rejected because those + are 2.4.0. A 401 or a 429 fails the page and writes nothing for it. +- Convert a date-only bound into the athlete profile timezone. Rejected + because D88 forbids rewriting a source bound into a timezone the source + did not use. + +## D202. The Windows cleanup and the maintainability notes are not part of this build + +Checked on `main` at `8db90b42ac654767e9e9570a121bbbd4fde3348a`, which is the +merge of pull request 39. + +The failed-init cleanup is still the code in `src/program.ts` (the `init` +catch closes the database and deletes the file, the wal file, and the shm +file with `rm`). `createDatabase` still deletes a half-created file in +`removePartialLocalDatabase` (`src/db/migrate.ts`) by unlinking it. Neither +path collects garbage first. `removeTemporaryDirectory` in `src/db/client.ts` +does, and tests use it. Version 2.1.0 spec section 12 left the production +paths out of that release and did not assign them a version. They are still +open. They do not run on a pull. This build does not change them. + +`crates/ath-core/src/store.rs` is 1034 lines. `mapping.rs` is 1443. +`persist.rs` is 1051. The pull is a new module so those files do not grow +for HTTP. `mapping.rs` may add the count by record type that D199 names, and +nothing else. Splitting the files is separate work. It is not required to +make the pull correct. + +`check_supplied_fields` runs in `store.rs` before insert and revise (D191). +`persist.rs` `insert_record` writes `data_json` and does not call that check. +The pull writes through `apply_mapping` and the store, so the check covers +it. Closing the persist gap is separate work. + +`isMappingPath` exists once, in `src/skill.ts`. Rust has no copy. The pull +uses the TypeScript function. There is no second path rule to remove. + +Rejected alternatives: + +- Fix the Windows cleanup, split the Rust files, and guard `persist.rs` + inside the 2.2.0 pull request. Rejected because none of them changes what + the pull writes, and the maintainer asked not to widen this build. +- Block the pull on those fixes. Rejected for the same reason. A later + change can take any one of them on its own. diff --git a/build-history/v2.2.0/progress.md b/build-history/v2.2.0/progress.md new file mode 100644 index 00000000..af7ea323 --- /dev/null +++ b/build-history/v2.2.0/progress.md @@ -0,0 +1,19 @@ +# v2.2.0 progress + +This folder is the plan. The maintainer has not approved it. Nothing in the +program, the record, or the database has changed for 2.2.0. + +| Step | What | Status | +|---|---|---| +| 0 | The plan: spec, decisions D198–D202, and the Open Wearables study | written, not approved | +| 1 | Version 2.2.0, migration step 5, no new column (D198) | not started | +| 2 | `ath pull openwearables` in `ath-core`, using the shipped mapping (D199, D201) | not started | +| 3 | Key, server, and user id kept out of the record (D200) | not started | +| 4 | Fixture tests, with no live key in CI | not started | +| 5 | Generated schema, demo athlete, skill command reference, and the public-data list | not started | +| 6 | Laptop card and the proof in the build pull request | not started | + +The build, after approval, is one pull request. It is not three. + +The Windows failed-init cleanup, the size of `store.rs` and `mapping.rs`, and +the `persist.rs` field-name check stay out of that pull request (D202). diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md new file mode 100644 index 00000000..9a2482fc --- /dev/null +++ b/build-history/v2.2.0/spec.md @@ -0,0 +1,397 @@ +# Athletic Standard 2.2.0 + +Status: **plan only. The maintainer has not approved it. Not approved for build.** + +`ath pull openwearables` reads one person's sleep, workouts, and raw samples +from an Open Wearables server they run, and writes them with the mapping file +that version 2.1.0 already ships. The decisions are D198 through D202 in +[decisions.md](decisions.md). The evidence is +[appendix/open-wearables-api.md](appendix/open-wearables-api.md), checked on +6 November 2026. + +This pull request is the plan. The build after approval is one later pull +request. This plan does not change a version number, a schema, a fixture, or +the program. + +Version 2.1.0 on `main` `8db90b42ac654767e9e9570a121bbbd4fde3348a` is the +software this plan was read against. That commit is the merge of pull request +39. The pull request head was `72b9db9`. + +## 1. What a person does + +They already run Open Wearables and have already connected their devices in +that server's own portal. This command does not sign them in to Garmin, WHOOP, +Oura, Apple, or anyone else. It does not start a sync. + +They save the key once: + +```text +ath key set openwearables +``` + +The program asks them to paste the key and does not print it. A script may set +`OPEN_WEARABLES_API_KEY` instead. + +They name the server, the user, and the range: + +```text +ath pull openwearables \ + --base-url http://127.0.0.1:8000 \ + --user 00000000-0000-4000-8000-000000000001 \ + --from 2026-01-01 \ + --to 2026-01-07 +``` + +The same three values may come from `OPEN_WEARABLES_BASE_URL`, +`OPEN_WEARABLES_USER_ID`, and the key variable above. A flag wins over the +environment when both are set. + +The first run writes nothing. It prints: + +- one line that a date-only bound is sent as typed, and Open Wearables decides + what that day means +- counts, by record type, of sleep sessions, workouts, points, summaries, and + scores that would be new, changed, or unchanged +- two fixed lines: this pull asks for raw samples only, so a nightly + heart-rate variability, resting heart rate, blood oxygen, or VO2 max that + the server keeps as a day value is not in this pull; and the heart-rate + stream is not stored, while a workout's average and maximum heart rate are + stored when the server sent them +- how many rows were left out, then up to 20 left-out lines +- `nothing written; pass --yes after reviewing this preview` + +`--yes` writes, then prints those same two limit lines. It prints +`pulled openwearables from through ` only when every read ended +because `has_more` was false. `--json` prints the structured result and does +not write, including when `--yes` is also present. That is the same rule as +`ath import --mapping`. `ath pull garmin --json` still writes, which is the +Garmin command as it is today. `--file` chooses a database, as on the other +commands. + +A failed page names the read (`sleep`, `workouts`, or `timeseries`). The +command exits with a failure and does not print the success line. When +`--yes` had already written a page, the message says those pages are kept. +It says to run the same command again. An empty range prints zero counts and +is a success, and it still prints the two limit lines. + +`--date` stays required only for `garmin`. `--from` and `--to` are required +only for `openwearables`, and they are flags, not environment variables. +`--base-url` and `--user` are required for `openwearables` unless the +environment named above supplies them. `ath pull garmin --date YYYY-MM-DD` is +otherwise unchanged. `ath pull` with any other name still fails. The failure +text becomes `pull reads garmin or openwearables`. + +The saved key can read every user on that server. `ath key` shows whether it +is saved, without printing it. `ath key` with no further word does not remove +it. `ath key clear` with no name leaves it. `ath key clear openwearables` +removes it. + +## 2. What this release leaves for later + +D198 names the boundary. File imports stay. The Garmin pull stays. Junction is +2.3.0. Automatic sync, retries, token refresh, and backfill are 2.4.0. +Storing day-level heart-rate variability, resting heart rate, blood oxygen, +and VO2 max is 2.5.0, and so is the heart-rate stream. That version is not a +decision, made here, to add an Open Wearables period type. A shared connector +interface is later than that. + +This release also leaves out: + +- creating users, OAuth, webhooks, SDK uploads, and Apple Health XML upload + through Open Wearables +- `DELETE` on the server, and any local delete inferred from a missing row +- health scores, meals, menstrual cycles, body summaries, and the activity, + sleep, and recovery summary routes +- timeseries resolutions other than `raw` +- the heart-rate stream, steps, and the other series the mapping file does not + name +- storing the server address, the user id, the API key, or a resume cursor + +On Open Wearables 0.11.0, day and session values are no longer raw samples. +A raw pull can return an empty timeseries for resting heart rate, nightly +heart-rate variability, blood oxygen, and VO2 max even when the server holds +them as day rows. Sleep sessions and workouts still return. The release does +not invent a midnight timestamp for those day rows (D88, D110, D199). + +## 3. How a response becomes records + +The pull resolves `open-wearables` through `resolveMappingFile`. It parses and +checks the file before the first request. A bad file fails with no network +call. + +For each page of sleep it calls `apply_mapping` with +`{ "sleep": }`. For each page of workouts it uses `workout`. +For each timeseries page it passes the response object unchanged. Pagination +is not a record. Sleep and workout `metadata` is not a record. Timeseries +`metadata.resolution` stays, because the mapping file requires it. + +Everything after that is the mapping engine from 2.1.0: match keys (D181), +replace on change (D182), source and device (D183), one transaction per call +(D189), a deleted source left out (D190), and field names refused when they +are empty or `__proto__` (D191). A Garmin file import remains a different +`data_route`, so both copies of one workout stay (D161). A second pull of the +same Open Wearables object, or an `ath import --mapping open-wearables` of a +saved copy of that object, updates the same rows. + +The writer is `source.provider`. The sensor string is `source.device_type`, +`source.device`, and `source.source`. Two devices that share those three +strings share one source and one baseline. `source.device_id` is stored as +hardware on the source-device row. It does not split the source. That is the +mapping file version 2.1.0 already ships (D183). The queries in D201 ask for +every device. + +`zone_offset` is not copied into `start_at`. It remains in `supplied_fields` +when the server sends it. The timestamp text is the server's `start_time`, +`end_time`, or `timestamp`. A timestamp with no offset is left out by the +mapping. The pull does not add `Z`. + +`computed_by`, `window_seconds`, `is_nap`, `intensity`, and `efficiency_percent` +stay under those names when they are present. The basis on a mapped value +stays the basis the file already states. This release does not read +`computed_by` as a new basis. Raw samples on 0.11.0 are built without that +field. Aggregates, which do carry it, are not requested. + +## 4. Credentials, privacy, and the network + +D200 is the rule. The key never enters the athlete database, the export, the +preview, or an error line. The pull reads only the three paths in D201, plus +no others. It does not list users and does not read the personal record. + +The process refuses a base URL that could carry the key in the URL itself. +It refuses plain `http` except to loopback. It does not follow a redirect, so +the key cannot be sent to a second host. One attempt, then stop. Timeouts are +10 seconds to connect and 30 seconds to read. One response may be at most +8 MiB. One read may be at most 1000 pages. Before a page is written, the +response text is checked for the key. A body that contains the key is not +written. Printed failure text is the status and, when the body is problem +JSON, the `code`. It omits the request path, which contains the user id. + +There is no Athletic Standard telemetry on this command. The server the person +named is the only host contacted. + +A deployment API key can read every user on that server. The command cannot +shrink that key. It can avoid using the extra power: one user id, three +reads, no user list. + +## 5. Version, migration, and what stays compatible + +The build sets `2.2.0` on the package, the record, and `ath-core`, by the +same constants 2.1.0 moved. Migration step 5 is a new SQL file. It updates +`athleticstandard_version` to `2.2.0` and `sql_schema_version` to 5. No column +is added. Step 4 and file `004` are not edited (D165). + +A new database runs that step 5 SQL after step 4 and before the `user_version` +pragma, inside `installInitialSchema`. `applyMigrationStep` gains an arm for +target 5. `MIGRATION_CHAIN` in `src/db/sql-contract.ts`, +`scripts/generate-sql-contract.ts`, and `scripts/check-schema-drift.ts` gain +the step. `package.json` exports and `tests/v1-package-exports.test.ts` point +at `schema/2.2.0/`. + +`READABLE_DATABASE_VERSIONS` and `ACCEPTED_RECORD_VERSIONS` become `1.0.0`, +`2.0.0`, `2.1.0`, and `2.2.0`. Both sets already contain `1.0.0`. Dropping it +would make a 1.0.0 database unloadable, so migrate could not open it. +`IMPORTABLE_PACKAGE_VERSIONS` is only `2.0.0` and `2.1.0` today. It gains +`2.2.0` and keeps those two. `Store::open` rejects a `2.1.0` database until +`ath migrate`, with the refusal it already uses for an older database. A +`2.1.0` database will not open in `ath-core` until that migrate. + +The build generates `schema/2.2.0/` and does not rewrite `schema/2.1.0/` or +`schema/2.0.0/`. The JSON schema gains no field. The folder exists so the +package version and the schema path stay aligned. The demo athlete is +regenerated because the stored version is inside it. `examples/demo-athlete/athlete.ath.json` +stays the legacy 0.4.3 file. `tests/fixtures/version-2-0-0/` is not +regenerated. + +`package.json` `files` already includes `mappings`. The mapping files are not +rewritten by this release. `pnpm generate:skill-cli` runs because help text +changes (D80). `AGENTS.md`, `build-history/README.md`, and `SPEC.md` are +updated in the build so they name 2.2.0 as the software. `docs/connections.md` +keeps the file imports and states the same limit as section 1: a raw pull +does not store day-level resting heart rate, nightly heart-rate variability, +blood oxygen, VO2 max, or the heart-rate stream. This plan's edits to +`AGENTS.md` and `build-history/README.md` only point at the plan. + +A database from 2.1.0 needs `ath migrate` before the pull. The migrate +command still previews, backs up, and asks (D124). `Store::open` only +refuses. A noninteractive open and an open with `--json` do not migrate. An +interactive open can preview, back up, ask, and then migrate. + +## 6. Where the code goes + +| Piece | Place | +|---|---| +| HTTP, page loop, envelope split, call `apply_mapping` | `crates/ath-core/src/open_wearables.rs` | +| Command `pull-openwearables` | `crates/ath-core/src/main.rs` | +| Flags, key, preview text, refusal if the key appears | `src/program.ts`, `src/help.ts`, `src/keyring.ts` | +| Mapping names and field rules | the existing file `mappings/open-wearables.md` | +| Stored records | the existing store and mapping engine | + +`store.rs`, `persist.rs`, and `personal.rs` are not the home for this client. +`personal.rs` remains the Garmin pull. The two clients may each call `ureq`. +A shared trait is the later connector work, and this release does not add it. + +`mapping.rs` changes in one place. `apply_mapping` keeps its `outcome` field +and adds counts by record type. The pull sums only `sleep_session`, +`workout_session`, `point_measurement`, `provider_summary`, and +`provider_score`. It does not add `outcome` across pages. `outcome` counts +the source-device row in the same group, and a preview rolls each page back, +so that total would not match the write. The three printed record families, +plus summaries and scores, do match, because each row's match key is looked +up on its own. + +The Rust command reads the key from the environment only. It has no `--key` +flag. The child checks the response body for the key before `apply_mapping`. +The parent checks that stdout and stderr do not contain the key before +printing, and the child does the same before it returns JSON. + +The program runs on Linux, macOS, and Windows with the same command. The +fixture server listens on `127.0.0.1` and an ephemeral port, which is the +pattern `personal.rs` already tests. Paths stay the TypeScript resolver's +job. No new installer and no new system library. + +## 7. Tests + +CI has no Open Wearables account, no API key, and no Docker Compose. The +acceptance tests are the fixture server and the synthetic files already in +`tests/fixtures/exports/open-wearables/`. Those files are on the public-data +list. A new file, if one is required for a two-page response, is synthetic, +invented, and added to `scripts/check-public-data.ts` with its hash. No real +export is copied. + +Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: + +- two pages, the second `next_cursor`, then `has_more: false`, and the + success line is printed +- a repeated cursor fails that read, writes nothing for that page, and does + not print the success line +- `has_more: true` with a null cursor fails the page and writes nothing for it +- a 401, a 429, a timeout, and a non-JSON body fail the page +- a redirect is not followed, and the key is not sent to the second host +- `http` to a non-loopback host is refused before a socket opens +- a base URL with a user name, a query, or a path is refused +- the request header is `X-Open-Wearables-API-Key`, and the key is not in the + result or the error +- `filter_by_priority=false` and `resolution=raw` are present, and each + mapping type is one repeated `types` query parameter, with duplicates + removed (`skin_temperature` is named twice in the file and sent once) +- the date strings are the ones the caller passed +- `page-sleep.json`, served as the sleep response, becomes a sleep session +- a workout page with one `entry_source` of `manual` and one automatic + neighbor leaves the manual row out and keeps the neighbor +- a user id that is not a UUID is refused before a socket opens +- `page-raw.json` stores the mapped sample, and `page-5min.json` is left out +- RMSSD and SDNN stay different quantities +- a second run reports unchanged +- a changed end time keeps the record id and increases the revision +- a `__proto__` supplied field fails the page and leaves that page unwritten +- a deleted mapped source is left out +- a Garmin file import of another workout remains a second source +- the 1000-page cap and the 8 MiB cap fail that read, write nothing for the + failed page, and do not print the success line; the page cap is tested with + a small limit passed into the loop, not by looping 1000 times +- a timestamp with no offset is left out; the stored fixture's timestamps + include `Z`, and the test does not add `Z` to a bare timestamp + +TypeScript tests cover the missing-key sentence, `ath key set` and +`ath key clear` for `openwearables` against the memory store, the preview +sentence, and `--json` not writing. They do not open the real password store. + +`pnpm check:public-data`, `pnpm typecheck`, `pnpm test`, and `pnpm build` +pass, and `cargo test` passes, before the build is called done. + +## 8. Laptop card and the proof + +The card uses the fixture server or Open Wearables' own synthetic seed. It +does not use a real account or a real export. + +1. Create an empty database with `ath init --yes --empty` in a temporary folder. +2. Save the fixture key with `ath key set openwearables`. +3. Run the pull for `2026-01-01` through `2026-01-07` without `--yes`. +4. Read the preview. Confirm the two limit lines are on screen, a left-out + line is visible, and the key is not. +5. Run the same command with `--yes`. `ath check` exits 0. +6. Run it with `--yes` again. The counts say unchanged. +7. Run `ath pull garmin` with no date and confirm it still asks for `--date`. +8. Import one existing synthetic Apple, WHOOP, or Oura fixture and confirm + `ath check` still exits 0. + +The build pull request's description carries screenshots or a short recording +of steps 3 through 6. The images are not committed. The numbers on screen are +the fixture's invented values. The release workflow on Linux, macOS, and +Windows is the cross-platform proof. The recording is one system. + +This plan pull request has no recording. + +## 9. Separate follow-ups + +D202 records the check. None of these is a prerequisite for the pull, and none +is in the build pull request. + +- Failed `ath init` and failed `createDatabase` still delete the database file + in the same process that closed it, without the garbage collection + `removeTemporaryDirectory` uses. On Windows that delete can fail with + `EBUSY`. Version 2.1.0 spec section 12 left it out and named no later + version. +- `store.rs` and `mapping.rs` are past a thousand lines. The pull does not + add HTTP to them. The only `mapping.rs` change is the count by record type + in section 6. Splitting the files stays out. +- `persist.rs` can still store a supplied field named `__proto__` if a caller + uses `ath-core persist` directly. The pull does not use that path. +- The mapping path rule is already one function. There is no duplicate to + delete. + +No maintainability note under another name was found in the 2.1.0 decision +log. The sizes and the persist gap are the current code, not a recorded +D-number. + +## 10. Risks and the approval + +Cloud-agent time for the build is uncertain. The published history has no +measured run for this pull. + +Risks: + +- A server newer than 0.11.0 can add a default that hides a second device. + Current `main` does not, when the queries in D201 are sent. The client is + tested against the stored fixture. That fixture is not a live response, and + a live timestamp without an offset is left out. A breaking envelope needs a + new fixture before the pull trusts it. +- A raw range of mapped series can be large. The 1000-page cap and the 8 MiB + cap fail that read, write nothing for the failed page, and withhold the + success line. The person narrows `--from` and `--to` and runs again. An + unchecked server limit, including a 429, can stop a later page after earlier + pages have been kept. The study did not read the rate-limit middleware. +- Date-only bounds mean whatever Open Wearables decides. The docs and the + 0.11.0 parser disagree about UTC. This release does not correct that server. +- Day-level recovery values are absent after a successful pull, because they + are not requested. The two printed lines say so. Workout average and maximum + heart rate can still be stored. +- Fields on a sleep or workout object that the mapping does not consume are + stored under the server's names. The shipped mapping does not request + latitude or longitude. A replaced mapping file can name more series, and + those series are then requested when they map onto an existing field. +- The administrator key is more powerful than this command. A leaked key from + the password store exposes every user on that deployment. The command's job + is to avoid copying the key into the record. + +The maintainer approves or rejects this plan before any build. The proposal +to approve is D198 through D202, in particular: + +1. One number, 2.2.0. Readable sets keep `1.0.0`. Step 5 runs on create and + on migrate. No new column. A `2.1.0` database does not open until + `ath migrate`. This release does not schedule, retry, refresh a token, + backfill, or store a cursor (D198). +2. The mapping file writes the records. A 0.11.0 raw pull stores workout + average and maximum heart rate when the server sent them, and it can store + zero points for the day values. The heart-rate stream is not requested. + `ProviderReportingPeriodType` is unchanged. Storing the day values is + 2.5.0, and that is not a decision to add a period type (D199). +3. The key, the server, and the user id stay out of the record. Failure text + omits the request path. `ath key clear` leaves this key. + `ath key clear openwearables` removes it (D200). +4. Preview is the default. A failed later page keeps earlier pages, the + command fails, and it does not print the success line. A missing row is + not deleted. Date-only bounds are sent unchanged, and the server decides + the day. The 1000-page cap and the 8 MiB cap fail that read (D201). +5. The Windows cleanup and the maintainability notes stay separate. The count + by record type in `mapping.rs` is the only change in that file (D202). From 1124e566e470cbbab293bea4221c4dec28680388 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 6 Nov 2026 23:52:59 +0000 Subject: [PATCH 02/60] Revise the 2.2.0 pull proposal after review. Keep D198 through D202 unadopted. State empty-type skip, decoded secret checks, estimated previews, partial-page acceptance, and the coverage choices the maintainer still has to make. Co-authored-by: Michael Whitham --- .../v2.2.0/appendix/open-wearables-api.md | 32 +- build-history/v2.2.0/decisions.md | 238 +++++--- build-history/v2.2.0/progress.md | 2 +- build-history/v2.2.0/spec.md | 506 +++++++++++++----- 4 files changed, 565 insertions(+), 213 deletions(-) diff --git a/build-history/v2.2.0/appendix/open-wearables-api.md b/build-history/v2.2.0/appendix/open-wearables-api.md index 19d832e5..d32abc87 100644 --- a/build-history/v2.2.0/appendix/open-wearables-api.md +++ b/build-history/v2.2.0/appendix/open-wearables-api.md @@ -14,7 +14,8 @@ GitHub is MIT. The repository was created on 30 October 2025. GitHub reported the default branch `main` pushed at 13:43 UTC on 6 November 2026. The newest published release on that date was `0.11.0`, published at 16:10 UTC -on 2 November 2026, at commit `183e8cc4f6de`. Its title is "0.11 - Daily +on 2 November 2026, at commit `183e8cc4f6de897dbd288c93d49a691f2cf721ae`. +Its title is "0.11 - Daily aggregates & faster summaries". The commit on `main` that day, `7ca121dd4e48`, is "chore: update OW to 1.0 (#2065)". There was no GitHub release named 1.0.0. @@ -95,8 +96,20 @@ Sleep, from the `0.11.0` schema `SleepSession`: `id`, `start_time`, `end_time`, `zone_offset`, `source`, `duration_seconds`, `sleep_duration_seconds`, `time_in_bed_seconds`, `efficiency_percent`, `stages`, `sleep_stage_intervals`, `is_nap`. Stages have `awake_minutes`, -`light_minutes`, `deep_minutes`, `rem_minutes`. `source` has `provider`, -`source`, `device`, `device_type`, `device_id`, and read-only `device_name`. +`light_minutes`, `deep_minutes`, `rem_minutes`. The session object does not +carry resting heart rate, heart-rate variability, blood oxygen, skin +temperature, or respiration. `sleep_stage_intervals` is null unless the +query sends `include=stages` (`event_record_service.py` on this commit). +Stage minute totals are returned either way. Workout zones need +`include=zones`. Workout segments need `include=segments`. `source` has +`provider`, `source`, `device`, `device_type`, `device_id`, and read-only +`device_name`. `metadata.py` on this commit says `device_id` tells +same-model devices apart. `provider` is the integration, and `source` is +the writer inside it. + +The timeseries route defaults `types` to an empty list. The repository +filters by type only when that list is nonempty. An empty list is every +series. Workouts, from `Workout`: `id`, `type`, `name`, `start_time`, `end_time`, `zone_offset`, `source`, `entry_source`, `intensity`, the distance, heart-rate, @@ -124,12 +137,13 @@ The API introduction says a date-only start is midnight UTC and a date-only end covers that whole UTC day. The `0.11.0` parser does not say UTC. `parse_query_datetime` in -`backend/app/utils/dates.py` uses `datetime.fromisoformat` after rejecting a -value that parses as a number. A date-only string becomes midnight with no -timezone. `parse_query_end_datetime` turns a date-only end into the next -midnight, also with no timezone, because the comparison is `<`. This study -did not follow those naive values into the database session, so it does not -claim which timezone PostgreSQL applies. +`backend/app/utils/dates.py` accepts a numeric Unix timestamp in seconds +before it tries `datetime.fromisoformat`. A date-only string becomes midnight +with no timezone. `parse_query_end_datetime` turns a date-only end into the +next midnight, also with no timezone, because the comparison is `<`. This +study did not follow those naive values into the database session, so it does +not claim which timezone PostgreSQL applies. Athletic Standard's own command +still refuses a numeric bound. That is this program's rule, not the server's. A full timestamp is sent through as parsed. The docs say a value with an explicit time is used as given, and `end_time` at midnight includes nothing diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index 10398971..516e884e 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -2,8 +2,8 @@ D-numbers continue from [v2.1.0](../v2.1.0/decisions.md). D198 follows D197. -These decisions are the proposal in [spec.md](spec.md). The maintainer has not -approved them. This pull request does not build them. A change of mind before +These are proposals in [spec.md](spec.md). The maintainer has not adopted +them. This pull request does not build them. A change of mind before approval is an edit of the proposal. After approval, a change is a new D-number. @@ -29,18 +29,22 @@ until `ath migrate`. The build is one pull request after this plan is approved. It is not split into a version change, a client, and a mapping change. -The versions named here are boundaries for this plan. They are not specs. - -- 2.2.0 is this pull. -- 2.3.0 is a Junction pull. This release does not call Junction. -- 2.4.0 is automatic incremental sync, saved sign-in refresh, retries, and - backfill. This release has none of those. -- 2.5.0 is the work of storing day aggregates and the heart-rate stream. - This release does not store them, and it does not decide to add an Open - Wearables period type. `ProviderReportingPeriodType` stays the Whoop, Oura, - and Apple values it has now. +The version numbers below are proposals. They are not specs, and they are +not adopted. + +- 2.2.0 is this pull: sleep, workouts, and raw samples. +- 2.3.0 is a proposed Junction pull. This release does not call Junction. +- 2.4.0 is proposed automatic incremental sync, saved sign-in refresh, + retries, and backfill. This release has none of those. +- Day aggregates and the heart-rate stream are left out of this pull. D88 + supports that exclusion, because a day must not become an invented midnight. + D88 does not say they wait until after the proposed Junction pull and the + proposed automatic sync. This proposal suggests 2.5.0 for that work. The + maintainer decides the timing. `ProviderReportingPeriodType` stays the + Whoop, Oura, and Apple values it has now. - A connector interface that every future source would implement is later - than 2.5.0. This release adds one module for this server. + than the slot suggested for day aggregates. This release adds one module + for this server. File imports stay: Apple Health, WHOOP, Oura, Garmin, and Strava. `ath pull garmin` stays as it is. `ath import --mapping` stays as it is. @@ -54,8 +58,12 @@ Rejected alternatives: - Ship the pull as three pull requests. Rejected because the maintainer asked for one versioned build. - Pull Junction, start sync jobs, or add a connector trait in this release. - Rejected because each of those is a later version, and this release has to - make one manual read reliable first. + Rejected because this release has to make one manual read reliable first. + The later version numbers are proposals, not adopted assignments. +- Store day aggregates in this release by calling them 2.5.0 work and then + requesting them anyway. Rejected. Leaving them out is the proposal. Adding + them silently is not. The maintainer can choose an earlier version than + the suggested 2.5.0. That choice is still open. ## D199. The pull fetches pages and the shipped mapping writes the records @@ -80,32 +88,68 @@ shipped file's page section is `timeseries`, so `apply_mapping` would leave that envelope out. The pull passes sleep rows as `{ "sleep": [ ... ] }` and workout rows as `{ "workout": [ ... ] }`. It passes each timeseries response through unchanged, so `metadata.resolution` still reaches the mapping. The -pull does not drop a row before the mapping sees it. A manual workout stays -the mapping's `left_out`, and the other rows in that page are still written. +pull does not drop one row and keep its neighbors. A credential, a reflected +origin or user id, a same-key `device_id` collision, or a bad envelope +rejects the whole page first. A manual workout stays the mapping's +`left_out`, and the other rows in that page are still written. The timeseries query's `types` list is the `type.` lines in the -resolved mapping file, read when the command runs. Each name is one repeated -`types` query parameter. A name that appears twice is sent once. -`skin_temperature` is that case. A comma-joined value is not a series type -on the 0.11.0 server and returns 422. The Rust source has no second copy of -those names. `heart_rate` is not one of those lines, and it is not a point -quantity the mapping can write. This release does not add the line and does -not store the heart-rate stream. Workout `avg_heart_rate_bpm` and +resolved mapping file, read when the command runs. The prefix is that +section's `type_field`. Each name is one repeated `types` query parameter. +A name that appears twice is sent once. `skin_temperature` is that case. A +comma-joined string is not a member of the `SeriesType` enum. This study did +not send that request, so it does not claim a live 422. The Rust source has +no second copy of those names. + +If the checked mapping produces no timeseries types, the pull skips the +timeseries request and reports zero counts for that read. The read is +`skipped`. On Open Wearables 0.11.0 the route defaults `types` to an empty +list, and the repository applies a type filter only when the list is +nonempty (`data_point_series_repository.py`). An empty list therefore +returns every series, including heart rate and location. This pull never +sends that request. A mapping that cannot be read for types fails before +any network call. + +`heart_rate` is not one of the shipped lines, and it is not a point quantity +the mapping can write. This proposal does not add the line and does not +store the heart-rate stream. Workout `avg_heart_rate_bpm` and `max_heart_rate_bpm` stay as the file already maps them. `apply_mapping` adds counts by record type and keeps the existing `outcome` -field. The pull prints the sleep, workout, point, summary, and score counts. -It does not add `outcome` across pages. Those printed counts match the write -when each object id appears on one page. A server that repeats an id on a -later page can make the preview say new where the write says unchanged. The -write still follows D182. - -Day aggregates, recovery summaries, health scores, meals, and body summaries -are not requested. On Open Wearables 0.11.0 those day values are no longer -raw samples. Storing a date as midnight would break D88. This release leaves -`ProviderReportingPeriodType` unchanged. Whether a later version adds an Open -Wearables period is a later decision. Storing the day values is named as -2.5.0 work, and that name is a boundary, not that decision. +field. The pull adds those counts into the committed result for a page that +committed and into `estimated` for a page that was rolled back. It does not +add `outcome` across pages. Estimated counts are against the database before +this command. They are not equal to the write when the same match key appears +on two pages, or when the server changes between runs. The write still +follows D182. This proposal does not keep a command-wide preview overlay. + +The proposed read order is sleep, then workouts, then raw timeseries. That +order is part of what the maintainer approves. A failure in a later read +leaves the earlier read's pages committed and the reads after the failure +unattempted. The result says so. See D201. + +The coverage table in the specification is the proposed scope. Day +aggregates, sleep-linked physiology, recovery summaries, health scores, +meals, and body summaries are not requested. Open Wearables 0.11.0 already +returns reporting bounds on a day sample: an interval, `period_end`, +`computed_by`, and `stats`. Leaving those values out is incomplete coverage. +It is not required by D88. D88 forbids inventing a midnight. It does not +forbid storing a bound the server sent, and it does not assign the work to +a version after Junction and automatic sync. The suggested version is 2.5.0. +That suggestion is not adopted, and it is not approval of the loss. + +The other choice is a preservation design: store those intervals with their +bounds and basis, after a new period type. This proposal does not add that +type, does not label an Open Wearables day as a Whoop cycle or an Oura day, +and does not turn a summary into a point or a score. + +Sleep requests `include=stages`. Workouts request `include=zones`. Stage +minute totals return either way. The timeline and the zones are null when +the expansion is omitted, so omitting it would drop them before +`supplied_fields` can keep them. This proposal requests them and keeps +unmapped fields under the server's names. It does not request +`include=segments`. Segments are a separate size and privacy choice because +they can carry nested route detail. A page over 8 MiB still fails. Rejected alternatives: @@ -121,7 +165,13 @@ Rejected alternatives: keep them. - Map `heart_rate` samples as points, or map recovery summaries onto midnight. Rejected because one invents a point quantity and the other - invents an instant (D88, D110). + invents an instant (D88, D110). The server's own period bounds are a + different fact. This proposal still does not store them. +- Send timeseries with an empty `types` list. Rejected because 0.11.0 then + returns every series. +- Put `device_id` on the match key in this pull only. Rejected because file + import and pull would stop sharing an identity. Changing both paths is a + separate decision. The pull guard rejects an ambiguous page instead. ## D200. The key, the server, and the user id stay out of the record @@ -133,11 +183,26 @@ The child process receives it as `ATH_CORE_OPEN_WEARABLES_KEY`. The key is not a command argument. If the password store is missing, the command refuses and does not write a file. -`ath key clear openwearables` deletes that saved key. `ath key clear` with -no name still clears only the gateway keys. The Open Wearables key is cleared -only when it is named. `ath key` keeps its gateway lines and adds one line -that says whether an Open Wearables key is saved or set in the environment. -The line does not include the key. Garmin's key command is unchanged. +Open Wearables is not added to the gateway list. `GATEWAYS` stays `vercel` +and `openrouter`. `ath key clear` with no name still clears only those +gateway keys, and it still exits successfully when that is what it did. +When a saved Open Wearables key remains, the text adds two sentences: the +Open Wearables key remains saved, and `ath key clear openwearables` removes +it. When no saved Open Wearables key remains, the gateway sentences stay as +they are today. `ath key clear vercel` and `ath key clear openrouter` do not +remove the Open Wearables key and do not gain that sentence. + +`ath key clear openwearables` deletes the password-store key only. It does +not unset `OPEN_WEARABLES_API_KEY`. The text says the saved key was removed. +When the environment variable is set, the text also says that key is still +available and a pull can still use it. When the variable is unset, the text +does not claim an environment key remains. + +`ath key` keeps its gateway lines. It adds separate lines for a saved Open +Wearables key and for `OPEN_WEARABLES_API_KEY`, and it prints neither value. +`ath key --json` keeps `saved` and `environment` as the gateway lists they +are today, and adds `openwearables.saved` and `openwearables.environment`. +Garmin's key command is unchanged. The server is `--base-url` or `OPEN_WEARABLES_BASE_URL`. The user id is `--user` or `OPEN_WEARABLES_USER_ID`. Neither is written into the database, @@ -149,13 +214,19 @@ password, no path other than empty or `/`, no query, and no fragment. `http` is allowed only for `localhost`, `127.0.0.1`, and `::1`. Any other host requires `https`. The pull appends `/api/v1` itself. Redirects are not followed. A timeout, a non-JSON body, or an HTTP error becomes the page -failure in D201. The printed error is the status and, when the body is -problem JSON, the `code`. It does not include the request path. The path -contains the user id. The response body is checked for the key before -`apply_mapping`. A body that contains the key is not written. The key is -removed from any text the command prints. A result that still contains the -key is replaced with a fixed refusal, as the Garmin pull already does for -its own key. +failure in D201. The printed error is a fixed sentence and the HTTP status. A problem `code` +is printed only when it is one short token and does not contain the key, +the origin, or the user id. Otherwise it is withheld. A transport error or +a parser error is replaced with a fixed sentence that has no URL, no path, +and no user id. + +After the body is read inside the size cap and parsed, and before +`apply_mapping`, `open_wearables.rs` walks every object key and every string. +A value that contains the API key, the selected origin, or the selected user +id rejects the whole page. The row is not rewritten. A scan of the raw text +misses a Unicode escape. The raw-text scan and the check before printing +stay as defense in depth. They are not what keeps the key out of a committed +page. Named clear of the saved key does not revoke it on the server. The shell history can contain the server and the user id when they are passed as flags. The key is not a flag. `ath key set openwearables`, or @@ -180,22 +251,41 @@ Rejected alternatives: Each response page is one `apply_mapping` call. D189 still makes that call one transaction: a failure rolls the page back, and a preview rolls the page -back after counting. The pull itself is a series of those calls. Sleep pages -finish before workout pages, then timeseries pages. - -The command previews unless `--yes` is present. `--json` is a preview and -does not write, matching `ath import --mapping`. `--yes` writes each page as -that page succeeds. If a later page fails, pages already written stay. The -message names the read. When at least one page was written, it says those -pages are kept. It says to run the same command again. An empty range is a -successful pull with zero records. A repeat uses the -match key from D181 and the replace from D182, so an unchanged row is not -written again. +back after counting. The pull itself is a series of those calls. The proposed +order is sleep pages, then workout pages, then timeseries pages. A committed +page follows D189. A committed page does not mean the pull is complete. + +The command previews unless `--yes` is present. `--json` does not write, +with or without `--yes`, matching `ath import --mapping`. `--yes` without +`--json` writes each page as that page succeeds. The text of that write +reports actual committed counts. Preview text and `--json` report +`estimated` counts against the pre-pull database, and committed zeros. + +Each of `sleep`, `workouts`, and `timeseries` is `completed`, `failed`, +`skipped`, or `not_attempted`. `skipped` is the timeseries read when the +mapping named no types. `range_complete` is true only on a `--yes` write +whose reads finished without a failed page. The success sentence is printed +only then. A non-zero committed count with an incomplete range is a partial +pull. The message names the failed read, names any read not attempted, gives +the retained counts, and says to run the same command again. A preview that +fails writes nothing, including pages that had already been counted. + +Before `apply_mapping`, the page must be a JSON object, `data` must be an +array, `pagination` must be an object, and `has_more` must be a boolean. +Anything else fails the page. It is not an empty success. The result keeps +a `left_out` total and at most 20 examples. + +An empty range whose three reads completed is a successful pull with +committed counts of zero and `range_complete` true. A repeat uses the match +key from D181 and the replace from D182, so an unchanged row is not written +again. A rerun after a partial write leaves the committed rows in place, +runs the failed read again, and runs any read that was not attempted. `has_more: false` is the only successful end of a read. A repeated cursor, a null cursor while `has_more` is true, the 1000-page cap, and a body over -8 MiB fail that read. The failed page is not written. The success line is -not printed. A cursor with the `prev_` prefix is not sent. +8 MiB fail that read. The failed page is not written. Later reads are +`unattempted`. The success line is not printed. A cursor with the `prev_` +prefix is not sent. `limit` is 1000. One attempt is made per request. There is no retry. The connect timeout is 10 seconds and the read timeout is 30 seconds. @@ -215,14 +305,16 @@ records the disagreement between the docs and the 0.11.0 parser. Queries that are sent: - Sleep: `start_date`, `end_date`, `limit`, `cursor` after the first page, - `filter_by_priority=false`. `is_nap` is omitted, so naps and main sleep - both return. `include` is omitted. -- Workouts: `start_date`, `end_date`, `limit`, `cursor` after the first page. - No priority flag, because 0.11.0 has none and current `main` already - returns every device when the flag is absent. -- Timeseries: `start_time`, `end_time`, `limit`, `resolution=raw`, - `filter_by_priority=false`, `types` from the mapping file, and `cursor` - after the first page. + `filter_by_priority=false`, `include=stages`. `is_nap` is omitted, so naps + and main sleep both return. +- Workouts: `start_date`, `end_date`, `limit`, `cursor` after the first page, + `include=zones`. `include=segments` is not sent. No priority flag, because + 0.11.0 has none and current `main` already returns every device when the + flag is absent. +- Timeseries, only when the mapping names at least one type: `start_time`, + `end_time`, `limit`, `resolution=raw`, `filter_by_priority=false`, repeated + `types` from the mapping file, and `cursor` after the first page. No types + means no request. `source_selection` is not sent. On 0.11.0 the parameter does not exist. On current `main`, omitting it returns every device when the priority flag is @@ -232,7 +324,11 @@ Rejected alternatives: - One transaction for the whole range. Rejected because a raw range can be large, and a failure at the end would discard pages that had already - succeeded. Each page is still atomic. + succeeded. Each page stays atomic under D189. The pull's result still says + the requested range is incomplete when a later read failed or was not + attempted. +- Treat a committed page as a finished pull. Rejected because the person and + an agent would read a partial database as the whole requested range. - Store a resume cursor in the database. Rejected because the same command finds the same rows by their match keys, so a stored cursor would be a second copy of progress. diff --git a/build-history/v2.2.0/progress.md b/build-history/v2.2.0/progress.md index af7ea323..2ed29e09 100644 --- a/build-history/v2.2.0/progress.md +++ b/build-history/v2.2.0/progress.md @@ -5,7 +5,7 @@ program, the record, or the database has changed for 2.2.0. | Step | What | Status | |---|---|---| -| 0 | The plan: spec, decisions D198–D202, and the Open Wearables study | written, not approved | +| 0 | The plan: proposals D198–D202, and the Open Wearables study. Revised after product, insights, engineer, and verify reviews of `d1fdde1`. Still not adopted. The new head needs re-review | written, not approved | | 1 | Version 2.2.0, migration step 5, no new column (D198) | not started | | 2 | `ath pull openwearables` in `ath-core`, using the shipped mapping (D199, D201) | not started | | 3 | Key, server, and user id kept out of the record (D200) | not started | diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index 9a2482fc..77db2b2b 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -4,8 +4,8 @@ Status: **plan only. The maintainer has not approved it. Not approved for build. `ath pull openwearables` reads one person's sleep, workouts, and raw samples from an Open Wearables server they run, and writes them with the mapping file -that version 2.1.0 already ships. The decisions are D198 through D202 in -[decisions.md](decisions.md). The evidence is +that version 2.1.0 already ships. The proposals are D198 through D202 in +[decisions.md](decisions.md). They are not adopted. The evidence is [appendix/open-wearables-api.md](appendix/open-wearables-api.md), checked on 6 November 2026. @@ -46,33 +46,84 @@ The same three values may come from `OPEN_WEARABLES_BASE_URL`, `OPEN_WEARABLES_USER_ID`, and the key variable above. A flag wins over the environment when both are set. -The first run writes nothing. It prints: +The first run writes nothing. `--json` writes nothing, including when +`--yes` is also present. That is the same rule as `ath import --mapping`. +`ath pull garmin --json` still writes. `--file` chooses a database, as on +the other commands. + +A review of the previous head asked for the committed result in JSON as well +as in text. This proposal does not add a JSON mode that writes. Section 7 +requires `--json` and `--json --yes` to leave the database unchanged. The +committed result is the text of `--yes` without `--json`. A writing JSON +report would be a different choice. It is not this proposal. + +Preview text, and every `--json` result, labels counts `estimated`. Each +page is counted against the database as it was before this command, then +rolled back. A match key that appears on two pages, or a server that changes +between the preview and `--yes`, can make the estimate differ from the +write. The estimate is not a promise of the final new, changed, and +unchanged split. Exact equality would need a command-wide overlay. This +proposal does not add one, and it does not add that work to `mapping.rs`. + +Preview text prints: - one line that a date-only bound is sent as typed, and Open Wearables decides what that day means -- counts, by record type, of sleep sessions, workouts, points, summaries, and - scores that would be new, changed, or unchanged -- two fixed lines: this pull asks for raw samples only, so a nightly - heart-rate variability, resting heart rate, blood oxygen, or VO2 max that - the server keeps as a day value is not in this pull; and the heart-rate - stream is not stored, while a workout's average and maximum heart rate are - stored when the server sent them -- how many rows were left out, then up to 20 left-out lines +- `preview only; nothing stored` +- `reads finished` or `reads incomplete` +- one line each for `sleep`, `workouts`, and `timeseries`: `completed`, + `failed`, `skipped`, or `not attempted` +- estimated counts, by record type, of sleep sessions, workouts, points, + summaries, and scores +- committed counts of zero +- the coverage lines in section 2 +- `left_out` as a total plus at most 20 example lines - `nothing written; pass --yes after reviewing this preview` -`--yes` writes, then prints those same two limit lines. It prints -`pulled openwearables from through ` only when every read ended -because `has_more` was false. `--json` prints the structured result and does -not write, including when `--yes` is also present. That is the same rule as -`ath import --mapping`. `ath pull garmin --json` still writes, which is the -Garmin command as it is today. `--file` chooses a database, as on the other -commands. +`--yes` without `--json` commits each successful page. That commit is one +`apply_mapping` transaction (D189). It is not a completed pull. The text +prints actual committed counts for pages kept. It prints `requested range + through is complete` only when every read ended with `has_more` +false, or timeseries was skipped because the mapping named no types. Only +then does it print `pulled openwearables from through `. + +If a later page fails, the command exits nonzero. The text says the +requested range is incomplete, names the failed read, names any read not +attempted, prints the retained counts, and says to run the same command +again. It does not print the success sentence. The failed page leaves no +rows and no revisions. An empty range whose reads finished says the range +is complete, with committed counts of zero. + +`--json` uses this shape. `written` is false. `committed` is zero. +`estimated` holds the page-local estimates. `range_complete` is false, +because a preview has not stored the range. `reads_finished` is true only +when every read completed or was skipped. The object has no key, server, +user id, or request path. + +```json +{ + "from": "2026-01-01", + "to": "2026-01-07", + "written": false, + "range_complete": false, + "reads_finished": false, + "reads": { + "sleep": "completed", + "workouts": "failed", + "timeseries": "not_attempted" + }, + "estimated": { + "sleep_session": { "new": 1, "changed": 0, "unchanged": 0 } + }, + "committed": { + "sleep_session": { "new": 0, "changed": 0, "unchanged": 0 } + }, + "left_out": { "total": 0, "examples": [] } +} +``` -A failed page names the read (`sleep`, `workouts`, or `timeseries`). The -command exits with a failure and does not print the success line. When -`--yes` had already written a page, the message says those pages are kept. -It says to run the same command again. An empty range prints zero counts and -is a success, and it still prints the two limit lines. +The same record types are present for workouts, points, summaries, and +scores. The example above is shortened. `--date` stays required only for `garmin`. `--from` and `--to` are required only for `openwearables`, and they are flags, not environment variables. @@ -81,19 +132,41 @@ environment named above supplies them. `ath pull garmin --date YYYY-MM-DD` is otherwise unchanged. `ath pull` with any other name still fails. The failure text becomes `pull reads garmin or openwearables`. -The saved key can read every user on that server. `ath key` shows whether it -is saved, without printing it. `ath key` with no further word does not remove -it. `ath key clear` with no name leaves it. `ath key clear openwearables` -removes it. +The saved key can read every user on that server. `ath key` shows whether a +key is saved in the password store and whether `OPEN_WEARABLES_API_KEY` is +set, without printing either value. Those are different facts. `ath key` +with no further word does not remove the saved key. + +`ath key clear` with no name still clears only the gateway keys, `vercel` +and `openrouter`, and it still exits successfully. Open Wearables is not a +gateway name, so this command does not delete that saved key. When a saved +Open Wearables key remains, the text keeps the gateway sentence and adds +`The Open Wearables key remains saved.` and `Remove it with ath key clear +openwearables.` When no saved Open Wearables key remains, the gateway +sentences stay as they are today. + +`ath key clear openwearables` removes the saved key from the password store. +It does not change `OPEN_WEARABLES_API_KEY`, and it does not revoke the key +on the server. When that variable is set, the text says the saved key was +removed and the environment key is still available, so a pull can still use +it. `ath key` still reports the environment key after the saved key is gone. +When the variable is unset, the text says only that the saved key was +removed. `ath key clear vercel` and `ath key clear openrouter` stay the +gateway commands they are today. ## 2. What this release leaves for later -D198 names the boundary. File imports stay. The Garmin pull stays. Junction is -2.3.0. Automatic sync, retries, token refresh, and backfill are 2.4.0. -Storing day-level heart-rate variability, resting heart rate, blood oxygen, -and VO2 max is 2.5.0, and so is the heart-rate stream. That version is not a -decision, made here, to add an Open Wearables period type. A shared connector -interface is later than that. +D198 names the proposed boundary. File imports stay. The Garmin pull stays. +A Junction pull is proposed as 2.3.0. Automatic sync, retries, token refresh, +and backfill are proposed as 2.4.0. None of those numbers is adopted. + +This proposal pulls sleep and workouts first, then raw samples for the types +the checked mapping names. The maintainer is asked to accept incomplete +coverage, or to reject it in favor of a preservation design. The two choices +are in the table below. This proposal is the incomplete one. It does not add +aggregates under another name. Suggesting 2.5.0 is not approval of the loss, +and it is not a claim that Open Wearables lacks reporting bounds. 2.5.0 is +not adopted. A shared connector interface is later than that suggested slot. This release also leaves out: @@ -105,13 +178,52 @@ This release also leaves out: - timeseries resolutions other than `raw` - the heart-rate stream, steps, and the other series the mapping file does not name +- workout segments (`include=segments`) - storing the server address, the user id, the API key, or a resume cursor -On Open Wearables 0.11.0, day and session values are no longer raw samples. -A raw pull can return an empty timeseries for resting heart rate, nightly -heart-rate variability, blood oxygen, and VO2 max even when the server holds -them as day rows. Sleep sessions and workouts still return. The release does -not invent a midnight timestamp for those day rows (D88, D110, D199). +On Open Wearables 0.11.0, day and session physiology are not raw samples. +A raw query can return nothing for a value the server holds as a day row or +as a sleep-linked aggregate. Fetching `SleepSession` does not bring those +scalars back: the session object has durations and stage totals, not resting +heart rate, heart-rate variability, blood oxygen, skin temperature, or +respiration. A day response from the timeseries route carries a reporting +interval, `period_end`, `computed_by`, and `stats`. Those are bounds the +server already has. Storing them does not require Athletic Standard to invent +a midnight instant (D88, D110). This proposal still does not request +`resolution=1day`, and it does not add an Open Wearables period type. +`ProviderReportingPeriodType` stays the Whoop, Oura, and Apple values it has. +An Open Wearables local day is not stored as a Whoop cycle or an Oura day. + +Some raw samples do exist. Oura interval heart-rate variability and Garmin +health-snapshot RMSSD and SDNN can be raw. A raw pull is not a claim that +every heart-rate variability or blood-oxygen value is absent. Coverage is by +provider and by granularity. + +| What the server can hold | This proposal | +|---|---| +| Sleep session: times, durations, stage minute totals | Stored by the shipped mapping | +| Sleep stage timeline (`sleep_stage_intervals`) | Requested with `include=stages`, then kept under the server's names. Totals return even when `include` is omitted. A null timeline means not requested when `include` was omitted, and means the server sent none when `include=stages` was sent | +| Workout average and maximum heart rate | Stored when the server sent them | +| Workout heart-rate and power zones | Requested with `include=zones`, then kept under the server's names. Not turned into scores | +| Workout segments | Not requested. Segments can carry nested route detail. Size and privacy are the reason. The 8 MiB page cap is a separate limit | +| WHOOP sleep-linked resting heart rate, RMSSD, blood oxygen, skin temperature | Not requested. Not on `SleepSession`. Not recovered by a raw query | +| Oura sleep scalar respiratory rate and resting heart rate | Not requested. Distinct from Oura's raw heart-rate-variability samples, which this pull can store when the mapping names them | +| Day resting heart rate, nightly heart-rate variability, blood oxygen, VO2 max | Not requested. The server can return them at `resolution=1day` with real period bounds | +| Heart-rate stream, steps, latitude, longitude | Not requested. The shipped mapping has no `type.heart_rate` line. A replaced mapping that names an existing field does request that series | + +The preview and the `--yes` text say which of those rows were not requested. +They do not call a missing row a zero, a server gap, or a `left_out` row. +`left_out` counts only rows the server returned and the mapping refused. +Not requested, zero, missing on the server, and returned-but-left-out are +four different facts. + +`source.provider` is the Open Wearables integration name. `source.source` is +the writer inside that integration. The mapping's `writer_field` is a +convention. It is not proof that the device vendor computed the value. The +shipped bases stay `provider_or_aggregator` for session numbers and +`provider` for a provider score. Nullable `computed_by` on a raw sample is +not a new basis. Workout fields may be filled by Open Wearables and have no +per-field `computed_by` in this response. ## 3. How a response becomes records @@ -134,11 +246,39 @@ same Open Wearables object, or an `ath import --mapping open-wearables` of a saved copy of that object, updates the same rows. The writer is `source.provider`. The sensor string is `source.device_type`, -`source.device`, and `source.source`. Two devices that share those three -strings share one source and one baseline. `source.device_id` is stored as -hardware on the source-device row. It does not split the source. That is the -mapping file version 2.1.0 already ships (D183). The queries in D201 ask for -every device. +`source.device`, and `source.source`. Two devices with different triples are +two sources and two baselines. Two devices that share the triple share one +source and one baseline. `source.device_id` is stored as hardware on the +source-device row. It does not split the source, and it is not part of the +match key (D181, D183). The mapping file is not rewritten. File import and +pull of the same mapped object, in either order, keep one record id when +they use that same checked mapping. A replaced mapping that changes `name` +or `route` is a different source. The dedupe promise does not cover that +file. + +Open Wearables uses `device_id` to tell same-model devices apart. The pinned +note is `backend/app/schemas/utils/metadata.py` at +`183e8cc4f6de897dbd288c93d49a691f2cf721ae`. A shared match key is then +conditional loss, not the intentional choice to share a baseline. Two +samples with the same triple, the same type, and the same timestamp, and +different `device_id` values, are one timeseries key. Inside one mapping +call the second row is left out. Across calls, D182 can replace the stored +point. + +This proposal does not put `device_id` on the match key. Doing that for the +pull alone would break the file-import identity. Doing it for both paths +would be a new decision, and putting it on the sensor string would also +split baselines. The maintainer can adopt that decision later. It is not +this proposal. + +Until that decision, the pull guard lives in `open_wearables.rs` and not in +`mapping.rs`. Before `apply_mapping`, if this page, or this page together +with a key already accepted in this command, has one timeseries match key +and two `device_id` values, the page is rejected with a fixed sentence. +Nothing from that page is written. On `--yes`, earlier pages stay and the +range is incomplete. A later command that contains only the second device +can still replace the stored point. The proposal names that remaining hole. +It does not close it. The queries in D201 ask for every device. `zone_offset` is not copied into `start_at`. It remains in `supplied_fields` when the server sends it. The timestamp text is the server's `start_time`, @@ -161,10 +301,26 @@ The process refuses a base URL that could carry the key in the URL itself. It refuses plain `http` except to loopback. It does not follow a redirect, so the key cannot be sent to a second host. One attempt, then stop. Timeouts are 10 seconds to connect and 30 seconds to read. One response may be at most -8 MiB. One read may be at most 1000 pages. Before a page is written, the -response text is checked for the key. A body that contains the key is not -written. Printed failure text is the status and, when the body is problem -JSON, the `code`. It omits the request path, which contains the user id. +8 MiB. One read may be at most 1000 pages. + +The body is read inside that cap and parsed before any `apply_mapping` call. +The guard is in `open_wearables.rs`. It walks every decoded object key and +every decoded string. A value that contains the API key, the selected +origin, or the selected user id rejects the whole page. The page is not +rewritten and it is not mapped. A Unicode escape such as `\u0073` is visible +only after parsing, so a scan of the raw text is not enough. The raw-text +scan still runs on a body that did not parse, and the parent still refuses +to print the key. Those checks are defense in depth. They do not repair a +page that has already committed. + +Printed failure text is a fixed sentence plus the HTTP status. A server +problem `code` is printed only when it is a single token of letters, digits, +`_`, or `-`, at most 64 characters, and it does not contain the key, the +origin, or the user id. Any other code is withheld. A transport error or a +parser error is replaced with a fixed sentence. The sentence has no URL, no +path, and no user id. The result keeps a `left_out` total and at most 20 +example lines. It does not keep every id or every source string. The child +output has to stay inside the 64 MiB buffer in `src/ath-core.ts`. There is no Athletic Standard telemetry on this command. The server the person named is the only host contacted. @@ -206,9 +362,10 @@ regenerated. rewritten by this release. `pnpm generate:skill-cli` runs because help text changes (D80). `AGENTS.md`, `build-history/README.md`, and `SPEC.md` are updated in the build so they name 2.2.0 as the software. `docs/connections.md` -keeps the file imports and states the same limit as section 1: a raw pull -does not store day-level resting heart rate, nightly heart-rate variability, -blood oxygen, VO2 max, or the heart-rate stream. This plan's edits to +keeps the file imports and states the same limit as section 2: this proposed +pull does not store the day and sleep-session physiology the table leaves +out, and it does not store the heart-rate stream. The note says that +coverage is a proposal, not an adopted later version. This plan's edits to `AGENTS.md` and `build-history/README.md` only point at the plan. A database from 2.1.0 needs `ath migrate` before the pull. The migrate @@ -233,16 +390,20 @@ A shared trait is the later connector work, and this release does not add it. `mapping.rs` changes in one place. `apply_mapping` keeps its `outcome` field and adds counts by record type. The pull sums only `sleep_session`, `workout_session`, `point_measurement`, `provider_summary`, and -`provider_score`. It does not add `outcome` across pages. `outcome` counts -the source-device row in the same group, and a preview rolls each page back, -so that total would not match the write. The three printed record families, -plus summaries and scores, do match, because each row's match key is looked -up on its own. +`provider_score`. A committed page adds those counts to the actual committed +result. A rolled-back preview page adds them to `estimated`. It does not add +`outcome` across pages. `outcome` counts the source-device row in the same +group. Filtering that row out of the totals does not make a preview equal a +write. Each preview page is rolled back, so page two does not see page one. The Rust command reads the key from the environment only. It has no `--key` -flag. The child checks the response body for the key before `apply_mapping`. -The parent checks that stdout and stderr do not contain the key before -printing, and the child does the same before it returns JSON. +flag. The decoded-key walk in section 4 runs before `apply_mapping`. The +parent still checks stdout and stderr before printing. + +The child returns the object from section 1. The parent prints it for +`--json`, and prints sentences for a person. `--json` still does not write. +The success sentence is parent text, and only after `--yes` when the range +is complete. The program runs on Linux, macOS, and Windows with the same command. The fixture server listens on `127.0.0.1` and an ephemeral port, which is the @@ -258,69 +419,139 @@ list. A new file, if one is required for a two-page response, is synthetic, invented, and added to `scripts/check-public-data.ts` with its hash. No real export is copied. +Before the first request, `--from` and `--to` are both dates or both +timestamps with an offset, `--from` is not after `--to`, and a calendar date +is a real date. A number is refused here even though Open Wearables accepts +Unix seconds. A bad bound does not open a socket. + Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: -- two pages, the second `next_cursor`, then `has_more: false`, and the - success line is printed -- a repeated cursor fails that read, writes nothing for that page, and does - not print the success line -- `has_more: true` with a null cursor fails the page and writes nothing for it -- a 401, a 429, a timeout, and a non-JSON body fail the page -- a redirect is not followed, and the key is not sent to the second host -- `http` to a non-loopback host is refused before a socket opens -- a base URL with a user name, a query, or a path is refused -- the request header is `X-Open-Wearables-API-Key`, and the key is not in the - result or the error -- `filter_by_priority=false` and `resolution=raw` are present, and each - mapping type is one repeated `types` query parameter, with duplicates - removed (`skin_temperature` is named twice in the file and sent once) -- the date strings are the ones the caller passed -- `page-sleep.json`, served as the sleep response, becomes a sleep session -- a workout page with one `entry_source` of `manual` and one automatic - neighbor leaves the manual row out and keeps the neighbor -- a user id that is not a UUID is refused before a socket opens -- `page-raw.json` stores the mapped sample, and `page-5min.json` is left out -- RMSSD and SDNN stay different quantities -- a second run reports unchanged +- two pages, the second `next_cursor`, then `has_more: false`. `--yes` sets + `range_complete` in the text and prints the success sentence +- the same session id on two pages, identical payload: the preview estimate + counts two new rows, and `--yes` counts one new and one unchanged +- the same session id on two pages, changed payload: the preview estimate + counts two new rows, and `--yes` counts one new and one changed +- a valid page, then a failing page, under `--yes`. The failure is one of a + 401, a 429, a repeated or null cursor, an invalid row, or a body over + 8 MiB. Page 1 remains. Page 2 adds no rows and no revisions. No later read + runs. The exit is nonzero. The success sentence is absent. The text gives + the retained counts. The same command run again stores no second copy +- the same failure sequence with no `--yes`, and again with `--json --yes`, + leaves zero rows, including from page 1 +- a sleep-only mapping, installed where `.agents/mappings/` wins, produces + no timeseries types. The server sees no `/timeseries` request. Counts for + that read are zero and the read is `skipped`. A nonempty type list is + still one repeated `types` parameter per name, with duplicates removed +- a missing object, a `data` value that is not an array, a missing + pagination object, or a `has_more` value that is not a boolean fails the + page before `apply_mapping`. It is not an empty success +- `filter_by_priority=false` and `resolution=raw` are present on the reads + that send them. Sleep sends `include=stages`. Workouts send `include=zones`. + Neither sends `include=segments`. A fixture with stages omitted has null + intervals and still has stage totals. A fixture with `include=stages` keeps + the intervals under the server's names +- two distinct sensor triples become two sources. The same triple with two + `device_id` values on one page rejects that page and writes nothing from + it. The same collision on page 2, after page 1 committed a different key, + keeps page 1 and writes nothing from page 2 +- import the synthetic objects, then pull them, and pull them, then import + them. Both orders keep the same record ids, sources, match keys, and + revisions when both paths use the same checked mapping. A sample keeps + basis `provider_or_aggregator`. A provider score keeps basis `provider` +- `page-sleep.json` becomes a sleep session. A manual workout is left out + and its automatic neighbor is kept. `page-raw.json` is stored. + `page-5min.json` is left out. RMSSD and SDNN stay different quantities - a changed end time keeps the record id and increases the revision -- a `__proto__` supplied field fails the page and leaves that page unwritten -- a deleted mapped source is left out -- a Garmin file import of another workout remains a second source -- the 1000-page cap and the 8 MiB cap fail that read, write nothing for the - failed page, and do not print the success line; the page cap is tested with - a small limit passed into the loop, not by looping 1000 times -- a timestamp with no offset is left out; the stored fixture's timestamps - include `Z`, and the test does not add `Z` to a bare timestamp - -TypeScript tests cover the missing-key sentence, `ath key set` and -`ath key clear` for `openwearables` against the memory store, the preview -sentence, and `--json` not writing. They do not open the real password store. +- a `__proto__` supplied field fails the page +- a literal key, a Unicode-escaped key in a nested unconsumed field, the + key used as an object key, the selected origin, and the selected user id + each reject the page before mapping. The database, its revisions, and the + export do not contain them. The error text does not contain them. A page + that committed earlier remains. A problem `code` or a transport error that + contains those values is withheld +- a redirect is not followed. `http` to a non-loopback host is refused. A + base URL with a user name, a query, or a path is refused. A user id that + is not a UUID is refused before a socket opens +- the 1000-page cap is tested with a small limit passed into the loop +- a timestamp with no offset is left out. The stored fixture's timestamps + include `Z`. The test does not add `Z` +- a deleted mapped source is left out. A Garmin file import of a different + workout remains a second source +- `left_out` in the result is a total and at most 20 examples + +Migration tests, in the build gate: + +- a synthetic 2.1.0 database makes `Store::open` refuse before any network + call. `ath migrate` previews without writing. It still previews, backs up, + and asks, as D124 requires. The target it names is `2.2.0` +- a confirmed migrate backs up, then sets the record version to `2.2.0`, + SQL schema 5, and `user_version` 5. Record ids, revisions, deletions, and + attachments are unchanged. A second migrate does nothing +- `ath init` creates a database that is already `2.2.0`, SQL schema 5, and + `user_version` 5, and `ath check` exits 0. Step 4 still writes `2.1.0` and + schema 4, and the create path runs step 5 after that +- databases at `1.0.0` and `2.0.0` still open for migrate. Packages at + `2.0.0` and `2.1.0` still import. `spec/sql/migrations/004-version-2-1.sql` + and the folders `schema/2.0.0/` and `schema/2.1.0/` stay byte-identical + +TypeScript tests use the memory store and do not open the real password +store. They cover: + +- the missing-key sentence +- `ath key set openwearables` +- `ath key clear` with no name, when an Open Wearables key is saved, clears + `vercel` and `openrouter` only, exits successfully, and prints that the + Open Wearables key remains saved, with the command `ath key clear + openwearables` +- `ath key clear` with no name, when no Open Wearables key is saved, keeps + today's gateway sentences +- `ath key clear vercel` does not remove a saved Open Wearables key +- `ath key clear openwearables` removes the saved key and, when + `OPEN_WEARABLES_API_KEY` is set, says that variable is still available. The + variable is still set afterward +- `ath key --json` keeps `saved` and `environment` as gateway lists and adds + `openwearables.saved` and `openwearables.environment` +- a preview `--json` has `written: false`, committed zeros, `estimated` + counts, and `range_complete: false` +- `--json --yes` after a later-page failure writes nothing, including page 1 `pnpm check:public-data`, `pnpm typecheck`, `pnpm test`, and `pnpm build` pass, and `cargo test` passes, before the build is called done. -## 8. Laptop card and the proof - -The card uses the fixture server or Open Wearables' own synthetic seed. It -does not use a real account or a real export. - -1. Create an empty database with `ath init --yes --empty` in a temporary folder. -2. Save the fixture key with `ath key set openwearables`. -3. Run the pull for `2026-01-01` through `2026-01-07` without `--yes`. -4. Read the preview. Confirm the two limit lines are on screen, a left-out - line is visible, and the key is not. -5. Run the same command with `--yes`. `ath check` exits 0. -6. Run it with `--yes` again. The counts say unchanged. -7. Run `ath pull garmin` with no date and confirm it still asks for `--date`. -8. Import one existing synthetic Apple, WHOOP, or Oura fixture and confirm - `ath check` still exits 0. - -The build pull request's description carries screenshots or a short recording -of steps 3 through 6. The images are not committed. The numbers on screen are -the fixture's invented values. The release workflow on Linux, macOS, and -Windows is the cross-platform proof. The recording is one system. - -This plan pull request has no recording. +## 8. You test this (Laptop) + +The card uses the fixture server the tests use. It does not use a real +account or a real export. The build starts that server on `127.0.0.1` and an +ephemeral port, prints the port, and uses the fixture key and the fixture +user id. The range is `--from 2026-01-01 --to 2026-01-07`. The person pastes +the fixture key once into `ath key set openwearables`. + +1. Setup. Success: `ath init --yes --empty` creates the database, the key + command saves the fixture key, and the key is not on screen. Failure: + init fails, or the key is printed. +2. Preview. Success: the pull without `--yes` says nothing is stored, shows + estimated counts, says which physiology was not requested, and `ath check` + still passes. Failure: a row is written, or the key appears. +3. Write. Success: the same command with `--yes` says the requested range is + complete, shows committed counts, and `ath check` exits 0. Failure: the + success sentence appears while the range is incomplete, or `ath check` + fails. +4. Repeat. Success: `--yes` again reports the stored rows unchanged. + Failure: a second copy of a sleep session or a point appears. +5. Compatibility. Success: one synthetic Apple, WHOOP, or Oura import still + passes `ath check`, and `ath pull garmin` with no date still asks for + `--date`. Failure: that import or the Garmin command breaks. + +The automated cases in section 7 are not extra card steps. + +The build pull request's description carries a screenshot of each step and +one video that plays on the pull request page. The images are not committed. +The numbers on screen are the fixture's invented values. The release workflow +on Linux, macOS, and Windows is the cross-platform proof. The video is one +system. + +This plan pull request has no screenshots and no video. ## 9. Separate follow-ups @@ -363,9 +594,12 @@ Risks: pages have been kept. The study did not read the rate-limit middleware. - Date-only bounds mean whatever Open Wearables decides. The docs and the 0.11.0 parser disagree about UTC. This release does not correct that server. -- Day-level recovery values are absent after a successful pull, because they - are not requested. The two printed lines say so. Workout average and maximum - heart rate can still be stored. +- The table in section 2 is incomplete coverage, chosen on purpose and + still not adopted. It is separate from the same-model `device_id` + collision, which is conditional loss and rejects the ambiguous page. + Suggesting 2.5.0 does not approve either one. Workout average and maximum + heart rate can still be stored. Raw heart-rate variability can still arrive + when the mapping names it. - Fields on a sleep or workout object that the mapping does not consume are stored under the server's names. The shipped mapping does not request latitude or longitude. A replaced mapping file can name more series, and @@ -374,24 +608,32 @@ Risks: the password store exposes every user on that deployment. The command's job is to avoid copying the key into the record. -The maintainer approves or rejects this plan before any build. The proposal -to approve is D198 through D202, in particular: +The maintainer approves or rejects this plan before any build. D198 through +D202 are the proposal. They are not adopted. Reviews of commit `d1fdde1` +were incorporated here. Those reviews are not approval of this revision. +The next head needs their re-review. A product review accepted a migration +with no new column, under D152 and D184. That acceptance does not adopt D198. 1. One number, 2.2.0. Readable sets keep `1.0.0`. Step 5 runs on create and on migrate. No new column. A `2.1.0` database does not open until `ath migrate`. This release does not schedule, retry, refresh a token, backfill, or store a cursor (D198). -2. The mapping file writes the records. A 0.11.0 raw pull stores workout - average and maximum heart rate when the server sent them, and it can store - zero points for the day values. The heart-rate stream is not requested. - `ProviderReportingPeriodType` is unchanged. Storing the day values is - 2.5.0, and that is not a decision to add a period type (D199). -3. The key, the server, and the user id stay out of the record. Failure text - omits the request path. `ath key clear` leaves this key. - `ath key clear openwearables` removes it (D200). -4. Preview is the default. A failed later page keeps earlier pages, the - command fails, and it does not print the success line. A missing row is - not deleted. Date-only bounds are sent unchanged, and the server decides - the day. The 1000-page cap and the 8 MiB cap fail that read (D201). +2. Incomplete coverage, as the table in section 2, or a preservation design + that stores Open Wearables reporting intervals. This proposal is the + incomplete one. It does not invent a midnight, and it does not add a + period type. Suggesting 2.5.0 does not approve the loss. Sleep stage + timelines and workout zones are requested. Segments are not (D199). +3. The key, the selected origin, and the selected user id are rejected in + decoded JSON before a page is mapped. Failure text uses a fixed sentence. + `ath key clear` with no name still clears only the gateway keys and says + when the Open Wearables key remains. Named clear removes the saved key + only. It does not unset the environment and it does not revoke the server + key (D200). +4. Preview is the default and its counts are estimates. `--json` does not + write. `--yes` commits each successful page under D189, and a committed + page is not a completed pull. The text of `--yes` shows retained counts + and whether the requested range is complete. A missing row is not deleted. + An empty type list skips timeseries. Same-model `device_id` collisions + reject the ambiguous page and do not change the match key (D201). 5. The Windows cleanup and the maintainability notes stay separate. The count - by record type in `mapping.rs` is the only change in that file (D202). + by record type is the only `mapping.rs` change (D202). From da006a608c0f127ed17420131caa3af4d2e7663d Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 7 Nov 2026 00:00:04 +0000 Subject: [PATCH 03/60] Refuse a second device instead of replacing the stored point. Keep the current match key. Mapped import and pull share one binding check before any write, and a confirmed pull reports retained counts without a public JSON write. Co-authored-by: Michael Whitham --- build-history/v2.2.0/decisions.md | 66 +++++--- build-history/v2.2.0/progress.md | 2 +- build-history/v2.2.0/spec.md | 241 ++++++++++++++++++++---------- 3 files changed, 206 insertions(+), 103 deletions(-) diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index 516e884e..bd6acce6 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -36,12 +36,12 @@ not adopted. - 2.3.0 is a proposed Junction pull. This release does not call Junction. - 2.4.0 is proposed automatic incremental sync, saved sign-in refresh, retries, and backfill. This release has none of those. -- Day aggregates and the heart-rate stream are left out of this pull. D88 - supports that exclusion, because a day must not become an invented midnight. - D88 does not say they wait until after the proposed Junction pull and the - proposed automatic sync. This proposal suggests 2.5.0 for that work. The - maintainer decides the timing. `ProviderReportingPeriodType` stays the - Whoop, Oura, and Apple values it has now. +- Day aggregates and the heart-rate stream are left out of this proposed + pull. That is the proposed scope. D88 forbids a fabricated instant. It does + not forbid keeping a reporting bound the server sent, and it does not put + that work after Junction or automatic sync. This proposal suggests 2.5.0 + for that work. The maintainer decides the timing. `ProviderReportingPeriodType` + stays the Whoop, Oura, and Apple values it has now. - A connector interface that every future source would implement is later than the slot suggested for day aggregates. This release adds one module for this server. @@ -169,9 +169,18 @@ Rejected alternatives: different fact. This proposal still does not store them. - Send timeseries with an empty `types` list. Rejected because 0.11.0 then returns every series. -- Put `device_id` on the match key in this pull only. Rejected because file - import and pull would stop sharing an identity. Changing both paths is a - separate decision. The pull guard rejects an ambiguous page instead. +- Put `device_id` on the sensor string, and therefore on the match key, for + both import and pull. Not this proposal. It needs no new column, and the + mapping engine already joins configured sensor paths, but it changes + source, baseline, and key identity. Old triple-key rows would stay where + they are, and dedupe against them cannot be promised. A `device_id` that + contains `|` collides with the join unless those values are refused or + the join is encoded. The shared binding in the specification keeps the + current keys and refuses the unsafe write instead. +- Guard the pull only, or treat `source_devices.hardware` as the binding. + Rejected. Import after pull would still replace the point, and hardware + is one mutable column. The point's revisions do not contain `device_id` + today, because that path is removed as hardware. ## D200. The key, the server, and the user id stay out of the record @@ -257,18 +266,27 @@ page follows D189. A committed page does not mean the pull is complete. The command previews unless `--yes` is present. `--json` does not write, with or without `--yes`, matching `ath import --mapping`. `--yes` without -`--json` writes each page as that page succeeds. The text of that write -reports actual committed counts. Preview text and `--json` report -`estimated` counts against the pre-pull database, and committed zeros. +`--json` writes each page as that page succeeds. + +The child returns one bounded outcome for the mode it ran. A preview, +including public `--json`, has `written` false, committed zeros, estimated +counts, and `range_complete` false. A confirmed `--yes` has the actual +committed counts. `written` is true only when that command committed a new +or revised record. A successful repeat has `written` false and +`database_changed` false. The database is unchanged. The parent renders the +confirmed outcome as text. It renders the preview outcome as public JSON. +On a partial failure the child returns the confirmed outcome and then exits +nonzero. The parent renders the text before it uses that status. Each of `sleep`, `workouts`, and `timeseries` is `completed`, `failed`, -`skipped`, or `not_attempted`. `skipped` is the timeseries read when the -mapping named no types. `range_complete` is true only on a `--yes` write -whose reads finished without a failed page. The success sentence is printed -only then. A non-zero committed count with an incomplete range is a partial -pull. The message names the failed read, names any read not attempted, gives -the retained counts, and says to run the same command again. A preview that -fails writes nothing, including pages that had already been counted. +`skipped`, or `not_attempted`. The token is `not_attempted` in the outcome +and in the text. `skipped` is the timeseries read when the mapping named no +types. `range_complete` is true only on a `--yes` write whose reads finished +without a failed page. The success sentence is printed only then. A retained +count with an incomplete range is a partial pull. The message names the +failed read, names any `not_attempted` read, gives the retained counts, and +says to run the same command again. A preview that fails makes no database +changes, including for pages that had already been counted. Before `apply_mapping`, the page must be a JSON object, `data` must be an array, `pagination` must be an object, and `has_more` must be a boolean. @@ -279,7 +297,7 @@ An empty range whose three reads completed is a successful pull with committed counts of zero and `range_complete` true. A repeat uses the match key from D181 and the replace from D182, so an unchanged row is not written again. A rerun after a partial write leaves the committed rows in place, -runs the failed read again, and runs any read that was not attempted. +runs the failed read again, and runs any read that was `not_attempted`. `has_more: false` is the only successful end of a read. A repeated cursor, a null cursor while `has_more` is true, the 1000-page cap, and a body over @@ -356,9 +374,11 @@ open. They do not run on a pull. This build does not change them. `crates/ath-core/src/store.rs` is 1034 lines. `mapping.rs` is 1443. `persist.rs` is 1051. The pull is a new module so those files do not grow -for HTTP. `mapping.rs` may add the count by record type that D199 names, and -nothing else. Splitting the files is separate work. It is not required to -make the pull correct. +for HTTP. `mapping.rs` may add the count by record type that D199 names, and the +open-wearables device-binding check in the specification. That check is +shared by mapped import and pull, and it is limited to route +`open_wearables`. Nothing else is added to `mapping.rs`. Splitting the +files is separate work. It is not required to make the pull correct. `check_supplied_fields` runs in `store.rs` before insert and revise (D191). `persist.rs` `insert_record` writes `data_json` and does not call that check. diff --git a/build-history/v2.2.0/progress.md b/build-history/v2.2.0/progress.md index 2ed29e09..1a4a6dab 100644 --- a/build-history/v2.2.0/progress.md +++ b/build-history/v2.2.0/progress.md @@ -5,7 +5,7 @@ program, the record, or the database has changed for 2.2.0. | Step | What | Status | |---|---|---| -| 0 | The plan: proposals D198–D202, and the Open Wearables study. Revised after product, insights, engineer, and verify reviews of `d1fdde1`. Still not adopted. The new head needs re-review | written, not approved | +| 0 | The plan: proposals D198–D202, and the Open Wearables study. Revised after the re-reviews of `1124e56`. Still not adopted. The new head needs re-review | written, not approved | | 1 | Version 2.2.0, migration step 5, no new column (D198) | not started | | 2 | `ath pull openwearables` in `ath-core`, using the shipped mapping (D199, D201) | not started | | 3 | Key, server, and user id kept out of the record (D200) | not started | diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index 77db2b2b..58cf2edd 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -72,7 +72,7 @@ Preview text prints: - `preview only; nothing stored` - `reads finished` or `reads incomplete` - one line each for `sleep`, `workouts`, and `timeseries`: `completed`, - `failed`, `skipped`, or `not attempted` + `failed`, `skipped`, or `not_attempted` - estimated counts, by record type, of sleep sessions, workouts, points, summaries, and scores - committed counts of zero @@ -87,18 +87,23 @@ prints actual committed counts for pages kept. It prints `requested range false, or timeseries was skipped because the mapping named no types. Only then does it print `pulled openwearables from through `. -If a later page fails, the command exits nonzero. The text says the -requested range is incomplete, names the failed read, names any read not -attempted, prints the retained counts, and says to run the same command -again. It does not print the success sentence. The failed page leaves no -rows and no revisions. An empty range whose reads finished says the range -is complete, with committed counts of zero. - -`--json` uses this shape. `written` is false. `committed` is zero. -`estimated` holds the page-local estimates. `range_complete` is false, -because a preview has not stored the range. `reads_finished` is true only -when every read completed or was skipped. The object has no key, server, -user id, or request path. +If a later page fails, the child returns a typed outcome to the parent +before the process exits nonzero. The parent renders that outcome as text, +then uses the exit status. The text says the requested range is incomplete, +names the failed read, names any read that is `not_attempted`, prints the +retained counts, and says to run the same command again. It does not print +the success sentence. The failed page makes no database changes. Records +already stored stay, including their revisions. An empty range whose reads +finished says the range is complete. `written` is false when the confirmed +command changed nothing. The database is unchanged. That is not a claim that +the database has no rows. + +Public `--json`, with or without `--yes`, is only the preview outcome below. +`written` is false. `committed` is zero. `estimated` holds the page-local +estimates. `range_complete` is false. `reads_finished` is true only when +every read completed or was skipped. The read status token is +`not_attempted`, in this object and in the text. The object has no key, +server, user id, or request path. ```json { @@ -123,7 +128,16 @@ user id, or request path. ``` The same record types are present for workouts, points, summaries, and -scores. The example above is shortened. +scores. The example above is shortened. It is the preview outcome. + +The child returns a different outcome for `--yes` without `--json`. That +outcome has the actual `committed` counts, `database_changed`, and +`range_complete`. `written` is true only when that confirmed command +committed at least one new or revised record. A successful repeat has +`written` false, `database_changed` false, `range_complete` true, and +unchanged counts. A later-page failure has `range_complete` false and the +retained counts. The parent prints sentences from this outcome. It does not +print the outcome as public JSON. `--date` stays required only for `garmin`. `--from` and `--to` are required only for `openwearables`, and they are flags, not environment variables. @@ -248,37 +262,80 @@ saved copy of that object, updates the same rows. The writer is `source.provider`. The sensor string is `source.device_type`, `source.device`, and `source.source`. Two devices with different triples are two sources and two baselines. Two devices that share the triple share one -source and one baseline. `source.device_id` is stored as hardware on the -source-device row. It does not split the source, and it is not part of the -match key (D181, D183). The mapping file is not rewritten. File import and -pull of the same mapped object, in either order, keep one record id when -they use that same checked mapping. A replaced mapping that changes `name` -or `route` is a different source. The dedupe promise does not cover that -file. - -Open Wearables uses `device_id` to tell same-model devices apart. The pinned -note is `backend/app/schemas/utils/metadata.py` at -`183e8cc4f6de897dbd288c93d49a691f2cf721ae`. A shared match key is then -conditional loss, not the intentional choice to share a baseline. Two -samples with the same triple, the same type, and the same timestamp, and -different `device_id` values, are one timeseries key. Inside one mapping -call the second row is left out. Across calls, D182 can replace the stored -point. - -This proposal does not put `device_id` on the match key. Doing that for the -pull alone would break the file-import identity. Doing it for both paths -would be a new decision, and putting it on the sensor string would also -split baselines. The maintainer can adopt that decision later. It is not -this proposal. - -Until that decision, the pull guard lives in `open_wearables.rs` and not in -`mapping.rs`. Before `apply_mapping`, if this page, or this page together -with a key already accepted in this command, has one timeseries match key -and two `device_id` values, the page is rejected with a fixed sentence. -Nothing from that page is written. On `--yes`, earlier pages stay and the -range is incomplete. A later command that contains only the second device -can still replace the stored point. The proposal names that remaining hole. -It does not close it. The queries in D201 ask for every device. +source and one baseline. `source.device_id` is copied to `source_device.hardware`. +It does not split the source, and it is not part of the match key (D181, +D183). Route, writer, and sensor are the source identity. The mapping +`name` is a label. Changing `name` alone does not change the source or the +match key. File import and pull of the same mapped object, in either order, +keep one record id when route, writer, and sensor are the same. + +Open Wearables uses `device_id` to tell same-model devices apart when a +provider sends it. The pinned field is optional (`str | None`) in +`backend/app/schemas/utils/metadata.py` at +`183e8cc4f6de897dbd288c93d49a691f2cf721ae`. This study does not treat that +id as stable or unique for every provider. A timeseries sample has no +sample id. Its match key is the writer, the sensor, the kind, the type, and +the UTC time. Two `device_id` values therefore share one key. The mapping +removes `source.device_id` from the point because that path is hardware, so +the point and its revisions do not carry it. `source_devices.hardware` is +one mutable column. A later write can revise it. It is not a binding. +D45 records hardware without splitting a source. D181 and D182 then replace +one key with a different payload. None of those decisions says a second +device's observation may replace the first. + +The recommended rule keeps the match key, the sensor, and the baseline. +Putting `device_id` into the sensor list would split sources and baselines, +change keys, and drop the promise that an old triple-key row and a new pull +are one record. The sensor join uses `|`, so a `device_id` that contains +`|` is not a safe extra part unless values containing `|` are refused or +the join is encoded. That identity change is not this proposal. Old rows +are not rewritten, moved, or deleted. + +Both `ath import --mapping` and `ath pull` call `apply_mapping`. The check +lives there, for route `open_wearables` only, inside the same transaction +as the write and before `insert_group` changes a source device or a +timeseries record. Other routes are not checked. A pull-only check would +leave import-after-pull able to replace the point. The check reads every +incoming row, not only the first. + +The binding is `source.supplied_fields.device_binding`, one nonempty +string. `SourceData` already allows `supplied_fields`, so step 5 adds no +column and does not copy hardware into this field. The binding is written +once, with the first accepted write, and is never replaced by another id. + +- A new source whose accepted rows share one nonempty `device_id` stores + that binding with the first write. +- The same `device_id` may repeat unchanged or revise a value under D182. + It may not change the binding or replace hardware with a different id. +- A different, missing, null, or blank `device_id` refuses the whole page + or the whole file import before any mutation. A missing id does not clear + a binding and is not proof of the same device. Equal point values with a + different id are still a conflict. The second observation is not dropped + inside the call. The call is refused. +- A source that already has records and has no binding is unbound legacy. + Hardware, including disagreeing older hardware revisions, is not promoted + into a binding. The write is refused. Existing records, revisions, + sources, and hardware stay. A 2.1.0 open-wearables source cannot be + refreshed by this pull or by this mapped import until a separate + reconciliation exists. That block is this safety rule. It is not the + coverage choice in section 2. +- A new source whose rows have no `device_id` does not get a binding. The + result says device identity is unprovable. Timeseries rows with no id are + refused, because they share a key. Sleep and workout keys are not + redesigned. A later timeseries row then sees records and no binding and + is refused. +- A device at a different timestamp is the same rule. Its first conflicting + row refuses the call before hardware changes, so a later row cannot + overwrite an older point after the receipt has been rewritten. + +Preview keeps the binding it would have stored, in memory only, across +pages that were rolled back, so the next preview page can see the conflict. +That memory is not a second stored binding. `--json` and `--json --yes` +make no database changes. On `--yes`, an earlier committed page stays, the +failed page makes no database changes, the range is not complete, and the +exit is nonzero. File import rolls back the whole call. The queries in +D201 still ask for every device. A second device is refused rather than +merged. `zone_offset` is not copied into `start_at`. It remains in `supplied_fields` when the server sends it. The timestamp text is the server's `start_time`, @@ -387,8 +444,12 @@ interactive open can preview, back up, ask, and then migrate. `personal.rs` remains the Garmin pull. The two clients may each call `ureq`. A shared trait is the later connector work, and this release does not add it. -`mapping.rs` changes in one place. `apply_mapping` keeps its `outcome` field -and adds counts by record type. The pull sums only `sleep_session`, +`mapping.rs` changes in two places, both required by this proposal. +`apply_mapping` keeps its `outcome` field and adds counts by record type. +For route `open_wearables` only, it also runs the device-binding check in +section 3 before it mutates a source device or a timeseries record. That +check is the shared import and pull enforcement. It is not a new match key +and it does not apply to any other route. The pull sums only `sleep_session`, `workout_session`, `point_measurement`, `provider_summary`, and `provider_score`. A committed page adds those counts to the actual committed result. A rolled-back preview page adds them to `estimated`. It does not add @@ -400,10 +461,13 @@ The Rust command reads the key from the environment only. It has no `--key` flag. The decoded-key walk in section 4 runs before `apply_mapping`. The parent still checks stdout and stderr before printing. -The child returns the object from section 1. The parent prints it for -`--json`, and prints sentences for a person. `--json` still does not write. -The success sentence is parent text, and only after `--yes` when the range -is complete. +The child returns the preview outcome from section 1 when the mode is a +preview, including public `--json`. It returns the confirmed outcome when +the mode is `--yes` without `--json`. On a partial failure it returns that +confirmed outcome to the parent and then exits nonzero. The parent renders +text from the confirmed outcome and public JSON from the preview outcome. +The success sentence is parent text, and only after `--yes` when +`range_complete` is true. The program runs on Linux, macOS, and Windows with the same command. The fixture server listens on `127.0.0.1` and an ephemeral port, which is the @@ -438,7 +502,9 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: runs. The exit is nonzero. The success sentence is absent. The text gives the retained counts. The same command run again stores no second copy - the same failure sequence with no `--yes`, and again with `--json --yes`, - leaves zero rows, including from page 1 + makes no database changes. Rows that were already stored stay. A + successful `--json --yes` of a readable range is also a preview and makes + no database changes - a sleep-only mapping, installed where `.agents/mappings/` wins, produces no timeseries types. The server sees no `/timeseries` request. Counts for that read are zero and the read is `skipped`. A nonempty type list is @@ -450,15 +516,27 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: that send them. Sleep sends `include=stages`. Workouts send `include=zones`. Neither sends `include=segments`. A fixture with stages omitted has null intervals and still has stage totals. A fixture with `include=stages` keeps - the intervals under the server's names -- two distinct sensor triples become two sources. The same triple with two - `device_id` values on one page rejects that page and writes nothing from - it. The same collision on page 2, after page 1 committed a different key, - keeps page 1 and writes nothing from page 2 -- import the synthetic objects, then pull them, and pull them, then import - them. Both orders keep the same record ids, sources, match keys, and - revisions when both paths use the same checked mapping. A sample keeps - basis `provider_or_aggregator`. A provider score keeps basis `provider` + the intervals under the server's names. A fixture with `include=zones` + keeps the nested heart-rate and power zones under the server's names +- two distinct sensor triples become two sources. Device A is stored, then + a separate operation contains only device B at the same triple, type, and + instant, with a different value. The operation fails. The current point, + its revisions, the source, and hardware are unchanged, and the range is + not complete. The pairs are pull then pull, pull then pull in reverse, + file import then pull, and pull then file import. The same collision + inside one page, and split across two pages, refuses the failed page + instead of keeping one device and dropping the other. On `--yes`, an + earlier committed page stays. Preview and `--json --yes` make no database + changes. Equal values with different ids still fail. B at a different + timestamp fails before hardware changes, and a later B row does not + replace A's older point +- the same `device_id` with the same payload is unchanged. The same + `device_id` with a changed value revises that record and does not change + the binding. Import then pull, and pull then import, of that one device + keep one record id. A missing, null, or blank id does not replace a bound + source. A 2.1.0 source that already has records and has no binding is + refused, and its rows are not rewritten. A sample keeps basis + `provider_or_aggregator`. A provider score keeps basis `provider` - `page-sleep.json` becomes a sleep session. A manual workout is left out and its automatic neighbor is kept. `page-raw.json` is stored. `page-5min.json` is left out. RMSSD and SDNN stay different quantities @@ -514,7 +592,8 @@ store. They cover: `openwearables.saved` and `openwearables.environment` - a preview `--json` has `written: false`, committed zeros, `estimated` counts, and `range_complete: false` -- `--json --yes` after a later-page failure writes nothing, including page 1 +- `--json --yes` is a preview. After a later-page failure, and after a + readable range, the database is unchanged `pnpm check:public-data`, `pnpm typecheck`, `pnpm test`, and `pnpm build` pass, and `cargo test` passes, before the build is called done. @@ -545,11 +624,12 @@ the fixture key once into `ath key set openwearables`. The automated cases in section 7 are not extra card steps. -The build pull request's description carries a screenshot of each step and -one video that plays on the pull request page. The images are not committed. -The numbers on screen are the fixture's invented values. The release workflow -on Linux, macOS, and Windows is the cross-platform proof. The video is one -system. +The build's proof is one phone message in Grok Bot. That message contains a +screenshot of each step inline and one video that plays in the conversation. +A video that plays only on the pull request page is not that packet. The +images are not committed. The numbers on screen are the fixture's invented +values. The release workflow on Linux, macOS, and Windows is the +cross-platform proof. The video is one system. This plan pull request has no screenshots and no video. @@ -595,11 +675,10 @@ Risks: - Date-only bounds mean whatever Open Wearables decides. The docs and the 0.11.0 parser disagree about UTC. This release does not correct that server. - The table in section 2 is incomplete coverage, chosen on purpose and - still not adopted. It is separate from the same-model `device_id` - collision, which is conditional loss and rejects the ambiguous page. - Suggesting 2.5.0 does not approve either one. Workout average and maximum - heart rate can still be stored. Raw heart-rate variability can still arrive - when the mapping names it. + still not adopted. It is not the device-binding rule. Suggesting 2.5.0 + does not approve the coverage gap. Workout average and maximum heart rate + can still be stored. Raw heart-rate variability can still arrive when the + mapping names it and the device binding allows the write. - Fields on a sleep or workout object that the mapping does not consume are stored under the server's names. The shipped mapping does not request latitude or longitude. A replaced mapping file can name more series, and @@ -610,9 +689,10 @@ Risks: The maintainer approves or rejects this plan before any build. D198 through D202 are the proposal. They are not adopted. Reviews of commit `d1fdde1` -were incorporated here. Those reviews are not approval of this revision. -The next head needs their re-review. A product review accepted a migration -with no new column, under D152 and D184. That acceptance does not adopt D198. +were incorporated here, and the re-reviews of `1124e56` are incorporated +here. None of those reviews approves this revision. The next head needs +their re-review. A product review accepted a migration with no new column, +under D152 and D184. That acceptance does not adopt D198. 1. One number, 2.2.0. Readable sets keep `1.0.0`. Step 5 runs on create and on migrate. No new column. A `2.1.0` database does not open until @@ -633,7 +713,10 @@ with no new column, under D152 and D184. That acceptance does not adopt D198. write. `--yes` commits each successful page under D189, and a committed page is not a completed pull. The text of `--yes` shows retained counts and whether the requested range is complete. A missing row is not deleted. - An empty type list skips timeseries. Same-model `device_id` collisions - reject the ambiguous page and do not change the match key (D201). -5. The Windows cleanup and the maintainability notes stay separate. The count - by record type is the only `mapping.rs` change (D202). + An empty type list skips timeseries. The same sensor triple keeps one + source. A second `device_id` does not replace or suppress the first, in + a later command or in a mapped file import. Unbound legacy data is + refused and left in place (D201). +5. The Windows cleanup and the maintainability notes stay separate. + `mapping.rs` gains counts by record type and the open-wearables binding + check. It gains nothing else (D202). From c9ca93afffa22e5fc2fd5674cc1756eca11d5484 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 7 Nov 2026 00:11:47 +0000 Subject: [PATCH 04/60] Name who may write the Open Wearables device receipt. Keep the receipt on the source record, ignore a 2.1.0 supplied field of the same name, and say which owner operations store a whole source. Co-authored-by: Michael Whitham --- build-history/v2.2.0/decisions.md | 35 ++++- build-history/v2.2.0/progress.md | 2 +- build-history/v2.2.0/spec.md | 216 ++++++++++++++++++++++-------- 3 files changed, 186 insertions(+), 67 deletions(-) diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index bd6acce6..aee2ab33 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -47,7 +47,10 @@ not adopted. for this server. File imports stay: Apple Health, WHOOP, Oura, Garmin, and Strava. `ath pull -garmin` stays as it is. `ath import --mapping` stays as it is. +garmin` stays as it is. Mapped import for every route other than +`open_wearables` stays as it is. Open Wearables mapped import gains the +shared binding refusal in the specification. It no longer accepts a second +device id, or a refresh of history that has no established binding. Evidence: [appendix/open-wearables-api.md](appendix/open-wearables-api.md). @@ -126,7 +129,7 @@ follows D182. This proposal does not keep a command-wide preview overlay. The proposed read order is sleep, then workouts, then raw timeseries. That order is part of what the maintainer approves. A failure in a later read leaves the earlier read's pages committed and the reads after the failure -unattempted. The result says so. See D201. +`not_attempted`. The result says so. See D201. The coverage table in the specification is the proposed scope. Day aggregates, sleep-linked physiology, recovery summaries, health scores, @@ -181,6 +184,16 @@ Rejected alternatives: Rejected. Import after pull would still replace the point, and hardware is one mutable column. The point's revisions do not contain `device_id` today, because that path is removed as hardware. +- Put the receipt in `supplied_fields`, under `device_binding` or another + name. Rejected. D185 keeps that object for names the source sent. A 2.1.0 + source may already hold an arbitrary value at that name, and step 5 must + not turn that value into authority. The receipt is the source object's own + key `device_binding`. +- Treat a nonempty string at the new key as proof no matter who wrote it, + or require a signature so the owner cannot change it. Rejected. The + automatic path writes the key only by the checked rule. `ath correct`, + package restore, and an accepted package merge store the whole source the + owner supplied. A hand-edited database file is outside this proposal. ## D200. The key, the server, and the user id stay out of the record @@ -284,8 +297,12 @@ and in the text. `skipped` is the timeseries read when the mapping named no types. `range_complete` is true only on a `--yes` write whose reads finished without a failed page. The success sentence is printed only then. A retained count with an incomplete range is a partial pull. The message names the -failed read, names any `not_attempted` read, gives the retained counts, and -says to run the same command again. A preview that fails makes no database +failed read, names any `not_attempted` read, and gives the retained counts. +A failed read says to run the same command again. An identity refusal uses +the sentence in the specification's section 3: a replacement id is blocked +even at a new time, a 2.1.0 Open Wearables history cannot be refreshed until +reconciliation, and +a rerun cannot repair either one. A preview that fails makes no database changes, including for pages that had already been counted. Before `apply_mapping`, the page must be a JSON object, `data` must be an @@ -302,7 +319,7 @@ runs the failed read again, and runs any read that was `not_attempted`. `has_more: false` is the only successful end of a read. A repeated cursor, a null cursor while `has_more` is true, the 1000-page cap, and a body over 8 MiB fail that read. The failed page is not written. Later reads are -`unattempted`. The success line is not printed. A cursor with the `prev_` +`not_attempted`. The success line is not printed. A cursor with the `prev_` prefix is not sent. `limit` is 1000. One attempt is made per request. There is no retry. The connect timeout is 10 seconds and the read timeout is 30 seconds. @@ -377,8 +394,12 @@ open. They do not run on a pull. This build does not change them. for HTTP. `mapping.rs` may add the count by record type that D199 names, and the open-wearables device-binding check in the specification. That check is shared by mapped import and pull, and it is limited to route -`open_wearables`. Nothing else is added to `mapping.rs`. Splitting the -files is separate work. It is not required to make the pull correct. +`open_wearables`. Nothing else is added to `mapping.rs`. `store.rs` may +preserve `device_binding` inside `revise` when the record is a source, and +refuse a partial patch that contains that key. Nothing else is added to +`store.rs`. `ath correct`, package restore, and an accepted package merge +remain the owner's whole source record. Splitting the files is separate +work. It is not required to make the pull correct. `check_supplied_fields` runs in `store.rs` before insert and revise (D191). `persist.rs` `insert_record` writes `data_json` and does not call that check. diff --git a/build-history/v2.2.0/progress.md b/build-history/v2.2.0/progress.md index 1a4a6dab..27b531d2 100644 --- a/build-history/v2.2.0/progress.md +++ b/build-history/v2.2.0/progress.md @@ -5,7 +5,7 @@ program, the record, or the database has changed for 2.2.0. | Step | What | Status | |---|---|---| -| 0 | The plan: proposals D198–D202, and the Open Wearables study. Revised after the re-reviews of `1124e56`. Still not adopted. The new head needs re-review | written, not approved | +| 0 | The plan: proposals D198–D202, and the Open Wearables study. Revised after the four re-reviews of `da006a6`. Still not adopted. The new head needs re-review | written, not approved | | 1 | Version 2.2.0, migration step 5, no new column (D198) | not started | | 2 | `ath pull openwearables` in `ath-core`, using the shipped mapping (D199, D201) | not started | | 3 | Key, server, and user id kept out of the record (D200) | not started | diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index 58cf2edd..b39d06fa 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -90,9 +90,10 @@ then does it print `pulled openwearables from through `. If a later page fails, the child returns a typed outcome to the parent before the process exits nonzero. The parent renders that outcome as text, then uses the exit status. The text says the requested range is incomplete, -names the failed read, names any read that is `not_attempted`, prints the -retained counts, and says to run the same command again. It does not print -the success sentence. The failed page makes no database changes. Records +names the failed read, names any read that is `not_attempted`, and prints +the retained counts. A failed read says to run the same command again. An +identity refusal uses the sentence in section 3, which says a rerun cannot +repair the device id. It does not print the success sentence. The failed page makes no database changes. Records already stored stay, including their revisions. An empty range whose reads finished says the range is complete. `written` is false when the confirmed command changed nothing. The database is unchanged. That is not a claim that @@ -296,46 +297,102 @@ lives there, for route `open_wearables` only, inside the same transaction as the write and before `insert_group` changes a source device or a timeseries record. Other routes are not checked. A pull-only check would leave import-after-pull able to replace the point. The check reads every -incoming row, not only the first. - -The binding is `source.supplied_fields.device_binding`, one nonempty -string. `SourceData` already allows `supplied_fields`, so step 5 adds no -column and does not copy hardware into this field. The binding is written -once, with the first accepted write, and is never replaced by another id. - -- A new source whose accepted rows share one nonempty `device_id` stores - that binding with the first write. -- The same `device_id` may repeat unchanged or revise a value under D182. - It may not change the binding or replace hardware with a different id. -- A different, missing, null, or blank `device_id` refuses the whole page - or the whole file import before any mutation. A missing id does not clear - a binding and is not proof of the same device. Equal point values with a - different id are still a conflict. The second observation is not dropped - inside the call. The call is refused. -- A source that already has records and has no binding is unbound legacy. - Hardware, including disagreeing older hardware revisions, is not promoted - into a binding. The write is refused. Existing records, revisions, - sources, and hardware stay. A 2.1.0 open-wearables source cannot be - refreshed by this pull or by this mapped import until a separate - reconciliation exists. That block is this safety rule. It is not the - coverage choice in section 2. -- A new source whose rows have no `device_id` does not get a binding. The - result says device identity is unprovable. Timeseries rows with no id are - refused, because they share a key. Sleep and workout keys are not - redesigned. A later timeseries row then sees records and no binding and - is refused. -- A device at a different timestamp is the same rule. Its first conflicting - row refuses the call before hardware changes, so a later row cannot - overwrite an older point after the receipt has been rewritten. - -Preview keeps the binding it would have stored, in memory only, across -pages that were rolled back, so the next preview page can see the conflict. -That memory is not a second stored binding. `--json` and `--json --yes` -make no database changes. On `--yes`, an earlier committed page stays, the -failed page makes no database changes, the range is not complete, and the -exit is nonzero. File import rolls back the whole call. The queries in -D201 still ask for every device. A second device is refused rather than -merged. +accepted row, including a row after the first source device. + +The receipt is the source object's own key `device_binding`. The 2.2.0 +source schema makes it an optional nonempty string. D185 keeps +`supplied_fields` for names the source sent, so the receipt is a sibling of +that object, as `field_basis` is a sibling on a measured record. Step 5 +adds no column, copies no field, and rewrites no record. A source migrated +from 2.1.0 has no `device_binding` key. A string already stored at +`supplied_fields.device_binding` stays in `supplied_fields`. Migration does +not treat it as the receipt. Renaming that supplied name would still leave +an old free-form value able to authorize a write, so this proposal does not +do that. + +An established binding is that source key holding a nonempty string. The +automatic path reads only that key. The same name anywhere in a raw payload, +a mapped file, or nested `supplied_fields` is source data. The mapping may +keep it on the measured record. It is not copied onto the source, and it +cannot replace or erase the source key. + +The value the automatic path compares is the row's `source.device_id`. The +mapping `name` does not choose it. The shipped file points `device_hardware` +at `source.device_id`. A resolved mapping that points `device_hardware` +somewhere else fails before any write, because that file cannot satisfy this +contract. The source already stored stays unchanged. + +The check runs on accepted rows. A row the mapping has already classified +as `left_out` does not establish a binding and does not supply the id. The +call is one of these states: + +- The source is deleted. D190 leaves its rows out. The call does not revive + the source and does not set a binding. +- The source has an established binding, and the incoming id equals it. The + row may repeat unchanged or correct the stored value under D182. The + binding stays. Hardware is not replaced with a different id. Other fields + already on the source stay. +- The source has an established binding, and the incoming id is different, + missing, null, or blank. The call is refused before any mutation. Equal + point values with a different id are still refused. A new timestamp does + not make the new id acceptable. The text says the replacement device is + blocked, including when the sample time is new, and that running the + command again cannot change the id. +- The source exists, the source key is absent, and any history exists. + History includes a deleted record and a deleted source device, not only + live rows. `same_source_records` is not this test, because it keeps + `is_deleted = 0`. The call is refused. Hardware is not promoted. The text + says this Open Wearables history cannot be refreshed until a separate + reconciliation exists, and that running the command again cannot create + the binding. This is the block for 2.1.0 history. It is not the coverage + choice in section 2. +- The source key is present and is not a nonempty string. The call is + refused. The stored value is left as it is. The text says this command + cannot use that binding, and a rerun cannot repair it. +- The source is new for this call, or it already exists with the source key + absent and with no history. Accepted rows that are only sleep and + workouts, and that all lack an id, are stored. The source has no + `device_binding`. The result says the device id is unknown. An accepted + timeseries row with no id is refused. Accepted rows that mix a nonempty + id with a missing id are refused. Accepted rows that share one nonempty + `source.device_id` store that string on the new source in the same + transaction as the first accepted write. A call that accepts no rows + creates no binding. A source created inside a refused call is rolled + back with the call. + +A second device is refused rather than merged. On `--yes`, an earlier +committed page stays, the failed page makes no database changes, the range +is not complete, and the exit is nonzero. File import rolls back the whole +call. `--json` and `--json --yes` make no database changes. The queries in +D201 still ask for every device. + +Preview keeps two facts in memory for this command: the binding it would +have stored, and an unbound source it would have created once that source +has accepted history. A later preview page uses those facts, including a +later page that adds an id after an id-less sleep page. The memory is +discarded with the process. It does not change the estimated record counts. +A second command reads the committed source inside its own `BEGIN IMMEDIATE` +transaction. + +Three owner operations store a whole source record and do not run this +device-id guard. `ath correct` stores the source `data` the person +supplied, after the schema check. Native package restore copies the +package's records. A package merge the person accepts for a changed source +stores that source record. A 2.2.0 record keeps `device_binding` when the +record has it. A 2.1.0 record does not gain the key, and a supplied field +of the same name stays a supplied field. The next mapped pull or mapped +import then uses the source key that those operations left behind. A 2.2.0 +export and restore keeps the key and the import keys, so the same id can +correct a point and a different id is refused. No signature is added. A +person who replaces the database file is outside this rule. + +`Store::revise` on a source is a partial update. It applies the other keys +in the patch and keeps the current `device_binding`, including when the key +is absent. A patch that contains `device_binding` is refused, and the +source stays unchanged. This is the one `store.rs` change. Other record +types are unchanged. The automatic path sets the key only on the source +object `ensure_mapped_source` already builds. It does not replace +`detail`, `vendor`, or `supplied_fields`. `zone_offset` is not copied into `start_at`. It remains in `supplied_fields` when the server sends it. The timestamp text is the server's `start_time`, @@ -409,8 +466,9 @@ would make a 1.0.0 database unloadable, so migrate could not open it. `2.1.0` database will not open in `ath-core` until that migrate. The build generates `schema/2.2.0/` and does not rewrite `schema/2.1.0/` or -`schema/2.0.0/`. The JSON schema gains no field. The folder exists so the -package version and the schema path stay aligned. The demo athlete is +`schema/2.0.0/`. The 2.2.0 source object gains optional `device_binding`. +No other field is added. The folder exists so the package version and the +schema path stay aligned. The demo athlete is regenerated because the stored version is inside it. `examples/demo-athlete/athlete.ath.json` stays the legacy 0.4.3 file. `tests/fixtures/version-2-0-0/` is not regenerated. @@ -439,6 +497,8 @@ interactive open can preview, back up, ask, and then migrate. | Flags, key, preview text, refusal if the key appears | `src/program.ts`, `src/help.ts`, `src/keyring.ts` | | Mapping names and field rules | the existing file `mappings/open-wearables.md` | | Stored records | the existing store and mapping engine | +| Keep `device_binding` on a partial source update | `Store::revise` in `crates/ath-core/src/store.rs`, sources only | +| Whole source record from the owner | existing `ath correct`, package restore, and an accepted package merge | `store.rs`, `persist.rs`, and `personal.rs` are not the home for this client. `personal.rs` remains the Garmin pull. The two clients may each call `ureq`. @@ -448,8 +508,12 @@ A shared trait is the later connector work, and this release does not add it. `apply_mapping` keeps its `outcome` field and adds counts by record type. For route `open_wearables` only, it also runs the device-binding check in section 3 before it mutates a source device or a timeseries record. That -check is the shared import and pull enforcement. It is not a new match key -and it does not apply to any other route. The pull sums only `sleep_session`, +check is the shared mapped-import and pull enforcement. It is not a new +match key and it does not apply to any other route. `store.rs` changes +`revise` for a source record only, so a partial update keeps +`device_binding`. `ath correct`, package restore, and an accepted package +merge stay whole-record owner writes. They are named in section 3 so the +binding survives a 2.2.0 round trip. They are not a new importer. The pull sums only `sleep_session`, `workout_session`, `point_measurement`, `provider_summary`, and `provider_score`. A committed page adds those counts to the actual committed result. A rolled-back preview page adds them to `estimated`. It does not add @@ -533,10 +597,38 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: - the same `device_id` with the same payload is unchanged. The same `device_id` with a changed value revises that record and does not change the binding. Import then pull, and pull then import, of that one device - keep one record id. A missing, null, or blank id does not replace a bound - source. A 2.1.0 source that already has records and has no binding is - refused, and its rows are not rewritten. A sample keeps basis + keep one record id. Mapped file import of device A, then a second mapped + file import of only device B, fails the same way. A missing, null, or + blank id does not replace a bound source. A 2.1.0 source that already has + history and has no source key `device_binding` is refused, including when + the only history is a deleted record or a deleted source device, and + including when `supplied_fields.device_binding` is already the string for + device B. The same misleading field in a 2.1.0 package is still a supplied + field after import. Device B does not replace A's point. The supplied + field and the hardware stay. No source key is added. A sample keeps basis `provider_or_aggregator`. A provider score keeps basis `provider` +- a raw page and a mapped file that carry `device_binding` on the row, on a + nested source object, and inside `supplied_fields` do not set, replace, or + erase the source key. A mapping whose `name` changes and whose + `device_hardware` stays `source.device_id` keeps the same binding. A + mapping whose `device_hardware` points elsewhere is refused before any + write +- a new source of only id-less sleep is stored with no source key. A later + timeseries row with an id is refused, and the sleep row stays. One call + that accepts both an id and a missing id is refused. A `left_out` row does + not create a binding. The first preview page is id-less sleep and the + second preview page has an id for that same source: the preview refuses + and writes nothing +- a partial source update changes `detail` and leaves `device_binding` + unchanged. A partial update that includes `device_binding` changes + nothing. `ath correct` with a complete source object replaces that object. + After that correction, a mapped write follows the source key the + correction stored +- export a 2.2.0 database that has an established binding, import that + package, and the source key and the import keys are still there. The same + id can correct the point. A different id is refused, with no new point + revision, source revision, or hardware revision. A stored source key that + is not a nonempty string refuses the automatic write and is left unchanged - `page-sleep.json` becomes a sleep session. A manual workout is left out and its automatic neighbor is kept. `page-raw.json` is stored. `page-5min.json` is left out. RMSSD and SDNN stay different quantities @@ -644,8 +736,9 @@ is in the build pull request. `EBUSY`. Version 2.1.0 spec section 12 left it out and named no later version. - `store.rs` and `mapping.rs` are past a thousand lines. The pull does not - add HTTP to them. The only `mapping.rs` change is the count by record type - in section 6. Splitting the files stays out. + add HTTP to them. `mapping.rs` gains the counts by record type and the + shared open-wearables binding check in section 6. `store.rs` gains the + source-only preserve in section 3. Splitting the files stays out. - `persist.rs` can still store a supplied field named `__proto__` if a caller uses `ath-core persist` directly. The pull does not use that path. - The mapping path rule is already one function. There is no duplicate to @@ -689,10 +782,11 @@ Risks: The maintainer approves or rejects this plan before any build. D198 through D202 are the proposal. They are not adopted. Reviews of commit `d1fdde1` -were incorporated here, and the re-reviews of `1124e56` are incorporated -here. None of those reviews approves this revision. The next head needs -their re-review. A product review accepted a migration with no new column, -under D152 and D184. That acceptance does not adopt D198. +were incorporated here. The re-reviews of `1124e56` and of `da006a6` are +incorporated here. None of those reviews approves this revision. The next +head needs their re-review. A product review accepted a migration with no +new column, under D152 and D184. That acceptance does not adopt D198. The +optional source key adds no column. 1. One number, 2.2.0. Readable sets keep `1.0.0`. Step 5 runs on create and on migrate. No new column. A `2.1.0` database does not open until @@ -715,8 +809,12 @@ under D152 and D184. That acceptance does not adopt D198. and whether the requested range is complete. A missing row is not deleted. An empty type list skips timeseries. The same sensor triple keeps one source. A second `device_id` does not replace or suppress the first, in - a later command or in a mapped file import. Unbound legacy data is - refused and left in place (D201). + a later command or in a mapped file import, including import then import. + The receipt is the source key `device_binding`. A 2.1.0 supplied field of + that name does not become the receipt. Unbound history is refused and + left in place. `ath correct` and a native 2.2.0 package restore are the + owner's whole source record (D201). 5. The Windows cleanup and the maintainability notes stay separate. `mapping.rs` gains counts by record type and the open-wearables binding - check. It gains nothing else (D202). + check. `store.rs` gains the source-only preserve. Nothing else is added + to either file (D202). From 354a8bbffcd2ebe6ad7322b9bdb76b25e0b7e30d Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 7 Nov 2026 00:18:30 +0000 Subject: [PATCH 05/60] Let the store write the first device receipt. The mapping cannot see deleted history or set the receipt through an ordinary source update, so the plan allows three store operations inside the caller's transaction. Co-authored-by: Michael Whitham --- build-history/v2.2.0/decisions.md | 17 +++++-- build-history/v2.2.0/progress.md | 2 +- build-history/v2.2.0/spec.md | 83 +++++++++++++++++++++++-------- 3 files changed, 75 insertions(+), 27 deletions(-) diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index aee2ab33..46635e14 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -396,10 +396,19 @@ open-wearables device-binding check in the specification. That check is shared by mapped import and pull, and it is limited to route `open_wearables`. Nothing else is added to `mapping.rs`. `store.rs` may preserve `device_binding` inside `revise` when the record is a source, and -refuse a partial patch that contains that key. Nothing else is added to -`store.rs`. `ath correct`, package restore, and an accepted package merge -remain the owner's whole source record. Splitting the files is separate -work. It is not required to make the pull correct. +refuse a partial patch that contains that key. `revise` cannot set, change, +or clear the receipt. The connection is private, `ensure_mapped_source` +has no receipt argument, and `same_source_records` omits deleted rows, so +`store.rs` may also read the receipt and tombstone-inclusive history, +create a source with the checked receipt, and write that receipt on an +existing unbound source only when the same transaction shows no accepted +or deleted record and no source device. Those writes keep every other +source field and the normal revision and `data_json` bookkeeping. They +join the caller's `BEGIN IMMEDIATE` transaction. Nothing else is added to +`store.rs`. Other routes do not call them. `ath correct`, package restore, +and an accepted package merge remain the owner's whole source record. +Splitting the files is separate work. It is not required to make the pull +correct. `check_supplied_fields` runs in `store.rs` before insert and revise (D191). `persist.rs` `insert_record` writes `data_json` and does not call that check. diff --git a/build-history/v2.2.0/progress.md b/build-history/v2.2.0/progress.md index 27b531d2..f8196016 100644 --- a/build-history/v2.2.0/progress.md +++ b/build-history/v2.2.0/progress.md @@ -5,7 +5,7 @@ program, the record, or the database has changed for 2.2.0. | Step | What | Status | |---|---|---| -| 0 | The plan: proposals D198–D202, and the Open Wearables study. Revised after the four re-reviews of `da006a6`. Still not adopted. The new head needs re-review | written, not approved | +| 0 | The plan: proposals D198–D202, and the Open Wearables study. Revised after the four reviews of `c9ca93a`. Still not adopted. The new head needs re-review | written, not approved | | 1 | Version 2.2.0, migration step 5, no new column (D198) | not started | | 2 | `ath pull openwearables` in `ath-core`, using the shipped mapping (D199, D201) | not started | | 3 | Key, server, and user id kept out of the record (D200) | not started | diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index b39d06fa..46f960da 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -340,8 +340,9 @@ call is one of these states: command again cannot change the id. - The source exists, the source key is absent, and any history exists. History includes a deleted record and a deleted source device, not only - live rows. `same_source_records` is not this test, because it keeps - `is_deleted = 0`. The call is refused. Hardware is not promoted. The text + live rows. `same_source_records` keeps `is_deleted = 0`, so it is not + this test. The store read below includes the deleted rows. The call is + refused. Hardware is not promoted. The text says this Open Wearables history cannot be refreshed until a separate reconciliation exists, and that running the command again cannot create the binding. This is the block for 2.1.0 history. It is not the coverage @@ -355,10 +356,11 @@ call is one of these states: `device_binding`. The result says the device id is unknown. An accepted timeseries row with no id is refused. Accepted rows that mix a nonempty id with a missing id are refused. Accepted rows that share one nonempty - `source.device_id` store that string on the new source in the same - transaction as the first accepted write. A call that accepts no rows - creates no binding. A source created inside a refused call is rolled - back with the call. + `source.device_id` store that string on the source in the same + transaction as the first accepted write. That source may be created in + this call, or it may already exist with no receipt and no history. A call + that accepts no rows creates no binding. A source created or first-bound + inside a refused call is rolled back with the call. A second device is refused rather than merged. On `--yes`, an earlier committed page stays, the failed page makes no database changes, the range @@ -388,11 +390,36 @@ person who replaces the database file is outside this rule. `Store::revise` on a source is a partial update. It applies the other keys in the patch and keeps the current `device_binding`, including when the key -is absent. A patch that contains `device_binding` is refused, and the -source stays unchanged. This is the one `store.rs` change. Other record -types are unchanged. The automatic path sets the key only on the source -object `ensure_mapped_source` already builds. It does not replace -`detail`, `vendor`, or `supplied_fields`. +is absent. A patch that contains `device_binding` is refused. The source +stays unchanged. `revise` cannot set, change, or clear the receipt. Other +record types are unchanged. + +The store connection is private. `ensure_mapped_source` takes the writer, +the route, the vendor, and the sensor. An existing source returns before a +data object is built. A new source's JSON is built inside that function, +and that JSON has no receipt argument today. The mapping receives a source +id. It cannot add the receipt to an object it does not hold, and it cannot +read deleted rows through `same_source_records` or through the private +connection. A later `revise` cannot fill the receipt in, because that patch +is refused. + +`store.rs` therefore gains three source operations besides the `revise` +rule above. It gains nothing else: + +- Read the committed receipt, and whether any record or source device for + that source exists, including a deleted row. +- Create a source with the checked receipt already in its JSON. +- Write the checked receipt on an existing source only when the receipt is + absent and that same read shows no accepted or deleted record and no + source device. Every other source field stays. The write uses the normal + revision and `data_json` bookkeeping. Writer, route, sensor, import keys, + and baselines stay. + +The three operations run inside the caller's `BEGIN IMMEDIATE` transaction. +A refused call rolls them back with the call. Other routes do not call +them. The build may extend `ensure_mapped_source` or add a narrow operation +beside it. It does not add a table, a trait, or a file split. The automatic +path does not replace `detail`, `vendor`, or `supplied_fields`. `zone_offset` is not copied into `start_at`. It remains in `supplied_fields` when the server sends it. The timestamp text is the server's `start_time`, @@ -498,6 +525,7 @@ interactive open can preview, back up, ask, and then migrate. | Mapping names and field rules | the existing file `mappings/open-wearables.md` | | Stored records | the existing store and mapping engine | | Keep `device_binding` on a partial source update | `Store::revise` in `crates/ath-core/src/store.rs`, sources only | +| Read receipt and tombstone history; create or first-bind with the checked receipt | three source operations in `store.rs`, inside the caller's transaction | | Whole source record from the owner | existing `ath correct`, package restore, and an accepted package merge | `store.rs`, `persist.rs`, and `personal.rs` are not the home for this client. @@ -509,11 +537,13 @@ A shared trait is the later connector work, and this release does not add it. For route `open_wearables` only, it also runs the device-binding check in section 3 before it mutates a source device or a timeseries record. That check is the shared mapped-import and pull enforcement. It is not a new -match key and it does not apply to any other route. `store.rs` changes -`revise` for a source record only, so a partial update keeps -`device_binding`. `ath correct`, package restore, and an accepted package -merge stay whole-record owner writes. They are named in section 3 so the -binding survives a 2.2.0 round trip. They are not a new importer. The pull sums only `sleep_session`, +match key and it does not apply to any other route. `store.rs` keeps the +`revise` refusal and adds the three source operations in section 3: the +receipt and tombstone read, creation with the checked receipt, and a +first bind on an existing source that has no history. `ath correct`, +package restore, and an accepted package merge stay whole-record owner +writes. They are named in section 3 so the binding survives a 2.2.0 round +trip. They are not a new importer. The pull sums only `sleep_session`, `workout_session`, `point_measurement`, `provider_summary`, and `provider_score`. A committed page adds those counts to the actual committed result. A rolled-back preview page adds them to `estimated`. It does not add @@ -613,6 +643,12 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: `device_hardware` stays `source.device_id` keeps the same binding. A mapping whose `device_hardware` points elsewhere is refused before any write +- an existing open-wearables source has no receipt, no record, and no + source device. The first accepted write stores the checked receipt on + that source. Its other fields, its writer, its route, its sensor, and + its baselines stay. The revision and `data_json` record that receipt. A + source whose only history is a deleted record or a deleted source device + is still refused, and that refusal writes no receipt - a new source of only id-less sleep is stored with no source key. A later timeseries row with an id is refused, and the sleep row stays. One call that accepts both an id and a missing id is refused. A `left_out` row does @@ -738,7 +774,8 @@ is in the build pull request. - `store.rs` and `mapping.rs` are past a thousand lines. The pull does not add HTTP to them. `mapping.rs` gains the counts by record type and the shared open-wearables binding check in section 6. `store.rs` gains the - source-only preserve in section 3. Splitting the files stays out. + partial-update refusal and the three source operations in section 3. + Splitting the files stays out. - `persist.rs` can still store a supplied field named `__proto__` if a caller uses `ath-core persist` directly. The pull does not use that path. - The mapping path rule is already one function. There is no duplicate to @@ -782,9 +819,9 @@ Risks: The maintainer approves or rejects this plan before any build. D198 through D202 are the proposal. They are not adopted. Reviews of commit `d1fdde1` -were incorporated here. The re-reviews of `1124e56` and of `da006a6` are -incorporated here. None of those reviews approves this revision. The next -head needs their re-review. A product review accepted a migration with no +were incorporated here. The re-reviews of `1124e56`, `da006a6`, and +`c9ca93a` are incorporated here. None of those reviews approves this +revision. The next head needs their re-review. A product review accepted a migration with no new column, under D152 and D184. That acceptance does not adopt D198. The optional source key adds no column. @@ -816,5 +853,7 @@ optional source key adds no column. owner's whole source record (D201). 5. The Windows cleanup and the maintainability notes stay separate. `mapping.rs` gains counts by record type and the open-wearables binding - check. `store.rs` gains the source-only preserve. Nothing else is added - to either file (D202). + check. `store.rs` gains the partial-update refusal, the receipt and + tombstone read, creation with the checked receipt, and the first bind + of an existing source that has no history. Nothing else is added to + either file (D202). From 21aa30adb9a9df6eb9dfeea5388b4d4cc7518df5 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 7 Nov 2026 02:46:05 +0000 Subject: [PATCH 06/60] Keep stored Open Wearables measurements in the 2.2.0 plan. D203 stores day windows, series, summaries, and workout segments in this pull, and names the routes that stay out. Co-authored-by: Michael Whitham --- .../v2.2.0/appendix/open-wearables-api.md | 61 ++- build-history/v2.2.0/decisions.md | 216 ++++++---- build-history/v2.2.0/progress.md | 6 +- build-history/v2.2.0/spec.md | 392 +++++++++++------- 4 files changed, 437 insertions(+), 238 deletions(-) diff --git a/build-history/v2.2.0/appendix/open-wearables-api.md b/build-history/v2.2.0/appendix/open-wearables-api.md index d32abc87..94eaf69e 100644 --- a/build-history/v2.2.0/appendix/open-wearables-api.md +++ b/build-history/v2.2.0/appendix/open-wearables-api.md @@ -45,10 +45,11 @@ introduction, that stores data for people who do not run the server. Open Wearables is not Junction. Junction remains the other shipped mapping file, and this plan does not call it. -## The read this plan uses +## The reads this plan uses -All three reads are under `/api/v1` and take a user id in the path. The user -id is an Open Wearables UUID. Dates are required. +D203 names every read. The paths below are the ones this study opened +first. Each is under `/api/v1` and takes a user id in the path. The user +id is an Open Wearables UUID. Dates are required on the paged reads. | Read | Path on `0.11.0` | Page shape | |---|---|---| @@ -125,11 +126,11 @@ Timeseries, from `TimeSeriesSample`: `timestamp`, `zone_offset`, `type`, capture a live JSON body, so it does not claim the wire format beyond that schema. `zone_offset` is a separate string, `+01:00` or `-05:30`, or null. -The shipped mapping file's timeseries lines do not name `heart_rate`. In +The 2.1.0 mapping file's timeseries lines do not name `heart_rate`. In Athletic Standard, `heart_rate` is a series quantity (`SERIES_QUANTITY_UNITS` in `src/v1/schema.ts`). It is not one of the point -quantities the mapping engine writes. A raw heart-rate stream therefore has -nowhere to go in the current mapping. +quantities the 2.1.0 mapping engine writes. D203 stores that stream as +measurement samples. The 2.1.0 file, by itself, still has nowhere to put it. ## Time bounds @@ -193,6 +194,54 @@ and `avg_hrv_sdnn_ms` as separate fields. No rate-limit field was in the API introduction or in the three `0.11.0` route files. A limit may still exist in middleware this study did not open. +## Coverage audit on 7 November 2026 + +The same commit, `183e8cc4f6de897dbd288c93d49a691f2cf721ae`, was read again +for every user data route. The OpenAPI file is `docs/openapi.json`, +`info.version` `0.11.0`. The storage rule is D203. This section records +what the source shows. + +`SeriesType` is the enum in `backend/app/schemas/enums/series_types.py`. +Each entry in `SERIES_TYPE_DEFINITIONS` is an id, a name, and a unit. +`heart_rate` is `bpm`. `latitude` and `longitude` are `degrees`. The raw +path in `timeseries_service.py` copies `recorded_at`, `zone_offset`, the +type, the value, and `window_seconds`. It does not set `period_end` or +`computed_by`. + +`_aggregated_timeseries` handles `1min`, `5min`, `15min`, and `1hour`. It +sets `window_seconds` from `BUCKET_SIZES` and does not set `period_end`. +Those rows are buckets of raw samples, built when the query runs. + +`_period_timeseries` handles `1day`, `1week`, and `1month`. The timestamp +is `CalendarPeriod.of_date(period, zone_offset).start`. `period_end` is +the start of the next period. For a day, `computed_by` is the stored row's +value. For a week or a month, the code sets `computed_by` to +`open_wearables`. The comment says weeks start on Monday and months on +the first, from the local day. One response row is one period, one +source, and one series type. `stats` is the combined object. + +`SleepSession` has no resting heart rate, heart-rate variability, blood +oxygen, respiration, or temperature. `SleepSummary` has +`avg_heart_rate_bpm`, `avg_hrv_sdnn_ms`, `avg_hrv_rmssd_ms`, +`avg_respiratory_rate`, and `avg_spo2_percent`, plus a `date` and optional +`start_time` and `end_time`. `RecoverySummary` has `resting_heart_rate_bpm`, +`avg_hrv_rmssd_ms`, `avg_hrv_sdnn_ms`, `avg_spo2_percent`, and +`recovery_score`. It has no temperature field. The SDNN field text says +the value is null for current rows because they come from WHOOP and +WHOOP's HRV there is RMSSD. `recovery_score` is deprecated in that class +and documented as 0 to 100. `BodyLatest` has `skin_temperature_celsius` +and `skin_temperature_measured_at`. `BodyAveraged` has `period_start`, +`period_end`, and separate RMSSD and SDNN fields. + +Workout `segments` is an array of objects. `event_record_service.py` +fills it only when `include=segments`. Zones are filled only when +`include=zones`. The provider workout routes describe a live call to +Suunto, Polar, or Garmin. They are not the stored workout object. + +Sleep totals, workout totals, and activity totals describe sums of the +listed rows. The personal-record response fields are `birth_date`, +`gender`, and `sex`. + ## What was not checked - A running server's JSON, including the exact `start_time` text. diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index 46635e14..e3634ef0 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -9,14 +9,15 @@ D-number. ## D198. Version 2.2.0 is one manual pull, and the program and the record share that number -`ath pull openwearables` reads sleep, workouts, and raw samples from an Open -Wearables server the person runs, for one user and one range they name. The -command is manual. The person runs it. The program does not schedule it, retry -it, or sign the person in to a device maker. +`ath pull openwearables` reads the stored measurements D203 lists from an +Open Wearables server the person runs, for one user and one range they name. The +command is manual. The person runs it. The program does not schedule it, +retry a failed request, or sign the person in to a device maker. The program, the record, and the database become `2.2.0` together. D152 made those one number. D184 kept that rule. Migration step 5 stores `2.2.0` and -SQL schema 5. It adds no column and changes no record. Step 4 is not edited +SQL schema 5. It adds no column. It rebuilds `provider_summaries` as D203 +describes and copies existing rows with their numbers. Step 4 is not edited (D165). A new database runs step 5 after step 4 and before `user_version` is set. `applyMigrationStep` handles target 5. The migration chain, the SQL contract generator, and the drift check gain that step. The package exports @@ -32,19 +33,17 @@ into a version change, a client, and a mapping change. The version numbers below are proposals. They are not specs, and they are not adopted. -- 2.2.0 is this pull: sleep, workouts, and raw samples. +- 2.2.0 is this pull. D203 says which stored measurements it keeps. - 2.3.0 is a proposed Junction pull. This release does not call Junction. - 2.4.0 is proposed automatic incremental sync, saved sign-in refresh, - retries, and backfill. This release has none of those. -- Day aggregates and the heart-rate stream are left out of this proposed - pull. That is the proposed scope. D88 forbids a fabricated instant. It does - not forbid keeping a reporting bound the server sent, and it does not put - that work after Junction or automatic sync. This proposal suggests 2.5.0 - for that work. The maintainer decides the timing. `ProviderReportingPeriodType` - stays the Whoop, Oura, and Apple values it has now. -- A connector interface that every future source would implement is later - than the slot suggested for day aggregates. This release adds one module - for this server. + retries, and backfill. This release has none of those. A smaller page + after a local 8 MiB cap, described in D203, is not that retry. +- An earlier draft of this plan left day aggregates and the heart-rate + stream out and suggested 2.5.0 for them. D203 supersedes that draft. + D88 still forbids a fabricated instant. It does not forbid keeping a + bound the server sent. +- A connector interface that every future source would implement is not + part of this release. This release adds one module for this server. File imports stay: Apple Health, WHOOP, Oura, Garmin, and Strava. `ath pull garmin` stays as it is. Mapped import for every route other than @@ -63,15 +62,14 @@ Rejected alternatives: - Pull Junction, start sync jobs, or add a connector trait in this release. Rejected because this release has to make one manual read reliable first. The later version numbers are proposals, not adopted assignments. -- Store day aggregates in this release by calling them 2.5.0 work and then - requesting them anyway. Rejected. Leaving them out is the proposal. Adding - them silently is not. The maintainer can choose an earlier version than - the suggested 2.5.0. That choice is still open. +- Leave day aggregates and the heart-rate stream for a later version, or + request them while still calling that later version their home. Superseded + by D203. The current proposal stores them in this pull and says so. ## D199. The pull fetches pages and the shipped mapping writes the records -New Rust module `crates/ath-core/src/open_wearables.rs` requests the three -reads and calls `apply_mapping`. The command-line front end stays in +New Rust module `crates/ath-core/src/open_wearables.rs` requests the reads +in D203 and calls `apply_mapping`. The command-line front end stays in TypeScript (D174). New imports stay in `ath-core` (D155). The HTTP client is the `ureq` 2.12 dependency the Garmin pull already uses. No new crate. @@ -104,18 +102,15 @@ comma-joined string is not a member of the `SeriesType` enum. This study did not send that request, so it does not claim a live 422. The Rust source has no second copy of those names. -If the checked mapping produces no timeseries types, the pull skips the -timeseries request and reports zero counts for that read. The read is -`skipped`. On Open Wearables 0.11.0 the route defaults `types` to an empty -list, and the repository applies a type filter only when the list is -nonempty (`data_point_series_repository.py`). An empty list therefore -returns every series, including heart rate and location. This pull never -sends that request. A mapping that cannot be read for types fails before -any network call. - -`heart_rate` is not one of the shipped lines, and it is not a point quantity -the mapping can write. This proposal does not add the line and does not -store the heart-rate stream. Workout `avg_heart_rate_bpm` and +On Open Wearables 0.11.0 the route defaults `types` to an empty list, and +the repository applies a type filter only when the list is nonempty +(`data_point_series_repository.py`). An empty list therefore returns every +series. D203 omits `types` on the raw read and the day read for that +reason. A mapping that cannot store those series fails before any network +call. A comma-joined type string is still not sent. + +`heart_rate` is a series quantity. D203 stores the raw stream as +measurement samples. Workout `avg_heart_rate_bpm` and `max_heart_rate_bpm` stay as the file already maps them. `apply_mapping` adds counts by record type and keeps the existing `outcome` @@ -126,33 +121,21 @@ this command. They are not equal to the write when the same match key appears on two pages, or when the server changes between runs. The write still follows D182. This proposal does not keep a command-wide preview overlay. -The proposed read order is sleep, then workouts, then raw timeseries. That -order is part of what the maintainer approves. A failure in a later read +The read order is the order in D203. A failure in a later read leaves the earlier read's pages committed and the reads after the failure `not_attempted`. The result says so. See D201. -The coverage table in the specification is the proposed scope. Day -aggregates, sleep-linked physiology, recovery summaries, health scores, -meals, and body summaries are not requested. Open Wearables 0.11.0 already -returns reporting bounds on a day sample: an interval, `period_end`, -`computed_by`, and `stats`. Leaving those values out is incomplete coverage. -It is not required by D88. D88 forbids inventing a midnight. It does not -forbid storing a bound the server sent, and it does not assign the work to -a version after Junction and automatic sync. The suggested version is 2.5.0. -That suggestion is not adopted, and it is not approval of the loss. - -The other choice is a preservation design: store those intervals with their -bounds and basis, after a new period type. This proposal does not add that -type, does not label an Open Wearables day as a Whoop cycle or an Oura day, -and does not turn a summary into a point or a score. - -Sleep requests `include=stages`. Workouts request `include=zones`. Stage -minute totals return either way. The timeline and the zones are null when -the expansion is omitted, so omitting it would drop them before -`supplied_fields` can keep them. This proposal requests them and keeps -unmapped fields under the server's names. It does not request -`include=segments`. Segments are a separate size and privacy choice because -they can carry nested route detail. A page over 8 MiB still fails. +D203 is the coverage rule. An earlier draft of this decision left the day +rows, the summaries, and the heart-rate stream unrequested. That draft is +superseded. D88 still forbids inventing a midnight. The period type in +D203 stores the bound the server sent. An Open Wearables window is not +labeled as a Whoop cycle or an Oura day. + +Sleep requests `include=stages`. Workouts request `include=zones` and +`include=segments`. Stage minute totals return either way. The timeline, +the zones, and the segments are null when the expansion is omitted, so +omitting it would drop them before `supplied_fields` can keep them. A page +over 8 MiB is handled as D203 says. Rejected alternatives: @@ -162,16 +145,16 @@ Rejected alternatives: - Pass the sleep envelope straight to `apply_mapping`. Rejected because the current page rule would leave the page out. The check is `page_rows` and `row_fits` in `crates/ath-core/src/mapping.rs`. -- Request every series type and let `left_out` drop the rest. Rejected - because the type list includes latitude, longitude, and other series the - file does not store. The pull would download them for a result that cannot - keep them. -- Map `heart_rate` samples as points, or map recovery summaries onto - midnight. Rejected because one invents a point quantity and the other - invents an instant (D88, D110). The server's own period bounds are a - different fact. This proposal still does not store them. -- Send timeseries with an empty `types` list. Rejected because 0.11.0 then - returns every series. +- Request every series type and let `left_out` drop the ones the mapping + cannot store. Rejected. D203 stores them. `left_out` remains a row the + server returned and this program refused for a named reason. +- Map `heart_rate` samples as points, or map a day summary onto midnight. + Rejected. `heart_rate` is stored as a measurement sample. A day row is + stored as a reporting window (D88, D110, D203). +- Refuse an empty `types` list in order to avoid heart rate and location. + Superseded by D203. Omitting `types` is how 0.11.0 returns every series, + and those series are stored. A comma-joined string is still not a member + of the enum. - Put `device_id` on the sensor string, and therefore on the match key, for both import and pull. Not this proposal. It needs no new column, and the mapping engine already joins configured sensor paths, but it changes @@ -310,22 +293,24 @@ array, `pagination` must be an object, and `has_more` must be a boolean. Anything else fails the page. It is not an empty success. The result keeps a `left_out` total and at most 20 examples. -An empty range whose three reads completed is a successful pull with +An empty range whose reads completed is a successful pull with committed counts of zero and `range_complete` true. A repeat uses the match key from D181 and the replace from D182, so an unchanged row is not written again. A rerun after a partial write leaves the committed rows in place, runs the failed read again, and runs any read that was `not_attempted`. `has_more: false` is the only successful end of a read. A repeated cursor, -a null cursor while `has_more` is true, the 1000-page cap, and a body over -8 MiB fail that read. The failed page is not written. Later reads are -`not_attempted`. The success line is not printed. A cursor with the `prev_` -prefix is not sent. -`limit` is 1000. One attempt is made per request. There is no retry. The -connect timeout is 10 seconds and the read timeout is 30 seconds. +a null cursor while `has_more` is true, and the 1000-page cap fail that +read. A body over 8 MiB is handled by D203: the same query is sent with a +smaller limit, and one row that is still over 8 MiB fails that read. The +failed page is not written. Later reads are `not_attempted`. The success +line is not printed. A cursor with the `prev_` prefix is not sent. +`limit` starts at 1000. One attempt is made per request, except the smaller +page D203 sends after a local size cap. A transport error is not retried. +The connect timeout is 10 seconds and the read timeout is 30 seconds. A row that this range did not return is left where it is. The pull does not -call `DELETE`. There is no deletion feed on the three reads. Absence can be +call `DELETE`. There is no deletion feed on these reads. Absence can be a short range, a failed page, or a server filter. D190 still applies: a source the person has deleted stays deleted, and its rows are left out. A record the person has deleted stays deleted, and that object is left out @@ -343,13 +328,21 @@ Queries that are sent: `filter_by_priority=false`, `include=stages`. `is_nap` is omitted, so naps and main sleep both return. - Workouts: `start_date`, `end_date`, `limit`, `cursor` after the first page, - `include=zones`. `include=segments` is not sent. No priority flag, because - 0.11.0 has none and current `main` already returns every device when the - flag is absent. -- Timeseries, only when the mapping names at least one type: `start_time`, - `end_time`, `limit`, `resolution=raw`, `filter_by_priority=false`, repeated - `types` from the mapping file, and `cursor` after the first page. No types - means no request. + `include=zones`, and `include=segments`. No priority flag, because 0.11.0 + has none and current `main` already returns every device when the flag + is absent. +- Timeseries, twice: `start_time`, `end_time`, `limit`, + `filter_by_priority=false`, `cursor` after the first page, and + `resolution=raw` on one read and `resolution=1day` on the other. `types` + is omitted on both. +- Sleep summary, activity summary, and recovery summary: `start_date`, + `end_date`, `limit`, and `cursor` after the first page. +- Body summary: one request. `average_period` and `latest_window_hours` + are omitted, so the server's defaults apply. +- Health scores: `start_date`, `end_date`, `limit`, and `offset` until a + short page. This route has no cursor. +- Meals and menstrual cycles: `start_date`, `end_date`, `limit`, and + `cursor` after the first page. `source_selection` is not sent. On 0.11.0 the parameter does not exist. On current `main`, omitting it returns every device when the priority flag is @@ -394,7 +387,9 @@ open. They do not run on a pull. This build does not change them. for HTTP. `mapping.rs` may add the count by record type that D199 names, and the open-wearables device-binding check in the specification. That check is shared by mapped import and pull, and it is limited to route -`open_wearables`. Nothing else is added to `mapping.rs`. `store.rs` may +`open_wearables`. D203 also adds the measurement-sample target, the +reporting-window write, and the segment copy. Nothing beyond that is added +to `mapping.rs`. `store.rs` may preserve `device_binding` inside `revise` when the record is a source, and refuse a partial patch that contains that key. `revise` cannot set, change, or clear the receipt. The connection is private, `ensure_mapped_source` @@ -425,3 +420,56 @@ Rejected alternatives: the pull writes, and the maintainer asked not to widen this build. - Block the pull on those fixes. Rejected for the same reason. A later change can take any one of them on its own. + +## D203. Stored Open Wearables measurements are kept in this pull + +This supersedes the earlier draft, inside D198 and D199, that left day +values, the heart-rate stream, sleep and recovery summaries, meals, and +workout segments out of this pull. Those drafts are not deleted above. +They are not the current proposal. The specification's section 2 is the +list of reads, the storage rule, and the omissions that remain. + +A raw series that 2.1.0 already stores as a point stays a point, on the +same match key. A raw `heart_rate` series is a measurement sample because +that quantity already exists and it is not a point. Every other pinned +series type that has no quantity yet gains one. The unit and the number +come from the server. A row with `period_end` is a provider summary with +period type `open_wearables_reporting_window`. `recorded_at` is unset. +`start_at` and `end_at` are the server's `timestamp` and `period_end`. + +`ProviderReportingPeriodType` gains that one value. `ValueBasis` gains +`aggregator`, used when `computed_by` is `open_wearables`. Series +quantities gain the missing pinned types. `quantity` is already an +unconstrained text column, so those names add no SQL column. Step 5 +rebuilds `provider_summaries` so `standard_value` and `standard_unit` can +be null together. Existing summary rows are copied with their numbers. +The device receipt still adds no column. The receipt, the transaction, +the preview counts, and the public non-writing `--json` rule are +unchanged. + +The mapping file `mappings/open-wearables.md` is rewritten in the build +so a raw point, a raw sample, a day window, and a segment follow section +2. A resolved file that does not do that fails before any request. D179 +still lets an installed file win. This check stops the 2.1.0 file from +dropping rows the pull can store. + +Rejected alternatives: + +- Keep the earlier draft and store these values in a later version. + Rejected. The server already returns them, and a later version was + being used as a reason to leave them out. +- Store a day row as a point at the period start. Rejected. That would + make a reporting window look like one instant (D88, D110). +- Drop latitude, longitude, segments, or a large series to keep a + response under 8 MiB. Rejected. The smaller page in the specification + stores the rows. One row larger than 8 MiB is a real limit and is + named. +- Call the personal-record route, the live provider workout proxy, or + the totals routes so the pull can say it hit every path. Rejected. + The personal record is birth date, gender, and sex. The provider + workout routes read the vendor through the server's connection. The + totals routes add up rows this pull already stores. +- Invent a midnight, a zero, or an SDNN value from an RMSSD value. + Rejected. A null stays absent. Skin temperature is stored only from + a response that has the field. `RecoverySummary` at the pinned commit + does not have one. diff --git a/build-history/v2.2.0/progress.md b/build-history/v2.2.0/progress.md index f8196016..a8746261 100644 --- a/build-history/v2.2.0/progress.md +++ b/build-history/v2.2.0/progress.md @@ -5,9 +5,9 @@ program, the record, or the database has changed for 2.2.0. | Step | What | Status | |---|---|---| -| 0 | The plan: proposals D198–D202, and the Open Wearables study. Revised after the four reviews of `c9ca93a`. Still not adopted. The new head needs re-review | written, not approved | -| 1 | Version 2.2.0, migration step 5, no new column (D198) | not started | -| 2 | `ath pull openwearables` in `ath-core`, using the shipped mapping (D199, D201) | not started | +| 0 | The plan: proposals D198–D203, and the Open Wearables study. D203 keeps the stored measurements in this pull. Still not adopted. The new head needs re-review | written, not approved | +| 1 | Version 2.2.0 and migration step 5. No new column. Provider summaries may omit a number (D198, D203) | not started | +| 2 | `ath pull openwearables` in `ath-core`, with the rewritten mapping (D199, D201, D203) | not started | | 3 | Key, server, and user id kept out of the record (D200) | not started | | 4 | Fixture tests, with no live key in CI | not started | | 5 | Generated schema, demo athlete, skill command reference, and the public-data list | not started | diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index 46f960da..a3a24e26 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -2,9 +2,9 @@ Status: **plan only. The maintainer has not approved it. Not approved for build.** -`ath pull openwearables` reads one person's sleep, workouts, and raw samples -from an Open Wearables server they run, and writes them with the mapping file -that version 2.1.0 already ships. The proposals are D198 through D202 in +`ath pull openwearables` reads one person's stored health data from an Open +Wearables server they run, and writes it with the mapping this release +ships. The proposals are D198 through D203 in [decisions.md](decisions.md). They are not adopted. The evidence is [appendix/open-wearables-api.md](appendix/open-wearables-api.md), checked on 6 November 2026. @@ -71,10 +71,12 @@ Preview text prints: what that day means - `preview only; nothing stored` - `reads finished` or `reads incomplete` -- one line each for `sleep`, `workouts`, and `timeseries`: `completed`, - `failed`, `skipped`, or `not_attempted` +- one line each for `sleep`, `workouts`, `timeseries_raw`, + `timeseries_day`, `sleep_summary`, `activity_summary`, + `recovery_summary`, `body`, `health_scores`, `meals`, and `cycles`: + `completed`, `failed`, `skipped`, or `not_attempted` - estimated counts, by record type, of sleep sessions, workouts, points, - summaries, and scores + measurement samples, summaries, and scores - committed counts of zero - the coverage lines in section 2 - `left_out` as a total plus at most 20 example lines @@ -84,8 +86,7 @@ Preview text prints: `apply_mapping` transaction (D189). It is not a completed pull. The text prints actual committed counts for pages kept. It prints `requested range through is complete` only when every read ended with `has_more` -false, or timeseries was skipped because the mapping named no types. Only -then does it print `pulled openwearables from through `. +false. Only then does it print `pulled openwearables from through `. If a later page fails, the child returns a typed outcome to the parent before the process exits nonzero. The parent renders that outcome as text, @@ -116,7 +117,8 @@ server, user id, or request path. "reads": { "sleep": "completed", "workouts": "failed", - "timeseries": "not_attempted" + "timeseries_raw": "not_attempted", + "timeseries_day": "not_attempted" }, "estimated": { "sleep_session": { "new": 1, "changed": 0, "unchanged": 0 } @@ -169,82 +171,147 @@ When the variable is unset, the text says only that the saved key was removed. `ath key clear vercel` and `ath key clear openrouter` stay the gateway commands they are today. -## 2. What this release leaves for later - -D198 names the proposed boundary. File imports stay. The Garmin pull stays. -A Junction pull is proposed as 2.3.0. Automatic sync, retries, token refresh, -and backfill are proposed as 2.4.0. None of those numbers is adopted. - -This proposal pulls sleep and workouts first, then raw samples for the types -the checked mapping names. The maintainer is asked to accept incomplete -coverage, or to reject it in favor of a preservation design. The two choices -are in the table below. This proposal is the incomplete one. It does not add -aggregates under another name. Suggesting 2.5.0 is not approval of the loss, -and it is not a claim that Open Wearables lacks reporting bounds. 2.5.0 is -not adopted. A shared connector interface is later than that suggested slot. - -This release also leaves out: - -- creating users, OAuth, webhooks, SDK uploads, and Apple Health XML upload - through Open Wearables -- `DELETE` on the server, and any local delete inferred from a missing row -- health scores, meals, menstrual cycles, body summaries, and the activity, - sleep, and recovery summary routes -- timeseries resolutions other than `raw` -- the heart-rate stream, steps, and the other series the mapping file does not - name -- workout segments (`include=segments`) -- storing the server address, the user id, the API key, or a resume cursor - -On Open Wearables 0.11.0, day and session physiology are not raw samples. -A raw query can return nothing for a value the server holds as a day row or -as a sleep-linked aggregate. Fetching `SleepSession` does not bring those -scalars back: the session object has durations and stage totals, not resting -heart rate, heart-rate variability, blood oxygen, skin temperature, or -respiration. A day response from the timeseries route carries a reporting -interval, `period_end`, `computed_by`, and `stats`. Those are bounds the -server already has. Storing them does not require Athletic Standard to invent -a midnight instant (D88, D110). This proposal still does not request -`resolution=1day`, and it does not add an Open Wearables period type. -`ProviderReportingPeriodType` stays the Whoop, Oura, and Apple values it has. -An Open Wearables local day is not stored as a Whoop cycle or an Oura day. - -Some raw samples do exist. Oura interval heart-rate variability and Garmin -health-snapshot RMSSD and SDNN can be raw. A raw pull is not a claim that -every heart-rate variability or blood-oxygen value is absent. Coverage is by -provider and by granularity. - -| What the server can hold | This proposal | -|---|---| -| Sleep session: times, durations, stage minute totals | Stored by the shipped mapping | -| Sleep stage timeline (`sleep_stage_intervals`) | Requested with `include=stages`, then kept under the server's names. Totals return even when `include` is omitted. A null timeline means not requested when `include` was omitted, and means the server sent none when `include=stages` was sent | -| Workout average and maximum heart rate | Stored when the server sent them | -| Workout heart-rate and power zones | Requested with `include=zones`, then kept under the server's names. Not turned into scores | -| Workout segments | Not requested. Segments can carry nested route detail. Size and privacy are the reason. The 8 MiB page cap is a separate limit | -| WHOOP sleep-linked resting heart rate, RMSSD, blood oxygen, skin temperature | Not requested. Not on `SleepSession`. Not recovered by a raw query | -| Oura sleep scalar respiratory rate and resting heart rate | Not requested. Distinct from Oura's raw heart-rate-variability samples, which this pull can store when the mapping names them | -| Day resting heart rate, nightly heart-rate variability, blood oxygen, VO2 max | Not requested. The server can return them at `resolution=1day` with real period bounds | -| Heart-rate stream, steps, latitude, longitude | Not requested. The shipped mapping has no `type.heart_rate` line. A replaced mapping that names an existing field does request that series | - -The preview and the `--yes` text say which of those rows were not requested. -They do not call a missing row a zero, a server gap, or a `left_out` row. -`left_out` counts only rows the server returned and the mapping refused. -Not requested, zero, missing on the server, and returned-but-left-out are -four different facts. +## 2. What this pull stores + +D203 is the rule. An earlier draft of this plan left day values, the +heart-rate stream, sleep and recovery summaries, and workout segments for a +later version. That draft is superseded. Those values are part of this pull. +File imports stay. The Garmin pull stays. A Junction pull is proposed as +2.3.0. Automatic sync, retries, token refresh, and backfill are proposed as +2.4.0. None of those numbers is adopted. This release adds one module for +this server. It does not add a connector interface. + +The pull stores the measurements Open Wearables 0.11.0 can return for one +user and one range. A number is stored with the unit the server sent. A +period is stored as the period the server sent. A null field is absent. It +is not stored as zero. A value the provider never sent is absent. That +absence belongs to the provider. This plan did not remove the field. + +Sleep sessions are requested with `include=stages`. Workouts are requested +with `include=zones` and `include=segments`. Raw timeseries and day +timeseries each omit `types`, so the server returns every series it holds +for that resolution. The same dates are also read from the sleep, activity, +and recovery summaries, the body summary, health scores, meals, and +menstrual cycles. Reads that accept `filter_by_priority` send `false`, so +every device is included. Section 3 still applies to those rows. + +A raw row with no `period_end`, whose type is already a point quantity, +stays a point at the server's timestamp. Those 2.1.0 lines keep their match +keys, so a file import and a pull of that raw point stay one record. A raw +`heart_rate` row is a measurement sample. `heart_rate` is already a series +quantity. It is not stored as a point. When that row has `window_seconds`, +`duration_ms` is that count times 1000, and `window_seconds` also stays in +`supplied_fields`. Any other raw series that is not +already a point is a measurement sample. The build adds a quantity for each +pinned series type that does not have one. The unit is the unit in +`SERIES_TYPE_DEFINITIONS` at the pinned commit, and the number is the +server's number. Latitude and longitude are in that list. The stored record +then contains the locations the server sent. + +A row with `period_end`, including every `resolution=1day` row, is a +provider summary. `recorded_at` is left unset. The period type is +`open_wearables_reporting_window`. `start_at` and `end_at` are the server's +`timestamp` and `period_end`. On 0.11.0 those instants come from +`CalendarPeriod.of_date` in `timeseries_service.py`. This program stores the +strings the server sent. It does not calculate the boundary, and it does +not label the window as a Whoop cycle or an Oura day. `stats` and +`computed_by` stay under those names. Basis is `provider` when +`computed_by` is `provider`, `aggregator` when it is `open_wearables`, and +`provider_or_aggregator` when `computed_by` is absent. + +`SleepSession` has durations and stage totals. It has no resting heart +rate, heart-rate variability, blood oxygen, respiration, or skin +temperature. Those numbers are stored from the summary or the series that +actually carries them. Each non-null number on a sleep, activity, or +recovery summary is its own provider summary. `provider_date` is the +server's `date`. When a sleep summary also sends `start_time` and +`end_time`, those are the period bounds. A date by itself does not become +midnight. RMSSD and SDNN stay separate fields. The body summary uses +`measured_at` for a latest reading and `period_start` with `period_end` +for an average, when the server sent them. `age` is stored as the +calculated number the server sent. This pull does not call the +personal-record route. + +A health score that has a number is a provider score. The metric is the +category. The scale is `0-100` only for a field the server documents that +way. `RecoverySummary.recovery_score` is documented as 0 to 100 and marked +deprecated. The number is still stored, and the deprecation text stays in +`supplied_fields`. A score with a null value keeps the server object, +including its qualifier, on a provider summary that has no numeric value. +Meal numbers are provider summaries at the meal timestamp. Cycle numbers +use the cycle's start and end. The original object stays in +`supplied_fields` under the server's names. Workout numbers that are not +already typed stay there too, and each number is also a source-reported +summary on the workout. Segment objects stay under `segments`. A segment +with a label is also a typed segment. A missing label is not filled in. +Zones stay under the server's names. + +A provider summary may omit `value` when the server object has no number. +`supplied_fields` holds that object, and the record has an instant or a +reporting period. Step 5 rebuilds `provider_summaries` so `standard_value` +and `standard_unit` may be null together. Existing rows are copied with +their numbers. No number is created. + +The following are not requested. Each line is the reason. + +- Resolutions `1min`, `5min`, `15min`, and `1hour`. `_aggregated_timeseries` + builds those buckets from raw samples when the query runs. The raw + samples are stored. +- Resolutions `1week` and `1month`. `_period_timeseries` builds them from + day rows and sets `computed_by` to `open_wearables`. The day rows are + stored. +- Sleep totals, workout totals, and activity totals. The route text says + they add up the same rows the corresponding list returns. +- The data summary and the data timeline. They count stored rows. +- The personal-record route. Its fields are birth date, gender, and sex. +- The provider workout list and the provider workout detail. Those routes + read the vendor through the server's live connection. This pull keeps + the stored workout, including segments. +- Accounts, connections, sync, OAuth, webhooks, API keys, config, uploads, + and every `DELETE`. They are not measurements. The API key, the server + address, and the user id are not written into the athlete record. +- A workout with `entry_source` `manual`. The server describes it as a + self-reported entry with no device measurement. The measured record does + not take it. + +`RecoverySummary` at this commit has no skin-temperature field. The class +ends at `recovery_score`. Skin temperature is stored from a timeseries row +or from `BodyLatest.skin_temperature_celsius` when the server sends one. +The recovery field `avg_hrv_sdnn_ms` is in the schema. Its text says the +value is null for the rows that endpoint returns today, because those rows +come from WHOOP and WHOOP's HRV on that object is RMSSD. A non-null SDNN +is stored. RMSSD is not written into the SDNN field. + +A raw page and a day page are separate reads. Each page is one transaction +(D201). The body cap stays 8 MiB. A larger response is not mapped. The +same query is sent again with `limit` cut in half, down to 1. A transport +failure is not retried. One row that is itself larger than 8 MiB cannot +be stored. That read stays incomplete, and the message names the series +type. The pull does not drop a series to stay under the cap. + +The result separates four facts. The server returned no row. The server +sent null. The row was stored. The server returned a row and the mapping +refused it. `left_out` counts only the last fact. A missing series is not +reported as zero. `source.provider` is the Open Wearables integration name. `source.source` is the writer inside that integration. The mapping's `writer_field` is a convention. It is not proof that the device vendor computed the value. The -shipped bases stay `provider_or_aggregator` for session numbers and -`provider` for a provider score. Nullable `computed_by` on a raw sample is -not a new basis. Workout fields may be filled by Open Wearables and have no -per-field `computed_by` in this response. +basis is `provider_or_aggregator` when the server does not say who computed +the number, `provider` when `computed_by` is `provider` or the record is a +provider score, and `aggregator` when `computed_by` is `open_wearables`. +A raw sample on 0.11.0 is built without `computed_by`. That absence stays +`provider_or_aggregator`. Workout fields may be filled by Open Wearables +and have no per-field `computed_by` on the workout object. The original +`computed_by` string, when the server sent it, stays in `supplied_fields`. ## 3. How a response becomes records The pull resolves `open-wearables` through `resolveMappingFile`. It parses and checks the file before the first request. A bad file fails with no network -call. +call. A resolved file that does not implement section 2 also fails before +any request. An installed 2.1.0 copy still wins under D179, and this check +stops it from quietly dropping the rows section 2 stores. For each page of sleep it calls `apply_mapping` with `{ "sleep": }`. For each page of workouts it uses `workout`. @@ -295,7 +362,8 @@ are not rewritten, moved, or deleted. Both `ath import --mapping` and `ath pull` call `apply_mapping`. The check lives there, for route `open_wearables` only, inside the same transaction as the write and before `insert_group` changes a source device or a -timeseries record. Other routes are not checked. A pull-only check would +timeseries record, including a measurement sample and a window summary. +Other routes are not checked. A pull-only check would leave import-after-pull able to replace the point. The check reads every accepted row, including a row after the first source device. @@ -427,16 +495,15 @@ when the server sends it. The timestamp text is the server's `start_time`, mapping. The pull does not add `Z`. `computed_by`, `window_seconds`, `is_nap`, `intensity`, and `efficiency_percent` -stay under those names when they are present. The basis on a mapped value -stays the basis the file already states. This release does not read -`computed_by` as a new basis. Raw samples on 0.11.0 are built without that -field. Aggregates, which do carry it, are not requested. +stay under those names when they are present. `computed_by` sets the basis +in section 2. It does not change the writer. Raw samples on 0.11.0 are +built without that field. Day rows carry it, and those rows are stored. ## 4. Credentials, privacy, and the network D200 is the rule. The key never enters the athlete database, the export, the -preview, or an error line. The pull reads only the three paths in D201, plus -no others. It does not list users and does not read the personal record. +preview, or an error line. The pull reads only the paths in D201 and D203. +It does not list users and does not read the personal record. The process refuses a base URL that could carry the key in the URL itself. It refuses plain `http` except to loopback. It does not follow a redirect, so @@ -467,15 +534,16 @@ There is no Athletic Standard telemetry on this command. The server the person named is the only host contacted. A deployment API key can read every user on that server. The command cannot -shrink that key. It can avoid using the extra power: one user id, three -reads, no user list. +shrink that key. It can avoid using the extra power: one user id, the +reads in section 2, no user list. ## 5. Version, migration, and what stays compatible The build sets `2.2.0` on the package, the record, and `ath-core`, by the same constants 2.1.0 moved. Migration step 5 is a new SQL file. It updates `athleticstandard_version` to `2.2.0` and `sql_schema_version` to 5. No column -is added. Step 4 and file `004` are not edited (D165). +is added. The same file rebuilds `provider_summaries` as section 2 describes +and copies existing rows. Step 4 and file `004` are not edited (D165). A new database runs that step 5 SQL after step 4 and before the `user_version` pragma, inside `installInitialSchema`. `applyMigrationStep` gains an arm for @@ -494,21 +562,26 @@ would make a 1.0.0 database unloadable, so migrate could not open it. The build generates `schema/2.2.0/` and does not rewrite `schema/2.1.0/` or `schema/2.0.0/`. The 2.2.0 source object gains optional `device_binding`. -No other field is added. The folder exists so the package version and the -schema path stay aligned. The demo athlete is +`ProviderReportingPeriodType` gains `open_wearables_reporting_window`. +`ValueBasis` gains `aggregator`. Series quantities gain one entry for each +pinned series type that does not already have a point or series quantity. +`provider_summary.value` may be omitted, as section 2 says. No other field +is added. The folder exists so the package version and the schema path +stay aligned. The demo athlete is regenerated because the stored version is inside it. `examples/demo-athlete/athlete.ath.json` stays the legacy 0.4.3 file. `tests/fixtures/version-2-0-0/` is not regenerated. -`package.json` `files` already includes `mappings`. The mapping files are not -rewritten by this release. `pnpm generate:skill-cli` runs because help text +`package.json` `files` already includes `mappings`. The build rewrites +`mappings/open-wearables.md` so it implements section 2. Other mapping +files stay as they are. `pnpm generate:skill-cli` runs because help text changes (D80). `AGENTS.md`, `build-history/README.md`, and `SPEC.md` are updated in the build so they name 2.2.0 as the software. `docs/connections.md` -keeps the file imports and states the same limit as section 2: this proposed -pull does not store the day and sleep-session physiology the table leaves -out, and it does not store the heart-rate stream. The note says that -coverage is a proposal, not an adopted later version. This plan's edits to -`AGENTS.md` and `build-history/README.md` only point at the plan. +keeps the file imports and is updated to the coverage in section 2, including +that `RecoverySummary` at the pinned commit has no skin-temperature field. +This +plan's edits to `AGENTS.md` and `build-history/README.md` only point at the +plan. A database from 2.1.0 needs `ath migrate` before the pull. The migrate command still previews, backs up, and asks (D124). `Store::open` only @@ -532,19 +605,22 @@ interactive open can preview, back up, ask, and then migrate. `personal.rs` remains the Garmin pull. The two clients may each call `ureq`. A shared trait is the later connector work, and this release does not add it. -`mapping.rs` changes in two places, both required by this proposal. -`apply_mapping` keeps its `outcome` field and adds counts by record type. +`mapping.rs` changes for the counts, the device check, and the preservation +writes in section 2. `apply_mapping` keeps its `outcome` field and adds +counts by record type. For route `open_wearables` only, it also runs the device-binding check in section 3 before it mutates a source device or a timeseries record. That check is the shared mapped-import and pull enforcement. It is not a new -match key and it does not apply to any other route. `store.rs` keeps the +match key and it does not apply to any other route. It also gains the +measurement-sample target, the reporting-window write, and the segment +copy from section 2. HTTP stays out of `mapping.rs`. `store.rs` keeps the `revise` refusal and adds the three source operations in section 3: the receipt and tombstone read, creation with the checked receipt, and a first bind on an existing source that has no history. `ath correct`, package restore, and an accepted package merge stay whole-record owner writes. They are named in section 3 so the binding survives a 2.2.0 round -trip. They are not a new importer. The pull sums only `sleep_session`, -`workout_session`, `point_measurement`, `provider_summary`, and +trip. They are not a new importer. The pull sums only `sleep_session`, `workout_session`, +`point_measurement`, `measurement_sample`, `provider_summary`, and `provider_score`. A committed page adds those counts to the actual committed result. A rolled-back preview page adds them to `estimated`. It does not add `outcome` across pages. `outcome` counts the source-device row in the same @@ -599,19 +675,40 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: makes no database changes. Rows that were already stored stay. A successful `--json --yes` of a readable range is also a preview and makes no database changes -- a sleep-only mapping, installed where `.agents/mappings/` wins, produces - no timeseries types. The server sees no `/timeseries` request. Counts for - that read are zero and the read is `skipped`. A nonempty type list is - still one repeated `types` parameter per name, with duplicates removed +- an installed mapping that does not implement section 2 fails before any + request. The server sees no request. Raw and day timeseries requests omit + `types`. A comma-joined type string is not sent - a missing object, a `data` value that is not an array, a missing pagination object, or a `has_more` value that is not a boolean fails the page before `apply_mapping`. It is not an empty success -- `filter_by_priority=false` and `resolution=raw` are present on the reads - that send them. Sleep sends `include=stages`. Workouts send `include=zones`. - Neither sends `include=segments`. A fixture with stages omitted has null - intervals and still has stage totals. A fixture with `include=stages` keeps - the intervals under the server's names. A fixture with `include=zones` - keeps the nested heart-rate and power zones under the server's names +- `filter_by_priority=false` is present on the reads that have the flag. + Raw timeseries sends `resolution=raw`. Day timeseries sends + `resolution=1day`. Sleep sends `include=stages`. Workouts send + `include=zones` and `include=segments`. A fixture with stages omitted has + null intervals and still has stage totals. A fixture with `include=stages` + keeps the intervals under the server's names. A fixture with + `include=zones` keeps the nested heart-rate and power zones under the + server's names. A fixture with segments keeps the original objects, and a + segment that has a label is also a typed segment +- a raw `heart_rate` row becomes a measurement sample in bpm at the + server's timestamp. Export and import keep that timestamp, unit, and + value. A day row for resting heart rate, RMSSD, SDNN, blood oxygen, and + VO2 max becomes a provider summary with + `open_wearables_reporting_window`, no `recorded_at`, and the server's + `timestamp` and `period_end`. A null RMSSD beside a present SDNN stores + only the SDNN. A sleep summary respiratory rate is stored, and the sleep + session from the same night still has no respiration field. Skin + temperature is stored from a series row or from body latest. A recovery + object with no skin-temperature field does not gain one. `page-5min.json` + is left out, and the reason says it is a query bucket. RMSSD and SDNN + stay different quantities. A 2.1.0 raw point and a pull of that same raw + point through the new mapping stay one record. A heart-rate sample from + device B does not replace device A's sample +- a response larger than 8 MiB is requested again with a smaller limit, and + the rows are stored. One row larger than 8 MiB leaves that read + incomplete and names the series type. The personal-record route is not + requested. The export after a pull and a package import contains the + period bounds, the units, `computed_by`, and the segment objects - two distinct sensor triples become two sources. Device A is stored, then a separate operation contains only device B at the same triple, type, and instant, with a different value. The operation fails. The current point, @@ -738,8 +835,8 @@ the fixture key once into `ath key set openwearables`. command saves the fixture key, and the key is not on screen. Failure: init fails, or the key is printed. 2. Preview. Success: the pull without `--yes` says nothing is stored, shows - estimated counts, says which physiology was not requested, and `ath check` - still passes. Failure: a row is written, or the key appears. + estimated counts that include a heart-rate sample and a day summary, and + `ath check` still passes. Failure: a row is written, or the key appears. 3. Write. Success: the same command with `--yes` says the requested range is complete, shows committed counts, and `ath check` exits 0. Failure: the success sentence appears while the range is incomplete, or `ath check` @@ -752,7 +849,7 @@ the fixture key once into `ath key set openwearables`. The automated cases in section 7 are not extra card steps. -The build's proof is one phone message in Grok Bot. That message contains a +The build's proof is one phone message. That message contains a screenshot of each step inline and one video that plays in the conversation. A video that plays only on the pull request page is not that packet. The images are not committed. The numbers on screen are the fixture's invented @@ -772,8 +869,8 @@ is in the build pull request. `EBUSY`. Version 2.1.0 spec section 12 left it out and named no later version. - `store.rs` and `mapping.rs` are past a thousand lines. The pull does not - add HTTP to them. `mapping.rs` gains the counts by record type and the - shared open-wearables binding check in section 6. `store.rs` gains the + add HTTP to them. `mapping.rs` gains the counts, the open-wearables + binding check, and the preservation writes in section 2. `store.rs` gains the partial-update refusal and the three source operations in section 3. Splitting the files stays out. - `persist.rs` can still store a supplied field named `__proto__` if a caller @@ -797,43 +894,47 @@ Risks: tested against the stored fixture. That fixture is not a live response, and a live timestamp without an offset is left out. A breaking envelope needs a new fixture before the pull trusts it. -- A raw range of mapped series can be large. The 1000-page cap and the 8 MiB - cap fail that read, write nothing for the failed page, and withhold the - success line. The person narrows `--from` and `--to` and runs again. An - unchecked server limit, including a 429, can stop a later page after earlier - pages have been kept. The study did not read the rate-limit middleware. +- A raw range can be large. A page over 8 MiB is read again with a smaller + limit. A 429 or another transport failure still stops that read, keeps + earlier pages, and withholds the success line. The study did not read the + rate-limit middleware. - Date-only bounds mean whatever Open Wearables decides. The docs and the 0.11.0 parser disagree about UTC. This release does not correct that server. -- The table in section 2 is incomplete coverage, chosen on purpose and - still not adopted. It is not the device-binding rule. Suggesting 2.5.0 - does not approve the coverage gap. Workout average and maximum heart rate - can still be stored. Raw heart-rate variability can still arrive when the - mapping names it and the device binding allows the write. +- Section 2 stores the server's periods and series. It does not invent a + midnight. A provider that never sent a value still has a gap. The device + receipt is a separate rule. - Fields on a sleep or workout object that the mapping does not consume are - stored under the server's names. The shipped mapping does not request - latitude or longitude. A replaced mapping file can name more series, and - those series are then requested when they map onto an existing field. + stored under the server's names. Latitude and longitude are stored when + the server sends them. - The administrator key is more powerful than this command. A leaked key from the password store exposes every user on that deployment. The command's job is to avoid copying the key into the record. +The build, after approval, is one pull request in this order. First the +schema and step 5: the period type, the `aggregator` basis, the series +quantities, and the nullable provider-summary value. Then the mapping +engine and `mappings/open-wearables.md`. Then the reads, the smaller-page +split, and the tests in section 7. The laptop card and the phone proof are +part of that same pull request. This plan pull request has no media. + The maintainer approves or rejects this plan before any build. D198 through -D202 are the proposal. They are not adopted. Reviews of commit `d1fdde1` +D203 are the proposal. They are not adopted. Reviews of commit `d1fdde1` were incorporated here. The re-reviews of `1124e56`, `da006a6`, and `c9ca93a` are incorporated here. None of those reviews approves this -revision. The next head needs their re-review. A product review accepted a migration with no -new column, under D152 and D184. That acceptance does not adopt D198. The +revision. The next head needs re-review. An earlier review accepted a +migration with no new column, under D152 and D184. That acceptance does not +adopt D198. The optional source key adds no column. 1. One number, 2.2.0. Readable sets keep `1.0.0`. Step 5 runs on create and - on migrate. No new column. A `2.1.0` database does not open until - `ath migrate`. This release does not schedule, retry, refresh a token, - backfill, or store a cursor (D198). -2. Incomplete coverage, as the table in section 2, or a preservation design - that stores Open Wearables reporting intervals. This proposal is the - incomplete one. It does not invent a midnight, and it does not add a - period type. Suggesting 2.5.0 does not approve the loss. Sleep stage - timelines and workout zones are requested. Segments are not (D199). + on migrate. The device receipt adds no column. Step 5 does rebuild + `provider_summaries` so a summary of an object with no number can omit + `value`. A `2.1.0` database does not open until `ath migrate`. This + release does not schedule, refresh a token, backfill, or store a cursor + (D198, D203). +2. Store the Open Wearables measurements in section 2. Periods keep the + server's bounds. Series keep the server's numbers and units. Null stays + null. The omissions in section 2 are the ones with a reason (D203). 3. The key, the selected origin, and the selected user id are rejected in decoded JSON before a page is mapped. Failure text uses a fixed sentence. `ath key clear` with no name still clears only the gateway keys and says @@ -844,7 +945,8 @@ optional source key adds no column. write. `--yes` commits each successful page under D189, and a committed page is not a completed pull. The text of `--yes` shows retained counts and whether the requested range is complete. A missing row is not deleted. - An empty type list skips timeseries. The same sensor triple keeps one + Raw and day reads omit `types` and store every series. The same sensor + triple keeps one source. A second `device_id` does not replace or suppress the first, in a later command or in a mapped file import, including import then import. The receipt is the source key `device_binding`. A 2.1.0 supplied field of @@ -852,8 +954,8 @@ optional source key adds no column. left in place. `ath correct` and a native 2.2.0 package restore are the owner's whole source record (D201). 5. The Windows cleanup and the maintainability notes stay separate. - `mapping.rs` gains counts by record type and the open-wearables binding - check. `store.rs` gains the partial-update refusal, the receipt and - tombstone read, creation with the checked receipt, and the first bind - of an existing source that has no history. Nothing else is added to - either file (D202). + `mapping.rs` gains counts by record type, the open-wearables binding + check, and the preservation writes in section 2. `store.rs` gains the + partial-update refusal, the receipt and tombstone read, creation with + the checked receipt, and the first bind of an existing source that has + no history. Nothing else is added to either file (D202, D203). From 0ab1eb3933e7db428c9fd8d75eea3830b5f97a33 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 7 Nov 2026 03:07:21 +0000 Subject: [PATCH 07/60] Correct the 2.2.0 preservation contracts. D204 keeps the expanded Open Wearables data and states source, time, meaning, score, and read rules that match the pinned server. Co-authored-by: Michael Whitham --- .../v2.2.0/appendix/open-wearables-api.md | 75 +++ build-history/v2.2.0/decisions.md | 177 +++-- build-history/v2.2.0/progress.md | 6 +- build-history/v2.2.0/spec.md | 637 ++++++++++++------ 4 files changed, 624 insertions(+), 271 deletions(-) diff --git a/build-history/v2.2.0/appendix/open-wearables-api.md b/build-history/v2.2.0/appendix/open-wearables-api.md index 94eaf69e..d96bb5c6 100644 --- a/build-history/v2.2.0/appendix/open-wearables-api.md +++ b/build-history/v2.2.0/appendix/open-wearables-api.md @@ -242,6 +242,81 @@ Sleep totals, workout totals, and activity totals describe sums of the listed rows. The personal-record response fields are `birth_date`, `gender`, and `sex`. +## Contract read on 7 November 2026 + +The same commit was read again for the summary, score, meal, cycle, body, +and personal-record contracts. D204 is the storage rule. This section +records the source facts that rule uses. `SERIES_TYPE_DEFINITIONS` has 141 +entries. + +Raw rows keep the 2.1.0 kind when the mapping already names one. Those +series are `heart_rate_variability_rmssd`, `heart_rate_variability_sdnn`, +`resting_heart_rate`, `respiratory_rate`, `skin_temperature`, +`oxygen_saturation`, `heart_rate_recovery_one_minute`, `vo2_max`, +`garmin_stress_level`, and `garmin_body_battery`. + +These raw series become points because one existing quantity fits each of +them: `walking_heart_rate`, `body_temperature`, `height`, `weight`, +`body_fat_percentage`, `lean_body_mass`, `blood_pressure_systolic`, and +`blood_pressure_diastolic`. `weight` is stored as `body_weight`. The +series name stays in `supplied_fields`. + +These raw series are provider summaries, not samples: +`peripheral_perfusion_index`, `breathing_disturbance_index`, +`body_mass_index`, `cardiovascular_age`, `workout_effort_score`, +`estimated_workout_effort_score`, `garmin_fitness_age`, +`withings_metabolic_age`, and `nike_fuel`. + +Reported intake is every `dietary_*` series and +`number_of_alcoholic_beverages`. There are 42 `dietary_*` series. They are +provider summaries. + +The remaining 71 raw series are measurement samples: + +`heart_rate`, `blood_glucose`, `sleeping_breathing_disturbances`, +`blood_alcohol_content`, `forced_vital_capacity`, +`forced_expiratory_volume_1`, `peak_expiratory_flow_rate`, +`waist_circumference`, `body_fat_mass`, `skeletal_muscle_mass`, +`skin_temperature_deviation`, `skin_temperature_trend_deviation`, +`bone_mass`, `body_water_mass`, `six_minute_walk_test_distance`, `steps`, +`active_energy`, `basal_energy`, `stand_time`, `exercise_time`, +`physical_effort`, `flights_climbed`, `active_time`, `total_energy`, +`distance_walking_running`, `distance_cycling`, `distance_swimming`, +`distance_downhill_snow_sports`, `distance_other`, `walking_step_length`, +`walking_speed`, `walking_double_support_percentage`, +`walking_asymmetry_percentage`, `walking_steadiness`, +`stair_descent_speed`, `stair_ascent_speed`, `running_power`, +`running_speed`, `running_vertical_oscillation`, +`running_ground_contact_time`, `running_stride_length`, +`running_vertical_ratio`, `running_stance_time_balance`, +`swimming_stroke_count`, `underwater_depth`, `cadence`, `power`, `speed`, +`distance`, `elevation_gain`, `environmental_audio_exposure`, +`headphone_audio_exposure`, `environmental_sound_reduction`, +`time_in_daylight`, `water_temperature`, `uv_exposure`, `inhaler_usage`, +`weather_temperature`, `weather_humidity`, `elevation`, `latitude`, +`longitude`, `air_temperature`, `garmin_skin_temperature`, +`withings_pulse_wave_velocity`, `electrodermal_activity`, `push_count`, +`atrial_fibrillation_burden`, `insulin_delivery`, +`number_of_times_fallen`, and `hydration`. + +`get_day_rows` keeps one row per data source, series, and local day. It +orders provider-computed rows first, then the later `period_start`. +`_period_timeseries` rebuilds the response bounds with `CalendarPeriod`. +A week or month forces `computed_by` to `open_wearables`. A day page's +`limit` counts periods. The service floors that count at 1, and one period +can contain one row per source and series. + +`HEALTH_SCORE_RANGES` sets the finite scales. Polar readiness is 0 to 10. +Polar recovery is 1 to 6. WHOOP strain is 0 to 21. Polar strain has no +finite maximum. The route text says `provider: internal` scores were +computed by Open Wearables and are still returned. WHOOP recovery +components include `skin_temp_celsius` when the provider sent it. + +`get_menstrual_cycles` sets `end_datetime` to null. `get_body_summary` +uses `datetime.now`, omits `device_id`, and does not put a time on +`BodySlowChanging`. The personal-record response is `birth_date`, +`gender`, `sex`, and `user_id`. A field that was never set is null. + ## What was not checked - A running server's JSON, including the exact `start_time` text. diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index e3634ef0..e0cb4a4f 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -9,7 +9,7 @@ D-number. ## D198. Version 2.2.0 is one manual pull, and the program and the record share that number -`ath pull openwearables` reads the stored measurements D203 lists from an +`ath pull openwearables` reads the stored measurements D204 lists from an Open Wearables server the person runs, for one user and one range they name. The command is manual. The person runs it. The program does not schedule it, retry a failed request, or sign the person in to a device maker. @@ -211,8 +211,9 @@ Garmin's key command is unchanged. The server is `--base-url` or `OPEN_WEARABLES_BASE_URL`. The user id is `--user` or `OPEN_WEARABLES_USER_ID`. Neither is written into the database, -the export, a config file, or a log line. The pull never calls `GET /users` -and never calls the personal-record route. One command reads one user. +the export, a config file, or a log line. The pull never calls `GET /users`. +D204 reads the personal record and drops its `user_id` before the scan. +Birth date, gender, and sex are stored. One command reads one user. `--base-url` is an origin: scheme, host, and optional port. No user name, no password, no path other than empty or `/`, no query, and no fragment. `http` @@ -256,8 +257,9 @@ Rejected alternatives: Each response page is one `apply_mapping` call. D189 still makes that call one transaction: a failure rolls the page back, and a preview rolls the page -back after counting. The pull itself is a series of those calls. The proposed -order is sleep pages, then workout pages, then timeseries pages. A committed +back after counting. The pull itself is a series of those calls. The order and the terminal +condition of each read are the table in the specification's section 2. +A committed page follows D189. A committed page does not mean the pull is complete. The command previews unless `--yes` is present. `--json` does not write, @@ -274,11 +276,11 @@ confirmed outcome as text. It renders the preview outcome as public JSON. On a partial failure the child returns the confirmed outcome and then exits nonzero. The parent renders the text before it uses that status. -Each of `sleep`, `workouts`, and `timeseries` is `completed`, `failed`, -`skipped`, or `not_attempted`. The token is `not_attempted` in the outcome -and in the text. `skipped` is the timeseries read when the mapping named no -types. `range_complete` is true only on a `--yes` write whose reads finished -without a failed page. The success sentence is printed only then. A retained +Each read in that table is `completed`, `failed`, or `not_attempted`. The +token is `not_attempted` in the outcome and in the text. There is no +`skipped` read. `range_complete` is true only on a `--yes` write whose +ranged reads reached their terminal conditions. The success sentence also +requires the personal record and the body snapshot to have completed. A retained count with an incomplete range is a partial pull. The message names the failed read, names any `not_attempted` read, and gives the retained counts. A failed read says to run the same command again. An identity refusal uses @@ -288,10 +290,12 @@ reconciliation, and a rerun cannot repair either one. A preview that fails makes no database changes, including for pages that had already been counted. -Before `apply_mapping`, the page must be a JSON object, `data` must be an -array, `pagination` must be an object, and `has_more` must be a boolean. -Anything else fails the page. It is not an empty success. The result keeps -a `left_out` total and at most 20 examples. +Before `apply_mapping`, a cursor page and an offset page must be a JSON +object, `data` must be an array, `pagination` must be an object, and +`has_more` must be a boolean. Anything else fails that page. It is not an +empty success. Body may be one object or JSON `null`. `null` is a completed +empty snapshot. The personal record is one object. The result keeps a +`left_out` total and at most 20 examples. An empty range whose reads completed is a successful pull with committed counts of zero and `range_complete` true. A repeat uses the match @@ -299,14 +303,14 @@ key from D181 and the replace from D182, so an unchanged row is not written again. A rerun after a partial write leaves the committed rows in place, runs the failed read again, and runs any read that was `not_attempted`. -`has_more: false` is the only successful end of a read. A repeated cursor, -a null cursor while `has_more` is true, and the 1000-page cap fail that -read. A body over 8 MiB is handled by D203: the same query is sent with a -smaller limit, and one row that is still over 8 MiB fails that read. The -failed page is not written. Later reads are `not_attempted`. The success -line is not printed. A cursor with the `prev_` prefix is not sent. -`limit` starts at 1000. One attempt is made per request, except the smaller -page D203 sends after a local size cap. A transport error is not retried. +`has_more: false` is the successful end of a cursor read and of the offset +read. A repeated cursor, a null cursor while `has_more` is true, and the +1000-page cap fail that read. An offset retry uses the same offset. A body +over 8 MiB is handled by D204. The failed page is not written. Later reads +are `not_attempted`. The success line is not printed. A cursor with the +`prev_` prefix is not sent. `limit` starts at 1000. One attempt is made per +request, except the smaller page D204 sends after a local size cap. A +transport error is not retried. The connect timeout is 10 seconds and the read timeout is 30 seconds. A row that this range did not return is left where it is. The pull does not @@ -322,31 +326,12 @@ that a date-only bound is interpreted by Open Wearables, and that Athletic Standard did not convert it to the athlete's timezone (D88). The appendix records the disagreement between the docs and the 0.11.0 parser. -Queries that are sent: - -- Sleep: `start_date`, `end_date`, `limit`, `cursor` after the first page, - `filter_by_priority=false`, `include=stages`. `is_nap` is omitted, so naps - and main sleep both return. -- Workouts: `start_date`, `end_date`, `limit`, `cursor` after the first page, - `include=zones`, and `include=segments`. No priority flag, because 0.11.0 - has none and current `main` already returns every device when the flag - is absent. -- Timeseries, twice: `start_time`, `end_time`, `limit`, - `filter_by_priority=false`, `cursor` after the first page, and - `resolution=raw` on one read and `resolution=1day` on the other. `types` - is omitted on both. -- Sleep summary, activity summary, and recovery summary: `start_date`, - `end_date`, `limit`, and `cursor` after the first page. -- Body summary: one request. `average_period` and `latest_window_hours` - are omitted, so the server's defaults apply. -- Health scores: `start_date`, `end_date`, `limit`, and `offset` until a - short page. This route has no cursor. -- Meals and menstrual cycles: `start_date`, `end_date`, `limit`, and - `cursor` after the first page. - -`source_selection` is not sent. On 0.11.0 the parameter does not exist. On -current `main`, omitting it returns every device when the priority flag is -false. +The queries are the table in the specification's section 2. An earlier +draft of this proposal listed three reads and treated every page as a +cursor envelope. D204 supersedes that draft. `source_selection` is not +sent. On 0.11.0 the parameter does not exist. On current `main`, omitting +it returns every device when the priority flag is false. Summary routes +still select a source. That selection is not a client filter. Rejected alternatives: @@ -399,8 +384,12 @@ create a source with the checked receipt, and write that receipt on an existing unbound source only when the same transaction shows no accepted or deleted record and no source device. Those writes keep every other source field and the normal revision and `data_json` bookkeeping. They -join the caller's `BEGIN IMMEDIATE` transaction. Nothing else is added to -`store.rs`. Other routes do not call them. `ath correct`, package restore, +join the caller's `BEGIN IMMEDIATE` transaction. D204 also allows +`measurement_sample` insert and update, and a null value and unit pair on +provider summaries and provider scores. A half-null pair is refused. The +same pair is allowed in the TypeScript projection, package import, record +view, and repair copy. Nothing beyond that is added to `store.rs`. Other +routes do not call the receipt operations. `ath correct`, package restore, and an accepted package merge remain the owner's whole source record. Splitting the files is separate work. It is not required to make the pull correct. @@ -423,6 +412,11 @@ Rejected alternatives: ## D203. Stored Open Wearables measurements are kept in this pull +D204 supersedes the classification, source identity, time, score, endpoint, +and size sentences in this proposal. The decision to keep the returned +health data in this pull stands. Where a paragraph below disagrees with +D204, D204 is the proposal. + This supersedes the earlier draft, inside D198 and D199, that left day values, the heart-rate stream, sleep and recovery summaries, meals, and workout segments out of this pull. Those drafts are not deleted above. @@ -462,14 +456,79 @@ Rejected alternatives: make a reporting window look like one instant (D88, D110). - Drop latitude, longitude, segments, or a large series to keep a response under 8 MiB. Rejected. The smaller page in the specification - stores the rows. One row larger than 8 MiB is a real limit and is - named. -- Call the personal-record route, the live provider workout proxy, or - the totals routes so the pull can say it hit every path. Rejected. - The personal record is birth date, gender, and sex. The provider - workout routes read the vendor through the server's connection. The - totals routes add up rows this pull already stores. + stores the rows. D204 states the minimum-page limit without naming a + series type. +- Call the live provider workout proxy or the totals routes so the pull + can say it hit every path. Rejected. Those routes are not the stored + measurements. D204 does read the personal record. An earlier sentence + in this list left it out. That sentence is superseded. - Invent a midnight, a zero, or an SDNN value from an RMSSD value. - Rejected. A null stays absent. Skin temperature is stored only from - a response that has the field. `RecoverySummary` at the pinned commit - does not have one. + Rejected. A null stays absent. `RecoverySummary` at the pinned commit + has no skin-temperature field. A health-score component can still carry + one. D204 says so. + +## D204. Returned values keep their meaning, source, and time + +This corrects D203. The values stay in this pull. The corrections are the +contracts in the specification's section 2. + +A device source is still the 2.1.0 sensor, and its receipt rules are +unchanged. A summary the server builds without `device_id`, a meal or +cycle without one, a null timeseries source, and a health score use the +separate sensors in that section. They do not borrow a device id, and +their history does not block a later device binding. A raw or day sample +that has a source and no device id is still refused. + +A number is classified before it is normalized. Existing raw points, raw +`vo2_max`, and the two raw Garmin scores keep their kinds and keys. Dietary +series and the named indexes, ages, and effort scores are provider +summaries. The other raw series readings are measurement samples. Day rows +use the same classes on the server's calendar window. That window is not +the provider's original interval. + +Health-score `provider` is the author. `source` is the input and may be +null. `provider: internal` is basis `aggregator`. A finite range in +`constants/health_scores.py` is the scale. An unknown or unbounded range +is not given `0-100`. The original object, including components and +`event_record_id`, is kept. + +Sleep main-sleep bounds apply only to the fields section 2 names. Body is +the server's current snapshot, not the requested range. Fields with no +time use `not_provided_by_source` and no invented instant. Age is +calculated. BMI is not labeled measured. The personal record's birth date, +gender, and sex are stored. Its `user_id` is not. The athlete profile is +not used for them, because that record cannot hold a full birth date, the +gender values, or a source. + +Cursor pages, offset pages, and the two one-shot reads have the terminal +conditions in the table. A smaller page repeats the same uncommitted +cursor or offset. A minimum page or an unpaginated response that is still +over 8 MiB is an incomplete read. The message names the read. It does not +name a series type. Menstrual cycles keep an in-range start and a future +end. A later start is not stored. The page is still followed to the end. + +Step 5 rebuilds `provider_summaries` and `provider_scores` so value and +unit are both null or both present. It copies existing rows and keeps +their ids, revisions, import keys, and tombstones. `store.rs` may insert +and update samples and those paired-null rows. The TypeScript projection, +package import, record view, and repair copy may do the same. Half-null +is refused. No other store change is included. + +Rejected alternatives: + +- Put a summary with no device id on the bound device source. Rejected. + The summary would be refused, or the missing id would be invented. +- Leave birth date, gender, and sex out because they are sensitive. + Rejected. They are health data. The user id is the part that stays out. +- Use the athlete profile for those three fields. Rejected. The profile + has no source, no full birth date, and no room for every gender value. +- Call every numeric series a measurement sample. Rejected. Intake, + indexes, ages, effort scores, and the existing summary and score lines + would change meaning or identity. +- Treat body as a read of `--from` and `--to`, or date the undated fields + with the average window or the pull time. Rejected. The route has no + date parameters, and those times would be invented. +- Give every health score the scale `0-100` or the basis `provider`. + Rejected. The pinned range table and `provider: internal` say otherwise. +- Stop a day read at `limit` 1 and report one oversized series. Rejected. + That limit counts periods, and one period can hold many rows. diff --git a/build-history/v2.2.0/progress.md b/build-history/v2.2.0/progress.md index a8746261..20194c31 100644 --- a/build-history/v2.2.0/progress.md +++ b/build-history/v2.2.0/progress.md @@ -5,9 +5,9 @@ program, the record, or the database has changed for 2.2.0. | Step | What | Status | |---|---|---| -| 0 | The plan: proposals D198–D203, and the Open Wearables study. D203 keeps the stored measurements in this pull. Still not adopted. The new head needs re-review | written, not approved | -| 1 | Version 2.2.0 and migration step 5. No new column. Provider summaries may omit a number (D198, D203) | not started | -| 2 | `ath pull openwearables` in `ath-core`, with the rewritten mapping (D199, D201, D203) | not started | +| 0 | The plan: proposals D198–D204, and the Open Wearables study. D204 corrects the meaning of the stored measurements. Still not adopted. The new head needs re-review | written, not approved | +| 1 | Version 2.2.0 and migration step 5. No new column. Summary and score values may be omitted in pairs (D198, D204) | not started | +| 2 | `ath pull openwearables` in `ath-core`, with the rewritten mapping (D199, D201, D204) | not started | | 3 | Key, server, and user id kept out of the record (D200) | not started | | 4 | Fixture tests, with no live key in CI | not started | | 5 | Generated schema, demo athlete, skill command reference, and the public-data list | not started | diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index a3a24e26..de0b9bf4 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -4,10 +4,10 @@ Status: **plan only. The maintainer has not approved it. Not approved for build. `ath pull openwearables` reads one person's stored health data from an Open Wearables server they run, and writes it with the mapping this release -ships. The proposals are D198 through D203 in +ships. The proposals are D198 through D204 in [decisions.md](decisions.md). They are not adopted. The evidence is [appendix/open-wearables-api.md](appendix/open-wearables-api.md), checked on -6 November 2026. +6 and 7 November 2026. This pull request is the plan. The build after approval is one later pull request. This plan does not change a version number, a schema, a fixture, or @@ -71,10 +71,10 @@ Preview text prints: what that day means - `preview only; nothing stored` - `reads finished` or `reads incomplete` -- one line each for `sleep`, `workouts`, `timeseries_raw`, - `timeseries_day`, `sleep_summary`, `activity_summary`, - `recovery_summary`, `body`, `health_scores`, `meals`, and `cycles`: - `completed`, `failed`, `skipped`, or `not_attempted` +- one line each for the twelve reads in section 2: `completed`, `failed`, + or `not_attempted` +- for body, one extra line: `body snapshot stored`, `body snapshot empty`, + or `body snapshot incomplete` - estimated counts, by record type, of sleep sessions, workouts, points, measurement samples, summaries, and scores - committed counts of zero @@ -85,8 +85,12 @@ Preview text prints: `--yes` without `--json` commits each successful page. That commit is one `apply_mapping` transaction (D189). It is not a completed pull. The text prints actual committed counts for pages kept. It prints `requested range - through is complete` only when every read ended with `has_more` -false. Only then does it print `pulled openwearables from through `. + through is complete` only when every ranged read in section 2 +reached that read's terminal condition. Body is not one of those reads. +The success sentence `pulled openwearables from through ` is +printed only when the range is complete and body and the personal record +also completed. A finished range with an incomplete body snapshot does not +print that sentence. The body line still says the snapshot is incomplete. If a later page fails, the child returns a typed outcome to the parent before the process exits nonzero. The parent renders that outcome as text, @@ -103,7 +107,7 @@ the database has no rows. Public `--json`, with or without `--yes`, is only the preview outcome below. `written` is false. `committed` is zero. `estimated` holds the page-local estimates. `range_complete` is false. `reads_finished` is true only when -every read completed or was skipped. The read status token is +every read completed. The read status token is `not_attempted`, in this object and in the text. The object has no key, server, user id, or request path. @@ -173,137 +177,286 @@ gateway commands they are today. ## 2. What this pull stores -D203 is the rule. An earlier draft of this plan left day values, the -heart-rate stream, sleep and recovery summaries, and workout segments for a -later version. That draft is superseded. Those values are part of this pull. -File imports stay. The Garmin pull stays. A Junction pull is proposed as +D204 is the storage rule. D203 keeps these values in this pull. D204 +corrects how they are identified, timed, and classified. An earlier draft +left day values, the heart-rate stream, summaries, and workout segments for +a later version. That draft is superseded. File imports stay. The Garmin pull stays. A Junction pull is proposed as 2.3.0. Automatic sync, retries, token refresh, and backfill are proposed as 2.4.0. None of those numbers is adopted. This release adds one module for this server. It does not add a connector interface. -The pull stores the measurements Open Wearables 0.11.0 can return for one -user and one range. A number is stored with the unit the server sent. A -period is stored as the period the server sent. A null field is absent. It -is not stored as zero. A value the provider never sent is absent. That -absence belongs to the provider. This plan did not remove the field. - -Sleep sessions are requested with `include=stages`. Workouts are requested -with `include=zones` and `include=segments`. Raw timeseries and day -timeseries each omit `types`, so the server returns every series it holds -for that resolution. The same dates are also read from the sleep, activity, -and recovery summaries, the body summary, health scores, meals, and -menstrual cycles. Reads that accept `filter_by_priority` send `false`, so -every device is included. Section 3 still applies to those rows. - -A raw row with no `period_end`, whose type is already a point quantity, -stays a point at the server's timestamp. Those 2.1.0 lines keep their match -keys, so a file import and a pull of that raw point stay one record. A raw -`heart_rate` row is a measurement sample. `heart_rate` is already a series -quantity. It is not stored as a point. When that row has `window_seconds`, -`duration_ms` is that count times 1000, and `window_seconds` also stays in -`supplied_fields`. Any other raw series that is not -already a point is a measurement sample. The build adds a quantity for each -pinned series type that does not have one. The unit is the unit in -`SERIES_TYPE_DEFINITIONS` at the pinned commit, and the number is the -server's number. Latitude and longitude are in that list. The stored record -then contains the locations the server sent. - -A row with `period_end`, including every `resolution=1day` row, is a -provider summary. `recorded_at` is left unset. The period type is -`open_wearables_reporting_window`. `start_at` and `end_at` are the server's -`timestamp` and `period_end`. On 0.11.0 those instants come from -`CalendarPeriod.of_date` in `timeseries_service.py`. This program stores the -strings the server sent. It does not calculate the boundary, and it does -not label the window as a Whoop cycle or an Oura day. `stats` and -`computed_by` stay under those names. Basis is `provider` when -`computed_by` is `provider`, `aggregator` when it is `open_wearables`, and -`provider_or_aggregator` when `computed_by` is absent. - -`SleepSession` has durations and stage totals. It has no resting heart -rate, heart-rate variability, blood oxygen, respiration, or skin -temperature. Those numbers are stored from the summary or the series that -actually carries them. Each non-null number on a sleep, activity, or -recovery summary is its own provider summary. `provider_date` is the -server's `date`. When a sleep summary also sends `start_time` and -`end_time`, those are the period bounds. A date by itself does not become -midnight. RMSSD and SDNN stay separate fields. The body summary uses -`measured_at` for a latest reading and `period_start` with `period_end` -for an average, when the server sent them. `age` is stored as the -calculated number the server sent. This pull does not call the -personal-record route. - -A health score that has a number is a provider score. The metric is the -category. The scale is `0-100` only for a field the server documents that -way. `RecoverySummary.recovery_score` is documented as 0 to 100 and marked -deprecated. The number is still stored, and the deprecation text stays in -`supplied_fields`. A score with a null value keeps the server object, -including its qualifier, on a provider summary that has no numeric value. -Meal numbers are provider summaries at the meal timestamp. Cycle numbers -use the cycle's start and end. The original object stays in -`supplied_fields` under the server's names. Workout numbers that are not -already typed stay there too, and each number is also a source-reported -summary on the workout. Segment objects stay under `segments`. A segment -with a label is also a typed segment. A missing label is not filled in. -Zones stay under the server's names. - -A provider summary may omit `value` when the server object has no number. -`supplied_fields` holds that object, and the record has an instant or a -reporting period. Step 5 rebuilds `provider_summaries` so `standard_value` -and `standard_unit` may be null together. Existing rows are copied with -their numbers. No number is created. +This pull stores the representations Open Wearables 0.11.0 returns for one +user. A ranged read stores that range. Body does not. A returned number +keeps the server's unit. A returned null stays absent and is not stored as +zero. A returned zero stays zero. A row the server did not return is not +labeled provider-unavailable. Priority selection, a day-row pick, and a +rollup can omit a stored row from the response. That omission is unknown +here. It is not a null, and it is not a refusal. `left_out` counts only a +row the server returned and this program refused. + +The promise is the returned object. It is not a copy of the Open Wearables +database, and it is not every device on a route that selects one source. +Sleep events, workouts, and raw and day timeseries send +`filter_by_priority=false` where that parameter exists. Sleep, activity, +and recovery summaries have no such parameter. Their services select a +source. This pull does not send a priority switch and does not change the +server's priority. Activity summaries also add together data sources that +share provider, writer, model, and type +(`series_aggregate_repository.py`, `daily_activity`). The stored source is +the source object on the response. It is not a receipt that every +contributor was that device. + +The twelve reads, in order, use these paths under +`/api/v1/users/{user_id}`: + +| Read | Path and query | Response and end | What the time means | +|---|---|---|---| +| `sleep` | `/events/sleep`. `start_date`, `end_date`, `limit`, `cursor`, `filter_by_priority=false`, `include=stages` | Cursor page. Ends at `has_more: false` | Session start and end | +| `workouts` | `/events/workouts`. dates, `limit`, `cursor`, `include=zones`, `include=segments`. No priority parameter | Cursor page. Ends at `has_more: false` | Session start and end | +| `timeseries_raw` | `/timeseries`. `start_time`, `end_time`, `limit`, `cursor`, `resolution=raw`, `filter_by_priority=false`. `types` omitted | Cursor page. Ends at `has_more: false` | Sample `timestamp` | +| `timeseries_day` | `/timeseries`. Same, with `resolution=1day` | Cursor page. `limit` counts periods, not rows. Ends at `has_more: false` | Server calendar window, not the provider's original interval | +| `sleep_summary` | `/summaries/sleep`. dates, `limit`, `cursor`. No priority parameter | Cursor page. Ends at `has_more: false` | `date`, plus main-sleep bounds only on the fields named below | +| `activity_summary` | `/summaries/activity`. dates, `limit`, `cursor`. No priority parameter | Cursor page. Ends at `has_more: false` | `date` only | +| `recovery_summary` | `/summaries/recovery`. dates, `limit`, `cursor`. No priority parameter | Cursor page. Ends at `has_more: false` | `date` only | +| `health_scores` | `/health-scores`. dates, `limit`, `offset`. No category or provider filter | Offset page with `pagination.has_more`. Ends at `has_more: false` | Score `recorded_at` | +| `meals` | `/events/meals`. dates, `limit`, `cursor` | Cursor page. Ends at `has_more: false` | Meal `timestamp` | +| `cycles` | `/events/menstrual-cycles`. dates, `limit`, `cursor`. The service clears `end_datetime` | Cursor page, then the local start rule below. Ends at `has_more: false` | Cycle `start_time` and `end_time` | +| `personal_record` | `/personal-record`. No dates | One object. The top-level `user_id` is removed before the privacy scan and is not stored | No measurement time | +| `body` | `/summaries/body`. No dates, no limit. `average_period` and `latest_window_hours` omitted, so the server uses 7 days and 4 hours | One `BodySummary`, or JSON `null`. `null` is an empty snapshot, not a bad page | Current snapshot. Not the requested range | + +A cursor page is a JSON object whose `data` is an array and whose +`pagination` is an object with boolean `has_more`, checked before mapping. +An offset page is the same, and it has no `next_cursor` requirement. Body +and the personal record are not those envelopes. A cursor rule applied to +them is a failed read. Health-score `metadata` is not a record. + +The menstrual-cycle service sets `end_datetime` to null so a predicted +future end is not dropped. This program still sends the requested dates. +Before mapping, it keeps a cycle whose start falls in the requested range +and keeps that cycle's end as sent, including an end after the range. For +date bounds, the date is the `YYYY-MM-DD` at the start of `start_time`, +with no timezone conversion, and the dates are inclusive. For timestamp +bounds, the start instant is greater than or equal to `--from` and less +than `--to`. A start that cannot be compared, because it has no offset, is +`left_out`. It is not given `Z`. A start after the range is not stored and +is not `left_out`. Paging continues until `has_more` is false. The server +still applies its own start bound, so a cycle that started before `--from` +is not returned. That is the server's filter. + +A page over 8 MiB is not mapped. On a cursor or offset read, the same +cursor or the same offset is sent again with `limit` halved, down to 1. +The discarded response writes nothing and does not advance the cursor or +the offset. A transport failure is not retried. Day `limit` counts periods. +A `limit` of 1 can still hold many rows, one for each source and series in +that period. The server also floors that period count at 1. If the minimum +page is still over 8 MiB, the read is incomplete. The message names the +read and, for timeseries, the resolution. It does not name a series type, +and it does not say one row was too large. Body and the personal record +have no limit. An oversized response fails that read and names the read. +Earlier committed pages stay. The pull does not drop a series, a segment, +or a location to stay under the cap. + +Device rows and other rows do not share a source. A device source uses the +2.1.0 sensor, `device_type|device|source`. Its receipt rules in section 3 +are unchanged. A row enters that source only when its `source` object has a +nonempty `device_id`, or when it is an id-less sleep or workout on a new +source with no history. A raw or day sample whose `source` object exists +and whose `device_id` is missing, null, or blank is `left_out`. The reason +is the missing device id. No id is copied from another row. + +A summary built without `device_id` uses a different sensor, +`summary:{family}:{provider}:{device}:{device_type}:{source}`. A missing +part is `-`. Sleep, activity, recovery, and body summaries use that sensor. +The builders in `summaries_service.py` omit `device_id`. Body's `source` +is the newest slow-changing measurement's provider, writer, model, and +type. The service discards provider and device on the latest readings. +That object is the response's umbrella source. It is not the author of +every field, and it is not a device receipt. A meal or cycle with no +`device_id` uses `event:{family}:{provider}:{device}:{device_type}:{source}`. +A meal or cycle that has a `device_id` uses the device source. A timeseries +or score with `source: null` uses +`unattributed:{resource}:{author}`. A health score's sensor is +`score:{author}`, where `{author}` is the top-level `provider`, or `-` +when that field is null. The score's `source` is the input object. It is +stored on the record and does not choose the sensor. + +These sensors do not establish `device_binding`. Their history is not +history of the device source. A summary stored first does not block a +later raw page from binding its own device source. A bound device source +does not reject a later summary. Preview memory is kept per sensor. A +refused device page rolls back only that page. + +Match keys stay D181 for the existing raw points, the raw `vo2_max` +summary, and the raw `garmin_stress_level` and `garmin_body_battery` +scores. A day row adds `1day` and `period_end` to its key, so it does not +replace the raw row. A summary field's key is the writer, the summary +sensor, the family, the `date`, and the field path. A meal, cycle, or +score uses the server id. Two meals at one timestamp stay two records. +Two metrics on one date stay two records. A body field's key is the +writer, the body sensor, the group, and the field path. It has no +requested date. A later snapshot revises that record. `received_at` stays +the time this program stored the revision. It is not the measurement time. +The personal record's key is the writer, its sensor, and `personal_record`. +The athlete profile is not changed. Birth date, gender, and sex do not fit +that profile: it has a birth year, a two-value sex, and no source. + +The original server object is stored on one anchor record, in +`supplied_fields`, including nulls, text, booleans, codes, and nested +objects. A normalized number is a second record. Its `supplied_fields` +hold the leaf it came from, including that leaf's unit. Transport through +this API is not by itself evidence the value was measured (D161). The +classes are: + +- A raw point the 2.1.0 file already stores stays that point. The lines + are RMSSD, SDNN, resting heart rate, respiratory rate, skin temperature, + blood oxygen, and one-minute heart-rate recovery. Apple skin temperature + stays `wrist_temperature_sleeping` when the writer is `apple`. +- Raw `vo2_max` stays `provider_summary.vo2_max`. Raw + `garmin_stress_level` stays a provider score on scale `1-100`. Raw + `garmin_body_battery` stays a provider score on scale `0-100`. Body + battery is not a sample. +- These raw series are points because Athletic Standard already has one + quantity for each, and the original series name stays in + `supplied_fields`: `walking_heart_rate`, `body_temperature`, `height`, + `weight` as `body_weight`, `body_fat_percentage`, `lean_body_mass`, + `blood_pressure_systolic`, and `blood_pressure_diastolic`. +- The other raw series readings are measurement samples. The appendix + lists all 71. The number is unchanged. The unit is the server unit, + using the existing conversions `percent` to `%`, `celsius` to `°C`, + `degrees` to `deg`, and `brpm`, `bpm`, `ms`, and `m` unchanged. A new + series quantity uses the server's unit string when no conversion exists. + Latitude and longitude are samples. A negative coordinate stays negative. + `heart_rate` is a sample. It is not a point. Integer `window_seconds` + sets `duration_ms` to that count times 1000, and the original field + stays. +- Dietary series, and `number_of_alcoholic_beverages`, are reported + intake. Each is a provider summary at the sample time. The summary type + is the series name. They are not nutrition entries and not samples. +- These raw series are provider summaries, not samples: + `peripheral_perfusion_index`, `breathing_disturbance_index`, + `body_mass_index`, `cardiovascular_age`, `workout_effort_score`, + `estimated_workout_effort_score`, `garmin_fitness_age`, + `withings_metabolic_age`, and `nike_fuel`. The estimated effort score + keeps that name. Its basis is omitted. It is not relabeled as measured. +- A day row uses the same class, with the window below. The two Garmin + scores stay scores. A day row of a point series is a provider summary, + not a point. `vo2_max` on a day row is a window summary. Its key is not + the raw `vo2_max` key. + +`computed_by: provider` sets basis `provider`. `computed_by: +open_wearables` sets basis `aggregator`. `computed_by: null` omits the +basis and keeps the null. A raw row has no `computed_by`. Its basis stays +`provider_or_aggregator`. A health score with top-level `provider: +internal` has basis `aggregator`. That score was computed by Open +Wearables. A vendor name in that field has basis `provider`. A null +`provider` omits the basis. The writer field on the device sensor is not +this author. + +A health score with a finite range in `constants/health_scores.py` is a +provider score. The scale text is `{min}-{max}`. The unit is `score` when +the number is present. Polar readiness is `0-10`. Polar recovery is `1-6`. +WHOOP strain is `0-21`. Sleep, and WHOOP recovery, are `0-100` only for +the provider entries in that table. Polar strain has no finite maximum, so +it is not given a scale. A category or provider missing from the table is +not given `0-100`. That score is a provider summary with no numeric +`value`. The number, qualifier, components, and `event_record_id` stay on +the anchor. A null score value uses the same kind as a present value for +that provider and category, with `value` and unit both absent. Components +are not turned into extra scores. RMSSD and SDNN stay separate names. +`RecoverySummary.recovery_score` is a deprecated 0 to 100 field. A present +number is a provider score on scale `0-100`. A null is only the anchor's +original object. + +WHOOP recovery components can include `skin_temp_celsius`. The health-score +object keeps that component. `RecoverySummary` has no skin-temperature +field. Its class ends at `recovery_score`. Its `avg_hrv_sdnn_ms` text says +current rows are null because they come from WHOOP and that HRV is RMSSD. +A non-null SDNN is stored. RMSSD is not copied into it. The body snapshot +does not fill historical temperature. + +Sleep summary `start_time` and `end_time` are the longest main sleep when +one exists, and otherwise the service's minimum start and maximum end. +Those bounds are the period `open_wearables_main_sleep` only for +`duration_minutes`, `time_in_bed_minutes`, `efficiency_percent`, the stage +minutes, and `interruptions_count`. `total_duration_minutes`, nap count, +nap duration, the session list, and the heart-rate, HRV, respiration, and +blood-oxygen averages stay on `provider_date` alone. A nap outside the +main sleep does not inherit the main-sleep bounds. The session list stays +on the anchor. It does not become extra sleep sessions. The service can +add a missing main duration as zero when it builds +`total_duration_minutes`. This program stores the returned number and the +original. It does not turn a null into zero, and it does not reverse the +server's sum. + +Activity fields are date-only. `floors_climbed` is described as calculated +from elevation. `total_calories_kcal` can be the provider total or the sum +of active and basal energy. The response does not say which. The basis +stays `provider_or_aggregator`. Intensity minutes can be returned as zero +where the service fills a missing key with zero. A returned zero stays +zero. + +Body is one current snapshot. `range_complete` does not treat it as the +requested dates. `slow_changing` has weight, height, fat, muscle, BMI, and +age, and no measurement time. Those values use +`input_timestamp.timestamp_missing_reason: not_provided_by_source`. They +have no `recorded_at` and no reporting period. The average window is not +borrowed, and the pull time is not written as the measurement time. Age is +basis `aggregator` because the service calculates it from the birth date +and the server clock. BMI is not called measured. The response does not +say whether that BMI was stored or calculated, so its basis is omitted. +`averaged` uses the server's `period_start` and `period_end`. Those bounds +are the current averaging window, computed from `datetime.now` in the +service. They are not applied to `slow_changing` or `latest`. Each latest +field uses its own time: `body_temperature_measured_at`, +`skin_temperature_measured_at`, or `blood_pressure_measured_at`. A value +with a null time uses the same time-unknown receipt. The three groups can +be stored together or alone. A null group stores no field records. The +anchor still holds the object. + +A meal's calories, macros, water, and `nutrients` entries are provider +summaries at the meal timestamp. A nutrient uses the value and unit on +that entry. The name, meal type, and full nutrient map stay on the anchor. +A meal with no numbers is the anchor only. A cycle's reported lengths are +provider summaries on the cycle's start and end. `current_phase` is a +code. `predicted_cycle_length` and `is_predicted_cycle` stay on the +anchor, as do booleans, text, and `pregnancy_snapshot`. They are not +turned into measurements. Workout numbers that are not already typed stay +on the workout as source-reported summaries, and the original fields stay. +`intensity` stays under that name. It is not a sample. Segments stay under +`segments`. A segment with a label is also a typed segment. A missing +label is not filled in. Zones stay under the server's names. A workout +with `entry_source` `manual` is left out. + +A provider summary or provider score may omit `value` only together with +its unit. One without the other is refused. Step 5 rebuilds both typed +tables so the pair can be null, copies every existing row, and keeps +record ids, `data_json`, import keys, revisions, tombstones, and reporting +periods. Scale on a provider score stays required. No number is invented. +The time-unknown summary is valid only with the missing-timestamp reason +above. A summary that has a server time uses that time. The following are not requested. Each line is the reason. -- Resolutions `1min`, `5min`, `15min`, and `1hour`. `_aggregated_timeseries` - builds those buckets from raw samples when the query runs. The raw - samples are stored. -- Resolutions `1week` and `1month`. `_period_timeseries` builds them from - day rows and sets `computed_by` to `open_wearables`. The day rows are - stored. -- Sleep totals, workout totals, and activity totals. The route text says - they add up the same rows the corresponding list returns. +- Resolutions `1min`, `5min`, `15min`, and `1hour`. They are buckets built + at query time from raw samples. The raw samples are stored. +- Resolutions `1week` and `1month`. They are built from day rows. The day + rows are stored. +- Sleep totals, workout totals, and activity totals. They add up rows the + lists return. - The data summary and the data timeline. They count stored rows. -- The personal-record route. Its fields are birth date, gender, and sex. -- The provider workout list and the provider workout detail. Those routes - read the vendor through the server's live connection. This pull keeps - the stored workout, including segments. +- The provider workout list and detail. They call the vendor through the + server's live connection. This pull keeps the stored workout. - Accounts, connections, sync, OAuth, webhooks, API keys, config, uploads, - and every `DELETE`. They are not measurements. The API key, the server - address, and the user id are not written into the athlete record. -- A workout with `entry_source` `manual`. The server describes it as a - self-reported entry with no device measurement. The measured record does - not take it. - -`RecoverySummary` at this commit has no skin-temperature field. The class -ends at `recovery_score`. Skin temperature is stored from a timeseries row -or from `BodyLatest.skin_temperature_celsius` when the server sends one. -The recovery field `avg_hrv_sdnn_ms` is in the schema. Its text says the -value is null for the rows that endpoint returns today, because those rows -come from WHOOP and WHOOP's HRV on that object is RMSSD. A non-null SDNN -is stored. RMSSD is not written into the SDNN field. - -A raw page and a day page are separate reads. Each page is one transaction -(D201). The body cap stays 8 MiB. A larger response is not mapped. The -same query is sent again with `limit` cut in half, down to 1. A transport -failure is not retried. One row that is itself larger than 8 MiB cannot -be stored. That read stays incomplete, and the message names the series -type. The pull does not drop a series to stay under the cap. - -The result separates four facts. The server returned no row. The server -sent null. The row was stored. The server returned a row and the mapping -refused it. `left_out` counts only the last fact. A missing series is not -reported as zero. - -`source.provider` is the Open Wearables integration name. `source.source` is -the writer inside that integration. The mapping's `writer_field` is a -convention. It is not proof that the device vendor computed the value. The -basis is `provider_or_aggregator` when the server does not say who computed -the number, `provider` when `computed_by` is `provider` or the record is a -provider score, and `aggregator` when `computed_by` is `open_wearables`. -A raw sample on 0.11.0 is built without `computed_by`. That absence stays -`provider_or_aggregator`. Workout fields may be filled by Open Wearables -and have no per-field `computed_by` on the workout object. The original -`computed_by` string, when the server sent it, stays in `supplied_fields`. + and every `DELETE`. They are not health readings. The API key, the + server address, and the user id are not written into the athlete record. + +Day rows are one selected row per source, series, and local day. The +repository prefers `computed_by: provider`, then the later provider row. +With the sample fallback on, a missing day can be computed while reading. +The returned `timestamp` and `period_end` come from `CalendarPeriod`, not +from the provider interval that was stored. `stats` and `computed_by` are +kept. They are the server's window receipt, not the original provider +period. ## 3. How a response becomes records @@ -313,11 +466,12 @@ call. A resolved file that does not implement section 2 also fails before any request. An installed 2.1.0 copy still wins under D179, and this check stops it from quietly dropping the rows section 2 stores. -For each page of sleep it calls `apply_mapping` with -`{ "sleep": }`. For each page of workouts it uses `workout`. -For each timeseries page it passes the response object unchanged. Pagination -is not a record. Sleep and workout `metadata` is not a record. Timeseries -`metadata.resolution` stays, because the mapping file requires it. +File import and pull use the same envelopes. A cursor or offset page passes +its `data` array to the section named in the mapping file. A timeseries +page passes the response object, because `metadata.resolution` is required. +Body passes the object. JSON `null` is not mapped. The personal record +passes the object after `user_id` is removed. Pagination and health-score +`metadata` are not records. Everything after that is the mapping engine from 2.1.0: match keys (D181), replace on change (D182), source and device (D183), one transaction per call @@ -327,8 +481,10 @@ are empty or `__proto__` (D191). A Garmin file import remains a different same Open Wearables object, or an `ath import --mapping open-wearables` of a saved copy of that object, updates the same rows. -The writer is `source.provider`. The sensor string is `source.device_type`, -`source.device`, and `source.source`. Two devices with different triples are +On a device source, the writer is `source.provider`. The sensor string is +`source.device_type`, `source.device`, and `source.source`. Section 2's +other sensors are different sources. They do not enter the device check. +Two devices with different triples are two sources and two baselines. Two devices that share the triple share one source and one baseline. `source.device_id` is copied to `source_device.hardware`. It does not split the source, and it is not part of the match key (D181, @@ -361,17 +517,17 @@ are not rewritten, moved, or deleted. Both `ath import --mapping` and `ath pull` call `apply_mapping`. The check lives there, for route `open_wearables` only, inside the same transaction -as the write and before `insert_group` changes a source device or a -timeseries record, including a measurement sample and a window summary. -Other routes are not checked. A pull-only check would +as the write and before `insert_group` changes a device source or a +timeseries record on that source. Summary, event, score, and unattributed +sensors do not enter it. Other routes are not checked. A pull-only check would leave import-after-pull able to replace the point. The check reads every accepted row, including a row after the first source device. The receipt is the source object's own key `device_binding`. The 2.2.0 source schema makes it an optional nonempty string. D185 keeps `supplied_fields` for names the source sent, so the receipt is a sibling of -that object, as `field_basis` is a sibling on a measured record. Step 5 -adds no column, copies no field, and rewrites no record. A source migrated +that object, as `field_basis` is a sibling on a measured record. The +receipt adds no column and copies no field onto old sources. A source migrated from 2.1.0 has no `device_binding` key. A string already stored at `supplied_fields.device_binding` stays in `supplied_fields`. Migration does not treat it as the receipt. Renaming that supplied name would still leave @@ -433,12 +589,14 @@ call is one of these states: A second device is refused rather than merged. On `--yes`, an earlier committed page stays, the failed page makes no database changes, the range is not complete, and the exit is nonzero. File import rolls back the whole -call. `--json` and `--json --yes` make no database changes. The queries in -D201 still ask for every device. - -Preview keeps two facts in memory for this command: the binding it would -have stored, and an unbound source it would have created once that source -has accepted history. A later preview page uses those facts, including a +call. `--json` and `--json --yes` make no database changes. Device reads +that have `filter_by_priority` send `false`. Summary routes have no such +switch. Section 2 states that limit. + +Preview keeps two facts in memory for this command, for each source sensor: +the binding it would have stored, and an unbound source it would have +created once that source has accepted history. A summary sensor does not +supply a binding for the device sensor. A later preview page uses those facts, including a later page that adds an id after an id-less sleep page. The memory is discarded with the process. It does not change the estimated record counts. A second command reads the committed source inside its own `BEGIN IMMEDIATE` @@ -472,7 +630,7 @@ connection. A later `revise` cannot fill the receipt in, because that patch is refused. `store.rs` therefore gains three source operations besides the `revise` -rule above. It gains nothing else: +rule above, and the typed writes in section 6. It gains nothing beyond those: - Read the committed receipt, and whether any record or source device for that source exists, including a deleted row. @@ -502,8 +660,10 @@ built without that field. Day rows carry it, and those rows are stored. ## 4. Credentials, privacy, and the network D200 is the rule. The key never enters the athlete database, the export, the -preview, or an error line. The pull reads only the paths in D201 and D203. -It does not list users and does not read the personal record. +preview, or an error line. The pull reads only the paths in section 2. +It does not list users. The personal-record object includes `user_id`. +That field is removed before the scan below and is not stored. Birth date, +gender, and sex are stored. They are account health data, not the API key. The process refuses a base URL that could carry the key in the URL itself. It refuses plain `http` except to loopback. It does not follow a redirect, so @@ -514,7 +674,9 @@ the key cannot be sent to a second host. One attempt, then stop. Timeouts are The body is read inside that cap and parsed before any `apply_mapping` call. The guard is in `open_wearables.rs`. It walks every decoded object key and every decoded string. A value that contains the API key, the selected -origin, or the selected user id rejects the whole page. The page is not +origin, or the selected user id rejects the whole page. The removed +personal-record `user_id` is the only field that is dropped before this +walk. Any other copy of the user id still rejects the page. The page is not rewritten and it is not mapped. A Unicode escape such as `\u0073` is visible only after parsing, so a scan of the raw text is not enough. The raw-text scan still runs on a body that did not parse, and the parent still refuses @@ -542,8 +704,10 @@ reads in section 2, no user list. The build sets `2.2.0` on the package, the record, and `ath-core`, by the same constants 2.1.0 moved. Migration step 5 is a new SQL file. It updates `athleticstandard_version` to `2.2.0` and `sql_schema_version` to 5. No column -is added. The same file rebuilds `provider_summaries` as section 2 describes -and copies existing rows. Step 4 and file `004` are not edited (D165). +is added. The same file rebuilds `provider_summaries` and `provider_scores` +as section 2 describes and copies existing rows, including deleted rows. +Record ids, revisions, import keys, and reporting-period rows stay. Step 4 +and file `004` are not edited (D165). A new database runs that step 5 SQL after step 4 and before the `user_version` pragma, inside `installInitialSchema`. `applyMigrationStep` gains an arm for @@ -562,11 +726,14 @@ would make a 1.0.0 database unloadable, so migrate could not open it. The build generates `schema/2.2.0/` and does not rewrite `schema/2.1.0/` or `schema/2.0.0/`. The 2.2.0 source object gains optional `device_binding`. -`ProviderReportingPeriodType` gains `open_wearables_reporting_window`. -`ValueBasis` gains `aggregator`. Series quantities gain one entry for each -pinned series type that does not already have a point or series quantity. -`provider_summary.value` may be omitted, as section 2 says. No other field -is added. The folder exists so the package version and the schema path +`ProviderReportingPeriodType` gains `open_wearables_reporting_window` and +`open_wearables_main_sleep`. `ValueBasis` gains `aggregator`. Series +quantities gain the sample series in section 2, not the intake, index, age, +or effort series. `provider_summary.value` and `provider_score.value` may +be omitted together with the unit, as section 2 says. A provider summary +may also omit `recorded_at` and reporting periods when its input timestamp +uses `not_provided_by_source`. No other field is added. The folder exists +so the package version and the schema path stay aligned. The demo athlete is regenerated because the stored version is inside it. `examples/demo-athlete/athlete.ath.json` stays the legacy 0.4.3 file. `tests/fixtures/version-2-0-0/` is not @@ -599,6 +766,7 @@ interactive open can preview, back up, ask, and then migrate. | Stored records | the existing store and mapping engine | | Keep `device_binding` on a partial source update | `Store::revise` in `crates/ath-core/src/store.rs`, sources only | | Read receipt and tombstone history; create or first-bind with the checked receipt | three source operations in `store.rs`, inside the caller's transaction | +| Measurement samples; paired null value and unit on summaries and scores | `insert_typed`, `update_typed`, and `typed_table` in `store.rs`; the same pair in `src/db/records.ts`, `src/db/import-package.ts`, `src/db/records-view.ts`, and the repair copy from `data_json` | | Whole source record from the owner | existing `ath correct`, package restore, and an accepted package merge | `store.rs`, `persist.rs`, and `personal.rs` are not the home for this client. @@ -616,7 +784,12 @@ measurement-sample target, the reporting-window write, and the segment copy from section 2. HTTP stays out of `mapping.rs`. `store.rs` keeps the `revise` refusal and adds the three source operations in section 3: the receipt and tombstone read, creation with the checked receipt, and a -first bind on an existing source that has no history. `ath correct`, +first bind on an existing source that has no history. It also inserts and +updates `measurement_sample`, and it accepts a provider summary or provider +score whose `value` and unit are both present or both absent. A half-null +pair is refused. `src/db/records.ts`, `src/db/import-package.ts`, +`src/db/records-view.ts`, and the repair copy from `data_json` follow that +pair. No other store behavior changes. `ath correct`, package restore, and an accepted package merge stay whole-record owner writes. They are named in section 3 so the binding survives a 2.2.0 round trip. They are not a new importer. The pull sums only `sleep_session`, `workout_session`, @@ -667,8 +840,8 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: - the same session id on two pages, changed payload: the preview estimate counts two new rows, and `--yes` counts one new and one changed - a valid page, then a failing page, under `--yes`. The failure is one of a - 401, a 429, a repeated or null cursor, an invalid row, or a body over - 8 MiB. Page 1 remains. Page 2 adds no rows and no revisions. No later read + 401, a 429, a repeated or null cursor, an invalid row, or a minimum page + that is still over 8 MiB. Page 1 remains. Page 2 adds no rows and no revisions. No later read runs. The exit is nonzero. The success sentence is absent. The text gives the retained counts. The same command run again stores no second copy - the same failure sequence with no `--yes`, and again with `--json --yes`, @@ -678,9 +851,12 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: - an installed mapping that does not implement section 2 fails before any request. The server sees no request. Raw and day timeseries requests omit `types`. A comma-joined type string is not sent -- a missing object, a `data` value that is not an array, a missing - pagination object, or a `has_more` value that is not a boolean fails the - page before `apply_mapping`. It is not an empty success +- a cursor or offset page fails before `apply_mapping` when the object is + missing, `data` is not an array, `pagination` is missing, or `has_more` + is not a boolean. That failure is not an empty success. A body response + of JSON `null` is a completed empty snapshot and writes nothing. A body + object is mapped. A health-score page ends on `has_more: false`, and a + smaller retry uses the same offset - `filter_by_priority=false` is present on the reads that have the flag. Raw timeseries sends `resolution=raw`. Day timeseries sends `resolution=1day`. Sleep sends `include=stages`. Workouts send @@ -692,23 +868,63 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: segment that has a label is also a typed segment - a raw `heart_rate` row becomes a measurement sample in bpm at the server's timestamp. Export and import keep that timestamp, unit, and - value. A day row for resting heart rate, RMSSD, SDNN, blood oxygen, and - VO2 max becomes a provider summary with - `open_wearables_reporting_window`, no `recorded_at`, and the server's - `timestamp` and `period_end`. A null RMSSD beside a present SDNN stores - only the SDNN. A sleep summary respiratory rate is stored, and the sleep - session from the same night still has no respiration field. Skin - temperature is stored from a series row or from body latest. A recovery - object with no skin-temperature field does not gain one. `page-5min.json` - is left out, and the reason says it is a query bucket. RMSSD and SDNN - stay different quantities. A 2.1.0 raw point and a pull of that same raw - point through the new mapping stay one record. A heart-rate sample from - device B does not replace device A's sample -- a response larger than 8 MiB is requested again with a smaller limit, and - the rows are stored. One row larger than 8 MiB leaves that read - incomplete and names the series type. The personal-record route is not - requested. The export after a pull and a package import contains the - period bounds, the units, `computed_by`, and the segment objects + value. A day row for resting heart rate, RMSSD, SDNN, and blood oxygen + becomes a provider summary with `open_wearables_reporting_window`, no + `recorded_at`, and the server's `timestamp` and `period_end`. Raw + `vo2_max` stays `provider_summary.vo2_max` on its 2.1.0 key. A day + `vo2_max` row is a different window summary. Raw `garmin_stress_level` + and `garmin_body_battery` stay provider scores on their existing scales + and keys. They do not become samples. A null RMSSD beside a present SDNN + stores only the SDNN. A sleep-summary respiratory rate is date-only. The + sleep session from the same night still has no respiration field. Nap + totals do not receive the main-sleep bounds. Skin temperature is stored + from a series row or from body latest when that time is present. A + recovery object does not gain a skin field. A WHOOP health-score + component named `skin_temp_celsius` stays on that object. + `page-5min.json` is left out as a query bucket. A 2.1.0 raw point and a + pull of that same raw point stay one record. A heart-rate sample from + device B does not replace device A's sample. A negative latitude and a + negative longitude are stored +- a response larger than 8 MiB on a cursor or offset read is requested + again with a smaller limit, the same cursor or offset, and the rows are + stored. A day page at `limit` 1 that holds many small rows and is still + over 8 MiB leaves that read incomplete and names the read and + `resolution=1day`. It does not name a series type. An oversized body + response names `body` and writes nothing. The export after a pull, and a + native package import, keep period bounds, units, `computed_by`, + segments, score components, meal nutrients, and a pregnancy snapshot +- a summary shaped like `summaries_service.py`, with no `device_id`, is + stored after a bound raw page. The device receipt and the device's + points stay. The same summary stored first does not block a later raw + page from binding its device source. File import then pull, pull then + file import, and import then import keep one summary id. A refused + device page rolls back only that page. Two meals with one timestamp and + different ids stay two records. Two summary fields on one date stay two + records. A timeseries row with a source and no `device_id` is `left_out`. + A timeseries row with `source: null` is stored on the unattributed sensor +- an internal health score has basis `aggregator`. A vendor score has + basis `provider`. A null `provider` omits the basis. Polar readiness uses + scale `0-10`, Polar recovery uses `1-6`, and WHOOP strain uses `0-21`. + A score with no finite range keeps its number on the anchor and does not + use scale `0-100`. A null value and a later number revise the same + record. `computed_by: null` omits the basis and keeps the null +- body fetched during a historical range is the current object. Weight + with no time has no `recorded_at` and does not use the average window. + A latest value with a null time is stored the same way. Age has basis + `aggregator`. BMI's basis is omitted. The three groups can arrive + together or alone. JSON null and a returned zero and a missing field + stay three different results +- a dietary series is a provider summary, not a sample and not a nutrition + entry. A cycle code, a predicted length, and a pregnancy snapshot stay + on the anchor. A cycle that starts in range and ends later keeps that + end. A cycle that starts later is not stored, and the read can still + complete. Birth date, gender, and sex are stored. `user_id` is not. + The athlete profile is unchanged +- step 5 keeps an old summary's id, number, unit, `data_json`, import key, + revisions, and tombstone. A numeric summary can be corrected to + numberless and back. A half-null value and unit is refused. A sample + repeats and corrects. `ath check`, export, native import, and restore + accept the numberless summary and the sample - two distinct sensor triples become two sources. Device A is stored, then a separate operation contains only device B at the same triple, type, and instant, with a different value. The operation fails. The current point, @@ -835,12 +1051,13 @@ the fixture key once into `ath key set openwearables`. command saves the fixture key, and the key is not on screen. Failure: init fails, or the key is printed. 2. Preview. Success: the pull without `--yes` says nothing is stored, shows - estimated counts that include a heart-rate sample and a day summary, and - `ath check` still passes. Failure: a row is written, or the key appears. + estimated counts that include a heart-rate sample and a day summary, shows + a body snapshot line, and `ath check` still passes. Failure: a row is + written, or the key appears. 3. Write. Success: the same command with `--yes` says the requested range is - complete, shows committed counts, and `ath check` exits 0. Failure: the - success sentence appears while the range is incomplete, or `ath check` - fails. + complete, shows the body snapshot line, shows committed counts, and + `ath check` exits 0. Failure: the success sentence appears while the + range is incomplete, or `ath check` fails. 4. Repeat. Success: `--yes` again reports the stored rows unchanged. Failure: a second copy of a sleep session or a point appears. 5. Compatibility. Success: one synthetic Apple, WHOOP, or Oura import still @@ -871,8 +1088,8 @@ is in the build pull request. - `store.rs` and `mapping.rs` are past a thousand lines. The pull does not add HTTP to them. `mapping.rs` gains the counts, the open-wearables binding check, and the preservation writes in section 2. `store.rs` gains the - partial-update refusal and the three source operations in section 3. - Splitting the files stays out. + partial-update refusal, the three source operations in section 3, and the + sample and paired-null writes in section 6. Splitting the files stays out. - `persist.rs` can still store a supplied field named `__proto__` if a caller uses `ath-core persist` directly. The pull does not use that path. - The mapping path rule is already one function. There is no duplicate to @@ -900,9 +1117,9 @@ Risks: rate-limit middleware. - Date-only bounds mean whatever Open Wearables decides. The docs and the 0.11.0 parser disagree about UTC. This release does not correct that server. -- Section 2 stores the server's periods and series. It does not invent a - midnight. A provider that never sent a value still has a gap. The device - receipt is a separate rule. +- Section 2 stores returned periods, series, and snapshots. It does not + invent a measurement time. A null stays null. A row the server did not + return stays unknown. The device receipt is a separate rule. - Fields on a sleep or workout object that the mapping does not consume are stored under the server's names. Latitude and longitude are stored when the server sends them. @@ -911,30 +1128,31 @@ Risks: is to avoid copying the key into the record. The build, after approval, is one pull request in this order. First the -schema and step 5: the period type, the `aggregator` basis, the series -quantities, and the nullable provider-summary value. Then the mapping -engine and `mappings/open-wearables.md`. Then the reads, the smaller-page -split, and the tests in section 7. The laptop card and the phone proof are +schema and step 5: the period types, the `aggregator` basis, the sample +series quantities, the paired null value and unit, and the time-unknown +summary. Then the store and record paths in section 6. Then the mapping +engine and `mappings/open-wearables.md`. Then the reads, the cycle filter, +the smaller-page split, and the tests in section 7. The laptop card and the phone proof are part of that same pull request. This plan pull request has no media. The maintainer approves or rejects this plan before any build. D198 through -D203 are the proposal. They are not adopted. Reviews of commit `d1fdde1` -were incorporated here. The re-reviews of `1124e56`, `da006a6`, and -`c9ca93a` are incorporated here. None of those reviews approves this -revision. The next head needs re-review. An earlier review accepted a +D204 are the proposal. They are not adopted. Reviews of earlier heads were +incorporated here. None of those reviews approves this revision. The next +head needs re-review. An earlier review accepted a migration with no new column, under D152 and D184. That acceptance does not adopt D198. The optional source key adds no column. 1. One number, 2.2.0. Readable sets keep `1.0.0`. Step 5 runs on create and on migrate. The device receipt adds no column. Step 5 does rebuild - `provider_summaries` so a summary of an object with no number can omit - `value`. A `2.1.0` database does not open until `ath migrate`. This - release does not schedule, refresh a token, backfill, or store a cursor - (D198, D203). -2. Store the Open Wearables measurements in section 2. Periods keep the - server's bounds. Series keep the server's numbers and units. Null stays - null. The omissions in section 2 are the ones with a reason (D203). + `provider_summaries` and `provider_scores` so a numberless object can omit + `value` and its unit together. Existing ids and rows are copied. A + `2.1.0` database does not open until `ath migrate`. This release does + not schedule, refresh a token, backfill, or store a cursor (D198, D204). +2. Store the returned representations in section 2. Device receipts stay + on device sources. Summaries without a device id use their own sensors. + Null stays null. A missing response is not called provider-unavailable. + The omissions in section 2 are the ones with a reason (D203, D204). 3. The key, the selected origin, and the selected user id are rejected in decoded JSON before a page is mapped. Failure text uses a fixed sentence. `ath key clear` with no name still clears only the gateway keys and says @@ -958,4 +1176,5 @@ optional source key adds no column. check, and the preservation writes in section 2. `store.rs` gains the partial-update refusal, the receipt and tombstone read, creation with the checked receipt, and the first bind of an existing source that has - no history. Nothing else is added to either file (D202, D203). + no history, and the sample and paired-null writes in section 6. + Nothing else is added to either file (D202, D204). From 1251ac084068bb42d322c6cb8685bd7bec03076e Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 7 Nov 2026 03:25:30 +0000 Subject: [PATCH 08/60] Correct the 2.2.0 unit, window, identity, and report contracts. Day rows stay reporting windows, sleep sums stay date-scoped, and reported intake, accounts, and manual workouts use a non-measured source report. Co-authored-by: Michael Whitham --- .../v2.2.0/appendix/open-wearables-api.md | 212 +++++-- build-history/v2.2.0/decisions.md | 137 ++++- build-history/v2.2.0/progress.md | 6 +- build-history/v2.2.0/spec.md | 578 ++++++++++-------- 4 files changed, 629 insertions(+), 304 deletions(-) diff --git a/build-history/v2.2.0/appendix/open-wearables-api.md b/build-history/v2.2.0/appendix/open-wearables-api.md index d96bb5c6..1fcdf262 100644 --- a/build-history/v2.2.0/appendix/open-wearables-api.md +++ b/build-history/v2.2.0/appendix/open-wearables-api.md @@ -198,7 +198,7 @@ route files. A limit may still exist in middleware this study did not open. The same commit, `183e8cc4f6de897dbd288c93d49a691f2cf721ae`, was read again for every user data route. The OpenAPI file is `docs/openapi.json`, -`info.version` `0.11.0`. The storage rule is D203. This section records +`info.version` `0.11.0`. The storage rule is D205. This section records what the source shows. `SeriesType` is the enum in `backend/app/schemas/enums/series_types.py`. @@ -245,7 +245,7 @@ listed rows. The personal-record response fields are `birth_date`, ## Contract read on 7 November 2026 The same commit was read again for the summary, score, meal, cycle, body, -and personal-record contracts. D204 is the storage rule. This section +and personal-record contracts. D205 is the storage rule. This section records the source facts that rule uses. `SERIES_TYPE_DEFINITIONS` has 141 entries. @@ -255,49 +255,162 @@ series are `heart_rate_variability_rmssd`, `heart_rate_variability_sdnn`, `oxygen_saturation`, `heart_rate_recovery_one_minute`, `vo2_max`, `garmin_stress_level`, and `garmin_body_battery`. -These raw series become points because one existing quantity fits each of -them: `walking_heart_rate`, `body_temperature`, `height`, `weight`, -`body_fat_percentage`, `lean_body_mass`, `blood_pressure_systolic`, and -`blood_pressure_diastolic`. `weight` is stored as `body_weight`. The -series name stays in `supplied_fields`. - -These raw series are provider summaries, not samples: -`peripheral_perfusion_index`, `breathing_disturbance_index`, -`body_mass_index`, `cardiovascular_age`, `workout_effort_score`, -`estimated_workout_effort_score`, `garmin_fitness_age`, -`withings_metabolic_age`, and `nike_fuel`. - -Reported intake is every `dietary_*` series and -`number_of_alcoholic_beverages`. There are 42 `dietary_*` series. They are -provider summaries. - -The remaining 71 raw series are measurement samples: - -`heart_rate`, `blood_glucose`, `sleeping_breathing_disturbances`, -`blood_alcohol_content`, `forced_vital_capacity`, -`forced_expiratory_volume_1`, `peak_expiratory_flow_rate`, -`waist_circumference`, `body_fat_mass`, `skeletal_muscle_mass`, -`skin_temperature_deviation`, `skin_temperature_trend_deviation`, -`bone_mass`, `body_water_mass`, `six_minute_walk_test_distance`, `steps`, -`active_energy`, `basal_energy`, `stand_time`, `exercise_time`, -`physical_effort`, `flights_climbed`, `active_time`, `total_energy`, -`distance_walking_running`, `distance_cycling`, `distance_swimming`, -`distance_downhill_snow_sports`, `distance_other`, `walking_step_length`, -`walking_speed`, `walking_double_support_percentage`, -`walking_asymmetry_percentage`, `walking_steadiness`, -`stair_descent_speed`, `stair_ascent_speed`, `running_power`, -`running_speed`, `running_vertical_oscillation`, -`running_ground_contact_time`, `running_stride_length`, -`running_vertical_ratio`, `running_stance_time_balance`, -`swimming_stroke_count`, `underwater_depth`, `cadence`, `power`, `speed`, -`distance`, `elevation_gain`, `environmental_audio_exposure`, -`headphone_audio_exposure`, `environmental_sound_reduction`, -`time_in_daylight`, `water_temperature`, `uv_exposure`, `inhaler_usage`, -`weather_temperature`, `weather_humidity`, `elevation`, `latitude`, -`longitude`, `air_temperature`, `garmin_skin_temperature`, -`withings_pulse_wave_velocity`, `electrodermal_activity`, `push_count`, -`atrial_fibrillation_burden`, `insulin_delivery`, -`number_of_times_fallen`, and `hydration`. +The table below is the mapping for all 141 series. D205 is the storage rule. +`input_value` and the input unit are the server's number and unit. +`standard_value` equals `input_value` except where the conversion is +`divide by 100`. A day row uses the day record in the last column. It is +never a measurement sample. Apple skin temperature stays +`wrist_temperature_sleeping` when the writer is `apple`. `weight` is stored +as `body_weight`. The series name stays in `supplied_fields`. + +Sleep summary numbers in `event_record_repository.py` sum every non-nap +session in the source and date. The summary service sets `start_time` and +`end_time` from the longest main sleep. Those bounds stay on the original +object. They are not the period of the summed fields. + +| Series | Input unit | Raw class | Target | Standard unit | Conversion | Day record | +|---|---|---|---|---|---|---| +| `heart_rate` | `bpm` | measurement_sample | `heart_rate` | `bpm` | unchanged | provider_summary window | +| `resting_heart_rate` | `bpm` | point | `resting_heart_rate` | `bpm` | unchanged | provider_summary window | +| `heart_rate_variability_sdnn` | `ms` | point | `hrv_sdnn` | `ms` | unchanged | provider_summary window | +| `heart_rate_recovery_one_minute` | `bpm` | point | `heart_rate_recovery_one_minute` | `bpm` | unchanged | provider_summary window | +| `walking_heart_rate` | `bpm` | point | `walking_heart_rate` | `bpm` | unchanged | provider_summary window | +| `heart_rate_variability_rmssd` | `ms` | point | `hrv_rmssd` | `ms` | unchanged | provider_summary window | +| `oxygen_saturation` | `percent` | point | `oxygen_saturation` | `%` | alias | provider_summary window | +| `blood_glucose` | `mg_dl` | measurement_sample | `blood_glucose` | `mg_dl` | unchanged | provider_summary window | +| `blood_pressure_systolic` | `mmHg` | point | `blood_pressure_systolic` | `mmHg` | unchanged | provider_summary window | +| `blood_pressure_diastolic` | `mmHg` | point | `blood_pressure_diastolic` | `mmHg` | unchanged | provider_summary window | +| `respiratory_rate` | `brpm` | point | `respiratory_rate` | `brpm` | unchanged | provider_summary window | +| `sleeping_breathing_disturbances` | `count` | measurement_sample | `sleeping_breathing_disturbances` | `count` | unchanged | provider_summary window | +| `blood_alcohol_content` | `mg_dl` | measurement_sample | `blood_alcohol_content` | `mg_dl` | unchanged | provider_summary window | +| `peripheral_perfusion_index` | `score` | source_report | `peripheral_perfusion_index` | `score` | unchanged | source_report window | +| `forced_vital_capacity` | `liters` | measurement_sample | `forced_vital_capacity` | `liters` | unchanged | provider_summary window | +| `forced_expiratory_volume_1` | `liters` | measurement_sample | `forced_expiratory_volume_1` | `liters` | unchanged | provider_summary window | +| `peak_expiratory_flow_rate` | `L/min` | measurement_sample | `peak_expiratory_flow_rate` | `L/min` | unchanged | provider_summary window | +| `breathing_disturbance_index` | `score` | source_report | `breathing_disturbance_index` | `score` | unchanged | source_report window | +| `height` | `cm` | point | `height` | `cm` | unchanged | provider_summary window | +| `weight` | `kg` | point | `body_weight` | `kg` | unchanged | provider_summary window | +| `body_fat_percentage` | `percent` | point | `body_fat_percentage` | `%` | alias | provider_summary window | +| `body_mass_index` | `kg_m2` | source_report | `body_mass_index` | `kg_m2` | unchanged | source_report window | +| `lean_body_mass` | `kg` | point | `lean_body_mass` | `kg` | unchanged | provider_summary window | +| `body_temperature` | `celsius` | point | `body_temperature` | `°C` | alias | provider_summary window | +| `skin_temperature` | `celsius` | point | `skin_temperature` | `°C` | alias | provider_summary window | +| `waist_circumference` | `cm` | measurement_sample | `waist_circumference` | `cm` | unchanged | provider_summary window | +| `body_fat_mass` | `kg` | measurement_sample | `body_fat_mass` | `kg` | unchanged | provider_summary window | +| `skeletal_muscle_mass` | `kg` | measurement_sample | `skeletal_muscle_mass` | `kg` | unchanged | provider_summary window | +| `skin_temperature_deviation` | `celsius` | measurement_sample | `skin_temperature_deviation` | `°C` | alias | provider_summary window | +| `skin_temperature_trend_deviation` | `celsius` | measurement_sample | `skin_temperature_trend_deviation` | `°C` | alias | provider_summary window | +| `bone_mass` | `kg` | measurement_sample | `bone_mass` | `kg` | unchanged | provider_summary window | +| `body_water_mass` | `kg` | measurement_sample | `body_water_mass` | `kg` | unchanged | provider_summary window | +| `vo2_max` | `ml_kg_min` | provider_summary | `vo2_max` | `ml/kg/min` | alias | provider_summary window | +| `six_minute_walk_test_distance` | `meters` | measurement_sample | `six_minute_walk_test_distance` | `m` | alias | provider_summary window | +| `cardiovascular_age` | `years` | source_report | `cardiovascular_age` | `years` | unchanged | source_report window | +| `steps` | `count` | measurement_sample | `steps` | `count` | unchanged | provider_summary window | +| `active_energy` | `kcal` | measurement_sample | `active_energy` | `kcal` | unchanged | provider_summary window | +| `basal_energy` | `kcal` | measurement_sample | `basal_energy` | `kcal` | unchanged | provider_summary window | +| `stand_time` | `minutes` | measurement_sample | `stand_time` | `min` | alias | provider_summary window | +| `exercise_time` | `minutes` | measurement_sample | `exercise_time` | `min` | alias | provider_summary window | +| `physical_effort` | `met` | measurement_sample | `physical_effort` | `MET` | alias | provider_summary window | +| `flights_climbed` | `count` | measurement_sample | `flights_climbed` | `count` | unchanged | provider_summary window | +| `active_time` | `minutes` | measurement_sample | `active_time` | `min` | alias | provider_summary window | +| `total_energy` | `kcal` | measurement_sample | `total_energy` | `kcal` | unchanged | provider_summary window | +| `distance_walking_running` | `meters` | measurement_sample | `distance_walking_running` | `m` | alias | provider_summary window | +| `distance_cycling` | `meters` | measurement_sample | `distance_cycling` | `m` | alias | provider_summary window | +| `distance_swimming` | `meters` | measurement_sample | `distance_swimming` | `m` | alias | provider_summary window | +| `distance_downhill_snow_sports` | `meters` | measurement_sample | `distance_downhill_snow_sports` | `m` | alias | provider_summary window | +| `distance_other` | `meters` | measurement_sample | `distance_other` | `m` | alias | provider_summary window | +| `walking_step_length` | `cm` | measurement_sample | `walking_step_length` | `m` | divide by 100 | provider_summary window | +| `walking_speed` | `m_per_s` | measurement_sample | `walking_speed` | `m/s` | alias | provider_summary window | +| `walking_double_support_percentage` | `percent` | measurement_sample | `walking_double_support_percentage` | `%` | alias | provider_summary window | +| `walking_asymmetry_percentage` | `percent` | measurement_sample | `walking_asymmetry_percentage` | `%` | alias | provider_summary window | +| `walking_steadiness` | `percent` | measurement_sample | `walking_steadiness` | `%` | alias | provider_summary window | +| `stair_descent_speed` | `m_per_s` | measurement_sample | `stair_descent_speed` | `m/s` | alias | provider_summary window | +| `stair_ascent_speed` | `m_per_s` | measurement_sample | `stair_ascent_speed` | `m/s` | alias | provider_summary window | +| `running_power` | `watts` | measurement_sample | `running_power` | `W` | alias | provider_summary window | +| `running_speed` | `m_per_s` | measurement_sample | `running_speed` | `m/s` | alias | provider_summary window | +| `running_vertical_oscillation` | `cm` | measurement_sample | `running_vertical_oscillation` | `cm` | unchanged | provider_summary window | +| `running_ground_contact_time` | `ms` | measurement_sample | `running_ground_contact_time` | `ms` | unchanged | provider_summary window | +| `running_stride_length` | `cm` | measurement_sample | `running_stride_length` | `m` | divide by 100 | provider_summary window | +| `running_vertical_ratio` | `percent` | measurement_sample | `running_vertical_ratio` | `%` | alias | provider_summary window | +| `running_stance_time_balance` | `percent` | measurement_sample | `running_stance_time_balance` | `%` | alias | provider_summary window | +| `swimming_stroke_count` | `count` | measurement_sample | `swimming_stroke_count` | `count` | unchanged | provider_summary window | +| `underwater_depth` | `meters` | measurement_sample | `underwater_depth` | `m` | alias | provider_summary window | +| `cadence` | `rpm` | measurement_sample | `cadence` | `rpm` | unchanged | provider_summary window | +| `power` | `watts` | measurement_sample | `power` | `W` | alias | provider_summary window | +| `speed` | `m_per_s` | measurement_sample | `speed` | `m/s` | alias | provider_summary window | +| `workout_effort_score` | `score` | source_report | `workout_effort_score` | `score` | unchanged | source_report window | +| `estimated_workout_effort_score` | `score` | source_report | `estimated_workout_effort_score` | `score` | unchanged | source_report window | +| `distance` | `meters` | measurement_sample | `distance` | `m` | alias | provider_summary window | +| `elevation_gain` | `meters` | measurement_sample | `elevation_gain` | `m` | alias | provider_summary window | +| `environmental_audio_exposure` | `dB` | measurement_sample | `environmental_audio_exposure` | `dB` | unchanged | provider_summary window | +| `headphone_audio_exposure` | `dB` | measurement_sample | `headphone_audio_exposure` | `dB` | unchanged | provider_summary window | +| `environmental_sound_reduction` | `dB` | measurement_sample | `environmental_sound_reduction` | `dB` | unchanged | provider_summary window | +| `time_in_daylight` | `minutes` | measurement_sample | `time_in_daylight` | `min` | alias | provider_summary window | +| `water_temperature` | `celsius` | measurement_sample | `water_temperature` | `°C` | alias | provider_summary window | +| `uv_exposure` | `count` | measurement_sample | `uv_exposure` | `count` | unchanged | provider_summary window | +| `inhaler_usage` | `count` | measurement_sample | `inhaler_usage` | `count` | unchanged | provider_summary window | +| `weather_temperature` | `celsius` | measurement_sample | `weather_temperature` | `°C` | alias | provider_summary window | +| `weather_humidity` | `percent` | measurement_sample | `weather_humidity` | `%` | alias | provider_summary window | +| `elevation` | `meters` | measurement_sample | `elevation` | `m` | alias | provider_summary window | +| `latitude` | `degrees` | measurement_sample | `latitude` | `deg` | alias | provider_summary window | +| `longitude` | `degrees` | measurement_sample | `longitude` | `deg` | alias | provider_summary window | +| `air_temperature` | `celsius` | measurement_sample | `air_temperature` | `°C` | alias | provider_summary window | +| `garmin_stress_level` | `score` | provider_score | `garmin_stress_level` | `score` | unchanged; scale 1-100 | provider_score window | +| `garmin_skin_temperature` | `celsius` | measurement_sample | `garmin_skin_temperature` | `°C` | alias | provider_summary window | +| `garmin_fitness_age` | `years` | source_report | `garmin_fitness_age` | `years` | unchanged | source_report window | +| `garmin_body_battery` | `percent` | provider_score | `garmin_body_battery` | `score` | unchanged; input percent; scale 0-100 | provider_score window | +| `withings_pulse_wave_velocity` | `m_per_s` | measurement_sample | `withings_pulse_wave_velocity` | `m/s` | alias | provider_summary window | +| `withings_metabolic_age` | `years` | source_report | `withings_metabolic_age` | `years` | unchanged | source_report window | +| `dietary_energy_consumed` | `kcal` | source_report | `dietary_energy_consumed` | `kcal` | unchanged | source_report window | +| `dietary_carbohydrates` | `g` | source_report | `dietary_carbohydrates` | `g` | unchanged | source_report window | +| `dietary_fiber` | `g` | source_report | `dietary_fiber` | `g` | unchanged | source_report window | +| `dietary_sugar` | `g` | source_report | `dietary_sugar` | `g` | unchanged | source_report window | +| `dietary_fat_total` | `g` | source_report | `dietary_fat_total` | `g` | unchanged | source_report window | +| `dietary_fat_saturated` | `g` | source_report | `dietary_fat_saturated` | `g` | unchanged | source_report window | +| `dietary_fat_monounsaturated` | `g` | source_report | `dietary_fat_monounsaturated` | `g` | unchanged | source_report window | +| `dietary_fat_polyunsaturated` | `g` | source_report | `dietary_fat_polyunsaturated` | `g` | unchanged | source_report window | +| `dietary_cholesterol` | `mg` | source_report | `dietary_cholesterol` | `mg` | unchanged | source_report window | +| `dietary_protein` | `g` | source_report | `dietary_protein` | `g` | unchanged | source_report window | +| `dietary_sodium` | `mg` | source_report | `dietary_sodium` | `mg` | unchanged | source_report window | +| `dietary_potassium` | `mg` | source_report | `dietary_potassium` | `mg` | unchanged | source_report window | +| `dietary_calcium` | `mg` | source_report | `dietary_calcium` | `mg` | unchanged | source_report window | +| `dietary_iron` | `mg` | source_report | `dietary_iron` | `mg` | unchanged | source_report window | +| `dietary_magnesium` | `mg` | source_report | `dietary_magnesium` | `mg` | unchanged | source_report window | +| `dietary_phosphorus` | `mg` | source_report | `dietary_phosphorus` | `mg` | unchanged | source_report window | +| `dietary_zinc` | `mg` | source_report | `dietary_zinc` | `mg` | unchanged | source_report window | +| `dietary_copper` | `mg` | source_report | `dietary_copper` | `mg` | unchanged | source_report window | +| `dietary_manganese` | `mg` | source_report | `dietary_manganese` | `mg` | unchanged | source_report window | +| `dietary_selenium` | `mcg` | source_report | `dietary_selenium` | `mcg` | unchanged | source_report window | +| `dietary_chromium` | `mcg` | source_report | `dietary_chromium` | `mcg` | unchanged | source_report window | +| `dietary_molybdenum` | `mcg` | source_report | `dietary_molybdenum` | `mcg` | unchanged | source_report window | +| `dietary_iodine` | `mcg` | source_report | `dietary_iodine` | `mcg` | unchanged | source_report window | +| `dietary_chloride` | `mg` | source_report | `dietary_chloride` | `mg` | unchanged | source_report window | +| `dietary_vitamin_a` | `mcg` | source_report | `dietary_vitamin_a` | `mcg` | unchanged | source_report window | +| `dietary_vitamin_b6` | `mg` | source_report | `dietary_vitamin_b6` | `mg` | unchanged | source_report window | +| `dietary_vitamin_b12` | `mcg` | source_report | `dietary_vitamin_b12` | `mcg` | unchanged | source_report window | +| `dietary_vitamin_c` | `mg` | source_report | `dietary_vitamin_c` | `mg` | unchanged | source_report window | +| `dietary_vitamin_d` | `mcg` | source_report | `dietary_vitamin_d` | `mcg` | unchanged | source_report window | +| `dietary_vitamin_e` | `mg` | source_report | `dietary_vitamin_e` | `mg` | unchanged | source_report window | +| `dietary_vitamin_k` | `mcg` | source_report | `dietary_vitamin_k` | `mcg` | unchanged | source_report window | +| `dietary_thiamin` | `mg` | source_report | `dietary_thiamin` | `mg` | unchanged | source_report window | +| `dietary_riboflavin` | `mg` | source_report | `dietary_riboflavin` | `mg` | unchanged | source_report window | +| `dietary_niacin` | `mg` | source_report | `dietary_niacin` | `mg` | unchanged | source_report window | +| `dietary_folate` | `mcg` | source_report | `dietary_folate` | `mcg` | unchanged | source_report window | +| `dietary_pantothenic_acid` | `mg` | source_report | `dietary_pantothenic_acid` | `mg` | unchanged | source_report window | +| `dietary_biotin` | `mcg` | source_report | `dietary_biotin` | `mcg` | unchanged | source_report window | +| `dietary_caffeine` | `mg` | source_report | `dietary_caffeine` | `mg` | unchanged | source_report window | +| `dietary_fat_trans` | `g` | source_report | `dietary_fat_trans` | `g` | unchanged | source_report window | +| `dietary_energy_from_fat` | `kcal` | source_report | `dietary_energy_from_fat` | `kcal` | unchanged | source_report window | +| `dietary_fat_unsaturated` | `g` | source_report | `dietary_fat_unsaturated` | `g` | unchanged | source_report window | +| `dietary_folic_acid` | `mcg` | source_report | `dietary_folic_acid` | `mcg` | unchanged | source_report window | +| `electrodermal_activity` | `count` | measurement_sample | `electrodermal_activity` | `count` | unchanged | provider_summary window | +| `push_count` | `count` | measurement_sample | `push_count` | `count` | unchanged | provider_summary window | +| `atrial_fibrillation_burden` | `count` | measurement_sample | `atrial_fibrillation_burden` | `count` | unchanged | provider_summary window | +| `insulin_delivery` | `count` | measurement_sample | `insulin_delivery` | `count` | unchanged | provider_summary window | +| `number_of_times_fallen` | `count` | measurement_sample | `number_of_times_fallen` | `count` | unchanged | provider_summary window | +| `number_of_alcoholic_beverages` | `count` | source_report | `number_of_alcoholic_beverages` | `count` | unchanged | source_report window | +| `nike_fuel` | `count` | source_report | `nike_fuel` | `count` | unchanged | source_report window | +| `hydration` | `mL` | measurement_sample | `hydration` | `mL` | unchanged | provider_summary window | `get_day_rows` keeps one row per data source, series, and local day. It orders provider-computed rows first, then the later `period_start`. @@ -306,9 +419,12 @@ A week or month forces `computed_by` to `open_wearables`. A day page's `limit` counts periods. The service floors that count at 1, and one period can contain one row per source and series. -`HEALTH_SCORE_RANGES` sets the finite scales. Polar readiness is 0 to 10. -Polar recovery is 1 to 6. WHOOP strain is 0 to 21. Polar strain has no -finite maximum. The route text says `provider: internal` scores were +`HEALTH_SCORE_RANGES` sets the finite scales. Sleep is 0 to 100 for +internal, WHOOP, and Samsung, and 1 to 100 for Oura, Garmin, and Polar. +Oura readiness and Oura activity are 1 to 100. Polar readiness is 0 to 10. +Garmin stress and Garmin body battery are 0 to 100. WHOOP and Suunto +recovery are 0 to 100. Polar recovery is 1 to 6. WHOOP strain is 0 to 21. +Polar strain has no finite maximum. The route text says `provider: internal` scores were computed by Open Wearables and are still returned. WHOOP recovery components include `skin_temp_celsius` when the provider sent it. diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index e0cb4a4f..2a6aabf5 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -9,15 +9,16 @@ D-number. ## D198. Version 2.2.0 is one manual pull, and the program and the record share that number -`ath pull openwearables` reads the stored measurements D204 lists from an +`ath pull openwearables` reads the stored representations D205 lists from an Open Wearables server the person runs, for one user and one range they name. The command is manual. The person runs it. The program does not schedule it, retry a failed request, or sign the person in to a device maker. The program, the record, and the database become `2.2.0` together. D152 made those one number. D184 kept that rule. Migration step 5 stores `2.2.0` and -SQL schema 5. It adds no column. It rebuilds `provider_summaries` as D203 -describes and copies existing rows with their numbers. Step 4 is not edited +SQL schema 5. It adds no column to an existing table. It rebuilds +`provider_summaries` and `provider_scores`, and it creates +`source_reports`, as D205 describes. Existing rows keep their numbers. Step 4 is not edited (D165). A new database runs step 5 after step 4 and before `user_version` is set. `applyMigrationStep` handles target 5. The migration chain, the SQL contract generator, and the drift check gain that step. The package exports @@ -297,8 +298,9 @@ empty success. Body may be one object or JSON `null`. `null` is a completed empty snapshot. The personal record is one object. The result keeps a `left_out` total and at most 20 examples. -An empty range whose reads completed is a successful pull with -committed counts of zero and `range_complete` true. A repeat uses the match +An empty ranged result whose ranged reads completed has `range_complete` +true. The personal record and the body snapshot can still be written. +Those writes are counted. They are not ranged rows. A repeat uses the match key from D181 and the replace from D182, so an unchanged row is not written again. A rerun after a partial write leaves the committed rows in place, runs the failed read again, and runs any read that was `not_attempted`. @@ -388,7 +390,9 @@ join the caller's `BEGIN IMMEDIATE` transaction. D204 also allows `measurement_sample` insert and update, and a null value and unit pair on provider summaries and provider scores. A half-null pair is refused. The same pair is allowed in the TypeScript projection, package import, record -view, and repair copy. Nothing beyond that is added to `store.rs`. Other +view, and repair copy. D205 also allows `source_report` insert and update, +and withdrawal of a child whose anchor is in this response. Nothing beyond +that is added to `store.rs`. Other routes do not call the receipt operations. `ath correct`, package restore, and an accepted package merge remain the owner's whole source record. Splitting the files is separate work. It is not required to make the pull @@ -413,9 +417,9 @@ Rejected alternatives: ## D203. Stored Open Wearables measurements are kept in this pull D204 supersedes the classification, source identity, time, score, endpoint, -and size sentences in this proposal. The decision to keep the returned -health data in this pull stands. Where a paragraph below disagrees with -D204, D204 is the proposal. +and size sentences in this proposal. D205 supersedes D204 where they +disagree. The decision to keep the returned health data in this pull +stands. Where a paragraph below disagrees with D205, D205 is the proposal. This supersedes the earlier draft, inside D198 and D199, that left day values, the heart-rate stream, sleep and recovery summaries, meals, and @@ -469,7 +473,16 @@ Rejected alternatives: ## D204. Returned values keep their meaning, source, and time -This corrects D203. The values stay in this pull. The corrections are the +D205 supersedes the sentences below that call dietary or index series +provider summaries, that store a day row as the same class as its raw +sample, that build a sensor by joining parts with `:` and `-`, that put +main-sleep bounds on a summed field, that leave a missing device id as +`left_out`, that omit a manual workout, and that treat `received_at` as +the time a revision was written. The values stay in this pull. The +device-receipt rules stay. Where this proposal disagrees with D205, D205 +is the proposal. + +This corrects D203. The corrections that D205 does not replace are the contracts in the specification's section 2. A device source is still the 2.1.0 sensor, and its receipt rules are @@ -532,3 +545,107 @@ Rejected alternatives: Rejected. The pinned range table and `provider: internal` say otherwise. - Stop a day read at `limit` 1 and report one oversized series. Rejected. That limit counts periods, and one period can hold many rows. + +## D205. Units, windows, reported records, and identities stay distinct + +This corrects D204. The returned health data stays in this pull. The +specification's section 2 and the appendix series table are the contract. + +Every series has an input number, an input unit, a standard number, and a +standard unit. The input pair is the server's pair. The standard number +equals the input number except for `walking_step_length` and +`running_stride_length`. Those quantities are metres in Athletic Standard +and centimetres on the server, so the standard number is the input number +divided by 100. A 70 cm step is 0.70 m. The aliases change the unit text +and not the number: `percent` to `%`, `celsius` to `°C`, `degrees` to +`deg`, `meters` to `m`, `m_per_s` to `m/s`, `watts` to `W`, `met` to +`MET`, `minutes` to `min`, and `ml_kg_min` to `ml/kg/min`. A new quantity +uses that alias, or the server unit token when it has no alias. Existing +quantity units are not edited. + +A raw row keeps the class in the appendix table. A day row is never a +measurement sample. Its `timestamp` is the start of a calendar period, and +`window_seconds` is null. The stored period is +`open_wearables_reporting_window`, from that timestamp to `period_end`, +with `recorded_at` unset. The window is not called the measurement +instant. Raw points, raw `vo2_max`, and the two raw Garmin scores keep +their kinds and keys. Day heart rate, day steps, and day speed are window +summaries. Day Garmin scores stay scores on the window. + +Sleep summary numbers cover every non-nap session in the selected source +and date. The longest session supplies `start_time` and `end_time` on the +original object only. Those bounds are not a period on the summed fields. +A 360 minute total from two main sleeps stays on `provider_date`. This +program does not re-sum the sessions and does not invent the missing +interval. + +`source_report` is a new record type. It has a source, so it is not an +athlete report and not a nutrition entry. It is not one of the seven +measured types. D161 still forbids turning a personal report into a +measured record. Dietary series, alcoholic-beverage counts, meal and +nutrient numbers, index, age, and effort series, personal-record fields, +predicted and coded cycle content, BMI, calculated age, an unbounded +health score, and a manual workout use this type. The eight range +calculations and `provider-period-summary` do not read it. A manual +workout is not left out and is not a workout session. An automatic +workout stays a measured session on the device source. + +A new sensor is `ow1:` plus a JSON array with no spaces. JSON `null`, an +empty string, and `-` stay different. Legacy device sensors are not +rewritten. A health score's sensor is `["score", provider]`, using the +top-level author. The input source is not in that array, so a change from +null to a known input revises the same score. A null-source timeseries +uses `["unattributed", "timeseries"]` and the writer `open_wearables`. +Two unequal payloads at the same type and time refuse the call. The +personal record uses `["personal_record"]` and that same writer. A meal, +cycle, or manual workout uses the event array even when `device_id` is +present. That id stays in the array and in the original object. It does +not establish `device_binding`. + +A raw or day row whose `source` object has no `device_id` is an incoming +device row. The whole call is refused, including a valid row on the same +page. It is not marked `left_out` before the check. Null-source rows do +not enter that check. + +The same returned object can change a child from a number to null or +remove a nutrient. That child is revised to an absent value and unit. +The id and the first `received_at` stay. D182 copies that `received_at` +onto the revision. `became_known_at` is when the revision was written. A +later number returns on the same child. A range that does not return the +object does not withdraw its children. A refused page rolls the +withdrawal back. + +A finished range with a failed body or personal-record read says the +range is complete, names the failed snapshot, and exits nonzero. It does +not print the success sentence. A preview says a snapshot would be +stored. It does not say it was stored. An empty ranged result does not +mean the command wrote nothing. + +`computed_by` omitted on a raw row keeps basis `provider_or_aggregator`. +`computed_by: null` omits the basis. The raw Garmin scores keep basis +`provider`. `provider: internal` keeps basis `aggregator`. The scale text +comes only from `HEALTH_SCORE_RANGES`, including the `1-100` rows. + +Rejected alternatives: + +- Store a day heart-rate, step, or speed row as a measurement sample at + the calendar start. Rejected. That start is not a measurement instant, + and a sample requires `recorded_at`. +- Add an interval-sample table so a day row can carry a duration. + Rejected for this release. The reporting window already holds the + bounds the server returned, and a day row does not carry + `window_seconds`. +- Put the longest sleep's bounds on the summed duration. Rejected. The + sum covers every non-nap session, and the bounds cover one session. +- Keep colon-joined sensors with `-` for a missing part. Rejected. A + colon in a part and a literal hyphen collide with that encoding. +- Treat a second null-source payload as a correction. Rejected. There is + no sample id, so the program cannot tell a correction from a second + observation. +- Call dietary intake or a manual workout a provider summary or a workout + session. Rejected. SPEC section 5.4 and D161 keep those measured types + for measured records. A source report preserves the object without + making it a measurement. +- Leave a removed nutrient current because the store compares emitted + keys. Rejected. The same object no longer contains that number. + diff --git a/build-history/v2.2.0/progress.md b/build-history/v2.2.0/progress.md index 20194c31..3962ee01 100644 --- a/build-history/v2.2.0/progress.md +++ b/build-history/v2.2.0/progress.md @@ -5,9 +5,9 @@ program, the record, or the database has changed for 2.2.0. | Step | What | Status | |---|---|---| -| 0 | The plan: proposals D198–D204, and the Open Wearables study. D204 corrects the meaning of the stored measurements. Still not adopted. The new head needs re-review | written, not approved | -| 1 | Version 2.2.0 and migration step 5. No new column. Summary and score values may be omitted in pairs (D198, D204) | not started | -| 2 | `ath pull openwearables` in `ath-core`, with the rewritten mapping (D199, D201, D204) | not started | +| 0 | The plan: proposals D198–D205, and the Open Wearables study. D205 corrects units, day windows, sleep bounds, identities, and reported records. Still not adopted. The new head needs re-review | written, not approved | +| 1 | Version 2.2.0 and migration step 5. No new column on an existing table. `source_reports` is created. Summary and score values may be omitted in pairs (D198, D205) | not started | +| 2 | `ath pull openwearables` in `ath-core`, with the rewritten mapping (D199, D201, D205) | not started | | 3 | Key, server, and user id kept out of the record (D200) | not started | | 4 | Fixture tests, with no live key in CI | not started | | 5 | Generated schema, demo athlete, skill command reference, and the public-data list | not started | diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index de0b9bf4..79d9acaa 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -4,7 +4,7 @@ Status: **plan only. The maintainer has not approved it. Not approved for build. `ath pull openwearables` reads one person's stored health data from an Open Wearables server they run, and writes it with the mapping this release -ships. The proposals are D198 through D204 in +ships. The proposals are D198 through D205 in [decisions.md](decisions.md). They are not adopted. The evidence is [appendix/open-wearables-api.md](appendix/open-wearables-api.md), checked on 6 and 7 November 2026. @@ -73,11 +73,12 @@ Preview text prints: - `reads finished` or `reads incomplete` - one line each for the twelve reads in section 2: `completed`, `failed`, or `not_attempted` -- for body, one extra line: `body snapshot stored`, `body snapshot empty`, - or `body snapshot incomplete` +- for body, on a preview: `body snapshot would store` or `body snapshot + would be empty`. On a confirmed write: `body snapshot stored`, + `body snapshot empty`, or `body snapshot incomplete` - estimated counts, by record type, of sleep sessions, workouts, points, - measurement samples, summaries, and scores -- committed counts of zero + measurement samples, summaries, scores, and source reports +- committed counts of zero on a preview - the coverage lines in section 2 - `left_out` as a total plus at most 20 example lines - `nothing written; pass --yes after reviewing this preview` @@ -94,13 +95,18 @@ print that sentence. The body line still says the snapshot is incomplete. If a later page fails, the child returns a typed outcome to the parent before the process exits nonzero. The parent renders that outcome as text, -then uses the exit status. The text says the requested range is incomplete, -names the failed read, names any read that is `not_attempted`, and prints -the retained counts. A failed read says to run the same command again. An -identity refusal uses the sentence in section 3, which says a rerun cannot +then uses the exit status. When a ranged read failed, the text says the +requested range is incomplete. When every ranged read completed and body +or the personal record failed, the text says the requested range is +complete and names the snapshot that failed. It names any read that is +`not_attempted`, and it prints the retained counts. The exit is nonzero +in both cases. The success sentence is not printed. A failed read says to +run the same command again. An identity refusal uses the sentence in +section 3, which says a rerun cannot repair the device id. It does not print the success sentence. The failed page makes no database changes. Records -already stored stay, including their revisions. An empty range whose reads -finished says the range is complete. `written` is false when the confirmed +already stored stay, including their revisions. An empty ranged result +can still store the personal record or the body snapshot. Those writes are +counted. They are not ranged rows. `written` is false when the confirmed command changed nothing. The database is unchanged. That is not a claim that the database has no rows. @@ -134,17 +140,21 @@ server, user id, or request path. } ``` -The same record types are present for workouts, points, summaries, and -scores. The example above is shortened. It is the preview outcome. +The same record types are present for workouts, points, summaries, scores, +and source reports. The example above is shortened. It is the preview +outcome. A preview does not say a snapshot was stored. The child returns a different outcome for `--yes` without `--json`. That -outcome has the actual `committed` counts, `database_changed`, and -`range_complete`. `written` is true only when that confirmed command -committed at least one new or revised record. A successful repeat has -`written` false, `database_changed` false, `range_complete` true, and -unchanged counts. A later-page failure has `range_complete` false and the -retained counts. The parent prints sentences from this outcome. It does not -print the outcome as public JSON. +outcome has the actual `committed` counts, `database_changed`, +`range_complete`, and `snapshots_complete`. `range_complete` is true when +the ranged reads finished. `snapshots_complete` is true when the personal +record and the body snapshot finished. `written` is true only when that +confirmed command committed at least one new or revised record. A +successful repeat has `written` false, `database_changed` false, both +flags true, and unchanged counts. A failed ranged page has +`range_complete` false. A failed snapshot after a finished range has +`range_complete` true and `snapshots_complete` false. The parent prints +sentences from this outcome. It does not print the outcome as public JSON. `--date` stays required only for `garmin`. `--from` and `--to` are required only for `openwearables`, and they are flags, not environment variables. @@ -177,8 +187,10 @@ gateway commands they are today. ## 2. What this pull stores -D204 is the storage rule. D203 keeps these values in this pull. D204 -corrects how they are identified, timed, and classified. An earlier draft +D205 is the storage rule. D203 keeps these values in this pull. D204 +corrected source, time, and score direction. D205 corrects units, day +windows, sleep bounds, identity encoding, reported records, and child +withdrawal. An earlier draft left day values, the heart-rate stream, summaries, and workout segments for a later version. That draft is superseded. File imports stay. The Garmin pull stays. A Junction pull is proposed as 2.3.0. Automatic sync, retries, token refresh, and backfill are proposed as @@ -256,176 +268,206 @@ have no limit. An oversized response fails that read and names the read. Earlier committed pages stay. The pull does not drop a series, a segment, or a location to stay under the cap. -Device rows and other rows do not share a source. A device source uses the -2.1.0 sensor, `device_type|device|source`. Its receipt rules in section 3 -are unchanged. A row enters that source only when its `source` object has a -nonempty `device_id`, or when it is an id-less sleep or workout on a new -source with no history. A raw or day sample whose `source` object exists -and whose `device_id` is missing, null, or blank is `left_out`. The reason -is the missing device id. No id is copied from another row. - -A summary built without `device_id` uses a different sensor, -`summary:{family}:{provider}:{device}:{device_type}:{source}`. A missing -part is `-`. Sleep, activity, recovery, and body summaries use that sensor. -The builders in `summaries_service.py` omit `device_id`. Body's `source` -is the newest slow-changing measurement's provider, writer, model, and -type. The service discards provider and device on the latest readings. -That object is the response's umbrella source. It is not the author of -every field, and it is not a device receipt. A meal or cycle with no -`device_id` uses `event:{family}:{provider}:{device}:{device_type}:{source}`. -A meal or cycle that has a `device_id` uses the device source. A timeseries -or score with `source: null` uses -`unattributed:{resource}:{author}`. A health score's sensor is -`score:{author}`, where `{author}` is the top-level `provider`, or `-` -when that field is null. The score's `source` is the input object. It is -stored on the record and does not choose the sensor. - -These sensors do not establish `device_binding`. Their history is not -history of the device source. A summary stored first does not block a -later raw page from binding its own device source. A bound device source -does not reject a later summary. Preview memory is kept per sensor. A -refused device page rolls back only that page. - -Match keys stay D181 for the existing raw points, the raw `vo2_max` -summary, and the raw `garmin_stress_level` and `garmin_body_battery` -scores. A day row adds `1day` and `period_end` to its key, so it does not -replace the raw row. A summary field's key is the writer, the summary -sensor, the family, the `date`, and the field path. A meal, cycle, or -score uses the server id. Two meals at one timestamp stay two records. -Two metrics on one date stay two records. A body field's key is the -writer, the body sensor, the group, and the field path. It has no -requested date. A later snapshot revises that record. `received_at` stays -the time this program stored the revision. It is not the measurement time. -The personal record's key is the writer, its sensor, and `personal_record`. -The athlete profile is not changed. Birth date, gender, and sex do not fit -that profile: it has a birth year, a two-value sex, and no source. - -The original server object is stored on one anchor record, in -`supplied_fields`, including nulls, text, booleans, codes, and nested -objects. A normalized number is a second record. Its `supplied_fields` -hold the leaf it came from, including that leaf's unit. Transport through -this API is not by itself evidence the value was measured (D161). The -classes are: - -- A raw point the 2.1.0 file already stores stays that point. The lines - are RMSSD, SDNN, resting heart rate, respiratory rate, skin temperature, - blood oxygen, and one-minute heart-rate recovery. Apple skin temperature - stays `wrist_temperature_sleeping` when the writer is `apple`. -- Raw `vo2_max` stays `provider_summary.vo2_max`. Raw - `garmin_stress_level` stays a provider score on scale `1-100`. Raw - `garmin_body_battery` stays a provider score on scale `0-100`. Body - battery is not a sample. -- These raw series are points because Athletic Standard already has one - quantity for each, and the original series name stays in - `supplied_fields`: `walking_heart_rate`, `body_temperature`, `height`, - `weight` as `body_weight`, `body_fat_percentage`, `lean_body_mass`, - `blood_pressure_systolic`, and `blood_pressure_diastolic`. -- The other raw series readings are measurement samples. The appendix - lists all 71. The number is unchanged. The unit is the server unit, - using the existing conversions `percent` to `%`, `celsius` to `°C`, - `degrees` to `deg`, and `brpm`, `bpm`, `ms`, and `m` unchanged. A new - series quantity uses the server's unit string when no conversion exists. - Latitude and longitude are samples. A negative coordinate stays negative. - `heart_rate` is a sample. It is not a point. Integer `window_seconds` - sets `duration_ms` to that count times 1000, and the original field - stays. -- Dietary series, and `number_of_alcoholic_beverages`, are reported - intake. Each is a provider summary at the sample time. The summary type - is the series name. They are not nutrition entries and not samples. -- These raw series are provider summaries, not samples: - `peripheral_perfusion_index`, `breathing_disturbance_index`, - `body_mass_index`, `cardiovascular_age`, `workout_effort_score`, - `estimated_workout_effort_score`, `garmin_fitness_age`, - `withings_metabolic_age`, and `nike_fuel`. The estimated effort score - keeps that name. Its basis is omitted. It is not relabeled as measured. -- A day row uses the same class, with the window below. The two Garmin - scores stay scores. A day row of a point series is a provider summary, - not a point. `vo2_max` on a day row is a window summary. Its key is not - the raw `vo2_max` key. +A device source uses the 2.1.0 sensor, `device_type|device|source`. Its +receipt rules in section 3 are unchanged. A sleep session or an automatic +workout enters that source when it has a nonempty `device_id`, or when it +is id-less on a new source with no history. Every raw or day series row +whose `source` object exists enters that same check, including intake and +index series. The stored class is still the appendix class. A source +report on that source is not a measurement. A missing, null, or blank +`device_id` on that row refuses the whole call before any write. It is +not classified `left_out` first. A valid row beside it on the same page +is not stored. No id is copied from another row. Summaries, meals, +cycles, manual workouts, scores, and the personal record use the sensors +below. They do not establish the device receipt. + +A new sensor is the prefix `ow1:` plus a JSON array. The array has no +spaces. A missing part is JSON `null`. An empty string and the text `-` +stay strings. JSON escaping keeps a colon, a quote, and a backslash +inside one part. Two different tuples therefore stay different sensors. +The legacy device sensor is not rewritten into this form. D181 still +escapes `:` and `\` when the sensor is placed in a match key. + +The array shapes are: + +- Summary or body: `["summary", family, provider, device, device_type, source, device_id]` +- Meal, cycle, or manual workout: `["event", family, provider, device, device_type, source, device_id]` +- Health score: `["score", provider]`. `provider` is the top-level author, + or JSON `null` when that field is null. The input `source` is not in + the array. +- Timeseries with `source: null`: `["unattributed", "timeseries"]` +- Personal record: `["personal_record"]` + +The writer is `source.provider` when that string is nonempty. A health +score uses its top-level `provider` when that string is nonempty. The +personal record, a null-provider score, and a null-source timeseries use +the writer `open_wearables`. That word names this route. It is not a +device maker and it is not an invented author. The vendor is omitted. +`source_type` is `connector`. These sensors do not establish +`device_binding`. Their history is not history of a device source. + +A health score never uses the unattributed timeseries sensor. A change +of its input `source` from null to an object, or the reverse, revises +the same score. The writer, the sensor, and the score id stay put. + +A null-source timeseries row has no sample id. Two rows with the same +type and timestamp are one record only when the whole returned row is +equal. A different value, in the same call or a later call, refuses the +call. The stored row stays. The text says the rows are ambiguous and a +rerun cannot choose one. `ath correct` remains the owner's way to replace +a record. The same rule applies to a day row with `source: null`. + +File import and pull use one envelope table. The pull passes these +objects. A saved file imports the same object. A mapping that sends a +device row to another sensor, or that changes a series class in the +appendix table, fails before any request. + +| Resource | Envelope | Writer | Sensor | Anchor | Child | +|---|---|---|---|---|---| +| Sleep session | `{ "sleep": data }` | `source.provider` | legacy device | `sleep_session`, D181 id key | stage and duration fields on that session | +| Automatic workout | `{ "workout": data }` | `source.provider` | legacy device | `workout_session`, D181 id key | existing typed fields and source-reported summaries | +| Manual workout | `{ "workout": data }` | `source.provider` | `ow1` event | `source_report` `manual_workout`, server id | none. The original object is the record | +| Raw series with `device_id` | timeseries object, `resolution` `raw` | `source.provider` | legacy device | the raw class in the appendix, D181 time key | none | +| Raw or day series, source present, no `device_id` | timeseries object | `source.provider` | legacy device, then the call is refused | nothing stored | none | +| Raw series, `source` null | timeseries object | `open_wearables` | `ow1` unattributed | the raw class, D181 time key | none. Unequal payloads refuse the call | +| Day series | timeseries object, `resolution` `1day` | same as the raw row | same as the raw row | window form in the appendix. Key adds `1day` and `period_end` | none | +| Sleep, activity, or recovery summary | `{ "sleep_summary": data }`, `{ "activity_summary": data }`, or `{ "recovery_summary": data }` | `source.provider` | `ow1` summary | `source_report` subject `object`, date | one measured child per numeric field, field path in the key | +| Body | the object | umbrella `source.provider`, or `open_wearables` when it is missing | `ow1` summary, family `body` | `source_report` subject `object` | slow-changing weight, height, fat, and muscle are time-unknown provider summaries; averaged heart rate and HRV use the server window; latest temperature and blood pressure use their own times; age and BMI are source reports | +| Health score | `{ "health_score": data }` | top-level `provider`, or `open_wearables` | `ow1` score | `provider_score` when the scale table has a finite range, otherwise `source_report` | none. Components stay on the record | +| Meal | `{ "meal": data }` | `source.provider` | `ow1` event | `source_report` subject `object`, meal id | one `source_report` per numeric field path | +| Cycle | `{ "cycle": data }` | `source.provider` | `ow1` event | `source_report` subject `object`, cycle id | one `source_report` per numeric reported length | +| Personal record | the object after `user_id` is removed | `open_wearables` | `ow1` personal | `source_report` subject `personal_record` | none | + +`source_report` is not one of the seven measured record types in SPEC +section 5.4. It has a source, so it is not an athlete report and it is +not a nutrition entry. Nutrition entries have no source. D161 still says +a mapping cannot turn a personal report into a measured record. A source +report stores that report without making it a measurement. The eight range calculations and +`provider-period-summary` do not read it. Step 5 creates the +`source_reports` table. Value and unit are both present or both absent. +`report_kind` is one of `intake`, `account`, `predicted`, `code`, `text`, +`manual_workout`, `index`, or `original`. Gender uses `account`. It is not +copied into `sex` or the athlete profile. The receipt still adds no column. + +Match keys for the new records are the writer, the sensor, the resource, +the server id or the date or the body group, and the subject. The anchor +subject is `object`. A child subject is the field path, one key part, so +`nutrients.dietary_sugar` and `calories_kcal` do not collide. Two meals +at one timestamp stay two records because the meal id differs. Legacy +device keys are unchanged. + +The original server object is stored on the anchor, in `supplied_fields`, +including nulls, text, booleans, codes, and nested objects. A normalized +number is a child. Its `input_value` and `input_unit` are the server's +number and unit. `supplied_fields` hold that leaf. The appendix table is +the mapping for all 141 series, raw and day. `standard_value` equals +`input_value` except for `walking_step_length` and `running_stride_length`. +Those quantities are metres. The server sends centimetres, so +`standard_value` is `input_value / 100`. A 70 cm step is 0.70 m. A 120 cm +stride is 1.20 m. The other aliases change the unit text and not the +number: `percent` to `%`, `celsius` to `°C`, `degrees` to `deg`, `meters` +to `m`, `m_per_s` to `m/s`, `watts` to `W`, `met` to `MET`, `minutes` to +`min`, and `ml_kg_min` to `ml/kg/min`. A new quantity uses that alias, or +the server's unit token when it has no alias. Existing quantity units are +not edited to match the server token. + +No day row is a measurement sample. The day `timestamp` is +`CalendarPeriod.of_date(...).start`. `period_end` is the next boundary. +`window_seconds` is null. Those bounds are the reporting window +`open_wearables_reporting_window` on a provider summary, a provider +score, or a source report. `recorded_at` is unset. `duration_ms` is unset. +The program does not turn the two bounds into a duration, so a 23-hour or +25-hour local day stays the server's two timestamps. The window is not +called the measurement instant. Integer `window_seconds` on a raw sample +sets `duration_ms` to that count times 1000. The original field stays. Raw `heart_rate` stays a sample at the +server timestamp. Day `heart_rate`, day steps, and day speed are window +summaries. The two Garmin day scores stay scores on their existing +scales, with the window and without `recorded_at`. Raw points, raw +`vo2_max`, and the two raw Garmin scores keep their kinds and keys. `computed_by: provider` sets basis `provider`. `computed_by: open_wearables` sets basis `aggregator`. `computed_by: null` omits the -basis and keeps the null. A raw row has no `computed_by`. Its basis stays -`provider_or_aggregator`. A health score with top-level `provider: -internal` has basis `aggregator`. That score was computed by Open -Wearables. A vendor name in that field has basis `provider`. A null -`provider` omits the basis. The writer field on the device sensor is not -this author. - -A health score with a finite range in `constants/health_scores.py` is a -provider score. The scale text is `{min}-{max}`. The unit is `score` when -the number is present. Polar readiness is `0-10`. Polar recovery is `1-6`. -WHOOP strain is `0-21`. Sleep, and WHOOP recovery, are `0-100` only for -the provider entries in that table. Polar strain has no finite maximum, so -it is not given a scale. A category or provider missing from the table is -not given `0-100`. That score is a provider summary with no numeric -`value`. The number, qualifier, components, and `event_record_id` stay on -the anchor. A null score value uses the same kind as a present value for -that provider and category, with `value` and unit both absent. Components -are not turned into extra scores. RMSSD and SDNN stay separate names. -`RecoverySummary.recovery_score` is a deprecated 0 to 100 field. A present -number is a provider score on scale `0-100`. A null is only the anchor's -original object. - -WHOOP recovery components can include `skin_temp_celsius`. The health-score +basis and keeps the null. A raw row that omits `computed_by` keeps the +2.1.0 basis `provider_or_aggregator`. That omission is not the JSON null. +The raw Garmin scores keep basis `provider` from the existing lines. +A health score with top-level `provider: internal` has basis +`aggregator`. A vendor name there has basis `provider`. A null provider +omits the basis. The device writer is not this author. + +A finite range in `constants/health_scores.py` is the only scale. The +text is `{min}-{max}`. The unit is `score` when the number is present. +Sleep is `0-100` for internal, WHOOP, and Samsung, and `1-100` for Oura, +Garmin, and Polar. Oura readiness is `1-100`. Polar readiness is `0-10`. +Oura activity is `1-100`. Garmin stress and Garmin body battery are +`0-100`. WHOOP and Suunto recovery are `0-100`. Polar recovery is `1-6`. +WHOOP strain is `0-21`. Polar strain has no finite maximum. A missing +category or provider is not given a scale. That score is a +`source_report`. The number stays in the original object. The raw series +`garmin_stress_level` and `garmin_body_battery` stay the existing score +lines. They are not these health-score rows. A null value uses the same kind as a present value for +that provider and category. Components are not extra scores. RMSSD and +SDNN stay separate. `RecoverySummary.recovery_score`, when the number is +present, is a provider score on scale `0-100`. When it is null, that +child is withdrawn as section 2 says. The anchor keeps the null. + +WHOOP recovery components can include `skin_temp_celsius`. The score object keeps that component. `RecoverySummary` has no skin-temperature -field. Its class ends at `recovery_score`. Its `avg_hrv_sdnn_ms` text says -current rows are null because they come from WHOOP and that HRV is RMSSD. -A non-null SDNN is stored. RMSSD is not copied into it. The body snapshot -does not fill historical temperature. - -Sleep summary `start_time` and `end_time` are the longest main sleep when -one exists, and otherwise the service's minimum start and maximum end. -Those bounds are the period `open_wearables_main_sleep` only for -`duration_minutes`, `time_in_bed_minutes`, `efficiency_percent`, the stage -minutes, and `interruptions_count`. `total_duration_minutes`, nap count, -nap duration, the session list, and the heart-rate, HRV, respiration, and -blood-oxygen averages stay on `provider_date` alone. A nap outside the -main sleep does not inherit the main-sleep bounds. The session list stays -on the anchor. It does not become extra sleep sessions. The service can -add a missing main duration as zero when it builds -`total_duration_minutes`. This program stores the returned number and the -original. It does not turn a null into zero, and it does not reverse the -server's sum. - -Activity fields are date-only. `floors_climbed` is described as calculated -from elevation. `total_calories_kcal` can be the provider total or the sum -of active and basal energy. The response does not say which. The basis +field. A non-null SDNN is stored. RMSSD is not copied into it. The body +snapshot does not fill historical temperature. + +Sleep summary numbers are sums or weighted values across every non-nap +session in the selected source and date. `start_time` and `end_time` are +only the longest main sleep, or the service's minimum start and maximum +end when no main sleep exists. Those bounds stay inside the anchor's +original object. They are not a reporting period on `duration_minutes`, +time in bed, efficiency, stage minutes, or interruptions. Two main sleeps, +00:00–04:00 and 06:00–08:00, can sum to 360 minutes. That 360 stays on +`provider_date`. It is not placed inside the four-hour sleep. This +program does not re-sum the sessions and does not invent an interval. +Nap totals and the heart-rate, HRV, respiration, and blood-oxygen +averages are also date-only. The session list stays on the anchor. The +service can add a missing part as zero when it builds +`total_duration_minutes`. A returned zero stays zero. A null stays null. + +Activity fields are date-only provider summaries. `floors_climbed` is +described as calculated from elevation. `total_calories_kcal` can be the +provider total or a sum. The response does not say which, so the basis stays `provider_or_aggregator`. Intensity minutes can be returned as zero -where the service fills a missing key with zero. A returned zero stays -zero. - -Body is one current snapshot. `range_complete` does not treat it as the -requested dates. `slow_changing` has weight, height, fat, muscle, BMI, and -age, and no measurement time. Those values use -`input_timestamp.timestamp_missing_reason: not_provided_by_source`. They -have no `recorded_at` and no reporting period. The average window is not -borrowed, and the pull time is not written as the measurement time. Age is -basis `aggregator` because the service calculates it from the birth date -and the server clock. BMI is not called measured. The response does not -say whether that BMI was stored or calculated, so its basis is omitted. -`averaged` uses the server's `period_start` and `period_end`. Those bounds -are the current averaging window, computed from `datetime.now` in the -service. They are not applied to `slow_changing` or `latest`. Each latest -field uses its own time: `body_temperature_measured_at`, -`skin_temperature_measured_at`, or `blood_pressure_measured_at`. A value -with a null time uses the same time-unknown receipt. The three groups can -be stored together or alone. A null group stores no field records. The -anchor still holds the object. - -A meal's calories, macros, water, and `nutrients` entries are provider -summaries at the meal timestamp. A nutrient uses the value and unit on -that entry. The name, meal type, and full nutrient map stay on the anchor. -A meal with no numbers is the anchor only. A cycle's reported lengths are -provider summaries on the cycle's start and end. `current_phase` is a -code. `predicted_cycle_length` and `is_predicted_cycle` stay on the -anchor, as do booleans, text, and `pregnancy_snapshot`. They are not -turned into measurements. Workout numbers that are not already typed stay -on the workout as source-reported summaries, and the original fields stay. -`intensity` stays under that name. It is not a sample. Segments stay under -`segments`. A segment with a label is also a typed segment. A missing -label is not filled in. Zones stay under the server's names. A workout -with `entry_source` `manual` is left out. +where the service fills a missing key with zero. + +Body is the current snapshot. It is not the requested range. The anchor +is a `source_report`. Weight, height, fat, and muscle are provider +summaries with `timestamp_missing_reason: not_provided_by_source`, no +`recorded_at`, and no borrowed window. Age and BMI are `source_report` +children. Age is calculated. BMI is not labeled measured. The averaged +heart-rate and HRV values are provider summaries on the server's +`period_start` and `period_end`. Those bounds are not copied onto the +slow-changing fields. Each latest field uses its own measured-at time +when the server sends one. A value with a null time uses the time-unknown +receipt. A null group withdraws that group's existing children. It does +not delete them because a different request omitted the snapshot. + +Meal numbers, nutrient numbers, dietary series, alcoholic-beverage +counts, and the index, age, and effort series are `source_report` +records. They are not provider summaries and not nutrition entries. A +nutrient keeps the value and unit on its leaf. Cycle codes, predicted +lengths, booleans, text, and `pregnancy_snapshot` stay on the cycle +anchor. A numeric cycle length is also a `source_report` child, not a +measurement. On an automatic workout, a number that is not already a +typed session field stays in `supplied_fields` and is a `source_report` +child. It is not a provider summary. `intensity` stays under that name. +Segments and zones stay under the server's names. A +manual workout is the `source_report` in the table. It does not become a +workout session, a point, or a device receipt. + +The same returned object can change a child from a number to null, or +remove a nutrient. The mapper emits that child again with value and unit +both absent. The record id, the revisions, and the first `received_at` +stay. D182 copies the stored `received_at` onto the new revision. +`became_known_at` is when that revision was written. A later number +returns on the same child. A range that does not return the object does +not withdraw its children. A refused page rolls the withdrawals back +with the page. A provider summary or provider score may omit `value` only together with its unit. One without the other is refused. Step 5 rebuilds both typed @@ -433,7 +475,7 @@ tables so the pair can be null, copies every existing row, and keeps record ids, `data_json`, import keys, revisions, tombstones, and reporting periods. Scale on a provider score stays required. No number is invented. The time-unknown summary is valid only with the missing-timestamp reason -above. A summary that has a server time uses that time. +above. The following are not requested. Each line is the reason. @@ -546,8 +588,11 @@ at `source.device_id`. A resolved mapping that points `device_hardware` somewhere else fails before any write, because that file cannot satisfy this contract. The source already stored stays unchanged. -The check runs on accepted rows. A row the mapping has already classified -as `left_out` does not establish a binding and does not supply the id. The +The check runs on device-source rows, including a raw or day row whose +`source` object has no `device_id`. That row is not marked `left_out` +before the check. A query-bucket row that is already `left_out` does not +establish a binding and does not supply the id. Summary, event, score, +unattributed, and personal-record rows do not enter this check. The call is one of these states: - The source is deleted. D190 leaves its rows out. The call does not revive @@ -661,8 +706,10 @@ built without that field. Day rows carry it, and those rows are stored. D200 is the rule. The key never enters the athlete database, the export, the preview, or an error line. The pull reads only the paths in section 2. -It does not list users. The personal-record object includes `user_id`. -That field is removed before the scan below and is not stored. Birth date, +It does not list users. The personal-record object includes `user_id`. When that field is a +string, it must equal the selected user id. Any other string refuses the +page. A matching string is removed before the scan below and is not stored. +A null or absent field is not filled in. Birth date, gender, and sex are stored. They are account health data, not the API key. The process refuses a base URL that could carry the key in the URL itself. @@ -674,9 +721,10 @@ the key cannot be sent to a second host. One attempt, then stop. Timeouts are The body is read inside that cap and parsed before any `apply_mapping` call. The guard is in `open_wearables.rs`. It walks every decoded object key and every decoded string. A value that contains the API key, the selected -origin, or the selected user id rejects the whole page. The removed -personal-record `user_id` is the only field that is dropped before this -walk. Any other copy of the user id still rejects the page. The page is not +origin, or the selected user id rejects the whole page. The matching personal-record `user_id` is the only field that is dropped +before this walk. Any other copy of the user id still rejects the page. A +personal-record `user_id` that is not the selected user refuses the page +before the drop. The page is not rewritten and it is not mapped. A Unicode escape such as `\u0073` is visible only after parsing, so a scan of the raw text is not enough. The raw-text scan still runs on a body that did not parse, and the parent still refuses @@ -703,9 +751,10 @@ reads in section 2, no user list. The build sets `2.2.0` on the package, the record, and `ath-core`, by the same constants 2.1.0 moved. Migration step 5 is a new SQL file. It updates -`athleticstandard_version` to `2.2.0` and `sql_schema_version` to 5. No column -is added. The same file rebuilds `provider_summaries` and `provider_scores` -as section 2 describes and copies existing rows, including deleted rows. +`athleticstandard_version` to `2.2.0` and `sql_schema_version` to 5. No +column is added to an existing table. The same file creates +`source_reports` and rebuilds `provider_summaries` and `provider_scores` +as section 2 describes. It copies existing rows, including deleted rows. Record ids, revisions, import keys, and reporting-period rows stay. Step 4 and file `004` are not edited (D165). @@ -726,13 +775,19 @@ would make a 1.0.0 database unloadable, so migrate could not open it. The build generates `schema/2.2.0/` and does not rewrite `schema/2.1.0/` or `schema/2.0.0/`. The 2.2.0 source object gains optional `device_binding`. -`ProviderReportingPeriodType` gains `open_wearables_reporting_window` and -`open_wearables_main_sleep`. `ValueBasis` gains `aggregator`. Series -quantities gain the sample series in section 2, not the intake, index, age, -or effort series. `provider_summary.value` and `provider_score.value` may -be omitted together with the unit, as section 2 says. A provider summary -may also omit `recorded_at` and reporting periods when its input timestamp -uses `not_provided_by_source`. No other field is added. The folder exists +`ProviderReportingPeriodType` gains `open_wearables_reporting_window`. +`ValueBasis` gains `aggregator`. Series quantities gain the sample series +whose units are in the appendix table. Intake, index, age, and effort +series do not gain quantities. The record type `source_report` is added. +It is not a measured type. Its table has `record_id`, `source_id`, +`report_kind`, `subject`, optional `reported_at`, optional +`standard_value` and `standard_unit` together, optional +`provider_record_id`, `received_at`, and `data_json`. It has no required +measured value. `provider_summary.value` and +`provider_score.value` may be omitted together with the unit, as section 2 +says. A provider summary may also omit `recorded_at` and reporting periods +when its input timestamp uses `not_provided_by_source`. No other field is +added. The folder exists so the package version and the schema path stay aligned. The demo athlete is regenerated because the stored version is inside it. `examples/demo-athlete/athlete.ath.json` @@ -766,7 +821,7 @@ interactive open can preview, back up, ask, and then migrate. | Stored records | the existing store and mapping engine | | Keep `device_binding` on a partial source update | `Store::revise` in `crates/ath-core/src/store.rs`, sources only | | Read receipt and tombstone history; create or first-bind with the checked receipt | three source operations in `store.rs`, inside the caller's transaction | -| Measurement samples; paired null value and unit on summaries and scores | `insert_typed`, `update_typed`, and `typed_table` in `store.rs`; the same pair in `src/db/records.ts`, `src/db/import-package.ts`, `src/db/records-view.ts`, and the repair copy from `data_json` | +| Measurement samples, source reports, paired null value and unit, and child withdrawal | `insert_typed`, `update_typed`, and `typed_table` in `store.rs`; the same pair and table in `src/db/records.ts`, `src/db/import-package.ts`, `src/db/records-view.ts`, and the repair copy from `data_json` | | Whole source record from the owner | existing `ath correct`, package restore, and an accepted package merge | `store.rs`, `persist.rs`, and `personal.rs` are not the home for this client. @@ -785,16 +840,20 @@ copy from section 2. HTTP stays out of `mapping.rs`. `store.rs` keeps the `revise` refusal and adds the three source operations in section 3: the receipt and tombstone read, creation with the checked receipt, and a first bind on an existing source that has no history. It also inserts and -updates `measurement_sample`, and it accepts a provider summary or provider -score whose `value` and unit are both present or both absent. A half-null -pair is refused. `src/db/records.ts`, `src/db/import-package.ts`, +updates `measurement_sample` and `source_report`, and it accepts a provider +summary or provider score whose `value` and unit are both present or both +absent. A half-null pair is refused. When an anchor in this response no +longer emits a child, that child is revised to the absent pair in the same +transaction. `src/db/records.ts`, `src/db/import-package.ts`, `src/db/records-view.ts`, and the repair copy from `data_json` follow that -pair. No other store behavior changes. `ath correct`, +pair and the new table. The eight range calculations and +`provider-period-summary` do not read `source_reports`. No other store +behavior changes. `ath correct`, package restore, and an accepted package merge stay whole-record owner writes. They are named in section 3 so the binding survives a 2.2.0 round trip. They are not a new importer. The pull sums only `sleep_session`, `workout_session`, -`point_measurement`, `measurement_sample`, `provider_summary`, and -`provider_score`. A committed page adds those counts to the actual committed +`point_measurement`, `measurement_sample`, `provider_summary`, +`provider_score`, and `source_report`. A committed page adds those counts to the actual committed result. A rolled-back preview page adds them to `estimated`. It does not add `outcome` across pages. `outcome` counts the source-device row in the same group. Filtering that row out of the totals does not make a preview equal a @@ -810,7 +869,7 @@ the mode is `--yes` without `--json`. On a partial failure it returns that confirmed outcome to the parent and then exits nonzero. The parent renders text from the confirmed outcome and public JSON from the preview outcome. The success sentence is parent text, and only after `--yes` when -`range_complete` is true. +`range_complete` and `snapshots_complete` are both true. The program runs on Linux, macOS, and Windows with the same command. The fixture server listens on `127.0.0.1` and an ephemeral port, which is the @@ -833,8 +892,12 @@ Unix seconds. A bad bound does not open a socket. Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: -- two pages, the second `next_cursor`, then `has_more: false`. `--yes` sets - `range_complete` in the text and prints the success sentence +- two pages, the second `next_cursor`, then `has_more: false`. `--yes` + with a finished body and personal record prints the success sentence. + A finished range whose body read fails says the range is complete, names + the body snapshot, does not print the success sentence, and exits + nonzero. A preview says the snapshot would be stored. An empty ranged + result can still store the personal record - the same session id on two pages, identical payload: the preview estimate counts two new rows, and `--yes` counts one new and one unchanged - the same session id on two pages, changed payload: the preview estimate @@ -868,16 +931,23 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: segment that has a label is also a typed segment - a raw `heart_rate` row becomes a measurement sample in bpm at the server's timestamp. Export and import keep that timestamp, unit, and - value. A day row for resting heart rate, RMSSD, SDNN, and blood oxygen - becomes a provider summary with `open_wearables_reporting_window`, no - `recorded_at`, and the server's `timestamp` and `period_end`. Raw + value. A day row for heart rate, steps, running speed, resting heart + rate, RMSSD, SDNN, and blood oxygen becomes a provider summary with + `open_wearables_reporting_window`, no `recorded_at`, and the server's + `timestamp` and `period_end`. Check, export, and import keep that window + and do not invent an instant. A step length of 70 cm is stored as 0.70 m. + A stride of 120 cm is stored as 1.20 m. The input number and `cm` stay + on the record. Every row in the appendix table has one raw fixture and + one day fixture. Check, export, and import keep the input pair, the + standard pair, and the day window. Raw `vo2_max` stays `provider_summary.vo2_max` on its 2.1.0 key. A day `vo2_max` row is a different window summary. Raw `garmin_stress_level` and `garmin_body_battery` stay provider scores on their existing scales and keys. They do not become samples. A null RMSSD beside a present SDNN stores only the SDNN. A sleep-summary respiratory rate is date-only. The sleep session from the same night still has no respiration field. Nap - totals do not receive the main-sleep bounds. Skin temperature is stored + totals do not receive main-sleep bounds. Two main sleeps of 240 and 120 + minutes store duration 360 on `provider_date` only. Skin temperature is stored from a series row or from body latest when that time is present. A recovery object does not gain a skin field. A WHOOP health-score component named `skin_temp_celsius` stays on that object. @@ -900,31 +970,47 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: file import, and import then import keep one summary id. A refused device page rolls back only that page. Two meals with one timestamp and different ids stay two records. Two summary fields on one date stay two - records. A timeseries row with a source and no `device_id` is `left_out`. - A timeseries row with `source: null` is stored on the unattributed sensor + records. A page with one bound heart-rate row and one same-triple row + whose `device_id` is missing refuses the page. Neither row is stored. + Import then pull of that pair refuses the same way. A timeseries row with + `source: null` is stored on the unattributed sensor when the payload + matches. A different payload at that type and time refuses the call. + Sensors `ow1:["summary","sleep",null]` and a colon inside a provider + name stay different from a shifted tuple. The text `-` is not the same + sensor as a missing part. A score whose input source changes from null + to an object keeps its id. A personal record repeats. A personal record + with no birth date uses the time-unknown receipt. A meal with calories + and two nutrients stays three children plus the anchor - an internal health score has basis `aggregator`. A vendor score has basis `provider`. A null `provider` omits the basis. Polar readiness uses scale `0-10`, Polar recovery uses `1-6`, and WHOOP strain uses `0-21`. A score with no finite range keeps its number on the anchor and does not - use scale `0-100`. A null value and a later number revise the same - record. `computed_by: null` omits the basis and keeps the null + use scale `0-100`. An Oura sleep score uses `1-100`. A null value and a + later number revise the same record. `computed_by: null` omits the basis + and keeps the null. A raw row that omits `computed_by` keeps + `provider_or_aggregator` - body fetched during a historical range is the current object. Weight with no time has no `recorded_at` and does not use the average window. A latest value with a null time is stored the same way. Age has basis `aggregator`. BMI's basis is omitted. The three groups can arrive together or alone. JSON null and a returned zero and a missing field stay three different results -- a dietary series is a provider summary, not a sample and not a nutrition - entry. A cycle code, a predicted length, and a pregnancy snapshot stay - on the anchor. A cycle that starts in range and ends later keeps that - end. A cycle that starts later is not stored, and the read can still - complete. Birth date, gender, and sex are stored. `user_id` is not. - The athlete profile is unchanged +- a dietary series and `number_of_alcoholic_beverages` are source reports, + not samples, not provider summaries, and not nutrition entries. A cycle + code, a predicted length, and a pregnancy snapshot stay on the anchor. + A cycle that starts in range and ends later keeps that end. A cycle that + starts later is not stored, and the read can still complete. Birth date, + gender, and sex are source reports. Gender is not copied into the + athlete profile. A matching `user_id` is not stored. A different + `user_id` refuses the page. The athlete profile is unchanged - step 5 keeps an old summary's id, number, unit, `data_json`, import key, revisions, and tombstone. A numeric summary can be corrected to numberless and back. A half-null value and unit is refused. A sample repeats and corrects. `ath check`, export, native import, and restore - accept the numberless summary and the sample + accept the numberless summary, the numberless score, and the sample. A + meal nutrient that changes from a number to null, then back, keeps one + child id. A null body group withdraws that group's children. A refused + page restores the withdrawn child - two distinct sensor triples become two sources. Device A is stored, then a separate operation contains only device B at the same triple, type, and instant, with a different value. The operation fails. The current point, @@ -949,13 +1035,16 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: device B. The same misleading field in a 2.1.0 package is still a supplied field after import. Device B does not replace A's point. The supplied field and the hardware stay. No source key is added. A sample keeps basis - `provider_or_aggregator`. A provider score keeps basis `provider` + `provider_or_aggregator`. A raw Garmin score keeps basis `provider`. An + internal score keeps basis `aggregator` - a raw page and a mapped file that carry `device_binding` on the row, on a nested source object, and inside `supplied_fields` do not set, replace, or erase the source key. A mapping whose `name` changes and whose `device_hardware` stays `source.device_id` keeps the same binding. A mapping whose `device_hardware` points elsewhere is refused before any - write + write. A mapping that sends a device row to an `ow1` sensor, or that + changes a series class in the appendix table, is refused before any + request - an existing open-wearables source has no receipt, no record, and no source device. The first accepted write stores the checked receipt on that source. Its other fields, its writer, its route, its sensor, and @@ -978,8 +1067,11 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: id can correct the point. A different id is refused, with no new point revision, source revision, or hardware revision. A stored source key that is not a nonempty string refuses the automatic write and is left unchanged -- `page-sleep.json` becomes a sleep session. A manual workout is left out - and its automatic neighbor is kept. `page-raw.json` is stored. +- `page-sleep.json` becomes a sleep session. A manual workout and its + automatic neighbor from one response stay two records. The automatic + workout is a session on the device source. The manual workout is a + source report with the original object and no device receipt. Export and + import keep both. `page-raw.json` is stored. `page-5min.json` is left out. RMSSD and SDNN stay different quantities - a changed end time keeps the record id and increases the revision - a `__proto__` supplied field fails the page @@ -1057,7 +1149,7 @@ the fixture key once into `ath key set openwearables`. 3. Write. Success: the same command with `--yes` says the requested range is complete, shows the body snapshot line, shows committed counts, and `ath check` exits 0. Failure: the success sentence appears while the - range is incomplete, or `ath check` fails. + range or the body snapshot is incomplete, or `ath check` fails. 4. Repeat. Success: `--yes` again reports the stored rows unchanged. Failure: a second copy of a sleep session or a point appears. 5. Compatibility. Success: one synthetic Apple, WHOOP, or Oura import still @@ -1128,15 +1220,15 @@ Risks: is to avoid copying the key into the record. The build, after approval, is one pull request in this order. First the -schema and step 5: the period types, the `aggregator` basis, the sample -series quantities, the paired null value and unit, and the time-unknown -summary. Then the store and record paths in section 6. Then the mapping +schema and step 5: the period type, the `aggregator` basis, the sample +series quantities in the appendix table, the `source_report` type and +table, the paired null value and unit, and the time-unknown summary. Then the store and record paths in section 6. Then the mapping engine and `mappings/open-wearables.md`. Then the reads, the cycle filter, the smaller-page split, and the tests in section 7. The laptop card and the phone proof are part of that same pull request. This plan pull request has no media. The maintainer approves or rejects this plan before any build. D198 through -D204 are the proposal. They are not adopted. Reviews of earlier heads were +D205 are the proposal. They are not adopted. Reviews of earlier heads were incorporated here. None of those reviews approves this revision. The next head needs re-review. An earlier review accepted a migration with no new column, under D152 and D184. That acceptance does not @@ -1148,11 +1240,11 @@ optional source key adds no column. `provider_summaries` and `provider_scores` so a numberless object can omit `value` and its unit together. Existing ids and rows are copied. A `2.1.0` database does not open until `ath migrate`. This release does - not schedule, refresh a token, backfill, or store a cursor (D198, D204). + not schedule, refresh a token, backfill, or store a cursor (D198, D205). 2. Store the returned representations in section 2. Device receipts stay on device sources. Summaries without a device id use their own sensors. Null stays null. A missing response is not called provider-unavailable. - The omissions in section 2 are the ones with a reason (D203, D204). + The omissions in section 2 are the ones with a reason (D203, D205). 3. The key, the selected origin, and the selected user id are rejected in decoded JSON before a page is mapped. Failure text uses a fixed sentence. `ath key clear` with no name still clears only the gateway keys and says @@ -1176,5 +1268,5 @@ optional source key adds no column. check, and the preservation writes in section 2. `store.rs` gains the partial-update refusal, the receipt and tombstone read, creation with the checked receipt, and the first bind of an existing source that has - no history, and the sample and paired-null writes in section 6. - Nothing else is added to either file (D202, D204). + no history, and the sample, source-report, withdrawal, and paired-null + writes in section 6. Nothing else is added to either file (D202, D205). From 9f2acfd973551fb46e852d008d2b227dd093ab72 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 7 Nov 2026 03:40:21 +0000 Subject: [PATCH 09/60] Separate root migration, numberless inputs, and refused originals in the 2.2.0 plan. The new record type needs the root check, absent scores stay out of calculations, and a refused original is archived only after the protected write rolls back. Co-authored-by: Michael Whitham --- .../v2.2.0/appendix/open-wearables-api.md | 25 +- build-history/v2.2.0/decisions.md | 86 +++- build-history/v2.2.0/progress.md | 6 +- build-history/v2.2.0/spec.md | 419 ++++++++++++++---- 4 files changed, 424 insertions(+), 112 deletions(-) diff --git a/build-history/v2.2.0/appendix/open-wearables-api.md b/build-history/v2.2.0/appendix/open-wearables-api.md index 1fcdf262..db0c149b 100644 --- a/build-history/v2.2.0/appendix/open-wearables-api.md +++ b/build-history/v2.2.0/appendix/open-wearables-api.md @@ -115,8 +115,11 @@ series. Workouts, from `Workout`: `id`, `type`, `name`, `start_time`, `end_time`, `zone_offset`, `source`, `entry_source`, `intensity`, the distance, heart-rate, and elevation fields the mapping already names, plus fields it does not name. -`entry_source` is `manual`, `automatic`, or `unknown`. The schema text says -`manual` is a self-reported entry with no device measurement behind it. +`entry_source` is `manual`, `automatic`, or `unknown`, and the response +allows null. The SDK maps an unsupported method to `unknown` and a +missing method to null. The schema text says `manual` is a self-reported +entry with no device measurement behind it. `unknown` and null are not +that entry, and they are not `automatic`. Timeseries, from `TimeSeriesSample`: `timestamp`, `zone_offset`, `type`, `value`, `unit`, `source`, `is_daily_total`, `window_seconds`, `period_end`, @@ -198,7 +201,7 @@ route files. A limit may still exist in middleware this study did not open. The same commit, `183e8cc4f6de897dbd288c93d49a691f2cf721ae`, was read again for every user data route. The OpenAPI file is `docs/openapi.json`, -`info.version` `0.11.0`. The storage rule is D205. This section records +`info.version` `0.11.0`. The storage rule is D206. This section records what the source shows. `SeriesType` is the enum in `backend/app/schemas/enums/series_types.py`. @@ -228,8 +231,12 @@ oxygen, respiration, or temperature. `SleepSummary` has `avg_hrv_rmssd_ms`, `avg_hrv_sdnn_ms`, `avg_spo2_percent`, and `recovery_score`. It has no temperature field. The SDNN field text says the value is null for current rows because they come from WHOOP and -WHOOP's HRV there is RMSSD. `recovery_score` is deprecated in that class -and documented as 0 to 100. `BodyLatest` has `skin_temperature_celsius` +WHOOP's HRV there is RMSSD. The class prose calls `recovery_score` +deprecated, WHOOP-only, and 0 to 100. The recovery query selects by +category, not by WHOOP, and copies `provider` and `value` unchanged. +Polar writes recovery scores on the 1 to 6 range. D206 uses that range +table and the copied provider. It does not use the prose as the scale. +`BodyLatest` has `skin_temperature_celsius` and `skin_temperature_measured_at`. `BodyAveraged` has `period_start`, `period_end`, and separate RMSSD and SDNN fields. @@ -245,7 +252,7 @@ listed rows. The personal-record response fields are `birth_date`, ## Contract read on 7 November 2026 The same commit was read again for the summary, score, meal, cycle, body, -and personal-record contracts. D205 is the storage rule. This section +and personal-record contracts. D206 is the storage rule. This section records the source facts that rule uses. `SERIES_TYPE_DEFINITIONS` has 141 entries. @@ -255,7 +262,7 @@ series are `heart_rate_variability_rmssd`, `heart_rate_variability_sdnn`, `oxygen_saturation`, `heart_rate_recovery_one_minute`, `vo2_max`, `garmin_stress_level`, and `garmin_body_battery`. -The table below is the mapping for all 141 series. D205 is the storage rule. +The table below is the mapping for all 141 series. D206 is the storage rule. `input_value` and the input unit are the server's number and unit. `standard_value` equals `input_value` except where the conversion is `divide by 100`. A day row uses the day record in the last column. It is @@ -273,7 +280,7 @@ object. They are not the period of the summed fields. | `heart_rate` | `bpm` | measurement_sample | `heart_rate` | `bpm` | unchanged | provider_summary window | | `resting_heart_rate` | `bpm` | point | `resting_heart_rate` | `bpm` | unchanged | provider_summary window | | `heart_rate_variability_sdnn` | `ms` | point | `hrv_sdnn` | `ms` | unchanged | provider_summary window | -| `heart_rate_recovery_one_minute` | `bpm` | point | `heart_rate_recovery_one_minute` | `bpm` | unchanged | provider_summary window | +| `heart_rate_recovery_one_minute` | `bpm` | point | `hr_recovery` | `bpm` | unchanged | provider_summary window, summary type `hr_recovery` | | `walking_heart_rate` | `bpm` | point | `walking_heart_rate` | `bpm` | unchanged | provider_summary window | | `heart_rate_variability_rmssd` | `ms` | point | `hrv_rmssd` | `ms` | unchanged | provider_summary window | | `oxygen_saturation` | `percent` | point | `oxygen_saturation` | `%` | alias | provider_summary window | @@ -410,7 +417,7 @@ object. They are not the period of the summed fields. | `number_of_times_fallen` | `count` | measurement_sample | `number_of_times_fallen` | `count` | unchanged | provider_summary window | | `number_of_alcoholic_beverages` | `count` | source_report | `number_of_alcoholic_beverages` | `count` | unchanged | source_report window | | `nike_fuel` | `count` | source_report | `nike_fuel` | `count` | unchanged | source_report window | -| `hydration` | `mL` | measurement_sample | `hydration` | `mL` | unchanged | provider_summary window | +| `hydration` | `mL` | source_report | `hydration` | `mL` | unchanged | source_report window | `get_day_rows` keeps one row per data source, series, and local day. It orders provider-computed rows first, then the later `period_start`. diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index 2a6aabf5..56ed0618 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -9,7 +9,7 @@ D-number. ## D198. Version 2.2.0 is one manual pull, and the program and the record share that number -`ath pull openwearables` reads the stored representations D205 lists from an +`ath pull openwearables` reads the stored representations D206 lists from an Open Wearables server the person runs, for one user and one range they name. The command is manual. The person runs it. The program does not schedule it, retry a failed request, or sign the person in to a device maker. @@ -419,7 +419,7 @@ Rejected alternatives: D204 supersedes the classification, source identity, time, score, endpoint, and size sentences in this proposal. D205 supersedes D204 where they disagree. The decision to keep the returned health data in this pull -stands. Where a paragraph below disagrees with D205, D205 is the proposal. +stands. Where a paragraph below disagrees with D206, D206 is the proposal. This supersedes the earlier draft, inside D198 and D199, that left day values, the heart-rate stream, sleep and recovery summaries, meals, and @@ -548,6 +548,14 @@ Rejected alternatives: ## D205. Units, windows, reported records, and identities stay distinct +D206 supersedes the sentences below that put every source-present series +through the device check, that compare null-source rows by type and +timestamp alone, that leave a refused original unstored in every case, +that map `heart_rate_recovery_one_minute` to a quantity of that same +name, and that call `hydration` a measurement sample. The units, day +windows, sleep bounds, and reported-record direction stay. Where this +proposal disagrees with D206, D206 is the proposal. + This corrects D204. The returned health data stays in this pull. The specification's section 2 and the appendix series table are the contract. @@ -649,3 +657,77 @@ Rejected alternatives: - Leave a removed nutrient current because the store compares emitted keys. Rejected. The same object no longer contains that number. +## D206. The new record type, numberless inputs, and refused originals stay separable + +This corrects D205. The returned health data stays in this pull. The +specification is the contract. + +`records.record_type` is a closed check. `source_report` is not in it. +Creating `source_reports` does not make a root row insertable. Step 5 +adds `source_report` to that check in the generated contract. It does +not edit migrations 001 through 004, and it does not drop the check. +Ordinary writes keep foreign keys on. The migration connection may turn +them off only before its own transaction, rebuild `records` and the two +nullable typed tables by copy, rename, and recreate, then require +`foreign_key_check` and `integrity_check` before commit. A drop of +`records` inside the ordinary foreign-key transaction is not the +procedure. Fresh init and a populated, deleted, history-bearing upgrade +both have to accept a source report afterward. + +A numberless provider summary or provider score is excluded by the +instant reader and the period reader before the limit, the count, and +the numeric decode. It is not zero, and it is not the previous revision. +Source reports stay out of those readers. The formulas stay. + +`RecoverySummary.recovery_score` takes its scale from +`HEALTH_SCORE_RANGES` and the provider the builder copied. Polar recovery +is 1 to 6. A provider the table does not name is a source report. The +WHOOP-only prose is not the scale. + +Raw `heart_rate_recovery_one_minute` is quantity `hr_recovery`. The +server name and the old key stay. `hydration` is a source report. A +device id does not make that intake a sample. + +Sleep, workout, meal, cycle, and score ids must be UUIDs. A raw HTTP +personal record must have a `user_id` UUID equal to the selected user +before that field is removed. The canonical envelope does not contain +it. A missing id refuses the protected page. It is not `left_out`, and +it is not archived. + +`entry_source` `unknown`, null, and omission are `unknown_workout` +reports. They are not sessions and not manual reports. The same server +id with a different kind refuses the page. + +A protected refusal rolls back. For a missing device id on a +device-targeted series row, and for unequal null-source payloads of one +full match key, a later archive transaction stores kind `original` with +no amount and no device receipt. `written` stays false. The command +exits nonzero. Credential failures, invalid ids, conflicting device ids, +legacy history, and kind changes are not archived. Those originals are +not kept, because storing them would invent an id or keep a payload the +guard rejected. Preview does not see a cross-page null-source conflict. +A raw midnight row and a day window that starts then are different keys. + +Rejected alternatives: + +- Rebuild `records` with `DROP TABLE` inside the foreign-key write + transaction. Rejected. The child links cascade or the drop fails, and + the history would not survive. +- Leave foreign keys off after migrate. Rejected. Ordinary writes keep + the check. +- Decode a null summary as zero or as its previous number. Rejected. The + current row says the number is absent. +- Use 0 to 100 for every recovery summary because the class prose says + so. Rejected. Polar writes 1 to 6, and the query copies that value. +- Add a point quantity named `heart_rate_recovery_one_minute`. Rejected. + `hr_recovery` is the existing quantity and the existing key. +- Treat unknown provenance as automatic when a device id is present. + Rejected. The id is not a measurement label. +- Archive every refused page, or write the archive inside the refused + transaction. Rejected. The first keeps rejected secrets and rejected + devices. The second stores the refused write. +- Drop the originals of a missing device id so the refusal stays one + transaction. Rejected for the two reasons above. The archive is a + second transaction with a failed protected-write status. The other + refusal reasons stay unstored. + diff --git a/build-history/v2.2.0/progress.md b/build-history/v2.2.0/progress.md index 3962ee01..04aee386 100644 --- a/build-history/v2.2.0/progress.md +++ b/build-history/v2.2.0/progress.md @@ -5,9 +5,9 @@ program, the record, or the database has changed for 2.2.0. | Step | What | Status | |---|---|---| -| 0 | The plan: proposals D198–D205, and the Open Wearables study. D205 corrects units, day windows, sleep bounds, identities, and reported records. Still not adopted. The new head needs re-review | written, not approved | -| 1 | Version 2.2.0 and migration step 5. No new column on an existing table. `source_reports` is created. Summary and score values may be omitted in pairs (D198, D205) | not started | -| 2 | `ath pull openwearables` in `ath-core`, with the rewritten mapping (D199, D201, D205) | not started | +| 0 | The plan: proposals D198–D206, and the Open Wearables study. D206 corrects the root record check, numberless calculation inputs, recovery scales, required ids, and the archive of a refused original. Still not adopted. The new head needs re-review | written, not approved | +| 1 | Version 2.2.0 and migration step 5. No new column on an existing table. The root check gains `source_report` by the copy in D206. Summary and score values may be omitted in pairs (D198, D206) | not started | +| 2 | `ath pull openwearables` in `ath-core`, with the rewritten mapping (D199, D201, D206) | not started | | 3 | Key, server, and user id kept out of the record (D200) | not started | | 4 | Fixture tests, with no live key in CI | not started | | 5 | Generated schema, demo athlete, skill command reference, and the public-data list | not started | diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index 79d9acaa..b1450784 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -4,7 +4,7 @@ Status: **plan only. The maintainer has not approved it. Not approved for build. `ath pull openwearables` reads one person's stored health data from an Open Wearables server they run, and writes it with the mapping this release -ships. The proposals are D198 through D205 in +ships. The proposals are D198 through D206 in [decisions.md](decisions.md). They are not adopted. The evidence is [appendix/open-wearables-api.md](appendix/open-wearables-api.md), checked on 6 and 7 November 2026. @@ -103,8 +103,11 @@ complete and names the snapshot that failed. It names any read that is in both cases. The success sentence is not printed. A failed read says to run the same command again. An identity refusal uses the sentence in section 3, which says a rerun cannot -repair the device id. It does not print the success sentence. The failed page makes no database changes. Records -already stored stay, including their revisions. An empty ranged result +repair the device id. It does not print the success sentence. The +protected transaction of a refused page makes no database changes. +Records already stored stay, including their revisions. An archive, when +section 2 allows one, is a later transaction. It does not print the +success sentence, and it does not set `written`. An empty ranged result can still store the personal record or the body snapshot. Those writes are counted. They are not ranged rows. `written` is false when the confirmed command changed nothing. The database is unchanged. That is not a claim that @@ -187,10 +190,12 @@ gateway commands they are today. ## 2. What this pull stores -D205 is the storage rule. D203 keeps these values in this pull. D204 +D206 is the storage rule. D203 keeps these values in this pull. D204 corrected source, time, and score direction. D205 corrects units, day windows, sleep bounds, identity encoding, reported records, and child -withdrawal. An earlier draft +withdrawal. D206 corrects the root record type, numberless calculation +inputs, recovery scales, required ids, workout provenance, hydration, +and the archive of a refused original. An earlier draft left day values, the heart-rate stream, summaries, and workout segments for a later version. That draft is superseded. File imports stay. The Garmin pull stays. A Junction pull is proposed as 2.3.0. Automatic sync, retries, token refresh, and backfill are proposed as @@ -269,17 +274,35 @@ Earlier committed pages stay. The pull does not drop a series, a segment, or a location to stay under the cap. A device source uses the 2.1.0 sensor, `device_type|device|source`. Its -receipt rules in section 3 are unchanged. A sleep session or an automatic -workout enters that source when it has a nonempty `device_id`, or when it -is id-less on a new source with no history. Every raw or day series row -whose `source` object exists enters that same check, including intake and -index series. The stored class is still the appendix class. A source -report on that source is not a measurement. A missing, null, or blank -`device_id` on that row refuses the whole call before any write. It is -not classified `left_out` first. A valid row beside it on the same page -is not stored. No id is copied from another row. Summaries, meals, -cycles, manual workouts, scores, and the personal record use the sensors -below. They do not establish the device receipt. +receipt rules in section 3 are unchanged. A sleep session or a workout +with `entry_source` `automatic` enters that source when it has a nonempty +`device_id`, or when it is id-less on a new source with no history. A raw +or day row enters that check only when the appendix class is a point, a +measurement sample, `vo2_max`, or one of the two Garmin scores. A missing, +null, or blank `device_id` on that row refuses the protected transaction +before any measured write. It is not classified `left_out` first. A valid +row beside it on the same page is not stored as a measurement. No id is +copied from another row. Intake, index, age, effort, and `hydration` do +not enter that check. A device id on those rows is original data. It is +not a receipt and it is not evidence the value was measured. + +`entry_source` `automatic` is the only workout class that becomes a +workout session. `manual` is a source report of kind `manual_workout`. +`unknown`, JSON null, and a missing `entry_source` are source reports of +kind `unknown_workout`. The original keeps null and absence distinct. +Unknown is not labeled manual, and it is not labeled automatic because a +model or a device id is present. A repeated server workout id that arrives +as a different kind or sensor refuses the protected page. The stored +record stays. The new interpretation is not written beside it. The text +says the classification changed and a rerun cannot choose. `ath correct` +remains the owner's way to replace the record. + +Sleep, workout, meal, cycle, and health-score objects need a `id` that is +a UUID string. Missing, null, blank, and any other shape refuse the +protected page before a source, a row, or hardware changes. The row is not +`left_out`. No empty or time-based id is invented. A valid neighbor on +that page is not stored. A later page of the same command still rolls +back only the failed page, and earlier committed pages stay. A new sensor is the prefix `ow1:` plus a JSON array. The array has no spaces. A missing part is JSON `null`. An empty string and the text `-` @@ -291,11 +314,13 @@ escapes `:` and `\` when the sensor is placed in a match key. The array shapes are: - Summary or body: `["summary", family, provider, device, device_type, source, device_id]` -- Meal, cycle, or manual workout: `["event", family, provider, device, device_type, source, device_id]` +- Meal, cycle, manual workout, or unknown workout: `["event", family, provider, device, device_type, source, device_id]` +- Reported series: `["report", resolution, provider, device, device_type, source, device_id]`. `resolution` is `raw` or `1day`. - Health score: `["score", provider]`. `provider` is the top-level author, or JSON `null` when that field is null. The input `source` is not in the array. - Timeseries with `source: null`: `["unattributed", "timeseries"]` +- Archive originals: `["archive"]` - Personal record: `["personal_record"]` The writer is `source.provider` when that string is nonempty. A health @@ -310,12 +335,19 @@ A health score never uses the unattributed timeseries sensor. A change of its input `source` from null to an object, or the reverse, revises the same score. The writer, the sensor, and the score id stay put. -A null-source timeseries row has no sample id. Two rows with the same -type and timestamp are one record only when the whole returned row is -equal. A different value, in the same call or a later call, refuses the -call. The stored row stays. The text says the rows are ambiguous and a -rerun cannot choose one. `ath correct` remains the owner's way to replace -a record. The same rule applies to a day row with `source: null`. +A null-source timeseries row has no sample id. The comparison is the full +match key: writer, sensor, `timeseries`, resolution, series type, UTC +timestamp, and, for a day row, `period_end`. A raw row at midnight and a +day window that starts at that midnight are different keys. Two rows with +one key are one normalized record only when the whole returned row is +equal. A different value, in the same page or a later confirmed call, +refuses the protected transaction. The stored normalized row stays. The +text says the rows are ambiguous and a rerun cannot choose the normalized +row. `ath correct` remains the owner's way to replace that row. Preview +pages roll back, and the command memory holds device-binding facts only. +A preview therefore does not claim to see a null-source conflict from an +earlier preview page. A confirmed `--yes` page does see an earlier +committed page. File import and pull use one envelope table. The pull passes these objects. A saved file imports the same object. A mapping that sends a @@ -325,11 +357,13 @@ appendix table, fails before any request. | Resource | Envelope | Writer | Sensor | Anchor | Child | |---|---|---|---|---|---| | Sleep session | `{ "sleep": data }` | `source.provider` | legacy device | `sleep_session`, D181 id key | stage and duration fields on that session | -| Automatic workout | `{ "workout": data }` | `source.provider` | legacy device | `workout_session`, D181 id key | existing typed fields and source-reported summaries | +| Automatic workout | `{ "workout": data }` | `source.provider` | legacy device | `workout_session`, D181 id key | existing typed fields; untyped numbers are source reports | | Manual workout | `{ "workout": data }` | `source.provider` | `ow1` event | `source_report` `manual_workout`, server id | none. The original object is the record | -| Raw series with `device_id` | timeseries object, `resolution` `raw` | `source.provider` | legacy device | the raw class in the appendix, D181 time key | none | -| Raw or day series, source present, no `device_id` | timeseries object | `source.provider` | legacy device, then the call is refused | nothing stored | none | -| Raw series, `source` null | timeseries object | `open_wearables` | `ow1` unattributed | the raw class, D181 time key | none. Unequal payloads refuse the call | +| Unknown, null, or omitted `entry_source` | `{ "workout": data }` | `source.provider` | `ow1` event | `source_report` `unknown_workout`, server id | none. The original object is the record | +| Measured raw series with `device_id` | timeseries object, `resolution` `raw` | `source.provider` | legacy device | the raw class in the appendix, D181 time key | none | +| Measured raw or day series, source present, no `device_id` | timeseries object | `source.provider` | legacy device, then the protected transaction is refused | no measured row. Section 2 may archive the original | none | +| Reported series, with or without `device_id` | timeseries object | `source.provider`, or `open_wearables` when that string is missing | `ow1` report | `source_report`, appendix subject | none. The amount is the reported pair | +| Raw series, `source` null | timeseries object | `open_wearables` | `ow1` unattributed | the raw class, full match key | none. An unequal payload refuses the protected transaction and may be archived | | Day series | timeseries object, `resolution` `1day` | same as the raw row | same as the raw row | window form in the appendix. Key adds `1day` and `period_end` | none | | Sleep, activity, or recovery summary | `{ "sleep_summary": data }`, `{ "activity_summary": data }`, or `{ "recovery_summary": data }` | `source.provider` | `ow1` summary | `source_report` subject `object`, date | one measured child per numeric field, field path in the key | | Body | the object | umbrella `source.provider`, or `open_wearables` when it is missing | `ow1` summary, family `body` | `source_report` subject `object` | slow-changing weight, height, fat, and muscle are time-unknown provider summaries; averaged heart rate and HRV use the server window; latest temperature and blood pressure use their own times; age and BMI are source reports | @@ -346,8 +380,43 @@ report stores that report without making it a measurement. The eight range calcu `provider-period-summary` do not read it. Step 5 creates the `source_reports` table. Value and unit are both present or both absent. `report_kind` is one of `intake`, `account`, `predicted`, `code`, `text`, -`manual_workout`, `index`, or `original`. Gender uses `account`. It is not -copied into `sex` or the athlete profile. The receipt still adds no column. +`manual_workout`, `unknown_workout`, `index`, or `original`. Gender uses +`account`. It is not copied into `sex` or the athlete profile. The +receipt still adds no column. + +One source report has this JSON shape. Extra fields are refused. + +```json +{ + "source_id": "record id of the source", + "report_kind": "intake", + "subject": "hydration", + "provider_record_id": "optional server id", + "reported_at": "optional UTC timestamp", + "input_timestamp": { "timestamp_text": "the server timestamp" }, + "provider_reporting_periods": [], + "amount": { + "input_value": 250, + "input_unit": "mL", + "standard_value": 250, + "standard_unit": "mL" + }, + "received_at": "when this program first stored it", + "received_at_basis": "provider_import", + "supplied_fields": {} +} +``` + +`amount` is optional. When it is present, both input fields and both +standard fields are present. It is a reported pair. It is not a measured +`SourceValue`, and `field_basis` is absent. A day report omits +`reported_at` and uses `open_wearables_reporting_window` for the server's +timestamp and `period_end`. Kind `original` omits `amount` and omits +reporting periods. `input_timestamp` is either a timestamp text or +`timestamp_missing_reason`. The record is registered on `RecordType`, the +current and revision unions, the package schema, `typedTables`, repair, +and the root SQL check. It is not added to the seven measured types or to +the point, sample, or session readers. Match keys for the new records are the writer, the sensor, the resource, the server id or the date or the body group, and the subject. The anchor @@ -383,7 +452,13 @@ sets `duration_ms` to that count times 1000. The original field stays. Raw `hear server timestamp. Day `heart_rate`, day steps, and day speed are window summaries. The two Garmin day scores stay scores on their existing scales, with the window and without `recorded_at`. Raw points, raw -`vo2_max`, and the two raw Garmin scores keep their kinds and keys. +`vo2_max`, and the two raw Garmin scores keep their kinds and keys. Raw +`heart_rate_recovery_one_minute` is the point quantity `hr_recovery`, in +bpm. The server series name stays in `supplied_fields`. The 2.1.0 import +key stays. A day row of that series is a window summary whose summary +type is also `hr_recovery`. Its key adds `1day` and `period_end`, so it +does not replace the raw point. A mapped file and a pull, in either +order, keep one record id. `computed_by: provider` sets basis `provider`. `computed_by: open_wearables` sets basis `aggregator`. `computed_by: null` omits the @@ -406,9 +481,15 @@ category or provider is not given a scale. That score is a `garmin_stress_level` and `garmin_body_battery` stay the existing score lines. They are not these health-score rows. A null value uses the same kind as a present value for that provider and category. Components are not extra scores. RMSSD and -SDNN stay separate. `RecoverySummary.recovery_score`, when the number is -present, is a provider score on scale `0-100`. When it is null, that -child is withdrawn as section 2 says. The anchor keeps the null. +SDNN stay separate. `RecoverySummary.recovery_score` uses the same range +table, with category recovery and the provider copied onto the summary's +`source`. Polar is `1-6`. WHOOP and Suunto are `0-100`. A provider that +is missing or absent from that table does not get `0-100`. That child is +a source report, and the number stays in the original object. The schema +prose that says the field is WHOOP-only and 0 to 100 is not the scale. +The number is not rescaled. A null uses the same kind as a present value +for that provider, and the child is withdrawn as section 2 says. The +anchor keeps the null. WHOOP recovery components can include `skin_temp_celsius`. The score object keeps that component. `RecoverySummary` has no skin-temperature @@ -448,8 +529,11 @@ receipt. A null group withdraws that group's existing children. It does not delete them because a different request omitted the snapshot. Meal numbers, nutrient numbers, dietary series, alcoholic-beverage -counts, and the index, age, and effort series are `source_report` -records. They are not provider summaries and not nutrition entries. A +counts, `hydration`, and the index, age, and effort series are +`source_report` records. `hydration` is intake. The server's amount and +millilitre sum are not a sample and not a day measurement. A device id +on that row does not make them measured. They are not provider summaries +and not nutrition entries. A nutrient keeps the value and unit on its leaf. Cycle codes, predicted lengths, booleans, text, and `pregnancy_snapshot` stay on the cycle anchor. A numeric cycle length is also a `source_report` child, not a @@ -469,6 +553,53 @@ returns on the same child. A range that does not return the object does not withdraw its children. A refused page rolls the withdrawals back with the page. +A protected refusal rolls that transaction back. It does not become a +successful pull. Two refusal reasons may then start a separate archive +transaction: a device-targeted series row whose source has no device id, +and a null-source row whose full match key already has a different +payload, including two different payloads in one page. The archive runs +only after the protected rollback, and only after the privacy scan has +accepted the page. It is not a replay of the refused statements. + +The archive contains every series object on that refused page. A reported +row is kept there as an original, not as its structured amount. A later +clean page may store that structured report. The archive does not revise +it. The archive source uses writer `open_wearables`, sensor `ow1:["archive"]`, +and `source_type` `connector`. The receipt operations are not called, and +`device_binding` is not written. Each original is one source report of +kind `original`, with no `amount` and no reporting period. The number +stays inside `supplied_fields`. The match key is the writer, that sensor, +the resource, and the SHA-256 of the canonical JSON object, with keys +sorted and no extra whitespace. That hash is not a sample id and it is +not the measured key. The same bytes are one archive record. Different +bytes are another record. The pull does not revise an archive into a +measurement, and it does not revise a measurement from an archive. + +The outcome names `protected_write` as `committed` or `refused`, and +`archive` as `not_attempted`, `stored`, `unchanged`, or `failed`. +`written` stays false when only the archive changed. When the protected +write was refused, the success sentence is not printed and the exit is +nonzero. The text says the protected write was refused and how many +originals were archived. A preview rolls both +transactions back and says `would refuse` and `would archive`. It does +not say the original was stored. + +These pages are not archived. A credential hit never reaches either +transaction. A missing or invalid required UUID is not given a hash +identity. A conflicting device id is not stored under another source, +because that would keep the rejected device's payload. A deleted source, +an unbound legacy history, and a workout kind change are not archived. +Those originals are not retained. That is a safety limit: filing them +would look like an accepted import or would invent an id. + +On a confirmed command, a later page sees committed measurements and +committed archives. A repeat of the same conflicting payload refuses the +protected write again, leaves the archive unchanged, and sets `written` +false. A third payload adds an archive record and still does not change +the normalized row. A page of only reported series, with no device id, +is an ordinary source-report write. It is not an archive, and it does +not refuse the device check. + A provider summary or provider score may omit `value` only together with its unit. One without the other is refused. Step 5 rebuilds both typed tables so the pair can be null, copies every existing row, and keeps @@ -588,12 +719,13 @@ at `source.device_id`. A resolved mapping that points `device_hardware` somewhere else fails before any write, because that file cannot satisfy this contract. The source already stored stays unchanged. -The check runs on device-source rows, including a raw or day row whose -`source` object has no `device_id`. That row is not marked `left_out` -before the check. A query-bucket row that is already `left_out` does not -establish a binding and does not supply the id. Summary, event, score, -unattributed, and personal-record rows do not enter this check. The -call is one of these states: +The check runs on device-targeted rows. That includes a measured raw or +day row whose `source` object has no `device_id`. That row is not marked +`left_out` before the check. A reported series does not enter this check. +A query-bucket row that is already `left_out` does not establish a +binding and does not supply the id. Summary, event, score, report, +archive, unattributed, and personal-record rows do not enter this check. +The call is one of these states: - The source is deleted. D190 leaves its rows out. The call does not revive the source and does not set a binding. @@ -623,17 +755,19 @@ call is one of these states: absent and with no history. Accepted rows that are only sleep and workouts, and that all lack an id, are stored. The source has no `device_binding`. The result says the device id is unknown. An accepted - timeseries row with no id is refused. Accepted rows that mix a nonempty - id with a missing id are refused. Accepted rows that share one nonempty + device-targeted timeseries row with no id is refused. Accepted rows that + mix a nonempty id with a missing id are refused. A reported series is + not one of these rows. Accepted rows that share one nonempty `source.device_id` store that string on the source in the same transaction as the first accepted write. That source may be created in this call, or it may already exist with no receipt and no history. A call that accepts no rows creates no binding. A source created or first-bound inside a refused call is rolled back with the call. -A second device is refused rather than merged. On `--yes`, an earlier -committed page stays, the failed page makes no database changes, the range -is not complete, and the exit is nonzero. File import rolls back the whole +A second device is refused rather than merged. That refusal is not +archived. On `--yes`, an earlier committed page stays, the failed page +makes no database changes, the range is not complete, and the exit is +nonzero. File import rolls back the whole call. `--json` and `--json --yes` make no database changes. Device reads that have `filter_by_priority` send `false`. Summary routes have no such switch. Section 2 states that limit. @@ -643,7 +777,9 @@ the binding it would have stored, and an unbound source it would have created once that source has accepted history. A summary sensor does not supply a binding for the device sensor. A later preview page uses those facts, including a later page that adds an id after an id-less sleep page. The memory is -discarded with the process. It does not change the estimated record counts. +discarded with the process. It does not hold null-source payloads, so a +preview does not use it to judge those conflicts. It does not change the +estimated record counts. A second command reads the committed source inside its own `BEGIN IMMEDIATE` transaction. @@ -706,10 +842,14 @@ built without that field. Day rows carry it, and those rows are stored. D200 is the rule. The key never enters the athlete database, the export, the preview, or an error line. The pull reads only the paths in section 2. -It does not list users. The personal-record object includes `user_id`. When that field is a -string, it must equal the selected user id. Any other string refuses the -page. A matching string is removed before the scan below and is not stored. -A null or absent field is not filled in. Birth date, +It does not list users. A raw HTTP personal-record response includes `user_id`. That field must +be a string UUID equal to the selected user id. Absence, null, a +non-string, and any other string refuse the page before redaction and +before mapping. A matching string is removed before the scan below and +is not stored. The canonical import envelope is that object after the +removal. File import of the envelope does not put `user_id` back. An +envelope that still has `user_id` is not that envelope, and the scan +rejects it. Birth date, gender, and sex are stored. They are account health data, not the API key. The process refuses a base URL that could carry the key in the URL itself. @@ -722,9 +862,9 @@ The body is read inside that cap and parsed before any `apply_mapping` call. The guard is in `open_wearables.rs`. It walks every decoded object key and every decoded string. A value that contains the API key, the selected origin, or the selected user id rejects the whole page. The matching personal-record `user_id` is the only field that is dropped -before this walk. Any other copy of the user id still rejects the page. A -personal-record `user_id` that is not the selected user refuses the page -before the drop. The page is not +before this walk. Any other copy of the user id still rejects the page. +A raw personal-record `user_id` that is absent, null, the wrong type, or +not the selected user refuses the page before the drop. The page is not rewritten and it is not mapped. A Unicode escape such as `\u0073` is visible only after parsing, so a scan of the raw text is not enough. The raw-text scan still runs on a body that did not parse, and the parent still refuses @@ -750,17 +890,48 @@ reads in section 2, no user list. ## 5. Version, migration, and what stays compatible The build sets `2.2.0` on the package, the record, and `ath-core`, by the -same constants 2.1.0 moved. Migration step 5 is a new SQL file. It updates +same constants 2.1.0 moved. Migration step 5 is a new SQL file and a narrow runner arm. It updates `athleticstandard_version` to `2.2.0` and `sql_schema_version` to 5. No -column is added to an existing table. The same file creates -`source_reports` and rebuilds `provider_summaries` and `provider_scores` -as section 2 describes. It copies existing rows, including deleted rows. -Record ids, revisions, import keys, and reporting-period rows stay. Step 4 -and file `004` are not edited (D165). - -A new database runs that step 5 SQL after step 4 and before the `user_version` -pragma, inside `installInitialSchema`. `applyMigrationStep` gains an arm for -target 5. `MIGRATION_CHAIN` in `src/db/sql-contract.ts`, +column is added to an existing table. The generated contract adds +`source_report` to the `records.record_type` check, creates +`source_reports`, and rebuilds `provider_summaries` and +`provider_scores` as section 2 describes. Files `001` through `004` stay +byte-identical. The check is not removed, and ordinary store writes do +not turn foreign keys off. + +SQLite cannot change that check in place. `records` and +`record_revisions` reference each other. The link from a record to its +current revision is deferred. The link from a revision back to the +record, and the links from typed rows, import keys, deletions, +attachments, reporting periods, and the other child tables, use +`ON DELETE CASCADE` and are not deferred. Triggers and views name +`records`. `PRAGMA foreign_keys` does not change inside a transaction. +`installInitialSchema` and `withWriteTransaction` already require it to +be on. A `DROP TABLE records` there would fail or cascade through the +children. Step 5 does not do that. + +The runner arm for target 5, and the create path after step 4, open the +work before their write transaction and set `PRAGMA foreign_keys=OFF` +only on that connection. Inside one transaction they create +`records_next` with the old columns and the check extended by +`source_report`, copy every root row, drop `records`, and rename +`records_next` back to `records`. They do the same for +`provider_summaries` and `provider_scores`, copying deleted rows and +keeping record ids, `data_json`, import keys, revisions, and periods, +with value and unit nullable together. They create `source_reports` and +its type trigger. They recreate the indexes and the triggers that were +defined on `records`, using the text already in `001`. Views stay, +because they name `records` and the name is restored before commit. +Then `PRAGMA foreign_key_check` and `PRAGMA integrity_check` must be +empty and `ok`. Only then does the transaction commit, and the +connection turns foreign keys back on. A failed check rolls the +transaction back and leaves the live file unchanged. The D124 backup +still happens before this step. Device receipts stay in the copied +source JSON. They are not rewritten. + +A new database runs that step 5 path after step 4 and before the +`user_version` pragma. `applyMigrationStep` gains this arm for target 5 +and does not use `withWriteTransaction` for it. `MIGRATION_CHAIN` in `src/db/sql-contract.ts`, `scripts/generate-sql-contract.ts`, and `scripts/check-schema-drift.ts` gain the step. `package.json` exports and `tests/v1-package-exports.test.ts` point at `schema/2.2.0/`. @@ -778,8 +949,9 @@ The build generates `schema/2.2.0/` and does not rewrite `schema/2.1.0/` or `ProviderReportingPeriodType` gains `open_wearables_reporting_window`. `ValueBasis` gains `aggregator`. Series quantities gain the sample series whose units are in the appendix table. Intake, index, age, and effort -series do not gain quantities. The record type `source_report` is added. -It is not a measured type. Its table has `record_id`, `source_id`, +series do not gain quantities. The record type `source_report` is added to `RecordType`, the current +and revision unions, the package schema, and `typedTables` in +`src/db/check-tables.ts`. It is not a measured type. Its table has `record_id`, `source_id`, `report_kind`, `subject`, optional `reported_at`, optional `standard_value` and `standard_unit` together, optional `provider_record_id`, `received_at`, and `data_json`. It has no required @@ -846,9 +1018,17 @@ absent. A half-null pair is refused. When an anchor in this response no longer emits a child, that child is revised to the absent pair in the same transaction. `src/db/records.ts`, `src/db/import-package.ts`, `src/db/records-view.ts`, and the repair copy from `data_json` follow that -pair and the new table. The eight range calculations and -`provider-period-summary` do not read `source_reports`. No other store -behavior changes. `ath correct`, +pair and the new table. `src/db/check-tables.ts` gains the +`source_report` entry. The eight range calculations and +`provider-period-summary` do not read `source_reports`. In +`read_inputs` and `read_period`, a provider summary or provider score +whose `standard_value` or `standard_unit` is null is excluded in the SQL, +before the limit, the count, the grouping, and the numeric decode. A null +is not stored as zero and is not replaced by an older revision. The +session-summary branch of `read_period` uses the same filter on the +extracted number and unit. Formulas and source grouping stay as they are. +The archive insert is the separate transaction in section 2. It does not +call the receipt operations. No other store behavior changes. `ath correct`, package restore, and an accepted package merge stay whole-record owner writes. They are named in section 3 so the binding survives a 2.2.0 round trip. They are not a new importer. The pull sums only `sleep_session`, `workout_session`, @@ -937,7 +1117,9 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: `timestamp` and `period_end`. Check, export, and import keep that window and do not invent an instant. A step length of 70 cm is stored as 0.70 m. A stride of 120 cm is stored as 1.20 m. The input number and `cm` stay - on the record. Every row in the appendix table has one raw fixture and + on the record. Raw `heart_rate_recovery_one_minute` is quantity + `hr_recovery` in bpm. A 2.1.0 mapped file and this pull, in either + order, keep one record id and the old import key. Every row in the appendix table has one raw fixture and one day fixture. Check, export, and import keep the input pair, the standard pair, and the day window. Raw `vo2_max` stays `provider_summary.vo2_max` on its 2.1.0 key. A day @@ -971,10 +1153,21 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: device page rolls back only that page. Two meals with one timestamp and different ids stay two records. Two summary fields on one date stay two records. A page with one bound heart-rate row and one same-triple row - whose `device_id` is missing refuses the page. Neither row is stored. - Import then pull of that pair refuses the same way. A timeseries row with + whose `device_id` is missing refuses the protected page. Neither row + is stored as a measurement. The archive stores both originals, with no + amount and no device receipt. A later page that has only the valid row + stores that measurement. The archive remains a different record. Import + then pull of the missing-id pair refuses the same way. A sleep id that + is missing, beside a valid workout, refuses the page before any write + and is not archived. The next page still rolls back on its own failure. + A timeseries row with `source: null` is stored on the unattributed sensor when the payload - matches. A different payload at that type and time refuses the call. + matches. A different payload with the same full key, including + resolution and `period_end`, refuses the protected write and archives + the new original. A raw midnight row and a day window that starts then + stay two records. A preview of those two pages does not claim the + conflict, because the first preview page was rolled back. A confirmed + second page does. Sensors `ow1:["summary","sleep",null]` and a colon inside a provider name stay different from a shifted tuple. The text `-` is not the same sensor as a missing part. A score whose input source changes from null @@ -985,7 +1178,10 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: basis `provider`. A null `provider` omits the basis. Polar readiness uses scale `0-10`, Polar recovery uses `1-6`, and WHOOP strain uses `0-21`. A score with no finite range keeps its number on the anchor and does not - use scale `0-100`. An Oura sleep score uses `1-100`. A null value and a + use scale `0-100`. An Oura sleep score uses `1-100`. A Polar recovery + summary value of 3 and the Polar health score use scale `1-6`. A WHOOP + recovery summary uses `0-100`. An author missing from the range table + is a source report and is not given `0-100`. A null value and a later number revise the same record. `computed_by: null` omits the basis and keeps the null. A raw row that omits `computed_by` keeps `provider_or_aggregator` @@ -995,14 +1191,19 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: `aggregator`. BMI's basis is omitted. The three groups can arrive together or alone. JSON null and a returned zero and a missing field stay three different results -- a dietary series and `number_of_alcoholic_beverages` are source reports, - not samples, not provider summaries, and not nutrition entries. A cycle +- a dietary series, `number_of_alcoholic_beverages`, and `hydration` are + source reports, not samples, not provider summaries, and not nutrition + entries. Raw and day hydration stay out of the eight range calculations + and out of `provider-period-summary`. A device id on the hydration row + does not create a receipt. A cycle code, a predicted length, and a pregnancy snapshot stay on the anchor. A cycle that starts in range and ends later keeps that end. A cycle that starts later is not stored, and the read can still complete. Birth date, gender, and sex are source reports. Gender is not copied into the - athlete profile. A matching `user_id` is not stored. A different - `user_id` refuses the page. The athlete profile is unchanged + athlete profile. A matching `user_id` is not stored. A different, + absent, null, or non-string `user_id` on the HTTP object refuses the + page. The canonical envelope without `user_id` imports. The athlete + profile is unchanged - step 5 keeps an old summary's id, number, unit, `data_json`, import key, revisions, and tombstone. A numeric summary can be corrected to numberless and back. A half-null value and unit is refused. A sample @@ -1010,7 +1211,12 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: accept the numberless summary, the numberless score, and the sample. A meal nutrient that changes from a number to null, then back, keeps one child id. A null body group withdraws that group's children. A refused - page restores the withdrawn child + page restores the withdrawn child. A range calculation that sees a + numeric summary and a numberless summary uses only the numeric row. + The same is true for a score, on the instant reader and the period + reader. An all-numberless set adds no inputs and does not fail the + calculation. After value, then null, then value, the calculation sees + the current number and not the withdrawn one - two distinct sensor triples become two sources. Device A is stored, then a separate operation contains only device B at the same triple, type, and instant, with a different value. The operation fails. The current point, @@ -1070,8 +1276,12 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: - `page-sleep.json` becomes a sleep session. A manual workout and its automatic neighbor from one response stay two records. The automatic workout is a session on the device source. The manual workout is a - source report with the original object and no device receipt. Export and - import keep both. `page-raw.json` is stored. + source report with the original object and no device receipt. A workout + with `entry_source` `unknown`, null, or omitted is an `unknown_workout` + report. It is not a session and not a manual report. The same server id + arriving later as `automatic` refuses the page, and the stored report + stays. Export and import keep the pair that was accepted. + `page-raw.json` is stored. `page-5min.json` is left out. RMSSD and SDNN stay different quantities - a changed end time keeps the record id and increases the revision - a `__proto__` supplied field fails the page @@ -1097,11 +1307,16 @@ Migration tests, in the build gate: call. `ath migrate` previews without writing. It still previews, backs up, and asks, as D124 requires. The target it names is `2.2.0` - a confirmed migrate backs up, then sets the record version to `2.2.0`, - SQL schema 5, and `user_version` 5. Record ids, revisions, deletions, and - attachments are unchanged. A second migrate does nothing + SQL schema 5, and `user_version` 5. Record ids, revisions, deletions, + attachments, import keys, reporting periods, and device receipts are + unchanged. `PRAGMA foreign_key_check` is empty. A deleted row and its + history are still there. A second migrate does nothing. After migrate, + a source report can be created, revised, checked, exported, restored, + and repaired from `data_json` without becoming a measured type - `ath init` creates a database that is already `2.2.0`, SQL schema 5, and - `user_version` 5, and `ath check` exits 0. Step 4 still writes `2.1.0` and - schema 4, and the create path runs step 5 after that + `user_version` 5, and `ath check` exits 0. The fresh database accepts a + source report. Step 4 still writes `2.1.0` and schema 4, and the create + path runs step 5 after that - databases at `1.0.0` and `2.0.0` still open for migrate. Packages at `2.0.0` and `2.1.0` still import. `spec/sql/migrations/004-version-2-1.sql` and the folders `schema/2.0.0/` and `schema/2.1.0/` stay byte-identical @@ -1181,7 +1396,8 @@ is in the build pull request. add HTTP to them. `mapping.rs` gains the counts, the open-wearables binding check, and the preservation writes in section 2. `store.rs` gains the partial-update refusal, the three source operations in section 3, and the - sample and paired-null writes in section 6. Splitting the files stays out. + sample, source-report, withdrawal, null-filter, archive, and paired-null + writes in section 6. Splitting the files stays out. - `persist.rs` can still store a supplied field named `__proto__` if a caller uses `ath-core persist` directly. The pull does not use that path. - The mapping path rule is already one function. There is no duplicate to @@ -1220,15 +1436,17 @@ Risks: is to avoid copying the key into the record. The build, after approval, is one pull request in this order. First the -schema and step 5: the period type, the `aggregator` basis, the sample -series quantities in the appendix table, the `source_report` type and -table, the paired null value and unit, and the time-unknown summary. Then the store and record paths in section 6. Then the mapping -engine and `mappings/open-wearables.md`. Then the reads, the cycle filter, -the smaller-page split, and the tests in section 7. The laptop card and the phone proof are +schema and step 5: the root `record_type` check, the period type, the +`aggregator` basis, the sample series quantities in the appendix table, +the `source_report` type and table, the paired null value and unit, and +the time-unknown summary. Then the store, the calculation null filter, +the archive transaction, and the record paths in section 6. Then the +mapping engine and `mappings/open-wearables.md`. Then the reads, the +cycle filter, the smaller-page split, and the tests in section 7. The laptop card and the phone proof are part of that same pull request. This plan pull request has no media. The maintainer approves or rejects this plan before any build. D198 through -D205 are the proposal. They are not adopted. Reviews of earlier heads were +D206 are the proposal. They are not adopted. Reviews of earlier heads were incorporated here. None of those reviews approves this revision. The next head needs re-review. An earlier review accepted a migration with no new column, under D152 and D184. That acceptance does not @@ -1236,15 +1454,18 @@ adopt D198. The optional source key adds no column. 1. One number, 2.2.0. Readable sets keep `1.0.0`. Step 5 runs on create and - on migrate. The device receipt adds no column. Step 5 does rebuild - `provider_summaries` and `provider_scores` so a numberless object can omit - `value` and its unit together. Existing ids and rows are copied. A + on migrate. The device receipt adds no column. Step 5 extends the + root check with `source_report` by the copy in section 5, creates + `source_reports`, and rebuilds `provider_summaries` and + `provider_scores` so a numberless object can omit `value` and its unit + together. Existing ids and rows are copied. Foreign keys stay on for + ordinary writes. A `2.1.0` database does not open until `ath migrate`. This release does - not schedule, refresh a token, backfill, or store a cursor (D198, D205). + not schedule, refresh a token, backfill, or store a cursor (D198, D206). 2. Store the returned representations in section 2. Device receipts stay on device sources. Summaries without a device id use their own sensors. Null stays null. A missing response is not called provider-unavailable. - The omissions in section 2 are the ones with a reason (D203, D205). + The omissions in section 2 are the ones with a reason (D203, D206). 3. The key, the selected origin, and the selected user id are rejected in decoded JSON before a page is mapped. Failure text uses a fixed sentence. `ath key clear` with no name still clears only the gateway keys and says @@ -1269,4 +1490,6 @@ optional source key adds no column. partial-update refusal, the receipt and tombstone read, creation with the checked receipt, and the first bind of an existing source that has no history, and the sample, source-report, withdrawal, and paired-null - writes in section 6. Nothing else is added to either file (D202, D205). + writes in section 6, including the null filter in the calculation + readers and the archive transaction. Nothing else is added to either + file (D202, D206). From 01bb6d9e77f7d6c5c74d53e51e108fb01dfe2355 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 7 Nov 2026 03:58:00 +0000 Subject: [PATCH 10/60] Align the 2.2.0 migration, archive, and command-count contracts. Step 5 drops the record views and cross-table triggers around the root rename. Archive eligibility, capsules, and command flags are one rule. Co-authored-by: Michael Whitham --- .../v2.2.0/appendix/open-wearables-api.md | 10 +- build-history/v2.2.0/decisions.md | 107 ++++- build-history/v2.2.0/progress.md | 6 +- build-history/v2.2.0/spec.md | 431 ++++++++++++------ 4 files changed, 398 insertions(+), 156 deletions(-) diff --git a/build-history/v2.2.0/appendix/open-wearables-api.md b/build-history/v2.2.0/appendix/open-wearables-api.md index db0c149b..55601d59 100644 --- a/build-history/v2.2.0/appendix/open-wearables-api.md +++ b/build-history/v2.2.0/appendix/open-wearables-api.md @@ -201,7 +201,7 @@ route files. A limit may still exist in middleware this study did not open. The same commit, `183e8cc4f6de897dbd288c93d49a691f2cf721ae`, was read again for every user data route. The OpenAPI file is `docs/openapi.json`, -`info.version` `0.11.0`. The storage rule is D206. This section records +`info.version` `0.11.0`. The storage rule is D207. This section records what the source shows. `SeriesType` is the enum in `backend/app/schemas/enums/series_types.py`. @@ -209,7 +209,9 @@ Each entry in `SERIES_TYPE_DEFINITIONS` is an id, a name, and a unit. `heart_rate` is `bpm`. `latitude` and `longitude` are `degrees`. The raw path in `timeseries_service.py` copies `recorded_at`, `zone_offset`, the type, the value, and `window_seconds`. It does not set `period_end` or -`computed_by`. +`computed_by`. The response `metadata.resolution` is the raw or day +label. A series row does not carry that label. The archive capsule +copies it. `_aggregated_timeseries` handles `1min`, `5min`, `15min`, and `1hour`. It sets `window_seconds` from `BUCKET_SIZES` and does not set `period_end`. @@ -252,7 +254,7 @@ listed rows. The personal-record response fields are `birth_date`, ## Contract read on 7 November 2026 The same commit was read again for the summary, score, meal, cycle, body, -and personal-record contracts. D206 is the storage rule. This section +and personal-record contracts. D207 is the storage rule. This section records the source facts that rule uses. `SERIES_TYPE_DEFINITIONS` has 141 entries. @@ -262,7 +264,7 @@ series are `heart_rate_variability_rmssd`, `heart_rate_variability_sdnn`, `oxygen_saturation`, `heart_rate_recovery_one_minute`, `vo2_max`, `garmin_stress_level`, and `garmin_body_battery`. -The table below is the mapping for all 141 series. D206 is the storage rule. +The table below is the mapping for all 141 series. D207 is the storage rule. `input_value` and the input unit are the server's number and unit. `standard_value` equals `input_value` except where the conversion is `divide by 100`. A day row uses the day record in the last column. It is diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index 56ed0618..a3902ec0 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -9,7 +9,7 @@ D-number. ## D198. Version 2.2.0 is one manual pull, and the program and the record share that number -`ath pull openwearables` reads the stored representations D206 lists from an +`ath pull openwearables` reads the stored representations D207 lists from an Open Wearables server the person runs, for one user and one range they name. The command is manual. The person runs it. The program does not schedule it, retry a failed request, or sign the person in to a device maker. @@ -18,9 +18,12 @@ The program, the record, and the database become `2.2.0` together. D152 made those one number. D184 kept that rule. Migration step 5 stores `2.2.0` and SQL schema 5. It adds no column to an existing table. It rebuilds `provider_summaries` and `provider_scores`, and it creates -`source_reports`, as D205 describes. Existing rows keep their numbers. Step 4 is not edited -(D165). A new database runs step 5 after step 4 and before `user_version` is -set. `applyMigrationStep` handles target 5. The migration chain, the SQL +`source_reports`, as D205 describes. D207 drops the record views and +the two cross-table triggers around the root rename. Existing rows keep +their numbers. Step 4 is not edited +(D165). A new database closes the step 4 transaction, then runs step 5, +which sets `user_version` 5. `applyMigrationStep` handles target 5 +outside `withWriteTransaction`. The migration chain, the SQL contract generator, and the drift check gain that step. The package exports point at `schema/2.2.0/`. `READABLE_DATABASE_VERSIONS` and `ACCEPTED_RECORD_VERSIONS` keep `1.0.0`, `2.0.0`, and `2.1.0`, and gain @@ -265,14 +268,19 @@ page follows D189. A committed page does not mean the pull is complete. The command previews unless `--yes` is present. `--json` does not write, with or without `--yes`, matching `ath import --mapping`. `--yes` without -`--json` writes each page as that page succeeds. +`--json` writes each protected page as that page succeeds. A refused +page is not a success. The pull-only archive in D207 is a separate +transaction. The child returns one bounded outcome for the mode it ran. A preview, -including public `--json`, has `written` false, committed zeros, estimated -counts, and `range_complete` false. A confirmed `--yes` has the actual -committed counts. `written` is true only when that command committed a new -or revised record. A successful repeat has `written` false and -`database_changed` false. The database is unchanged. The parent renders the +including public `--json`, has `written` false, protected and archive +committed zeros, estimated counts, and `range_complete` false. A +confirmed `--yes` has the actual protected and archive counts. `written` is +true when a protected transaction in the command created or revised a +counted record. An archive does not make it true. `database_changed` is +true when a protected transaction or an archive transaction committed a +change. A successful repeat of an unchanged command has both flags false. +The parent renders the confirmed outcome as text. It renders the preview outcome as public JSON. On a partial failure the child returns the confirmed outcome and then exits nonzero. The parent renders the text before it uses that status. @@ -419,7 +427,7 @@ Rejected alternatives: D204 supersedes the classification, source identity, time, score, endpoint, and size sentences in this proposal. D205 supersedes D204 where they disagree. The decision to keep the returned health data in this pull -stands. Where a paragraph below disagrees with D206, D206 is the proposal. +stands. Where a paragraph below disagrees with D207, D207 is the proposal. This supersedes the earlier draft, inside D198 and D199, that left day values, the heart-rate stream, sleep and recovery summaries, meals, and @@ -553,8 +561,9 @@ through the device check, that compare null-source rows by type and timestamp alone, that leave a refused original unstored in every case, that map `heart_rate_recovery_one_minute` to a quantity of that same name, and that call `hydration` a measurement sample. The units, day -windows, sleep bounds, and reported-record direction stay. Where this -proposal disagrees with D206, D206 is the proposal. +windows, sleep bounds, and reported-record direction stay. D207 +supersedes D206 where they disagree. Where this proposal disagrees +with D207, D207 is the proposal. This corrects D204. The returned health data stays in this pull. The specification's section 2 and the appendix series table are the contract. @@ -659,6 +668,15 @@ Rejected alternatives: ## D206. The new record type, numberless inputs, and refused originals stay separable +D207 supersedes the sentences below that leave the record views in place +during the rename, that set `written` false for an archive without +defining `database_changed`, that archive a page from the first error, +that hash the series row without its resolution, and that give a +null-source reported series both the report sensor and the unattributed +sensor. The root check, the numberless readers, and the reported-record +direction stay. Where this proposal disagrees with D207, D207 is the +proposal. + This corrects D205. The returned health data stays in this pull. The specification is the contract. @@ -669,7 +687,9 @@ not edit migrations 001 through 004, and it does not drop the check. Ordinary writes keep foreign keys on. The migration connection may turn them off only before its own transaction, rebuild `records` and the two nullable typed tables by copy, rename, and recreate, then require -`foreign_key_check` and `integrity_check` before commit. A drop of +`foreign_key_check` and `integrity_check` before commit. D207 drops the +two record views and the two cross-table triggers before that rename and +recreates them unchanged. A drop of `records` inside the ordinary foreign-key transaction is not the procedure. Fresh init and a populated, deleted, history-bearing upgrade both have to accept a source report afterward. @@ -701,7 +721,9 @@ id with a different kind refuses the page. A protected refusal rolls back. For a missing device id on a device-targeted series row, and for unequal null-source payloads of one full match key, a later archive transaction stores kind `original` with -no amount and no device receipt. `written` stays false. The command +no amount and no device receipt. D207 is the page decision, the capsule, +and the command counts. `written` stays false when only the archive +changed. The command exits nonzero. Credential failures, invalid ids, conflicting device ids, legacy history, and kind changes are not archived. Those originals are not kept, because storing them would invent an id or keep a payload the @@ -731,3 +753,58 @@ Rejected alternatives: second transaction with a failed protected-write status. The other refusal reasons stay unstored. +## D207. The migration rename, the command counts, and the archive decision stay consistent + +This corrects D206. The returned health data stays in this pull. The +specification is the contract. + +Step 5 drops `sql_v1_current_records`, `sql_v1_active_records`, and the +two `record_revisions` triggers that read `records` before it drops +`records`. It recreates them from the `001` text after the new root +exists, in the same transaction. Foreign keys are turned off only before +that transaction, on a connection ordinary writes do not reuse. After +every exit the connection reads `foreign_keys` back as on, or it is +closed. A failure before commit restores the old schema, the old rows, +and the old version. `writable_schema` is not used. Files 001 through +004 stay unchanged. + +`written` counts protected creates and revisions across the command. An +archive-only change leaves it false and sets `database_changed` true. +Archive counts are separate from protected counts. A later page does not +clear either. A failed archive transaction keeps the refusal, rolls +itself back, and leaves earlier commits. The pull text for a new +archive-only change is `Protected write refused; N originals archived; +database changed; pull incomplete.` + +The pull classifies the whole page before either transaction. Any veto +on the page forbids the archive, in either row order, including a +`left_out` row that carries the veto. The privacy scan still comes first. +The archive is pull-only. A mapped file import does not gain it. The +archive transaction does not reclassify the page. It does refuse to +revive a deleted archive source or to write a device receipt. + +Each archived series row is a capsule of `resource`, the response +`resolution`, and the unchanged row. The hash is of that capsule. A raw +capsule and a day capsule are different records. A stored capsule that +hashes equal but differs is an archive failure, not a merge. + +A reported series uses only the report sensor, including when `source` +is null. A measured series with `source: null` uses only the unattributed +sensor. Age is a source report with no `field_basis`. + +Rejected alternatives: + +- Leave the views in place until commit. Rejected. SQLite checks them + when the replacement table is renamed, and the missing `records` name + fails that check. +- Count an archive as `written`. Rejected. The protected import failed. + The database change is reported by `database_changed` and the archive + counts. +- Archive whichever error the mapper returns first. Rejected. A later + conflicting device id would then be stored. +- Give a mapped file import the same second transaction. Rejected. The + file has no selected-server privacy context, and the shared mapper + would gain a write the import did not ask for. +- Hash the series row and infer the resolution later. Rejected. The + resolution is on the response, not on the row. + diff --git a/build-history/v2.2.0/progress.md b/build-history/v2.2.0/progress.md index 04aee386..e70d7379 100644 --- a/build-history/v2.2.0/progress.md +++ b/build-history/v2.2.0/progress.md @@ -5,9 +5,9 @@ program, the record, or the database has changed for 2.2.0. | Step | What | Status | |---|---|---| -| 0 | The plan: proposals D198–D206, and the Open Wearables study. D206 corrects the root record check, numberless calculation inputs, recovery scales, required ids, and the archive of a refused original. Still not adopted. The new head needs re-review | written, not approved | -| 1 | Version 2.2.0 and migration step 5. No new column on an existing table. The root check gains `source_report` by the copy in D206. Summary and score values may be omitted in pairs (D198, D206) | not started | -| 2 | `ath pull openwearables` in `ath-core`, with the rewritten mapping (D199, D201, D206) | not started | +| 0 | The plan: proposals D198–D207, and the Open Wearables study. D207 corrects the migration rename, the command counts, and the archive decision. Still not adopted. The new head needs re-review | written, not approved | +| 1 | Version 2.2.0 and migration step 5. No new column on an existing table. The root check gains `source_report` by the copy in D207. Summary and score values may be omitted in pairs (D198, D207) | not started | +| 2 | `ath pull openwearables` in `ath-core`, with the rewritten mapping (D199, D201, D207) | not started | | 3 | Key, server, and user id kept out of the record (D200) | not started | | 4 | Fixture tests, with no live key in CI | not started | | 5 | Generated schema, demo athlete, skill command reference, and the public-data list | not started | diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index b1450784..a40ecb49 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -4,7 +4,7 @@ Status: **plan only. The maintainer has not approved it. Not approved for build. `ath pull openwearables` reads one person's stored health data from an Open Wearables server they run, and writes it with the mapping this release -ships. The proposals are D198 through D206 in +ships. The proposals are D198 through D207 in [decisions.md](decisions.md). They are not adopted. The evidence is [appendix/open-wearables-api.md](appendix/open-wearables-api.md), checked on 6 and 7 November 2026. @@ -106,16 +106,24 @@ section 3, which says a rerun cannot repair the device id. It does not print the success sentence. The protected transaction of a refused page makes no database changes. Records already stored stay, including their revisions. An archive, when -section 2 allows one, is a later transaction. It does not print the -success sentence, and it does not set `written`. An empty ranged result -can still store the personal record or the body snapshot. Those writes are -counted. They are not ranged rows. `written` is false when the confirmed -command changed nothing. The database is unchanged. That is not a claim that -the database has no rows. +section 2 allows one, is a later pull-only transaction. It does not print +the success sentence. `written` is true when any protected transaction +in this command created or revised a counted record. An archive does not +make `written` true. `database_changed` is true when any protected +transaction or any archive transaction in this command committed a +change, including the first insert of the archive source. A later page +does not reset either flag or the counts from an earlier page. An empty +ranged result can still store the personal record or the body snapshot. +Those writes are counted as protected rows. They are not ranged rows. +`written` is false and `database_changed` is false when the confirmed +command committed no protected change and no archive change. Rows stored by an earlier +command can still be there. Public `--json`, with or without `--yes`, is only the preview outcome below. -`written` is false. `committed` is zero. `estimated` holds the page-local -estimates. `range_complete` is false. `reads_finished` is true only when +`written` is false. `database_changed` is false. `committed` and +`archive_committed` are zero. `estimated` holds the protected +page-local estimates. `estimated_archive` holds the archive estimates. +`range_complete` is false. `reads_finished` is true only when every read completed. The read status token is `not_attempted`, in this object and in the text. The object has no key, server, user id, or request path. @@ -125,6 +133,7 @@ server, user id, or request path. "from": "2026-01-01", "to": "2026-01-07", "written": false, + "database_changed": false, "range_complete": false, "reads_finished": false, "reads": { @@ -139,6 +148,12 @@ server, user id, or request path. "committed": { "sleep_session": { "new": 0, "changed": 0, "unchanged": 0 } }, + "estimated_archive": { + "source_report": { "new": 0, "changed": 0, "unchanged": 0 } + }, + "archive_committed": { + "source_report": { "new": 0, "changed": 0, "unchanged": 0 } + }, "left_out": { "total": 0, "examples": [] } } ``` @@ -148,16 +163,25 @@ and source reports. The example above is shortened. It is the preview outcome. A preview does not say a snapshot was stored. The child returns a different outcome for `--yes` without `--json`. That -outcome has the actual `committed` counts, `database_changed`, -`range_complete`, and `snapshots_complete`. `range_complete` is true when -the ranged reads finished. `snapshots_complete` is true when the personal -record and the body snapshot finished. `written` is true only when that -confirmed command committed at least one new or revised record. A -successful repeat has `written` false, `database_changed` false, both -flags true, and unchanged counts. A failed ranged page has -`range_complete` false. A failed snapshot after a finished range has -`range_complete` true and `snapshots_complete` false. The parent prints -sentences from this outcome. It does not print the outcome as public JSON. +outcome has the actual `committed` counts, the actual `archive_committed` +counts, `database_changed`, `protected_write`, `archive`, +`range_complete`, and `snapshots_complete`. `committed` counts protected +records only. `archive_committed` counts archive records only, including +a created archive source, counted once. A record is in one of those +maps. `new`, `changed`, and `unchanged` are the created, revised, and +unchanged counts in each map. `range_complete` is true when the ranged reads +finished and no protected page in those reads was refused. `snapshots_complete` +is true when the personal record and the body snapshot finished. `written` +is true when any protected transaction in this command created or revised +a counted record. A command that only repeats unchanged protected pages, +and that commits no archive change, has `written` false, +`database_changed` false, both completion flags true, and unchanged +protected counts. An earlier change keeps both flags true. A failed ranged page has `range_complete` false. A +failed snapshot after a finished range has `range_complete` true and +`snapshots_complete` false. The parent prints sentences from this outcome. +It does not print the outcome as public JSON. Public `--json`, with or +without `--yes`, commits neither the protected transaction nor the +archive transaction. `--date` stays required only for `garmin`. `--from` and `--to` are required only for `openwearables`, and they are flags, not environment variables. @@ -190,12 +214,14 @@ gateway commands they are today. ## 2. What this pull stores -D206 is the storage rule. D203 keeps these values in this pull. D204 +D207 is the storage rule. D203 keeps these values in this pull. D204 corrected source, time, and score direction. D205 corrects units, day windows, sleep bounds, identity encoding, reported records, and child withdrawal. D206 corrects the root record type, numberless calculation inputs, recovery scales, required ids, workout provenance, hydration, -and the archive of a refused original. An earlier draft +and the archive of a refused original. D207 corrects the migration +dependencies, the command counts, archive eligibility, the archive +capsule, and null-source report routing. An earlier draft left day values, the heart-rate stream, summaries, and workout segments for a later version. That draft is superseded. File imports stay. The Garmin pull stays. A Junction pull is proposed as 2.3.0. Automatic sync, retries, token refresh, and backfill are proposed as @@ -315,19 +341,20 @@ The array shapes are: - Summary or body: `["summary", family, provider, device, device_type, source, device_id]` - Meal, cycle, manual workout, or unknown workout: `["event", family, provider, device, device_type, source, device_id]` -- Reported series: `["report", resolution, provider, device, device_type, source, device_id]`. `resolution` is `raw` or `1day`. +- Reported series, including a row whose `source` is null: `["report", resolution, provider, device, device_type, source, device_id]`. `resolution` is `raw` or `1day`. - Health score: `["score", provider]`. `provider` is the top-level author, or JSON `null` when that field is null. The input `source` is not in the array. -- Timeseries with `source: null`: `["unattributed", "timeseries"]` +- Measured series with `source: null`: `["unattributed", "timeseries"]`. A reported series does not use this sensor. - Archive originals: `["archive"]` - Personal record: `["personal_record"]` The writer is `source.provider` when that string is nonempty. A health score uses its top-level `provider` when that string is nonempty. The -personal record, a null-provider score, and a null-source timeseries use -the writer `open_wearables`. That word names this route. It is not a -device maker and it is not an invented author. The vendor is omitted. +personal record, a null-provider score, a measured series with +`source: null`, and a reported series whose provider is missing use the +writer `open_wearables`. That word names this route. It is not a device +maker and it is not an invented author. The vendor is omitted. `source_type` is `connector`. These sensors do not establish `device_binding`. Their history is not history of a device source. @@ -335,15 +362,17 @@ A health score never uses the unattributed timeseries sensor. A change of its input `source` from null to an object, or the reverse, revises the same score. The writer, the sensor, and the score id stay put. -A null-source timeseries row has no sample id. The comparison is the full -match key: writer, sensor, `timeseries`, resolution, series type, UTC -timestamp, and, for a day row, `period_end`. A raw row at midnight and a -day window that starts at that midnight are different keys. Two rows with -one key are one normalized record only when the whole returned row is -equal. A different value, in the same page or a later confirmed call, -refuses the protected transaction. The stored normalized row stays. The -text says the rows are ambiguous and a rerun cannot choose the normalized -row. `ath correct` remains the owner's way to replace that row. Preview +A null-source timeseries row has no sample id. A measured row uses the +unattributed sensor. A reported row uses the report sensor and does not +also get an unattributed record. The comparison is that one full match +key: writer, sensor, resource, resolution, series type, UTC timestamp, +and, for a day row, `period_end`. A raw row at midnight and a day window +that starts at that midnight are different keys. Two rows with one key +are one normalized record only when the whole returned row is equal. A +different value, in the same page or a later confirmed call, refuses the +protected transaction. The stored normalized row stays. The text says the +rows are ambiguous and a rerun cannot choose the normalized row. `ath +correct` remains the owner's way to replace that row. Preview pages roll back, and the command memory holds device-binding facts only. A preview therefore does not claim to see a null-source conflict from an earlier preview page. A confirmed `--yes` page does see an earlier @@ -362,8 +391,8 @@ appendix table, fails before any request. | Unknown, null, or omitted `entry_source` | `{ "workout": data }` | `source.provider` | `ow1` event | `source_report` `unknown_workout`, server id | none. The original object is the record | | Measured raw series with `device_id` | timeseries object, `resolution` `raw` | `source.provider` | legacy device | the raw class in the appendix, D181 time key | none | | Measured raw or day series, source present, no `device_id` | timeseries object | `source.provider` | legacy device, then the protected transaction is refused | no measured row. Section 2 may archive the original | none | -| Reported series, with or without `device_id` | timeseries object | `source.provider`, or `open_wearables` when that string is missing | `ow1` report | `source_report`, appendix subject | none. The amount is the reported pair | -| Raw series, `source` null | timeseries object | `open_wearables` | `ow1` unattributed | the raw class, full match key | none. An unequal payload refuses the protected transaction and may be archived | +| Reported series, source present or null | timeseries object | `source.provider`, or `open_wearables` when that string is missing | `ow1` report only | `source_report`, appendix subject | none. The amount is the reported pair | +| Measured series, `source` null | timeseries object | `open_wearables` | `ow1` unattributed only | the raw class, full match key | none. An unequal payload refuses the protected transaction and may be archived | | Day series | timeseries object, `resolution` `1day` | same as the raw row | same as the raw row | window form in the appendix. Key adds `1day` and `period_end` | none | | Sleep, activity, or recovery summary | `{ "sleep_summary": data }`, `{ "activity_summary": data }`, or `{ "recovery_summary": data }` | `source.provider` | `ow1` summary | `source_report` subject `object`, date | one measured child per numeric field, field path in the key | | Body | the object | umbrella `source.provider`, or `open_wearables` when it is missing | `ow1` summary, family `body` | `source_report` subject `object` | slow-changing weight, height, fat, and muscle are time-unknown provider summaries; averaged heart rate and HRV use the server window; latest temperature and blood pressure use their own times; age and BMI are source reports | @@ -520,7 +549,8 @@ Body is the current snapshot. It is not the requested range. The anchor is a `source_report`. Weight, height, fat, and muscle are provider summaries with `timestamp_missing_reason: not_provided_by_source`, no `recorded_at`, and no borrowed window. Age and BMI are `source_report` -children. Age is calculated. BMI is not labeled measured. The averaged +children. Age is calculated by the service. The child is a source report +and has no `field_basis`. BMI is not labeled measured. The averaged heart-rate and HRV values are provider summaries on the server's `period_start` and `period_end`. Those bounds are not copied onto the slow-changing fields. Each latest field uses its own measured-at time @@ -554,51 +584,92 @@ not withdraw its children. A refused page rolls the withdrawals back with the page. A protected refusal rolls that transaction back. It does not become a -successful pull. Two refusal reasons may then start a separate archive -transaction: a device-targeted series row whose source has no device id, -and a null-source row whose full match key already has a different -payload, including two different payloads in one page. The archive runs -only after the protected rollback, and only after the privacy scan has -accepted the page. It is not a replay of the refused statements. - -The archive contains every series object on that refused page. A reported -row is kept there as an original, not as its structured amount. A later -clean page may store that structured report. The archive does not revise -it. The archive source uses writer `open_wearables`, sensor `ow1:["archive"]`, +successful pull. The archive is pull-only. `ath import --mapping` uses +the same protected envelopes and the same refusal, and it does not start +the archive transaction. A refused file import keeps no original. + +Before either transaction, the pull reads the whole page. The order of +the rows does not matter. The privacy scan is first. A hit starts +neither transaction. The pull then classifies every row, including a row +that would be `left_out`. One veto anywhere forbids the archive for the +whole page. The vetoes are a conflicting device id, a deleted source, an +unbound legacy history, a malformed or missing required UUID, a workout +kind change, a malformed receipt, and a supplied field whose name is not +allowed. A deleted-source row that the mapping would leave out is still +a veto. A query-bucket `left_out` row is not a veto and is not archived. +A timeseries row has no required UUID. Its missing device id is not that +veto. + +The archive is allowed only when the page has no veto and it has one of +these eligible facts: a device-targeted series row whose source has no +device id, or a null-source series row, measured or reported, whose full +match key has a different payload in this page or already stored. An +eligible row does not authorize the archive when a veto is +also on the page. The decision is this snapshot. It includes a read of +each stored null-source match key before the protected write. The +archive transaction does not classify the page again. Its only new check +is that the archive source is not deleted. + +The archive runs only after the protected rollback. It stores one capsule +per returned series row on that page, not a query-bucket row and not a +non-series row. A workout or a meal on that page is not a capsule. A +later page that does not refuse can store it. The capsule is: + +```json +{ + "resource": "timeseries", + "resolution": "raw", + "row": {} +} +``` + +`resolution` is the response's `metadata.resolution`, copied. It is not +inferred from `window_seconds` or `period_end`. `row` is the original +series object, unchanged. The capsule is the same object for a pull and +for a later native export and import. Kind is `original`. There is no +`amount` and no reporting period. The number stays inside `row`. The +match key is the writer, the archive sensor, and the SHA-256 of the +canonical capsule, with keys sorted and no extra whitespace. The same +capsule is one record. A raw capsule and a day capsule are different +even when the row bodies match. The hash is not a sample id. This plan +does not claim that two different capsules cannot hash equal. If the key +is already stored and the stored capsule differs, the archive transaction +fails and does not revise the old capsule. + +The archive source uses writer `open_wearables`, sensor `ow1:["archive"]`, and `source_type` `connector`. The receipt operations are not called, and -`device_binding` is not written. Each original is one source report of -kind `original`, with no `amount` and no reporting period. The number -stays inside `supplied_fields`. The match key is the writer, that sensor, -the resource, and the SHA-256 of the canonical JSON object, with keys -sorted and no extra whitespace. That hash is not a sample id and it is -not the measured key. The same bytes are one archive record. Different -bytes are another record. The pull does not revise an archive into a -measurement, and it does not revise a measurement from an archive. - -The outcome names `protected_write` as `committed` or `refused`, and -`archive` as `not_attempted`, `stored`, `unchanged`, or `failed`. -`written` stays false when only the archive changed. When the protected -write was refused, the success sentence is not printed and the exit is -nonzero. The text says the protected write was refused and how many -originals were archived. A preview rolls both -transactions back and says `would refuse` and `would archive`. It does -not say the original was stored. - -These pages are not archived. A credential hit never reaches either -transaction. A missing or invalid required UUID is not given a hash -identity. A conflicting device id is not stored under another source, -because that would keep the rejected device's payload. A deleted source, -an unbound legacy history, and a workout kind change are not archived. -Those originals are not retained. That is a safety limit: filing them -would look like an accepted import or would invent an id. - -On a confirmed command, a later page sees committed measurements and -committed archives. A repeat of the same conflicting payload refuses the -protected write again, leaves the archive unchanged, and sets `written` -false. A third payload adds an archive record and still does not change -the normalized row. A page of only reported series, with no device id, -is an ordinary source-report write. It is not an archive, and it does -not refuse the device check. +`device_binding` is not written. If that source is deleted, the archive +transaction fails and does not insert a new source. A later page sees the +committed archive. It does not see a deletion that happened after the +snapshot except for this one check. + +`protected_write` is `committed` or `refused`. `archive` is +`not_attempted`, `stored`, `unchanged`, or `failed`. `committed` is the +protected counts. `archive_committed` is the archive counts. A record is +not in both. `written` follows section 1 and is not set by the archive +alone. `database_changed` is true when this command's archive transaction +committed a new source or a new capsule, and it stays true if an earlier +page already changed the database. A later refusal does not clear the +earlier counts. When the archive stores N new capsules and the command +has no protected change, the text is `Protected write refused; N +originals archived; database changed; pull incomplete.` A repeat that +stores nothing says `0 originals archived` and says the database is +unchanged only when no earlier page changed it. The unchanged text is +`Protected write refused; 0 originals archived; database unchanged; pull +incomplete.` After an earlier change it is `Protected write refused; 0 +originals archived; database changed; pull incomplete.` A third payload +adds its own new count and does not replace the earlier capsule. If the +archive transaction fails, it rolls back entirely, `archive` is `failed`, +the protected refusal remains, earlier commits remain, the success +sentence is not printed, and the exit is nonzero. The text is `Protected +write refused; archive failed; database unchanged; pull incomplete.` +After an earlier change it says `database changed`. It does not print a +partial archive count. A preview, including `--json` and `--json --yes`, +rolls both transactions back and commits neither. + +A page of only reported series, with no device id, is an ordinary source +report write. It is not an archive, and it does not refuse the device +check. A normalized row is not revised from an archive. A provider summary or provider score may omit `value` only together with its unit. One without the other is refused. Step 5 rebuilds both typed @@ -910,27 +981,65 @@ attachments, reporting periods, and the other child tables, use be on. A `DROP TABLE records` there would fail or cascade through the children. Step 5 does not do that. -The runner arm for target 5, and the create path after step 4, open the -work before their write transaction and set `PRAGMA foreign_keys=OFF` -only on that connection. Inside one transaction they create -`records_next` with the old columns and the check extended by -`source_report`, copy every root row, drop `records`, and rename -`records_next` back to `records`. They do the same for -`provider_summaries` and `provider_scores`, copying deleted rows and -keeping record ids, `data_json`, import keys, revisions, and periods, -with value and unit nullable together. They create `source_reports` and -its type trigger. They recreate the indexes and the triggers that were -defined on `records`, using the text already in `001`. Views stay, -because they name `records` and the name is restored before commit. -Then `PRAGMA foreign_key_check` and `PRAGMA integrity_check` must be -empty and `ok`. Only then does the transaction commit, and the -connection turns foreign keys back on. A failed check rolls the -transaction back and leaves the live file unchanged. The D124 backup -still happens before this step. Device receipts stay in the copied -source JSON. They are not rewritten. - -A new database runs that step 5 path after step 4 and before the -`user_version` pragma. `applyMigrationStep` gains this arm for target 5 +The create path finishes steps 1 through 4 and closes that transaction +before step 5. `installInitialSchema` does not run step 5 inside the +transaction that requires foreign keys to be on. Target 5 does not use +`withWriteTransaction`. + +Step 5 uses one connection that ordinary writes do not reuse. Before +`BEGIN`, it sets `PRAGMA foreign_keys=OFF` and reads the pragma back. The +value must be 0. Turning foreign keys off does not turn off the schema +check SQLite runs during `ALTER TABLE`. `sql_v1_current_records` and +`sql_v1_active_records` select from `records`. The triggers +`record_revisions_record_type_matches_parent_insert` and +`record_revisions_record_type_matches_parent_update` are defined on +`record_revisions` and also read `records`. Dropping `records` does not +drop them. A rename while they still point at a missing `records` fails. +`writable_schema` is not used. + +Inside that one transaction the order is fixed. + +1. Drop `sql_v1_current_records` and `sql_v1_active_records`. +2. Drop the two cross-table triggers named above. +3. Create `records_next` with the old columns and the check extended by + `source_report`. Copy every root row. Drop `records`. Rename + `records_next` to `records`. +4. Rebuild `provider_summaries` and `provider_scores` the same way. + Copy deleted rows. Keep record ids, `data_json`, import keys, + revisions, and periods. Value and unit may be null together. + Recreate `provider_summaries_lookup_idx` and + `provider_scores_lookup_idx` from the text in `001`. No view and no + trigger in `001` names those two tables. A generated object whose + text names one of them is dropped before that rebuild and recreated + from the same text afterward. There is no search of the whole schema. +5. Recreate `records_record_type_idx` and the triggers defined on + `records`, from the text in `001`: + `records_current_revision_must_exist`, + `records_deleted_flag_must_match_deletion_row`, + `record_erasure_blocks_current_record_insert`, and + `record_erasure_blocks_current_record_update`. +6. Recreate the two views and the two cross-table triggers from that + same text, unchanged. +7. Create `source_reports` and its type trigger. +8. `PRAGMA foreign_key_check` is empty and `PRAGMA integrity_check` is + `ok`. +9. Set the version rows and `user_version` 5. + +`sql_v1_database_info`, `sql_v1_record_revisions`, and +`sql_v1_record_deletions` do not name `records`, so they stay through the +gap. Then the transaction commits. After commit, and after a rollback or +a thrown error, the connection sets `PRAGMA foreign_keys=ON` and reads it +back. The value must be 1. If that read fails, the connection is closed +and is not reused. A later ordinary open still refuses to write while +foreign keys are off. A failure before commit restores the views, the +cross-table triggers, the old check, the rows, and the version. The D124 +backup is already on disk. Device receipts stay in the copied source +JSON. They are not rewritten. + +A new database closes the step 4 transaction, then runs this step 5 path. +Step 9 sets `user_version`. If step 5 fails during init, the closed step +4 database remains, foreign keys are on, and init reports failure. The +views are not left dropped. `applyMigrationStep` gains this arm for target 5 and does not use `withWriteTransaction` for it. `MIGRATION_CHAIN` in `src/db/sql-contract.ts`, `scripts/generate-sql-contract.ts`, and `scripts/check-schema-drift.ts` gain the step. `package.json` exports and `tests/v1-package-exports.test.ts` point @@ -1027,14 +1136,18 @@ before the limit, the count, the grouping, and the numeric decode. A null is not stored as zero and is not replaced by an older revision. The session-summary branch of `read_period` uses the same filter on the extracted number and unit. Formulas and source grouping stay as they are. -The archive insert is the separate transaction in section 2. It does not -call the receipt operations. No other store behavior changes. `ath correct`, +The archive insert is the pull-only transaction in section 2. It is not +inside `apply_mapping`, and a mapped file import does not call it. It does +not call the receipt operations. No other store behavior changes. `ath correct`, package restore, and an accepted package merge stay whole-record owner writes. They are named in section 3 so the binding survives a 2.2.0 round trip. They are not a new importer. The pull sums only `sleep_session`, `workout_session`, `point_measurement`, `measurement_sample`, `provider_summary`, -`provider_score`, and `source_report`. A committed page adds those counts to the actual committed -result. A rolled-back preview page adds them to `estimated`. It does not add +`provider_score`, and `source_report`. A committed protected page adds +those counts to `committed`. A committed archive page adds its counts +only to `archive_committed`. A rolled-back preview page adds its +protected estimates to `estimated` and its archive estimates to +`estimated_archive`. It does not add `outcome` across pages. `outcome` counts the source-device row in the same group. Filtering that row out of the totals does not make a preview equal a write. Each preview page is rolled back, so page two does not see page one. @@ -1083,7 +1196,7 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: - the same session id on two pages, changed payload: the preview estimate counts two new rows, and `--yes` counts one new and one changed - a valid page, then a failing page, under `--yes`. The failure is one of a - 401, a 429, a repeated or null cursor, an invalid row, or a minimum page + 401, a 429, a repeated or null cursor, a vetoed page, or a minimum page that is still over 8 MiB. Page 1 remains. Page 2 adds no rows and no revisions. No later read runs. The exit is nonzero. The success sentence is absent. The text gives the retained counts. The same command run again stores no second copy @@ -1154,21 +1267,49 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: different ids stay two records. Two summary fields on one date stay two records. A page with one bound heart-rate row and one same-triple row whose `device_id` is missing refuses the protected page. Neither row - is stored as a measurement. The archive stores both originals, with no - amount and no device receipt. A later page that has only the valid row - stores that measurement. The archive remains a different record. Import - then pull of the missing-id pair refuses the same way. A sleep id that + is stored as a measurement. The pull archive stores both series rows + as capsules, with `resolution` copied from the response and no device + receipt. A mapped file import of that page refuses and stores no + capsule. A later pull page that has only the valid row stores that + measurement. The capsule remains a different record. Export and native + import keep the resolution. A raw capsule and a day capsule of the same + row body stay two records. A sleep id that is missing, beside a valid workout, refuses the page before any write and is not archived. The next page still rolls back on its own failure. - A timeseries row with + A measured timeseries row with `source: null` is stored on the unattributed sensor when the payload - matches. A different payload with the same full key, including + matches. A reported row with `source: null` uses the report sensor + only. A different payload with the same full key, including resolution and `period_end`, refuses the protected write and archives - the new original. A raw midnight row and a day window that starts then + the new original. A mapped file import of that changed payload writes + nothing. A raw midnight row and a day window that starts then stay two records. A preview of those two pages does not claim the conflict, because the first preview page was rolled back. A confirmed second page does. - Sensors `ow1:["summary","sleep",null]` and a colon inside a provider +- a missing device id beside a conflicting device id, in either row order, + refuses the protected page and stores no capsule and no revision. The + same veto holds for a deleted source, an unbound legacy history, and a + missing workout UUID on the same page as an eligible row, including when + the deleted-source row would otherwise be `left_out`. A credential on a + neighboring object starts neither transaction. A deleted archive source + is not recreated. An existing device receipt is unchanged. On an empty + database, the first eligible archive sets + `written` false, `database_changed` true, `archive` `stored`, and the + text `Protected write refused; N originals archived; database changed; + pull incomplete.` A repeat on that empty database sets `archive` + `unchanged`, `written` false, `database_changed` false, and the text + `Protected write refused; 0 originals archived; database unchanged; pull + incomplete.` A third payload adds one archive count and + leaves the earlier capsule. An archive-transaction failure on that + empty database sets `archive` `failed`, keeps the refusal, adds no + archive row, leaves `written` false and `database_changed` false, and + uses the text `Protected write refused; archive failed; database + unchanged; pull incomplete.` The same four results after an earlier + committed sleep page keep that page's `written` true, its `committed` + counts, and `database_changed` true. The failure text then says + `database changed`. + Preview and `--json --yes` commit neither transaction +- sensors `ow1:["summary","sleep",null]` and a colon inside a provider name stay different from a shifted tuple. The text `-` is not the same sensor as a missing part. A score whose input source changes from null to an object keeps its id. A personal record repeats. A personal record @@ -1187,15 +1328,22 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: `provider_or_aggregator` - body fetched during a historical range is the current object. Weight with no time has no `recorded_at` and does not use the average window. - A latest value with a null time is stored the same way. Age has basis - `aggregator`. BMI's basis is omitted. The three groups can arrive + A latest value with a null time is stored the same way. Age is a source + report. The service calculates it, and the record has no `field_basis`. + BMI's basis is omitted. The three groups can arrive together or alone. JSON null and a returned zero and a missing field stay three different results - a dietary series, `number_of_alcoholic_beverages`, and `hydration` are source reports, not samples, not provider summaries, and not nutrition entries. Raw and day hydration stay out of the eight range calculations and out of `provider-period-summary`. A device id on the hydration row - does not create a receipt. A cycle + does not create a receipt. A null-source hydration, + `dietary_energy_consumed`, or index row, raw and day, uses only the + report sensor. File import then + pull, pull then file import, and a repeat keep one record and no + receipt. A changed payload refuses the protected write. A pull with no + veto archives that new capsule and leaves the stored report. A mapped + file import writes nothing. The row is not a calculation input. A cycle code, a predicted length, and a pregnancy snapshot stay on the anchor. A cycle that starts in range and ends later keeps that end. A cycle that starts later is not stored, and the read can still complete. Birth date, @@ -1310,13 +1458,22 @@ Migration tests, in the build gate: SQL schema 5, and `user_version` 5. Record ids, revisions, deletions, attachments, import keys, reporting periods, and device receipts are unchanged. `PRAGMA foreign_key_check` is empty. A deleted row and its - history are still there. A second migrate does nothing. After migrate, - a source report can be created, revised, checked, exported, restored, - and repaired from `data_json` without becoming a measured type + history are still there. The upgraded database is populated, including + a tombstone. `sql_v1_current_records` and + `sql_v1_active_records` still return rows. An insert that would make a + revision type disagree with its record is still rejected. A second + migrate does nothing. A failure injected before the step 5 commit + leaves the old views, the two cross-table triggers, the rows, the + version, and `foreign_keys` read back as on. A successful migrate + leaves `foreign_keys` on. A source report can then be created, revised, + checked, exported, restored, and repaired from `data_json` without + becoming a measured type - `ath init` creates a database that is already `2.2.0`, SQL schema 5, and `user_version` 5, and `ath check` exits 0. The fresh database accepts a - source report. Step 4 still writes `2.1.0` and schema 4, and the create - path runs step 5 after that + source report, the same two views are queryable, and a mismatched + revision type is rejected. Step 4 still + writes `2.1.0` and schema 4, and the create path closes that + transaction before step 5 - databases at `1.0.0` and `2.0.0` still open for migrate. Packages at `2.0.0` and `2.1.0` still import. `spec/sql/migrations/004-version-2-1.sql` and the folders `schema/2.0.0/` and `schema/2.1.0/` stay byte-identical @@ -1338,10 +1495,11 @@ store. They cover: variable is still set afterward - `ath key --json` keeps `saved` and `environment` as gateway lists and adds `openwearables.saved` and `openwearables.environment` -- a preview `--json` has `written: false`, committed zeros, `estimated` - counts, and `range_complete: false` +- a preview `--json` has `written: false`, protected and archive + committed zeros, `estimated` counts, and `range_complete: false` - `--json --yes` is a preview. After a later-page failure, and after a - readable range, the database is unchanged + readable range, neither transaction commits and the database is + unchanged `pnpm check:public-data`, `pnpm typecheck`, `pnpm test`, and `pnpm build` pass, and `cargo test` passes, before the build is called done. @@ -1446,7 +1604,7 @@ cycle filter, the smaller-page split, and the tests in section 7. The laptop car part of that same pull request. This plan pull request has no media. The maintainer approves or rejects this plan before any build. D198 through -D206 are the proposal. They are not adopted. Reviews of earlier heads were +D207 are the proposal. They are not adopted. Reviews of earlier heads were incorporated here. None of those reviews approves this revision. The next head needs re-review. An earlier review accepted a migration with no new column, under D152 and D184. That acceptance does not @@ -1458,14 +1616,18 @@ optional source key adds no column. root check with `source_report` by the copy in section 5, creates `source_reports`, and rebuilds `provider_summaries` and `provider_scores` so a numberless object can omit `value` and its unit - together. Existing ids and rows are copied. Foreign keys stay on for - ordinary writes. A + together. Existing ids and rows are copied. Before the root rename, + step 5 drops and later recreates `sql_v1_current_records`, + `sql_v1_active_records`, and the two `record_revisions` triggers that + read `records`. Foreign keys stay on for ordinary writes. The step 5 + connection turns them off only before its transaction and reads them + back on after every exit. A `2.1.0` database does not open until `ath migrate`. This release does - not schedule, refresh a token, backfill, or store a cursor (D198, D206). + not schedule, refresh a token, backfill, or store a cursor (D198, D207). 2. Store the returned representations in section 2. Device receipts stay on device sources. Summaries without a device id use their own sensors. Null stays null. A missing response is not called provider-unavailable. - The omissions in section 2 are the ones with a reason (D203, D206). + The omissions in section 2 are the ones with a reason (D203, D207). 3. The key, the selected origin, and the selected user id are rejected in decoded JSON before a page is mapped. Failure text uses a fixed sentence. `ath key clear` with no name still clears only the gateway keys and says @@ -1491,5 +1653,6 @@ optional source key adds no column. the checked receipt, and the first bind of an existing source that has no history, and the sample, source-report, withdrawal, and paired-null writes in section 6, including the null filter in the calculation - readers and the archive transaction. Nothing else is added to either - file (D202, D206). + readers. The pull command owns the archive transaction and calls the + store. `mapping.rs` does not start it. Nothing else is added to either + file (D202, D207). From d96216e23d466e5b764e41959045e7c443a4ff81 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 7 Nov 2026 04:07:31 +0000 Subject: [PATCH 11/60] Read archive safety facts under the write lock. The protected transaction records the whole-page veto before it mutates. The archive transaction reads those facts again before it writes. A failed init still uses the existing cleanup. Co-authored-by: Michael Whitham --- .../v2.2.0/appendix/open-wearables-api.md | 8 +- build-history/v2.2.0/decisions.md | 84 +++++++-- build-history/v2.2.0/progress.md | 2 +- build-history/v2.2.0/spec.md | 175 +++++++++++++----- 4 files changed, 197 insertions(+), 72 deletions(-) diff --git a/build-history/v2.2.0/appendix/open-wearables-api.md b/build-history/v2.2.0/appendix/open-wearables-api.md index 55601d59..c348b5d8 100644 --- a/build-history/v2.2.0/appendix/open-wearables-api.md +++ b/build-history/v2.2.0/appendix/open-wearables-api.md @@ -201,7 +201,7 @@ route files. A limit may still exist in middleware this study did not open. The same commit, `183e8cc4f6de897dbd288c93d49a691f2cf721ae`, was read again for every user data route. The OpenAPI file is `docs/openapi.json`, -`info.version` `0.11.0`. The storage rule is D207. This section records +`info.version` `0.11.0`. The storage rule is D208. This section records what the source shows. `SeriesType` is the enum in `backend/app/schemas/enums/series_types.py`. @@ -211,7 +211,7 @@ path in `timeseries_service.py` copies `recorded_at`, `zone_offset`, the type, the value, and `window_seconds`. It does not set `period_end` or `computed_by`. The response `metadata.resolution` is the raw or day label. A series row does not carry that label. The archive capsule -copies it. +copies it. D208 writes that capsule only after the locked safety read. `_aggregated_timeseries` handles `1min`, `5min`, `15min`, and `1hour`. It sets `window_seconds` from `BUCKET_SIZES` and does not set `period_end`. @@ -254,7 +254,7 @@ listed rows. The personal-record response fields are `birth_date`, ## Contract read on 7 November 2026 The same commit was read again for the summary, score, meal, cycle, body, -and personal-record contracts. D207 is the storage rule. This section +and personal-record contracts. D208 is the storage rule. This section records the source facts that rule uses. `SERIES_TYPE_DEFINITIONS` has 141 entries. @@ -264,7 +264,7 @@ series are `heart_rate_variability_rmssd`, `heart_rate_variability_sdnn`, `oxygen_saturation`, `heart_rate_recovery_one_minute`, `vo2_max`, `garmin_stress_level`, and `garmin_body_battery`. -The table below is the mapping for all 141 series. D207 is the storage rule. +The table below is the mapping for all 141 series. D208 is the storage rule. `input_value` and the input unit are the server's number and unit. `standard_value` equals `input_value` except where the conversion is `divide by 100`. A day row uses the day record in the last column. It is diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index a3902ec0..4ba56d10 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -9,7 +9,7 @@ D-number. ## D198. Version 2.2.0 is one manual pull, and the program and the record share that number -`ath pull openwearables` reads the stored representations D207 lists from an +`ath pull openwearables` reads the stored representations D208 lists from an Open Wearables server the person runs, for one user and one range they name. The command is manual. The person runs it. The program does not schedule it, retry a failed request, or sign the person in to a device maker. @@ -269,8 +269,8 @@ page follows D189. A committed page does not mean the pull is complete. The command previews unless `--yes` is present. `--json` does not write, with or without `--yes`, matching `ath import --mapping`. `--yes` without `--json` writes each protected page as that page succeeds. A refused -page is not a success. The pull-only archive in D207 is a separate -transaction. +page is not a success. The pull-only archive in D208 is a separate +transaction. It reads the safety facts again before it writes. The child returns one bounded outcome for the mode it ran. A preview, including public `--json`, has `written` false, protected and archive @@ -375,7 +375,8 @@ file with `rm`). `createDatabase` still deletes a half-created file in path collects garbage first. `removeTemporaryDirectory` in `src/db/client.ts` does, and tests use it. Version 2.1.0 spec section 12 left the production paths out of that release and did not assign them a version. They are still -open. They do not run on a pull. This build does not change them. +open. They do not run on a pull. This build does not change them. D208 +rolls a failed step 5 back before this cleanup runs. `crates/ath-core/src/store.rs` is 1034 lines. `mapping.rs` is 1443. `persist.rs` is 1051. The pull is a new module so those files do not grow @@ -427,7 +428,7 @@ Rejected alternatives: D204 supersedes the classification, source identity, time, score, endpoint, and size sentences in this proposal. D205 supersedes D204 where they disagree. The decision to keep the returned health data in this pull -stands. Where a paragraph below disagrees with D207, D207 is the proposal. +stands. Where a paragraph below disagrees with D208, D208 is the proposal. This supersedes the earlier draft, inside D198 and D199, that left day values, the heart-rate stream, sleep and recovery summaries, meals, and @@ -562,8 +563,8 @@ timestamp alone, that leave a refused original unstored in every case, that map `heart_rate_recovery_one_minute` to a quantity of that same name, and that call `hydration` a measurement sample. The units, day windows, sleep bounds, and reported-record direction stay. D207 -supersedes D206 where they disagree. Where this proposal disagrees -with D207, D207 is the proposal. +supersedes D206 where they disagree. D208 supersedes D207 where they +disagree. Where this proposal disagrees with D208, D208 is the proposal. This corrects D204. The returned health data stays in this pull. The specification's section 2 and the appendix series table are the contract. @@ -674,8 +675,8 @@ defining `database_changed`, that archive a page from the first error, that hash the series row without its resolution, and that give a null-source reported series both the report sensor and the unattributed sensor. The root check, the numberless readers, and the reported-record -direction stay. Where this proposal disagrees with D207, D207 is the -proposal. +direction stay. D208 supersedes D207 where they disagree. Where this +proposal disagrees with D208, D208 is the proposal. This corrects D205. The returned health data stays in this pull. The specification is the contract. @@ -721,8 +722,8 @@ id with a different kind refuses the page. A protected refusal rolls back. For a missing device id on a device-targeted series row, and for unequal null-source payloads of one full match key, a later archive transaction stores kind `original` with -no amount and no device receipt. D207 is the page decision, the capsule, -and the command counts. `written` stays false when only the archive +no amount and no device receipt. D208 is when that transaction may +write. D207 is the capsule and the command counts. `written` stays false when only the archive changed. The command exits nonzero. Credential failures, invalid ids, conflicting device ids, legacy history, and kind changes are not archived. Those originals are @@ -755,6 +756,12 @@ Rejected alternatives: ## D207. The migration rename, the command counts, and the archive decision stay consistent +D208 supersedes the sentences below that classify database facts before +either transaction, that leave the archive with only an archive-source +check, and that leave a failed init file in place. The migration graph, +the command counts, the capsule, and the report routing stay. Where this +proposal disagrees with D208, D208 is the proposal. + This corrects D206. The returned health data stays in this pull. The specification is the contract. @@ -776,12 +783,12 @@ itself back, and leaves earlier commits. The pull text for a new archive-only change is `Protected write refused; N originals archived; database changed; pull incomplete.` -The pull classifies the whole page before either transaction. Any veto -on the page forbids the archive, in either row order, including a -`left_out` row that carries the veto. The privacy scan still comes first. -The archive is pull-only. A mapped file import does not gain it. The -archive transaction does not reclassify the page. It does refuse to -revive a deleted archive source or to write a device receipt. +D208 reads database-dependent vetoes inside the protected transaction +and reads them again before any archive write. A veto there, including +on a `left_out` row, forbids the archive. The privacy scan still comes +first. The archive is pull-only. A mapped file import does not gain it. +A deleted archive source is not recreated, and the archive writes no +device receipt. Each archived series row is a capsule of `resource`, the response `resolution`, and the unchanged row. The hash is of that capsule. A raw @@ -808,3 +815,46 @@ Rejected alternatives: - Hash the series row and infer the resolution later. Rejected. The resolution is on the response, not on the row. +## D208. The archive reads safety facts under the write lock + +This corrects D207. The returned health data stays in this pull. The +specification is the contract. + +Privacy, required ids, and supplied-field names are checked on the +returned page before either transaction. A failure starts neither +transaction. + +Receipts, bindings, history, source deletion, stored records, import +keys, tombstones, null-source payloads, and workout kinds are read +inside the protected `BEGIN IMMEDIATE`, before any mutation. The read +includes a row the mapping would leave out. That read is the safety +snapshot. A veto in it refuses the protected page, and the archive is +not attempted. An unlocked read from before that transaction is not the +snapshot. + +The archive transaction then takes its own `BEGIN IMMEDIATE`. Before it +inserts a source or a capsule, it reads those facts again, and it reads +the archive source and the target capsules, including tombstones. A new +veto or a safety fact that differs from the snapshot sets `archive` to +`not_attempted` and writes nothing. A deleted source or a deleted record +is not copied onto a new archive identity. A deleted archive source is +not recreated. A deleted capsule is not replaced. If the page names a +row the bounded read cannot cover, the page is not archived. There is +no retry. + +A failed step 5 during init rolls back to the closed step 4 schema +before the existing init cleanup runs. Init fails. D202's cleanup is +unchanged. A migrate of an existing database keeps that file and the old +schema when step 5 rolls back. + +Rejected alternatives: + +- Use an unlocked preflight as the archive decision. Rejected. Another + command can bind the source before the protected transaction, and the + protected veto would then be stored. +- Recheck only the archive source after the protected rollback. + Rejected. The owner can delete the original source or record in + between, and the payload would be stored under a new identity. +- Leave a failed init file at step 4. Rejected. The existing caller + removes that file, and this build does not change that cleanup. + diff --git a/build-history/v2.2.0/progress.md b/build-history/v2.2.0/progress.md index e70d7379..557484ab 100644 --- a/build-history/v2.2.0/progress.md +++ b/build-history/v2.2.0/progress.md @@ -5,7 +5,7 @@ program, the record, or the database has changed for 2.2.0. | Step | What | Status | |---|---|---| -| 0 | The plan: proposals D198–D207, and the Open Wearables study. D207 corrects the migration rename, the command counts, and the archive decision. Still not adopted. The new head needs re-review | written, not approved | +| 0 | The plan: proposals D198–D208, and the Open Wearables study. D208 reads archive safety facts under the write lock and leaves failed-init cleanup unchanged. Still not adopted. The new head needs re-review | written, not approved | | 1 | Version 2.2.0 and migration step 5. No new column on an existing table. The root check gains `source_report` by the copy in D207. Summary and score values may be omitted in pairs (D198, D207) | not started | | 2 | `ath pull openwearables` in `ath-core`, with the rewritten mapping (D199, D201, D207) | not started | | 3 | Key, server, and user id kept out of the record (D200) | not started | diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index a40ecb49..bfbf7635 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -4,7 +4,7 @@ Status: **plan only. The maintainer has not approved it. Not approved for build. `ath pull openwearables` reads one person's stored health data from an Open Wearables server they run, and writes it with the mapping this release -ships. The proposals are D198 through D207 in +ships. The proposals are D198 through D208 in [decisions.md](decisions.md). They are not adopted. The evidence is [appendix/open-wearables-api.md](appendix/open-wearables-api.md), checked on 6 and 7 November 2026. @@ -214,14 +214,15 @@ gateway commands they are today. ## 2. What this pull stores -D207 is the storage rule. D203 keeps these values in this pull. D204 +D208 is the storage rule. D203 keeps these values in this pull. D204 corrected source, time, and score direction. D205 corrects units, day windows, sleep bounds, identity encoding, reported records, and child withdrawal. D206 corrects the root record type, numberless calculation inputs, recovery scales, required ids, workout provenance, hydration, and the archive of a refused original. D207 corrects the migration -dependencies, the command counts, archive eligibility, the archive -capsule, and null-source report routing. An earlier draft +dependencies, the command counts, the archive capsule, and null-source +report routing. D208 corrects when the archive reads the database, and +the failed-init sentence. An earlier draft left day values, the heart-rate stream, summaries, and workout segments for a later version. That draft is superseded. File imports stay. The Garmin pull stays. A Junction pull is proposed as 2.3.0. Automatic sync, retries, token refresh, and backfill are proposed as @@ -588,31 +589,46 @@ successful pull. The archive is pull-only. `ath import --mapping` uses the same protected envelopes and the same refusal, and it does not start the archive transaction. A refused file import keeps no original. -Before either transaction, the pull reads the whole page. The order of +Before either transaction, the pull checks the page itself. The order of the rows does not matter. The privacy scan is first. A hit starts -neither transaction. The pull then classifies every row, including a row -that would be `left_out`. One veto anywhere forbids the archive for the -whole page. The vetoes are a conflicting device id, a deleted source, an -unbound legacy history, a malformed or missing required UUID, a workout -kind change, a malformed receipt, and a supplied field whose name is not -allowed. A deleted-source row that the mapping would leave out is still -a veto. A query-bucket `left_out` row is not a veto and is not archived. -A timeseries row has no required UUID. Its missing device id is not that -veto. - -The archive is allowed only when the page has no veto and it has one of -these eligible facts: a device-targeted series row whose source has no -device id, or a null-source series row, measured or reported, whose full -match key has a different payload in this page or already stored. An -eligible row does not authorize the archive when a veto is -also on the page. The decision is this snapshot. It includes a read of -each stored null-source match key before the protected write. The -archive transaction does not classify the page again. Its only new check -is that the archive source is not deleted. - -The archive runs only after the protected rollback. It stores one capsule -per returned series row on that page, not a query-bucket row and not a -non-series row. A workout or a meal on that page is not a capsule. A +neither transaction. A missing or malformed required UUID, a supplied +field whose name is not allowed, and any other decoded-field failure are +the same kind of check. They use the returned JSON. They do not use the +database. One such failure starts neither transaction. A timeseries row +has no required UUID. A query-bucket `left_out` row is not one of these +failures, and it is not archived. + +The database facts are read later, inside the protected +`BEGIN IMMEDIATE`, before any insert, update, or delete. The read covers +every row on the page, including a row the mapping would leave out. For +each named source it reads the receipt, the binding, deletion, and +history, and history includes tombstones. For each named record and +import key it reads deletion, the current revision, and, for a workout, +the stored kind. For each null-source full key it reads the stored +payload. That set of facts is the safety snapshot. An unlocked read +taken before this transaction is not the snapshot. + +One database veto anywhere in that snapshot refuses the protected page +before any mutation. The vetoes are a conflicting device id, a deleted +source, unbound history, a malformed receipt, a workout kind that +differs from the stored record, and a deleted record or import key the +page would copy. A deleted-source row that the mapping would leave out +is still a veto. The protected transaction rolls back. The archive is +not attempted. The veto stands even when an earlier unlocked read saw +no veto. A missing device id on a timeseries row is not this veto. + +The archive is allowed only when that snapshot has no veto and it has +one of these eligible facts: a device-targeted series row whose source +has no device id, or a null-source series row, measured or reported, +whose full match key has a different payload in this page or already +stored. An eligible row does not authorize the archive when a veto is +also on the page. A confirmed command keeps this snapshot for the +archive transaction. It does not keep a lock after the protected +rollback. A preview discards the snapshot with that rollback. + +When the archive revalidation below matches the safety snapshot, the +archive stores one capsule per returned series row on that page, not a +query-bucket row and not a non-series row. A workout or a meal on that page is not a capsule. A later page that does not refuse can store it. The capsule is: ```json @@ -634,14 +650,28 @@ capsule is one record. A raw capsule and a day capsule are different even when the row bodies match. The hash is not a sample id. This plan does not claim that two different capsules cannot hash equal. If the key is already stored and the stored capsule differs, the archive transaction -fails and does not revise the old capsule. +fails before any insert and does not revise the old capsule. The archive source uses writer `open_wearables`, sensor `ow1:["archive"]`, and `source_type` `connector`. The receipt operations are not called, and -`device_binding` is not written. If that source is deleted, the archive -transaction fails and does not insert a new source. A later page sees the -committed archive. It does not see a deletion that happened after the -snapshot except for this one check. +`device_binding` is not written. + +The archive transaction starts with its own `BEGIN IMMEDIATE`, after the +protected rollback. The re-read and any archive writes are that same +transaction, so another writer cannot commit between them. Before it +inserts a source or a capsule, it reads +the same safety facts again, including a `left_out` neighbor. It also +reads the archive source and each target capsule, including a tombstone. +It compares those facts with the safety snapshot. A new veto, a +different binding, a new or missing history row, a source or record +tombstone, or a different safety revision means the snapshot is stale. +`archive` is then `not_attempted`. The transaction rolls back with no +writes. The fetched payload is not stored under the archive source, and +it is not given a new identity. A deleted archive source is not +recreated. A deleted capsule is not replaced. If the pull cannot name +this bounded set for a row, it does not archive the page. There is no +retry. A page that committed an archive still sees that archive. A +deletion after this archive commits is a later command. `protected_write` is `committed` or `refused`. `archive` is `not_attempted`, `stored`, `unchanged`, or `failed`. `committed` is the @@ -664,8 +694,14 @@ the protected refusal remains, earlier commits remain, the success sentence is not printed, and the exit is nonzero. The text is `Protected write refused; archive failed; database unchanged; pull incomplete.` After an earlier change it says `database changed`. It does not print a -partial archive count. A preview, including `--json` and `--json --yes`, -rolls both transactions back and commits neither. +partial archive count. When the archive is `not_attempted` after a +protected refusal, the text is `Protected write refused; archive not +attempted; database unchanged; pull incomplete.` After an earlier change +it says `database changed`. That result adds no archive count. A +preview, including `--json` and `--json --yes`, rolls the protected +transaction back and does not start the archive transaction. +`estimated_archive` comes from that rolled-back read and is labeled +estimated. A page of only reported series, with no device id, is an ordinary source report write. It is not an archive, and it does not refuse the device @@ -882,7 +918,8 @@ connection. A later `revise` cannot fill the receipt in, because that patch is refused. `store.rs` therefore gains three source operations besides the `revise` -rule above, and the typed writes in section 6. It gains nothing beyond those: +rule above, the typed writes in section 6, and the bounded archive +safety read in section 2. It gains nothing beyond those: - Read the committed receipt, and whether any record or source device for that source exists, including a deleted row. @@ -892,8 +929,13 @@ rule above, and the typed writes in section 6. It gains nothing beyond those: source device. Every other source field stays. The write uses the normal revision and `data_json` bookkeeping. Writer, route, sensor, import keys, and baselines stay. +- Read the sources, records, import keys, and archive keys named by one + page, including tombstones and the current revision. This is the safety + read in section 2. It does not scan the database. -The three operations run inside the caller's `BEGIN IMMEDIATE` transaction. +The three receipt operations run inside the caller's `BEGIN IMMEDIATE` +transaction. The safety read runs in that same transaction, before any +mutation, and again at the start of the archive transaction. A refused call rolls them back with the call. Other routes do not call them. The build may extend `ensure_mapped_source` or add a narrow operation beside it. It does not add a table, a trait, or a file split. The automatic @@ -1037,9 +1079,15 @@ backup is already on disk. Device receipts stay in the copied source JSON. They are not rewritten. A new database closes the step 4 transaction, then runs this step 5 path. -Step 9 sets `user_version`. If step 5 fails during init, the closed step -4 database remains, foreign keys are on, and init reports failure. The -views are not left dropped. `applyMigrationStep` gains this arm for target 5 +Step 9 sets `user_version`. If step 5 fails during init, that transaction +rolls back to the closed step 4 schema before the existing failed-init +cleanup runs. Init reports failure. `createDatabase` still closes the +database and `removePartialLocalDatabase` still deletes the new file. +D202 leaves those paths in place, and this build does not change them. +A file that cleanup does not delete is not left with the views dropped. +A migrate of a database that already existed is a separate case. Its +step 5 rollback leaves that file in place, at the old schema, with +foreign keys on. `applyMigrationStep` gains this arm for target 5 and does not use `withWriteTransaction` for it. `MIGRATION_CHAIN` in `src/db/sql-contract.ts`, `scripts/generate-sql-contract.ts`, and `scripts/check-schema-drift.ts` gain the step. `package.json` exports and `tests/v1-package-exports.test.ts` point @@ -1120,7 +1168,10 @@ measurement-sample target, the reporting-window write, and the segment copy from section 2. HTTP stays out of `mapping.rs`. `store.rs` keeps the `revise` refusal and adds the three source operations in section 3: the receipt and tombstone read, creation with the checked receipt, and a -first bind on an existing source that has no history. It also inserts and +first bind on an existing source that has no history. The archive +transaction adds a bounded read of the sources, records, import keys, +and archive keys named by that page, including tombstones and the +current revision. It does not scan the database. It also inserts and updates `measurement_sample` and `source_report`, and it accepts a provider summary or provider score whose `value` and unit are both present or both absent. A half-null pair is refused. When an anchor in this response no @@ -1137,7 +1188,8 @@ is not stored as zero and is not replaced by an older revision. The session-summary branch of `read_period` uses the same filter on the extracted number and unit. Formulas and source grouping stay as they are. The archive insert is the pull-only transaction in section 2. It is not -inside `apply_mapping`, and a mapped file import does not call it. It does +inside `apply_mapping`, and a mapped file import does not call it. It +revalidates the safety snapshot before any insert. It does not call the receipt operations. No other store behavior changes. `ath correct`, package restore, and an accepted package merge stay whole-record owner writes. They are named in section 3 so the binding survives a 2.2.0 round @@ -1309,6 +1361,25 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: counts, and `database_changed` true. The failure text then says `database changed`. Preview and `--json --yes` commit neither transaction +- two connections, both row orders. Before the protected `BEGIN IMMEDIATE`, + the other connection commits a binding of device C on source S. The page + has a series for S with device B and a missing-id neighbor. The + protected transaction refuses. `archive` is `not_attempted`. No capsule, + source revision, or receipt change is written. The same refusal holds + when the other connection commits a tombstone or history on S instead + of the binding. A page whose safety snapshot has no veto, then a + deletion of S after the protected rollback, does not archive S's + payload. A deletion of the normalized record or its import key between + the two transactions does not create a capsule. A deletion of the + archive source, or of an existing capsule, does not recreate it and + does not store a second identity. An owner correction that changes the + binding, the history, or the safety revision after the protected + rollback leaves `archive` `not_attempted` and writes nothing. An + already deleted neighbor, in either row order, is a protected veto and + is not archived. A credential on the page starts neither transaction. + An earlier committed sleep page keeps `written` true, its `committed` + counts, and `database_changed` true. The text is `Protected write + refused; archive not attempted; database changed; pull incomplete.` - sensors `ow1:["summary","sleep",null]` and a colon inside a provider name stay different from a shifted tuple. The text `-` is not the same sensor as a missing part. A score whose input source changes from null @@ -1471,7 +1542,10 @@ Migration tests, in the build gate: - `ath init` creates a database that is already `2.2.0`, SQL schema 5, and `user_version` 5, and `ath check` exits 0. The fresh database accepts a source report, the same two views are queryable, and a mismatched - revision type is rejected. Step 4 still + revision type is rejected. A failed init rolls step 5 back and then the + existing cleanup removes the new file. A failed migrate of a populated + database leaves that file, the old schema, the views, and foreign-key + enforcement. Step 4 still writes `2.1.0` and schema 4, and the create path closes that transaction before step 5 - databases at `1.0.0` and `2.0.0` still open for migrate. Packages at @@ -1549,7 +1623,8 @@ is in the build pull request. in the same process that closed it, without the garbage collection `removeTemporaryDirectory` uses. On Windows that delete can fail with `EBUSY`. Version 2.1.0 spec section 12 left it out and named no later - version. + version. A failed step 5 rolls back before that cleanup. This build + does not replace the cleanup. - `store.rs` and `mapping.rs` are past a thousand lines. The pull does not add HTTP to them. `mapping.rs` gains the counts, the open-wearables binding check, and the preservation writes in section 2. `store.rs` gains the @@ -1604,7 +1679,7 @@ cycle filter, the smaller-page split, and the tests in section 7. The laptop car part of that same pull request. This plan pull request has no media. The maintainer approves or rejects this plan before any build. D198 through -D207 are the proposal. They are not adopted. Reviews of earlier heads were +D208 are the proposal. They are not adopted. Reviews of earlier heads were incorporated here. None of those reviews approves this revision. The next head needs re-review. An earlier review accepted a migration with no new column, under D152 and D184. That acceptance does not @@ -1623,11 +1698,11 @@ optional source key adds no column. connection turns them off only before its transaction and reads them back on after every exit. A `2.1.0` database does not open until `ath migrate`. This release does - not schedule, refresh a token, backfill, or store a cursor (D198, D207). + not schedule, refresh a token, backfill, or store a cursor (D198, D208). 2. Store the returned representations in section 2. Device receipts stay on device sources. Summaries without a device id use their own sensors. Null stays null. A missing response is not called provider-unavailable. - The omissions in section 2 are the ones with a reason (D203, D207). + The omissions in section 2 are the ones with a reason (D203, D208). 3. The key, the selected origin, and the selected user id are rejected in decoded JSON before a page is mapped. Failure text uses a fixed sentence. `ath key clear` with no name still clears only the gateway keys and says @@ -1653,6 +1728,6 @@ optional source key adds no column. the checked receipt, and the first bind of an existing source that has no history, and the sample, source-report, withdrawal, and paired-null writes in section 6, including the null filter in the calculation - readers. The pull command owns the archive transaction and calls the - store. `mapping.rs` does not start it. Nothing else is added to either - file (D202, D207). + readers and the bounded archive safety read. The pull command owns the + archive transaction and calls the store. `mapping.rs` does not start + it. Failed-init cleanup stays as it is (D202, D208). From d5ff5df31657622b57cd56d2028c8dc08c6ce6bf Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 8 Nov 2026 19:27:48 +0000 Subject: [PATCH 12/60] Store a typed Open Wearables workout as a workout session. D209 keeps the source as the person, with basis entered_by_hand, and leaves unknown workouts as source reports. Co-authored-by: Michael Whitham --- .../v2.2.0/appendix/open-wearables-api.md | 5 +- build-history/v2.2.0/decisions.md | 68 ++++++++++++++----- build-history/v2.2.0/progress.md | 2 +- build-history/v2.2.0/spec.md | 66 +++++++++++------- 4 files changed, 98 insertions(+), 43 deletions(-) diff --git a/build-history/v2.2.0/appendix/open-wearables-api.md b/build-history/v2.2.0/appendix/open-wearables-api.md index c348b5d8..d7a73dc9 100644 --- a/build-history/v2.2.0/appendix/open-wearables-api.md +++ b/build-history/v2.2.0/appendix/open-wearables-api.md @@ -3,7 +3,10 @@ This study is the evidence for the 2.2.0 plan. The rules are in [the specification](../spec.md) and [the decisions](../decisions.md). Provider software changes. A fact below is tied to the page or the file it came from. -Nothing here was read from a live server, and no key was used. +Nothing here was read from a live server, and no key was used. Files +under `tests/fixtures/exports/open-wearables/` are not evidence. A claim +about what the server sends cites the Open Wearables docs or the pinned +0.11.0 OpenAPI file already named in this appendix. ## What the product is diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index 4ba56d10..a17df0cc 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -95,8 +95,8 @@ workout rows as `{ "workout": [ ... ] }`. It passes each timeseries response through unchanged, so `metadata.resolution` still reaches the mapping. The pull does not drop one row and keep its neighbors. A credential, a reflected origin or user id, a same-key `device_id` collision, or a bad envelope -rejects the whole page first. A manual workout stays the mapping's -`left_out`, and the other rows in that page are still written. +rejects the whole page first. A manual workout is written. D209 stores +it as a workout session. The other rows in that page are still written. The timeseries query's `types` list is the `type.` lines in the resolved mapping file, read when the command runs. The prefix is that @@ -564,7 +564,9 @@ that map `heart_rate_recovery_one_minute` to a quantity of that same name, and that call `hydration` a measurement sample. The units, day windows, sleep bounds, and reported-record direction stay. D207 supersedes D206 where they disagree. D208 supersedes D207 where they -disagree. Where this proposal disagrees with D208, D208 is the proposal. +disagree. Where this proposal disagrees with D208, D208 is the proposal, +except the sentences that store a manual workout as a source report. +D209 supersedes those sentences. This corrects D204. The returned health data stays in this pull. The specification's section 2 and the appendix series table are the contract. @@ -602,11 +604,11 @@ athlete report and not a nutrition entry. It is not one of the seven measured types. D161 still forbids turning a personal report into a measured record. Dietary series, alcoholic-beverage counts, meal and nutrient numbers, index, age, and effort series, personal-record fields, -predicted and coded cycle content, BMI, calculated age, an unbounded -health score, and a manual workout use this type. The eight range -calculations and `provider-period-summary` do not read it. A manual -workout is not left out and is not a workout session. An automatic -workout stays a measured session on the device source. +predicted and coded cycle content, BMI, calculated age, and an unbounded +health score use this type. The eight range calculations and +`provider-period-summary` do not read it. A manual workout is a workout +session. D209 is that rule. An automatic workout stays a measured +session on the device source. A new sensor is `ow1:` plus a JSON array with no spaces. JSON `null`, an empty string, and `-` stay different. Legacy device sensors are not @@ -615,10 +617,11 @@ top-level author. The input source is not in that array, so a change from null to a known input revises the same score. A null-source timeseries uses `["unattributed", "timeseries"]` and the writer `open_wearables`. Two unequal payloads at the same type and time refuse the call. The -personal record uses `["personal_record"]` and that same writer. A meal, -cycle, or manual workout uses the event array even when `device_id` is -present. That id stays in the array and in the original object. It does -not establish `device_binding`. +personal record uses `["personal_record"]` and that same writer. A meal +or cycle uses the event array even when `device_id` is present. That id +stays in the array and in the original object. It does not establish +`device_binding`. A manual workout does not use that array. D209 puts it +on the manual source. A raw or day row whose `source` object has no `device_id` is an incoming device row. The whole call is refused, including a valid row on the same @@ -660,10 +663,12 @@ Rejected alternatives: - Treat a second null-source payload as a correction. Rejected. There is no sample id, so the program cannot tell a correction from a second observation. -- Call dietary intake or a manual workout a provider summary or a workout - session. Rejected. SPEC section 5.4 and D161 keep those measured types - for measured records. A source report preserves the object without - making it a measurement. +- Call dietary intake a provider summary or a workout session. Rejected. + SPEC section 5.4 and D161 keep those measured types for measured + records. A source report preserves the object without making it a + measurement. +- Call a manual workout a provider summary. Rejected. D209 stores it as + a workout session. It is not a provider summary. - Leave a removed nutrient current because the store compares emitted keys. Rejected. The same object no longer contains that number. @@ -858,3 +863,34 @@ Rejected alternatives: - Leave a failed init file at step 4. Rejected. The existing caller removes that file, and this build does not change that cleanup. +## D209. A workout the person typed is a workout session + +This supersedes only the sentences in D198 and D205 that store a manual +workout as a source report or leave it out. D198 through D208 otherwise +stay as written. The specification is the contract. + +`entry_source` `manual` is a `workout_session`. Its source type is +`manual`. `field_basis.value` is `entered_by_hand`. It is not a device +measurement. `device_id`, if the server sent one, stays on the original +object. It does not set `device_binding`, and it does not put the +workout on the watch's source. The server workout id is the match key, +so a later pull updates the same workout. Name, type, start, end, +distance, heart rate, elevation, zones, and segments are stored the same +way they are stored on an automatic workout. `activity_type` still +records that Open Wearables normalized the sport name. The eight range +calculations and `provider-period-summary` do not read it. A workout the +person typed must not enter a device baseline. + +`unknown`, JSON null, and a missing `entry_source` stay source reports of +kind `unknown_workout`. They are not a workout session, and they are not +manual. + +Rejected alternatives: + +- Store a manual workout as a source report. Rejected. The workout object + says a manual entry is self-reported and has no device measurement + behind it. The record is a workout, and the source is the person. +- Call a manual workout a provider summary. Rejected. It is a session. +- Treat `unknown`, JSON null, or a missing `entry_source` as manual. + Rejected. Those values are not the self-reported entry. + diff --git a/build-history/v2.2.0/progress.md b/build-history/v2.2.0/progress.md index 557484ab..3ac32563 100644 --- a/build-history/v2.2.0/progress.md +++ b/build-history/v2.2.0/progress.md @@ -5,7 +5,7 @@ program, the record, or the database has changed for 2.2.0. | Step | What | Status | |---|---|---| -| 0 | The plan: proposals D198–D208, and the Open Wearables study. D208 reads archive safety facts under the write lock and leaves failed-init cleanup unchanged. Still not adopted. The new head needs re-review | written, not approved | +| 0 | The plan: proposals D198–D209, and the Open Wearables study. D209 stores a workout the person typed as a workout session. Still not adopted. The new head needs re-review | written, not approved | | 1 | Version 2.2.0 and migration step 5. No new column on an existing table. The root check gains `source_report` by the copy in D207. Summary and score values may be omitted in pairs (D198, D207) | not started | | 2 | `ath pull openwearables` in `ath-core`, with the rewritten mapping (D199, D201, D207) | not started | | 3 | Key, server, and user id kept out of the record (D200) | not started | diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index bfbf7635..0b481581 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -4,7 +4,7 @@ Status: **plan only. The maintainer has not approved it. Not approved for build. `ath pull openwearables` reads one person's stored health data from an Open Wearables server they run, and writes it with the mapping this release -ships. The proposals are D198 through D208 in +ships. The proposals are D198 through D209 in [decisions.md](decisions.md). They are not adopted. The evidence is [appendix/open-wearables-api.md](appendix/open-wearables-api.md), checked on 6 and 7 November 2026. @@ -222,7 +222,8 @@ inputs, recovery scales, required ids, workout provenance, hydration, and the archive of a refused original. D207 corrects the migration dependencies, the command counts, the archive capsule, and null-source report routing. D208 corrects when the archive reads the database, and -the failed-init sentence. An earlier draft +the failed-init sentence. D209 stores a workout the person typed as a +workout session. An earlier draft left day values, the heart-rate stream, summaries, and workout segments for a later version. That draft is superseded. File imports stay. The Garmin pull stays. A Junction pull is proposed as 2.3.0. Automatic sync, retries, token refresh, and backfill are proposed as @@ -313,15 +314,27 @@ copied from another row. Intake, index, age, effort, and `hydration` do not enter that check. A device id on those rows is original data. It is not a receipt and it is not evidence the value was measured. -`entry_source` `automatic` is the only workout class that becomes a -workout session. `manual` is a source report of kind `manual_workout`. -`unknown`, JSON null, and a missing `entry_source` are source reports of -kind `unknown_workout`. The original keeps null and absence distinct. -Unknown is not labeled manual, and it is not labeled automatic because a -model or a device id is present. A repeated server workout id that arrives -as a different kind or sensor refuses the protected page. The stored -record stays. The new interpretation is not written beside it. The text -says the classification changed and a rerun cannot choose. `ath correct` +`entry_source` `automatic` is a workout session on the device source, as +the paragraph above says. `entry_source` `manual` is a workout session +on the source whose `source_type` is `manual`. `field_basis.value` is +`entered_by_hand`. It is not a device measurement. A `device_id` the +server sent stays on the original object. It does not set +`device_binding`, and the workout is not stored on the watch's source. +The server workout id is the match key. A later pull of that same +workout updates the session. Name, type, start, end, distance, heart +rate, elevation, zones, and segments are stored the same way they are +stored on an automatic workout. `field_basis.activity_type` is +`aggregator_normalized`, because Open Wearables normalized the sport +name. The eight range calculations and `provider-period-summary` do not +read this session. It does not enter a device baseline. `unknown`, JSON +null, and a missing `entry_source` are source reports of kind +`unknown_workout`. They are not a workout session, and they are not +manual. The original keeps null and absence distinct. Unknown is not +labeled manual, and it is not labeled automatic because a model or a +device id is present. A repeated server workout id that arrives as a +different kind or sensor refuses the protected page. The stored record +stays. The new interpretation is not written beside it. The text says +the classification changed and a rerun cannot choose. `ath correct` remains the owner's way to replace the record. Sleep, workout, meal, cycle, and health-score objects need a `id` that is @@ -341,7 +354,7 @@ escapes `:` and `\` when the sensor is placed in a match key. The array shapes are: - Summary or body: `["summary", family, provider, device, device_type, source, device_id]` -- Meal, cycle, manual workout, or unknown workout: `["event", family, provider, device, device_type, source, device_id]` +- Meal, cycle, or unknown workout: `["event", family, provider, device, device_type, source, device_id]` - Reported series, including a row whose `source` is null: `["report", resolution, provider, device, device_type, source, device_id]`. `resolution` is `raw` or `1day`. - Health score: `["score", provider]`. `provider` is the top-level author, or JSON `null` when that field is null. The input `source` is not in @@ -388,7 +401,7 @@ appendix table, fails before any request. |---|---|---|---|---|---| | Sleep session | `{ "sleep": data }` | `source.provider` | legacy device | `sleep_session`, D181 id key | stage and duration fields on that session | | Automatic workout | `{ "workout": data }` | `source.provider` | legacy device | `workout_session`, D181 id key | existing typed fields; untyped numbers are source reports | -| Manual workout | `{ "workout": data }` | `source.provider` | `ow1` event | `source_report` `manual_workout`, server id | none. The original object is the record | +| Manual workout | `{ "workout": data }` | `source.provider` | not the device sensor | `workout_session` on the manual source, server id | same typed fields, zones, and segments as an automatic workout | | Unknown, null, or omitted `entry_source` | `{ "workout": data }` | `source.provider` | `ow1` event | `source_report` `unknown_workout`, server id | none. The original object is the record | | Measured raw series with `device_id` | timeseries object, `resolution` `raw` | `source.provider` | legacy device | the raw class in the appendix, D181 time key | none | | Measured raw or day series, source present, no `device_id` | timeseries object | `source.provider` | legacy device, then the protected transaction is refused | no measured row. Section 2 may archive the original | none | @@ -410,7 +423,7 @@ report stores that report without making it a measurement. The eight range calcu `provider-period-summary` do not read it. Step 5 creates the `source_reports` table. Value and unit are both present or both absent. `report_kind` is one of `intake`, `account`, `predicted`, `code`, `text`, -`manual_workout`, `unknown_workout`, `index`, or `original`. Gender uses +`unknown_workout`, `index`, or `original`. Gender uses `account`. It is not copied into `sex` or the athlete profile. The receipt still adds no column. @@ -571,9 +584,9 @@ anchor. A numeric cycle length is also a `source_report` child, not a measurement. On an automatic workout, a number that is not already a typed session field stays in `supplied_fields` and is a `source_report` child. It is not a provider summary. `intensity` stays under that name. -Segments and zones stay under the server's names. A -manual workout is the `source_report` in the table. It does not become a -workout session, a point, or a device receipt. +Segments and zones stay under the server's names. A manual workout is +the workout session in the table. It is not a source report, a point, or +a device receipt. The same returned object can change a child from a number to null, or remove a nutrient. The mapper emits that child again with value and unit @@ -1298,7 +1311,7 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: from a series row or from body latest when that time is present. A recovery object does not gain a skin field. A WHOOP health-score component named `skin_temp_celsius` stays on that object. - `page-5min.json` is left out as a query bucket. A 2.1.0 raw point and a + A 2.1.0 raw point and a pull of that same raw point stay one record. A heart-rate sample from device B does not replace device A's sample. A negative latitude and a negative longitude are stored @@ -1495,13 +1508,16 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: - `page-sleep.json` becomes a sleep session. A manual workout and its automatic neighbor from one response stay two records. The automatic workout is a session on the device source. The manual workout is a - source report with the original object and no device receipt. A workout - with `entry_source` `unknown`, null, or omitted is an `unknown_workout` - report. It is not a session and not a manual report. The same server id - arriving later as `automatic` refuses the page, and the stored report - stays. Export and import keep the pair that was accepted. + workout session on the manual source, with `field_basis.value` + `entered_by_hand` and no device receipt. A `device_id` on that object + stays on the original. A workout with `entry_source` `unknown`, null, + or omitted is an `unknown_workout` report. It is not a session and not + a manual workout. The same server id arriving later as `automatic` + refuses the page, and the stored session stays. A later pull of the + same manual workout updates that session. Export and import keep the + pair that was accepted. `page-raw.json` is stored. - `page-5min.json` is left out. RMSSD and SDNN stay different quantities + RMSSD and SDNN stay different quantities - a changed end time keeps the record id and increases the revision - a `__proto__` supplied field fails the page - a literal key, a Unicode-escaped key in a nested unconsumed field, the @@ -1679,7 +1695,7 @@ cycle filter, the smaller-page split, and the tests in section 7. The laptop car part of that same pull request. This plan pull request has no media. The maintainer approves or rejects this plan before any build. D198 through -D208 are the proposal. They are not adopted. Reviews of earlier heads were +D209 are the proposal. They are not adopted. Reviews of earlier heads were incorporated here. None of those reviews approves this revision. The next head needs re-review. An earlier review accepted a migration with no new column, under D152 and D184. That acceptance does not From b101b7da921a9cf1a4d1de6bce6a0eadd55c55b4 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 8 Nov 2026 21:35:18 +0000 Subject: [PATCH 13/60] Plan live workout originals and three review corrections. D210 through D213 keep skin-temperature time unknown, finite heart-rate recovery, the manual drift window, and provider-live workout objects. Co-authored-by: Michael Whitham --- .../v2.2.0/appendix/open-wearables-api.md | 69 +++++++ build-history/v2.2.0/decisions.md | 106 +++++++++- build-history/v2.2.0/progress.md | 2 +- build-history/v2.2.0/spec.md | 188 +++++++++++++++--- 4 files changed, 338 insertions(+), 27 deletions(-) diff --git a/build-history/v2.2.0/appendix/open-wearables-api.md b/build-history/v2.2.0/appendix/open-wearables-api.md index d7a73dc9..8124ee31 100644 --- a/build-history/v2.2.0/appendix/open-wearables-api.md +++ b/build-history/v2.2.0/appendix/open-wearables-api.md @@ -445,9 +445,78 @@ uses `datetime.now`, omits `device_id`, and does not put a time on `BodySlowChanging`. The personal-record response is `birth_date`, `gender`, `sex`, and `user_id`. A field that was never set is null. +`summaries_service.py` reads skin temperature from the latest sample +window. When that read is empty, `latest_day_value` supplies the newest +day value and `period_start`. The service unpacks that pair into the same +`skin_temperature_measured_at` field. The response does not say which +read it was. `heart_rate_recovery_one_minute` is series id 4, unit `bpm`. +`TimeSeriesSampleBase.value` is a number with no positive minimum. The +column is `numeric_unbounded`. + +## Stored workouts and the live provider routes + +Checked at commit `183e8cc4f6de897dbd288c93d49a691f2cf721ae` on 8 November +2026. No server was called, and no vendor account was used. + +The stored workout response is the `Workout` model in +`schemas/responses/activity/events.py`. It has the Open Wearables id and +the normalized fields. It has no `external_id`. The database row does +have `external_id`. The public model does not return it. + +The live routes are `vendor_workouts.py`. Both handlers call +`get_workouts_from_api` or `get_workout_detail_from_api` and return that +value. Neither handler writes a row. + +Polar's live methods pass `samples`, `zones`, and `route` through to +`/v3/exercises`. The save path calls the list method without those +arguments, so the request uses false. `ExerciseJSON` can parse samples, +zones, and route. `_normalize_workout` copies the sport, the device, the +times, the average and maximum heart rate, the calories, and the +distance. It does not copy samples, zones, or route. The Polar provider +page says the exercise list is the exercises available in Polar Flow. It +does not say Polar keeps every past exercise. + +`ingest_workout_samples` defaults to false. `store_fit_files` defaults to +false. `raw_payload_storage` defaults to `disabled`. `store_raw_payload` +returns immediately when the backend is disabled. `store_fit_file` +returns immediately when FIT storage is disabled. Garmin's activity-file +branch still downloads a FIT file and can save parsed segments and zones. +It adds FIT samples to `series_sample` only when `ingest_workout_samples` +is true. Strava's stream save returns zero when that flag is false. Those +are settings. This study does not know how a particular deployment set +them. When the flags are off, the samples and the FIT bytes are not +stored. The stored timeseries read can return samples only when a save +path wrote them. + +Garmin's live list sends `uploadStartTimeInSeconds` and +`uploadEndTimeInSeconds`. With no range, the method uses the last 24 +hours. Its `load_data` saves nothing and says activities arrive by +webhook. Suunto's published parameters are `since`, `limit`, `offset`, +and `filter_by_modification_time`. Whoop's start, end, and `nextToken` +are not parameters of the route. The method then sends no start and caps +`limit` at 25. Oura's dates and `next_token` are not on the route. +Strava's `after` and `before` are not on the route. The method defaults +to page 1 and `strava_events_per_page` of 200. Fitbit's detail method is +the base method, which raises `NotImplementedError`. Its list method uses +the last 30 days when no dates are passed. Withings uses +`pull_sync_lookback` or 30 days and does not implement detail. Sensorbio +uses `limit` and `last-timestamp` 0 and does not implement detail. Google +Health does not implement the live method. Apple, Samsung, Health +Connect, and Ultrahuman leave `workouts` unset, and the route answers +501. + +A missing live payload is not the same fact as a stored row the list +route did not include. The stored list returns what normalization saved. +The live route returns what the provider method returns on that call. A +flag that is off explains samples and FIT bytes that were never written. +A route parameter that does not exist explains a provider page that +cannot take this pull's range. A provider that has no live method is not +an empty workout history. + ## What was not checked - A running server's JSON, including the exact `start_time` text. +- A live provider account, a sync call, or a historical-sync call. - Whether Docker tag `latest` matches release `0.11.0` or `main`. - The database timezone applied to a date-only bound. - Middleware rate limits. diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index a17df0cc..e5143671 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -877,9 +877,12 @@ workout on the watch's source. The server workout id is the match key, so a later pull updates the same workout. Name, type, start, end, distance, heart rate, elevation, zones, and segments are stored the same way they are stored on an automatic workout. `activity_type` still -records that Open Wearables normalized the sport name. The eight range -calculations and `provider-period-summary` do not read it. A workout the -person typed must not enter a device baseline. +records that Open Wearables normalized the sport name. D212 corrects the +next rule. The numbers on this session do not enter the eight range +calculations or `provider-period-summary`. `workout-drift` may use the +session's start and end when the caller names that session. The samples +in that window still exclude a manual source. The session does not enter +a device baseline. `unknown`, JSON null, and a missing `entry_source` stay source reports of kind `unknown_workout`. They are not a workout session, and they are not @@ -894,3 +897,100 @@ Rejected alternatives: - Treat `unknown`, JSON null, or a missing `entry_source` as manual. Rejected. Those values are not the self-reported entry. +## D210. A body skin-temperature time is not an instant by itself + +This corrects the sentence that treats a non-null +`skin_temperature_measured_at` as a measurement instant. The other body +rules stay. + +The body service reads a skin-temperature sample in the latest window. +When that sample is missing, it reads the newest day value and uses that +day's `period_start` as the same timestamp. The response has no field +that says which read it used. The amount, the unit, and the timestamp +stay on the original object. The skin-temperature child is time-unknown. +It has no `recorded_at`. The program does not choose by comparing +timestamps, and it does not invent bounds. Body temperature and blood +pressure still use their own times. A raw skin-temperature sample and a +day skin-temperature window keep the series rules they already have. + +Rejected alternatives: + +- Treat every non-null body timestamp as an instant. Rejected. The day + fallback writes `period_start` into the same field. +- Drop the timestamp. Rejected. The original object keeps what the server + sent. + +## D211. A finite heart-rate recovery stays, including zero + +This corrects the positive point gate for one quantity. The quantity, +the unit, and the import key stay `hr_recovery` and `bpm`. + +Open Wearables stores `heart_rate_recovery_one_minute` as a number in +bpm. The sample value has no positive minimum. The mapping and the v1 +point check currently reject a point at or below zero, except +`temperature_deviation`. A finite `hr_recovery`, including zero and a +negative number, passes that check. A non-finite value does not. Other +points stay positive. `temperature_deviation` stays signed. +`src/schema.ts` is not edited. No table is rebuilt for this check. + +Rejected alternatives: + +- Keep the positive gate and drop a recovery of zero. Rejected. The + server can return that number, and this pull said a returned zero stays + zero for this quantity. +- Allow zero for every point. Rejected. The other positive checks stay. + +## D212. A manual session can set a window, and its numbers stay out + +This corrects the D209 sentence that says the calculations do not read a +manual workout. It does not change the calculation code. + +`read_inputs` and `read_period` exclude `source_type` `manual`. They have +no `include_manual` switch. `workout-drift` loads the session the caller +names, including a manual session, and uses its start and end as the +window. The samples then come from `read_inputs`, so a manual source's +numbers are not inputs. The session's own heart rate and distance are not +inputs. Record queries omit manual sources unless `include_manual` is +true. A typed workout must not enter a device baseline. + +Rejected alternatives: + +- Refuse a manual session as the drift window. Rejected. The current + command already accepts that window and then reads the other sources' + samples. This proposal does not take that away. +- Let a manual heart rate enter a baseline when `include_manual` is set. + Rejected. The calculation SQL has no such switch. + +## D213. A provider-live workout is kept as an original + +The stored workout list is the normalized session. The provider routes +return the vendor object and do not save it. Defaults leave workout +samples, FIT bytes, and raw payloads unstored unless that deployment +turned the flag on. This pull reads the two live GET routes and stores +the vendor object. + +The original is a `source_report` of kind `original`, subject +`vendor_workout`, on the non-device Open Wearables source. The match key +is the provider plus the vendor workout id. A later pull updates that +original. It is not a second workout session, and it is not joined to the +stored session by time. The public stored workout has no `external_id`. +Device names, device ids, routes, and nested samples stay inside the +original. They do not set `device_binding`, and they are not measurement +samples. Calculations do not read the original. + +The pull uses the published query parameters, does not retry, and does +not call sync, historical sync, or a provider whose live method is +missing. A completed provider line means that provider's stated limit was +reached. It does not mean the vendor returned lifetime history. The same +API key is used. No new vendor permission is added. + +Rejected alternatives: + +- Leave the live routes unread. Rejected. The vendor object is available + from the server and is not the stored workout. +- Make the live object a second workout session. Rejected. The stored + session already exists, and the public workout has no vendor id to join + them. +- Call sync or historical sync to fill the gap. Rejected. Those routes + write on the server. This pull only reads. + diff --git a/build-history/v2.2.0/progress.md b/build-history/v2.2.0/progress.md index 3ac32563..092214d5 100644 --- a/build-history/v2.2.0/progress.md +++ b/build-history/v2.2.0/progress.md @@ -5,7 +5,7 @@ program, the record, or the database has changed for 2.2.0. | Step | What | Status | |---|---|---| -| 0 | The plan: proposals D198–D209, and the Open Wearables study. D209 stores a workout the person typed as a workout session. Still not adopted. The new head needs re-review | written, not approved | +| 0 | The plan: proposals D198–D213, and the Open Wearables study. D210 through D213 correct body skin-temperature time, finite heart-rate recovery, the manual-session window, and provider-live workout originals. Still not adopted. The new head needs re-review | written, not approved | | 1 | Version 2.2.0 and migration step 5. No new column on an existing table. The root check gains `source_report` by the copy in D207. Summary and score values may be omitted in pairs (D198, D207) | not started | | 2 | `ath pull openwearables` in `ath-core`, with the rewritten mapping (D199, D201, D207) | not started | | 3 | Key, server, and user id kept out of the record (D200) | not started | diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index 0b481581..03cceec7 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -3,11 +3,12 @@ Status: **plan only. The maintainer has not approved it. Not approved for build.** `ath pull openwearables` reads one person's stored health data from an Open -Wearables server they run, and writes it with the mapping this release -ships. The proposals are D198 through D209 in +Wearables server they run, and the provider-live workout list and detail +that server already exposes. It writes both with the mapping this release +ships. The proposals are D198 through D213 in [decisions.md](decisions.md). They are not adopted. The evidence is [appendix/open-wearables-api.md](appendix/open-wearables-api.md), checked on -6 and 7 November 2026. +6, 7, and 8 November 2026. This pull request is the plan. The build after approval is one later pull request. This plan does not change a version number, a schema, a fixture, or @@ -73,6 +74,8 @@ Preview text prints: - `reads finished` or `reads incomplete` - one line each for the twelve reads in section 2: `completed`, `failed`, or `not_attempted` +- one line each for the provider-live workout reads: `completed`, `failed`, + or `not_attempted`, plus the limit that read actually has - for body, on a preview: `body snapshot would store` or `body snapshot would be empty`. On a confirmed write: `body snapshot stored`, `body snapshot empty`, or `body snapshot incomplete` @@ -87,8 +90,10 @@ Preview text prints: `apply_mapping` transaction (D189). It is not a completed pull. The text prints actual committed counts for pages kept. It prints `requested range through is complete` only when every ranged read in section 2 -reached that read's terminal condition. Body is not one of those reads. -The success sentence `pulled openwearables from through ` is +reached that read's terminal condition and every provider-live workout +read reached the limit stated for that provider. Body is not one of those +ranged reads. The success sentence does not say a vendor kept lifetime +history. The success sentence `pulled openwearables from through ` is printed only when the range is complete and body and the personal record also completed. A finished range with an incomplete body snapshot does not print that sentence. The body line still says the snapshot is incomplete. @@ -223,7 +228,11 @@ and the archive of a refused original. D207 corrects the migration dependencies, the command counts, the archive capsule, and null-source report routing. D208 corrects when the archive reads the database, and the failed-init sentence. D209 stores a workout the person typed as a -workout session. An earlier draft +workout session. D210 keeps a body skin-temperature time unknown when the +response does not say it is an instant. D211 keeps a finite +`hr_recovery`, including zero and a negative number. D212 keeps the +current manual-session calculation rule. D213 stores the provider-live +workout list and detail as originals. An earlier draft left day values, the heart-rate stream, summaries, and workout segments for a later version. That draft is superseded. File imports stay. The Garmin pull stays. A Junction pull is proposed as 2.3.0. Automatic sync, retries, token refresh, and backfill are proposed as @@ -233,7 +242,10 @@ this server. It does not add a connector interface. This pull stores the representations Open Wearables 0.11.0 returns for one user. A ranged read stores that range. Body does not. A returned number keeps the server's unit. A returned null stays absent and is not stored as -zero. A returned zero stays zero. A row the server did not return is not +zero. A returned zero stays zero, except a point quantity whose rule still +requires a positive number. `hr_recovery` is not one of those quantities. +A finite zero and a finite negative `hr_recovery` stay. `temperature_deviation` +stays signed. Other points stay positive. A row the server did not return is not labeled provider-unavailable. Priority selection, a day-row pick, and a rollup can omit a stored row from the response. That omission is unknown here. It is not a null, and it is not a refusal. `left_out` counts only a @@ -325,8 +337,13 @@ workout updates the session. Name, type, start, end, distance, heart rate, elevation, zones, and segments are stored the same way they are stored on an automatic workout. `field_basis.activity_type` is `aggregator_normalized`, because Open Wearables normalized the sport -name. The eight range calculations and `provider-period-summary` do not -read this session. It does not enter a device baseline. `unknown`, JSON +name. The numbers on this session do not enter the eight range +calculations or `provider-period-summary`. `workout-drift` may use the +session's start and end as its window when the caller names that session. +The samples in that window still exclude `source_type` `manual`. Record +queries omit manual sources unless `include_manual` is true. This pull +does not change those controls. The session does not enter a device +baseline. `unknown`, JSON null, and a missing `entry_source` are source reports of kind `unknown_workout`. They are not a workout session, and they are not manual. The original keeps null and absence distinct. Unknown is not @@ -409,7 +426,7 @@ appendix table, fails before any request. | Measured series, `source` null | timeseries object | `open_wearables` | `ow1` unattributed only | the raw class, full match key | none. An unequal payload refuses the protected transaction and may be archived | | Day series | timeseries object, `resolution` `1day` | same as the raw row | same as the raw row | window form in the appendix. Key adds `1day` and `period_end` | none | | Sleep, activity, or recovery summary | `{ "sleep_summary": data }`, `{ "activity_summary": data }`, or `{ "recovery_summary": data }` | `source.provider` | `ow1` summary | `source_report` subject `object`, date | one measured child per numeric field, field path in the key | -| Body | the object | umbrella `source.provider`, or `open_wearables` when it is missing | `ow1` summary, family `body` | `source_report` subject `object` | slow-changing weight, height, fat, and muscle are time-unknown provider summaries; averaged heart rate and HRV use the server window; latest temperature and blood pressure use their own times; age and BMI are source reports | +| Body | the object | umbrella `source.provider`, or `open_wearables` when it is missing | `ow1` summary, family `body` | `source_report` subject `object` | slow-changing weight, height, fat, and muscle are time-unknown provider summaries; averaged heart rate and HRV use the server window; body temperature and blood pressure use their own times; skin temperature is time-unknown; age and BMI are source reports | | Health score | `{ "health_score": data }` | top-level `provider`, or `open_wearables` | `ow1` score | `provider_score` when the scale table has a finite range, otherwise `source_report` | none. Components stay on the record | | Meal | `{ "meal": data }` | `source.provider` | `ow1` event | `source_report` subject `object`, meal id | one `source_report` per numeric field path | | Cycle | `{ "cycle": data }` | `source.provider` | `ow1` event | `source_report` subject `object`, cycle id | one `source_report` per numeric reported length | @@ -497,7 +514,10 @@ summaries. The two Garmin day scores stay scores on their existing scales, with the window and without `recorded_at`. Raw points, raw `vo2_max`, and the two raw Garmin scores keep their kinds and keys. Raw `heart_rate_recovery_one_minute` is the point quantity `hr_recovery`, in -bpm. The server series name stays in `supplied_fields`. The 2.1.0 import +bpm. A finite value stays, including zero and a negative number. The +mapping's positive check and the v1 point check gain that exception +beside `temperature_deviation`. `src/schema.ts` stays as it is. No table +is rebuilt for the check. The server series name stays in `supplied_fields`. The 2.1.0 import key stays. A day row of that series is a window summary whose summary type is also `hr_recovery`. Its key adds `1day` and `period_end`, so it does not replace the raw point. A mapped file and a pull, in either @@ -567,10 +587,19 @@ children. Age is calculated by the service. The child is a source report and has no `field_basis`. BMI is not labeled measured. The averaged heart-rate and HRV values are provider summaries on the server's `period_start` and `period_end`. Those bounds are not copied onto the -slow-changing fields. Each latest field uses its own measured-at time -when the server sends one. A value with a null time uses the time-unknown -receipt. A null group withdraws that group's existing children. It does -not delete them because a different request omitted the snapshot. +slow-changing fields. Body temperature and blood pressure use their own +measured-at times when the server sends those times. Skin temperature +does not. The body service can put a day row's `period_start` into +`skin_temperature_measured_at` when no sample is in the latest window, +and the response has no field that says which one it did. The amount, +the unit, and that timestamp stay on the original object. The skin-temperature +child is time-unknown. It has no `recorded_at`. The program does not +decide by comparing timestamps, and it does not invent a window from +that timestamp. A raw skin-temperature sample and a day skin-temperature +window stay the series records they already are. A null time on body +temperature or blood pressure uses the time-unknown receipt. A null group +withdraws that group's existing children. It does not delete them because +a different request omitted the snapshot. Meal numbers, nutrient numbers, dietary series, alcoholic-beverage counts, `hydration`, and the index, age, and effort series are @@ -737,11 +766,91 @@ The following are not requested. Each line is the reason. - Sleep totals, workout totals, and activity totals. They add up rows the lists return. - The data summary and the data timeline. They count stored rows. -- The provider workout list and detail. They call the vendor through the - server's live connection. This pull keeps the stored workout. - Accounts, connections, sync, OAuth, webhooks, API keys, config, uploads, and every `DELETE`. They are not health readings. The API key, the server address, and the user id are not written into the athlete record. + `/sync` and `/sync/historical` are not called. + +The two provider-live reads are +`GET /api/v1/providers/{provider}/users/{user_id}/workouts` and +`GET /api/v1/providers/{provider}/users/{user_id}/workouts/{workout_id}`. +They use the same API key as the stored reads. They do not add a vendor +token, a scope, or a write. The route returns the provider method's +response. It does not save that response. This pull saves it. + +The original is a `source_report` of kind `original`. Its subject is +`vendor_workout`. Its source is the non-device Open Wearables source, not +the watch's source. `provider_record_id` is the provider name plus the +vendor workout id the save path already uses: Polar `id`, Garmin +`activityId`, Suunto `workoutId`, Whoop `id`, Oura `id`, Strava `id`, +Fitbit `logId`, Withings `id`, and Sensorbio `id`. A later pull of that +same id updates that original. The original is not a second +`workout_session`. The stored session stays matched by the Open Wearables +workout id. The public stored workout object has no `external_id`, so +this pull does not join the original to the session by time, distance, or +device. A manual session stays the manual session. A device id, a device +name, and a route inside the vendor object stay on the original. They do +not set `device_binding`. Nested samples stay inside the original. They +are not written again as measurement samples. The eight range +calculations do not read the original. + +A list item with no vendor id refuses that provider's list page. The +refusal follows the missing-id rule, including no archive. Detail is +requested only after the list item has an id, and only for a provider +whose detail method returns the vendor object. The detail replaces the +same original when its vendor id matches. A detail with a missing or +different id is not stored. The list original stays, and the result names +the mismatch. A detail method that raises `NotImplementedError` is not +called. That is not an empty workout list. + +The pull sends only the query parameters the route publishes. It does not +retry a transport failure. A response over 8 MiB is handled by the same +rule as the other reads: Suunto is asked again with a smaller `limit`, +down to 1. A route with no `limit` fails that read and names it. Route +coordinates are stored on the original and are not printed in the result +text. The privacy scan still refuses a page that contains the key, the +selected origin, or the selected user id. + +Each provider's list is what that method does when the route's parameters +are all it receives, except Garmin and Suunto, whose time parameters the +route does publish. + +- Polar sends `samples=true`, `zones=true`, and `route=true`. The route + has no date. The provider document says the exercise list is the + exercises available in Polar Flow. A start outside the requested range + is not stored and is not `left_out`. One list over 8 MiB fails the read. +- Garmin sends `summary_start_time` and `summary_end_time` from the + requested range. The method puts those values in + `uploadStartTimeInSeconds` and `uploadEndTimeInSeconds`. The result says + the filter is upload time. An omitted range would be the method's last + 24 hours, so this pull always sends the range. A range over 24 hours is + chunked by that method. +- Suunto sends `since` as the requested start in Unix milliseconds, + `filter_by_modification_time=false`, `limit` 100, and pages `offset` + until a short page. False means creation time, not workout start. + Detail is the workout URL with no `extensions` parameter. +- Whoop, Oura, and Strava have no date parameter on this route. Whoop is + one call with the method's limit of 25 and no `nextToken`. Oura is one + call with no date and no `next_token`. Strava is one call at page 1. + The method's `per_page` default is 200. Their detail methods are called + for ids on that page. +- Fitbit's list method uses the last 30 days when the route sends no + dates. Its detail method is not implemented and is not called. +- Withings uses `pull_sync_lookback` when set, otherwise 30 days, widens + each edge by one local day, and pages inside the method. Detail is not + implemented and is not called. +- Sensorbio uses the route's `limit` of 50 and `last-timestamp` 0. Detail + is not implemented and is not called. +- Apple, Samsung, Health Connect, Ultrahuman, Google Health, `internal`, + and `unknown` are not called. Apple, Samsung, Health Connect, and + Ultrahuman have no workout object on the strategy, and the route would + answer 501. Google Health does not implement the live method. Stored + workouts from those providers still come from `/events/workouts`. + +These reads run after the twelve stored reads. A completed line means that +stated limit was reached. It does not mean the vendor's lifetime history +was returned. A failed provider stops later provider reads, keeps earlier +commits, and exits nonzero. The success sentence is not printed. Day rows are one selected row per source, series, and local day. The repository prefers `computed_by: provider`, then the later provider row. @@ -1193,7 +1302,13 @@ transaction. `src/db/records.ts`, `src/db/import-package.ts`, `src/db/records-view.ts`, and the repair copy from `data_json` follow that pair and the new table. `src/db/check-tables.ts` gains the `source_report` entry. The eight range calculations and -`provider-period-summary` do not read `source_reports`. In +`provider-period-summary` do not read `source_reports`. `read_inputs` and +`read_period` also exclude `source_type` `manual`, and they have no +`include_manual` switch. `workout-drift` loads the named session first, +including a manual session, and uses that session's start and end as the +window. Its samples then go through `read_inputs`. A manual source's +numbers stay out. Record queries omit manual sources unless +`include_manual` is true. This proposal does not change that code. In `read_inputs` and `read_period`, a provider summary or provider score whose `standard_value` or `standard_unit` is null is excluded in the SQL, before the limit, the count, the grouping, and the numeric decode. A null @@ -1296,7 +1411,11 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: and do not invent an instant. A step length of 70 cm is stored as 0.70 m. A stride of 120 cm is stored as 1.20 m. The input number and `cm` stay on the record. Raw `heart_rate_recovery_one_minute` is quantity - `hr_recovery` in bpm. A 2.1.0 mapped file and this pull, in either + `hr_recovery` in bpm. A finite zero and a finite negative value are + stored. Import, a repeat pull, and the package export and import keep + the quantity, the unit, the key, and the value. A heart-rate point of + zero is still left out. A negative `temperature_deviation` is still + stored. A 2.1.0 mapped file and this pull, in either order, keep one record id and the old import key. Every row in the appendix table has one raw fixture and one day fixture. Check, export, and import keep the input pair, the standard pair, and the day window. Raw @@ -1412,7 +1531,13 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: `provider_or_aggregator` - body fetched during a historical range is the current object. Weight with no time has no `recorded_at` and does not use the average window. - A latest value with a null time is stored the same way. Age is a source + A latest value with a null time is stored the same way. A body object + whose `skin_temperature_measured_at` is a raw-looking instant, and one + whose timestamp is a day `period_start`, both keep the amount, the unit, + and the timestamp on the original. The skin-temperature child has no + `recorded_at`. Import, pull, and the native package roundtrip keep that + child out of an instant calculation. A raw skin-temperature sample and a + day skin-temperature window keep their own classes. Age is a source report. The service calculates it, and the record has no `field_basis`. BMI's basis is omitted. The three groups can arrive together or alone. JSON null and a returned zero and a missing field @@ -1515,7 +1640,11 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: a manual workout. The same server id arriving later as `automatic` refuses the page, and the stored session stays. A later pull of the same manual workout updates that session. Export and import keep the - pair that was accepted. + pair that was accepted. `workout-drift` named on that manual session + uses its start and end. A wearable sample inside the window is an input. + A manual sample and the session's own heart rate and distance are not. + A record query without `include_manual` omits the manual session. The + same query with `include_manual` true returns it. `page-raw.json` is stored. RMSSD and SDNN stay different quantities - a changed end time keeps the record id and increases the revision @@ -1535,6 +1664,15 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: - a deleted mapped source is left out. A Garmin file import of a different workout remains a second source - `left_out` in the result is a total and at most 20 examples +- a synthetic Polar list with samples, zones, and a route stores one + original. The nested samples are not measurement samples. A second pull + of the same vendor id updates that original and does not create a + session. The stored workout with a different Open Wearables id stays a + separate session. A device id on the vendor object does not set + `device_binding`. A Garmin list sends the requested upload window. A + Whoop list is one page. A missing vendor id refuses that list and + archives nothing. Preview and `--json --yes` write none of these rows. + The result text does not print a route coordinate Migration tests, in the build gate: @@ -1688,14 +1826,18 @@ The build, after approval, is one pull request in this order. First the schema and step 5: the root `record_type` check, the period type, the `aggregator` basis, the sample series quantities in the appendix table, the `source_report` type and table, the paired null value and unit, and -the time-unknown summary. Then the store, the calculation null filter, +the time-unknown summary. The v1 point check and the mapping's positive +check accept a finite `hr_recovery`, including zero and a negative number. +`src/schema.ts` is not edited. No table is rebuilt for that check. Then the store, the calculation null filter, the archive transaction, and the record paths in section 6. Then the mapping engine and `mappings/open-wearables.md`. Then the reads, the cycle filter, the smaller-page split, and the tests in section 7. The laptop card and the phone proof are part of that same pull request. This plan pull request has no media. The maintainer approves or rejects this plan before any build. D198 through -D209 are the proposal. They are not adopted. Reviews of earlier heads were +D213 are the proposal. They are not adopted. The stored workout and the +provider-live original stay separate records, because the public stored +workout has no vendor id. That split is part of this proposal. Reviews of earlier heads were incorporated here. None of those reviews approves this revision. The next head needs re-review. An earlier review accepted a migration with no new column, under D152 and D184. That acceptance does not From e145fa661a615da55cd67e22cf0ffa1684765b45 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 14 Nov 2026 19:30:58 +0000 Subject: [PATCH 14/60] Correct the live vendor workout procedure in the 2.2.0 plan. D214 makes those reads opt-in and keeps one provider's failure on that provider. D215 keeps each vendor object whole and refuses a token-shaped key. Co-authored-by: Michael Whitham --- .../v2.2.0/appendix/open-wearables-api.md | 19 +- build-history/v2.2.0/decisions.md | 122 +++++- build-history/v2.2.0/progress.md | 2 +- build-history/v2.2.0/spec.md | 381 ++++++++++++------ 4 files changed, 369 insertions(+), 155 deletions(-) diff --git a/build-history/v2.2.0/appendix/open-wearables-api.md b/build-history/v2.2.0/appendix/open-wearables-api.md index 8124ee31..10009f6f 100644 --- a/build-history/v2.2.0/appendix/open-wearables-api.md +++ b/build-history/v2.2.0/appendix/open-wearables-api.md @@ -465,7 +465,24 @@ have `external_id`. The public model does not return it. The live routes are `vendor_workouts.py`. Both handlers call `get_workouts_from_api` or `get_workout_detail_from_api` and return that -value. Neither handler writes a row. +value. Neither handler inserts a workout row. + +The authenticated client can still change the server. Checked in the same +commit on 14 November 2026. `refresh_access_token` calls +`update_tokens` and saves the new vendor token. `revoke_connection` marks +the connection revoked and calls `on_connection_revoked`, which emits +`connection.revoked`. Revoke runs when refresh is missing, when refresh +is rejected, and after auth has failed for `DEAD_GRANT_AFTER` of one day. +The client writes Redis keys `token_refresh_lock` and +`provider_auth_failing_since`. On HTTP 429, `RETRY_BASE_DELAY` is 15 +seconds and `MAX_RETRIES` is 3, so the waits are 15, 30, and 60 seconds. +A nearby comment says 1, 2, and 4 seconds. The constant is 15. + +`GET /api/v1/users/{user_id}/connections` returns the user's connections. +The pinned Strava page lists 200 requests per 15 minutes for the standard +tier and 400 for extended access. Garmin's live method accepts upload +start and end. A range the method itself splits can hide a failed chunk. +This plan has the client send windows of 24 hours or less instead. Polar's live methods pass `samples`, `zones`, and `route` through to `/v3/exercises`. The save path calls the list method without those diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index e5143671..993ee29a 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -950,8 +950,10 @@ no `include_manual` switch. `workout-drift` loads the session the caller names, including a manual session, and uses its start and end as the window. The samples then come from `read_inputs`, so a manual source's numbers are not inputs. The session's own heart rate and distance are not -inputs. Record queries omit manual sources unless `include_manual` is -true. A typed workout must not enter a device baseline. +inputs. `queryMeasurements`, `querySeries`, and `querySessions` omit +manual sources unless `include_manual` is true. A generic record listing +is not those three functions. A typed workout must not enter a device +baseline. Rejected alternatives: @@ -963,26 +965,29 @@ Rejected alternatives: ## D213. A provider-live workout is kept as an original -The stored workout list is the normalized session. The provider routes -return the vendor object and do not save it. Defaults leave workout -samples, FIT bytes, and raw payloads unstored unless that deployment -turned the flag on. This pull reads the two live GET routes and stores -the vendor object. +D214 is the live-read procedure. D215 is the privacy choice. Where this +proposal disagrees with either, those decisions are the proposal. + +The stored workout list is the normalized session. The provider route +handlers return the vendor object and do not insert a workout row. +Defaults leave workout samples, FIT bytes, and raw payloads unstored +unless that deployment turned the flag on. This pull can store the vendor +object when the person passes `--vendor-workouts`. The original is a `source_report` of kind `original`, subject -`vendor_workout`, on the non-device Open Wearables source. The match key -is the provider plus the vendor workout id. A later pull updates that -original. It is not a second workout session, and it is not joined to the -stored session by time. The public stored workout has no `external_id`. -Device names, device ids, routes, and nested samples stay inside the -original. They do not set `device_binding`, and they are not measurement -samples. Calculations do not read the original. - -The pull uses the published query parameters, does not retry, and does -not call sync, historical sync, or a provider whose live method is -missing. A completed provider line means that provider's stated limit was -reached. It does not mean the vendor returned lifetime history. The same -API key is used. No new vendor permission is added. +`vendor_workout`, writer `open_wearables`, sensor +`ow1:["vendor_workout", provider]`. The match key is the provider plus +the vendor workout id. It is not a second workout session, and it is not +joined to the stored session by time. The public stored workout has no +`external_id`. Device names, device ids, routes, and nested samples stay +inside the original. They do not set `device_binding`, and they are not +measurement samples. Calculations do not read the original. + +The pull uses the published query parameters and does not add its own +retry. It does not call sync or historical sync. A completed provider +line means that provider's stated limit was reached. It does not mean the +vendor returned lifetime history. The same API key is used. No new vendor +permission is added. Rejected alternatives: @@ -992,5 +997,80 @@ Rejected alternatives: session already exists, and the public workout has no vendor id to join them. - Call sync or historical sync to fill the gap. Rejected. Those routes - write on the server. This pull only reads. + are writes this pull does not call. + +## D214. A live vendor read is opt-in, and one failure stays on that provider + +This supersedes the D213 sentences that said a live GET does not write on +the server, that a failed provider stops the later providers, that Polar's +list asks for samples, zones, and route, that a start outside the range +is dropped, and that the server splits a Garmin range. + +`--vendor-workouts` is off unless the person passes it. Off, preview and +`--json` call neither the connections route nor a live workout route. +On, those calls run for a preview too. The preview writes nothing in this +database and prints `vendor requests were made`. + +The server, while answering the GET, can save a refreshed vendor token, +revoke a connection, emit `connection.revoked`, write `token_refresh_lock` +and `provider_auth_failing_since`, and on HTTP 429 sleep 15, then 30, +then 60 seconds, up to three retries. This program does not add a retry +of its own. + +The pull reads `GET /users/{id}/connections` and calls only a connected +provider that has a live list method. The order is Garmin, Polar, Suunto, +Whoop, Fitbit, Oura, Strava, Withings, Sensorbio. A provider that is not +connected, and a connected provider with no live list method, is +`not_attempted`. One failure leaves that line `incomplete`. The others +still run. + +Garmin is split by this program into windows of 24 hours or less, one +call each, with a 120 second read timeout. Any failed window makes Garmin +`incomplete`. Polar's list omits samples, zones, and route. Detail asks +for all three. One combined object is written once per command. A second +identical pull changes no row. A thinner object does not replace a richer +stored original. A failed detail keeps the list object. + +Every returned original is stored, including a start outside `--from` and +`--to`. The count is `vendor workout originals`. `range_complete` uses +only the stored ranged reads. Each line says whether its limit covers the +requested range and whether more data exists. Strava detail stops at 20 +calls per command. Later ids are deferred. Their list objects are stored. + +The unwrap, the id, and the start field for each provider are the table +in the spec. File import uses the same envelope. The provider logic lives +in `crates/ath-core/src/vendor_workouts.rs`, driven by one table. +`open_wearables.rs` calls that module. + +Rejected alternatives: + +- Leave live reads on by default. Rejected. The server can change a token + and revoke a connection while answering the GET. +- Stop the later providers after one failure. Rejected. A person connected + only to Garmin must still finish when another provider is absent, and a + failed provider must not hide a finished one. +- Let the server split a Garmin range. Rejected. A failed window must be + visible as incomplete. +- Drop an original whose start is outside the requested range. Rejected. + The live methods do not filter by workout start, so a drop would hide a + returned object. + +## D215. Vendor originals stay whole. The maintainer can change this + +This is a labeled choice. The default in this proposal is to keep each +vendor object whole, including account ids, Polar user URLs, and full GPS +routes. The reason is a complete, portable copy of what the vendor +returned. The output and the spec say those fields are included. + +The scan still refuses the API key, the selected origin, and the selected +user id. It also refuses an object key whose letters, after dropping `_` +and `-` and ignoring case, are `useraccesstoken`, `accesstoken`, +`refreshtoken`, `apikey`, `authorization`, `password`, `secret`, or +`clientsecret`. `polar_user` and a coordinate are not those keys. + +Rejected alternatives: + +- Strip account ids, user URLs, and routes before storage. Not chosen. + The stored object would no longer be the object the vendor returned. + The maintainer can replace this decision before approval. diff --git a/build-history/v2.2.0/progress.md b/build-history/v2.2.0/progress.md index 092214d5..679fce70 100644 --- a/build-history/v2.2.0/progress.md +++ b/build-history/v2.2.0/progress.md @@ -5,7 +5,7 @@ program, the record, or the database has changed for 2.2.0. | Step | What | Status | |---|---|---| -| 0 | The plan: proposals D198–D213, and the Open Wearables study. D210 through D213 correct body skin-temperature time, finite heart-rate recovery, the manual-session window, and provider-live workout originals. Still not adopted. The new head needs re-review | written, not approved | +| 0 | The plan: proposals D198–D215, and the Open Wearables study. D210 through D212 stay. D214 corrects the live-read procedure. D215 is the privacy choice for vendor objects. Still not adopted. The new head needs a fresh four-role review | written, not approved | | 1 | Version 2.2.0 and migration step 5. No new column on an existing table. The root check gains `source_report` by the copy in D207. Summary and score values may be omitted in pairs (D198, D207) | not started | | 2 | `ath pull openwearables` in `ath-core`, with the rewritten mapping (D199, D201, D207) | not started | | 3 | Key, server, and user id kept out of the record (D200) | not started | diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index 03cceec7..b483f3a3 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -3,12 +3,13 @@ Status: **plan only. The maintainer has not approved it. Not approved for build.** `ath pull openwearables` reads one person's stored health data from an Open -Wearables server they run, and the provider-live workout list and detail -that server already exposes. It writes both with the mapping this release -ships. The proposals are D198 through D213 in +Wearables server they run. When `--vendor-workouts` is passed, it also +reads the live workout list and detail. It writes the stored reads with +the mapping this release ships. It writes a live original only when that +flag is on and the person confirms the write. The proposals are D198 through D215 in [decisions.md](decisions.md). They are not adopted. The evidence is [appendix/open-wearables-api.md](appendix/open-wearables-api.md), checked on -6, 7, and 8 November 2026. +6, 7, 8, and 14 November 2026. This pull request is the plan. The build after approval is one later pull request. This plan does not change a version number, a schema, a fixture, or @@ -47,6 +48,10 @@ The same three values may come from `OPEN_WEARABLES_BASE_URL`, `OPEN_WEARABLES_USER_ID`, and the key variable above. A flag wins over the environment when both are set. +`--vendor-workouts` is off unless the person passes it. Without it, the +command does not call the connections route or either live workout route. +With it, those calls run, including on a preview and on `--json`. + The first run writes nothing. `--json` writes nothing, including when `--yes` is also present. That is the same rule as `ath import --mapping`. `ath pull garmin --json` still writes. `--file` chooses a database, as on @@ -74,8 +79,17 @@ Preview text prints: - `reads finished` or `reads incomplete` - one line each for the twelve reads in section 2: `completed`, `failed`, or `not_attempted` -- one line each for the provider-live workout reads: `completed`, `failed`, - or `not_attempted`, plus the limit that read actually has +- one line each for the live workout providers: `completed`, `incomplete`, + or `not_attempted`, whether that limit covers the requested range, and + whether more data exists +- when `--vendor-workouts` is on: `vendor requests were made` +- when `--vendor-workouts` is on: `vendor workout originals` with new, + changed, and unchanged counts +- when `--vendor-workouts` is on, this sentence: a workout can appear twice, + once as the vendor original and once as the stored session. The original + is the source report whose subject is `vendor_workout`. It is never a + session and never a calculation input +- when `--vendor-workouts` is on: `These originals keep the vendor's account ids, user URLs, and full routes.` - for body, on a preview: `body snapshot would store` or `body snapshot would be empty`. On a confirmed write: `body snapshot stored`, `body snapshot empty`, or `body snapshot incomplete` @@ -89,13 +103,15 @@ Preview text prints: `--yes` without `--json` commits each successful page. That commit is one `apply_mapping` transaction (D189). It is not a completed pull. The text prints actual committed counts for pages kept. It prints `requested range - through is complete` only when every ranged read in section 2 -reached that read's terminal condition and every provider-live workout -read reached the limit stated for that provider. Body is not one of those -ranged reads. The success sentence does not say a vendor kept lifetime -history. The success sentence `pulled openwearables from through ` is -printed only when the range is complete and body and the personal record -also completed. A finished range with an incomplete body snapshot does not + through is complete` only when every stored ranged read in +section 2 reached that read's terminal condition. A live workout line does +not change that sentence. Body is not one of those ranged reads. The +success sentence `pulled openwearables from through ` is +printed only when that range is complete, body and the personal record +completed, and every live provider is `completed` or `not_attempted`. +An `incomplete` live provider prints `vendor workouts incomplete:` and the +provider name. The exit is then nonzero. The success sentence is not +printed. The stored range sentence can still say the range is complete. A finished range with an incomplete body snapshot does not print that sentence. The body line still says the snapshot is incomplete. If a later page fails, the child returns a typed outcome to the parent @@ -129,9 +145,10 @@ Public `--json`, with or without `--yes`, is only the preview outcome below. `archive_committed` are zero. `estimated` holds the protected page-local estimates. `estimated_archive` holds the archive estimates. `range_complete` is false. `reads_finished` is true only when -every read completed. The read status token is -`not_attempted`, in this object and in the text. The object has no key, -server, user id, or request path. +every stored read completed. `range_complete` ignores the live workout +lines. The read status token is `not_attempted`, in this object and in +the text. The object has no key, server, user id, or request path. +`vendor_workouts` is always present. ```json { @@ -159,12 +176,28 @@ server, user id, or request path. "archive_committed": { "source_report": { "new": 0, "changed": 0, "unchanged": 0 } }, - "left_out": { "total": 0, "examples": [] } + "left_out": { "total": 0, "examples": [] }, + "vendor_workouts": { + "requested": false, + "requests_made": false, + "originals": { "new": 0, "changed": 0, "unchanged": 0 }, + "providers": { + "garmin": { + "status": "not_attempted", + "covers_requested_range": false, + "more": false, + "deferred": 0, + "limit": "not requested" + } + } + } } ``` The same record types are present for workouts, points, summaries, scores, -and source reports. The example above is shortened. It is the preview +and source reports. The example above is shortened. Polar, Suunto, Whoop, +Fitbit, Oura, Strava, Withings, and Sensorbio use the same fields as +`garmin`. Those names are the public `--json` keys. It is the preview outcome. A preview does not say a snapshot was stored. The child returns a different outcome for `--yes` without `--json`. That @@ -174,8 +207,9 @@ counts, `database_changed`, `protected_write`, `archive`, records only. `archive_committed` counts archive records only, including a created archive source, counted once. A record is in one of those maps. `new`, `changed`, and `unchanged` are the created, revised, and -unchanged counts in each map. `range_complete` is true when the ranged reads -finished and no protected page in those reads was refused. `snapshots_complete` +unchanged counts in each map. `range_complete` is true when the stored ranged reads +finished and no protected page in those reads was refused. A live workout +line does not change it. `snapshots_complete` is true when the personal record and the body snapshot finished. `written` is true when any protected transaction in this command created or revised a counted record. A command that only repeats unchanged protected pages, @@ -231,12 +265,15 @@ the failed-init sentence. D209 stores a workout the person typed as a workout session. D210 keeps a body skin-temperature time unknown when the response does not say it is an instant. D211 keeps a finite `hr_recovery`, including zero and a negative number. D212 keeps the -current manual-session calculation rule. D213 stores the provider-live -workout list and detail as originals. An earlier draft +current manual-session calculation rule. D213 stores the live +workout list and detail as originals. D214 is the live-read procedure. +D215 keeps each vendor object whole. An earlier draft left day values, the heart-rate stream, summaries, and workout segments for a later version. That draft is superseded. File imports stay. The Garmin pull stays. A Junction pull is proposed as 2.3.0. Automatic sync, retries, token refresh, and backfill are proposed as -2.4.0. None of those numbers is adopted. This release adds one module for +2.4.0. None of those numbers is adopted. This release does not add its +own token refresh. A live read can still make the server refresh one, as +section 2 says. This release adds one module for this server. It does not add a connector interface. This pull stores the representations Open Wearables 0.11.0 returns for one @@ -340,9 +377,10 @@ stored on an automatic workout. `field_basis.activity_type` is name. The numbers on this session do not enter the eight range calculations or `provider-period-summary`. `workout-drift` may use the session's start and end as its window when the caller names that session. -The samples in that window still exclude `source_type` `manual`. Record -queries omit manual sources unless `include_manual` is true. This pull -does not change those controls. The session does not enter a device +The samples in that window still exclude `source_type` `manual`. +`queryMeasurements`, `querySeries`, and `querySessions` omit manual +sources unless `include_manual` is true. This pull does not change those +three functions. Other record listings are not that switch. The session does not enter a device baseline. `unknown`, JSON null, and a missing `entry_source` are source reports of kind `unknown_workout`. They are not a workout session, and they are not @@ -431,6 +469,7 @@ appendix table, fails before any request. | Meal | `{ "meal": data }` | `source.provider` | `ow1` event | `source_report` subject `object`, meal id | one `source_report` per numeric field path | | Cycle | `{ "cycle": data }` | `source.provider` | `ow1` event | `source_report` subject `object`, cycle id | one `source_report` per numeric reported length | | Personal record | the object after `user_id` is removed | `open_wearables` | `ow1` personal | `source_report` subject `personal_record` | none | +| Vendor workout | one combined list and detail object | `open_wearables` | `ow1:["vendor_workout", provider]` | `source_report` subject `vendor_workout`, key is provider plus vendor id | none. The whole vendor object is the record | `source_report` is not one of the seven measured record types in SPEC section 5.4. It has a source, so it is not an athlete report and it is @@ -766,91 +805,121 @@ The following are not requested. Each line is the reason. - Sleep totals, workout totals, and activity totals. They add up rows the lists return. - The data summary and the data timeline. They count stored rows. -- Accounts, connections, sync, OAuth, webhooks, API keys, config, uploads, - and every `DELETE`. They are not health readings. The API key, the - server address, and the user id are not written into the athlete record. - `/sync` and `/sync/historical` are not called. - -The two provider-live reads are +- Accounts, sync, OAuth, webhooks, API keys, config, uploads, and every + `DELETE`. They are not health readings. The API key, the server address, + and the user id are not written into the athlete record. `/sync` and + `/sync/historical` are not called. The connections list is called only + when `--vendor-workouts` is on. + +`--vendor-workouts` is off by default. Off, the command makes no request +to `/api/v1/users/{user_id}/connections` and no request to either live +workout route. Preview and `--json` without the flag make those zero +requests. On, the same preview and `--json` do make them, write nothing +in this database, and print `vendor requests were made`. + +A live call can change the server. `api_client.py` at +the pinned commit can refresh a vendor token and save it, revoke a +connection when refresh is missing or auth has failed for a day, and emit +`connection.revoked`. It writes the Redis keys `token_refresh_lock` and +`provider_auth_failing_since`. On HTTP 429 it sleeps 15, then 30, then 60 +seconds, up to three retries. This pull does not add its own retry. It +does not add a vendor token or a new scope. The server may still do the +work above while answering the GET. + +With the flag on, the pull reads connections first. It then calls only a +connected provider whose live list method exists. The order is fixed: +Garmin, Polar, Suunto, Whoop, Fitbit, Oura, Strava, Withings, Sensorbio. +A provider that is not connected, and a connected provider with no live +list method, is `not_attempted`. That is not a failure. One provider's +failure leaves its line `incomplete` and the other providers still run. +Apple, Samsung, Health Connect, Ultrahuman, and Google Health have no +live list method. Their stored workouts still come from `/events/workouts`. + +The list and the detail for one vendor id are combined in memory. The +command writes that one original once. A second pull of the same object +reports the original unchanged and does not change the database for that +row. A failed detail keeps the list object, marks that detail incomplete, +and still writes the list object when no richer original is already +stored. A later payload that lacks a samples, zones, or route array the +stored original already has is not written. The richer original stays. + +Every returned original is stored, including one whose start is outside +`--from` and `--to`. The same rule is used for every provider. The count +is `vendor workout originals`. `range_complete` uses only the stored +ranged reads. Each live line names its limit, says whether that limit +covers the requested range, and sets `more` when the response shows +another page. Whoop sets `more` when `next_token` is present. Oura sets +`more` when `next_token` is present. Sensorbio sets `more` when +`links.next` is present. Strava sets `more` when the page length equals +`per_page`. Those tokens are not followed. The published route does not +accept them as the next request. `covers_requested_range` is false for +every provider in this pin. None of the live methods filter by the +workout's start inside `--from` and `--to`. + +The routes are `GET /api/v1/providers/{provider}/users/{user_id}/workouts` and `GET /api/v1/providers/{provider}/users/{user_id}/workouts/{workout_id}`. -They use the same API key as the stored reads. They do not add a vendor -token, a scope, or a write. The route returns the provider method's -response. It does not save that response. This pull saves it. - -The original is a `source_report` of kind `original`. Its subject is -`vendor_workout`. Its source is the non-device Open Wearables source, not -the watch's source. `provider_record_id` is the provider name plus the -vendor workout id the save path already uses: Polar `id`, Garmin -`activityId`, Suunto `workoutId`, Whoop `id`, Oura `id`, Strava `id`, -Fitbit `logId`, Withings `id`, and Sensorbio `id`. A later pull of that -same id updates that original. The original is not a second -`workout_session`. The stored session stays matched by the Open Wearables -workout id. The public stored workout object has no `external_id`, so -this pull does not join the original to the session by time, distance, or -device. A manual session stays the manual session. A device id, a device -name, and a route inside the vendor object stay on the original. They do -not set `device_binding`. Nested samples stay inside the original. They -are not written again as measurement samples. The eight range -calculations do not read the original. - -A list item with no vendor id refuses that provider's list page. The -refusal follows the missing-id rule, including no archive. Detail is -requested only after the list item has an id, and only for a provider -whose detail method returns the vendor object. The detail replaces the -same original when its vendor id matches. A detail with a missing or -different id is not stored. The list original stays, and the result names -the mismatch. A detail method that raises `NotImplementedError` is not -called. That is not an empty workout list. - -The pull sends only the query parameters the route publishes. It does not -retry a transport failure. A response over 8 MiB is handled by the same -rule as the other reads: Suunto is asked again with a smaller `limit`, -down to 1. A route with no `limit` fails that read and names it. Route -coordinates are stored on the original and are not printed in the result -text. The privacy scan still refuses a page that contains the key, the -selected origin, or the selected user id. - -Each provider's list is what that method does when the route's parameters -are all it receives, except Garmin and Suunto, whose time parameters the -route does publish. - -- Polar sends `samples=true`, `zones=true`, and `route=true`. The route - has no date. The provider document says the exercise list is the - exercises available in Polar Flow. A start outside the requested range - is not stored and is not `left_out`. One list over 8 MiB fails the read. -- Garmin sends `summary_start_time` and `summary_end_time` from the - requested range. The method puts those values in - `uploadStartTimeInSeconds` and `uploadEndTimeInSeconds`. The result says - the filter is upload time. An omitted range would be the method's last - 24 hours, so this pull always sends the range. A range over 24 hours is - chunked by that method. +The original is a `source_report` of kind `original`, subject +`vendor_workout`, writer `open_wearables`, sensor +`ow1:["vendor_workout", provider]`. The key is the provider name plus the +vendor id. The start field is stored and is not a filter. A missing id +refuses that one object and does not archive it. The other objects from +that provider are still stored. The original is not a workout session. +The stored session stays matched by the Open Wearables workout id. The +public stored workout has no `external_id`, so the two records are not +joined by time, distance, or device. A device id inside the vendor object +does not set `device_binding`. Nested samples stay inside the original. +The eight range calculations do not read it. + +| Provider | List unwrap | Id | Start field | +|---|---|---|---| +| Polar | the JSON array | `id` | `start_time` | +| Garmin | the JSON array | `activityId` | `startTimeInSeconds` | +| Suunto | `payload` | `workoutId` on the list. Detail may name the same value `workoutKey`. A different `workoutKey` is a mismatch and that detail is not stored | `startTime` | +| Whoop | `records` | `id` | `start` | +| Oura | `data` | `id` | `start_datetime` | +| Strava | the JSON array | `id` | `start_date` | +| Fitbit | the JSON array. The method reads `activities` and returns the rows | `logId` | `startTime` | +| Withings | the JSON array. The method reads `series` and returns the rows | `id` | `startdate` | +| Sensorbio | `data[].activities[]` | `id` on the nested activity | `start_time` | + +- Polar's list omits `samples`, `zones`, and `route`, so the route sends + false and the list stays under the 8 MiB cap when it can. Detail sends + all three true, one call per exercise id. A list over 8 MiB fails that + list. Detail is also called for Suunto, Whoop, and Oura. It is not + called for Fitbit, Withings, or Sensorbio. A provider with no detail + stores the list object alone. +- Garmin is split by this program into windows of 24 hours or less, one + call each. A longer window is not sent. Each call sends + `summary_start_time` and `summary_end_time`. The server puts those + values in `uploadStartTimeInSeconds` and `uploadEndTimeInSeconds`. The + read timeout for each window is 120 seconds. Any failed window makes + Garmin `incomplete`. A later window still runs. The server's own + provider timeout is a separate setting. Its default is 30 seconds. + Detail is called for each stored id. - Suunto sends `since` as the requested start in Unix milliseconds, `filter_by_modification_time=false`, `limit` 100, and pages `offset` - until a short page. False means creation time, not workout start. - Detail is the workout URL with no `extensions` parameter. -- Whoop, Oura, and Strava have no date parameter on this route. Whoop is - one call with the method's limit of 25 and no `nextToken`. Oura is one - call with no date and no `next_token`. Strava is one call at page 1. - The method's `per_page` default is 200. Their detail methods are called - for ids on that page. -- Fitbit's list method uses the last 30 days when the route sends no - dates. Its detail method is not implemented and is not called. -- Withings uses `pull_sync_lookback` when set, otherwise 30 days, widens - each edge by one local day, and pages inside the method. Detail is not - implemented and is not called. -- Sensorbio uses the route's `limit` of 50 and `last-timestamp` 0. Detail - is not implemented and is not called. -- Apple, Samsung, Health Connect, Ultrahuman, Google Health, `internal`, - and `unknown` are not called. Apple, Samsung, Health Connect, and - Ultrahuman have no workout object on the strategy, and the route would - answer 501. Google Health does not implement the live method. Stored - workouts from those providers still come from `/events/workouts`. - -These reads run after the twelve stored reads. A completed line means that -stated limit was reached. It does not mean the vendor's lifetime history -was returned. A failed provider stops later provider reads, keeps earlier -commits, and exits nonzero. The success sentence is not printed. + until a short page. False means creation time. Detail sends no + `extensions` parameter. A page over 8 MiB is asked again with a smaller + `limit`, down to 1. +- Whoop is one call. The method caps `limit` at 25 and sends no + `nextToken`. Oura is one call with no date and no `next_token`. Strava + is one list call at page 1. The method's `per_page` default is 200. +- Strava detail calls stop at 20 per command. The server can retry one + call three times, so 20 calls can become 80 provider requests. That + stays under 100 per 15 minutes, and under the 200 per 15 minutes on the + pinned Strava page. Ids past the budget are `deferred`. Their list + objects are stored. The detail is not called. +- Fitbit's list uses the last 30 days when the route sends no dates. + Detail is not implemented and is not called. Withings uses + `pull_sync_lookback` or 30 days, widens each edge by one local day, and + pages inside the method. Detail is not called. Sensorbio uses `limit` + 50 and `last-timestamp` 0. Detail is not called. + +A saved file imports the same envelope. Export and import keep one +original id. The per-provider unwrap lives in +`crates/ath-core/src/vendor_workouts.rs`, driven by one provider table. +`open_wearables.rs` calls that module. It does not grow a provider branch. Day rows are one selected row per source, series, and local day. The repository prefers `computed_by: provider`, then the later provider row. @@ -881,7 +950,9 @@ replace on change (D182), source and device (D183), one transaction per call are empty or `__proto__` (D191). A Garmin file import remains a different `data_route`, so both copies of one workout stay (D161). A second pull of the same Open Wearables object, or an `ath import --mapping open-wearables` of a -saved copy of that object, updates the same rows. +saved copy of that object, keeps the same rows. An identical vendor +original changes no row. A changed object replaces the stored one, except +a thinner vendor workout, which section 2 refuses. On a device source, the writer is `source.provider`. The sensor string is `source.device_type`, `source.device`, and `source.source`. Section 2's @@ -1076,7 +1147,8 @@ built without that field. Day rows carry it, and those rows are stored. ## 4. Credentials, privacy, and the network D200 is the rule. The key never enters the athlete database, the export, the -preview, or an error line. The pull reads only the paths in section 2. +preview, or an error line. The pull reads the paths in section 2. Connections and the two live +workout routes are included only when `--vendor-workouts` is on. It does not list users. A raw HTTP personal-record response includes `user_id`. That field must be a string UUID equal to the selected user id. Absence, null, a non-string, and any other string refuse the page before redaction and @@ -1090,13 +1162,20 @@ gender, and sex are stored. They are account health data, not the API key. The process refuses a base URL that could carry the key in the URL itself. It refuses plain `http` except to loopback. It does not follow a redirect, so the key cannot be sent to a second host. One attempt, then stop. Timeouts are -10 seconds to connect and 30 seconds to read. One response may be at most +10 seconds to connect and 30 seconds to read. A Garmin live window may +take 120 seconds to read. One response may be at most 8 MiB. One read may be at most 1000 pages. The body is read inside that cap and parsed before any `apply_mapping` call. The guard is in `open_wearables.rs`. It walks every decoded object key and every decoded string. A value that contains the API key, the selected -origin, or the selected user id rejects the whole page. The matching personal-record `user_id` is the only field that is dropped +origin, or the selected user id rejects the whole page. A key whose +letters, after dropping `_` and `-` and ignoring case, are +`useraccesstoken`, `accesstoken`, `refreshtoken`, `apikey`, +`authorization`, `password`, `secret`, or `clientsecret` also rejects +the page. `polar_user` and a route coordinate are not those keys. D215 +keeps the rest of the vendor object, including account ids, Polar user +URLs, and full routes. The matching personal-record `user_id` is the only field that is dropped before this walk. Any other copy of the user id still rejects the page. A raw personal-record `user_id` that is absent, null, the wrong type, or not the selected user refuses the page before the drop. The page is not @@ -1266,6 +1345,7 @@ interactive open can preview, back up, ask, and then migrate. | Piece | Place | |---|---| | HTTP, page loop, envelope split, call `apply_mapping` | `crates/ath-core/src/open_wearables.rs` | +| Live provider table, unwrap, windows, and detail budget | `crates/ath-core/src/vendor_workouts.rs` | | Command `pull-openwearables` | `crates/ath-core/src/main.rs` | | Flags, key, preview text, refusal if the key appears | `src/program.ts`, `src/help.ts`, `src/keyring.ts` | | Mapping names and field rules | the existing file `mappings/open-wearables.md` | @@ -1307,8 +1387,10 @@ pair and the new table. `src/db/check-tables.ts` gains the `include_manual` switch. `workout-drift` loads the named session first, including a manual session, and uses that session's start and end as the window. Its samples then go through `read_inputs`. A manual source's -numbers stay out. Record queries omit manual sources unless -`include_manual` is true. This proposal does not change that code. In +numbers stay out. `queryMeasurements`, `querySeries`, and +`querySessions` omit manual sources unless `include_manual` is true. +This proposal does not change that code. A generic record listing is +not those three functions. In `read_inputs` and `read_period`, a provider summary or provider score whose `standard_value` or `standard_unit` is null is excluded in the SQL, before the limit, the count, the grouping, and the numeric decode. A null @@ -1643,8 +1725,9 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: pair that was accepted. `workout-drift` named on that manual session uses its start and end. A wearable sample inside the window is an input. A manual sample and the session's own heart rate and distance are not. - A record query without `include_manual` omits the manual session. The - same query with `include_manual` true returns it. + `queryMeasurements`, `querySeries`, and `querySessions` omit the manual + session unless `include_manual` is true. That switch is not claimed for + every record listing. `page-raw.json` is stored. RMSSD and SDNN stay different quantities - a changed end time keeps the record id and increases the revision @@ -1664,15 +1747,42 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: - a deleted mapped source is left out. A Garmin file import of a different workout remains a second source - `left_out` in the result is a total and at most 20 examples -- a synthetic Polar list with samples, zones, and a route stores one - original. The nested samples are not measurement samples. A second pull - of the same vendor id updates that original and does not create a - session. The stored workout with a different Open Wearables id stays a - separate session. A device id on the vendor object does not set - `device_binding`. A Garmin list sends the requested upload window. A - Whoop list is one page. A missing vendor id refuses that list and - archives nothing. Preview and `--json --yes` write none of these rows. - The result text does not print a route coordinate +- a synthetic Polar list without samples, zones, and route, then one + detail with all three true, stores one original. The nested samples are + not measurement samples. A second identical pull changes no row and + reports no database change for that original. A thinner detail does not + replace a stored original that already has samples, zones, or a route. + A failed detail keeps the list object and marks that detail incomplete. + The stored workout with a different Open Wearables id stays a separate + session. A device id on the vendor object does not set `device_binding`. + The result text does not print a route coordinate. It does say the + originals keep account ids, user URLs, and full routes +- without `--vendor-workouts`, preview and `--json` make zero requests to + the connections route and to both workout routes. `requests_made` is + false and every live line is `not_attempted`. With the flag, preview + and `--json` still write nothing, `requests_made` is true, and the text + says vendor requests were made +- a connections list with only Garmin completes Garmin and marks Polar, + Suunto, Whoop, Fitbit, Oura, Strava, Withings, and Sensorbio + `not_attempted`. A failed Polar list does not stop Garmin +- one failed Garmin window makes Garmin `incomplete` and never + `completed`. A later window still runs +- a Sensorbio body stores `data[].activities[].id`. A missing id refuses + that object and keeps the others. File import of the saved original, + then export, keeps one record id +- a Polar exercise whose start is outside `--from` and `--to` is stored + and counted under `vendor workout originals`. `range_complete` still + follows the stored ranged reads +- Whoop `next_token`, Oura `next_token`, Sensorbio `links.next`, and a + Strava page whose length equals `per_page` set `more` true. + `covers_requested_range` is false. The 21st Strava detail id is + `deferred`. Its list object is stored +- `--json` includes `vendor_workouts.requested`, `requests_made`, + `originals`, and each provider's `status`, `covers_requested_range`, + `more`, `deferred`, and `limit` +- a page whose key is `userAccessToken`, `access_token`, `refresh-token`, + `apiKey`, `authorization`, `password`, `secret`, or `client_secret` is + refused. A `polar_user` URL and a route coordinate are stored Migration tests, in the build gate: @@ -1735,7 +1845,9 @@ pass, and `cargo test` passes, before the build is called done. ## 8. You test this (Laptop) The card uses the fixture server the tests use. It does not use a real -account or a real export. The build starts that server on `127.0.0.1` and an +account or a real export. The fixture user has a Garmin connection and no +other connection. The card does not pass `--vendor-workouts`, so it makes +no live vendor request. The build starts that server on `127.0.0.1` and an ephemeral port, prints the port, and uses the fixture key and the fixture user id. The range is `--from 2026-01-01 --to 2026-01-07`. The person pastes the fixture key once into `ath key set openwearables`. @@ -1745,11 +1857,13 @@ the fixture key once into `ath key set openwearables`. init fails, or the key is printed. 2. Preview. Success: the pull without `--yes` says nothing is stored, shows estimated counts that include a heart-rate sample and a day summary, shows - a body snapshot line, and `ath check` still passes. Failure: a row is - written, or the key appears. + a body snapshot line, makes no vendor request, and `ath check` still + passes. Failure: a row is written, a vendor request is made, or the key + appears. 3. Write. Success: the same command with `--yes` says the requested range is complete, shows the body snapshot line, shows committed counts, and - `ath check` exits 0. Failure: the success sentence appears while the + `ath check` exits 0. The stored range can be complete with only Garmin + connected. Failure: the success sentence appears while the range or the body snapshot is incomplete, or `ath check` fails. 4. Repeat. Success: `--yes` again reports the stored rows unchanged. Failure: a second copy of a sleep session or a point appears. @@ -1835,9 +1949,10 @@ cycle filter, the smaller-page split, and the tests in section 7. The laptop car part of that same pull request. This plan pull request has no media. The maintainer approves or rejects this plan before any build. D198 through -D213 are the proposal. They are not adopted. The stored workout and the -provider-live original stay separate records, because the public stored -workout has no vendor id. That split is part of this proposal. Reviews of earlier heads were +D215 are the proposal. They are not adopted. The stored workout and the +live original stay separate records, because the public stored +workout has no vendor id. That split is part of this proposal. D215 is the +privacy choice, and the maintainer can change it before approval. Reviews of earlier heads were incorporated here. None of those reviews approves this revision. The next head needs re-review. An earlier review accepted a migration with no new column, under D152 and D184. That acceptance does not @@ -1856,7 +1971,9 @@ optional source key adds no column. connection turns them off only before its transaction and reads them back on after every exit. A `2.1.0` database does not open until `ath migrate`. This release does - not schedule, refresh a token, backfill, or store a cursor (D198, D208). + not schedule a pull, add its own token refresh, backfill, or store a + cursor (D198, D208). A live read can still make the server refresh a + vendor token (D214). 2. Store the returned representations in section 2. Device receipts stay on device sources. Summaries without a device id use their own sensors. Null stays null. A missing response is not called provider-unavailable. From 7f940f0515455d496b63a9d311e59f058fd7805b Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 02:39:20 +0000 Subject: [PATCH 15/60] Point the 2.2.0 plan at the 2.1.1 native program. The plan was read against the TypeScript program. Version 2.1.1 is the software on main, and its migration already uses step 5. The proposed migration is step 6. The pull, the store, and the mapping are named where they live in the native crate. Co-authored-by: Michael Whitham --- .../v2.2.0/appendix/open-wearables-api.md | 2 +- build-history/v2.2.0/decisions.md | 217 ++++++----- build-history/v2.2.0/progress.md | 9 +- build-history/v2.2.0/spec.md | 355 ++++++++++-------- 4 files changed, 319 insertions(+), 264 deletions(-) diff --git a/build-history/v2.2.0/appendix/open-wearables-api.md b/build-history/v2.2.0/appendix/open-wearables-api.md index 10009f6f..5248ee7d 100644 --- a/build-history/v2.2.0/appendix/open-wearables-api.md +++ b/build-history/v2.2.0/appendix/open-wearables-api.md @@ -134,7 +134,7 @@ schema. `zone_offset` is a separate string, `+01:00` or `-05:30`, or null. The 2.1.0 mapping file's timeseries lines do not name `heart_rate`. In Athletic Standard, `heart_rate` is a series quantity -(`SERIES_QUANTITY_UNITS` in `src/v1/schema.ts`). It is not one of the point +(the unit table in `src/model/data.rs`). It is not one of the point quantities the 2.1.0 mapping engine writes. D203 stores that stream as measurement samples. The 2.1.0 file, by itself, still has nowhere to put it. diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index 993ee29a..745199f7 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -1,6 +1,12 @@ # Decisions — v2.2.0 -D-numbers continue from [v2.1.0](../v2.1.0/decisions.md). D198 follows D197. +These proposals were numbered when D197 was the last decision on main. +They are still D198 through D215 in this folder. Version 2.1.1 has since +used those numbers. D198 through D207 are reserved by the unapproved draft +in [v2.1.1/appendix/draft-2.1.1/](../v2.1.1/appendix/draft-2.1.1/spec.md). +D208 through D226 are the 2.1.1 decisions. A citation in this folder means +the proposal below, not the 2.1.1 decision with the same number. This plan +does not renumber the proposals. Renumbering is waiting on the maintainer. These are proposals in [spec.md](spec.md). The maintainer has not adopted them. This pull request does not build them. A change of mind before @@ -15,21 +21,24 @@ command is manual. The person runs it. The program does not schedule it, retry a failed request, or sign the person in to a device maker. The program, the record, and the database become `2.2.0` together. D152 made -those one number. D184 kept that rule. Migration step 5 stores `2.2.0` and -SQL schema 5. It adds no column to an existing table. It rebuilds -`provider_summaries` and `provider_scores`, and it creates +those one number. D184 kept that rule. Version 2.1.1 kept it too. Migration +step 5 is already published. It stores `2.1.1` and SQL schema 5 in +`spec/sql/migrations/005-version-2-1-1.sql`. This pull adds step 6. Step 6 +stores `2.2.0` and SQL schema 6. It adds no column to an existing table. It +rebuilds `provider_summaries` and `provider_scores`, and it creates `source_reports`, as D205 describes. D207 drops the record views and the two cross-table triggers around the root rename. Existing rows keep -their numbers. Step 4 is not edited -(D165). A new database closes the step 4 transaction, then runs step 5, -which sets `user_version` 5. `applyMigrationStep` handles target 5 -outside `withWriteTransaction`. The migration chain, the SQL -contract generator, and the drift check gain that step. The package exports -point at `schema/2.2.0/`. `READABLE_DATABASE_VERSIONS` and -`ACCEPTED_RECORD_VERSIONS` keep `1.0.0`, `2.0.0`, and `2.1.0`, and gain -`2.2.0`. `IMPORTABLE_PACKAGE_VERSIONS` gains `2.2.0` and keeps `2.0.0` and -`2.1.0`. A `2.1.0` package still imports. A `2.1.0` database does not open -until `ath migrate`. +their numbers. Steps 1 through 5 are not edited (D165). `install_schema` in +`src/store/mod.rs` runs steps 1 through 5 in one transaction with foreign +keys on, then commits. Step 6 runs after that commit, on a connection +ordinary writes do not reuse, and sets `user_version` 6. `apply_step` in +`src/store/migrate.rs` handles target 6 outside that ordinary transaction. +`MIGRATION_CHAIN` in that file and `spec/sql/contract.json` gain the step. +`packages/npm/package.json` exports point at `schema/2.2.0/`. +`READABLE_DATABASE_VERSIONS` and `ACCEPTED_RECORD_VERSIONS` keep `1.0.0`, +`2.0.0`, `2.1.0`, and `2.1.1`, and gain `2.2.0`. `IMPORTABLE_PACKAGE_VERSIONS` +gains `2.2.0` and keeps `2.0.0`, `2.1.0`, and `2.1.1`. A `2.1.1` package +still imports. A `2.1.1` database does not open until `ath migrate`. The build is one pull request after this plan is approved. It is not split into a version change, a client, and a mapping change. @@ -72,15 +81,18 @@ Rejected alternatives: ## D199. The pull fetches pages and the shipped mapping writes the records -New Rust module `crates/ath-core/src/open_wearables.rs` requests the reads -in D203 and calls `apply_mapping`. The command-line front end stays in -TypeScript (D174). New imports stay in `ath-core` (D155). The HTTP client is +New module `src/runtime/open_wearables.rs` requests the reads +in D203 and calls `MappedReader`. The command is added in `src/cli/`, +beside `ath pull garmin` in `src/cli/commands/routes.rs`. Version 2.1.1 +superseded D174's TypeScript front end and the separate `ath-core` library +in D155 and D162. This pull does not bring either back. The library is the +`athleticstandard` crate at the repository root. The HTTP client is the `ureq` 2.12 dependency the Garmin pull already uses. No new crate. -The mapping file is resolved with `resolveMappingFile` in `src/skill.ts`, +The mapping file is resolved with `resolve_mapping` in `src/assets/mod.rs`, name `open-wearables`. An installed copy in `.agents/mappings/` wins, which -is D179. Rust receives the absolute path. It does not grow a second rule for -what a path looks like. +is D179. The pull does not grow a second rule for what a path looks like. +`is_mapping_path` in that file is the one rule. The mapping file chooses every stored field. The pull does not rename a field, choose a unit, or decide that a value is RMSSD or SDNN. A field the @@ -89,7 +101,7 @@ file does not name stays in `supplied_fields` under the name it arrived with D187, D192). Sleep and workout responses are envelopes with `data` and `metadata`. The -shipped file's page section is `timeseries`, so `apply_mapping` would leave +shipped file's page section is `timeseries`, so `MappedReader` would leave that envelope out. The pull passes sleep rows as `{ "sleep": [ ... ] }` and workout rows as `{ "workout": [ ... ] }`. It passes each timeseries response through unchanged, so `metadata.resolution` still reaches the mapping. The @@ -117,8 +129,9 @@ call. A comma-joined type string is still not sent. measurement samples. Workout `avg_heart_rate_bpm` and `max_heart_rate_bpm` stay as the file already maps them. -`apply_mapping` adds counts by record type and keeps the existing `outcome` -field. The pull adds those counts into the committed result for a page that +`MappedReader` adds counts by record type. The mapped-import report in +`src/import/provider.rs` keeps its `outcome` field. The pull adds those +counts into the committed result for a page that committed and into `estimated` for a page that was rolled back. It does not add `outcome` across pages. Estimated counts are against the database before this command. They are not equal to the write when the same match key appears @@ -146,9 +159,9 @@ Rejected alternatives: - Teach the pull the Open Wearables field names in Rust. Rejected because D161 put those names in the mapping file so a second source does not become a second record format. -- Pass the sleep envelope straight to `apply_mapping`. Rejected because the +- Pass the sleep envelope straight to `MappedReader`. Rejected because the current page rule would leave the page out. The check is `page_rows` and - `row_fits` in `crates/ath-core/src/mapping.rs`. + `row_fits` in `src/import/mapping.rs`. - Request every series type and let `left_out` drop the ones the mapping cannot store. Rejected. D203 stores them. `left_out` remains a row the server returned and this program refused for a named reason. @@ -173,7 +186,7 @@ Rejected alternatives: today, because that path is removed as hardware. - Put the receipt in `supplied_fields`, under `device_binding` or another name. Rejected. D185 keeps that object for names the source sent. A 2.1.0 - source may already hold an arbitrary value at that name, and step 5 must + source may already hold an arbitrary value at that name, and step 6 must not turn that value into authority. The receipt is the source object's own key `device_binding`. - Treat a nonempty string at the new key as proof no matter who wrote it, @@ -188,7 +201,10 @@ The API key is an administrator key for every user on that deployment. The pull sends it only as the header `X-Open-Wearables-API-Key`. It is saved with `ath key set openwearables` in the operating system password store, the same store D75 uses. The environment name for a script is `OPEN_WEARABLES_API_KEY`. -The child process receives it as `ATH_CORE_OPEN_WEARABLES_KEY`. The key is +The command reads that variable and the password store in this process, +in `src/runtime/keyring.rs`. There is no child process and no +`ATH_CORE_OPEN_WEARABLES_KEY`. `ath pull garmin` already reads +`GARMIN_PERSONAL_API_KEY` the same way. The key is not a command argument. If the password store is missing, the command refuses and does not write a file. @@ -231,7 +247,7 @@ a parser error is replaced with a fixed sentence that has no URL, no path, and no user id. After the body is read inside the size cap and parsed, and before -`apply_mapping`, `open_wearables.rs` walks every object key and every string. +`MappedReader`, `open_wearables.rs` walks every object key and every string. A value that contains the API key, the selected origin, or the selected user id rejects the whole page. The row is not rewritten. A scan of the raw text misses a Unicode escape. The raw-text scan and the check before printing @@ -259,7 +275,7 @@ Rejected alternatives: ## D201. A page is atomic, a missing row is not a deletion, and the same command is safe to repeat -Each response page is one `apply_mapping` call. D189 still makes that call +Each response page is one `MappedReader` call. D189 still makes that call one transaction: a failure rolls the page back, and a preview rolls the page back after counting. The pull itself is a series of those calls. The order and the terminal condition of each read are the table in the specification's section 2. @@ -272,7 +288,7 @@ with or without `--yes`, matching `ath import --mapping`. `--yes` without page is not a success. The pull-only archive in D208 is a separate transaction. It reads the safety facts again before it writes. -The child returns one bounded outcome for the mode it ran. A preview, +The command returns one bounded outcome for the mode it ran. A preview, including public `--json`, has `written` false, protected and archive committed zeros, estimated counts, and `range_complete` false. A confirmed `--yes` has the actual protected and archive counts. `written` is @@ -280,10 +296,11 @@ true when a protected transaction in the command created or revised a counted record. An archive does not make it true. `database_changed` is true when a protected transaction or an archive transaction committed a change. A successful repeat of an unchanged command has both flags false. -The parent renders the -confirmed outcome as text. It renders the preview outcome as public JSON. -On a partial failure the child returns the confirmed outcome and then exits -nonzero. The parent renders the text before it uses that status. +The command prints the +confirmed outcome as text. It prints the preview outcome as public JSON. +On a partial failure it keeps the confirmed outcome and then exits +nonzero. It prints the text before it uses that status. There is no +separate child process. Version 2.1.1 removed that split. Each read in that table is `completed`, `failed`, or `not_attempted`. The token is `not_attempted` in the outcome and in the text. There is no @@ -299,7 +316,7 @@ reconciliation, and a rerun cannot repair either one. A preview that fails makes no database changes, including for pages that had already been counted. -Before `apply_mapping`, a cursor page and an offset page must be a JSON +Before `MappedReader`, a cursor page and an offset page must be a JSON object, `data` must be an array, `pagination` must be an object, and `has_more` must be a boolean. Anything else fails that page. It is not an empty success. Body may be one object or JSON `null`. `null` is a completed @@ -365,61 +382,67 @@ Rejected alternatives: ## D202. The Windows cleanup and the maintainability notes are not part of this build -Checked on `main` at `8db90b42ac654767e9e9570a121bbbd4fde3348a`, which is the -merge of pull request 39. - -The failed-init cleanup is still the code in `src/program.ts` (the `init` -catch closes the database and deletes the file, the wal file, and the shm -file with `rm`). `createDatabase` still deletes a half-created file in -`removePartialLocalDatabase` (`src/db/migrate.ts`) by unlinking it. Neither -path collects garbage first. `removeTemporaryDirectory` in `src/db/client.ts` -does, and tests use it. Version 2.1.0 spec section 12 left the production -paths out of that release and did not assign them a version. They are still -open. They do not run on a pull. This build does not change them. D208 -rolls a failed step 5 back before this cleanup runs. - -`crates/ath-core/src/store.rs` is 1034 lines. `mapping.rs` is 1443. -`persist.rs` is 1051. The pull is a new module so those files do not grow -for HTTP. `mapping.rs` may add the count by record type that D199 names, and the -open-wearables device-binding check in the specification. That check is -shared by mapped import and pull, and it is limited to route -`open_wearables`. D203 also adds the measurement-sample target, the -reporting-window write, and the segment copy. Nothing beyond that is added -to `mapping.rs`. `store.rs` may -preserve `device_binding` inside `revise` when the record is a source, and -refuse a partial patch that contains that key. `revise` cannot set, change, -or clear the receipt. The connection is private, `ensure_mapped_source` -has no receipt argument, and `same_source_records` omits deleted rows, so -`store.rs` may also read the receipt and tombstone-inclusive history, -create a source with the checked receipt, and write that receipt on an -existing unbound source only when the same transaction shows no accepted -or deleted record and no source device. Those writes keep every other -source field and the normal revision and `data_json` bookkeeping. They -join the caller's `BEGIN IMMEDIATE` transaction. D204 also allows -`measurement_sample` insert and update, and a null value and unit pair on -provider summaries and provider scores. A half-null pair is refused. The -same pair is allowed in the TypeScript projection, package import, record -view, and repair copy. D205 also allows `source_report` insert and update, -and withdrawal of a child whose anchor is in this response. Nothing beyond -that is added to `store.rs`. Other +Checked again on version 2.1.1 at `0de71bbd6474916af0408a4090bc2c74a1a3aed2`, +the merge of pull request 44. The earlier check was version 2.1.0 at +`8db90b42ac654767e9e9570a121bbbd4fde3348a`, the merge of pull request 39. + +Failed `ath init` still deletes the new file, the wal file, and the shm +file. `Store::create` in `src/store/mod.rs` calls `remove_partial_database`, +which unlinks those three paths. The `init` command in +`src/cli/commands/init.rs` unlinks the same three paths if creation fails +after that. Neither path collects abandoned temporary directories first. +`make_owned_temporary_directory` in `src/files/staging.rs` does, and import +working data uses it. The database file is not one of those directories. +Version 2.1.0 spec section 12 left the production database cleanup out and +named no later version. Version 2.1.1 did not take that work. The cleanup +does not run on a pull. This build does not change it. D208 rolls a failed +step 6 back before this cleanup runs. + +`src/import/mapping.rs` is 1703 lines. The store is already several files. +`src/store/mod.rs` is 848 lines, `src/store/write.rs` is 508, +`src/store/encode.rs` is 549, and `src/store/check.rs` is 1044. +`persist.rs` is gone. The pull is a new module so `mapping.rs` and the +store files do not grow for HTTP. `mapping.rs` may add the count by record +type that D199 names, and the open-wearables device-binding check in the +specification. That check is shared by mapped import and pull, and it is +limited to route `open_wearables`. D203 also adds the measurement-sample +target, the reporting-window write, and the segment copy. Nothing beyond +that is added to `mapping.rs`. Source writes go through `Store::apply` in +`src/store/write.rs`. There is no `Store::revise`. A correction carries the +whole record. The receipt rule is unchanged. A write that is not the +owner's whole source record cannot set, change, or clear `device_binding`. +`Store` keeps its connection private. `write.rs` may also read the receipt +and tombstone-inclusive history, create a source with the checked receipt, +and write that receipt on an existing unbound source only when the same +transaction shows no accepted or deleted record and no source device. Those +writes keep every other source field and the normal revision and `data_json` +bookkeeping. They join the caller's `BEGIN IMMEDIATE` transaction. D204 +also allows `measurement_sample` insert and update, and a null value and +unit pair on provider summaries and provider scores. A half-null pair is +refused. `write_current_state` in `src/store/encode.rs` is the only +record-to-table mapping. Package restore, repair, and the record check use +it. There is no TypeScript writer to update. D205 also allows +`source_report` insert and update, and withdrawal of a child whose anchor +is in this response. Nothing beyond that is added to the store. Other routes do not call the receipt operations. `ath correct`, package restore, and an accepted package merge remain the owner's whole source record. -Splitting the files is separate work. It is not required to make the pull +Splitting `mapping.rs` is separate work. It is not required to make the pull correct. -`check_supplied_fields` runs in `store.rs` before insert and revise (D191). -`persist.rs` `insert_record` writes `data_json` and does not call that check. -The pull writes through `apply_mapping` and the store, so the check covers -it. Closing the persist gap is separate work. +`check_supplied_fields` is in `src/import/shared.rs`. A keyed import calls +it before it builds a candidate (D191). There is no `persist.rs` and no +`ath-core persist` command. The pull writes through `MappedReader` and +the store, so the import check covers it. A name check outside import is +separate work. -`isMappingPath` exists once, in `src/skill.ts`. Rust has no copy. The pull -uses the TypeScript function. There is no second path rule to remove. +`is_mapping_path` exists once, in `src/assets/mod.rs`. The pull uses +`resolve_mapping` in that file. There is no second path rule to remove. Rejected alternatives: -- Fix the Windows cleanup, split the Rust files, and guard `persist.rs` - inside the 2.2.0 pull request. Rejected because none of them changes what - the pull writes, and the maintainer asked not to widen this build. +- Fix the Windows cleanup, split `mapping.rs`, and add a name check outside + import inside the 2.2.0 pull request. Rejected because none of them changes + what the pull writes, and the maintainer asked not to widen this build. - Block the pull on those fixes. Rejected for the same reason. A later change can take any one of them on its own. @@ -529,11 +552,12 @@ over 8 MiB is an incomplete read. The message names the read. It does not name a series type. Menstrual cycles keep an in-range start and a future end. A later start is not stored. The page is still followed to the end. -Step 5 rebuilds `provider_summaries` and `provider_scores` so value and +Step 6 rebuilds `provider_summaries` and `provider_scores` so value and unit are both null or both present. It copies existing rows and keeps -their ids, revisions, import keys, and tombstones. `store.rs` may insert -and update samples and those paired-null rows. The TypeScript projection, -package import, record view, and repair copy may do the same. Half-null +their ids, revisions, import keys, and tombstones. `src/store/write.rs` +may insert and update samples and those paired-null rows. +`write_current_state` in `src/store/encode.rs` writes the same pair. +Package restore, repair, and the record check use that encoder. Half-null is refused. No other store change is included. Rejected alternatives: @@ -847,10 +871,10 @@ not recreated. A deleted capsule is not replaced. If the page names a row the bounded read cannot cover, the page is not archived. There is no retry. -A failed step 5 during init rolls back to the closed step 4 schema +A failed step 6 during init rolls back to the committed step 5 schema before the existing init cleanup runs. Init fails. D202's cleanup is unchanged. A migrate of an existing database keeps that file and the old -schema when step 5 rolls back. +schema when step 6 rolls back. Rejected alternatives: @@ -860,7 +884,7 @@ Rejected alternatives: - Recheck only the archive source after the protected rollback. Rejected. The owner can delete the original source or record in between, and the payload would be stored under a new identity. -- Leave a failed init file at step 4. Rejected. The existing caller +- Leave a failed init file at step 5. Rejected. The existing caller removes that file, and this build does not change that cleanup. ## D209. A workout the person typed is a workout session @@ -931,7 +955,9 @@ point check currently reject a point at or below zero, except `temperature_deviation`. A finite `hr_recovery`, including zero and a negative number, passes that check. A non-finite value does not. Other points stay positive. `temperature_deviation` stays signed. -`src/schema.ts` is not edited. No table is rebuilt for this check. +The exception is the point check in `src/model/data.rs`. +`packages/npm/src/schema.ts` is frozen compatibility code and is not where +this check is added. No table is rebuilt for this check. Rejected alternatives: @@ -950,8 +976,11 @@ no `include_manual` switch. `workout-drift` loads the session the caller names, including a manual session, and uses its start and end as the window. The samples then come from `read_inputs`, so a manual source's numbers are not inputs. The session's own heart rate and distance are not -inputs. `queryMeasurements`, `querySeries`, and `querySessions` omit -manual sources unless `include_manual` is true. A generic record listing +inputs. `query_measurements`, `query_series`, and `query_sessions` in +`src/store/query.rs` omit manual sources unless `include_manual` is true. +The JavaScript names `queryMeasurements`, `querySeries`, and +`querySessions` in `packages/npm/src/database.ts` call those functions. +A generic record listing is not those three functions. A typed workout must not enter a device baseline. @@ -1039,8 +1068,8 @@ calls per command. Later ids are deferred. Their list objects are stored. The unwrap, the id, and the start field for each provider are the table in the spec. File import uses the same envelope. The provider logic lives -in `crates/ath-core/src/vendor_workouts.rs`, driven by one table. -`open_wearables.rs` calls that module. +in `src/runtime/vendor_workouts.rs`, driven by one table. +`src/runtime/open_wearables.rs` calls that module. Rejected alternatives: diff --git a/build-history/v2.2.0/progress.md b/build-history/v2.2.0/progress.md index 679fce70..1535fc2c 100644 --- a/build-history/v2.2.0/progress.md +++ b/build-history/v2.2.0/progress.md @@ -6,8 +6,8 @@ program, the record, or the database has changed for 2.2.0. | Step | What | Status | |---|---|---| | 0 | The plan: proposals D198–D215, and the Open Wearables study. D210 through D212 stay. D214 corrects the live-read procedure. D215 is the privacy choice for vendor objects. Still not adopted. The new head needs a fresh four-role review | written, not approved | -| 1 | Version 2.2.0 and migration step 5. No new column on an existing table. The root check gains `source_report` by the copy in D207. Summary and score values may be omitted in pairs (D198, D207) | not started | -| 2 | `ath pull openwearables` in `ath-core`, with the rewritten mapping (D199, D201, D207) | not started | +| 1 | Version 2.2.0 and migration step 6. Step 5 is the published 2.1.1 migration. No new column on an existing table. The root check gains `source_report` by the copy in D207. Summary and score values may be omitted in pairs (D198, D207) | not started | +| 2 | `ath pull openwearables` in the `athleticstandard` crate, with the rewritten mapping (D199, D201, D207) | not started | | 3 | Key, server, and user id kept out of the record (D200) | not started | | 4 | Fixture tests, with no live key in CI | not started | | 5 | Generated schema, demo athlete, skill command reference, and the public-data list | not started | @@ -15,5 +15,6 @@ program, the record, or the database has changed for 2.2.0. The build, after approval, is one pull request. It is not three. -The Windows failed-init cleanup, the size of `store.rs` and `mapping.rs`, and -the `persist.rs` field-name check stay out of that pull request (D202). +The Windows failed-init cleanup, the size of `src/import/mapping.rs`, and a +name check outside import stay out of that pull request (D202). `persist.rs` +is already gone. diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index b483f3a3..a7b00f74 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -15,9 +15,10 @@ This pull request is the plan. The build after approval is one later pull request. This plan does not change a version number, a schema, a fixture, or the program. -Version 2.1.0 on `main` `8db90b42ac654767e9e9570a121bbbd4fde3348a` is the -software this plan was read against. That commit is the merge of pull request -39. The pull request head was `72b9db9`. +Version 2.1.1 on `main` `0de71bbd6474916af0408a4090bc2c74a1a3aed2` is the +software this plan is read against. That commit is the merge of pull request +44. An earlier reading used version 2.1.0 at +`8db90b42ac654767e9e9570a121bbbd4fde3348a`, the merge of pull request 39. ## 1. What a person does @@ -101,7 +102,7 @@ Preview text prints: - `nothing written; pass --yes after reviewing this preview` `--yes` without `--json` commits each successful page. That commit is one -`apply_mapping` transaction (D189). It is not a completed pull. The text +`MappedReader` transaction (D189). It is not a completed pull. The text prints actual committed counts for pages kept. It prints `requested range through is complete` only when every stored ranged read in section 2 reached that read's terminal condition. A live workout line does @@ -114,9 +115,9 @@ provider name. The exit is then nonzero. The success sentence is not printed. The stored range sentence can still say the range is complete. A finished range with an incomplete body snapshot does not print that sentence. The body line still says the snapshot is incomplete. -If a later page fails, the child returns a typed outcome to the parent -before the process exits nonzero. The parent renders that outcome as text, -then uses the exit status. When a ranged read failed, the text says the +If a later page fails, the command keeps a typed outcome and then exits +nonzero. It prints that outcome as text, then uses the exit status. There +is no child process. Version 2.1.1 removed that split. When a ranged read failed, the text says the requested range is incomplete. When every ranged read completed and body or the personal record failed, the text says the requested range is complete and names the snapshot that failed. It names any read that is @@ -200,7 +201,7 @@ Fitbit, Oura, Strava, Withings, and Sensorbio use the same fields as `garmin`. Those names are the public `--json` keys. It is the preview outcome. A preview does not say a snapshot was stored. -The child returns a different outcome for `--yes` without `--json`. That +The command returns a different outcome for `--yes` without `--json`. That outcome has the actual `committed` counts, the actual `archive_committed` counts, `database_changed`, `protected_write`, `archive`, `range_complete`, and `snapshots_complete`. `committed` counts protected @@ -217,7 +218,7 @@ and that commits no archive change, has `written` false, `database_changed` false, both completion flags true, and unchanged protected counts. An earlier change keeps both flags true. A failed ranged page has `range_complete` false. A failed snapshot after a finished range has `range_complete` true and -`snapshots_complete` false. The parent prints sentences from this outcome. +`snapshots_complete` false. The command prints sentences from this outcome. It does not print the outcome as public JSON. Public `--json`, with or without `--yes`, commits neither the protected transaction nor the archive transaction. @@ -378,9 +379,9 @@ name. The numbers on this session do not enter the eight range calculations or `provider-period-summary`. `workout-drift` may use the session's start and end as its window when the caller names that session. The samples in that window still exclude `source_type` `manual`. -`queryMeasurements`, `querySeries`, and `querySessions` omit manual -sources unless `include_manual` is true. This pull does not change those -three functions. Other record listings are not that switch. The session does not enter a device +`query_measurements`, `query_series`, and `query_sessions` in +`src/store/query.rs` omit manual sources unless `include_manual` is true. +This pull does not change those three functions. Other record listings are not that switch. The session does not enter a device baseline. `unknown`, JSON null, and a missing `entry_source` are source reports of kind `unknown_workout`. They are not a workout session, and they are not @@ -555,7 +556,9 @@ scales, with the window and without `recorded_at`. Raw points, raw `heart_rate_recovery_one_minute` is the point quantity `hr_recovery`, in bpm. A finite value stays, including zero and a negative number. The mapping's positive check and the v1 point check gain that exception -beside `temperature_deviation`. `src/schema.ts` stays as it is. No table +beside `temperature_deviation`. The exception is the point check in +`src/model/data.rs`. `packages/npm/src/schema.ts` is frozen compatibility +code and is not where this check is added. No table is rebuilt for the check. The server series name stays in `supplied_fields`. The 2.1.0 import key stays. A day row of that series is a window summary whose summary type is also `hr_recovery`. Its key adds `1day` and `period_end`, so it @@ -918,7 +921,7 @@ The eight range calculations do not read it. A saved file imports the same envelope. Export and import keep one original id. The per-provider unwrap lives in -`crates/ath-core/src/vendor_workouts.rs`, driven by one provider table. +`src/runtime/vendor_workouts.rs`, driven by one provider table. `open_wearables.rs` calls that module. It does not grow a provider branch. Day rows are one selected row per source, series, and local day. The @@ -931,7 +934,8 @@ period. ## 3. How a response becomes records -The pull resolves `open-wearables` through `resolveMappingFile`. It parses and +The pull resolves `open-wearables` through `resolve_mapping` in +`src/assets/mod.rs`. It parses and checks the file before the first request. A bad file fails with no network call. A resolved file that does not implement section 2 also fails before any request. An installed 2.1.0 copy still wins under D179, and this check @@ -988,7 +992,7 @@ are one record. The sensor join uses `|`, so a `device_id` that contains the join is encoded. That identity change is not this proposal. Old rows are not rewritten, moved, or deleted. -Both `ath import --mapping` and `ath pull` call `apply_mapping`. The check +Both `ath import --mapping` and `ath pull` call `MappedReader`. The check lives there, for route `open_wearables` only, inside the same transaction as the write and before `insert_group` changes a device source or a timeseries record on that source. Summary, event, score, and unattributed @@ -1041,7 +1045,8 @@ The call is one of these states: command again cannot change the id. - The source exists, the source key is absent, and any history exists. History includes a deleted record and a deleted source device, not only - live rows. `same_source_records` keeps `is_deleted = 0`, so it is not + live rows. `existing_source` in `src/import/provider.rs` keeps + `records.is_deleted = 0`, so it is not this test. The store read below includes the deleted rows. The call is refused. Hardware is not promoted. The text says this Open Wearables history cannot be refreshed until a separate @@ -1095,23 +1100,22 @@ export and restore keeps the key and the import keys, so the same id can correct a point and a different id is refused. No signature is added. A person who replaces the database file is outside this rule. -`Store::revise` on a source is a partial update. It applies the other keys -in the patch and keeps the current `device_binding`, including when the key -is absent. A patch that contains `device_binding` is refused. The source -stays unchanged. `revise` cannot set, change, or clear the receipt. Other -record types are unchanged. - -The store connection is private. `ensure_mapped_source` takes the writer, -the route, the vendor, and the sensor. An existing source returns before a -data object is built. A new source's JSON is built inside that function, -and that JSON has no receipt argument today. The mapping receives a source -id. It cannot add the receipt to an object it does not hold, and it cannot -read deleted rows through `same_source_records` or through the private -connection. A later `revise` cannot fill the receipt in, because that patch -is refused. - -`store.rs` therefore gains three source operations besides the `revise` -rule above, the typed writes in section 6, and the bounded archive +`Store::apply` in `src/store/write.rs` writes a whole source record. There +is no partial `revise`. A source write that is not one of the three owner +operations cannot set, change, or clear `device_binding`, including when +the key is absent from the new record. A write that contains +`device_binding` and is not one of those owner operations is refused. The +source stays unchanged. Other record types are unchanged. + +The store connection is private. `Mapping::source` in `src/import/mapping.rs` +asks `route_source` for the writer, route, and sensor. That call takes no +receipt. The mapping receives a source id. It does not hold the source +JSON, and it cannot read deleted rows through the private connection. A +later whole-record write that is not an owner operation cannot fill the +receipt in, because a write that contains `device_binding` is refused. + +`src/store/write.rs` therefore gains three source operations besides that +refusal, the typed writes in section 6, and the bounded archive safety read in section 2. It gains nothing beyond those: - Read the committed receipt, and whether any record or source device for @@ -1130,7 +1134,7 @@ The three receipt operations run inside the caller's `BEGIN IMMEDIATE` transaction. The safety read runs in that same transaction, before any mutation, and again at the start of the archive transaction. A refused call rolls them back with the call. Other routes do not call -them. The build may extend `ensure_mapped_source` or add a narrow operation +them. The build may extend `route_source` or add a narrow operation beside it. It does not add a table, a trait, or a file split. The automatic path does not replace `detail`, `vendor`, or `supplied_fields`. @@ -1166,7 +1170,7 @@ the key cannot be sent to a second host. One attempt, then stop. Timeouts are take 120 seconds to read. One response may be at most 8 MiB. One read may be at most 1000 pages. -The body is read inside that cap and parsed before any `apply_mapping` call. +The body is read inside that cap and parsed before any `MappedReader` call. The guard is in `open_wearables.rs`. It walks every decoded object key and every decoded string. A value that contains the API key, the selected origin, or the selected user id rejects the whole page. A key whose @@ -1181,7 +1185,7 @@ A raw personal-record `user_id` that is absent, null, the wrong type, or not the selected user refuses the page before the drop. The page is not rewritten and it is not mapped. A Unicode escape such as `\u0073` is visible only after parsing, so a scan of the raw text is not enough. The raw-text -scan still runs on a body that did not parse, and the parent still refuses +scan still runs on a body that did not parse, and the command still refuses to print the key. Those checks are defense in depth. They do not repair a page that has already committed. @@ -1191,8 +1195,9 @@ problem `code` is printed only when it is a single token of letters, digits, origin, or the user id. Any other code is withheld. A transport error or a parser error is replaced with a fixed sentence. The sentence has no URL, no path, and no user id. The result keeps a `left_out` total and at most 20 -example lines. It does not keep every id or every source string. The child -output has to stay inside the 64 MiB buffer in `src/ath-core.ts`. +example lines. It does not keep every id or every source string. The 64 MiB +stdout buffer in `src/ath-core.ts` is gone with the TypeScript bridge. +The command prints from this process. The 20 example lines are the bound. There is no Athletic Standard telemetry on this command. The server the person named is the only host contacted. @@ -1203,13 +1208,17 @@ reads in section 2, no user list. ## 5. Version, migration, and what stays compatible -The build sets `2.2.0` on the package, the record, and `ath-core`, by the -same constants 2.1.0 moved. Migration step 5 is a new SQL file and a narrow runner arm. It updates -`athleticstandard_version` to `2.2.0` and `sql_schema_version` to 5. No -column is added to an existing table. The generated contract adds +The build sets `2.2.0` on the package, the record, and the +`athleticstandard` crate, by the same constants 2.1.1 uses. +`ATHLETIC_STANDARD_VERSION` is in `src/model/package.rs`. `SQL_SCHEMA_VERSION` is in +`src/store/migrate.rs`. Migration step 6 is a new SQL file and a narrow +runner arm. Step 5 is already +`spec/sql/migrations/005-version-2-1-1.sql`. Step 6 updates +`athleticstandard_version` to `2.2.0` and `sql_schema_version` to 6. No +column is added to an existing table. The contract adds `source_report` to the `records.record_type` check, creates `source_reports`, and rebuilds `provider_summaries` and -`provider_scores` as section 2 describes. Files `001` through `004` stay +`provider_scores` as section 2 describes. Files `001` through `005` stay byte-identical. The check is not removed, and ordinary store writes do not turn foreign keys off. @@ -1220,16 +1229,17 @@ record, and the links from typed rows, import keys, deletions, attachments, reporting periods, and the other child tables, use `ON DELETE CASCADE` and are not deferred. Triggers and views name `records`. `PRAGMA foreign_keys` does not change inside a transaction. -`installInitialSchema` and `withWriteTransaction` already require it to -be on. A `DROP TABLE records` there would fail or cascade through the -children. Step 5 does not do that. +`configure` in `src/store/mod.rs` requires foreign keys on before +`install_schema` runs. A `DROP TABLE records` inside that transaction +would fail or cascade through the children. Step 6 does not do that. -The create path finishes steps 1 through 4 and closes that transaction -before step 5. `installInitialSchema` does not run step 5 inside the -transaction that requires foreign keys to be on. Target 5 does not use -`withWriteTransaction`. +`install_schema` runs steps 1 through 5 in one transaction and commits it. +Today that same transaction sets `user_version` to `SQL_SCHEMA_VERSION`. +The step 1 through 5 transaction sets `user_version` 5. Step 6 is not +inside that transaction, and step 6 sets `user_version` 6. Target 6 does +not use the ordinary write transaction. -Step 5 uses one connection that ordinary writes do not reuse. Before +Step 6 uses one connection that ordinary writes do not reuse. Before `BEGIN`, it sets `PRAGMA foreign_keys=OFF` and reads the pragma back. The value must be 0. Turning foreign keys off does not turn off the schema check SQLite runs during `ALTER TABLE`. `sql_v1_current_records` and @@ -1266,7 +1276,7 @@ Inside that one transaction the order is fixed. 7. Create `source_reports` and its type trigger. 8. `PRAGMA foreign_key_check` is empty and `PRAGMA integrity_check` is `ok`. -9. Set the version rows and `user_version` 5. +9. Set the version rows and `user_version` 6. `sql_v1_database_info`, `sql_v1_record_revisions`, and `sql_v1_record_deletions` do not name `records`, so they stay through the @@ -1279,37 +1289,39 @@ cross-table triggers, the old check, the rows, and the version. The D124 backup is already on disk. Device receipts stay in the copied source JSON. They are not rewritten. -A new database closes the step 4 transaction, then runs this step 5 path. -Step 9 sets `user_version`. If step 5 fails during init, that transaction -rolls back to the closed step 4 schema before the existing failed-init -cleanup runs. Init reports failure. `createDatabase` still closes the -database and `removePartialLocalDatabase` still deletes the new file. -D202 leaves those paths in place, and this build does not change them. -A file that cleanup does not delete is not left with the views dropped. -A migrate of a database that already existed is a separate case. Its -step 5 rollback leaves that file in place, at the old schema, with -foreign keys on. `applyMigrationStep` gains this arm for target 5 -and does not use `withWriteTransaction` for it. `MIGRATION_CHAIN` in `src/db/sql-contract.ts`, -`scripts/generate-sql-contract.ts`, and `scripts/check-schema-drift.ts` gain -the step. `package.json` exports and `tests/v1-package-exports.test.ts` point -at `schema/2.2.0/`. +A new database commits steps 1 through 5, then runs this step 6 path. +Step 9 sets `user_version`. If step 6 fails during init, that transaction +rolls back to the committed step 5 schema before the existing failed-init +cleanup runs. Init reports failure. `Store::create` still calls +`remove_partial_database`, which deletes the new file, the wal file, and +the shm file. D202 leaves that cleanup in place, and this build does not +change it. A file that cleanup does not delete is not left with the views +dropped. A migrate of a database that already existed is a separate case. +Its step 6 rollback leaves that file in place, at the old schema, with +foreign keys on. `apply_step` in `src/store/migrate.rs` gains this arm for +target 6 and does not use the ordinary write transaction for it. +`MIGRATION_CHAIN` in that file and `spec/sql/contract.json` gain the step. +The native tests check that the contract matches the embedded SQL. +`packages/npm/package.json` exports and `packages/npm/test/public-api.test.ts` +point at `schema/2.2.0/`. `READABLE_DATABASE_VERSIONS` and `ACCEPTED_RECORD_VERSIONS` become `1.0.0`, -`2.0.0`, `2.1.0`, and `2.2.0`. Both sets already contain `1.0.0`. Dropping it -would make a 1.0.0 database unloadable, so migrate could not open it. -`IMPORTABLE_PACKAGE_VERSIONS` is only `2.0.0` and `2.1.0` today. It gains -`2.2.0` and keeps those two. `Store::open` rejects a `2.1.0` database until -`ath migrate`, with the refusal it already uses for an older database. A -`2.1.0` database will not open in `ath-core` until that migrate. - -The build generates `schema/2.2.0/` and does not rewrite `schema/2.1.0/` or -`schema/2.0.0/`. The 2.2.0 source object gains optional `device_binding`. +`2.0.0`, `2.1.0`, `2.1.1`, and `2.2.0`. Both sets already contain `1.0.0`. +Dropping it would make a 1.0.0 database unloadable, so migrate could not +open it. `IMPORTABLE_PACKAGE_VERSIONS` is `2.0.0`, `2.1.0`, and `2.1.1` +today. It gains `2.2.0` and keeps those three. `Store::open` rejects a +`2.1.1` database until `ath migrate`, with the refusal it already uses for +an older database. A `2.1.1` database will not open until that migrate. + +The build generates `schema/2.2.0/` and does not rewrite `schema/2.1.1/`, +`schema/2.1.0/`, or `schema/2.0.0/`. The 2.2.0 source object gains optional `device_binding`. `ProviderReportingPeriodType` gains `open_wearables_reporting_window`. `ValueBasis` gains `aggregator`. Series quantities gain the sample series whose units are in the appendix table. Intake, index, age, and effort -series do not gain quantities. The record type `source_report` is added to `RecordType`, the current -and revision unions, the package schema, and `typedTables` in -`src/db/check-tables.ts`. It is not a measured type. Its table has `record_id`, `source_id`, +series do not gain quantities. The record type `source_report` is added to `RecordType` in +`src/model/`, the current and revision unions, the package schema, and the +table description in `src/store/encode.rs`. `src/store/check.rs` compares +stored rows with that description. It is not a measured type. Its table has `record_id`, `source_id`, `report_kind`, `subject`, optional `reported_at`, optional `standard_value` and `standard_unit` together, optional `provider_record_id`, `received_at`, and `data_json`. It has no required @@ -1320,14 +1332,17 @@ when its input timestamp uses `not_provided_by_source`. No other field is added. The folder exists so the package version and the schema path stay aligned. The demo athlete is -regenerated because the stored version is inside it. `examples/demo-athlete/athlete.ath.json` -stays the legacy 0.4.3 file. `tests/fixtures/version-2-0-0/` is not +regenerated because the stored version is inside it. The demo is +`examples/demo-athlete/athlete.ath.sqlite`. The preserved 2.1.0 demo in +`tests/fixtures/version-2-1-0/` is not regenerated. The 0.4.3 file in +`tests/fixtures/version-0-4-3/` is not regenerated. `tests/fixtures/version-2-0-0/` is not regenerated. `package.json` `files` already includes `mappings`. The build rewrites `mappings/open-wearables.md` so it implements section 2. Other mapping -files stay as they are. `pnpm generate:skill-cli` runs because help text -changes (D80). `AGENTS.md`, `build-history/README.md`, and `SPEC.md` are +files stay as they are. `ATH_WRITE_GENERATED=1 cargo test --test generated` +runs because help text, the schema, and the demo change (D80, and the 2.1.1 +generator decision). `AGENTS.md`, `build-history/README.md`, and `SPEC.md` are updated in the build so they name 2.2.0 as the software. `docs/connections.md` keeps the file imports and is updated to the coverage in section 2, including that `RecoverySummary` at the pinned commit has no skin-temperature field. @@ -1335,7 +1350,7 @@ This plan's edits to `AGENTS.md` and `build-history/README.md` only point at the plan. -A database from 2.1.0 needs `ath migrate` before the pull. The migrate +A database from 2.1.1 needs `ath migrate` before the pull. The migrate command still previews, backs up, and asks (D124). `Store::open` only refuses. A noninteractive open and an open with `--json` do not migrate. An interactive open can preview, back up, ask, and then migrate. @@ -1344,31 +1359,32 @@ interactive open can preview, back up, ask, and then migrate. | Piece | Place | |---|---| -| HTTP, page loop, envelope split, call `apply_mapping` | `crates/ath-core/src/open_wearables.rs` | -| Live provider table, unwrap, windows, and detail budget | `crates/ath-core/src/vendor_workouts.rs` | -| Command `pull-openwearables` | `crates/ath-core/src/main.rs` | -| Flags, key, preview text, refusal if the key appears | `src/program.ts`, `src/help.ts`, `src/keyring.ts` | +| HTTP, page loop, envelope split, call `MappedReader` | `src/runtime/open_wearables.rs` | +| Live provider table, unwrap, windows, and detail budget | `src/runtime/vendor_workouts.rs` | +| Command `pull openwearables` | `src/cli/spec.rs` and `src/cli/commands/routes.rs` | +| Flags, key, preview text, refusal if the key appears | `src/cli/`, `src/cli/help.rs`, `src/runtime/keyring.rs` | | Mapping names and field rules | the existing file `mappings/open-wearables.md` | | Stored records | the existing store and mapping engine | -| Keep `device_binding` on a partial source update | `Store::revise` in `crates/ath-core/src/store.rs`, sources only | -| Read receipt and tombstone history; create or first-bind with the checked receipt | three source operations in `store.rs`, inside the caller's transaction | -| Measurement samples, source reports, paired null value and unit, and child withdrawal | `insert_typed`, `update_typed`, and `typed_table` in `store.rs`; the same pair and table in `src/db/records.ts`, `src/db/import-package.ts`, `src/db/records-view.ts`, and the repair copy from `data_json` | +| Keep `device_binding` on a source write that is not the owner's whole record | `Store::apply` in `src/store/write.rs`, sources only | +| Read receipt and tombstone history; create or first-bind with the checked receipt | three source operations in `src/store/write.rs`, inside the caller's transaction | +| Measurement samples, source reports, paired null value and unit, and child withdrawal | `write_current_state` and `typed_columns` in `src/store/encode.rs`. Package restore, repair, and the record check use that encoder | | Whole source record from the owner | existing `ath correct`, package restore, and an accepted package merge | -`store.rs`, `persist.rs`, and `personal.rs` are not the home for this client. -`personal.rs` remains the Garmin pull. The two clients may each call `ureq`. +`src/store/`, `src/import/mapping.rs`, and `src/runtime/garmin_pull.rs` are +not the home for this client. `garmin_pull.rs` remains the Garmin pull. +The two clients may each call `ureq`. A shared trait is the later connector work, and this release does not add it. `mapping.rs` changes for the counts, the device check, and the preservation -writes in section 2. `apply_mapping` keeps its `outcome` field and adds -counts by record type. +writes in section 2. The mapped-import report in `src/import/provider.rs` +keeps its `outcome` field. `MappedReader` adds counts by record type. For route `open_wearables` only, it also runs the device-binding check in section 3 before it mutates a source device or a timeseries record. That check is the shared mapped-import and pull enforcement. It is not a new match key and it does not apply to any other route. It also gains the measurement-sample target, the reporting-window write, and the segment -copy from section 2. HTTP stays out of `mapping.rs`. `store.rs` keeps the -`revise` refusal and adds the three source operations in section 3: the +copy from section 2. HTTP stays out of `mapping.rs`. `src/store/write.rs` +keeps the receipt refusal and adds the three source operations in section 3: the receipt and tombstone read, creation with the checked receipt, and a first bind on an existing source that has no history. The archive transaction adds a bounded read of the sources, records, import keys, @@ -1378,17 +1394,19 @@ updates `measurement_sample` and `source_report`, and it accepts a provider summary or provider score whose `value` and unit are both present or both absent. A half-null pair is refused. When an anchor in this response no longer emits a child, that child is revised to the absent pair in the same -transaction. `src/db/records.ts`, `src/db/import-package.ts`, -`src/db/records-view.ts`, and the repair copy from `data_json` follow that -pair and the new table. `src/db/check-tables.ts` gains the -`source_report` entry. The eight range calculations and +transaction. `write_current_state` in `src/store/encode.rs` writes that +pair and the new table. Package restore, repair, and the record check use +that encoder. `RecordType` in `src/model/` gains the `source_report` entry. +The eight range calculations and `provider-period-summary` do not read `source_reports`. `read_inputs` and `read_period` also exclude `source_type` `manual`, and they have no `include_manual` switch. `workout-drift` loads the named session first, including a manual session, and uses that session's start and end as the window. Its samples then go through `read_inputs`. A manual source's -numbers stay out. `queryMeasurements`, `querySeries`, and -`querySessions` omit manual sources unless `include_manual` is true. +numbers stay out. `query_measurements`, `query_series`, and +`query_sessions` in `src/store/query.rs` omit manual sources unless +`include_manual` is true. The JavaScript names in +`packages/npm/src/database.ts` call those functions. This proposal does not change that code. A generic record listing is not those three functions. In `read_inputs` and `read_period`, a provider summary or provider score @@ -1398,7 +1416,7 @@ is not stored as zero and is not replaced by an older revision. The session-summary branch of `read_period` uses the same filter on the extracted number and unit. Formulas and source grouping stay as they are. The archive insert is the pull-only transaction in section 2. It is not -inside `apply_mapping`, and a mapped file import does not call it. It +inside `MappedReader`, and a mapped file import does not call it. It revalidates the safety snapshot before any insert. It does not call the receipt operations. No other store behavior changes. `ath correct`, package restore, and an accepted package merge stay whole-record owner @@ -1414,22 +1432,24 @@ protected estimates to `estimated` and its archive estimates to group. Filtering that row out of the totals does not make a preview equal a write. Each preview page is rolled back, so page two does not see page one. -The Rust command reads the key from the environment only. It has no `--key` -flag. The decoded-key walk in section 4 runs before `apply_mapping`. The -parent still checks stdout and stderr before printing. +The command reads the saved key and `OPEN_WEARABLES_API_KEY` in this +process, in `src/runtime/keyring.rs`. It has no `--key` flag. The +decoded-key walk in section 4 runs before `MappedReader`. The command +checks its own text before printing. -The child returns the preview outcome from section 1 when the mode is a +The command returns the preview outcome from section 1 when the mode is a preview, including public `--json`. It returns the confirmed outcome when -the mode is `--yes` without `--json`. On a partial failure it returns that -confirmed outcome to the parent and then exits nonzero. The parent renders -text from the confirmed outcome and public JSON from the preview outcome. -The success sentence is parent text, and only after `--yes` when -`range_complete` and `snapshots_complete` are both true. +the mode is `--yes` without `--json`. On a partial failure it keeps that +confirmed outcome and then exits nonzero. It prints text from the confirmed +outcome and public JSON from the preview outcome. The success sentence is +printed only after `--yes` when `range_complete` and `snapshots_complete` +are both true. There is no child process. The program runs on Linux, macOS, and Windows with the same command. The fixture server listens on `127.0.0.1` and an ephemeral port, which is the -pattern `personal.rs` already tests. Paths stay the TypeScript resolver's -job. No new installer and no new system library. +pattern `src/runtime/garmin_pull.rs` already tests. Mapping paths stay +`resolve_mapping` in `src/assets/mod.rs`. No new installer and no new +system library. ## 7. Tests @@ -1437,7 +1457,8 @@ CI has no Open Wearables account, no API key, and no Docker Compose. The acceptance tests are the fixture server and the synthetic files already in `tests/fixtures/exports/open-wearables/`. Those files are on the public-data list. A new file, if one is required for a two-page response, is synthetic, -invented, and added to `scripts/check-public-data.ts` with its hash. No real +invented, and added to `tools/public-data-allowlist.json` with its path +and SHA-256. `tests/public_data.rs` enforces that list. No real export is copied. Before the first request, `--from` and `--to` are both dates or both @@ -1469,7 +1490,7 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: - an installed mapping that does not implement section 2 fails before any request. The server sees no request. Raw and day timeseries requests omit `types`. A comma-joined type string is not sent -- a cursor or offset page fails before `apply_mapping` when the object is +- a cursor or offset page fails before `MappedReader` when the object is missing, `data` is not an array, `pagination` is missing, or `has_more` is not a boolean. That failure is not an empty success. A body response of JSON `null` is a completed empty snapshot and writes nothing. A body @@ -1643,7 +1664,7 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: absent, null, or non-string `user_id` on the HTTP object refuses the page. The canonical envelope without `user_id` imports. The athlete profile is unchanged -- step 5 keeps an old summary's id, number, unit, `data_json`, import key, +- step 6 keeps an old summary's id, number, unit, `data_json`, import key, revisions, and tombstone. A numeric summary can be corrected to numberless and back. A half-null value and unit is refused. A sample repeats and corrects. `ath check`, export, native import, and restore @@ -1725,7 +1746,7 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: pair that was accepted. `workout-drift` named on that manual session uses its start and end. A wearable sample inside the window is an input. A manual sample and the session's own heart rate and distance are not. - `queryMeasurements`, `querySeries`, and `querySessions` omit the manual + `query_measurements`, `query_series`, and `query_sessions` omit the manual session unless `include_manual` is true. That switch is not claimed for every record listing. `page-raw.json` is stored. @@ -1786,38 +1807,39 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: Migration tests, in the build gate: -- a synthetic 2.1.0 database makes `Store::open` refuse before any network +- a synthetic 2.1.1 database makes `Store::open` refuse before any network call. `ath migrate` previews without writing. It still previews, backs up, and asks, as D124 requires. The target it names is `2.2.0` - a confirmed migrate backs up, then sets the record version to `2.2.0`, - SQL schema 5, and `user_version` 5. Record ids, revisions, deletions, + SQL schema 6, and `user_version` 6. Record ids, revisions, deletions, attachments, import keys, reporting periods, and device receipts are unchanged. `PRAGMA foreign_key_check` is empty. A deleted row and its history are still there. The upgraded database is populated, including a tombstone. `sql_v1_current_records` and `sql_v1_active_records` still return rows. An insert that would make a revision type disagree with its record is still rejected. A second - migrate does nothing. A failure injected before the step 5 commit + migrate does nothing. A failure injected before the step 6 commit leaves the old views, the two cross-table triggers, the rows, the version, and `foreign_keys` read back as on. A successful migrate leaves `foreign_keys` on. A source report can then be created, revised, checked, exported, restored, and repaired from `data_json` without becoming a measured type -- `ath init` creates a database that is already `2.2.0`, SQL schema 5, and - `user_version` 5, and `ath check` exits 0. The fresh database accepts a +- `ath init` creates a database that is already `2.2.0`, SQL schema 6, and + `user_version` 6, and `ath check` exits 0. The fresh database accepts a source report, the same two views are queryable, and a mismatched - revision type is rejected. A failed init rolls step 5 back and then the + revision type is rejected. A failed init rolls step 6 back and then the existing cleanup removes the new file. A failed migrate of a populated database leaves that file, the old schema, the views, and foreign-key - enforcement. Step 4 still - writes `2.1.0` and schema 4, and the create path closes that - transaction before step 5 -- databases at `1.0.0` and `2.0.0` still open for migrate. Packages at - `2.0.0` and `2.1.0` still import. `spec/sql/migrations/004-version-2-1.sql` - and the folders `schema/2.0.0/` and `schema/2.1.0/` stay byte-identical + enforcement. Step 5 still + writes `2.1.1` and schema 5, and `install_schema` commits that + transaction before step 6 +- databases at `1.0.0`, `2.0.0`, and `2.1.0` still open for migrate. Packages at + `2.0.0`, `2.1.0`, and `2.1.1` still import. `spec/sql/migrations/004-version-2-1.sql`, + `spec/sql/migrations/005-version-2-1-1.sql`, and the folders `schema/2.0.0/`, + `schema/2.1.0/`, and `schema/2.1.1/` stay byte-identical -TypeScript tests use the memory store and do not open the real password -store. They cover: +Rust tests use `MemorySecretStore` in `src/runtime/keyring.rs` and do not +open the real password store. They cover: - the missing-key sentence - `ath key set openwearables` @@ -1839,8 +1861,9 @@ store. They cover: readable range, neither transaction commits and the database is unchanged -`pnpm check:public-data`, `pnpm typecheck`, `pnpm test`, and `pnpm build` -pass, and `cargo test` passes, before the build is called done. +`cargo fmt --check`, `cargo clippy --all-targets -- -D warnings`, and +`cargo test` pass. In `packages/npm`, `npm ci`, `npm run typecheck`, and +`npm test` pass. That is the gate before the build is called done. ## 8. You test this (Laptop) @@ -1887,26 +1910,26 @@ This plan pull request has no screenshots and no video. D202 records the check. None of these is a prerequisite for the pull, and none is in the build pull request. -- Failed `ath init` and failed `createDatabase` still delete the database file - in the same process that closed it, without the garbage collection - `removeTemporaryDirectory` uses. On Windows that delete can fail with - `EBUSY`. Version 2.1.0 spec section 12 left it out and named no later - version. A failed step 5 rolls back before that cleanup. This build - does not replace the cleanup. -- `store.rs` and `mapping.rs` are past a thousand lines. The pull does not - add HTTP to them. `mapping.rs` gains the counts, the open-wearables - binding check, and the preservation writes in section 2. `store.rs` gains the - partial-update refusal, the three source operations in section 3, and the - sample, source-report, withdrawal, null-filter, archive, and paired-null - writes in section 6. Splitting the files stays out. -- `persist.rs` can still store a supplied field named `__proto__` if a caller - uses `ath-core persist` directly. The pull does not use that path. -- The mapping path rule is already one function. There is no duplicate to - delete. +- Failed `ath init` and failed `Store::create` still delete the database + file in the same process that closed it, without the abandoned-directory + cleanup `make_owned_temporary_directory` uses. On Windows that delete can + fail with `EBUSY`. Version 2.1.0 spec section 12 left it out + and named no later version. Version 2.1.1 did not take it. A failed step 6 + rolls back before that cleanup. This build does not replace the cleanup. +- `src/import/mapping.rs` is 1703 lines. `src/store/check.rs` is 1044. The + pull does not add HTTP to them. `mapping.rs` gains the counts, the + open-wearables binding check, and the preservation writes in section 2. + `src/store/write.rs` gains the receipt refusal, the three source + operations in section 3, and the sample, source-report, withdrawal, + null-filter, archive, and paired-null writes in section 6. Splitting + `mapping.rs` stays out. +- `persist.rs` and `ath-core persist` are gone. A name check outside import + is separate work. The pull does not add one. +- The mapping path rule is already `is_mapping_path` in `src/assets/mod.rs`. + There is no duplicate to delete. No maintainability note under another name was found in the 2.1.0 decision -log. The sizes and the persist gap are the current code, not a recorded -D-number. +log. The sizes above are the current code, not a recorded D-number. ## 10. Risks and the approval @@ -1937,12 +1960,13 @@ Risks: is to avoid copying the key into the record. The build, after approval, is one pull request in this order. First the -schema and step 5: the root `record_type` check, the period type, the +schema and step 6: the root `record_type` check, the period type, the `aggregator` basis, the sample series quantities in the appendix table, the `source_report` type and table, the paired null value and unit, and -the time-unknown summary. The v1 point check and the mapping's positive -check accept a finite `hr_recovery`, including zero and a negative number. -`src/schema.ts` is not edited. No table is rebuilt for that check. Then the store, the calculation null filter, +the time-unknown summary. The point check in `src/model/data.rs` and the +mapping's positive check accept a finite `hr_recovery`, including zero and +a negative number. `packages/npm/src/schema.ts` is not where that check is +added. No table is rebuilt for that check. Then the store, the calculation null filter, the archive transaction, and the record paths in section 6. Then the mapping engine and `mappings/open-wearables.md`. Then the reads, the cycle filter, the smaller-page split, and the tests in section 7. The laptop card and the phone proof are @@ -1959,18 +1983,19 @@ migration with no new column, under D152 and D184. That acceptance does not adopt D198. The optional source key adds no column. -1. One number, 2.2.0. Readable sets keep `1.0.0`. Step 5 runs on create and - on migrate. The device receipt adds no column. Step 5 extends the +1. One number, 2.2.0. Readable sets keep `1.0.0`. Step 6 runs on create and + on migrate. Step 5 stays the published 2.1.1 migration. The device + receipt adds no column. Step 6 extends the root check with `source_report` by the copy in section 5, creates `source_reports`, and rebuilds `provider_summaries` and `provider_scores` so a numberless object can omit `value` and its unit together. Existing ids and rows are copied. Before the root rename, - step 5 drops and later recreates `sql_v1_current_records`, + step 6 drops and later recreates `sql_v1_current_records`, `sql_v1_active_records`, and the two `record_revisions` triggers that - read `records`. Foreign keys stay on for ordinary writes. The step 5 + read `records`. Foreign keys stay on for ordinary writes. The step 6 connection turns them off only before its transaction and reads them back on after every exit. A - `2.1.0` database does not open until `ath migrate`. This release does + `2.1.1` database does not open until `ath migrate`. This release does not schedule a pull, add its own token refresh, backfill, or store a cursor (D198, D208). A live read can still make the server refresh a vendor token (D214). @@ -1997,9 +2022,9 @@ optional source key adds no column. left in place. `ath correct` and a native 2.2.0 package restore are the owner's whole source record (D201). 5. The Windows cleanup and the maintainability notes stay separate. - `mapping.rs` gains counts by record type, the open-wearables binding - check, and the preservation writes in section 2. `store.rs` gains the - partial-update refusal, the receipt and tombstone read, creation with + `src/import/mapping.rs` gains counts by record type, the open-wearables binding + check, and the preservation writes in section 2. `src/store/write.rs` + gains the receipt refusal, the receipt and tombstone read, creation with the checked receipt, and the first bind of an existing source that has no history, and the sample, source-report, withdrawal, and paired-null writes in section 6, including the null filter in the calculation From 5e896fa3562625e404ef6029d55361abe3ea9eb0 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 04:06:54 +0000 Subject: [PATCH 16/60] Renumber the 2.2.0 proposals and fit most of the plan to 2.1.1. Version 2.1.1 used D208 through D226, so the proposals move from D198-D215 to D227-D244 in the same order. The decisions file records the old and new numbers. The spec now follows the 2.1.1 import: each page is one preview and one apply, the page reader holds the page in memory, step 6 runs in its own transaction with foreign keys off, and limits are the 2.1.1 named constants. It also carries the vendor-workout corrections from the review at e145fa6. Decisions D230-D237 and D242-D244, the appendix, and the progress table are finished in later commits. Co-authored-by: Michael Whitham --- .../v2.2.0/appendix/open-wearables-api.md | 14 +- build-history/v2.2.0/decisions.md | 340 ++-- build-history/v2.2.0/progress.md | 10 +- build-history/v2.2.0/spec.md | 1378 +++++++++++------ 4 files changed, 1157 insertions(+), 585 deletions(-) diff --git a/build-history/v2.2.0/appendix/open-wearables-api.md b/build-history/v2.2.0/appendix/open-wearables-api.md index 5248ee7d..25ef32ae 100644 --- a/build-history/v2.2.0/appendix/open-wearables-api.md +++ b/build-history/v2.2.0/appendix/open-wearables-api.md @@ -50,7 +50,7 @@ file, and this plan does not call it. ## The reads this plan uses -D203 names every read. The paths below are the ones this study opened +D232 names every read. The paths below are the ones this study opened first. Each is under `/api/v1` and takes a user id in the path. The user id is an Open Wearables UUID. Dates are required on the paged reads. @@ -135,7 +135,7 @@ schema. `zone_offset` is a separate string, `+01:00` or `-05:30`, or null. The 2.1.0 mapping file's timeseries lines do not name `heart_rate`. In Athletic Standard, `heart_rate` is a series quantity (the unit table in `src/model/data.rs`). It is not one of the point -quantities the 2.1.0 mapping engine writes. D203 stores that stream as +quantities the 2.1.0 mapping engine writes. D232 stores that stream as measurement samples. The 2.1.0 file, by itself, still has nowhere to put it. ## Time bounds @@ -204,7 +204,7 @@ route files. A limit may still exist in middleware this study did not open. The same commit, `183e8cc4f6de897dbd288c93d49a691f2cf721ae`, was read again for every user data route. The OpenAPI file is `docs/openapi.json`, -`info.version` `0.11.0`. The storage rule is D208. This section records +`info.version` `0.11.0`. The storage rule is D237. This section records what the source shows. `SeriesType` is the enum in `backend/app/schemas/enums/series_types.py`. @@ -214,7 +214,7 @@ path in `timeseries_service.py` copies `recorded_at`, `zone_offset`, the type, the value, and `window_seconds`. It does not set `period_end` or `computed_by`. The response `metadata.resolution` is the raw or day label. A series row does not carry that label. The archive capsule -copies it. D208 writes that capsule only after the locked safety read. +copies it. D237 writes that capsule only after the locked safety read. `_aggregated_timeseries` handles `1min`, `5min`, `15min`, and `1hour`. It sets `window_seconds` from `BUCKET_SIZES` and does not set `period_end`. @@ -239,7 +239,7 @@ the value is null for current rows because they come from WHOOP and WHOOP's HRV there is RMSSD. The class prose calls `recovery_score` deprecated, WHOOP-only, and 0 to 100. The recovery query selects by category, not by WHOOP, and copies `provider` and `value` unchanged. -Polar writes recovery scores on the 1 to 6 range. D206 uses that range +Polar writes recovery scores on the 1 to 6 range. D235 uses that range table and the copied provider. It does not use the prose as the scale. `BodyLatest` has `skin_temperature_celsius` and `skin_temperature_measured_at`. `BodyAveraged` has `period_start`, @@ -257,7 +257,7 @@ listed rows. The personal-record response fields are `birth_date`, ## Contract read on 7 November 2026 The same commit was read again for the summary, score, meal, cycle, body, -and personal-record contracts. D208 is the storage rule. This section +and personal-record contracts. D237 is the storage rule. This section records the source facts that rule uses. `SERIES_TYPE_DEFINITIONS` has 141 entries. @@ -267,7 +267,7 @@ series are `heart_rate_variability_rmssd`, `heart_rate_variability_sdnn`, `oxygen_saturation`, `heart_rate_recovery_one_minute`, `vo2_max`, `garmin_stress_level`, and `garmin_body_battery`. -The table below is the mapping for all 141 series. D208 is the storage rule. +The table below is the mapping for all 141 series. D237 is the storage rule. `input_value` and the input unit are the server's number and unit. `standard_value` equals `input_value` except where the conversion is `divide by 100`. A day row uses the day record in the last column. It is diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index 745199f7..cf8dea4e 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -1,21 +1,85 @@ # Decisions — v2.2.0 -These proposals were numbered when D197 was the last decision on main. -They are still D198 through D215 in this folder. Version 2.1.1 has since -used those numbers. D198 through D207 are reserved by the unapproved draft -in [v2.1.1/appendix/draft-2.1.1/](../v2.1.1/appendix/draft-2.1.1/spec.md). -D208 through D226 are the 2.1.1 decisions. A citation in this folder means -the proposal below, not the 2.1.1 decision with the same number. This plan -does not renumber the proposals. Renumbering is waiting on the maintainer. - These are proposals in [spec.md](spec.md). The maintainer has not adopted them. This pull request does not build them. A change of mind before approval is an edit of the proposal. After approval, a change is a new D-number. -## D198. Version 2.2.0 is one manual pull, and the program and the record share that number - -`ath pull openwearables` reads the stored representations D208 lists from an +## Numbering + +These proposals are D227 through D244. They were first written as D198 +through D215, when D197 was the last decision on `main`. Version 2.1.1 then +used D208 through D226. D224 keeps D198 through D207 reserved for the +unapproved 2.1.1 draft in +[v2.1.1/appendix/draft-2.1.1/](../v2.1.1/appendix/draft-2.1.1/spec.md), so +they are never reused. On 15 November 2026 each proposal moved to the next +free number, in the same order. In this folder, D208 through D226 now mean +the 2.1.1 decisions. Reviews written before that day use the old numbers. + +| Old | New | Subject | +|---|---|---| +| D198 | D227 | Version 2.2.0 and one manual pull | +| D199 | D228 | Pages, and the shipped mapping writes the records | +| D200 | D229 | The key, the server, and the user id | +| D201 | D230 | A page is atomic and a repeat is safe | +| D202 | D231 | Work left out of this build | +| D203 | D232 | Stored measurements are kept | +| D204 | D233 | Meaning, source, and time | +| D205 | D234 | Units, windows, reported records, and identities | +| D206 | D235 | The new record type and refused originals | +| D207 | D236 | The migration rename, the counts, and the archive | +| D208 | D237 | The archive's safety facts | +| D209 | D238 | A typed workout is a session | +| D210 | D239 | Skin-temperature times | +| D211 | D240 | Heart-rate recovery of zero | +| D212 | D241 | A manual session window | +| D213 | D242 | A live workout original | +| D214 | D243 | The live vendor read | +| D215 | D244 | Vendor originals and credentials | + +## Changes on 15 November 2026 + +The plan was read again against `main` at `0de71bb`, the merge of 2.1.1. +These edits follow from that reading: + +- D230 and D237. A page is one 2.1.1 import preview and one apply. The + preview never writes. The apply refuses the page when the database + revision moved after the preview. The earlier text counted a page inside + a write transaction, rolled the count back, and read the safety facts a + second time under the write lock. Version 2.1.1 has no such step. +- D236 and D237. A deleted source or a deleted record leaves its rows out, + as D182 and D190 say. It no longer refuses the page. It still stops the + archive of that page. +- D227 and D236. Step 6 runs on the store's own connection. Foreign keys + are turned off before its transaction starts, in `src/store/migrate.rs`. +- D228. The pull gives each page to a reader that holds the page in + memory. `MappedReader` in 2.1.1 reads a file path. +- D229. The Open Wearables key is a third `KeyAccount`, beside the gateway + keys and the Garmin token. `ath key clear garmin` stays refused, as it is + in 2.1.1. +- D230, D232, D233, and D243. Limits and timeouts are named constants, as + 2.1.1 does. One response may be at most `MAX_PULL_RESPONSE_BYTES`, which + is 10 MiB. The earlier text said 8 MiB. +- D231. The source rules go in `src/import/provider.rs` and a new + `src/import/binding.rs`, where 2.1.1 stages and applies an import. They + no longer go in `src/store/write.rs`. The protocol's record writes join + the owner writes that store a whole source record. +- D232, D235, and D236. Sentences that called the new migration step 5 now + say step 6. Step 5 is the published 2.1.1 migration. + +These edits answer the thirteen findings of the review at `e145fa6`: + +- D242. The stored original's JSON layout, its key, its counts, and owner + deletion and correction. +- D243. Connections, statuses, Suunto keys, detail rules, timeouts, request + budgets, Garmin windows, id spelling, start times, and the count of every + object left out. +- D244. A credential-shaped value is withheld and counted. It no longer + refuses the page. + +## D227. Version 2.2.0 is one manual pull, and the program and the record share that number + +`ath pull openwearables` reads the stored representations D232 lists from an Open Wearables server the person runs, for one user and one range they name. The command is manual. The person runs it. The program does not schedule it, retry a failed request, or sign the person in to a device maker. @@ -26,14 +90,25 @@ step 5 is already published. It stores `2.1.1` and SQL schema 5 in `spec/sql/migrations/005-version-2-1-1.sql`. This pull adds step 6. Step 6 stores `2.2.0` and SQL schema 6. It adds no column to an existing table. It rebuilds `provider_summaries` and `provider_scores`, and it creates -`source_reports`, as D205 describes. D207 drops the record views and +`source_reports`, as D234 describes. D236 drops the record views and the two cross-table triggers around the root rename. Existing rows keep -their numbers. Steps 1 through 5 are not edited (D165). `install_schema` in -`src/store/mod.rs` runs steps 1 through 5 in one transaction with foreign -keys on, then commits. Step 6 runs after that commit, on a connection -ordinary writes do not reuse, and sets `user_version` 6. `apply_step` in -`src/store/migrate.rs` handles target 6 outside that ordinary transaction. -`MIGRATION_CHAIN` in that file and `spec/sql/contract.json` gain the step. +their numbers. Steps 1 through 5 are not edited (D165). + +In 2.1.1, `install_schema` in `src/store/mod.rs` runs the whole chain in one +transaction with foreign keys on. Every other migration runs inside +`Store::transaction`, which refuses to write when foreign keys are off. +Step 6 needs them off while it rebuilds tables that other tables point to. +So `install_schema` commits steps 1 through 5 first, and step 6 runs in its +own transaction on the store's own connection. `src/store/migrate.rs` turns +foreign keys off before that transaction begins, because SQLite ignores the +setting inside a transaction, and reads the setting back. The step runs +`PRAGMA foreign_key_check` and refuses any row it returns. It sets +`user_version` 6 and commits. Foreign keys are turned on again and read +back, whether the step committed or not. `ath migrate` keeps its verified +backup. Inside the step-6 transaction it checks again that the file, the +database ID, the schema, and the database revision are the ones its earlier +steps left. `MIGRATION_CHAIN` in that file and `spec/sql/contract.json` gain +the step. `packages/npm/package.json` exports point at `schema/2.2.0/`. `READABLE_DATABASE_VERSIONS` and `ACCEPTED_RECORD_VERSIONS` keep `1.0.0`, `2.0.0`, `2.1.0`, and `2.1.1`, and gain `2.2.0`. `IMPORTABLE_PACKAGE_VERSIONS` @@ -46,13 +121,13 @@ into a version change, a client, and a mapping change. The version numbers below are proposals. They are not specs, and they are not adopted. -- 2.2.0 is this pull. D203 says which stored measurements it keeps. +- 2.2.0 is this pull. D232 says which stored measurements it keeps. - 2.3.0 is a proposed Junction pull. This release does not call Junction. - 2.4.0 is proposed automatic incremental sync, saved sign-in refresh, retries, and backfill. This release has none of those. A smaller page - after a local 8 MiB cap, described in D203, is not that retry. + after the local response cap, described in D232, is not that retry. - An earlier draft of this plan left day aggregates and the heart-rate - stream out and suggested 2.5.0 for them. D203 supersedes that draft. + stream out and suggested 2.5.0 for them. D232 supersedes that draft. D88 still forbids a fabricated instant. It does not forbid keeping a bound the server sent. - A connector interface that every future source would implement is not @@ -77,12 +152,18 @@ Rejected alternatives: The later version numbers are proposals, not adopted assignments. - Leave day aggregates and the heart-rate stream for a later version, or request them while still calling that later version their home. Superseded - by D203. The current proposal stores them in this pull and says so. + by D232. The current proposal stores them in this pull and says so. -## D199. The pull fetches pages and the shipped mapping writes the records +## D228. The pull fetches pages and the shipped mapping writes the records New module `src/runtime/open_wearables.rs` requests the reads -in D203 and calls `MappedReader`. The command is added in `src/cli/`, +in D232 and gives each page to the mapping engine. In 2.1.1, `MappedReader` +in `src/import/mapping.rs` reads a JSON file from a path. The pull adds a +second reader beside it, `MappedPage`, that holds one decoded page in memory. +It runs the same checks as `MappedReader::read` and the same +`Run::map_input`. `preview_route` in `src/import/provider.rs` stages and +matches the page, and `ProviderPreview::apply` writes it. The command is +added in `src/cli/`, beside `ath pull garmin` in `src/cli/commands/routes.rs`. Version 2.1.1 superseded D174's TypeScript front end and the separate `ath-core` library in D155 and D162. This pull does not bring either back. The library is the @@ -101,13 +182,15 @@ file does not name stays in `supplied_fields` under the name it arrived with D187, D192). Sleep and workout responses are envelopes with `data` and `metadata`. The -shipped file's page section is `timeseries`, so `MappedReader` would leave -that envelope out. The pull passes sleep rows as `{ "sleep": [ ... ] }` and +shipped file's page section is `timeseries`, so the mapping engine would +leave that envelope out. The pull passes sleep rows as `{ "sleep": [ ... ] }` and workout rows as `{ "workout": [ ... ] }`. It passes each timeseries response through unchanged, so `metadata.resolution` still reaches the mapping. The -pull does not drop one row and keep its neighbors. A credential, a reflected -origin or user id, a same-key `device_id` collision, or a bad envelope -rejects the whole page first. A manual workout is written. D209 stores +pull does not drop one row and keep its neighbors. The API key, the +server's origin or the selected user id echoed in a response, a same-key +`device_id` collision, or a bad envelope rejects the whole page first. A +value under a credential-shaped key is withheld and counted instead, as +D244 says. A manual workout is written. D238 stores it as a workout session. The other rows in that page are still written. The timeseries query's `types` list is the `type.` lines in the @@ -121,55 +204,57 @@ no second copy of those names. On Open Wearables 0.11.0 the route defaults `types` to an empty list, and the repository applies a type filter only when the list is nonempty (`data_point_series_repository.py`). An empty list therefore returns every -series. D203 omits `types` on the raw read and the day read for that +series. D232 omits `types` on the raw read and the day read for that reason. A mapping that cannot store those series fails before any network call. A comma-joined type string is still not sent. -`heart_rate` is a series quantity. D203 stores the raw stream as +`heart_rate` is a series quantity. D232 stores the raw stream as measurement samples. Workout `avg_heart_rate_bpm` and `max_heart_rate_bpm` stay as the file already maps them. -`MappedReader` adds counts by record type. The mapped-import report in -`src/import/provider.rs` keeps its `outcome` field. The pull adds those -counts into the committed result for a page that -committed and into `estimated` for a page that was rolled back. It does not -add `outcome` across pages. Estimated counts are against the database before -this command. They are not equal to the write when the same match key appears -on two pages, or when the server changes between runs. The write still -follows D182. This proposal does not keep a command-wide preview overlay. - -The read order is the order in D203. A failure in a later read +The pull counts each page by record type from its staged plan, which +`ProviderPreview::planned` already lists. The mapped-import report from +`report_value` in `src/import/provider.rs` keeps its `outcome` field. The +pull adds the counts into the committed result for a page it applied, and +into `estimated` for a page it only previewed. It does not add `outcome` +across pages. A preview writes nothing, so estimated counts are against the +database as it was before this command. They are not equal to the write +when the same match key appears on two pages, or when the server changes +between runs. The write still follows D182. This proposal does not keep a +command-wide preview overlay. + +The read order is the order in D232. A failure in a later read leaves the earlier read's pages committed and the reads after the failure -`not_attempted`. The result says so. See D201. +`not_attempted`. The result says so. See D230. -D203 is the coverage rule. An earlier draft of this decision left the day +D232 is the coverage rule. An earlier draft of this decision left the day rows, the summaries, and the heart-rate stream unrequested. That draft is superseded. D88 still forbids inventing a midnight. The period type in -D203 stores the bound the server sent. An Open Wearables window is not +D232 stores the bound the server sent. An Open Wearables window is not labeled as a Whoop cycle or an Oura day. Sleep requests `include=stages`. Workouts request `include=zones` and `include=segments`. Stage minute totals return either way. The timeline, the zones, and the segments are null when the expansion is omitted, so omitting it would drop them before `supplied_fields` can keep them. A page -over 8 MiB is handled as D203 says. +over the response cap is handled as D232 says. Rejected alternatives: - Teach the pull the Open Wearables field names in Rust. Rejected because D161 put those names in the mapping file so a second source does not become a second record format. -- Pass the sleep envelope straight to `MappedReader`. Rejected because the - current page rule would leave the page out. The check is `page_rows` and +- Pass the sleep envelope straight to the mapping engine. Rejected because + the current page rule would leave the page out. The check is `page_rows` and `row_fits` in `src/import/mapping.rs`. - Request every series type and let `left_out` drop the ones the mapping - cannot store. Rejected. D203 stores them. `left_out` remains a row the + cannot store. Rejected. D232 stores them. `left_out` remains a row the server returned and this program refused for a named reason. - Map `heart_rate` samples as points, or map a day summary onto midnight. Rejected. `heart_rate` is stored as a measurement sample. A day row is - stored as a reporting window (D88, D110, D203). + stored as a reporting window (D88, D110, D232). - Refuse an empty `types` list in order to avoid heart rate and location. - Superseded by D203. Omitting `types` is how 0.11.0 returns every series, + Superseded by D232. Omitting `types` is how 0.11.0 returns every series, and those series are stored. A comma-joined string is still not a member of the enum. - Put `device_id` on the sensor string, and therefore on the match key, for @@ -195,7 +280,7 @@ Rejected alternatives: package restore, and an accepted package merge store the whole source the owner supplied. A hand-edited database file is outside this proposal. -## D200. The key, the server, and the user id stay out of the record +## D229. The key, the server, and the user id stay out of the record The API key is an administrator key for every user on that deployment. The pull sends it only as the header `X-Open-Wearables-API-Key`. It is saved with @@ -208,9 +293,14 @@ in `src/runtime/keyring.rs`. There is no child process and no not a command argument. If the password store is missing, the command refuses and does not write a file. -Open Wearables is not added to the gateway list. `GATEWAYS` stays `vercel` -and `openrouter`. `ath key clear` with no name still clears only those -gateway keys, and it still exits successfully when that is what it did. +Open Wearables is not a gateway. `Gateway::ALL` in `src/runtime/keyring.rs` +stays `vercel` and `openrouter`. `KeyAccount` in that file gains +`OpenWearables`, saved under the account `openwearables`, the way 2.1.1 +added `Garmin`. `account_secret` reads `OPEN_WEARABLES_API_KEY` before the +saved key, as it reads `GARMIN_PERSONAL_API_KEY` for Garmin. `key_clear` in +`src/cli/commands/model.rs` accepts `openwearables` before it parses a +gateway name. `ath key clear` with no name still clears only the gateway +keys, and it still exits successfully when that is what it did. When a saved Open Wearables key remains, the text adds two sentences: the Open Wearables key remains saved, and `ath key clear openwearables` removes it. When no saved Open Wearables key remains, the gateway sentences stay as @@ -227,12 +317,14 @@ does not claim an environment key remains. Wearables key and for `OPEN_WEARABLES_API_KEY`, and it prints neither value. `ath key --json` keeps `saved` and `environment` as the gateway lists they are today, and adds `openwearables.saved` and `openwearables.environment`. -Garmin's key command is unchanged. +Garmin's key command is unchanged. In 2.1.1, `ath key clear garmin` is +refused because `garmin` is not a gateway name. This pull keeps that, and +the specification's section 9 lists it as a separate follow-up. The server is `--base-url` or `OPEN_WEARABLES_BASE_URL`. The user id is `--user` or `OPEN_WEARABLES_USER_ID`. Neither is written into the database, the export, a config file, or a log line. The pull never calls `GET /users`. -D204 reads the personal record and drops its `user_id` before the scan. +D233 reads the personal record and drops its `user_id` before the scan. Birth date, gender, and sex are stored. One command reads one user. `--base-url` is an origin: scheme, host, and optional port. No user name, no @@ -240,16 +332,18 @@ password, no path other than empty or `/`, no query, and no fragment. `http` is allowed only for `localhost`, `127.0.0.1`, and `::1`. Any other host requires `https`. The pull appends `/api/v1` itself. Redirects are not followed. A timeout, a non-JSON body, or an HTTP error becomes the page -failure in D201. The printed error is a fixed sentence and the HTTP status. A problem `code` +failure in D230. The printed error is a fixed sentence and the HTTP status. A problem `code` is printed only when it is one short token and does not contain the key, the origin, or the user id. Otherwise it is withheld. A transport error or a parser error is replaced with a fixed sentence that has no URL, no path, and no user id. -After the body is read inside the size cap and parsed, and before -`MappedReader`, `open_wearables.rs` walks every object key and every string. -A value that contains the API key, the selected origin, or the selected user -id rejects the whole page. The row is not rewritten. A scan of the raw text +After the body is read inside the size cap and parsed, and before the page +reaches `MappedPage`, `open_wearables.rs` walks every object key and every +string. A value that contains the API key, the selected origin, or the +selected user id rejects the whole page. The row is not rewritten. A value +under a credential-shaped key is a different case. D244 withholds that one +value and counts it. A scan of the raw text misses a Unicode escape. The raw-text scan and the check before printing stay as defense in depth. They are not what keeps the key out of a committed page. Named clear of the saved key does not revoke it on the server. @@ -273,7 +367,7 @@ Rejected alternatives: - List users and pull every user the key can see. Rejected because the key sees the whole deployment, and this record is one athlete. -## D201. A page is atomic, a missing row is not a deletion, and the same command is safe to repeat +## D230. A page is atomic, a missing row is not a deletion, and the same command is safe to repeat Each response page is one `MappedReader` call. D189 still makes that call one transaction: a failure rolls the page back, and a preview rolls the page @@ -285,7 +379,7 @@ page follows D189. A committed page does not mean the pull is complete. The command previews unless `--yes` is present. `--json` does not write, with or without `--yes`, matching `ath import --mapping`. `--yes` without `--json` writes each protected page as that page succeeds. A refused -page is not a success. The pull-only archive in D208 is a separate +page is not a success. The pull-only archive in D237 is a separate transaction. It reads the safety facts again before it writes. The command returns one bounded outcome for the mode it ran. A preview, @@ -333,10 +427,10 @@ runs the failed read again, and runs any read that was `not_attempted`. `has_more: false` is the successful end of a cursor read and of the offset read. A repeated cursor, a null cursor while `has_more` is true, and the 1000-page cap fail that read. An offset retry uses the same offset. A body -over 8 MiB is handled by D204. The failed page is not written. Later reads +over 8 MiB is handled by D233. The failed page is not written. Later reads are `not_attempted`. The success line is not printed. A cursor with the `prev_` prefix is not sent. `limit` starts at 1000. One attempt is made per -request, except the smaller page D204 sends after a local size cap. A +request, except the smaller page D233 sends after a local size cap. A transport error is not retried. The connect timeout is 10 seconds and the read timeout is 30 seconds. @@ -355,7 +449,7 @@ records the disagreement between the docs and the 0.11.0 parser. The queries are the table in the specification's section 2. An earlier draft of this proposal listed three reads and treated every page as a -cursor envelope. D204 supersedes that draft. `source_selection` is not +cursor envelope. D233 supersedes that draft. `source_selection` is not sent. On 0.11.0 the parameter does not exist. On current `main`, omitting it returns every device when the priority flag is false. Summary routes still select a source. That selection is not a client filter. @@ -380,7 +474,7 @@ Rejected alternatives: because D88 forbids rewriting a source bound into a timezone the source did not use. -## D202. The Windows cleanup and the maintainability notes are not part of this build +## D231. The Windows cleanup and the maintainability notes are not part of this build Checked again on version 2.1.1 at `0de71bbd6474916af0408a4090bc2c74a1a3aed2`, the merge of pull request 44. The earlier check was version 2.1.0 at @@ -395,7 +489,7 @@ after that. Neither path collects abandoned temporary directories first. working data uses it. The database file is not one of those directories. Version 2.1.0 spec section 12 left the production database cleanup out and named no later version. Version 2.1.1 did not take that work. The cleanup -does not run on a pull. This build does not change it. D208 rolls a failed +does not run on a pull. This build does not change it. D237 rolls a failed step 6 back before this cleanup runs. `src/import/mapping.rs` is 1703 lines. The store is already several files. @@ -403,9 +497,9 @@ step 6 back before this cleanup runs. `src/store/encode.rs` is 549, and `src/store/check.rs` is 1044. `persist.rs` is gone. The pull is a new module so `mapping.rs` and the store files do not grow for HTTP. `mapping.rs` may add the count by record -type that D199 names, and the open-wearables device-binding check in the +type that D228 names, and the open-wearables device-binding check in the specification. That check is shared by mapped import and pull, and it is -limited to route `open_wearables`. D203 also adds the measurement-sample +limited to route `open_wearables`. D232 also adds the measurement-sample target, the reporting-window write, and the segment copy. Nothing beyond that is added to `mapping.rs`. Source writes go through `Store::apply` in `src/store/write.rs`. There is no `Store::revise`. A correction carries the @@ -416,12 +510,12 @@ and tombstone-inclusive history, create a source with the checked receipt, and write that receipt on an existing unbound source only when the same transaction shows no accepted or deleted record and no source device. Those writes keep every other source field and the normal revision and `data_json` -bookkeeping. They join the caller's `BEGIN IMMEDIATE` transaction. D204 +bookkeeping. They join the caller's `BEGIN IMMEDIATE` transaction. D233 also allows `measurement_sample` insert and update, and a null value and unit pair on provider summaries and provider scores. A half-null pair is refused. `write_current_state` in `src/store/encode.rs` is the only record-to-table mapping. Package restore, repair, and the record check use -it. There is no TypeScript writer to update. D205 also allows +it. There is no TypeScript writer to update. D234 also allows `source_report` insert and update, and withdrawal of a child whose anchor is in this response. Nothing beyond that is added to the store. Other routes do not call the receipt operations. `ath correct`, package restore, @@ -446,14 +540,14 @@ Rejected alternatives: - Block the pull on those fixes. Rejected for the same reason. A later change can take any one of them on its own. -## D203. Stored Open Wearables measurements are kept in this pull +## D232. Stored Open Wearables measurements are kept in this pull -D204 supersedes the classification, source identity, time, score, endpoint, -and size sentences in this proposal. D205 supersedes D204 where they +D233 supersedes the classification, source identity, time, score, endpoint, +and size sentences in this proposal. D234 supersedes D233 where they disagree. The decision to keep the returned health data in this pull -stands. Where a paragraph below disagrees with D208, D208 is the proposal. +stands. Where a paragraph below disagrees with D237, D237 is the proposal. -This supersedes the earlier draft, inside D198 and D199, that left day +This supersedes the earlier draft, inside D227 and D228, that left day values, the heart-rate stream, sleep and recovery summaries, meals, and workout segments out of this pull. Those drafts are not deleted above. They are not the current proposal. The specification's section 2 is the @@ -492,29 +586,29 @@ Rejected alternatives: make a reporting window look like one instant (D88, D110). - Drop latitude, longitude, segments, or a large series to keep a response under 8 MiB. Rejected. The smaller page in the specification - stores the rows. D204 states the minimum-page limit without naming a + stores the rows. D233 states the minimum-page limit without naming a series type. - Call the live provider workout proxy or the totals routes so the pull can say it hit every path. Rejected. Those routes are not the stored - measurements. D204 does read the personal record. An earlier sentence + measurements. D233 does read the personal record. An earlier sentence in this list left it out. That sentence is superseded. - Invent a midnight, a zero, or an SDNN value from an RMSSD value. Rejected. A null stays absent. `RecoverySummary` at the pinned commit has no skin-temperature field. A health-score component can still carry - one. D204 says so. + one. D233 says so. -## D204. Returned values keep their meaning, source, and time +## D233. Returned values keep their meaning, source, and time -D205 supersedes the sentences below that call dietary or index series +D234 supersedes the sentences below that call dietary or index series provider summaries, that store a day row as the same class as its raw sample, that build a sensor by joining parts with `:` and `-`, that put main-sleep bounds on a summed field, that leave a missing device id as `left_out`, that omit a manual workout, and that treat `received_at` as the time a revision was written. The values stay in this pull. The -device-receipt rules stay. Where this proposal disagrees with D205, D205 +device-receipt rules stay. Where this proposal disagrees with D234, D234 is the proposal. -This corrects D203. The corrections that D205 does not replace are the +This corrects D232. The corrections that D234 does not replace are the contracts in the specification's section 2. A device source is still the 2.1.0 sensor, and its receipt rules are @@ -579,20 +673,20 @@ Rejected alternatives: - Stop a day read at `limit` 1 and report one oversized series. Rejected. That limit counts periods, and one period can hold many rows. -## D205. Units, windows, reported records, and identities stay distinct +## D234. Units, windows, reported records, and identities stay distinct -D206 supersedes the sentences below that put every source-present series +D235 supersedes the sentences below that put every source-present series through the device check, that compare null-source rows by type and timestamp alone, that leave a refused original unstored in every case, that map `heart_rate_recovery_one_minute` to a quantity of that same name, and that call `hydration` a measurement sample. The units, day -windows, sleep bounds, and reported-record direction stay. D207 -supersedes D206 where they disagree. D208 supersedes D207 where they -disagree. Where this proposal disagrees with D208, D208 is the proposal, +windows, sleep bounds, and reported-record direction stay. D236 +supersedes D235 where they disagree. D237 supersedes D236 where they +disagree. Where this proposal disagrees with D237, D237 is the proposal, except the sentences that store a manual workout as a source report. -D209 supersedes those sentences. +D238 supersedes those sentences. -This corrects D204. The returned health data stays in this pull. The +This corrects D233. The returned health data stays in this pull. The specification's section 2 and the appendix series table are the contract. Every series has an input number, an input unit, a standard number, and a @@ -631,7 +725,7 @@ nutrient numbers, index, age, and effort series, personal-record fields, predicted and coded cycle content, BMI, calculated age, and an unbounded health score use this type. The eight range calculations and `provider-period-summary` do not read it. A manual workout is a workout -session. D209 is that rule. An automatic workout stays a measured +session. D238 is that rule. An automatic workout stays a measured session on the device source. A new sensor is `ow1:` plus a JSON array with no spaces. JSON `null`, an @@ -644,7 +738,7 @@ Two unequal payloads at the same type and time refuse the call. The personal record uses `["personal_record"]` and that same writer. A meal or cycle uses the event array even when `device_id` is present. That id stays in the array and in the original object. It does not establish -`device_binding`. A manual workout does not use that array. D209 puts it +`device_binding`. A manual workout does not use that array. D238 puts it on the manual source. A raw or day row whose `source` object has no `device_id` is an incoming @@ -691,23 +785,23 @@ Rejected alternatives: SPEC section 5.4 and D161 keep those measured types for measured records. A source report preserves the object without making it a measurement. -- Call a manual workout a provider summary. Rejected. D209 stores it as +- Call a manual workout a provider summary. Rejected. D238 stores it as a workout session. It is not a provider summary. - Leave a removed nutrient current because the store compares emitted keys. Rejected. The same object no longer contains that number. -## D206. The new record type, numberless inputs, and refused originals stay separable +## D235. The new record type, numberless inputs, and refused originals stay separable -D207 supersedes the sentences below that leave the record views in place +D236 supersedes the sentences below that leave the record views in place during the rename, that set `written` false for an archive without defining `database_changed`, that archive a page from the first error, that hash the series row without its resolution, and that give a null-source reported series both the report sensor and the unattributed sensor. The root check, the numberless readers, and the reported-record -direction stay. D208 supersedes D207 where they disagree. Where this -proposal disagrees with D208, D208 is the proposal. +direction stay. D237 supersedes D236 where they disagree. Where this +proposal disagrees with D237, D237 is the proposal. -This corrects D205. The returned health data stays in this pull. The +This corrects D234. The returned health data stays in this pull. The specification is the contract. `records.record_type` is a closed check. `source_report` is not in it. @@ -717,7 +811,7 @@ not edit migrations 001 through 004, and it does not drop the check. Ordinary writes keep foreign keys on. The migration connection may turn them off only before its own transaction, rebuild `records` and the two nullable typed tables by copy, rename, and recreate, then require -`foreign_key_check` and `integrity_check` before commit. D207 drops the +`foreign_key_check` and `integrity_check` before commit. D236 drops the two record views and the two cross-table triggers before that rename and recreates them unchanged. A drop of `records` inside the ordinary foreign-key transaction is not the @@ -751,8 +845,8 @@ id with a different kind refuses the page. A protected refusal rolls back. For a missing device id on a device-targeted series row, and for unequal null-source payloads of one full match key, a later archive transaction stores kind `original` with -no amount and no device receipt. D208 is when that transaction may -write. D207 is the capsule and the command counts. `written` stays false when only the archive +no amount and no device receipt. D237 is when that transaction may +write. D236 is the capsule and the command counts. `written` stays false when only the archive changed. The command exits nonzero. Credential failures, invalid ids, conflicting device ids, legacy history, and kind changes are not archived. Those originals are @@ -783,15 +877,15 @@ Rejected alternatives: second transaction with a failed protected-write status. The other refusal reasons stay unstored. -## D207. The migration rename, the command counts, and the archive decision stay consistent +## D236. The migration rename, the command counts, and the archive decision stay consistent -D208 supersedes the sentences below that classify database facts before +D237 supersedes the sentences below that classify database facts before either transaction, that leave the archive with only an archive-source check, and that leave a failed init file in place. The migration graph, the command counts, the capsule, and the report routing stay. Where this -proposal disagrees with D208, D208 is the proposal. +proposal disagrees with D237, D237 is the proposal. -This corrects D206. The returned health data stays in this pull. The +This corrects D235. The returned health data stays in this pull. The specification is the contract. Step 5 drops `sql_v1_current_records`, `sql_v1_active_records`, and the @@ -812,7 +906,7 @@ itself back, and leaves earlier commits. The pull text for a new archive-only change is `Protected write refused; N originals archived; database changed; pull incomplete.` -D208 reads database-dependent vetoes inside the protected transaction +D237 reads database-dependent vetoes inside the protected transaction and reads them again before any archive write. A veto there, including on a `left_out` row, forbids the archive. The privacy scan still comes first. The archive is pull-only. A mapped file import does not gain it. @@ -844,9 +938,9 @@ Rejected alternatives: - Hash the series row and infer the resolution later. Rejected. The resolution is on the response, not on the row. -## D208. The archive reads safety facts under the write lock +## D237. The archive reads safety facts under the write lock -This corrects D207. The returned health data stays in this pull. The +This corrects D236. The returned health data stays in this pull. The specification is the contract. Privacy, required ids, and supplied-field names are checked on the @@ -872,7 +966,7 @@ row the bounded read cannot cover, the page is not archived. There is no retry. A failed step 6 during init rolls back to the committed step 5 schema -before the existing init cleanup runs. Init fails. D202's cleanup is +before the existing init cleanup runs. Init fails. D231's cleanup is unchanged. A migrate of an existing database keeps that file and the old schema when step 6 rolls back. @@ -887,10 +981,10 @@ Rejected alternatives: - Leave a failed init file at step 5. Rejected. The existing caller removes that file, and this build does not change that cleanup. -## D209. A workout the person typed is a workout session +## D238. A workout the person typed is a workout session -This supersedes only the sentences in D198 and D205 that store a manual -workout as a source report or leave it out. D198 through D208 otherwise +This supersedes only the sentences in D227 and D234 that store a manual +workout as a source report or leave it out. D227 through D237 otherwise stay as written. The specification is the contract. `entry_source` `manual` is a `workout_session`. Its source type is @@ -901,7 +995,7 @@ workout on the watch's source. The server workout id is the match key, so a later pull updates the same workout. Name, type, start, end, distance, heart rate, elevation, zones, and segments are stored the same way they are stored on an automatic workout. `activity_type` still -records that Open Wearables normalized the sport name. D212 corrects the +records that Open Wearables normalized the sport name. D241 corrects the next rule. The numbers on this session do not enter the eight range calculations or `provider-period-summary`. `workout-drift` may use the session's start and end when the caller names that session. The samples @@ -921,7 +1015,7 @@ Rejected alternatives: - Treat `unknown`, JSON null, or a missing `entry_source` as manual. Rejected. Those values are not the self-reported entry. -## D210. A body skin-temperature time is not an instant by itself +## D239. A body skin-temperature time is not an instant by itself This corrects the sentence that treats a non-null `skin_temperature_measured_at` as a measurement instant. The other body @@ -944,7 +1038,7 @@ Rejected alternatives: - Drop the timestamp. Rejected. The original object keeps what the server sent. -## D211. A finite heart-rate recovery stays, including zero +## D240. A finite heart-rate recovery stays, including zero This corrects the positive point gate for one quantity. The quantity, the unit, and the import key stay `hr_recovery` and `bpm`. @@ -966,9 +1060,9 @@ Rejected alternatives: zero for this quantity. - Allow zero for every point. Rejected. The other positive checks stay. -## D212. A manual session can set a window, and its numbers stay out +## D241. A manual session can set a window, and its numbers stay out -This corrects the D209 sentence that says the calculations do not read a +This corrects the D238 sentence that says the calculations do not read a manual workout. It does not change the calculation code. `read_inputs` and `read_period` exclude `source_type` `manual`. They have @@ -992,9 +1086,9 @@ Rejected alternatives: - Let a manual heart rate enter a baseline when `include_manual` is set. Rejected. The calculation SQL has no such switch. -## D213. A provider-live workout is kept as an original +## D242. A provider-live workout is kept as an original -D214 is the live-read procedure. D215 is the privacy choice. Where this +D243 is the live-read procedure. D244 is the privacy choice. Where this proposal disagrees with either, those decisions are the proposal. The stored workout list is the normalized session. The provider route @@ -1028,9 +1122,9 @@ Rejected alternatives: - Call sync or historical sync to fill the gap. Rejected. Those routes are writes this pull does not call. -## D214. A live vendor read is opt-in, and one failure stays on that provider +## D243. A live vendor read is opt-in, and one failure stays on that provider -This supersedes the D213 sentences that said a live GET does not write on +This supersedes the D242 sentences that said a live GET does not write on the server, that a failed provider stops the later providers, that Polar's list asks for samples, zones, and route, that a start outside the range is dropped, and that the server splits a Garmin range. @@ -1084,7 +1178,7 @@ Rejected alternatives: The live methods do not filter by workout start, so a drop would hide a returned object. -## D215. Vendor originals stay whole. The maintainer can change this +## D244. Vendor originals stay whole. The maintainer can change this This is a labeled choice. The default in this proposal is to keep each vendor object whole, including account ids, Polar user URLs, and full GPS diff --git a/build-history/v2.2.0/progress.md b/build-history/v2.2.0/progress.md index 1535fc2c..5ad26964 100644 --- a/build-history/v2.2.0/progress.md +++ b/build-history/v2.2.0/progress.md @@ -5,10 +5,10 @@ program, the record, or the database has changed for 2.2.0. | Step | What | Status | |---|---|---| -| 0 | The plan: proposals D198–D215, and the Open Wearables study. D210 through D212 stay. D214 corrects the live-read procedure. D215 is the privacy choice for vendor objects. Still not adopted. The new head needs a fresh four-role review | written, not approved | -| 1 | Version 2.2.0 and migration step 6. Step 5 is the published 2.1.1 migration. No new column on an existing table. The root check gains `source_report` by the copy in D207. Summary and score values may be omitted in pairs (D198, D207) | not started | -| 2 | `ath pull openwearables` in the `athleticstandard` crate, with the rewritten mapping (D199, D201, D207) | not started | -| 3 | Key, server, and user id kept out of the record (D200) | not started | +| 0 | The plan: proposals D227–D244, and the Open Wearables study. D239 through D241 stay. D243 corrects the live-read procedure. D244 is the privacy choice for vendor objects. Still not adopted. The new head needs a fresh four-role review | written, not approved | +| 1 | Version 2.2.0 and migration step 6. Step 5 is the published 2.1.1 migration. No new column on an existing table. The root check gains `source_report` by the copy in D236. Summary and score values may be omitted in pairs (D227, D236) | not started | +| 2 | `ath pull openwearables` in the `athleticstandard` crate, with the rewritten mapping (D228, D230, D236) | not started | +| 3 | Key, server, and user id kept out of the record (D229) | not started | | 4 | Fixture tests, with no live key in CI | not started | | 5 | Generated schema, demo athlete, skill command reference, and the public-data list | not started | | 6 | Laptop card and the proof in the build pull request | not started | @@ -16,5 +16,5 @@ program, the record, or the database has changed for 2.2.0. The build, after approval, is one pull request. It is not three. The Windows failed-init cleanup, the size of `src/import/mapping.rs`, and a -name check outside import stay out of that pull request (D202). `persist.rs` +name check outside import stay out of that pull request (D231). `persist.rs` is already gone. diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index a7b00f74..8e06c0b6 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -6,7 +6,7 @@ Status: **plan only. The maintainer has not approved it. Not approved for build. Wearables server they run. When `--vendor-workouts` is passed, it also reads the live workout list and detail. It writes the stored reads with the mapping this release ships. It writes a live original only when that -flag is on and the person confirms the write. The proposals are D198 through D215 in +flag is on and the person confirms the write. The proposals are D227 through D244 in [decisions.md](decisions.md). They are not adopted. The evidence is [appendix/open-wearables-api.md](appendix/open-wearables-api.md), checked on 6, 7, 8, and 14 November 2026. @@ -51,7 +51,10 @@ environment when both are set. `--vendor-workouts` is off unless the person passes it. Without it, the command does not call the connections route or either live workout route. -With it, those calls run, including on a preview and on `--json`. +With it, those calls run, including on a preview and on `--json`. The +server may then refresh and save vendor tokens, revoke a connection, and +wait about 105 seconds on a rate limit. The help text and every run with +the flag say so (section 2). The first run writes nothing. `--json` writes nothing, including when `--yes` is also present. That is the same rule as `ath import --mapping`. @@ -65,8 +68,8 @@ committed result is the text of `--yes` without `--json`. A writing JSON report would be a different choice. It is not this proposal. Preview text, and every `--json` result, labels counts `estimated`. Each -page is counted against the database as it was before this command, then -rolled back. A match key that appears on two pages, or a server that changes +page is previewed against the database as it was before this command. A +preview writes nothing. A match key that appears on two pages, or a server that changes between the preview and `--yes`, can make the estimate differ from the write. The estimate is not a promise of the final new, changed, and unchanged split. Exact equality would need a command-wide overlay. This @@ -76,16 +79,21 @@ Preview text prints: - one line that a date-only bound is sent as typed, and Open Wearables decides what that day means -- `preview only; nothing stored` +- `preview only; nothing stored in this database` - `reads finished` or `reads incomplete` - one line each for the twelve reads in section 2: `completed`, `failed`, or `not_attempted` - one line each for the live workout providers: `completed`, `incomplete`, - or `not_attempted`, whether that limit covers the requested range, and - whether more data exists + or `not_attempted`, the connection status when it is not `active`, + whether that limit covers the requested range, whether more data exists, + and the detail and left-out counts in section 2 +- when `--vendor-workouts` is on, before the first live request: the three + sentences about server changes in section 2 - when `--vendor-workouts` is on: `vendor requests were made` - when `--vendor-workouts` is on: `vendor workout originals` with new, changed, and unchanged counts +- when a credential-shaped value was withheld: the count and up to 20 + paths, as section 4 says - when `--vendor-workouts` is on, this sentence: a workout can appear twice, once as the vendor original and once as the stored session. The original is the source report whose subject is `vendor_workout`. It is never a @@ -98,11 +106,15 @@ Preview text prints: measurement samples, summaries, scores, and source reports - committed counts of zero on a preview - the coverage lines in section 2 -- `left_out` as a total plus at most 20 example lines -- `nothing written; pass --yes after reviewing this preview` +- `left_out` as a total, a count for each reason, and at most 20 example + lines. When there are more lines, it says the list was shortened, as + 2.1.1 previews do with `MAX_PREVIEW_RECORD_IDS` +- `nothing written to this database; pass --yes after reviewing this preview`. + The shared `NOTHING_WRITTEN` line in `src/cli/commands/routes.rs` stays + as it is for the other commands `--yes` without `--json` commits each successful page. That commit is one -`MappedReader` transaction (D189). It is not a completed pull. The text +`ProviderPreview::apply` transaction (D189). It is not a completed pull. The text prints actual committed counts for pages kept. It prints `requested range through is complete` only when every stored ranged read in section 2 reached that read's terminal condition. A live workout line does @@ -125,10 +137,10 @@ complete and names the snapshot that failed. It names any read that is in both cases. The success sentence is not printed. A failed read says to run the same command again. An identity refusal uses the sentence in section 3, which says a rerun cannot -repair the device id. It does not print the success sentence. The -protected transaction of a refused page makes no database changes. +repair the device id. It does not print the success sentence. A refused +page is not applied, so it makes no database changes. Records already stored stay, including their revisions. An archive, when -section 2 allows one, is a later pull-only transaction. It does not print +section 2 allows one, is a later pull-only preview and apply. It does not print the success sentence. `written` is true when any protected transaction in this command created or revised a counted record. An archive does not make `written` true. `database_changed` is true when any protected @@ -177,24 +189,42 @@ the text. The object has no key, server, user id, or request path. "archive_committed": { "source_report": { "new": 0, "changed": 0, "unchanged": 0 } }, - "left_out": { "total": 0, "examples": [] }, + "left_out": { "total": 0, "by_reason": {}, "examples": [], "shortened": false }, + "withheld": { "total": 0, "paths": [], "shortened": false }, "vendor_workouts": { "requested": false, "requests_made": false, + "notice": [], "originals": { "new": 0, "changed": 0, "unchanged": 0 }, "providers": { "garmin": { "status": "not_attempted", + "connection_status": null, "covers_requested_range": false, "more": false, - "deferred": 0, - "limit": "not requested" + "limit": "not requested", + "details": { + "stored": 0, + "kept": 0, + "deferred": 0, + "failed": 0, + "mismatch": 0, + "thinner": 0, + "not_available": 0 + }, + "left_out": { "total": 0, "by_reason": {} } } } } } ``` +`notice` is empty without the flag. With it, `notice` holds the three +sentences about server changes in section 2, on every run, including a +preview. `connection_status` is `active`, `revoked`, `expired`, +`unknown status`, or `null` when the server listed no connection for that +provider. + The same record types are present for workouts, points, summaries, scores, and source reports. The example above is shortened. Polar, Suunto, Whoop, Fitbit, Oura, Strava, Withings, and Sensorbio use the same fields as @@ -220,15 +250,29 @@ protected counts. An earlier change keeps both flags true. A failed ranged page failed snapshot after a finished range has `range_complete` true and `snapshots_complete` false. The command prints sentences from this outcome. It does not print the outcome as public JSON. Public `--json`, with or -without `--yes`, commits neither the protected transaction nor the -archive transaction. - -`--date` stays required only for `garmin`. `--from` and `--to` are required +without `--yes`, applies neither the protected preview nor the archive +preview. + +`--date` stays required only for `garmin`. In 2.1.1, `PULL` in +`src/cli/spec.rs` marks `--date` mandatory, so the parser refuses any pull +without it: `error: required option '--date ' not specified`. The +build drops that mark. `pull` in `src/cli/commands/routes.rs` then checks +`--date` for `garmin` and prints that same text, so `ath pull garmin` +without a date fails as it does today. `--from` and `--to` are required only for `openwearables`, and they are flags, not environment variables. `--base-url` and `--user` are required for `openwearables` unless the -environment named above supplies them. `ath pull garmin --date YYYY-MM-DD` is -otherwise unchanged. `ath pull` with any other name still fails. The failure -text becomes `pull reads garmin or openwearables`. +environment named above supplies them. `--base-url` already exists for +`garmin`, where it names a test server's API root. For `openwearables` it +names the server origin, as D229 says. `ath pull garmin --date YYYY-MM-DD` +is otherwise unchanged, and it still writes without a preview. +`ath pull` with any other name still fails. The failure text +`pull currently reads garmin` becomes `pull reads garmin or openwearables`. + +The flag's help in `src/cli/spec.rs` says: also read live vendor workouts; +the server may refresh and save vendor tokens, revoke a connection, and +wait about 105 seconds on a rate limit. `src/cli/examples/pull.txt` repeats +those three effects and says that "nothing stored" means this database +only. The saved key can read every user on that server. `ath key` shows whether a key is saved in the password store and whether `OPEN_WEARABLES_API_KEY` is @@ -254,21 +298,21 @@ gateway commands they are today. ## 2. What this pull stores -D208 is the storage rule. D203 keeps these values in this pull. D204 -corrected source, time, and score direction. D205 corrects units, day +D237 is the storage rule. D232 keeps these values in this pull. D233 +corrected source, time, and score direction. D234 corrects units, day windows, sleep bounds, identity encoding, reported records, and child -withdrawal. D206 corrects the root record type, numberless calculation +withdrawal. D235 corrects the root record type, numberless calculation inputs, recovery scales, required ids, workout provenance, hydration, -and the archive of a refused original. D207 corrects the migration +and the archive of a refused original. D236 corrects the migration dependencies, the command counts, the archive capsule, and null-source -report routing. D208 corrects when the archive reads the database, and -the failed-init sentence. D209 stores a workout the person typed as a -workout session. D210 keeps a body skin-temperature time unknown when the -response does not say it is an instant. D211 keeps a finite -`hr_recovery`, including zero and a negative number. D212 keeps the -current manual-session calculation rule. D213 stores the live -workout list and detail as originals. D214 is the live-read procedure. -D215 keeps each vendor object whole. An earlier draft +report routing. D237 corrects when the archive reads the database, and +the failed-init sentence. D238 stores a workout the person typed as a +workout session. D239 keeps a body skin-temperature time unknown when the +response does not say it is an instant. D240 keeps a finite +`hr_recovery`, including zero and a negative number. D241 keeps the +current manual-session calculation rule. D242 stores the live +workout list and detail as originals. D243 is the live-read procedure. +D244 keeps each vendor object whole. An earlier draft left day values, the heart-rate stream, summaries, and workout segments for a later version. That draft is superseded. File imports stay. The Garmin pull stays. A Junction pull is proposed as 2.3.0. Automatic sync, retries, token refresh, and backfill are proposed as @@ -338,13 +382,14 @@ is not `left_out`. Paging continues until `has_more` is false. The server still applies its own start bound, so a cycle that started before `--from` is not returned. That is the server's filter. -A page over 8 MiB is not mapped. On a cursor or offset read, the same +A page over the response cap, `MAX_PULL_RESPONSE_BYTES` (10 MiB), is not +mapped. On a cursor or offset read, the same cursor or the same offset is sent again with `limit` halved, down to 1. The discarded response writes nothing and does not advance the cursor or the offset. A transport failure is not retried. Day `limit` counts periods. A `limit` of 1 can still hold many rows, one for each source and series in that period. The server also floors that period count at 1. If the minimum -page is still over 8 MiB, the read is incomplete. The message names the +page is still over the cap, the read is incomplete. The message names the read and, for timeseries, the resolution. It does not name a series type, and it does not say one row was too large. Body and the personal record have no limit. An oversized response fails that read and names the read. @@ -397,8 +442,9 @@ Sleep, workout, meal, cycle, and health-score objects need a `id` that is a UUID string. Missing, null, blank, and any other shape refuse the protected page before a source, a row, or hardware changes. The row is not `left_out`. No empty or time-based id is invented. A valid neighbor on -that page is not stored. A later page of the same command still rolls -back only the failed page, and earlier committed pages stay. +that page is not stored. Each page of the command is its own preview and +apply, so only the failed page is refused, and earlier committed pages +stay. A new sensor is the prefix `ow1:` plus a JSON array. The array has no spaces. A missing part is JSON `null`. An empty string and the text `-` @@ -418,6 +464,8 @@ The array shapes are: - Measured series with `source: null`: `["unattributed", "timeseries"]`. A reported series does not use this sensor. - Archive originals: `["archive"]` - Personal record: `["personal_record"]` +- Vendor originals: `["vendor_workout", provider]`. `provider` is the + provider name in the route path, such as `garmin` or `suunto`. The writer is `source.provider` when that string is nonempty. A health score uses its top-level `provider` when that string is nonempty. The @@ -440,10 +488,10 @@ and, for a day row, `period_end`. A raw row at midnight and a day window that starts at that midnight are different keys. Two rows with one key are one normalized record only when the whole returned row is equal. A different value, in the same page or a later confirmed call, refuses the -protected transaction. The stored normalized row stays. The text says the +protected page. The stored normalized row stays. The text says the rows are ambiguous and a rerun cannot choose the normalized row. `ath -correct` remains the owner's way to replace that row. Preview -pages roll back, and the command memory holds device-binding facts only. +correct` remains the owner's way to replace that row. A preview page +writes nothing, and the command memory holds device-binding facts only. A preview therefore does not claim to see a null-source conflict from an earlier preview page. A confirmed `--yes` page does see an earlier committed page. @@ -460,9 +508,9 @@ appendix table, fails before any request. | Manual workout | `{ "workout": data }` | `source.provider` | not the device sensor | `workout_session` on the manual source, server id | same typed fields, zones, and segments as an automatic workout | | Unknown, null, or omitted `entry_source` | `{ "workout": data }` | `source.provider` | `ow1` event | `source_report` `unknown_workout`, server id | none. The original object is the record | | Measured raw series with `device_id` | timeseries object, `resolution` `raw` | `source.provider` | legacy device | the raw class in the appendix, D181 time key | none | -| Measured raw or day series, source present, no `device_id` | timeseries object | `source.provider` | legacy device, then the protected transaction is refused | no measured row. Section 2 may archive the original | none | +| Measured raw or day series, source present, no `device_id` | timeseries object | `source.provider` | legacy device, then the protected page is refused | no measured row. Section 2 may archive the original | none | | Reported series, source present or null | timeseries object | `source.provider`, or `open_wearables` when that string is missing | `ow1` report only | `source_report`, appendix subject | none. The amount is the reported pair | -| Measured series, `source` null | timeseries object | `open_wearables` | `ow1` unattributed only | the raw class, full match key | none. An unequal payload refuses the protected transaction and may be archived | +| Measured series, `source` null | timeseries object | `open_wearables` | `ow1` unattributed only | the raw class, full match key | none. An unequal payload refuses the protected page and may be archived | | Day series | timeseries object, `resolution` `1day` | same as the raw row | same as the raw row | window form in the appendix. Key adds `1day` and `period_end` | none | | Sleep, activity, or recovery summary | `{ "sleep_summary": data }`, `{ "activity_summary": data }`, or `{ "recovery_summary": data }` | `source.provider` | `ow1` summary | `source_report` subject `object`, date | one measured child per numeric field, field path in the key | | Body | the object | umbrella `source.provider`, or `open_wearables` when it is missing | `ow1` summary, family `body` | `source_report` subject `object` | slow-changing weight, height, fat, and muscle are time-unknown provider summaries; averaged heart rate and HRV use the server window; body temperature and blood pressure use their own times; skin temperature is time-unknown; age and BMI are source reports | @@ -470,15 +518,15 @@ appendix table, fails before any request. | Meal | `{ "meal": data }` | `source.provider` | `ow1` event | `source_report` subject `object`, meal id | one `source_report` per numeric field path | | Cycle | `{ "cycle": data }` | `source.provider` | `ow1` event | `source_report` subject `object`, cycle id | one `source_report` per numeric reported length | | Personal record | the object after `user_id` is removed | `open_wearables` | `ow1` personal | `source_report` subject `personal_record` | none | -| Vendor workout | one combined list and detail object | `open_wearables` | `ow1:["vendor_workout", provider]` | `source_report` subject `vendor_workout`, key is provider plus vendor id | none. The whole vendor object is the record | +| Vendor workout | the vendor envelope in the vendor section below | `open_wearables` | `ow1:["vendor_workout", provider]` | `source_report` kind `original`, subject `vendor_workout`. The key ends with the provider and the vendor id | none. The whole envelope is the record | `source_report` is not one of the seven measured record types in SPEC section 5.4. It has a source, so it is not an athlete report and it is not a nutrition entry. Nutrition entries have no source. D161 still says a mapping cannot turn a personal report into a measured record. A source -report stores that report without making it a measurement. The eight range calculations and -`provider-period-summary` do not read it. Step 5 creates the -`source_reports` table. Value and unit are both present or both absent. +report stores that report without making it a measurement. The eight +range calculations in `src/calculate/range.rs`, `provider-period-summary` +among them, do not read it. Step 6 creates the `source_reports` table. Value and unit are both present or both absent. `report_kind` is one of `intake`, `account`, `predicted`, `code`, `text`, `unknown_workout`, `index`, or `original`. Gender uses `account`. It is not copied into `sex` or the athlete profile. The @@ -493,7 +541,12 @@ One source report has this JSON shape. Extra fields are refused. "subject": "hydration", "provider_record_id": "optional server id", "reported_at": "optional UTC timestamp", - "input_timestamp": { "timestamp_text": "the server timestamp" }, + "input_timestamp": { + "timestamp_text": "the server timestamp, as sent", + "utc_offset_text": "the offset at the end of that text", + "utc_offset_meaning": "meaning_not_documented", + "timestamp_basis": "source_offset_timestamp" + }, "provider_reporting_periods": [], "amount": { "input_value": 250, @@ -502,7 +555,7 @@ One source report has this JSON shape. Extra fields are refused. "standard_unit": "mL" }, "received_at": "when this program first stored it", - "received_at_basis": "provider_import", + "received_at_basis": "import_time", "supplied_fields": {} } ``` @@ -512,10 +565,16 @@ standard fields are present. It is a reported pair. It is not a measured `SourceValue`, and `field_basis` is absent. A day report omits `reported_at` and uses `open_wearables_reporting_window` for the server's timestamp and `period_end`. Kind `original` omits `amount` and omits -reporting periods. `input_timestamp` is either a timestamp text or -`timestamp_missing_reason`. The record is registered on `RecordType`, the -current and revision unions, the package schema, `typedTables`, repair, -and the root SQL check. It is not added to the seven measured types or to +reporting periods. `input_timestamp` is the receipt that `input_receipt` +in `src/import/mapping.rs` writes for a timestamp text. A `Z` text is +`source_instant` with `documented_recording_offset`. Any other offset is +`source_offset_timestamp` with `meaning_not_documented`. When the server +gave no time, it is `missing_timestamp_receipt` in +`src/import/candidate.rs`. `received_at_basis` is `import_time`, as every +2.1.1 mapped import writes. A vendor original's start follows the rule in +the vendor section below. The record is registered on `RecordType`, the +current and revision unions, the package schema, the table description in +`src/store/encode.rs`, repair, and the root SQL check. It is not added to the seven measured types or to the point, sample, or session readers. Match keys for the new records are the writer, the sensor, the resource, @@ -665,50 +724,62 @@ both absent. The record id, the revisions, and the first `received_at` stay. D182 copies the stored `received_at` onto the new revision. `became_known_at` is when that revision was written. A later number returns on the same child. A range that does not return the object does -not withdraw its children. A refused page rolls the withdrawals back -with the page. - -A protected refusal rolls that transaction back. It does not become a -successful pull. The archive is pull-only. `ath import --mapping` uses -the same protected envelopes and the same refusal, and it does not start -the archive transaction. A refused file import keeps no original. - -Before either transaction, the pull checks the page itself. The order of -the rows does not matter. The privacy scan is first. A hit starts -neither transaction. A missing or malformed required UUID, a supplied +not withdraw its children. A refused page writes nothing, so its +withdrawals are not written either. + +A page is one 2.1.1 import. `preview_route` in `src/import/provider.rs` +stages the page and matches it against the database in one read +transaction, at one database revision. It writes nothing. With `--yes`, +`ProviderPreview::apply` writes that plan in one write transaction. The +apply refuses the plan when the database revision moved after the +preview, when a corrected record's revision moved, or when a match key +now names another record. A protected refusal is found by the preview, +so the page is not applied. It does not become a successful pull. The +archive is pull-only. `ath import --mapping` uses the same protected +envelopes and the same refusal, and it does not build an archive. A +refused file import keeps no original. + +Before the preview, the pull checks the page itself. The order of +the rows does not matter. The privacy scan is first. A hit builds +no preview. A missing or malformed required UUID, a supplied field whose name is not allowed, and any other decoded-field failure are the same kind of check. They use the returned JSON. They do not use the -database. One such failure starts neither transaction. A timeseries row +database. One such failure builds no preview. A timeseries row has no required UUID. A query-bucket `left_out` row is not one of these failures, and it is not archived. -The database facts are read later, inside the protected -`BEGIN IMMEDIATE`, before any insert, update, or delete. The read covers -every row on the page, including a row the mapping would leave out. For -each named source it reads the receipt, the binding, deletion, and -history, and history includes tombstones. For each named record and -import key it reads deletion, the current revision, and, for a workout, -the stored kind. For each null-source full key it reads the stored -payload. That set of facts is the safety snapshot. An unlocked read -taken before this transaction is not the snapshot. - -One database veto anywhere in that snapshot refuses the protected page -before any mutation. The vetoes are a conflicting device id, a deleted -source, unbound history, a malformed receipt, a workout kind that -differs from the stored record, and a deleted record or import key the -page would copy. A deleted-source row that the mapping would leave out -is still a veto. The protected transaction rolls back. The archive is -not attempted. The veto stands even when an earlier unlocked read saw -no veto. A missing device id on a timeseries row is not this veto. - -The archive is allowed only when that snapshot has no veto and it has -one of these eligible facts: a device-targeted series row whose source -has no device id, or a null-source series row, measured or reported, -whose full match key has a different payload in this page or already -stored. An eligible row does not authorize the archive when a veto is -also on the page. A confirmed command keeps this snapshot for the -archive transaction. It does not keep a lock after the protected -rollback. A preview discards the snapshot with that rollback. +The database facts are read in the page's matching step, inside the read +transaction above. The read covers every row on the page, including a row +the mapping would leave out. For each named source it reads the receipt, +the binding, deletion, and history, and history includes tombstones. For +each named record and import key it reads deletion, the current revision, +and, for a workout, the stored kind. For each null-source full key it +reads the stored payload. That set of facts is the safety snapshot. It +belongs to the database revision the preview read. The apply refuses a +moved revision, so a page is never written against facts it did not read. + +One database veto anywhere in that snapshot refuses the protected page. +The vetoes are a conflicting device id, unbound history, a malformed +receipt, and a workout kind that differs from the stored record. The +archive is not attempted after a veto. A missing device id on a +timeseries row is not this veto. + +A deleted source or a deleted record is not a veto. A row whose source the +person deleted is left out, and the line says so (D190). A row whose +match key names a record the person deleted is left out, and the line +says so (D182). The rest of the page is written. These are the 2.1.1 +keyed-import rules, and a deleted row is never recreated. A deleted source +or a deleted record named anywhere on the page still forbids the archive +of that page. + +The archive is allowed only when that snapshot has no veto, names no +deleted source or record, and has one of these eligible facts: a +device-targeted series row whose source has no device id, or a +null-source series row, measured or reported, whose full match key has a +different payload in this page or already stored. An eligible row does not +authorize the archive when a veto is also on the page. A confirmed command +keeps the snapshot's database revision for the archive. A preview never +applies an archive. When the archive revalidation below matches the safety snapshot, the archive stores one capsule per returned series row on that page, not a @@ -733,35 +804,43 @@ canonical capsule, with keys sorted and no extra whitespace. The same capsule is one record. A raw capsule and a day capsule are different even when the row bodies match. The hash is not a sample id. This plan does not claim that two different capsules cannot hash equal. If the key -is already stored and the stored capsule differs, the archive transaction -fails before any insert and does not revise the old capsule. +is already stored and the stored capsule differs, the archive fails before +it writes and does not revise the old capsule. The archive source uses writer `open_wearables`, sensor `ow1:["archive"]`, and `source_type` `connector`. The receipt operations are not called, and `device_binding` is not written. -The archive transaction starts with its own `BEGIN IMMEDIATE`, after the -protected rollback. The re-read and any archive writes are that same -transaction, so another writer cannot commit between them. Before it -inserts a source or a capsule, it reads -the same safety facts again, including a `left_out` neighbor. It also -reads the archive source and each target capsule, including a tombstone. -It compares those facts with the safety snapshot. A new veto, a -different binding, a new or missing history row, a source or record -tombstone, or a different safety revision means the snapshot is stale. -`archive` is then `not_attempted`. The transaction rolls back with no -writes. The fetched payload is not stored under the archive source, and -it is not given a new identity. A deleted archive source is not -recreated. A deleted capsule is not replaced. If the pull cannot name -this bounded set for a row, it does not archive the page. There is no -retry. A page that committed an archive still sees that archive. A -deletion after this archive commits is a later command. +The archive is its own preview and apply, after the protected refusal. Its +preview stages one capsule per returned series row. It matches them +against the archive source and each target capsule, including a deleted +one. It goes ahead only when its database revision is still the one the +protected preview read. Otherwise `archive` is `not_attempted` and nothing +is written. Its apply refuses a moved revision, as every 2.1.1 apply does, +and `archive` is then `not_attempted` too. + +The archive does not read the safety facts a second time. Every write to a +database moves its revision: `Store::apply` in `src/store/write.rs`, +`ProviderPreview::apply`, repair in `src/store/repair.rs`, restore in +`src/package/restore.rs`, and erase in `src/package/erase.rs` all advance +it. So an unchanged revision means the binding, the history, the +tombstones, and the vetoes are the ones the protected preview read. The +fetched payload is not stored under the archive source, and it is not +given a new identity. + +A deleted archive source leaves every capsule out and is not recreated +(D190). A deleted capsule is left out and is not replaced (D182). The +archive refuses its own plan when that plan would revise a stored capsule, +so a stored capsule is never revised. If the pull cannot name this bounded +set for a row, it does not archive the page. There is no retry. A page that +committed an archive still sees that archive. A deletion after this archive +commits is a later command. `protected_write` is `committed` or `refused`. `archive` is `not_attempted`, `stored`, `unchanged`, or `failed`. `committed` is the protected counts. `archive_committed` is the archive counts. A record is not in both. `written` follows section 1 and is not set by the archive -alone. `database_changed` is true when this command's archive transaction +alone. `database_changed` is true when this command's archive apply committed a new source or a new capsule, and it stays true if an earlier page already changed the database. A later refusal does not clear the earlier counts. When the archive stores N new capsules and the command @@ -773,7 +852,7 @@ unchanged only when no earlier page changed it. The unchanged text is incomplete.` After an earlier change it is `Protected write refused; 0 originals archived; database changed; pull incomplete.` A third payload adds its own new count and does not replace the earlier capsule. If the -archive transaction fails, it rolls back entirely, `archive` is `failed`, +archive apply fails, its transaction writes nothing, `archive` is `failed`, the protected refusal remains, earlier commits remain, the success sentence is not printed, and the exit is nonzero. The text is `Protected write refused; archive failed; database unchanged; pull incomplete.` @@ -782,17 +861,16 @@ partial archive count. When the archive is `not_attempted` after a protected refusal, the text is `Protected write refused; archive not attempted; database unchanged; pull incomplete.` After an earlier change it says `database changed`. That result adds no archive count. A -preview, including `--json` and `--json --yes`, rolls the protected -transaction back and does not start the archive transaction. -`estimated_archive` comes from that rolled-back read and is labeled -estimated. +preview, including `--json` and `--json --yes`, applies neither the +protected plan nor the archive. `estimated_archive` comes from the +archive's own preview and is labeled estimated. A page of only reported series, with no device id, is an ordinary source report write. It is not an archive, and it does not refuse the device check. A normalized row is not revised from an archive. A provider summary or provider score may omit `value` only together with -its unit. One without the other is refused. Step 5 rebuilds both typed +its unit. One without the other is refused. Step 6 rebuilds both typed tables so the pair can be null, copies every existing row, and keeps record ids, `data_json`, import keys, revisions, tombstones, and reporting periods. Scale on a provider score stays required. No number is invented. @@ -814,114 +892,347 @@ The following are not requested. Each line is the reason. `/sync/historical` are not called. The connections list is called only when `--vendor-workouts` is on. +### Live vendor workouts + `--vendor-workouts` is off by default. Off, the command makes no request to `/api/v1/users/{user_id}/connections` and no request to either live workout route. Preview and `--json` without the flag make those zero requests. On, the same preview and `--json` do make them, write nothing -in this database, and print `vendor requests were made`. +in this database, and print `vendor requests were made`. "Nothing stored" +and "nothing written" always mean this database. The server can still +change, as the next paragraph says. A live call can change the server. `api_client.py` at the pinned commit can refresh a vendor token and save it, revoke a connection when refresh is missing or auth has failed for a day, and emit `connection.revoked`. It writes the Redis keys `token_refresh_lock` and `provider_auth_failing_since`. On HTTP 429 it sleeps 15, then 30, then 60 -seconds, up to three retries. This pull does not add its own retry. It -does not add a vendor token or a new scope. The server may still do the -work above while answering the GET. - -With the flag on, the pull reads connections first. It then calls only a -connected provider whose live list method exists. The order is fixed: -Garmin, Polar, Suunto, Whoop, Fitbit, Oura, Strava, Withings, Sensorbio. -A provider that is not connected, and a connected provider with no live -list method, is `not_attempted`. That is not a failure. One provider's -failure leaves its line `incomplete` and the other providers still run. -Apple, Samsung, Health Connect, Ultrahuman, and Google Health have no -live list method. Their stored workouts still come from `/events/workouts`. - -The list and the detail for one vendor id are combined in memory. The -command writes that one original once. A second pull of the same object -reports the original unchanged and does not change the database for that -row. A failed detail keeps the list object, marks that detail incomplete, -and still writes the list object when no richer original is already -stored. A later payload that lacks a samples, zones, or route array the -stored original already has is not written. The richer original stays. +seconds, up to three retries, so one request can wait about 105 seconds. +This pull does not add its own retry. It does not add a vendor token or a +new scope. The server may still do the work above while answering the GET. + +Every run with the flag says this in three sentences, before its first +live request. The server may refresh and save vendor tokens. It may revoke +a connection. It may wait about 105 seconds on a rate limit. A preview and +a `--yes` run print the sentences. A `--json` run puts them in +`vendor_workouts.notice`, so its output stays one JSON value. The flag's +help text says the same. + +With the flag on, the pull reads the connections list first. It checks +that each item's `user_id` is the selected user. Any other value refuses +the list, because it is not this user's list. The pull then keeps only +`provider` and `status` from each item and drops every other field, +including `linked_user_ids`, which holds other users' ids. The list is +never stored. Nothing from it is printed except a provider name from the +table below and a status. So the privacy scan in section 4 does not run on +this list, and the selected user id inside it does not refuse it. A +refused list makes every provider `not_attempted`, and the vendor read is +`incomplete`. + +A provider is called only when its item has `status` `active`. The +pinned `ConnectionStatus` also has `revoked` and `expired`. Those +providers are `not_attempted`, and their line shows that status. They are +never called, because a call could make the server try a refresh or a +revoke. A provider with no item is `not_attempted`, and its status is +`null`. A status the pin does not define is not active, and it is printed +as `unknown status`. + +The order is fixed: Garmin, Polar, Suunto, Whoop, Fitbit, Oura, Strava, +Withings, Sensorbio. An active provider with no live list method is +`not_attempted`. That is not a failure. One provider's failure leaves its +line `incomplete`, and the other providers still run. Apple, Samsung, +Health Connect, Ultrahuman, and Google Health have no live list method. +Their stored workouts still come from `/events/workouts`. + +Live requests go one at a time. Each starts at least one second after the +previous live request started. The connect timeout is 30 seconds. The read +timeout is 360 seconds. The server's own provider timeout, +`provider_request_timeout_seconds`, defaults to 30 seconds. So one GET can +take four attempts and three waits, about 225 seconds, plus any token +refresh under the server's lock. The longer read timeout lets the server +finish those retries first. If a live request still times out, the server +may still be working on it. The pull then sends no other request to that +provider in this command, so two requests to one provider never overlap. +That provider is `incomplete`. The next provider still runs, and it uses +a different vendor account and limit. A server whose provider timeout is +raised can outlast this timeout. The same rule covers that case. The +stored reads keep 30 seconds to connect and 120 seconds to read, the values +`src/runtime/garmin_pull.rs` uses. + +Budgets keep one command inside the providers' limits: + +- The pace above keeps this command at 60 live requests a minute or + fewer. The review cited about 100 a minute for Garmin. This study did + not find that number in Garmin's public docs. +- Garmin is read in windows of 86,400 seconds or less, one call each. + Every window is sent. A one-year range is 365 windows, so it takes at + least six minutes before any detail call. +- A command makes at most 100 detail calls to one provider, and at most 20 + to Strava. Ids past the budget are `deferred`. The next paragraphs say + which ids go first. +- Strava's limit is per application, so the deployment's own sync shares + it. Strava's rate-limit page, fetched 15 November 2026, gives a default + of 100 read requests per 15 minutes and 1,000 a day. Strava calls them + non-upload requests. One list call and 20 detail calls can become 84 + requests when the server retries each one three times. That leaves 16 + for the deployment's own sync in the same 15 minutes. The Strava line + says that its limit is shared. + +The routes are +`GET /api/v1/providers/{provider}/users/{user_id}/workouts` and +`GET /api/v1/providers/{provider}/users/{user_id}/workouts/{workout_id}`. +At the pinned commit both return the provider's raw response. The server +does not reshape it. The table below is the whole provider logic. Every +live request has the 30-second connect timeout and the 360-second read +timeout above. + +| Provider | List unwrap | Id | Start | Detail key | Detail unwrap | Detail fields | Budget | Read timeout | +|---|---|---|---|---|---|---|---|---| +| Garmin | the JSON array | `activityId` | `startTimeInSeconds`, Unix seconds | `activityId` | the object | none named | every window; 100 details | 360 s | +| Polar | the JSON array | `id` | `start_time`, text with no offset | `id` | the object | `samples`, `zones`, `route` | 1 list; 100 details | 360 s | +| Suunto | `payload` | `workoutId` | `startTime`, Unix milliseconds | `workoutKey`, else `workoutId` | `payload` | none named | list pages of 100; 100 details | 360 s | +| Whoop | `records` | `id` | `start`, text with offset | `id` | the object | none named | 1 list; 100 details | 360 s | +| Fitbit | the JSON array. The method reads `activities` | `logId` | `startTime`, text with offset | no detail call | none | none | 1 list | 360 s | +| Oura | `data` | `id` | `start_datetime`, text with offset | `id` | the object | none named | 1 list; 100 details | 360 s | +| Strava | the JSON array | `id` | `start_date`, text with `Z` | `id` | the object | `laps`, `splits_metric`, `splits_standard`, `segment_efforts`, `best_efforts`, `map` | 1 list; 20 details | 360 s | +| Withings | the JSON array. The method reads `series` | `id` | `startdate`, Unix seconds | no detail call | none | none | 1 list | 360 s | +| Sensorbio | `data[].activities[]`. The parent is kept as `list_parent` | `id` on the nested activity | `start_time`, Unix milliseconds | no detail call | none | none | 1 list | 360 s | + +- Garmin. The pull splits the range into windows and sends + `summary_start_time` and `summary_end_time` as integer Unix seconds. The + server puts those values in `uploadStartTimeInSeconds` and + `uploadEndTimeInSeconds`, so a window selects by upload time, not by + start. A window longer than 24 hours is never sent, because the pinned + server then splits it itself and drops a failed piece without saying so. + A failed window makes Garmin `incomplete`, and later windows still run. + The pinned code calls detail at + `/wellness-api/rest/activities/{activity_id}`. This study did not find + that path in Garmin's public docs. A failed Garmin detail is counted as + `failed`, like any other. +- Polar. The list sends `samples`, `zones`, and `route` false, the route's + default, so the list stays small. Detail sends all three true. A list + over the response cap fails that list, because the route has no smaller + page. +- Suunto. The list sends `since` as the requested start in Unix + milliseconds, `filter_by_modification_time=false`, and `limit` 100, and + pages `offset` until a short page. False means creation time. A page + over the response cap is asked again with a smaller `limit`, down to 1. + The record key is `workoutId`. Detail is called at `workoutKey` when the + list object has one, and at `workoutId` otherwise. Detail unwraps + `payload`. A detail matches when its `workoutId` or its `workoutKey` + equals the list object's. The pinned `WorkoutJSON` model has no + `workoutKey`. The pinned tests and Suunto's own API use it, so the list + object may carry it. Detail sends no `extensions` parameter. +- Whoop. One call. The method caps `limit` at 25. The response's + next-page field is `next_token`. The request parameter is `nextToken`, + and the route does not send it. `more` is true when the response has + `next_token`. +- Oura. One call with no date and no `next_token`. `more` is true when the + response has `next_token`. +- Strava. One list call at page 1. `per_page` is the server setting + `strava_events_per_page`, default 200. `more` is true when the page + length equals `per_page`. The detail object also carries `embed_token`. + Section 4 withholds that value. +- Fitbit. The list uses the last 30 days when the route sends no dates. + Detail is not implemented and is not called. +- Withings. The list uses `pull_sync_lookback` or 30 days, widens each + edge by one local day, and pages inside the method. Detail is not called. +- Sensorbio. The method sends `last-timestamp` 0 and `limit` at most 50, + and it does not follow `links.next`. So it reads only the oldest 50 + entries. `more` is true when `links.next` is present. Detail is not + called. Each nested activity is one object. Its parent entry, without + the `activities` array, is kept beside it as `list_parent`, so the + parent's `timestamp` and `name` are not lost. Every returned original is stored, including one whose start is outside `--from` and `--to`. The same rule is used for every provider. The count is `vendor workout originals`. `range_complete` uses only the stored ranged reads. Each live line names its limit, says whether that limit -covers the requested range, and sets `more` when the response shows -another page. Whoop sets `more` when `next_token` is present. Oura sets -`more` when `next_token` is present. Sensorbio sets `more` when -`links.next` is present. Strava sets `more` when the page length equals -`per_page`. Those tokens are not followed. The published route does not -accept them as the next request. `covers_requested_range` is false for -every provider in this pin. None of the live methods filter by the -workout's start inside `--from` and `--to`. +covers the requested range, and sets `more` as the notes above say. Those +next-page values are not followed. The published route does not accept +them as the next request. `covers_requested_range` is false for every +provider in this pin. None of the live methods filter by the workout's +start inside `--from` and `--to`. + +The pull converts the range once for Garmin and Suunto, because their +parameters are numbers. A date `--from` is midnight UTC that day. A date +`--to` ends at midnight UTC after that day. That is the rule the Open +Wearables API introduction gives for a date-only bound. A timestamp bound +converts exactly. A fraction of a second rounds down for the start and up +for the end, so the windows cover the whole range. The stored reads still +send `--from` and `--to` unchanged. + +A vendor id is text. A JSON string is used as it is, unless it is empty. +A JSON integer is written in decimal. So `123` and `"123"` are one id and +one record. An integer above 9007199254740991 is refused. D213 stores every +number the way JavaScript does, so its digits would change. Any other +number, and any other JSON type, is refused as an id. An object that holds +an integer above that size anywhere inside it is refused for the same +reason. A refused object refuses only itself, and the count says why. Two +different objects with one id in one provider's response refuse both, +because the pull cannot tell which is right. Two equal objects are one. + +The start column names one field and how to read it: + +- Text with an offset or `Z`. The receipt is the one `input_receipt` in + `src/import/mapping.rs` writes. `reported_at` is that instant in UTC. +- Text with no offset, such as Polar's `start_time`. The receipt is + `offset_timestamp_receipt` in `src/import/candidate.rs` with + `meaning_not_documented`. It keeps the text and says the source gave no + offset. There is no `reported_at`. Polar's separate + `start_time_utc_offset` stays in `list`. This pull does not join the two. +- Unix seconds or milliseconds. The receipt keeps the digits as + `timestamp_text`, with `timestamp_basis` `source_instant` and + `utc_offset_missing_reason` `not_applicable`. `reported_at` is that + instant in UTC, with milliseconds. A new helper beside + `offset_timestamp_receipt` writes this receipt. It passes the 2.1.1 + receipt checks: a text has a basis, and the missing offset has a reason. +- Missing, or any other value. The receipt is `missing_timestamp_receipt`. + There is no `reported_at`. + +The start is stored and is not a filter. + +For each listed id, the pull first reads the stored original, if there is +one. That read is crate-private and lives in `src/import/provider.rs`. It +returns whether the original exists, whether it is deleted, whether it +holds a detail, and its stored `list`. + +The pull calls detail only when the provider has a detail call and its +budget allows. It spends the budget in this order. First come ids with no +stored detail. Then come ids whose list object differs from the stored +`list`. Inside each group the oldest start goes first. An id without a +start instant goes last, in list order. An id whose original holds a +detail and whose list object is unchanged gets no detail call. A deleted +original gets no detail call. A detail is fetched again only when the list +object changed. A provider that changes a detail without changing the +list object is not seen, and the line does not claim it. + +The detail must name the same id. A detail that names another id is a +`mismatch`, and it is not stored. + +What is written for one id depends on what this command got: + +- A new detail that is not thinner than the stored one. The original is + written with this list object and this detail. The id counts as + `stored`. +- A new detail that is thinner. Nothing is written for that id, and the + stored original stays. The id counts as `thinner`. A detail is thinner + when one of the provider's detail fields in the table is a nonempty value + in the stored detail and is missing, null, or empty in the new one. A + provider with no named detail field has no thinner detail. +- No new detail call, because the stored detail is current. The pull sends + the envelope with the stored detail, so the original counts as + `unchanged` and nothing is written. The id counts as `kept`. +- No new detail, and none stored. The original is written with the list + object alone. `detail_status` says why: `deferred`, `failed`, + `mismatch`, or `not_available`. The id counts under the same word. +- No new detail, but one is stored, and the list object changed. Nothing + is written for that id, and no revision is added. The stored detail + stays. The id counts as `deferred`, `failed`, or `mismatch`. + +A list-only object therefore never replaces a stored detail. A `failed` +or `mismatch` detail makes the provider `incomplete`, and the exit is +nonzero. A `deferred` detail leaves the provider `completed`, with the +deferred count on its line, and the next command details those ids first. +A deferred id that the provider stops listing is never detailed by a later +command. The deferred count shows how many are waiting. + +Each original is one envelope. The pull builds it, and a saved file holds +the same object: -The routes are -`GET /api/v1/providers/{provider}/users/{user_id}/workouts` and -`GET /api/v1/providers/{provider}/users/{user_id}/workouts/{workout_id}`. -The original is a `source_report` of kind `original`, subject -`vendor_workout`, writer `open_wearables`, sensor -`ow1:["vendor_workout", provider]`. The key is the provider name plus the -vendor id. The start field is stored and is not a filter. A missing id -refuses that one object and does not archive it. The other objects from -that provider are still stored. The original is not a workout session. -The stored session stays matched by the Open Wearables workout id. The -public stored workout has no `external_id`, so the two records are not -joined by time, distance, or device. A device id inside the vendor object -does not set `device_binding`. Nested samples stay inside the original. -The eight range calculations do not read it. - -| Provider | List unwrap | Id | Start field | -|---|---|---|---| -| Polar | the JSON array | `id` | `start_time` | -| Garmin | the JSON array | `activityId` | `startTimeInSeconds` | -| Suunto | `payload` | `workoutId` on the list. Detail may name the same value `workoutKey`. A different `workoutKey` is a mismatch and that detail is not stored | `startTime` | -| Whoop | `records` | `id` | `start` | -| Oura | `data` | `id` | `start_datetime` | -| Strava | the JSON array | `id` | `start_date` | -| Fitbit | the JSON array. The method reads `activities` and returns the rows | `logId` | `startTime` | -| Withings | the JSON array. The method reads `series` and returns the rows | `id` | `startdate` | -| Sensorbio | `data[].activities[]` | `id` on the nested activity | `start_time` | - -- Polar's list omits `samples`, `zones`, and `route`, so the route sends - false and the list stays under the 8 MiB cap when it can. Detail sends - all three true, one call per exercise id. A list over 8 MiB fails that - list. Detail is also called for Suunto, Whoop, and Oura. It is not - called for Fitbit, Withings, or Sensorbio. A provider with no detail - stores the list object alone. -- Garmin is split by this program into windows of 24 hours or less, one - call each. A longer window is not sent. Each call sends - `summary_start_time` and `summary_end_time`. The server puts those - values in `uploadStartTimeInSeconds` and `uploadEndTimeInSeconds`. The - read timeout for each window is 120 seconds. Any failed window makes - Garmin `incomplete`. A later window still runs. The server's own - provider timeout is a separate setting. Its default is 30 seconds. - Detail is called for each stored id. -- Suunto sends `since` as the requested start in Unix milliseconds, - `filter_by_modification_time=false`, `limit` 100, and pages `offset` - until a short page. False means creation time. Detail sends no - `extensions` parameter. A page over 8 MiB is asked again with a smaller - `limit`, down to 1. -- Whoop is one call. The method caps `limit` at 25 and sends no - `nextToken`. Oura is one call with no date and no `next_token`. Strava - is one list call at page 1. The method's `per_page` default is 200. -- Strava detail calls stop at 20 per command. The server can retry one - call three times, so 20 calls can become 80 provider requests. That - stays under 100 per 15 minutes, and under the 200 per 15 minutes on the - pinned Strava page. Ids past the budget are `deferred`. Their list - objects are stored. The detail is not called. -- Fitbit's list uses the last 30 days when the route sends no dates. - Detail is not implemented and is not called. Withings uses - `pull_sync_lookback` or 30 days, widens each edge by one local day, and - pages inside the method. Detail is not called. Sensorbio uses `limit` - 50 and `last-timestamp` 0. Detail is not called. - -A saved file imports the same envelope. Export and import keep one -original id. The per-provider unwrap lives in -`src/runtime/vendor_workouts.rs`, driven by one provider table. +```json +{ + "provider": "suunto", + "vendor_id": "1001", + "start": 1767254400000, + "start_kind": "unix_milliseconds", + "list": { "workoutId": 1001, "workoutKey": "abc", "startTime": 1767254400000 }, + "detail": { "workoutId": 1001, "workoutKey": "abc", "startTime": 1767254400000 }, + "detail_status": "stored" +} +``` + +- `provider` is the provider name in the route path. +- `vendor_id` is the id from the table's id column, as text. +- `start` is the value at the table's start column, copied unchanged. It + is absent when the object has none. `start_kind` is `text`, + `unix_seconds`, or `unix_milliseconds`, from the table. It is absent + when `start` is. +- `list` is the list object. `list_parent` is present only for Sensorbio. +- `detail` is the detail object after the table's detail unwrap. It is + absent when no detail is stored. +- `detail_status` is `stored`, `deferred`, `failed`, `mismatch`, or + `not_available`. +- A value that section 4 withholds is replaced in place by its marker. + Nothing else in `list`, `list_parent`, or `detail` is changed. + +The record is a `source_report` of kind `original` and subject +`vendor_workout`. Its writer is `open_wearables`, its sensor is +`ow1:["vendor_workout", provider]`, and its `source_type` is `connector`. +`provider_record_id` is `vendor_id`. `input_timestamp` and `reported_at` +follow the start rule above. `received_at_basis` is `import_time`. The +whole envelope is kept in `supplied_fields`, including the fields the +mapping reads. The match key is the writer, the sensor, the resource +`vendor_workout`, the provider, and the vendor id, escaped by D181. So the +Suunto record in section 7 has a key that ends `suunto|1001`. + +The pull writes one provider's originals as one page, after that +provider's list and detail calls finish. The page is one preview at one +database revision. With `--yes` and without `--json`, it is then one +`ProviderPreview::apply`, which refuses a moved revision as every 2.1.1 +apply does. A stored page and an archive never hold a vendor original, and +a vendor original is never a capsule. A vendor page that fails or is +refused leaves that provider `incomplete`. It does not change a stored +page or an archive in the same command, and a refused stored page does not +change the vendor page. + +The vendor page uses the 2.1.1 keyed rules. If the person deleted an +original, a later pull leaves that object out, says so on its line, and +does not recreate it (D182). That happens on every later pull. If the +person deleted a provider's `vendor_workout` source, every object from +that provider is left out (D190). If the person corrected an original with +`ath correct`, a later pull whose envelope differs adds a revision with +the server's envelope, because a mapped import replaces the whole object +(D182). The person's revision stays in the history. A pull whose envelope +equals the current record adds nothing. To keep a pull from changing an +original, the person deletes it. + +Each provider's line, and its object in `--json`, counts: + +- `originals`: new, changed, and unchanged records. +- `details`: `stored`, `kept`, `deferred`, `failed`, `mismatch`, + `thinner`, and `not_available`. +- `left_out`: objects not written, by reason: `missing_id`, + `unusable_id`, `unsafe_number`, `duplicate_id`, `deleted_record`, + `deleted_source`, and `response_refused`. +- `withheld`: values that section 4 withheld, with up to 20 paths. + +Each listed object is in exactly one detail count or one left-out count. +A list response that fails or that the privacy scan refuses stores nothing +from that response. Its objects count as `response_refused` when they +could be read, and the provider is `incomplete`. + +The original is not a workout session. The stored session stays matched +by the Open Wearables workout id. The public stored workout has no +`external_id`, so the two records are not joined by time, distance, or +device. A device id inside the vendor object does not set +`device_binding`. Nested samples stay inside the original. The eight +range calculations do not read it. + +The rewritten `mappings/open-wearables.md` gains a section named +`vendor_workout`. It declares the record type `source_report`, kind +`original`, and subject `vendor_workout`. It names the writer +`open_wearables`, the sensor from `provider`, the key from `provider` and +`vendor_id`, and the start from `start` and `start_kind`. It keeps the +whole envelope in `supplied_fields`. A saved file of envelopes, under +`vendor_workout`, imports through that section with `ath import --mapping +open-wearables`. File import does not apply the detail rules above. It +writes each envelope as the file holds it, as D182 does for every mapped +import. Export and import keep one original id. + +The provider table, the detail rules, and the thinner check live in +`src/runtime/vendor_workouts.rs`. They run before the mapping engine sees +an envelope, so the mapping engine has no vendor exception. `open_wearables.rs` calls that module. It does not grow a provider branch. Day rows are one selected row per source, series, and local day. The @@ -948,15 +1259,17 @@ Body passes the object. JSON `null` is not mapped. The personal record passes the object after `user_id` is removed. Pagination and health-score `metadata` are not records. -Everything after that is the mapping engine from 2.1.0: match keys (D181), -replace on change (D182), source and device (D183), one transaction per call -(D189), a deleted source left out (D190), and field names refused when they -are empty or `__proto__` (D191). A Garmin file import remains a different -`data_route`, so both copies of one workout stay (D161). A second pull of the -same Open Wearables object, or an `ath import --mapping open-wearables` of a -saved copy of that object, keeps the same rows. An identical vendor -original changes no row. A changed object replaces the stored one, except -a thinner vendor workout, which section 2 refuses. +Everything after that is the mapping engine that 2.1.1 carries over from +2.1.0: match keys (D181), replace on change (D182), source and device +(D183), one write transaction per page (D189), a deleted source left out +(D190), and field names refused when they are empty or `__proto__` (D191). +A Garmin file import remains a different `data_route`, so both copies of +one workout stay (D161). A second pull of the same Open Wearables object, +or an `ath import --mapping open-wearables` of a saved copy of that object, +keeps the same rows. An identical vendor original changes no row. A +changed object replaces the stored one. The mapping engine has no vendor +exception. Section 2's detail rules decide which vendor envelopes reach +it. On a device source, the writer is `source.provider`. The sensor string is `source.device_type`, `source.device`, and `source.source`. Section 2's @@ -992,12 +1305,15 @@ are one record. The sensor join uses `|`, so a `device_id` that contains the join is encoded. That identity change is not this proposal. Old rows are not rewritten, moved, or deleted. -Both `ath import --mapping` and `ath pull` call `MappedReader`. The check -lives there, for route `open_wearables` only, inside the same transaction -as the write and before `insert_group` changes a device source or a -timeseries record on that source. Summary, event, score, and unattributed -sensors do not enter it. Other routes are not checked. A pull-only check would -leave import-after-pull able to replace the point. The check reads every +Both `ath import --mapping` and `ath pull` go through `preview_route` and +`ProviderPreview::apply` in `src/import/provider.rs`. The check lives in the +matching step there, for route `open_wearables` only. It reads its facts in +the read transaction, at the preview's database revision, and decides +before a staged plan can change a device source or a timeseries record on +that source. The apply refuses a moved revision, so the write sees the +facts the check read. Summary, event, score, and unattributed sensors do +not enter it. Other routes are not checked. A pull-only check would leave +import-after-pull able to replace the point. The check reads every accepted row, including a row after the first source device. The receipt is the source object's own key `device_binding`. The 2.2.0 @@ -1066,33 +1382,37 @@ The call is one of these states: `source.device_id` store that string on the source in the same transaction as the first accepted write. That source may be created in this call, or it may already exist with no receipt and no history. A call - that accepts no rows creates no binding. A source created or first-bound - inside a refused call is rolled back with the call. + that accepts no rows creates no binding. A refused call is not applied, + so it creates no source and binds none. A second device is refused rather than merged. That refusal is not archived. On `--yes`, an earlier committed page stays, the failed page makes no database changes, the range is not complete, and the exit is -nonzero. File import rolls back the whole -call. `--json` and `--json --yes` make no database changes. Device reads +nonzero. File import refuses the whole call and writes nothing. +`--json` and `--json --yes` make no database changes. Device reads that have `filter_by_priority` send `false`. Summary routes have no such switch. Section 2 states that limit. Preview keeps two facts in memory for this command, for each source sensor: the binding it would have stored, and an unbound source it would have created once that source has accepted history. A summary sensor does not -supply a binding for the device sensor. A later preview page uses those facts, including a -later page that adds an id after an id-less sleep page. The memory is -discarded with the process. It does not hold null-source payloads, so a -preview does not use it to judge those conflicts. It does not change the -estimated record counts. -A second command reads the committed source inside its own `BEGIN IMMEDIATE` -transaction. - -Three owner operations store a whole source record and do not run this -device-id guard. `ath correct` stores the source `data` the person -supplied, after the schema check. Native package restore copies the -package's records. A package merge the person accepts for a changed source -stores that source record. A 2.2.0 record keeps `device_binding` when the +supply a binding for the device sensor. The pull passes those facts to the +next preview page's matching step, including a later page that adds an id +after an id-less sleep page. The memory is discarded with the process. It +does not hold null-source payloads, so a preview does not use it to judge +those conflicts. It does not change the estimated record counts. A second +command's matching reads the committed source. + +Owner and library writes store a whole source record and do not run this +device-id guard. In 2.1.1 they are `ath correct` in +`src/cli/commands/edit.rs`, the protocol operations `records.write`, +`records.write_changes`, and `records.correct` in +`src/protocol/ops/records.rs`, native package restore, and a package merge +the person accepts, both in `src/package/restore.rs`. `ath correct` and the +protocol operations store the source `data` the caller supplied, after the +schema check. Native package restore copies the package's records. A +package merge the person accepts for a changed source stores that source +record. A 2.2.0 record keeps `device_binding` when the record has it. A 2.1.0 record does not gain the key, and a supplied field of the same name stays a supplied field. The next mapped pull or mapped import then uses the source key that those operations left behind. A 2.2.0 @@ -1101,42 +1421,52 @@ correct a point and a different id is refused. No signature is added. A person who replaces the database file is outside this rule. `Store::apply` in `src/store/write.rs` writes a whole source record. There -is no partial `revise`. A source write that is not one of the three owner -operations cannot set, change, or clear `device_binding`, including when -the key is absent from the new record. A write that contains -`device_binding` and is not one of those owner operations is refused. The +is no partial `revise`. In 2.1.1, every `Store::apply` caller that can +write a source is one of the owner and library writes above. The one +automatic source writer is `ProviderPreview::apply`. A keyed import there +only creates sources. It never revises one. So the binding rule is +enforced in `ProviderPreview::apply`. A staged source for route +`open_wearables` may carry `device_binding` only as the checked rule above +set it. The first bind of an existing source is a source correction in +that plan, with the source's expected revision. No other staged change may +set, change, or clear `device_binding`. Such a plan is refused, and the source stays unchanged. Other record types are unchanged. -The store connection is private. `Mapping::source` in `src/import/mapping.rs` -asks `route_source` for the writer, route, and sensor. That call takes no -receipt. The mapping receives a source id. It does not hold the source -JSON, and it cannot read deleted rows through the private connection. A -later whole-record write that is not an owner operation cannot fill the -receipt in, because a write that contains `device_binding` is refused. - -`src/store/write.rs` therefore gains three source operations besides that -refusal, the typed writes in section 6, and the bounded archive -safety read in section 2. It gains nothing beyond those: - -- Read the committed receipt, and whether any record or source device for - that source exists, including a deleted row. -- Create a source with the checked receipt already in its JSON. -- Write the checked receipt on an existing source only when the receipt is - absent and that same read shows no accepted or deleted record and no - source device. Every other source field stays. The write uses the normal - revision and `data_json` bookkeeping. Writer, route, sensor, import keys, - and baselines stay. -- Read the sources, records, import keys, and archive keys named by one - page, including tombstones and the current revision. This is the safety - read in section 2. It does not scan the database. - -The three receipt operations run inside the caller's `BEGIN IMMEDIATE` -transaction. The safety read runs in that same transaction, before any -mutation, and again at the start of the archive transaction. -A refused call rolls them back with the call. Other routes do not call -them. The build may extend `route_source` or add a narrow operation -beside it. It does not add a table, a trait, or a file split. The automatic -path does not replace `detail`, `vendor`, or `supplied_fields`. +The store connection is private (D223). `Run::source` in +`src/import/mapping.rs` asks `CandidateSink::route_source` in +`src/import/provider.rs` for a source by writer, route, and sensor. That +call takes no receipt. The mapping receives a provisional source id. It +does not hold the source JSON, and it does not read the database. The +facts come from the matching step. A later automatic write cannot fill +the receipt in, because `ProviderPreview::apply` refuses any staged change +to `device_binding` that the checked rule did not make. + +`src/import/provider.rs` therefore gains these source reads and writes, +besides the typed writes in section 6. It gains nothing beyond those: + +- In matching, read the committed receipt, and whether any record or + source device for that source exists, including a deleted row. +- In matching, read the sources, records, import keys, and archive keys + named by one page, including tombstones and the current revision. This is + the safety snapshot in section 2. It does not scan the database. +- In the staged plan, create a source with the checked receipt already in + its JSON. +- In the staged plan, write the checked receipt on an existing source only + when the receipt is absent and the same matching read shows no accepted + or deleted record and no source device. Every other source field stays. + The write is a correction with the source's expected revision. Writer, + route, sensor, import keys, and baselines stay. +- In `ProviderPreview::apply`, refuse any other staged change to + `device_binding`. + +The reads run in the matching step's read transaction. The writes run in +the page's one apply transaction. A refused call writes none of them. +Other routes do not call them. The build may extend `route_source` or add +a narrow operation beside it. It does not add a table or a trait. The +binding check and the safety snapshot go in one new file, +`src/import/binding.rs`, because `src/import/provider.rs` is already 1297 +lines. The automatic path does not replace `detail`, `vendor`, or +`supplied_fields`. `zone_offset` is not copied into `start_at`. It remains in `supplied_fields` when the server sends it. The timestamp text is the server's `start_time`, @@ -1150,7 +1480,7 @@ built without that field. Day rows carry it, and those rows are stored. ## 4. Credentials, privacy, and the network -D200 is the rule. The key never enters the athlete database, the export, the +D229 is the rule. The key never enters the athlete database, the export, the preview, or an error line. The pull reads the paths in section 2. Connections and the two live workout routes are included only when `--vendor-workouts` is on. It does not list users. A raw HTTP personal-record response includes `user_id`. That field must @@ -1165,22 +1495,41 @@ gender, and sex are stored. They are account health data, not the API key. The process refuses a base URL that could carry the key in the URL itself. It refuses plain `http` except to loopback. It does not follow a redirect, so -the key cannot be sent to a second host. One attempt, then stop. Timeouts are -10 seconds to connect and 30 seconds to read. A Garmin live window may -take 120 seconds to read. One response may be at most -8 MiB. One read may be at most 1000 pages. - -The body is read inside that cap and parsed before any `MappedReader` call. -The guard is in `open_wearables.rs`. It walks every decoded object key and -every decoded string. A value that contains the API key, the selected -origin, or the selected user id rejects the whole page. A key whose -letters, after dropping `_` and `-` and ignoring case, are -`useraccesstoken`, `accesstoken`, `refreshtoken`, `apikey`, -`authorization`, `password`, `secret`, or `clientsecret` also rejects -the page. `polar_user` and a route coordinate are not those keys. D215 -keeps the rest of the vendor object, including account ids, Polar user -URLs, and full routes. The matching personal-record `user_id` is the only field that is dropped -before this walk. Any other copy of the user id still rejects the page. +the key cannot be sent to a second host. One attempt per request, then +stop. The stored reads use 30 seconds to connect and 120 seconds to read, +as `src/runtime/garmin_pull.rs` does. A live vendor request uses 30 +seconds to connect and 360 seconds to read, for the reason in section 2. +The timeouts are named constants in `src/runtime/open_wearables.rs`. One +response may be at most `MAX_PULL_RESPONSE_BYTES`, which is 10 MiB. One +read may be at most 1000 pages. Those limits are named constants in +`src/input_policy.rs`, where 2.1.1 keeps every limit on untrusted input. + +The body is read inside that cap and parsed before the page reaches +`MappedPage`. The guard is in `open_wearables.rs`. It walks every decoded +object key and every decoded string. A value that contains the API key, +the selected origin, or the selected user id rejects the whole page, even +under a credential-shaped key. + +A credential-shaped key does not reject the page. Its value is withheld. +A key is credential-shaped when its letters and digits, with case ignored +and every other character dropped, end in `token` or `secret`, or are +`apikey`, `authorization`, or `password`. That covers `userAccessToken`, +`access_token`, `refresh-token`, `id_token`, `session_token`, `token`, +`embed_token`, `client_secret`, and `apiKey`. The value is replaced by the +text `[withheld by ath]`, whatever type it had. A string that is an +absolute URL keeps its address. Each query parameter in it whose name is +credential-shaped has its value replaced by the same text. The pull +records the JSON path of each withheld value and counts them. It prints +the count and up to 20 paths, and it says when that list was shortened. +Nothing else in the object changes. The rule applies to every page, +stored reads and vendor reads alike. Garmin's list objects can carry an +optional `userAccessToken`, so refusing the page would refuse every such +Garmin page. `polar_user` and a route coordinate are not credential-shaped. +D244 keeps the rest of the vendor object, including account ids, Polar +user URLs, and full routes. The matching personal-record `user_id` is the +only field of a stored read that is dropped before this walk. Any other +copy of the user id still rejects the page. The connections list is not +walked, as section 2 says. A raw personal-record `user_id` that is absent, null, the wrong type, or not the selected user refuses the page before the drop. The page is not rewritten and it is not mapped. A Unicode escape such as `\u0073` is visible @@ -1194,10 +1543,10 @@ problem `code` is printed only when it is a single token of letters, digits, `_`, or `-`, at most 64 characters, and it does not contain the key, the origin, or the user id. Any other code is withheld. A transport error or a parser error is replaced with a fixed sentence. The sentence has no URL, no -path, and no user id. The result keeps a `left_out` total and at most 20 -example lines. It does not keep every id or every source string. The 64 MiB -stdout buffer in `src/ath-core.ts` is gone with the TypeScript bridge. -The command prints from this process. The 20 example lines are the bound. +path, and no user id. The result keeps a `left_out` total, a count for +each reason, and at most 20 example lines. It does not keep every id or +every source string. The command prints from this process, as every 2.1.1 +command does. The 20 example lines are the bound. There is no Athletic Standard telemetry on this command. The server the person named is the only host contacted. @@ -1232,16 +1581,20 @@ attachments, reporting periods, and the other child tables, use `configure` in `src/store/mod.rs` requires foreign keys on before `install_schema` runs. A `DROP TABLE records` inside that transaction would fail or cascade through the children. Step 6 does not do that. - -`install_schema` runs steps 1 through 5 in one transaction and commits it. -Today that same transaction sets `user_version` to `SQL_SCHEMA_VERSION`. -The step 1 through 5 transaction sets `user_version` 5. Step 6 is not -inside that transaction, and step 6 sets `user_version` 6. Target 6 does -not use the ordinary write transaction. - -Step 6 uses one connection that ordinary writes do not reuse. Before -`BEGIN`, it sets `PRAGMA foreign_keys=OFF` and reads the pragma back. The -value must be 0. Turning foreign keys off does not turn off the schema +`write_transaction` in the same file refuses to write when foreign keys +are off. `Store::transaction` uses it, and every 2.1.1 migration runs +through `Store::transaction`. + +Today `install_schema` runs the whole chain, steps 1 through 5, in one +transaction. That transaction sets `user_version` to `SQL_SCHEMA_VERSION` +and commits. With step 6, that transaction stops after step 5, sets +`user_version` 5, and commits. Step 6 then runs in its own transaction and +sets `user_version` 6. + +Step 6 runs on the store's own connection, in a transaction that +`src/store/migrate.rs` opens itself rather than through +`Store::transaction`. Before `BEGIN IMMEDIATE`, it sets +`PRAGMA foreign_keys=OFF` and reads the pragma back. The value must be 0. Turning foreign keys off does not turn off the schema check SQLite runs during `ALTER TABLE`. `sql_v1_current_records` and `sql_v1_active_records` select from `records`. The triggers `record_revisions_record_type_matches_parent_insert` and @@ -1281,25 +1634,32 @@ Inside that one transaction the order is fixed. `sql_v1_database_info`, `sql_v1_record_revisions`, and `sql_v1_record_deletions` do not name `records`, so they stay through the gap. Then the transaction commits. After commit, and after a rollback or -a thrown error, the connection sets `PRAGMA foreign_keys=ON` and reads it -back. The value must be 1. If that read fails, the connection is closed -and is not reused. A later ordinary open still refuses to write while -foreign keys are off. A failure before commit restores the views, the +an error, the runner sets `PRAGMA foreign_keys=ON` and reads it back. The +value must be 1. If it is not, the command fails and closes the store. +`write_transaction` would refuse a later write on that connection anyway, +and the next open turns foreign keys on in `configure`. A failure before +commit restores the views, the cross-table triggers, the old check, the rows, and the version. The D124 backup is already on disk. Device receipts stay in the copied source JSON. They are not rewritten. -A new database commits steps 1 through 5, then runs this step 6 path. -Step 9 sets `user_version`. If step 6 fails during init, that transaction +A new database commits migration steps 1 through 5, then runs step 6. +Item 9 in the list above sets `user_version`. If step 6 fails during init, that transaction rolls back to the committed step 5 schema before the existing failed-init cleanup runs. Init reports failure. `Store::create` still calls `remove_partial_database`, which deletes the new file, the wal file, and -the shm file. D202 leaves that cleanup in place, and this build does not +the shm file. D231 leaves that cleanup in place, and this build does not change it. A file that cleanup does not delete is not left with the views dropped. A migrate of a database that already existed is a separate case. -Its step 6 rollback leaves that file in place, at the old schema, with -foreign keys on. `apply_step` in `src/store/migrate.rs` gains this arm for -target 6 and does not use the ordinary write transaction for it. +`apply_after_backup` and `apply_pending_without_backup` in +`src/store/migrate.rs` run the steps up to 5 in `Store::transaction`, as +2.1.1 does, and commit. They then run step 6 in its own transaction. For a +2.1.1 database, a step 6 rollback leaves the file at schema 5 with foreign +keys on. For an older database, the earlier steps stay committed, so the +file is now a 2.1.1 database. The message says which schema the file is +at and names the verified backup. Running `ath migrate` again runs only +step 6. `apply_step` keeps its signature for steps 2 through 5. Step 6 is +a separate function in that file. `MIGRATION_CHAIN` in that file and `spec/sql/contract.json` gain the step. The native tests check that the contract matches the embedded SQL. `packages/npm/package.json` exports and `packages/npm/test/public-api.test.ts` @@ -1338,8 +1698,9 @@ regenerated because the stored version is inside it. The demo is `tests/fixtures/version-0-4-3/` is not regenerated. `tests/fixtures/version-2-0-0/` is not regenerated. -`package.json` `files` already includes `mappings`. The build rewrites -`mappings/open-wearables.md` so it implements section 2. Other mapping +`build.rs` compiles every file under `mappings/` into the program, and +`src/assets/mod.rs` reads the compiled copy. No package list changes. The +build rewrites `mappings/open-wearables.md` so it implements section 2. Other mapping files stay as they are. `ATH_WRITE_GENERATED=1 cargo test --test generated` runs because help text, the schema, and the demo change (D80, and the 2.1.1 generator decision). `AGENTS.md`, `build-history/README.md`, and `SPEC.md` are @@ -1359,46 +1720,51 @@ interactive open can preview, back up, ask, and then migrate. | Piece | Place | |---|---| -| HTTP, page loop, envelope split, call `MappedReader` | `src/runtime/open_wearables.rs` | -| Live provider table, unwrap, windows, and detail budget | `src/runtime/vendor_workouts.rs` | -| Command `pull openwearables` | `src/cli/spec.rs` and `src/cli/commands/routes.rs` | -| Flags, key, preview text, refusal if the key appears | `src/cli/`, `src/cli/help.rs`, `src/runtime/keyring.rs` | -| Mapping names and field rules | the existing file `mappings/open-wearables.md` | -| Stored records | the existing store and mapping engine | -| Keep `device_binding` on a source write that is not the owner's whole record | `Store::apply` in `src/store/write.rs`, sources only | -| Read receipt and tombstone history; create or first-bind with the checked receipt | three source operations in `src/store/write.rs`, inside the caller's transaction | +| HTTP, timeouts, page loop, envelope split, privacy walk, and withheld values | `src/runtime/open_wearables.rs` | +| Live provider table, unwrap, windows, pacing, detail budget and rules, and the vendor envelope | `src/runtime/vendor_workouts.rs` | +| Command `pull openwearables`, and the `--date` check for `garmin` | `src/cli/spec.rs` and `src/cli/commands/routes.rs` | +| Flags, key, preview text, refusal if the key appears | `src/cli/`, `src/cli/help.rs`, `src/runtime/keyring.rs`, and `key_clear` in `src/cli/commands/model.rs` | +| Reader for one decoded page | `MappedPage`, beside `MappedReader` in `src/import/mapping.rs` | +| Mapping names and field rules, including the `vendor_workout` section | the existing file `mappings/open-wearables.md` | +| Stage, match, and write each page | `preview_route` and `ProviderPreview::apply` in `src/import/provider.rs` | +| Device-binding facts and the safety snapshot | new `src/import/binding.rs`, called from the matching step in `src/import/provider.rs` for route `open_wearables` | +| Create or first-bind with the checked receipt, and refuse any other `device_binding` change | the staged plan and `ProviderPreview::apply` in `src/import/provider.rs` | +| Stored-original read for the vendor detail rules | a crate-private read in `src/import/provider.rs` | +| Response cap and page cap | named constants in `src/input_policy.rs` | +| Receipt for a start in Unix seconds or milliseconds | a helper beside `offset_timestamp_receipt` in `src/import/candidate.rs` | | Measurement samples, source reports, paired null value and unit, and child withdrawal | `write_current_state` and `typed_columns` in `src/store/encode.rs`. Package restore, repair, and the record check use that encoder | -| Whole source record from the owner | existing `ath correct`, package restore, and an accepted package merge | +| Step 6 with foreign keys off | its own transaction in `src/store/migrate.rs`, and `install_schema` in `src/store/mod.rs` | +| Whole source record from the owner or a library caller | existing `ath correct`, protocol `records.write`, `records.write_changes`, and `records.correct`, package restore, and an accepted package merge | `src/store/`, `src/import/mapping.rs`, and `src/runtime/garmin_pull.rs` are not the home for this client. `garmin_pull.rs` remains the Garmin pull. The two clients may each call `ureq`. A shared trait is the later connector work, and this release does not add it. -`mapping.rs` changes for the counts, the device check, and the preservation -writes in section 2. The mapped-import report in `src/import/provider.rs` -keeps its `outcome` field. `MappedReader` adds counts by record type. -For route `open_wearables` only, it also runs the device-binding check in -section 3 before it mutates a source device or a timeseries record. That -check is the shared mapped-import and pull enforcement. It is not a new -match key and it does not apply to any other route. It also gains the -measurement-sample target, the reporting-window write, and the segment -copy from section 2. HTTP stays out of `mapping.rs`. `src/store/write.rs` -keeps the receipt refusal and adds the three source operations in section 3: the -receipt and tombstone read, creation with the checked receipt, and a -first bind on an existing source that has no history. The archive -transaction adds a bounded read of the sources, records, import keys, -and archive keys named by that page, including tombstones and the -current revision. It does not scan the database. It also inserts and -updates `measurement_sample` and `source_report`, and it accepts a provider +`mapping.rs` changes for `MappedPage` and for the preservation writes in +section 2: the measurement-sample target, the reporting-window write, the +segment copy, and the `vendor_workout` section. HTTP stays out of +`mapping.rs`. The mapped-import report from `report_value` in +`src/import/provider.rs` keeps its `outcome` field. The pull counts each +page by record type from its staged plan. For route `open_wearables` only, +the matching step runs the device-binding check in section 3 before a +staged plan can change a source device or a timeseries record. That check +is the shared mapped-import and pull enforcement. It is not a new match +key and it does not apply to any other route. The matching step also +reads the page's safety snapshot: the sources, records, import keys, and +archive keys named by that page, including tombstones and the current +revision. It does not scan the database. `ProviderPreview::apply` refuses +any `device_binding` change the checked rule did not make. The store +inserts and updates `measurement_sample` and `source_report`, and it +accepts a provider summary or provider score whose `value` and unit are both present or both absent. A half-null pair is refused. When an anchor in this response no longer emits a child, that child is revised to the absent pair in the same transaction. `write_current_state` in `src/store/encode.rs` writes that pair and the new table. Package restore, repair, and the record check use that encoder. `RecordType` in `src/model/` gains the `source_report` entry. -The eight range calculations and -`provider-period-summary` do not read `source_reports`. `read_inputs` and +The eight range calculations, `provider-period-summary` among them, do not +read `source_reports`. `read_inputs` and `read_period` also exclude `source_type` `manual`, and they have no `include_manual` switch. `workout-drift` loads the named session first, including a manual session, and uses that session's start and end as the @@ -1415,26 +1781,26 @@ before the limit, the count, the grouping, and the numeric decode. A null is not stored as zero and is not replaced by an older revision. The session-summary branch of `read_period` uses the same filter on the extracted number and unit. Formulas and source grouping stay as they are. -The archive insert is the pull-only transaction in section 2. It is not -inside `MappedReader`, and a mapped file import does not call it. It -revalidates the safety snapshot before any insert. It does -not call the receipt operations. No other store behavior changes. `ath correct`, -package restore, and an accepted package merge stay whole-record owner -writes. They are named in section 3 so the binding survives a 2.2.0 round -trip. They are not a new importer. The pull sums only `sleep_session`, `workout_session`, +The archive is the pull-only preview and apply in section 2. A mapped file +import does not build it. It goes ahead only at the database revision the +protected preview read, and its apply refuses a moved revision. It does +not call the receipt operations. No other store behavior changes. The +owner and library writes in section 3 stay whole-record writes. They are +named there so the binding survives a 2.2.0 round trip. They are not a +new importer. The pull sums only `sleep_session`, `workout_session`, `point_measurement`, `measurement_sample`, `provider_summary`, `provider_score`, and `source_report`. A committed protected page adds those counts to `committed`. A committed archive page adds its counts -only to `archive_committed`. A rolled-back preview page adds its -protected estimates to `estimated` and its archive estimates to -`estimated_archive`. It does not add -`outcome` across pages. `outcome` counts the source-device row in the same -group. Filtering that row out of the totals does not make a preview equal a -write. Each preview page is rolled back, so page two does not see page one. +only to `archive_committed`. A preview page adds its protected estimates +to `estimated` and its archive estimates to `estimated_archive`. It does +not add `outcome` across pages. `outcome` counts the source-device row in +the same group. Filtering that row out of the totals does not make a +preview equal a write. A preview page writes nothing, so page two does not +see page one. The command reads the saved key and `OPEN_WEARABLES_API_KEY` in this process, in `src/runtime/keyring.rs`. It has no `--key` flag. The -decoded-key walk in section 4 runs before `MappedReader`. The command +decoded-key walk in section 4 runs before `MappedPage`. The command checks its own text before printing. The command returns the preview outcome from section 1 when the mode is a @@ -1480,7 +1846,7 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: counts two new rows, and `--yes` counts one new and one changed - a valid page, then a failing page, under `--yes`. The failure is one of a 401, a 429, a repeated or null cursor, a vetoed page, or a minimum page - that is still over 8 MiB. Page 1 remains. Page 2 adds no rows and no revisions. No later read + that is still over the response cap. Page 1 remains. Page 2 adds no rows and no revisions. No later read runs. The exit is nonzero. The success sentence is absent. The text gives the retained counts. The same command run again stores no second copy - the same failure sequence with no `--yes`, and again with `--json --yes`, @@ -1490,7 +1856,7 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: - an installed mapping that does not implement section 2 fails before any request. The server sees no request. Raw and day timeseries requests omit `types`. A comma-joined type string is not sent -- a cursor or offset page fails before `MappedReader` when the object is +- a cursor or offset page fails before `MappedPage` when the object is missing, `data` is not an array, `pagination` is missing, or `has_more` is not a boolean. That failure is not an empty success. A body response of JSON `null` is a completed empty snapshot and writes nothing. A body @@ -1537,10 +1903,10 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: pull of that same raw point stay one record. A heart-rate sample from device B does not replace device A's sample. A negative latitude and a negative longitude are stored -- a response larger than 8 MiB on a cursor or offset read is requested - again with a smaller limit, the same cursor or offset, and the rows are - stored. A day page at `limit` 1 that holds many small rows and is still - over 8 MiB leaves that read incomplete and names the read and +- a response larger than the response cap on a cursor or offset read is + requested again with a smaller limit, the same cursor or offset, and the + rows are stored. A day page at `limit` 1 that holds many small rows and is + still over the cap leaves that read incomplete and names the read and `resolution=1day`. It does not name a series type. An oversized body response names `body` and writes nothing. The export after a pull, and a native package import, keep period bounds, units, `computed_by`, @@ -1550,7 +1916,7 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: points stay. The same summary stored first does not block a later raw page from binding its device source. File import then pull, pull then file import, and import then import keep one summary id. A refused - device page rolls back only that page. Two meals with one timestamp and + device page refuses only that page. Two meals with one timestamp and different ids stay two records. Two summary fields on one date stay two records. A page with one bound heart-rate row and one same-triple row whose `device_id` is missing refuses the protected page. Neither row @@ -1562,7 +1928,7 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: import keep the resolution. A raw capsule and a day capsule of the same row body stay two records. A sleep id that is missing, beside a valid workout, refuses the page before any write - and is not archived. The next page still rolls back on its own failure. + and is not archived. The next page is still refused on its own failure. A measured timeseries row with `source: null` is stored on the unattributed sensor when the payload matches. A reported row with `source: null` uses the report sensor @@ -1571,15 +1937,18 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: the new original. A mapped file import of that changed payload writes nothing. A raw midnight row and a day window that starts then stay two records. A preview of those two pages does not claim the - conflict, because the first preview page was rolled back. A confirmed + conflict, because the first preview page wrote nothing. A confirmed second page does. - a missing device id beside a conflicting device id, in either row order, refuses the protected page and stores no capsule and no revision. The - same veto holds for a deleted source, an unbound legacy history, and a - missing workout UUID on the same page as an eligible row, including when - the deleted-source row would otherwise be `left_out`. A credential on a - neighboring object starts neither transaction. A deleted archive source - is not recreated. An existing device receipt is unchanged. On an empty + same veto holds for an unbound legacy history and a missing workout UUID + on the same page as an eligible row. A deleted source on a page with an + eligible row leaves that source's rows out with the D190 line. The + eligible row still refuses the protected page, and the deleted source + stops the archive, so no capsule is stored. The API key, the server + origin, or the selected user id on a neighboring object builds no + preview. A deleted archive source is not recreated. An existing device + receipt is unchanged. On an empty database, the first eligible archive sets `written` false, `database_changed` true, `archive` `stored`, and the text `Protected write refused; N originals archived; database changed; @@ -1587,7 +1956,7 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: `unchanged`, `written` false, `database_changed` false, and the text `Protected write refused; 0 originals archived; database unchanged; pull incomplete.` A third payload adds one archive count and - leaves the earlier capsule. An archive-transaction failure on that + leaves the earlier capsule. An archive apply failure on that empty database sets `archive` `failed`, keeps the refusal, adds no archive row, leaves `written` false and `database_changed` false, and uses the text `Protected write refused; archive failed; database @@ -1595,26 +1964,32 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: committed sleep page keep that page's `written` true, its `committed` counts, and `database_changed` true. The failure text then says `database changed`. - Preview and `--json --yes` commit neither transaction -- two connections, both row orders. Before the protected `BEGIN IMMEDIATE`, - the other connection commits a binding of device C on source S. The page - has a series for S with device B and a missing-id neighbor. The - protected transaction refuses. `archive` is `not_attempted`. No capsule, - source revision, or receipt change is written. The same refusal holds - when the other connection commits a tombstone or history on S instead - of the binding. A page whose safety snapshot has no veto, then a - deletion of S after the protected rollback, does not archive S's - payload. A deletion of the normalized record or its import key between - the two transactions does not create a capsule. A deletion of the - archive source, or of an existing capsule, does not recreate it and - does not store a second identity. An owner correction that changes the - binding, the history, or the safety revision after the protected - rollback leaves `archive` `not_attempted` and writes nothing. An - already deleted neighbor, in either row order, is a protected veto and - is not archived. A credential on the page starts neither transaction. - An earlier committed sleep page keeps `written` true, its `committed` - counts, and `database_changed` true. The text is `Protected write - refused; archive not attempted; database changed; pull incomplete.` + Preview and `--json --yes` apply neither plan +- two connections, both row orders. After the protected preview and before + its apply, the other connection commits a binding of device C on source + S. The page has a series for S with device B. The protected apply + refuses because the database revision moved. `archive` is + `not_attempted`. No capsule, source revision, or receipt change is + written. The same refusal holds when the other connection commits a + tombstone or history on S instead of the binding. A page whose safety + snapshot has no veto and whose protected preview refused it, then a + deletion of S before the archive, leaves `archive` `not_attempted` and + does not archive S's payload. The same holds when the other connection + deletes the normalized record or its import key, deletes the archive + source or an existing capsule, or makes an owner correction, between + the protected preview and the archive apply. Nothing is recreated, and + no second identity is stored. An already deleted neighbor, in either + row order, is left out with its line, and the page is not archived. The + API key on the page builds no preview. An earlier committed sleep page + keeps `written` true, its `committed` counts, and `database_changed` + true. The text is `Protected write refused; archive not attempted; + database changed; pull incomplete.` +- every athlete-data write moves the database revision: `Store::apply`, + `ProviderPreview::apply`, repair, erase, and a package merge. A restore + into an empty database sets the package's revision and database ID, and + the apply refuses another database ID. A test commits each of these + between a protected preview and an archive apply, and each one makes the + archive `not_attempted` - sensors `ow1:["summary","sleep",null]` and a colon inside a provider name stay different from a shifted tuple. The text `-` is not the same sensor as a missing part. A score whose input source changes from null @@ -1723,11 +2098,12 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: not create a binding. The first preview page is id-less sleep and the second preview page has an id for that same source: the preview refuses and writes nothing -- a partial source update changes `detail` and leaves `device_binding` - unchanged. A partial update that includes `device_binding` changes - nothing. `ath correct` with a complete source object replaces that object. - After that correction, a mapped write follows the source key the - correction stored +- a mapped page never revises a stored source except by the checked first + bind. A staged plan that would set, change, or clear `device_binding` + any other way is refused by `ProviderPreview::apply`, and the source is + unchanged. `ath correct` with a complete source object replaces that + object, and protocol `records.correct` does the same. After that + correction, a mapped write follows the source key the correction stored - export a 2.2.0 database that has an established binding, import that package, and the source key and the import keys are still there. The same id can correct the point. A different id is refused, with no new point @@ -1767,43 +2143,121 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: include `Z`. The test does not add `Z` - a deleted mapped source is left out. A Garmin file import of a different workout remains a second source -- `left_out` in the result is a total and at most 20 examples +- `left_out` in the result is a total, a count for each reason, and at + most 20 example lines. With 21 lines it says the list was shortened - a synthetic Polar list without samples, zones, and route, then one - detail with all three true, stores one original. The nested samples are - not measurement samples. A second identical pull changes no row and - reports no database change for that original. A thinner detail does not - replace a stored original that already has samples, zones, or a route. - A failed detail keeps the list object and marks that detail incomplete. + detail with all three true, stores one original with `detail_status` + `stored`. The nested samples are not measurement samples. A second + identical pull makes no detail call for that id, counts it `kept`, + changes no row, and reports no database change for that original. A + changed list object whose new detail has an empty `route` writes + nothing for that id, counts it `thinner`, and keeps the stored original. The stored workout with a different Open Wearables id stays a separate session. A device id on the vendor object does not set `device_binding`. The result text does not print a route coordinate. It does say the originals keep account ids, user URLs, and full routes +- a Strava detail with `laps`, `splits_metric`, `segment_efforts`, and + `map` is stored. A later changed list object whose detail has no + `segment_efforts` is `thinner` and writes nothing. A Whoop detail is + never `thinner`, because the table names no Whoop detail field +- a failed Polar detail for a new id stores the list object with + `detail_status` `failed`. Polar is `incomplete`, and the command exits + nonzero. The same failure for an id that has a stored detail and a + changed list object writes nothing and adds no revision. A detail that + names another id is `mismatch`, is not stored, and also makes Polar + `incomplete` +- 45 Strava ids with no stored detail. The first pull details the 20 + oldest starts and stores the other 25 with `detail_status` `deferred`. + Strava stays `completed`, its line counts 25 deferred, and the exit is + zero when nothing else failed. A second pull details ids 21 to 40 in + start order. A third pull details the last five. A deferred id whose + original already has a detail, and whose list object changed, keeps + that detail, writes nothing, and adds no revision - without `--vendor-workouts`, preview and `--json` make zero requests to the connections route and to both workout routes. `requests_made` is - false and every live line is `not_attempted`. With the flag, preview - and `--json` still write nothing, `requests_made` is true, and the text - says vendor requests were made + false, `notice` is empty, and every live line is `not_attempted`. With + the flag, preview and `--json` still write nothing, `requests_made` is + true, and the text says vendor requests were made +- every run with the flag, as a preview, under `--yes`, and with `--json`, + says before its first live request that the server may refresh and save + vendor tokens, may revoke a connection, and may wait about 105 seconds + on a rate limit. `--json` holds those three sentences in + `vendor_workouts.notice` and is still one JSON value. The help text of + `--vendor-workouts` and `src/cli/examples/pull.txt` say the same, and + the generated `skills/athletic-standard/references/cli.md` matches them +- a connections list for the selected user whose items carry `user_id`, + `linked_user_ids`, `id`, `provider`, `status`, and other fields passes. + It is not stored, and no other user's id is printed. One item whose + `user_id` is another user refuses the list, and every provider is + `not_attempted` +- an active Garmin connection and a revoked Polar connection call only + Garmin. Polar is `not_attempted` with `connection_status` `revoked`, and + the fixture server sees no Polar request. `expired` is the same. A + status the pin does not define prints `unknown status` and is not + called - a connections list with only Garmin completes Garmin and marks Polar, Suunto, Whoop, Fitbit, Oura, Strava, Withings, and Sensorbio `not_attempted`. A failed Polar list does not stop Garmin -- one failed Garmin window makes Garmin `incomplete` and never +- a Suunto list object `{"workoutId": 1001, "workoutKey": "abc"}` calls + detail at `abc`. The detail's `payload` is unwrapped. One record is + stored, and its key ends `suunto|1001`. A detail that names 1001 or + `abc` matches. A list object with no `workoutKey` calls detail at 1001 +- a Garmin `activityId` of `123` and a later `"123"` are one record. An + integer above 9007199254740991 refuses only that object and counts it + as `unsafe_number`. A fractional id refuses only that object and counts + it as `unusable_id`. Two different objects with one id are both + refused as `duplicate_id` +- a three-day Garmin range sends three windows. Each window sends + `summary_start_time` and `summary_end_time` as integer Unix seconds, and + no window is longer than 86,400 seconds. A date `--from` starts at + midnight UTC. One failed window makes Garmin `incomplete` and never `completed`. A later window still runs -- a Sensorbio body stores `data[].activities[].id`. A missing id refuses - that object and keeps the others. File import of the saved original, - then export, keeps one record id +- live requests go one at a time, at least one second apart by the + fixture server's clock. A live request that times out, with the read + timeout shortened for the test, stops every later request to that + provider in the command. The next provider still runs. The 360-second + value is checked as a named constant +- a Garmin list object with `userAccessToken` stores that original with + the value `[withheld by ath]`. The record, the export, the text, and + `--json` do not hold the token. `withheld` counts 1 and names the path. + The same holds for `access_token`, `refresh-token`, `id_token`, + `session_token`, `token`, `embed_token`, `client_secret`, `apiKey`, + `authorization`, and `password`, and for a `token` query parameter in a + URL string. The URL keeps its address and its other parameters. The API + key under a credential-shaped key still refuses the page. A `polar_user` + URL and a route coordinate are stored unchanged +- a Sensorbio body stores `data[].activities[].id`, with the parent entry + as `list_parent`. A missing id refuses that object, counts it as + `missing_id`, and keeps the others. File import of the saved original, + then export, keeps one record id. Sensorbio's line says it reads only + the oldest 50 entries - a Polar exercise whose start is outside `--from` and `--to` is stored and counted under `vendor workout originals`. `range_complete` still - follows the stored ranged reads -- Whoop `next_token`, Oura `next_token`, Sensorbio `links.next`, and a - Strava page whose length equals `per_page` set `more` true. - `covers_requested_range` is false. The 21st Strava detail id is - `deferred`. Its list object is stored + follows the stored ranged reads. A Polar `start_time` with no offset has + no `reported_at`, and its receipt says the source gave no offset. A + Suunto start in Unix milliseconds keeps the digits and stores + `reported_at` with milliseconds. Both receipts pass `ath check` +- a Whoop response with `next_token`, an Oura response with + `next_token`, a Sensorbio response with `links.next`, and a Strava page + whose length equals `per_page` set `more` true. The fixture server sees + no `nextToken` sent to Whoop. `covers_requested_range` is false +- a vendor original that the person deleted is left out on every later + pull, counted as `deleted_record`, and not recreated. A deleted + `vendor_workout` source leaves out every object from that provider as + `deleted_source`. An original that the person corrected gains a + revision with the server's envelope when a later envelope differs, and + the correction stays in its history. An equal envelope adds nothing +- with the flag on, a run whose protected page is refused and archived + still writes the vendor page and keeps its counts apart. A refused + vendor page leaves the archive and the stored pages as they were +- a vendor list response that the privacy scan refuses stores nothing + from that response, counts its readable objects as `response_refused`, + and makes the provider `incomplete`. In every vendor test, each listed + object is in exactly one detail count or one left-out count - `--json` includes `vendor_workouts.requested`, `requests_made`, - `originals`, and each provider's `status`, `covers_requested_range`, - `more`, `deferred`, and `limit` -- a page whose key is `userAccessToken`, `access_token`, `refresh-token`, - `apiKey`, `authorization`, `password`, `secret`, or `client_secret` is - refused. A `polar_user` URL and a route coordinate are stored + `notice`, `originals`, and each provider's `status`, + `connection_status`, `covers_requested_range`, `more`, `limit`, + `details`, and `left_out` Migration tests, in the build gate: @@ -1828,11 +2282,19 @@ Migration tests, in the build gate: `user_version` 6, and `ath check` exits 0. The fresh database accepts a source report, the same two views are queryable, and a mismatched revision type is rejected. A failed init rolls step 6 back and then the - existing cleanup removes the new file. A failed migrate of a populated - database leaves that file, the old schema, the views, and foreign-key - enforcement. Step 5 still + existing cleanup removes the new file. A failed step 6 migrate of a + populated 2.1.1 database leaves that file, schema 5, the views, and + foreign-key enforcement. Step 5 still writes `2.1.1` and schema 5, and `install_schema` commits that transaction before step 6 +- a 2.0.0 database whose step 6 is made to fail after steps 3 to 5 + committed is a 2.1.1 database at schema 5. The message says so and names + the verified backup. A second `ath migrate` runs only step 6 and + finishes. `Store::transaction` still refuses a write while foreign keys + are off, and step 6 does not use it +- `ath migrate` re-checks the file, the database ID, the schema, and the + revision its earlier steps left before step 6. A change made between the + two transactions stops step 6 and changes nothing more - databases at `1.0.0`, `2.0.0`, and `2.1.0` still open for migrate. Packages at `2.0.0`, `2.1.0`, and `2.1.1` still import. `spec/sql/migrations/004-version-2-1.sql`, `spec/sql/migrations/005-version-2-1-1.sql`, and the folders `schema/2.0.0/`, @@ -1850,6 +2312,9 @@ open the real password store. They cover: - `ath key clear` with no name, when no Open Wearables key is saved, keeps today's gateway sentences - `ath key clear vercel` does not remove a saved Open Wearables key +- `ath key clear garmin` is still refused, as in 2.1.1 +- `OPEN_WEARABLES_API_KEY` is used before the saved key, as + `GARMIN_PERSONAL_API_KEY` is for Garmin - `ath key clear openwearables` removes the saved key and, when `OPEN_WEARABLES_API_KEY` is set, says that variable is still available. The variable is still set afterward @@ -1858,8 +2323,12 @@ open the real password store. They cover: - a preview `--json` has `written: false`, protected and archive committed zeros, `estimated` counts, and `range_complete: false` - `--json --yes` is a preview. After a later-page failure, and after a - readable range, neither transaction commits and the database is + readable range, neither preview is applied and the database is unchanged +- `ath pull garmin` with no `--date` fails with `error: required option + '--date ' not specified`, as in 2.1.1. `ath pull openwearables` + needs no `--date`. `ath pull other` fails with `pull reads garmin or + openwearables` `cargo fmt --check`, `cargo clippy --all-targets -- -D warnings`, and `cargo test` pass. In `packages/npm`, `npm ci`, `npm run typecheck`, and @@ -1891,8 +2360,9 @@ the fixture key once into `ath key set openwearables`. 4. Repeat. Success: `--yes` again reports the stored rows unchanged. Failure: a second copy of a sleep session or a point appears. 5. Compatibility. Success: one synthetic Apple, WHOOP, or Oura import still - passes `ath check`, and `ath pull garmin` with no date still asks for - `--date`. Failure: that import or the Garmin command breaks. + passes `ath check`, and `ath pull garmin` with no date still fails with + `error: required option '--date ' not specified`. Failure: that + import or the Garmin command breaks. The automated cases in section 7 are not extra card steps. @@ -1907,7 +2377,7 @@ This plan pull request has no screenshots and no video. ## 9. Separate follow-ups -D202 records the check. None of these is a prerequisite for the pull, and none +D231 records the check. None of these is a prerequisite for the pull, and none is in the build pull request. - Failed `ath init` and failed `Store::create` still delete the database @@ -1916,20 +2386,28 @@ is in the build pull request. fail with `EBUSY`. Version 2.1.0 spec section 12 left it out and named no later version. Version 2.1.1 did not take it. A failed step 6 rolls back before that cleanup. This build does not replace the cleanup. -- `src/import/mapping.rs` is 1703 lines. `src/store/check.rs` is 1044. The - pull does not add HTTP to them. `mapping.rs` gains the counts, the - open-wearables binding check, and the preservation writes in section 2. - `src/store/write.rs` gains the receipt refusal, the three source - operations in section 3, and the sample, source-report, withdrawal, - null-filter, archive, and paired-null writes in section 6. Splitting - `mapping.rs` stays out. +- `src/import/mapping.rs` is 1703 lines, `src/import/provider.rs` is 1297, + and `src/store/check.rs` is 1044. The pull does not add HTTP to them. + `mapping.rs` gains `MappedPage`, the `vendor_workout` section, and the + preservation writes in section 2. `provider.rs` gains the staged first + bind, the `device_binding` refusal in `ProviderPreview::apply`, and the + stored-original read. The binding check and the safety snapshot go in + the new `src/import/binding.rs`. `src/store/encode.rs` gains the sample, + source-report, withdrawal, and paired-null writes in section 6, and + `src/calculate/range.rs` gains the null filter. Splitting `mapping.rs` + stays out. +- `ath key clear garmin` is refused in 2.1.1, because `key_clear` in + `src/cli/commands/model.rs` accepts only gateway names. `ath key set + garmin` works. This pull leaves that as it is. Making the Garmin key + removable is separate work. - `persist.rs` and `ath-core persist` are gone. A name check outside import is separate work. The pull does not add one. - The mapping path rule is already `is_mapping_path` in `src/assets/mod.rs`. There is no duplicate to delete. -No maintainability note under another name was found in the 2.1.0 decision -log. The sizes above are the current code, not a recorded D-number. +No maintainability note under another name was found in the 2.1.0 or +2.1.1 decision logs. The sizes above are the code at 2.1.1, not a +recorded D-number. ## 10. Risks and the approval @@ -1939,7 +2417,7 @@ measured run for this pull. Risks: - A server newer than 0.11.0 can add a default that hides a second device. - Current `main` does not, when the queries in D201 are sent. The client is + Current `main` does not, when the queries in D230 are sent. The client is tested against the stored fixture. That fixture is not a live response, and a live timestamp without an offset is left out. A breaking envelope needs a new fixture before the pull trusts it. @@ -1972,15 +2450,15 @@ mapping engine and `mappings/open-wearables.md`. Then the reads, the cycle filter, the smaller-page split, and the tests in section 7. The laptop card and the phone proof are part of that same pull request. This plan pull request has no media. -The maintainer approves or rejects this plan before any build. D198 through -D215 are the proposal. They are not adopted. The stored workout and the +The maintainer approves or rejects this plan before any build. D227 through +D244 are the proposal. They are not adopted. The stored workout and the live original stay separate records, because the public stored -workout has no vendor id. That split is part of this proposal. D215 is the +workout has no vendor id. That split is part of this proposal. D244 is the privacy choice, and the maintainer can change it before approval. Reviews of earlier heads were incorporated here. None of those reviews approves this revision. The next head needs re-review. An earlier review accepted a migration with no new column, under D152 and D184. That acceptance does not -adopt D198. The +adopt D227. The optional source key adds no column. 1. One number, 2.2.0. Readable sets keep `1.0.0`. Step 6 runs on create and @@ -1997,18 +2475,18 @@ optional source key adds no column. back on after every exit. A `2.1.1` database does not open until `ath migrate`. This release does not schedule a pull, add its own token refresh, backfill, or store a - cursor (D198, D208). A live read can still make the server refresh a - vendor token (D214). + cursor (D227, D237). A live read can still make the server refresh a + vendor token (D243). 2. Store the returned representations in section 2. Device receipts stay on device sources. Summaries without a device id use their own sensors. Null stays null. A missing response is not called provider-unavailable. - The omissions in section 2 are the ones with a reason (D203, D208). + The omissions in section 2 are the ones with a reason (D232, D237). 3. The key, the selected origin, and the selected user id are rejected in decoded JSON before a page is mapped. Failure text uses a fixed sentence. `ath key clear` with no name still clears only the gateway keys and says when the Open Wearables key remains. Named clear removes the saved key only. It does not unset the environment and it does not revoke the server - key (D200). + key (D229). 4. Preview is the default and its counts are estimates. `--json` does not write. `--yes` commits each successful page under D189, and a committed page is not a completed pull. The text of `--yes` shows retained counts @@ -2020,7 +2498,7 @@ optional source key adds no column. The receipt is the source key `device_binding`. A 2.1.0 supplied field of that name does not become the receipt. Unbound history is refused and left in place. `ath correct` and a native 2.2.0 package restore are the - owner's whole source record (D201). + owner's whole source record (D230). 5. The Windows cleanup and the maintainability notes stay separate. `src/import/mapping.rs` gains counts by record type, the open-wearables binding check, and the preservation writes in section 2. `src/store/write.rs` @@ -2030,4 +2508,4 @@ optional source key adds no column. writes in section 6, including the null filter in the calculation readers and the bounded archive safety read. The pull command owns the archive transaction and calls the store. `mapping.rs` does not start - it. Failed-init cleanup stays as it is (D202, D208). + it. Failed-init cleanup stays as it is (D231, D237). From c7a7c6e95078f45b0d1d849385f7a538545a3e66 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 04:08:25 +0000 Subject: [PATCH 17/60] Fit D230 and D231 to the 2.1.1 import preview and apply. A page is one preview_route and one ProviderPreview::apply. Timeouts and the response cap are the 2.1.1 values. The source rules go in src/import/provider.rs and a new src/import/binding.rs, and the protocol's record writes join the owner writes. Co-authored-by: Michael Whitham --- build-history/v2.2.0/decisions.md | 112 ++++++++++++++++++------------ 1 file changed, 69 insertions(+), 43 deletions(-) diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index cf8dea4e..8f8fec7a 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -369,18 +369,22 @@ Rejected alternatives: ## D230. A page is atomic, a missing row is not a deletion, and the same command is safe to repeat -Each response page is one `MappedReader` call. D189 still makes that call -one transaction: a failure rolls the page back, and a preview rolls the page -back after counting. The pull itself is a series of those calls. The order and the terminal -condition of each read are the table in the specification's section 2. -A committed -page follows D189. A committed page does not mean the pull is complete. +Each response page is one 2.1.1 import preview and, under `--yes`, one +apply. `preview_route` in `src/import/provider.rs` stages and matches the +page in one read transaction, at one database revision, and never writes. +`ProviderPreview::apply` writes that plan in one transaction, as D189 +requires. It refuses the plan when the database revision moved after the +preview. A failure writes nothing for that page. The pull itself is a +series of those pages. The order and the terminal condition of each read +are the table in the specification's section 2. A committed page follows +D189. A committed page does not mean the pull is complete. The command previews unless `--yes` is present. `--json` does not write, with or without `--yes`, matching `ath import --mapping`. `--yes` without `--json` writes each protected page as that page succeeds. A refused page is not a success. The pull-only archive in D237 is a separate -transaction. It reads the safety facts again before it writes. +preview and apply. It goes ahead only when the database revision has not +moved since the protected preview. The command returns one bounded outcome for the mode it ran. A preview, including public `--json`, has `written` false, protected and archive @@ -410,12 +414,12 @@ reconciliation, and a rerun cannot repair either one. A preview that fails makes no database changes, including for pages that had already been counted. -Before `MappedReader`, a cursor page and an offset page must be a JSON +Before `MappedPage`, a cursor page and an offset page must be a JSON object, `data` must be an array, `pagination` must be an object, and `has_more` must be a boolean. Anything else fails that page. It is not an empty success. Body may be one object or JSON `null`. `null` is a completed empty snapshot. The personal record is one object. The result keeps a -`left_out` total and at most 20 examples. +`left_out` total, a count for each reason, and at most 20 examples. An empty ranged result whose ranged reads completed has `range_complete` true. The personal record and the body snapshot can still be written. @@ -427,12 +431,15 @@ runs the failed read again, and runs any read that was `not_attempted`. `has_more: false` is the successful end of a cursor read and of the offset read. A repeated cursor, a null cursor while `has_more` is true, and the 1000-page cap fail that read. An offset retry uses the same offset. A body -over 8 MiB is handled by D233. The failed page is not written. Later reads -are `not_attempted`. The success line is not printed. A cursor with the +over the response cap, `MAX_PULL_RESPONSE_BYTES` in `src/input_policy.rs`, +is handled by D233. The failed page is not written. Later reads are +`not_attempted`. The success line is not printed. A cursor with the `prev_` prefix is not sent. `limit` starts at 1000. One attempt is made per -request, except the smaller page D233 sends after a local size cap. A -transport error is not retried. -The connect timeout is 10 seconds and the read timeout is 30 seconds. +request, except the smaller page D233 sends after the response cap. A +transport error is not retried. The stored reads use a 30-second connect +timeout and a 120-second read timeout, the values +`src/runtime/garmin_pull.rs` uses. Live vendor requests use 30 and 360 +seconds, for the reason in D243. Each timeout is a named constant. A row that this range did not return is left where it is. The pull does not call `DELETE`. There is no deletion feed on these reads. Absence can be @@ -492,42 +499,57 @@ named no later version. Version 2.1.1 did not take that work. The cleanup does not run on a pull. This build does not change it. D237 rolls a failed step 6 back before this cleanup runs. -`src/import/mapping.rs` is 1703 lines. The store is already several files. -`src/store/mod.rs` is 848 lines, `src/store/write.rs` is 508, -`src/store/encode.rs` is 549, and `src/store/check.rs` is 1044. -`persist.rs` is gone. The pull is a new module so `mapping.rs` and the -store files do not grow for HTTP. `mapping.rs` may add the count by record -type that D228 names, and the open-wearables device-binding check in the -specification. That check is shared by mapped import and pull, and it is -limited to route `open_wearables`. D232 also adds the measurement-sample -target, the reporting-window write, and the segment copy. Nothing beyond -that is added to `mapping.rs`. Source writes go through `Store::apply` in -`src/store/write.rs`. There is no `Store::revise`. A correction carries the -whole record. The receipt rule is unchanged. A write that is not the -owner's whole source record cannot set, change, or clear `device_binding`. -`Store` keeps its connection private. `write.rs` may also read the receipt -and tombstone-inclusive history, create a source with the checked receipt, -and write that receipt on an existing unbound source only when the same -transaction shows no accepted or deleted record and no source device. Those -writes keep every other source field and the normal revision and `data_json` -bookkeeping. They join the caller's `BEGIN IMMEDIATE` transaction. D233 -also allows `measurement_sample` insert and update, and a null value and -unit pair on provider summaries and provider scores. A half-null pair is -refused. `write_current_state` in `src/store/encode.rs` is the only +`src/import/mapping.rs` is 1703 lines and `src/import/provider.rs` is +1297. The store is already several files. `src/store/mod.rs` is 848 +lines, `src/store/write.rs` is 508, `src/store/encode.rs` is 549, and +`src/store/check.rs` is 1044. `persist.rs` is gone. The pull is a new +module so `mapping.rs` and the store files do not grow for HTTP. +`mapping.rs` may add `MappedPage`, which D228 names, and the +`vendor_workout` section, which D242 names. D232 also adds the +measurement-sample target, the reporting-window write, and the segment +copy. Nothing beyond that is added to `mapping.rs`. + +Version 2.1.1 stages, matches, and applies a keyed import in +`src/import/provider.rs`. A keyed import there only creates sources. It +never revises one. So the source rules go there, not in +`src/store/write.rs`. The matching step runs the open-wearables +device-binding check and reads the page's safety snapshot. Both live in a +new file, `src/import/binding.rs`, so `provider.rs` grows little. That +check is shared by mapped import and pull, and it is limited to route +`open_wearables`. The staged plan may create a source with the checked +receipt. It may write that receipt on an existing unbound source only when +the snapshot shows no accepted or deleted record and no source device. +That first bind is a source correction with the source's expected +revision. `ProviderPreview::apply` refuses any other staged change to +`device_binding`. Those writes keep every other source field and the +normal revision and `data_json` bookkeeping. `provider.rs` also gains the +crate-private read of a stored vendor original that D243 uses. + +`Store::apply` in `src/store/write.rs` writes a whole record. There is no +`Store::revise`, and a correction carries the whole record. The owner and +library writes store a whole source record: `ath correct`, the protocol +operations `records.write`, `records.write_changes`, and `records.correct`, +native package restore, and an accepted package merge. They keep the +receipt the caller supplied. `Store` keeps its connection private (D223). +D233 also allows `measurement_sample` insert and update, and a null value +and unit pair on provider summaries and provider scores. A half-null pair +is refused. `write_current_state` in `src/store/encode.rs` is the only record-to-table mapping. Package restore, repair, and the record check use it. There is no TypeScript writer to update. D234 also allows `source_report` insert and update, and withdrawal of a child whose anchor is in this response. Nothing beyond that is added to the store. Other -routes do not call the receipt operations. `ath correct`, package restore, -and an accepted package merge remain the owner's whole source record. -Splitting `mapping.rs` is separate work. It is not required to make the pull -correct. +routes do not call the receipt operations. Splitting `mapping.rs` is +separate work. It is not required to make the pull correct. + +`ath key clear garmin` is refused in 2.1.1, because `key_clear` in +`src/cli/commands/model.rs` accepts only gateway names. D229 keeps that. +Making the Garmin key removable is separate work. `check_supplied_fields` is in `src/import/shared.rs`. A keyed import calls it before it builds a candidate (D191). There is no `persist.rs` and no -`ath-core persist` command. The pull writes through `MappedReader` and -the store, so the import check covers it. A name check outside import is -separate work. +`ath-core persist` command. The pull writes through `MappedPage` and the +2.1.1 import, so the import check covers it. A name check outside import +is separate work. `is_mapping_path` exists once, in `src/assets/mod.rs`. The pull uses `resolve_mapping` in that file. There is no second path rule to remove. @@ -539,6 +561,10 @@ Rejected alternatives: what the pull writes, and the maintainer asked not to widen this build. - Block the pull on those fixes. Rejected for the same reason. A later change can take any one of them on its own. +- Put the source rules in `Store::apply`. Rejected. In 2.1.1 every + `Store::apply` caller that can write a source is an owner or library + write, and the one automatic source writer is `ProviderPreview::apply`. + A rule in `Store::apply` would also block the owner's own correction. ## D232. Stored Open Wearables measurements are kept in this pull From 5af3fd7fe303d8283f043f2c9b3892a88ea240ed Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 04:09:55 +0000 Subject: [PATCH 18/60] Fit D232 to D237 to the 2.1.1 migration and revision check. The new migration step is step 6, and step 6 runs on the store's own connection with foreign keys off. The response cap is 10 MiB. D237 now lets the archive go ahead only at the database revision where the protected preview read the safety facts, instead of reading them again under a second write lock. Co-authored-by: Michael Whitham --- build-history/v2.2.0/decisions.md | 110 +++++++++++++++++------------- build-history/v2.2.0/spec.md | 2 +- 2 files changed, 64 insertions(+), 48 deletions(-) diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index 8f8fec7a..12deb6b8 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -590,7 +590,7 @@ period type `open_wearables_reporting_window`. `recorded_at` is unset. `ProviderReportingPeriodType` gains that one value. `ValueBasis` gains `aggregator`, used when `computed_by` is `open_wearables`. Series quantities gain the missing pinned types. `quantity` is already an -unconstrained text column, so those names add no SQL column. Step 5 +unconstrained text column, so those names add no SQL column. Step 6 rebuilds `provider_summaries` so `standard_value` and `standard_unit` can be null together. Existing summary rows are copied with their numbers. The device receipt still adds no column. The receipt, the transaction, @@ -611,7 +611,7 @@ Rejected alternatives: - Store a day row as a point at the period start. Rejected. That would make a reporting window look like one instant (D88, D110). - Drop latitude, longitude, segments, or a large series to keep a - response under 8 MiB. Rejected. The smaller page in the specification + response under the response cap. Rejected. The smaller page in the specification stores the rows. D233 states the minimum-page limit without naming a series type. - Call the live provider workout proxy or the totals routes so the pull @@ -668,7 +668,7 @@ gender values, or a source. Cursor pages, offset pages, and the two one-shot reads have the terminal conditions in the table. A smaller page repeats the same uncommitted cursor or offset. A minimum page or an unpaginated response that is still -over 8 MiB is an incomplete read. The message names the read. It does not +over the response cap, 10 MiB, is an incomplete read. The message names the read. It does not name a series type. Menstrual cycles keep an in-range start and a future end. A later start is not stored. The page is still followed to the end. @@ -831,9 +831,9 @@ This corrects D234. The returned health data stays in this pull. The specification is the contract. `records.record_type` is a closed check. `source_report` is not in it. -Creating `source_reports` does not make a root row insertable. Step 5 +Creating `source_reports` does not make a root row insertable. Step 6 adds `source_report` to that check in the generated contract. It does -not edit migrations 001 through 004, and it does not drop the check. +not edit migrations 001 through 005, and it does not drop the check. Ordinary writes keep foreign keys on. The migration connection may turn them off only before its own transaction, rebuild `records` and the two nullable typed tables by copy, rename, and recreate, then require @@ -868,11 +868,11 @@ it is not archived. reports. They are not sessions and not manual reports. The same server id with a different kind refuses the page. -A protected refusal rolls back. For a missing device id on a -device-targeted series row, and for unequal null-source payloads of one -full match key, a later archive transaction stores kind `original` with -no amount and no device receipt. D237 is when that transaction may -write. D236 is the capsule and the command counts. `written` stays false when only the archive +A refused protected page is not applied, so it writes nothing. For a +missing device id on a device-targeted series row, and for unequal +null-source payloads of one full match key, a later archive preview and +apply stores kind `original` with no amount and no device receipt. D237 +is when that archive may write. D236 is the capsule and the command counts. `written` stays false when only the archive changed. The command exits nonzero. Credential failures, invalid ids, conflicting device ids, legacy history, and kind changes are not archived. Those originals are @@ -896,7 +896,7 @@ Rejected alternatives: - Treat unknown provenance as automatic when a device id is present. Rejected. The id is not a measurement label. - Archive every refused page, or write the archive inside the refused - transaction. Rejected. The first keeps rejected secrets and rejected + page's apply. Rejected. The first keeps rejected secrets and rejected devices. The second stores the refused write. - Drop the originals of a missing device id so the refusal stays one transaction. Rejected for the two reasons above. The archive is a @@ -914,27 +914,31 @@ proposal disagrees with D237, D237 is the proposal. This corrects D235. The returned health data stays in this pull. The specification is the contract. -Step 5 drops `sql_v1_current_records`, `sql_v1_active_records`, and the +Step 6 drops `sql_v1_current_records`, `sql_v1_active_records`, and the two `record_revisions` triggers that read `records` before it drops `records`. It recreates them from the `001` text after the new root exists, in the same transaction. Foreign keys are turned off only before -that transaction, on a connection ordinary writes do not reuse. After -every exit the connection reads `foreign_keys` back as on, or it is -closed. A failure before commit restores the old schema, the old rows, +that transaction, on the store's own connection, in +`src/store/migrate.rs`. No ordinary write can run while they are off, +because `write_transaction` refuses one. After every exit the connection +reads `foreign_keys` back as on, or the command fails and closes the +store. A failure before commit restores the old schema, the old rows, and the old version. `writable_schema` is not used. Files 001 through -004 stay unchanged. +005 stay unchanged. `written` counts protected creates and revisions across the command. An archive-only change leaves it false and sets `database_changed` true. Archive counts are separate from protected counts. A later page does not -clear either. A failed archive transaction keeps the refusal, rolls -itself back, and leaves earlier commits. The pull text for a new +clear either. A failed archive apply keeps the refusal, writes nothing, +and leaves earlier commits. The pull text for a new archive-only change is `Protected write refused; N originals archived; database changed; pull incomplete.` -D237 reads database-dependent vetoes inside the protected transaction -and reads them again before any archive write. A veto there, including -on a `left_out` row, forbids the archive. The privacy scan still comes +D237 reads database-dependent vetoes in the protected preview, at one +database revision. The archive goes ahead only at that same revision. A +veto there, including on a `left_out` row, forbids the archive. A deleted +source or a deleted record leaves its rows out (D182, D190) and also +forbids the archive. The privacy scan still comes first. The archive is pull-only. A mapped file import does not gain it. A deleted archive source is not recreated, and the archive writes no device receipt. @@ -964,46 +968,58 @@ Rejected alternatives: - Hash the series row and infer the resolution later. Rejected. The resolution is on the response, not on the row. -## D237. The archive reads safety facts under the write lock +## D237. The archive goes ahead only at the revision where the safety facts were read This corrects D236. The returned health data stays in this pull. The -specification is the contract. +specification is the contract. The first version of this decision read +the safety facts under one write lock and read them again under a second +one. Version 2.1.1 has no write-locked preview, so this version uses the +2.1.1 revision check instead. Privacy, required ids, and supplied-field names are checked on the -returned page before either transaction. A failure starts neither -transaction. +returned page before either preview. A failure builds neither preview. Receipts, bindings, history, source deletion, stored records, import -keys, tombstones, null-source payloads, and workout kinds are read -inside the protected `BEGIN IMMEDIATE`, before any mutation. The read +keys, tombstones, null-source payloads, and workout kinds are read in the +protected preview. `preview_route` in `src/import/provider.rs` reads +them in one read transaction, at one database revision. The read includes a row the mapping would leave out. That read is the safety snapshot. A veto in it refuses the protected page, and the archive is -not attempted. An unlocked read from before that transaction is not the -snapshot. - -The archive transaction then takes its own `BEGIN IMMEDIATE`. Before it -inserts a source or a capsule, it reads those facts again, and it reads -the archive source and the target capsules, including tombstones. A new -veto or a safety fact that differs from the snapshot sets `archive` to -`not_attempted` and writes nothing. A deleted source or a deleted record -is not copied onto a new archive identity. A deleted archive source is -not recreated. A deleted capsule is not replaced. If the page names a -row the bounded read cannot cover, the page is not archived. There is -no retry. +not attempted. A deleted source or a deleted record leaves its rows out +(D182, D190), and it also stops the archive of that page. A read from +before that preview is not the snapshot. + +The archive is a second preview and apply. Its preview reads the archive +source and the target capsules, including tombstones. It is built only +when the database revision still equals the snapshot's revision. Its +apply refuses a moved revision, as every 2.1.1 apply does. Every +athlete-data write in 2.1.1 moves that revision. A restore into an empty +database instead sets a new database ID, and the apply refuses another +database ID. So a binding, a deletion, or an owner correction made after +the snapshot sets `archive` to `not_attempted`, and the archive writes +nothing. A deleted source or a deleted record is not copied onto a new +archive identity. A deleted archive source is not recreated. A deleted +capsule is not replaced. If the page names a row the bounded read cannot +cover, the page is not archived. There is no retry. A failed step 6 during init rolls back to the committed step 5 schema before the existing init cleanup runs. Init fails. D231's cleanup is -unchanged. A migrate of an existing database keeps that file and the old -schema when step 6 rolls back. +unchanged. A migrate of an existing 2.1.1 database keeps that file and +schema 5 when step 6 rolls back. An older database keeps the steps that +committed before step 6, as D227 says. Rejected alternatives: -- Use an unlocked preflight as the archive decision. Rejected. Another - command can bind the source before the protected transaction, and the - protected veto would then be stored. -- Recheck only the archive source after the protected rollback. - Rejected. The owner can delete the original source or record in - between, and the payload would be stored under a new identity. +- Read the safety facts again under a second write lock, as the first + version of this decision did. Rejected. The revision check already says + whether anything changed after the snapshot. A second read would repeat + that check in new code. +- Use a read from before the protected preview as the archive decision. + Rejected. Another command can bind the source before that preview, and + the protected veto would then be stored. +- Recheck only the archive source before the archive. Rejected. The owner + can delete the original source or record in between, and the payload + would be stored under a new identity. - Leave a failed init file at step 5. Rejected. The existing caller removes that file, and this build does not change that cleanup. diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index 8e06c0b6..7ecb71eb 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -1726,7 +1726,7 @@ interactive open can preview, back up, ask, and then migrate. | Flags, key, preview text, refusal if the key appears | `src/cli/`, `src/cli/help.rs`, `src/runtime/keyring.rs`, and `key_clear` in `src/cli/commands/model.rs` | | Reader for one decoded page | `MappedPage`, beside `MappedReader` in `src/import/mapping.rs` | | Mapping names and field rules, including the `vendor_workout` section | the existing file `mappings/open-wearables.md` | -| Stage, match, and write each page | `preview_route` and `ProviderPreview::apply` in `src/import/provider.rs` | +| Stage, match, and write each page | `preview_route` and `ProviderPreview::apply` in `src/import/provider.rs`, with a crate-private accessor for the revision a preview read | | Device-binding facts and the safety snapshot | new `src/import/binding.rs`, called from the matching step in `src/import/provider.rs` for route `open_wearables` | | Create or first-bind with the checked receipt, and refuse any other `device_binding` change | the staged plan and `ProviderPreview::apply` in `src/import/provider.rs` | | Stored-original read for the vendor detail rules | a crate-private read in `src/import/provider.rs` | From cfb0687149159273d627cd450547e657a0fdd5bc Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 04:11:35 +0000 Subject: [PATCH 19/60] Amend D242 to D244 for the review findings at e145fa6. D242 states the stored original's JSON layout, its key, its counts, the named vendor_workout mapping section, and what owner deletion and correction do. D243 checks and drops the connections list, calls only active connections, keys Suunto detail by workoutKey, never loses a stored detail, separates failed from deferred, warns on every flagged run, waits out the server's retries, budgets requests, and spells ids and starts. D244 withholds a credential-shaped value instead of refusing the page. Co-authored-by: Michael Whitham --- build-history/v2.2.0/decisions.md | 178 +++++++++++++++++++++++++----- 1 file changed, 152 insertions(+), 26 deletions(-) diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index 12deb6b8..b763ee67 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -1148,6 +1148,43 @@ joined to the stored session by time. The public stored workout has no inside the original. They do not set `device_binding`, and they are not measurement samples. Calculations do not read the original. +Each original is one envelope. It holds `provider`, `vendor_id` as text, +`start` and `start_kind` when the object has a start, `list`, `detail` +when a detail is stored, and `detail_status`. Sensorbio adds +`list_parent`. The specification's section 2 shows the JSON. The whole +envelope is kept in `supplied_fields`, and `provider_record_id` is +`vendor_id`. The match key is the writer, the sensor, the resource +`vendor_workout`, the provider, and the vendor id, escaped by D181. + +The rewritten `mappings/open-wearables.md` gains a section named +`vendor_workout`. It declares the record type, the kind, the subject, the +writer, the sensor, the key, and the start. A saved file of envelopes +imports through that section. File import writes each envelope as the +file holds it, as D182 does for every mapped import. The detail rules in +D243 run before the mapping engine sees an envelope, so the mapping +engine has no vendor exception. + +The pull writes one provider's originals as one page, after that +provider's list and detail calls finish. That page is one preview and, +under `--yes`, one apply, as D230 says for every page. A vendor page +never holds a stored row or an archive capsule. A failed or refused +vendor page leaves that provider `incomplete`. It does not change the +stored pages or the archive. + +The vendor page uses the 2.1.1 keyed rules. An original the person +deleted is left out on every later pull and is not recreated (D182). A +deleted `vendor_workout` source leaves out every object from that +provider (D190). An original the person corrected gains a revision with +the server's envelope when a later envelope differs, because a mapped +import replaces the whole object (D182). The person's revision stays in +the history. To keep a pull from changing an original, the person +deletes it. + +Each provider's line counts originals as new, changed, and unchanged. It +counts details by outcome, objects left out by reason, and withheld +values. Each listed object is in exactly one detail count or one left-out +count, so no object is dropped without a count. + The pull uses the published query parameters and does not add its own retry. It does not call sync or historical sync. A completed provider line means that provider's stated limit was reached. It does not mean the @@ -1163,6 +1200,13 @@ Rejected alternatives: them. - Call sync or historical sync to fill the gap. Rejected. Those routes are writes this pull does not call. +- Store the list object and the detail as two records. Rejected. They + describe one workout, and nothing in either object joins them except + the id the envelope already uses. +- Keep an owner correction when a later pull differs. Rejected for this + release. A 2.1.1 keyed import replaces a changed object and keeps the + history, on every route. A protection rule would be new import behavior + for all of them. Deleting the original keeps a pull from changing it. ## D243. A live vendor read is opt-in, and one failure stays on that provider @@ -1171,44 +1215,104 @@ the server, that a failed provider stops the later providers, that Polar's list asks for samples, zones, and route, that a start outside the range is dropped, and that the server splits a Garmin range. +On 15 November 2026 this decision was revised for the review at +`e145fa6` and for 2.1.1. The specification's section 2 is the full +procedure. + `--vendor-workouts` is off unless the person passes it. Off, preview and `--json` call neither the connections route nor a live workout route. On, those calls run for a preview too. The preview writes nothing in this -database and prints `vendor requests were made`. +database and prints `vendor requests were made`. "Nothing stored" and +"nothing written" always mean this database. The server, while answering the GET, can save a refreshed vendor token, revoke a connection, emit `connection.revoked`, write `token_refresh_lock` and `provider_auth_failing_since`, and on HTTP 429 sleep 15, then 30, then 60 seconds, up to three retries. This program does not add a retry -of its own. - -The pull reads `GET /users/{id}/connections` and calls only a connected -provider that has a live list method. The order is Garmin, Polar, Suunto, -Whoop, Fitbit, Oura, Strava, Withings, Sensorbio. A provider that is not -connected, and a connected provider with no live list method, is -`not_attempted`. One failure leaves that line `incomplete`. The others -still run. - -Garmin is split by this program into windows of 24 hours or less, one -call each, with a 120 second read timeout. Any failed window makes Garmin -`incomplete`. Polar's list omits samples, zones, and route. Detail asks -for all three. One combined object is written once per command. A second -identical pull changes no row. A thinner object does not replace a richer -stored original. A failed detail keeps the list object. +of its own. Every run with the flag says, before its first live request, +that the server may refresh and save vendor tokens, may revoke a +connection, and may wait about 105 seconds on a rate limit. That holds +for a preview, for `--yes`, and for `--json`, which puts the three +sentences in `vendor_workouts.notice`. The flag's help text says the +same. + +The pull reads `GET /users/{id}/connections` first. Each item's `user_id` +must be the selected user, or the list is refused. The pull keeps only +`provider` and `status` from each item. It drops the rest, including +`linked_user_ids`, which holds other users' ids. The list is never +stored, so the privacy scan does not run on it. A provider is called only +when its status is `active` and it has a live list method. `revoked`, +`expired`, a missing item, and an unknown status are `not_attempted`, and +the line shows the status. Those providers are never called, because a +call could make the server try a refresh or a revoke. The order is +Garmin, Polar, Suunto, Whoop, Fitbit, Oura, Strava, Withings, Sensorbio. +One failure leaves that line `incomplete`. The others still run. + +Garmin is split by this program into windows of 86,400 seconds or less, +one call each. Each window sends integer Unix seconds. Any failed window +makes Garmin `incomplete`. The pinned code calls Garmin detail at +`/wellness-api/rest/activities/{activity_id}`. This study did not find +that path in Garmin's public docs, so a failed Garmin detail is counted +like any other. Polar's list omits samples, zones, and route, and detail +asks for all three. Suunto's detail is called at `workoutKey` when the +list object has one, and at `workoutId` otherwise. Its `payload` is +unwrapped, and the record key is `workoutId`. Whoop's response names its +next page `next_token`. The request name, `nextToken`, is not sent. +Sensorbio reads only the oldest 50 entries, and its line says so. + +A stored detail is never lost. A detail is fetched for an id with no +stored detail, and again only when the list object changed. A list-only +object never replaces a stored detail. A new detail that is thinner than +the stored one writes nothing. Thinner means a detail field the +specification's table names for that provider is filled in the stored +detail and empty in the new one. A deferred or failed detail keeps the +stored detail and adds no revision. A failed or mismatched detail makes +the provider `incomplete` and the exit nonzero. A deferred detail leaves +the provider `completed`, with a separate deferred count. + +Live requests go one at a time, at least one second apart. The read +timeout is 360 seconds. The server's own retries can take about 225 +seconds, so the client waits for them. A live request that still times +out ends that provider for the command, so two requests to one provider +never overlap. A command makes at most 100 detail calls to one provider +and at most 20 to Strava. Ids with no stored detail go first, oldest +start first. Strava's limit belongs to the whole application, so the +deployment's own sync shares it. The review cited about 100 requests a +minute for Garmin. This study did not find that number in Garmin's public +docs. The one-second pace keeps this command at 60 a minute or fewer. + +A vendor id is text. A JSON integer is written in decimal, so `123` and +`"123"` are one id. An integer above 9007199254740991 is refused, because +D213 would change its digits. The start becomes `input_timestamp` by the +rules in the specification: text keeps its offset or says it has none, +and Unix seconds or milliseconds keep their digits. The start is stored +and is not a filter. Every returned original is stored, including a start outside `--from` and `--to`. The count is `vendor workout originals`. `range_complete` uses only the stored ranged reads. Each line says whether its limit covers the -requested range and whether more data exists. Strava detail stops at 20 -calls per command. Later ids are deferred. Their list objects are stored. +requested range and whether more data exists. An object the pull does not +write is counted by reason. -The unwrap, the id, and the start field for each provider are the table -in the spec. File import uses the same envelope. The provider logic lives -in `src/runtime/vendor_workouts.rs`, driven by one table. +The unwrap, the id, the start field, the detail key, the detail unwrap, +the detail fields, the budget, and the read timeout for each provider are +the table in the spec. File import uses the same envelope. The provider +logic lives in `src/runtime/vendor_workouts.rs`, driven by one table. `src/runtime/open_wearables.rs` calls that module. Rejected alternatives: +- Call every provider the server lists. Rejected. A call to a revoked or + expired connection can make the server try a refresh or a revoke. +- Store the connections list. Rejected. It holds other users' ids, and it + is not health data. +- Write the list object over a stored detail when the new detail fails or + is deferred. Rejected. The person would lose data they already have. +- Use a 30-second read timeout. Rejected. The server's own retries take + longer. The client would give up, and a rerun could send a second + request while the first still runs. +- Retry a live request that timed out. Rejected for the same reason. + - Leave live reads on by default. Rejected. The server can change a token and revoke a connection while answering the GET. - Stop the later providers after one failure. Rejected. A person connected @@ -1225,17 +1329,39 @@ Rejected alternatives: This is a labeled choice. The default in this proposal is to keep each vendor object whole, including account ids, Polar user URLs, and full GPS routes. The reason is a complete, portable copy of what the vendor -returned. The output and the spec say those fields are included. +returned. The output and the spec say those fields are included. Only a +credential-shaped value is withheld, as the next paragraphs say. The scan still refuses the API key, the selected origin, and the selected -user id. It also refuses an object key whose letters, after dropping `_` -and `-` and ignoring case, are `useraccesstoken`, `accesstoken`, -`refreshtoken`, `apikey`, `authorization`, `password`, `secret`, or -`clientsecret`. `polar_user` and a coordinate are not those keys. +user id, wherever they appear. That includes a value under a +credential-shaped key. + +A credential-shaped key does not refuse the page. Its value is withheld. +The value is replaced by the text `[withheld by ath]`, and the pull +records the JSON path and counts it. A key is credential-shaped when its +letters and digits, with case ignored and every other character dropped, +end in `token` or `secret`, or are `apikey`, `authorization`, or +`password`. A query parameter with such a name inside a URL string is +withheld the same way, and the URL keeps its address. `polar_user` and a +coordinate are not credential-shaped. The rule covers stored reads and +vendor reads alike. + +Garmin's list objects can carry an optional `userAccessToken`. Refusing +the page would refuse every such Garmin page, and the workouts on it +would be lost. Withholding keeps the workout and keeps the vendor's token +out of the record. The stored original then differs from the vendor's +object only at the withheld paths, and the count says how many there +are. The maintainer can change the key list or the marker before +approval. Rejected alternatives: - Strip account ids, user URLs, and routes before storage. Not chosen. The stored object would no longer be the object the vendor returned. The maintainer can replace this decision before approval. +- Refuse the whole page when a credential-shaped key appears, as the + first version of this decision did. Rejected. One optional Garmin field + would block every Garmin page, and the person would lose those workouts. +- Drop a credential-shaped field without a marker. Rejected. The stored + original would not show that a value was removed. From 89ddede48f560ae672a6b55343b526ef03c79a12 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 04:12:47 +0000 Subject: [PATCH 20/60] Update the 2.2.0 risks and approval list for 2.1.1 and the vendor read. The risks name the 10 MiB cap, the partial migrate of an older database, server-side effects of a live read, the shared Strava limit, the unverified Garmin detail path, owner corrections a later pull replaces, and deferred ids that stop being listed. The approval list follows the 2.1.1 code places, fixes two citations, and adds the vendor read. Co-authored-by: Michael Whitham --- build-history/v2.2.0/spec.md | 85 ++++++++++++++++++++++++------------ 1 file changed, 57 insertions(+), 28 deletions(-) diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index 7ecb71eb..4c80a13b 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -2421,10 +2421,28 @@ Risks: tested against the stored fixture. That fixture is not a live response, and a live timestamp without an offset is left out. A breaking envelope needs a new fixture before the pull trusts it. -- A raw range can be large. A page over 8 MiB is read again with a smaller - limit. A 429 or another transport failure still stops that read, keeps - earlier pages, and withholds the success line. The study did not read the - rate-limit middleware. +- A raw range can be large. A page over the response cap, 10 MiB, is read + again with a smaller limit. A 429 or another transport failure still + stops that read, keeps earlier pages, and withholds the success line. The + study did not read the rate-limit middleware. +- A failed step 6 on a database older than 2.1.1 leaves it at 2.1.1, + because the earlier steps committed first. The message says so and names + the verified backup, and a second `ath migrate` finishes. Step 6 needs + foreign keys off, and the earlier steps run with them on, so they cannot + share one transaction. +- A live read can change the server. It can refresh a token, revoke a + connection, or wait on a rate limit. The command says so before its + first live request. It cannot stop the server from doing it. +- Strava's limit is shared with the deployment's own sync. One command can + use most of a 15-minute window. +- The pinned Garmin detail path and the cited Garmin rate were not found + in Garmin's public docs. If the path does not exist, Garmin details show + as `failed`, and Garmin is `incomplete`. +- A later pull replaces an owner correction of a vendor original when the + server's envelope differs. The correction stays in the history. Deleting + the original stops it. +- A deferred id that the provider stops listing is never detailed. Its + list object stays stored, and the deferred count shows that it waits. - Date-only bounds mean whatever Open Wearables decides. The docs and the 0.11.0 parser disagree about UTC. This release does not correct that server. - Section 2 stores returned periods, series, and snapshots. It does not @@ -2444,11 +2462,14 @@ the `source_report` type and table, the paired null value and unit, and the time-unknown summary. The point check in `src/model/data.rs` and the mapping's positive check accept a finite `hr_recovery`, including zero and a negative number. `packages/npm/src/schema.ts` is not where that check is -added. No table is rebuilt for that check. Then the store, the calculation null filter, -the archive transaction, and the record paths in section 6. Then the -mapping engine and `mappings/open-wearables.md`. Then the reads, the -cycle filter, the smaller-page split, and the tests in section 7. The laptop card and the phone proof are -part of that same pull request. This plan pull request has no media. +added. No table is rebuilt for that check. Then the store, the +calculation null filter, the staging and apply changes in +`src/import/provider.rs` and `src/import/binding.rs`, the archive, and the +record paths in section 6. Then the mapping engine, `MappedPage`, and +`mappings/open-wearables.md`. Then the stored reads, the vendor read, the +cycle filter, the smaller-page split, and the tests in section 7. The +laptop card and the phone proof are part of that same pull request. This +plan pull request has no media. The maintainer approves or rejects this plan before any build. D227 through D244 are the proposal. They are not adopted. The stored workout and the @@ -2470,23 +2491,24 @@ optional source key adds no column. together. Existing ids and rows are copied. Before the root rename, step 6 drops and later recreates `sql_v1_current_records`, `sql_v1_active_records`, and the two `record_revisions` triggers that - read `records`. Foreign keys stay on for ordinary writes. The step 6 - connection turns them off only before its transaction and reads them - back on after every exit. A + read `records`. Foreign keys stay on for ordinary writes. Step 6 turns + them off on the store's own connection, only before its transaction, + and reads them back on after every exit. A `2.1.1` database does not open until `ath migrate`. This release does not schedule a pull, add its own token refresh, backfill, or store a - cursor (D227, D237). A live read can still make the server refresh a - vendor token (D243). + cursor (D227). A live read can still make the server refresh a vendor + token (D243). 2. Store the returned representations in section 2. Device receipts stay on device sources. Summaries without a device id use their own sensors. Null stays null. A missing response is not called provider-unavailable. - The omissions in section 2 are the ones with a reason (D232, D237). + The omissions in section 2 are the ones with a reason (D232, D235). 3. The key, the selected origin, and the selected user id are rejected in decoded JSON before a page is mapped. Failure text uses a fixed sentence. `ath key clear` with no name still clears only the gateway keys and says when the Open Wearables key remains. Named clear removes the saved key only. It does not unset the environment and it does not revoke the server - key (D229). + key (D229). A credential-shaped value is withheld and counted. It does + not refuse the page (D244). 4. Preview is the default and its counts are estimates. `--json` does not write. `--yes` commits each successful page under D189, and a committed page is not a completed pull. The text of `--yes` shows retained counts @@ -2497,15 +2519,22 @@ optional source key adds no column. a later command or in a mapped file import, including import then import. The receipt is the source key `device_binding`. A 2.1.0 supplied field of that name does not become the receipt. Unbound history is refused and - left in place. `ath correct` and a native 2.2.0 package restore are the - owner's whole source record (D230). -5. The Windows cleanup and the maintainability notes stay separate. - `src/import/mapping.rs` gains counts by record type, the open-wearables binding - check, and the preservation writes in section 2. `src/store/write.rs` - gains the receipt refusal, the receipt and tombstone read, creation with - the checked receipt, and the first bind of an existing source that has - no history, and the sample, source-report, withdrawal, and paired-null - writes in section 6, including the null filter in the calculation - readers and the bounded archive safety read. The pull command owns the - archive transaction and calls the store. `mapping.rs` does not start - it. Failed-init cleanup stays as it is (D231, D237). + left in place. `ath correct`, the protocol record writes, and a native + 2.2.0 package restore are the owner's whole source record (D230, D231). +5. The Windows cleanup, the Garmin key removal, and the maintainability + notes stay separate. `src/import/mapping.rs` gains `MappedPage`, the + `vendor_workout` section, and the preservation writes in section 2. + `src/import/provider.rs` gains the staged first bind, the + `device_binding` refusal in `ProviderPreview::apply`, and the + stored-original read. The new `src/import/binding.rs` holds the binding + check and the bounded safety snapshot. `src/store/encode.rs` gains the + sample, source-report, withdrawal, and paired-null writes in section 6, + and `src/calculate/range.rs` gains the null filter. The pull command + builds the archive preview and applies it only at the snapshot's + revision. `mapping.rs` does not start it. Failed-init cleanup stays as + it is (D231, D237). +6. The live vendor read is off by default and warns before its first + request. It calls only active connections and never stores the + connections list. It keeps every stored detail, counts every object it + does not write, and withholds credential-shaped values. The stored + workout and the vendor original stay two records (D242, D243, D244). From ff1cc5af0313ec2d81832070aad1e0ec4e4eb640 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 04:19:39 +0000 Subject: [PATCH 21/60] Record the 15 November Open Wearables checks and use 23-hour Garmin windows. The appendix records the connection fields and statuses, the route's parameters, the client's retries and timeout ceiling, Suunto's detail key, Whoop's and Sensorbio's single page, Strava's detailed fields and per-application limits, and the Strava tier wording. The pinned Garmin method measures a window in naive local time, so a 24-hour window can look 25 hours long on a server whose clock moves forward. The plan now sends 23-hour windows. The userAccessToken sentence now says what the pinned code shows. Co-authored-by: Michael Whitham --- .../v2.2.0/appendix/open-wearables-api.md | 91 ++++++++++++++++++- build-history/v2.2.0/decisions.md | 20 ++-- build-history/v2.2.0/spec.md | 32 ++++--- 3 files changed, 119 insertions(+), 24 deletions(-) diff --git a/build-history/v2.2.0/appendix/open-wearables-api.md b/build-history/v2.2.0/appendix/open-wearables-api.md index 25ef32ae..aed8fef0 100644 --- a/build-history/v2.2.0/appendix/open-wearables-api.md +++ b/build-history/v2.2.0/appendix/open-wearables-api.md @@ -134,7 +134,7 @@ schema. `zone_offset` is a separate string, `+01:00` or `-05:30`, or null. The 2.1.0 mapping file's timeseries lines do not name `heart_rate`. In Athletic Standard, `heart_rate` is a series quantity -(the unit table in `src/model/data.rs`). It is not one of the point +(`series_quantity_unit` in `src/model/data.rs`, unchanged in 2.1.1). It is not one of the point quantities the 2.1.0 mapping engine writes. D232 stores that stream as measurement samples. The 2.1.0 file, by itself, still has nowhere to put it. @@ -479,10 +479,13 @@ seconds and `MAX_RETRIES` is 3, so the waits are 15, 30, and 60 seconds. A nearby comment says 1, 2, and 4 seconds. The constant is 15. `GET /api/v1/users/{user_id}/connections` returns the user's connections. -The pinned Strava page lists 200 requests per 15 minutes for the standard -tier and 400 for extended access. Garmin's live method accepts upload +The pinned Open Wearables Strava page lists 200 requests per 15 minutes +for a standard tier and 400 for extended access. Those are Strava's +overall limits. The lower read limit, which covers every GET, is in the +15 November 2026 section below. Garmin's live method accepts upload start and end. A range the method itself splits can hide a failed chunk. -This plan has the client send windows of 24 hours or less instead. +This plan has the client send shorter windows instead. The 15 November +2026 section gives their length. Polar's live methods pass `samples`, `zones`, and `route` through to `/v3/exercises`. The save path calls the list method without those @@ -530,6 +533,80 @@ A route parameter that does not exist explains a provider page that cannot take this pull's range. A provider that has no live method is not an empty workout history. +## Checks on 15 November 2026 + +The live-route facts below were read again at commit +`183e8cc4f6de897dbd288c93d49a691f2cf721ae`, for the review findings and +for Athletic Standard 2.1.1. No server was called, and no vendor account +was used. + +Connections. `UserConnectionWithCapabilities`, in +`schemas/model_crud/user_management/user_connection.py`, has `user_id`, +`provider`, `provider_user_id`, `provider_username`, `scope`, `id`, +`status`, `last_synced_at`, `created_at`, `updated_at`, `icon_url`, +`max_historical_days`, `rest_pull`, four webhook flags, `live_sync_mode`, +and `linked_user_ids`. The route fills `linked_user_ids` with other users +linked to the same vendor account. `ConnectionStatus`, in +`schemas/auth/connection_status.py`, is `active`, `revoked`, or `expired`. + +Live routes. Both handlers in `vendor_workouts.py` return the provider +method's value unchanged. The list handler passes `since`, `limit` +(default 50, at most 100), `offset`, `filter_by_modification_time` +(default true), `samples`, `zones`, `route`, `summary_start_time`, and +`summary_end_time` to every provider. Each provider reads the ones it +uses. + +Client. `_make_api_request` in `api_client.py` makes at most four +attempts. Each attempt uses `provider_request_timeout_seconds`, which is +30 seconds by default and at most 300 in `config.py`. A 429 waits 15, then +30, then 60 seconds. A 401 reloads the token once and tries again. A +timeout or another transport error is not retried. A token refresh holds +`token_refresh_lock` for up to 60 seconds and waits up to 10 seconds for +it. So with the default timeout, one GET can take about 225 seconds, plus +a refresh. + +Garmin. `get_workouts_from_api` in `garmin_w.py` reads +`summary_start_time` and `summary_end_time` as an integer first, then as +ISO 8601. It turns both into naive local times with +`datetime.fromtimestamp` and compares them. A difference over 24 hours +goes to `get_workouts_historical`, which fetches 24-hour pieces and logs +and skips a piece that fails. On a server whose local zone moves its +clock forward, a true 24-hour window that crosses that change is 25 local +hours. So this plan sends windows of 82,800 seconds, 23 hours, or less. A +one-year range is 381 windows. Detail calls +`/wellness-api/rest/activities/{activity_id}`. This study did not find that +path in Garmin's public docs. `ActivityJSON` types `activityId` as an +integer or a string. The Garmin wellness models declare an optional +`userAccessToken`. `ActivityJSON` does not, but the live route returns +Garmin's objects unchanged. + +Suunto. `get_workout_detail` in `suunto_w.py` names its argument +`workout_key` and calls `/v3/workouts/{workout_key}`. The list method +reads `payload` and pages by `offset`, at most 100 a page. The route's +`filter_by_modification_time` defaults to true, so this plan sends false. + +Whoop. The method caps `limit` at 25, takes `nextToken` from the request, +and reads `next_token` in the response. The route never passes +`nextToken`, so one call reads only the first page. + +Sensorbio. The route's method sends `last-timestamp` 0 and `limit` at most +50, and returns that one response. It does not follow `links.next`, so it +reads the oldest 50 entries. + +Strava. `get_workouts_from_api` sends `page` 1 and `per_page` from +`strava_events_per_page`, which is 200 by default, and ignores `limit`. +Strava's API reference, fetched 15 November 2026, lists `DetailedActivity` +fields that include `laps`, `splits_metric`, `splits_standard`, +`segment_efforts`, `best_efforts`, `map`, `photos`, `gear`, +`description`, `calories`, and `embed_token`. It calls `embed_token` the +token used to embed a Strava activity. Strava's rate-limit page, +`https://developers.strava.com/docs/rate-limits/`, fetched the same day, +says limits are per application. The default overall limit is 200 +requests per 15 minutes and 2,000 a day. The default non-upload limit, +which covers every GET, is 100 per 15 minutes and 1,000 a day. After the +upgrade on the API settings page, the read limit is 200 and 2,000, and +the overall limit is 400 and 4,000. A request over a limit gets a 429. + ## What was not checked - A running server's JSON, including the exact `start_time` text. @@ -537,4 +614,10 @@ an empty workout history. - Whether Docker tag `latest` matches release `0.11.0` or `main`. - The database timezone applied to a date-only bound. - Middleware rate limits. +- Any timeout the server's web process puts in front of the live routes. +- Garmin's public docs for the detail path and for a per-minute rate. The + review cited about 100 requests a minute. This study did not find it. +- Which local timezone a given deployment runs in. +- Whether a Garmin activity object from the live list carries + `userAccessToken`. - The host `https://docs.openwearables.io`. diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index b763ee67..056a383d 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -73,7 +73,8 @@ These edits answer the thirteen findings of the review at `e145fa6`: deletion and correction. - D243. Connections, statuses, Suunto keys, detail rules, timeouts, request budgets, Garmin windows, id spelling, start times, and the count of every - object left out. + object left out. Garmin windows are 23 hours, not 24, because the pinned + server measures a window in naive local time. - D244. A credential-shaped value is withheld and counted. It no longer refuses the page. @@ -1248,9 +1249,13 @@ call could make the server try a refresh or a revoke. The order is Garmin, Polar, Suunto, Whoop, Fitbit, Oura, Strava, Withings, Sensorbio. One failure leaves that line `incomplete`. The others still run. -Garmin is split by this program into windows of 86,400 seconds or less, -one call each. Each window sends integer Unix seconds. Any failed window -makes Garmin `incomplete`. The pinned code calls Garmin detail at +Garmin is split by this program into windows of 82,800 seconds, 23 +hours, or less, one call each. Each window sends integer Unix seconds. +The pinned server splits a window it sees as longer than 24 hours and +drops a failed piece without saying so. It measures in naive local time, +so a true 24-hour window can look 25 hours long when the server's clock +moves forward. A 23-hour window cannot. Any failed window makes Garmin +`incomplete`. The pinned code calls Garmin detail at `/wellness-api/rest/activities/{activity_id}`. This study did not find that path in Garmin's public docs, so a failed Garmin detail is counted like any other. Polar's list omits samples, zones, and route, and detail @@ -1346,9 +1351,10 @@ withheld the same way, and the URL keeps its address. `polar_user` and a coordinate are not credential-shaped. The rule covers stored reads and vendor reads alike. -Garmin's list objects can carry an optional `userAccessToken`. Refusing -the page would refuse every such Garmin page, and the workouts on it -would be lost. Withholding keeps the workout and keeps the vendor's token +Garmin's summary objects can carry an optional `userAccessToken`. The +pinned server declares it on its Garmin wellness models, and the live +route returns Garmin's objects unchanged. Refusing the page would refuse +every Garmin page that carries it, and the workouts on it would be lost. Withholding keeps the workout and keeps the vendor's token out of the record. The stored original then differs from the vendor's object only at the withheld paths, and the count says how many there are. The maintainer can change the key list or the marker before diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index 4c80a13b..67577562 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -964,9 +964,9 @@ Budgets keep one command inside the providers' limits: - The pace above keeps this command at 60 live requests a minute or fewer. The review cited about 100 a minute for Garmin. This study did not find that number in Garmin's public docs. -- Garmin is read in windows of 86,400 seconds or less, one call each. - Every window is sent. A one-year range is 365 windows, so it takes at - least six minutes before any detail call. +- Garmin is read in windows of 82,800 seconds, 23 hours, or less, one + call each. Every window is sent. A one-year range is 381 windows, so it + takes more than six minutes before any detail call. - A command makes at most 100 detail calls to one provider, and at most 20 to Strava. Ids past the budget are `deferred`. The next paragraphs say which ids go first. @@ -1002,8 +1002,11 @@ timeout above. `summary_start_time` and `summary_end_time` as integer Unix seconds. The server puts those values in `uploadStartTimeInSeconds` and `uploadEndTimeInSeconds`, so a window selects by upload time, not by - start. A window longer than 24 hours is never sent, because the pinned - server then splits it itself and drops a failed piece without saying so. + start. Each window ends where the next begins. The pinned server splits + a window it sees as longer than 24 hours, and it drops a failed piece + without saying so. It measures the window in naive local time, so on a + server whose clock moves forward, a true 24-hour window can look 25 + hours long. A 23-hour window cannot look longer than 24 hours. A failed window makes Garmin `incomplete`, and later windows still run. The pinned code calls detail at `/wellness-api/rest/activities/{activity_id}`. This study did not find @@ -1522,9 +1525,11 @@ credential-shaped has its value replaced by the same text. The pull records the JSON path of each withheld value and counts them. It prints the count and up to 20 paths, and it says when that list was shortened. Nothing else in the object changes. The rule applies to every page, -stored reads and vendor reads alike. Garmin's list objects can carry an -optional `userAccessToken`, so refusing the page would refuse every such -Garmin page. `polar_user` and a route coordinate are not credential-shaped. +stored reads and vendor reads alike. Garmin's summary objects can carry +an optional `userAccessToken`. The pinned server declares it on its Garmin +wellness models, and the live route returns Garmin's objects unchanged. +Refusing the page would refuse every Garmin page that carries it. +`polar_user` and a route coordinate are not credential-shaped. D244 keeps the rest of the vendor object, including account ids, Polar user URLs, and full routes. The matching personal-record `user_id` is the only field of a stored read that is dropped before this walk. Any other @@ -2207,11 +2212,12 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: as `unsafe_number`. A fractional id refuses only that object and counts it as `unusable_id`. Two different objects with one id are both refused as `duplicate_id` -- a three-day Garmin range sends three windows. Each window sends - `summary_start_time` and `summary_end_time` as integer Unix seconds, and - no window is longer than 86,400 seconds. A date `--from` starts at - midnight UTC. One failed window makes Garmin `incomplete` and never - `completed`. A later window still runs +- a three-day Garmin range sends four windows, three of 82,800 seconds and + one of 10,800 seconds. Each window sends `summary_start_time` and + `summary_end_time` as integer Unix seconds, and each starts where the + last one ended. A date `--from` starts at midnight UTC. One failed + window makes Garmin `incomplete` and never `completed`. A later window + still runs - live requests go one at a time, at least one second apart by the fixture server's clock. A live request that times out, with the read timeout shortened for the test, stops every later request to that From 31b08b54a2844d4d32e4781e3479ec2b27cc434a Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 04:20:09 +0000 Subject: [PATCH 22/60] Update the 2.2.0 progress table for the 2.1.1 check. Step 0 now records the renumbering, the check against 0de71bb, and the answers to the review at e145fa6. The Garmin key removal joins the work kept out of the build. Co-authored-by: Michael Whitham --- build-history/v2.2.0/appendix/open-wearables-api.md | 3 ++- build-history/v2.2.0/progress.md | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/build-history/v2.2.0/appendix/open-wearables-api.md b/build-history/v2.2.0/appendix/open-wearables-api.md index aed8fef0..b238382e 100644 --- a/build-history/v2.2.0/appendix/open-wearables-api.md +++ b/build-history/v2.2.0/appendix/open-wearables-api.md @@ -6,7 +6,8 @@ software changes. A fact below is tied to the page or the file it came from. Nothing here was read from a live server, and no key was used. Files under `tests/fixtures/exports/open-wearables/` are not evidence. A claim about what the server sends cites the Open Wearables docs or the pinned -0.11.0 OpenAPI file already named in this appendix. +0.11.0 OpenAPI file already named in this appendix. Later checks are +dated in their own sections. The last one is 15 November 2026. ## What the product is diff --git a/build-history/v2.2.0/progress.md b/build-history/v2.2.0/progress.md index 5ad26964..fcf3b2bd 100644 --- a/build-history/v2.2.0/progress.md +++ b/build-history/v2.2.0/progress.md @@ -5,7 +5,7 @@ program, the record, or the database has changed for 2.2.0. | Step | What | Status | |---|---|---| -| 0 | The plan: proposals D227–D244, and the Open Wearables study. D239 through D241 stay. D243 corrects the live-read procedure. D244 is the privacy choice for vendor objects. Still not adopted. The new head needs a fresh four-role review | written, not approved | +| 0 | The plan: proposals D227–D244, and the Open Wearables study. The proposals were D198–D215 until 2.1.1 used D208–D226. Checked against 2.1.1 at `0de71bb` on 15 November 2026: a page is one import preview and one apply, and D237 uses the revision check. D239 through D241 stay. D242 and D243 answer the review at `e145fa6`. D244 withholds a credential-shaped value. Still not adopted. The new head needs a fresh four-role review | written, not approved | | 1 | Version 2.2.0 and migration step 6. Step 5 is the published 2.1.1 migration. No new column on an existing table. The root check gains `source_report` by the copy in D236. Summary and score values may be omitted in pairs (D227, D236) | not started | | 2 | `ath pull openwearables` in the `athleticstandard` crate, with the rewritten mapping (D228, D230, D236) | not started | | 3 | Key, server, and user id kept out of the record (D229) | not started | @@ -15,6 +15,6 @@ program, the record, or the database has changed for 2.2.0. The build, after approval, is one pull request. It is not three. -The Windows failed-init cleanup, the size of `src/import/mapping.rs`, and a -name check outside import stay out of that pull request (D231). `persist.rs` -is already gone. +The Windows failed-init cleanup, the size of `src/import/mapping.rs`, a +way to clear the Garmin key, and a name check outside import stay out of +that pull request (D231). `persist.rs` is already gone. From d636d7a05bb47781c6fe90f48f69b27a50b78bb6 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 04:25:14 +0000 Subject: [PATCH 23/60] Remove the extra blank line at the end of the 2.2.0 decisions. Co-authored-by: Michael Whitham --- build-history/v2.2.0/decisions.md | 1 - 1 file changed, 1 deletion(-) diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index 056a383d..76cbe40a 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -1370,4 +1370,3 @@ Rejected alternatives: would block every Garmin page, and the person would lose those workouts. - Drop a credential-shaped field without a marker. Rejected. The stored original would not show that a value was removed. - From 497b07fc4522fe0e3eb3279440ce838959607bc2 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 05:03:08 +0000 Subject: [PATCH 24/60] Cite real Open Wearables file paths in the 15 November checks The appendix named local download copies (garmin_w.py, suunto_w.py) that do not exist in the repository. Name each file by its path under backend/app/ at 183e8cc4, and record the Whoop response key, Suunto's one-page route, and how the client passes vendor errors through. Co-authored-by: Michael Whitham --- .../v2.2.0/appendix/open-wearables-api.md | 56 ++++++++++++------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/build-history/v2.2.0/appendix/open-wearables-api.md b/build-history/v2.2.0/appendix/open-wearables-api.md index b238382e..37240bce 100644 --- a/build-history/v2.2.0/appendix/open-wearables-api.md +++ b/build-history/v2.2.0/appendix/open-wearables-api.md @@ -539,7 +539,8 @@ an empty workout history. The live-route facts below were read again at commit `183e8cc4f6de897dbd288c93d49a691f2cf721ae`, for the review findings and for Athletic Standard 2.1.1. No server was called, and no vendor account -was used. +was used. Every path below is in the Open Wearables repository at that +commit, under `backend/app/`. Connections. `UserConnectionWithCapabilities`, in `schemas/model_crud/user_management/user_connection.py`, has `user_id`, @@ -550,23 +551,27 @@ and `linked_user_ids`. The route fills `linked_user_ids` with other users linked to the same vendor account. `ConnectionStatus`, in `schemas/auth/connection_status.py`, is `active`, `revoked`, or `expired`. -Live routes. Both handlers in `vendor_workouts.py` return the provider +Live routes. Both handlers in `api/routes/v1/vendor_workouts.py` return the provider method's value unchanged. The list handler passes `since`, `limit` (default 50, at most 100), `offset`, `filter_by_modification_time` (default true), `samples`, `zones`, `route`, `summary_start_time`, and `summary_end_time` to every provider. Each provider reads the ones it uses. -Client. `_make_api_request` in `api_client.py` makes at most four -attempts. Each attempt uses `provider_request_timeout_seconds`, which is -30 seconds by default and at most 300 in `config.py`. A 429 waits 15, then +Client. `_make_api_request` in `services/providers/api_client.py` makes +at most four attempts. Each attempt uses `provider_request_timeout_seconds`, +which is 30 seconds by default and at most 300 in `config.py`. A 429 waits 15, then 30, then 60 seconds. A 401 reloads the token once and tries again. A timeout or another transport error is not retried. A token refresh holds `token_refresh_lock` for up to 60 seconds and waits up to 10 seconds for it. So with the default timeout, one GET can take about 225 seconds, plus -a refresh. +a refresh. After the last 429 retry the client raises HTTP 429. Any other +vendor error status except 401 is raised with the vendor's own status, so +a vendor 404 reaches the caller as 404. A transport error becomes 500. The +route answers 501 only for a provider whose `workouts` is unset, so a +Garmin call never gets the route's own 501. -Garmin. `get_workouts_from_api` in `garmin_w.py` reads +Garmin. `get_workouts_from_api` in `services/providers/garmin/workouts.py` reads `summary_start_time` and `summary_end_time` as an integer first, then as ISO 8601. It turns both into naive local times with `datetime.fromtimestamp` and compares them. A difference over 24 hours @@ -581,20 +586,31 @@ integer or a string. The Garmin wellness models declare an optional `userAccessToken`. `ActivityJSON` does not, but the live route returns Garmin's objects unchanged. -Suunto. `get_workout_detail` in `suunto_w.py` names its argument -`workout_key` and calls `/v3/workouts/{workout_key}`. The list method -reads `payload` and pages by `offset`, at most 100 a page. The route's -`filter_by_modification_time` defaults to true, so this plan sends false. - -Whoop. The method caps `limit` at 25, takes `nextToken` from the request, -and reads `next_token` in the response. The route never passes -`nextToken`, so one call reads only the first page. - -Sensorbio. The route's method sends `last-timestamp` 0 and `limit` at most -50, and returns that one response. It does not follow `links.next`, so it -reads the oldest 50 entries. +Suunto. `get_workout_detail` in `services/providers/suunto/workouts.py` names its argument +`workout_key` and calls `/v3/workouts/{workout_key}`. The route calls +`get_workouts_from_api`, which sends one page: `since`, `limit` at most +100, `offset`, and `filter-by-modification-time`. The internal +`get_workouts` walks every page until a short one, but the route does not +call it. So each route call returns one page, and the caller pages by +`offset`. The route's `filter_by_modification_time` defaults to true, so +this plan sends false. + +Whoop. The method in `services/providers/whoop/workouts.py` caps `limit` +at 25, takes `nextToken` from the request, and reads `next_token` in the +response. `WhoopWorkoutCollectionJSON`, in +`schemas/providers/whoop/workout_import.py`, declares `records` and +`next_token` with no alias, so Whoop's own response key is `next_token`. +The route never passes `nextToken`, so one call reads only the first +page. Oura's method in `services/providers/oura/workouts.py` sends and +reads `next_token`. + +Sensorbio. The route's method in `services/providers/sensorbio/workouts.py` +sends `last-timestamp` 0 and `limit` at most 50, and returns that one +response. It does not follow `links.next`, so it reads the oldest 50 +entries. -Strava. `get_workouts_from_api` sends `page` 1 and `per_page` from +Strava. `get_workouts_from_api` in `services/providers/strava/workouts.py` +sends `page` 1 and `per_page` from `strava_events_per_page`, which is 200 by default, and ignores `limit`. Strava's API reference, fetched 15 November 2026, lists `DetailedActivity` fields that include `laps`, `splits_metric`, `splits_standard`, From 4c167f6d355e123b8bc543d7845dba983a9b6461 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 05:06:01 +0000 Subject: [PATCH 25/60] Name the 2.1.1 final-version checks step 6 must change install_schema and apply_steps both refuse unless one transaction reaches SQL_SCHEMA_VERSION. Say how each check changes when steps 1 through 5 commit at schema 5, and say that a new database runs on the connection Store::create opened, not through Store::transaction. Co-authored-by: Michael Whitham --- build-history/v2.2.0/decisions.md | 31 ++++++++++++++++++--- build-history/v2.2.0/spec.md | 45 ++++++++++++++++++++++--------- 2 files changed, 60 insertions(+), 16 deletions(-) diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index 76cbe40a..47a37210 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -78,6 +78,15 @@ These edits answer the thirteen findings of the review at `e145fa6`: - D244. A credential-shaped value is withheld and counted. It no longer refuses the page. +## Changes after the review at `d636d7a` + +These edits answer the review of this plan at `d636d7a`: + +- D227. A new database runs its migrations on the connection + `Store::create` opened, not through `Store::transaction`. The two 2.1.1 + checks that expect one transaction to reach the last schema are named, + with the check that replaces each. + ## D227. Version 2.2.0 is one manual pull, and the program and the record share that number `ath pull openwearables` reads the stored representations D232 lists from an @@ -96,16 +105,32 @@ the two cross-table triggers around the root rename. Existing rows keep their numbers. Steps 1 through 5 are not edited (D165). In 2.1.1, `install_schema` in `src/store/mod.rs` runs the whole chain in one -transaction with foreign keys on. Every other migration runs inside +transaction with foreign keys on. `Store::create` calls it on a new +connection before any `Store` exists, and it opens its own transaction. +`ath migrate` and `apply_pending_without_backup` run their steps inside `Store::transaction`, which refuses to write when foreign keys are off. Step 6 needs them off while it rebuilds tables that other tables point to. So `install_schema` commits steps 1 through 5 first, and step 6 runs in its -own transaction on the store's own connection. `src/store/migrate.rs` turns +own transaction on the same connection. Step 6 is one function in +`src/store/migrate.rs` that takes the connection, so init and migrate both +call it. It turns foreign keys off before that transaction begins, because SQLite ignores the setting inside a transaction, and reads the setting back. The step runs `PRAGMA foreign_key_check` and refuses any row it returns. It sets `user_version` 6 and commits. Foreign keys are turned on again and read -back, whether the step committed or not. `ath migrate` keeps its verified +back, whether the step committed or not. + +Two 2.1.1 checks expect one transaction to reach the last schema. +`install_schema` refuses unless the metadata reads `SQL_SCHEMA_VERSION` +and `ATHLETIC_STANDARD_VERSION` (`src/store/mod.rs`, lines 625 through +629 at `0de71bb`). `apply_steps` refuses unless its last step reached +`SQL_SCHEMA_VERSION` (`src/store/migrate.rs`, lines 321 through 326). With +the constant at 6, both would fail once steps 1 through 5 commit at schema +5. So the first transaction checks for schema 5 and `2.1.1`. `apply_steps` +checks for the last step it was given. The step-6 function checks for +schema 6, `2.2.0`, and `user_version` 6 before it commits. + +`ath migrate` keeps its verified backup. Inside the step-6 transaction it checks again that the file, the database ID, the schema, and the database revision are the ones its earlier steps left. `MIGRATION_CHAIN` in that file and `spec/sql/contract.json` gain diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index 67577562..e43c37a8 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -1587,18 +1587,31 @@ attachments, reporting periods, and the other child tables, use `install_schema` runs. A `DROP TABLE records` inside that transaction would fail or cascade through the children. Step 6 does not do that. `write_transaction` in the same file refuses to write when foreign keys -are off. `Store::transaction` uses it, and every 2.1.1 migration runs -through `Store::transaction`. - -Today `install_schema` runs the whole chain, steps 1 through 5, in one -transaction. That transaction sets `user_version` to `SQL_SCHEMA_VERSION` -and commits. With step 6, that transaction stops after step 5, sets -`user_version` 5, and commits. Step 6 then runs in its own transaction and -sets `user_version` 6. - -Step 6 runs on the store's own connection, in a transaction that -`src/store/migrate.rs` opens itself rather than through -`Store::transaction`. Before `BEGIN IMMEDIATE`, it sets +are off. `Store::transaction` uses it. `ath migrate` and +`apply_pending_without_backup` run steps 2 through 5 through +`Store::transaction`. A new database does not. `Store::create` opens a +connection, runs `configure` and `enable_wal`, and calls `install_schema` +on that connection before any `Store` exists. `install_schema` opens its +own transaction with `rusqlite::Transaction::new_unchecked`. + +Today `install_schema` runs the whole chain, steps 1 through 5, in that +one transaction. It sets `user_version` to `SQL_SCHEMA_VERSION`. Then it +refuses unless the metadata reads `SQL_SCHEMA_VERSION` and +`ATHLETIC_STANDARD_VERSION`, in `src/store/mod.rs` lines 625 through 629 +at `0de71bb`. `apply_steps` in `src/store/migrate.rs` has the same kind of +final check, in lines 321 through 326. It refuses unless the last step it +ran reached `SQL_SCHEMA_VERSION`. When the constant becomes 6 and steps 1 +through 5 commit at schema 5, both checks would fail. So the build changes +both. The first `install_schema` transaction stops after step 5, sets +`user_version` 5, checks for schema 5 and `2.1.1`, and commits. +`apply_steps` checks that it reached the last step it was given. The +step-6 function makes the final check before it commits: schema 6, +`2.2.0`, and `user_version` 6. + +Step 6 is one function in `src/store/migrate.rs`. It takes the +connection and opens its own transaction. At init it runs on the +connection `Store::create` opened. On migrate it runs on the store's +connection. It does not use `Store::transaction`. Before `BEGIN IMMEDIATE`, it sets `PRAGMA foreign_keys=OFF` and reads the pragma back. The value must be 0. Turning foreign keys off does not turn off the schema check SQLite runs during `ALTER TABLE`. `sql_v1_current_records` and `sql_v1_active_records` select from `records`. The triggers @@ -2292,7 +2305,13 @@ Migration tests, in the build gate: populated 2.1.1 database leaves that file, schema 5, the views, and foreign-key enforcement. Step 5 still writes `2.1.1` and schema 5, and `install_schema` commits that - transaction before step 6 + transaction before step 6. Its check accepts schema 5 and `2.1.1` there. + A step 6 that is made to stop before it sets the version rows fails the + step-6 check for schema 6 and `2.2.0`, and init fails. Init runs on the + connection `Store::create` opened and never calls `Store::transaction` +- `apply_steps` given steps 2 through 5 passes its final check at schema 5. + Given a list that ends before 5, it still refuses when the database + stops short of the last step in that list - a 2.0.0 database whose step 6 is made to fail after steps 3 to 5 committed is a 2.1.1 database at schema 5. The message says so and names the verified backup. A second `ath migrate` runs only step 6 and From 3c7a0444a53cf840502df9d084e801c724c4ef7c Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 05:09:40 +0000 Subject: [PATCH 26/60] Complete the provider.rs change list and the response-cap comment route_source stages only export_file sources that name a vendor, so the connector sources need their own staging call. Staging counts by action only, so the page counts need a count by record type. The revision a preview read is already public. The 2.1.1 comment on the 10 MiB cap names only Garmin, so the build rewrites it. Co-authored-by: Michael Whitham --- build-history/v2.2.0/decisions.md | 21 +++++++++++++-- build-history/v2.2.0/spec.md | 43 +++++++++++++++++++++++++------ 2 files changed, 54 insertions(+), 10 deletions(-) diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index 47a37210..a98e21b1 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -86,6 +86,12 @@ These edits answer the review of this plan at `d636d7a`: `Store::create` opened, not through `Store::transaction`. The two 2.1.1 checks that expect one transaction to reach the last schema are named, with the check that replaces each. +- D230. The 2.1.1 comment on the 10 MiB response cap names only Garmin. + The build rewrites it and the route list to name both pulls. +- D231. The `src/import/provider.rs` list is complete. It adds a + `connector` source call, because `route_source` stages only + `export_file` sources, and a count by record type in + `src/import/staging.rs`. The revision a preview read is already public. ## D227. Version 2.2.0 is one manual pull, and the program and the record share that number @@ -465,7 +471,11 @@ request, except the smaller page D233 sends after the response cap. A transport error is not retried. The stored reads use a 30-second connect timeout and a 120-second read timeout, the values `src/runtime/garmin_pull.rs` uses. Live vendor requests use 30 and 360 -seconds, for the reason in D243. Each timeout is a named constant. +seconds, for the reason in D243. Each timeout is a named constant. In +2.1.1 the comment on `MAX_PULL_RESPONSE_BYTES` calls it one Garmin +personal connection response, and the route list above it names only the +Garmin pull. The build rewrites both to name the Open Wearables pull too. +The value stays 10 MiB. A row that this range did not return is left where it is. The pull does not call `DELETE`. There is no deletion feed on these reads. Absence can be @@ -549,7 +559,14 @@ That first bind is a source correction with the source's expected revision. `ProviderPreview::apply` refuses any other staged change to `device_binding`. Those writes keep every other source field and the normal revision and `data_json` bookkeeping. `provider.rs` also gains the -crate-private read of a stored vendor original that D243 uses. +crate-private read of a stored vendor original that D243 uses. It gains +`connector_source` beside `route_source`, because `route_source` stages +only an `export_file` source that names a vendor. The writer +`open_wearables` sources, the archive source, and each `vendor_workout` +source are `connector` sources with no vendor. `Staging::count` in +`src/import/staging.rs` counts by action only, so a count by record type +goes beside it for the page counts. The revision a preview read is +already public as `ProviderPreview::destination_database_revision`. `Store::apply` in `src/store/write.rs` writes a whole record. There is no `Store::revise`, and a correction carries the whole record. The owner and diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index e43c37a8..b99eefb8 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -1461,11 +1461,29 @@ besides the typed writes in section 6. It gains nothing beyond those: route, sensor, import keys, and baselines stay. - In `ProviderPreview::apply`, refuse any other staged change to `device_binding`. +- In the sink, stage a `connector` source. `route_source` stages only an + `export_file` source that names a vendor, and it reuses only a staged + `export_file` source. The writer-`open_wearables` sensors in section 2, + the archive source, and each `vendor_workout` source are `connector` + sources with no vendor. So a new `connector_source(writer, sensor)` + goes beside `route_source`. Matching finds its stored source by writer, + route, and sensor, including a deleted one, as `keyed_existing_source` + already does. A device source still comes from `route_source`. +- In the preview, count the staged plan by record type and action. + `Staging::count` in `src/import/staging.rs` counts by action only. A count + by record type goes beside it, and `ProviderPreview` exposes it. Each + page's counts in section 1 come from that count. +- A crate-private read of a stored vendor original, for the detail rules + in section 2. + +The pull reads the revision a preview matched at from +`ProviderPreview::destination_database_revision`, which is already public. +No accessor is added for it. The reads run in the matching step's read transaction. The writes run in the page's one apply transaction. A refused call writes none of them. -Other routes do not call them. The build may extend `route_source` or add -a narrow operation beside it. It does not add a table or a trait. The +Other routes do not call them, and `route_source` is unchanged for them. +It does not add a table or a trait. The binding check and the safety snapshot go in one new file, `src/import/binding.rs`, because `src/import/provider.rs` is already 1297 lines. The automatic path does not replace `detail`, `vendor`, or @@ -1506,6 +1524,11 @@ The timeouts are named constants in `src/runtime/open_wearables.rs`. One response may be at most `MAX_PULL_RESPONSE_BYTES`, which is 10 MiB. One read may be at most 1000 pages. Those limits are named constants in `src/input_policy.rs`, where 2.1.1 keeps every limit on untrusted input. +In 2.1.1 the comment on `MAX_PULL_RESPONSE_BYTES` says it is the bytes of +one Garmin personal connection response. The route list at the top of +that file's route limits names only the Garmin pull. The build rewrites +that comment to name both pulls, and it adds the Open Wearables pull and +its new limits to that list. The value stays 10 MiB. The body is read inside that cap and parsed before the page reaches `MappedPage`. The guard is in `open_wearables.rs`. It walks every decoded @@ -1744,11 +1767,13 @@ interactive open can preview, back up, ask, and then migrate. | Flags, key, preview text, refusal if the key appears | `src/cli/`, `src/cli/help.rs`, `src/runtime/keyring.rs`, and `key_clear` in `src/cli/commands/model.rs` | | Reader for one decoded page | `MappedPage`, beside `MappedReader` in `src/import/mapping.rs` | | Mapping names and field rules, including the `vendor_workout` section | the existing file `mappings/open-wearables.md` | -| Stage, match, and write each page | `preview_route` and `ProviderPreview::apply` in `src/import/provider.rs`, with a crate-private accessor for the revision a preview read | +| Stage, match, and write each page | `preview_route` and `ProviderPreview::apply` in `src/import/provider.rs`. The revision a preview read is the public `destination_database_revision` | +| A `connector` source with no vendor | new `connector_source` beside `route_source` in `src/import/provider.rs` | +| Page counts by record type | a count beside `Staging::count` in `src/import/staging.rs`, exposed by `ProviderPreview` | | Device-binding facts and the safety snapshot | new `src/import/binding.rs`, called from the matching step in `src/import/provider.rs` for route `open_wearables` | | Create or first-bind with the checked receipt, and refuse any other `device_binding` change | the staged plan and `ProviderPreview::apply` in `src/import/provider.rs` | | Stored-original read for the vendor detail rules | a crate-private read in `src/import/provider.rs` | -| Response cap and page cap | named constants in `src/input_policy.rs` | +| Response cap and page cap, and the comment and route list that now name both pulls | named constants in `src/input_policy.rs` | | Receipt for a start in Unix seconds or milliseconds | a helper beside `offset_timestamp_receipt` in `src/import/candidate.rs` | | Measurement samples, source reports, paired null value and unit, and child withdrawal | `write_current_state` and `typed_columns` in `src/store/encode.rs`. Package restore, repair, and the record check use that encoder | | Step 6 with foreign keys off | its own transaction in `src/store/migrate.rs`, and `install_schema` in `src/store/mod.rs` | @@ -2415,8 +2440,9 @@ is in the build pull request. and `src/store/check.rs` is 1044. The pull does not add HTTP to them. `mapping.rs` gains `MappedPage`, the `vendor_workout` section, and the preservation writes in section 2. `provider.rs` gains the staged first - bind, the `device_binding` refusal in `ProviderPreview::apply`, and the - stored-original read. The binding check and the safety snapshot go in + bind, the `device_binding` refusal in `ProviderPreview::apply`, the + `connector` source call, and the stored-original read. `staging.rs` gains + the count by record type. The binding check and the safety snapshot go in the new `src/import/binding.rs`. `src/store/encode.rs` gains the sample, source-report, withdrawal, and paired-null writes in section 6, and `src/calculate/range.rs` gains the null filter. Splitting `mapping.rs` @@ -2550,8 +2576,9 @@ optional source key adds no column. notes stay separate. `src/import/mapping.rs` gains `MappedPage`, the `vendor_workout` section, and the preservation writes in section 2. `src/import/provider.rs` gains the staged first bind, the - `device_binding` refusal in `ProviderPreview::apply`, and the - stored-original read. The new `src/import/binding.rs` holds the binding + `device_binding` refusal in `ProviderPreview::apply`, the `connector` + source call, and the stored-original read. `src/import/staging.rs` gains + the count by record type. The new `src/import/binding.rs` holds the binding check and the bounded safety snapshot. `src/store/encode.rs` gains the sample, source-report, withdrawal, and paired-null writes in section 6, and `src/calculate/range.rs` gains the null filter. The pull command From dff511f270585f2a57a38d3c122eae139cb46c70 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 05:11:46 +0000 Subject: [PATCH 27/60] Count a Garmin detail 404 or 501 as not_available The pinned Garmin detail path is not in Garmin's public docs. Keep calling it, but let a 404 or 501 leave Garmin completed with the list object stored whole. Any other error stays failed. An id that was not_available is retried after new and changed ids, inside the same budget. Co-authored-by: Michael Whitham --- build-history/v2.2.0/decisions.md | 21 +++++++++++--- build-history/v2.2.0/spec.md | 46 ++++++++++++++++++++++++------- 2 files changed, 53 insertions(+), 14 deletions(-) diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index a98e21b1..ac8756ab 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -92,6 +92,9 @@ These edits answer the review of this plan at `d636d7a`: `connector` source call, because `route_source` stages only `export_file` sources, and a count by record type in `src/import/staging.rs`. The revision a preview read is already public. +- D243. A Garmin detail that answers 404 or 501 is `not_available`, not + `failed`. Garmin stays `completed`, and the list object is stored whole. + The pinned detail path is not in Garmin's public docs. ## D227. Version 2.2.0 is one manual pull, and the program and the record share that number @@ -1297,10 +1300,14 @@ The pinned server splits a window it sees as longer than 24 hours and drops a failed piece without saying so. It measures in naive local time, so a true 24-hour window can look 25 hours long when the server's clock moves forward. A 23-hour window cannot. Any failed window makes Garmin -`incomplete`. The pinned code calls Garmin detail at -`/wellness-api/rest/activities/{activity_id}`. This study did not find -that path in Garmin's public docs, so a failed Garmin detail is counted -like any other. Polar's list omits samples, zones, and route, and detail +`incomplete`. The pull keeps calling Garmin detail at the pinned path, +`/wellness-api/rest/activities/{activity_id}`. That path is not in +Garmin's public docs, and this study did not find it there. For a Garmin +detail only, HTTP 404 or 501 counts as `not_available`: the list object +is stored whole, and Garmin stays `completed`. Any other Garmin detail +error is `failed`. An id that was `not_available` is detailed again after +the new and changed ids, inside the same budget. The maintainer confirms +this rule before approval. Polar's list omits samples, zones, and route, and detail asks for all three. Suunto's detail is called at `workoutKey` when the list object has one, and at `workoutId` otherwise. Its `payload` is unwrapped, and the record key is `workoutId`. Whoop's response names its @@ -1355,6 +1362,12 @@ Rejected alternatives: is not health data. - Write the list object over a stored detail when the new detail fails or is deferred. Rejected. The person would lose data they already have. +- Count a Garmin detail 404 as `failed`, as the earlier text did. + Rejected. If the path does not exist, Garmin would be `incomplete` on + every command, and the person could not fix it. +- Drop the Garmin detail call because the path is not in Garmin's public + docs. Rejected. The pinned server calls it, and a deployment where it + works would lose every Garmin detail. - Use a 30-second read timeout. Rejected. The server's own retries take longer. The client would give up, and a rerun could send a second request while the first still runs. diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index b99eefb8..da03a239 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -1008,10 +1008,18 @@ timeout above. server whose clock moves forward, a true 24-hour window can look 25 hours long. A 23-hour window cannot look longer than 24 hours. A failed window makes Garmin `incomplete`, and later windows still run. - The pinned code calls detail at - `/wellness-api/rest/activities/{activity_id}`. This study did not find - that path in Garmin's public docs. A failed Garmin detail is counted as - `failed`, like any other. + The pull calls Garmin detail at the pinned path, + `/wellness-api/rest/activities/{activity_id}`. That path is not in + Garmin's public docs. This study looked and did not find it, so the path + may not exist. For a Garmin detail only, HTTP 404 or HTTP 501 counts as + `not_available`. The list object is stored whole, with `detail_status` + `not_available`, and Garmin stays `completed`. Any other failed Garmin + detail is `failed`, and Garmin is `incomplete`. A 404 or 501 on a Garmin + list window is not this rule. It fails that window. Every other + provider's detail 404 is `failed`. The pinned client passes a vendor's + 404 through unchanged, and the route answers 501 only for a provider it + has no workout method for, so this study cannot tell a missing path + from a missing activity. - Polar. The list sends `samples`, `zones`, and `route` false, the route's default, so the list stays small. Detail sends all three true. A list over the response cap fails that list, because the route has no smaller @@ -1102,9 +1110,12 @@ holds a detail, and its stored `list`. The pull calls detail only when the provider has a detail call and its budget allows. It spends the budget in this order. First come ids with no -stored detail. Then come ids whose list object differs from the stored -`list`. Inside each group the oldest start goes first. An id without a -start instant goes last, in list order. An id whose original holds a +stored detail that no earlier command marked `not_available`. Then come +ids whose list object differs from the stored `list`. Then come ids an +earlier command marked `not_available`. Inside each group the oldest start +goes first. An id without a start instant goes last in its group, in list +order. So a Garmin path that answers 404 for every id still lets new ids +go first, and it costs at most the provider's budget in one command. An id whose original holds a detail and whose list object is unchanged gets no detail call. A deleted original gets no detail call. A detail is fetched again only when the list object changed. A provider that changes a detail without changing the @@ -1129,13 +1140,16 @@ What is written for one id depends on what this command got: - No new detail, and none stored. The original is written with the list object alone. `detail_status` says why: `deferred`, `failed`, `mismatch`, or `not_available`. The id counts under the same word. + `not_available` means the provider has no detail call, or Garmin + answered its detail call with 404 or 501. - No new detail, but one is stored, and the list object changed. Nothing is written for that id, and no revision is added. The stored detail stays. The id counts as `deferred`, `failed`, or `mismatch`. A list-only object therefore never replaces a stored detail. A `failed` or `mismatch` detail makes the provider `incomplete`, and the exit is -nonzero. A `deferred` detail leaves the provider `completed`, with the +nonzero. A `not_available` detail leaves the provider `completed`. A +`deferred` detail leaves the provider `completed`, with the deferred count on its line, and the next command details those ids first. A deferred id that the provider stops listing is never detailed by a later command. The deferred count shows how many are waiting. @@ -2256,6 +2270,14 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: last one ended. A date `--from` starts at midnight UTC. One failed window makes Garmin `incomplete` and never `completed`. A later window still runs +- a Garmin detail that answers HTTP 404 stores the list object whole with + `detail_status` `not_available`. Garmin is `completed`, its line counts + 1 `not_available`, and the command exits 0. HTTP 501 is the same. A + Garmin detail that answers HTTP 500 is `failed`, Garmin is + `incomplete`, and the exit is nonzero. A Polar detail that answers 404 + is `failed`. A Garmin list window that answers 404 fails that window. + On the next command, a new Garmin id is detailed before the id that was + `not_available` - live requests go one at a time, at least one second apart by the fixture server's clock. A live request that times out, with the read timeout shortened for the test, stops every later request to that @@ -2487,8 +2509,12 @@ Risks: - Strava's limit is shared with the deployment's own sync. One command can use most of a 15-minute window. - The pinned Garmin detail path and the cited Garmin rate were not found - in Garmin's public docs. If the path does not exist, Garmin details show - as `failed`, and Garmin is `incomplete`. + in Garmin's public docs. If the path does not exist, each Garmin detail + answers 404 or 501. Those count as `not_available`, Garmin stays + `completed`, and each Garmin original holds its list object only. Each + command still spends up to 100 Garmin detail calls on ids that were + `not_available`, after new ids. A deployment where that path works fills + those details in on later commands. - A later pull replaces an owner correction of a vendor original when the server's envelope differs. The correction stays in the history. Deleting the original stops it. From 33da7a2c3e69f8fdaecd2de61b36baba0a048c87 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 05:16:51 +0000 Subject: [PATCH 28/60] Keep an owner correction until the server's data changes On route open_wearables, compare a candidate for an owner-corrected record with the newest provider_import revision instead of the owner's revision. Replace the correction only when the server's data changed, and count each replaced correction per provider and for stored records in the text, --json, and the preview. The skill says where a workout fix belongs. Co-authored-by: Michael Whitham --- build-history/v2.2.0/decisions.md | 51 +++++++++--- build-history/v2.2.0/spec.md | 124 ++++++++++++++++++++++++++---- 2 files changed, 149 insertions(+), 26 deletions(-) diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index ac8756ab..a38f82ec 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -95,6 +95,11 @@ These edits answer the review of this plan at `d636d7a`: - D243. A Garmin detail that answers 404 or 501 is `not_available`, not `failed`. Garmin stays `completed`, and the list object is stored whole. The pinned detail path is not in Garmin's public docs. +- D242. On route `open_wearables`, an owner correction is replaced only + when the server's data differs from the newest revision an import wrote. + Each replaced correction is counted per provider and for stored records, + in the text, in `--json`, and in the preview. The skill says where a + workout fix belongs. ## D227. Version 2.2.0 is one manual pull, and the program and the record share that number @@ -460,7 +465,8 @@ An empty ranged result whose ranged reads completed has `range_complete` true. The personal record and the body snapshot can still be written. Those writes are counted. They are not ranged rows. A repeat uses the match key from D181 and the replace from D182, so an unchanged row is not written -again. A rerun after a partial write leaves the committed rows in place, +again. An owner correction on this route is kept until the server's data +for that record changes (D242). A rerun after a partial write leaves the committed rows in place, runs the failed read again, and runs any read that was `not_attempted`. `has_more: false` is the successful end of a cursor read and of the offset @@ -1220,15 +1226,29 @@ stored pages or the archive. The vendor page uses the 2.1.1 keyed rules. An original the person deleted is left out on every later pull and is not recreated (D182). A deleted `vendor_workout` source leaves out every object from that -provider (D190). An original the person corrected gains a revision with -the server's envelope when a later envelope differs, because a mapped -import replaces the whole object (D182). The person's revision stays in -the history. To keep a pull from changing an original, the person -deletes it. +provider (D190). + +An owner correction is kept until the server's data changes. On route +`open_wearables` only, a pull or a mapped import compares a candidate for +an owner-corrected record with the newest revision an import wrote, basis +`provider_import`. It does not compare with the owner's revision. Equal +writes nothing, and the correction stays current. Different replaces the +correction, and the count `owner_corrections_replaced` shows it on that +provider's line, in `--json`, and in the preview, which says `would +replace N owner corrections; delete an original to keep it`. The +correction stays in the history. The rule covers every record on that +route, so a workout fix on the stored session also survives a pull of +unchanged data. For that route it supersedes the D182 sentence that a +mapped import replaces a changed object. Other routes keep D182. The +stored-original read in D243 uses the same import revision, so an owner's +edit does not trigger a detail call. The skill says that a workout fix +belongs on the session or in a note, not on the vendor original. +Deleting an original keeps the person's version in its history and stops +every later pull from changing it. Each provider's line counts originals as new, changed, and unchanged. It -counts details by outcome, objects left out by reason, and withheld -values. Each listed object is in exactly one detail count or one left-out +counts owner corrections replaced, details by outcome, objects left out +by reason, and withheld values. Each listed object is in exactly one detail count or one left-out count, so no object is dropped without a count. The pull uses the published query parameters and does not add its own @@ -1249,10 +1269,17 @@ Rejected alternatives: - Store the list object and the detail as two records. Rejected. They describe one workout, and nothing in either object joins them except the id the envelope already uses. -- Keep an owner correction when a later pull differs. Rejected for this - release. A 2.1.1 keyed import replaces a changed object and keeps the - history, on every route. A protection rule would be new import behavior - for all of them. Deleting the original keeps a pull from changing it. +- Replace an owner correction whenever the candidate differs from the + current record, as D182 does and as the first version of this decision + did. Rejected. A pull repeats the same server data, so every pull would + undo every correction even when the server had not changed. +- Never replace an owner correction. Rejected. A later fix by the vendor + would be lost, and nothing would say so. +- Limit the rule to vendor originals. Rejected. The skill sends workout + fixes to the stored session, and the D182 rule would undo those on every + pull. The maintainer can narrow it before approval. +- Use the rule on every mapped route. Not chosen for this release. Other + routes import a file the person chose, and D182 stays their rule. ## D243. A live vendor read is opt-in, and one failure stays on that provider diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index da03a239..852d73b9 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -191,6 +191,7 @@ the text. The object has no key, server, user id, or request path. }, "left_out": { "total": 0, "by_reason": {}, "examples": [], "shortened": false }, "withheld": { "total": 0, "paths": [], "shortened": false }, + "owner_corrections_replaced": 0, "vendor_workouts": { "requested": false, "requests_made": false, @@ -203,6 +204,7 @@ the text. The object has no key, server, user id, or request path. "covers_requested_range": false, "more": false, "limit": "not requested", + "owner_corrections_replaced": 0, "details": { "stored": 0, "kept": 0, @@ -225,6 +227,17 @@ preview. `connection_status` is `active`, `revoked`, `expired`, `unknown status`, or `null` when the server listed no connection for that provider. +The top-level `owner_corrections_replaced` counts owner corrections of +stored records that the stored pages replace, by the owner-correction rule +in section 2. Each provider's `owner_corrections_replaced` counts its +vendor originals. In a preview both are estimates. When a provider's count +is above zero, the preview prints `would replace N owner corrections; +delete an original to keep it` on that provider's line. When the top-level +count is above zero, it prints `would replace N owner corrections of +stored records because the server's data changed`. After `--yes` the same +lines say `replaced N owner corrections`, and that each correction stays +in the record's history. The text uses the singular when N is 1. + The same record types are present for workouts, points, summaries, scores, and source reports. The example above is shortened. Polar, Suunto, Whoop, Fitbit, Oura, Strava, Withings, and Sensorbio use the same fields as @@ -233,7 +246,8 @@ outcome. A preview does not say a snapshot was stored. The command returns a different outcome for `--yes` without `--json`. That outcome has the actual `committed` counts, the actual `archive_committed` -counts, `database_changed`, `protected_write`, `archive`, +counts, the actual `owner_corrections_replaced` counts, +`database_changed`, `protected_write`, `archive`, `range_complete`, and `snapshots_complete`. `committed` counts protected records only. `archive_committed` counts archive records only, including a created archive source, counted once. A record is in one of those @@ -772,6 +786,33 @@ keyed-import rules, and a deleted row is never recreated. A deleted source or a deleted record named anywhere on the page still forbids the archive of that page. +An owner correction is kept until the server's data changes. This rule +is new in 2.2.0. It covers every record on route `open_wearables`, from a +pull or from `ath import --mapping open-wearables`. Every other route +keeps D182 as it is. An import writes each revision with basis +`provider_import`. A revision with any other basis is an owner correction +here: `ath correct`, a protocol write, and an accepted package merge write +other bases. A native restore copies each revision's basis, so a restored +database keeps the same answer. When a page's candidate names a stored +record by its import key, and that record is not deleted: + +1. A candidate equal to the current record writes nothing, as in 2.1.1. +2. When the current revision has basis `provider_import`, a different + candidate replaces it, as in 2.1.1 (D182). +3. When the current revision is an owner correction, the candidate is + compared with the newest revision whose basis is `provider_import`. + Equal means the server has not changed that record since an import last + wrote it. Nothing is written, and the correction stays current. + Different means the server's data changed. The candidate replaces the + correction, and that counts as one `owner_corrections_replaced`. The + correction stays in the record's history. A record with no + `provider_import` revision is replaced and counted the same way. + +The comparison is the 2.1.1 comparison, with the compared revision's +`received_at`. Section 4 withholds credential values before the candidate +is built, so a withheld value is the same marker on both sides. A library +write that chooses basis `provider_import` counts as an import revision. + The archive is allowed only when that snapshot has no veto, names no deleted source or record, and has one of these eligible facts: a device-targeted series row whose source has no device id, or a @@ -1106,7 +1147,9 @@ The start is stored and is not a filter. For each listed id, the pull first reads the stored original, if there is one. That read is crate-private and lives in `src/import/provider.rs`. It returns whether the original exists, whether it is deleted, whether it -holds a detail, and its stored `list`. +holds a detail, and its stored `list`. It reads the newest revision with +basis `provider_import`, not an owner correction, so a person's edit does +not look like a vendor change and does not spend a detail call. The pull calls detail only when the provider has a detail call and its budget allows. It spends the budget in this order. First come ids with no @@ -1208,15 +1251,22 @@ original, a later pull leaves that object out, says so on its line, and does not recreate it (D182). That happens on every later pull. If the person deleted a provider's `vendor_workout` source, every object from that provider is left out (D190). If the person corrected an original with -`ath correct`, a later pull whose envelope differs adds a revision with -the server's envelope, because a mapped import replaces the whole object -(D182). The person's revision stays in the history. A pull whose envelope -equals the current record adds nothing. To keep a pull from changing an -original, the person deletes it. +`ath correct`, the owner-correction rule above applies. A later pull +whose envelope equals the newest `provider_import` revision adds nothing, +and the correction stays current. A later pull whose envelope differs +replaces the correction and counts it in `owner_corrections_replaced`. +The person's revision stays in the history. To keep a pull from changing +an original at all, the person deletes it. The deleted original then +keeps the person's version in its history, and every later pull leaves +that object out. A workout fix belongs on the stored session or in a +note, not on the vendor original. The skill says so (section 6). Each provider's line, and its object in `--json`, counts: - `originals`: new, changed, and unchanged records. +- `owner_corrections_replaced`: owner corrections that this page replaces, + by the owner-correction rule above. Each is also counted as a changed + original. - `details`: `stored`, `kept`, `deferred`, `failed`, `mismatch`, `thinner`, and `not_available`. - `left_out`: objects not written, by reason: `missing_id`, @@ -1277,7 +1327,8 @@ passes the object after `user_id` is removed. Pagination and health-score `metadata` are not records. Everything after that is the mapping engine that 2.1.1 carries over from -2.1.0: match keys (D181), replace on change (D182), source and device +2.1.0: match keys (D181), replace on change (D182) except for the owner +corrections section 2 keeps, source and device (D183), one write transaction per page (D189), a deleted source left out (D190), and field names refused when they are empty or `__proto__` (D191). A Garmin file import remains a different `data_route`, so both copies of @@ -1367,8 +1418,8 @@ The call is one of these states: - The source is deleted. D190 leaves its rows out. The call does not revive the source and does not set a binding. - The source has an established binding, and the incoming id equals it. The - row may repeat unchanged or correct the stored value under D182. The - binding stays. Hardware is not replaced with a different id. Other fields + row may repeat unchanged or correct the stored value under D182 and the + owner-correction rule in section 2. The binding stays. Hardware is not replaced with a different id. Other fields already on the source stay. - The source has an established binding, and the incoming id is different, missing, null, or blank. The call is refused before any mutation. Equal @@ -1489,6 +1540,12 @@ besides the typed writes in section 6. It gains nothing beyond those: page's counts in section 1 come from that count. - A crate-private read of a stored vendor original, for the detail rules in section 2. +- In matching, for route `open_wearables` only, the owner-correction rule + in section 2. `KeyedPolicy` gains a flag that only that route sets. + `record_by_import_key` also returns the current revision's basis. For an + owner correction, matching reads the newest `provider_import` revision of + that record and compares the candidate with it. The page's report counts + each replaced correction. The pull reads the revision a preview matched at from `ProviderPreview::destination_database_revision`, which is already public. @@ -1784,6 +1841,8 @@ interactive open can preview, back up, ask, and then migrate. | Stage, match, and write each page | `preview_route` and `ProviderPreview::apply` in `src/import/provider.rs`. The revision a preview read is the public `destination_database_revision` | | A `connector` source with no vendor | new `connector_source` beside `route_source` in `src/import/provider.rs` | | Page counts by record type | a count beside `Staging::count` in `src/import/staging.rs`, exposed by `ProviderPreview` | +| Owner-correction rule and its count | `match_keyed` and `record_by_import_key` in `src/import/provider.rs`, behind a `KeyedPolicy` flag that only route `open_wearables` sets | +| Where a workout fix belongs | one paragraph in `skills/athletic-standard/SKILL.md`, under "Stable IDs and revisions" | | Device-binding facts and the safety snapshot | new `src/import/binding.rs`, called from the matching step in `src/import/provider.rs` for route `open_wearables` | | Create or first-bind with the checked receipt, and refuse any other `device_binding` change | the staged plan and `ProviderPreview::apply` in `src/import/provider.rs` | | Stored-original read for the vendor detail rules | a crate-private read in `src/import/provider.rs` | @@ -1798,6 +1857,15 @@ not the home for this client. `garmin_pull.rs` remains the Garmin pull. The two clients may each call `ureq`. A shared trait is the later connector work, and this release does not add it. +The build adds this paragraph to `skills/athletic-standard/SKILL.md`, +under "Stable IDs and revisions": "Fix an Open Wearables workout on its +workout session, or write a note. Do not correct the vendor original. It +is the vendor's own copy. A later pull keeps your correction until the +server's data for that record changes. Then the pull replaces it, counts +it, and keeps your correction in the record's history." This plan pull +request does not edit the skill, because the skill describes the +released version. + `mapping.rs` changes for `MappedPage` and for the preservation writes in section 2: the measurement-sample target, the reporting-window write, the segment copy, and the `vendor_workout` section. HTTP stays out of @@ -2230,6 +2298,28 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: start order. A third pull details the last five. A deferred id whose original already has a detail, and whose list object changed, keeps that detail, writes nothing, and adds no revision +- an owner corrects a stored Polar original with `ath correct`. The next + pull with the same server data writes nothing for it, the correction + stays current, and Polar's `owner_corrections_replaced` is 0. That pull + makes no detail call for the id, because the stored-original read uses + the newest `provider_import` revision. After the server's list object + changes, the preview prints `would replace 1 owner correction; delete an + original to keep it`, and `--json` has Polar's + `owner_corrections_replaced` 1. `--yes` replaces the correction, counts + it as a changed original and as 1 replaced, and keeps the owner's + revision in the history. A deleted original is left out instead, and + the count stays 0 +- an owner corrects a stored sleep session. A pull with the same server + data keeps the correction, and the top-level `owner_corrections_replaced` + is 0. A pull whose session changed replaces it, and the count is 1 in + the preview, in `--json`, and after `--yes`. The preview says `would + replace 1 owner correction of stored records because the server's data + changed`. `ath import --mapping open-wearables` of a file that holds the + same data also keeps the correction. Another route keeps its 2.1.1 rule +- a record whose current revision came from an accepted package merge is + an owner correction. A native export and restore keeps every revision's + basis, so the same pull reports the same counts before and after the + restore - without `--vendor-workouts`, preview and `--json` make zero requests to the connections route and to both workout routes. `requests_made` is false, `notice` is empty, and every live line is `not_attempted`. With @@ -2515,9 +2605,12 @@ Risks: command still spends up to 100 Garmin detail calls on ids that were `not_available`, after new ids. A deployment where that path works fills those details in on later commands. -- A later pull replaces an owner correction of a vendor original when the - server's envelope differs. The correction stays in the history. Deleting - the original stops it. +- A later pull replaces an owner correction when the server's data for + that record changed since an import last wrote it. The preview and the + result count each one. The correction stays in the history. Deleting + the record stops later pulls from changing it, and it also takes the + record out of current data. This rule covers every record on route + `open_wearables`, not only vendor originals. Other routes keep D182. - A deferred id that the provider stops listing is never detailed. Its list object stays stored, and the deferred count shows that it waits. - Date-only bounds mean whatever Open Wearables decides. The docs and the @@ -2615,4 +2708,7 @@ optional source key adds no column. request. It calls only active connections and never stores the connections list. It keeps every stored detail, counts every object it does not write, and withholds credential-shaped values. The stored - workout and the vendor original stay two records (D242, D243, D244). + workout and the vendor original stay two records. On route + `open_wearables`, an owner correction is kept until the server's data + for that record changes, and each correction a page replaces is counted + (D242, D243, D244). From 6256e62ed7039d6be21a505f0c29a3b3dd709933 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 05:20:09 +0000 Subject: [PATCH 29/60] Stop a provider on 429, compare withheld copies, count vendor pages An HTTP 429 now ends that provider for the command, as a timeout does, with the remaining ids deferred. Credential values are withheld before any comparison, so a changed token does not look like a vendor change. A committed vendor page is a protected write: it sets written and database_changed, and its originals add to committed.source_report. Co-authored-by: Michael Whitham --- build-history/v2.2.0/decisions.md | 26 +++++++++++++++--- build-history/v2.2.0/spec.md | 44 ++++++++++++++++++++++++++++--- 2 files changed, 63 insertions(+), 7 deletions(-) diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index a38f82ec..73c71f96 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -100,6 +100,11 @@ These edits answer the review of this plan at `d636d7a`: Each replaced correction is counted per provider and for stored records, in the text, in `--json`, and in the preview. The skill says where a workout fix belongs. +- D243. An HTTP 429 stops that provider for the command, as a timeout + does. Credential values are withheld before any comparison. +- D230 and D236. A committed vendor page is a protected write. It sets + `written` and `database_changed`, and its originals add to + `committed.source_report`. ## D227. Version 2.2.0 is one manual pull, and the program and the record share that number @@ -433,7 +438,9 @@ confirmed `--yes` has the actual protected and archive counts. `written` is true when a protected transaction in the command created or revised a counted record. An archive does not make it true. `database_changed` is true when a protected transaction or an archive transaction committed a -change. A successful repeat of an unchanged command has both flags false. +change. A vendor page (D242) is a protected transaction, so a committed +vendor original makes both flags true even when every stored page was +unchanged. A successful repeat of an unchanged command has both flags false. The command prints the confirmed outcome as text. It prints the preview outcome as public JSON. On a partial failure it keeps the confirmed outcome and then exits @@ -978,7 +985,9 @@ store. A failure before commit restores the old schema, the old rows, and the old version. `writable_schema` is not used. Files 001 through 005 stay unchanged. -`written` counts protected creates and revisions across the command. An +`written` counts protected creates and revisions across the command, +including vendor originals. Those are `source_report` records, so they +also add to `committed.source_report`. An archive-only change leaves it false and sets `database_changed` true. Archive counts are separate from protected counts. A later page does not clear either. A failed archive apply keeps the refusal, writes nothing, @@ -1342,7 +1351,9 @@ next page `next_token`. The request name, `nextToken`, is not sent. Sensorbio reads only the oldest 50 entries, and its line says so. A stored detail is never lost. A detail is fetched for an id with no -stored detail, and again only when the list object changed. A list-only +stored detail, and again only when the list object changed. Credential +values (D244) are withheld before any comparison, so a token that changed +between pulls does not make a list object look changed. A list-only object never replaces a stored detail. A new detail that is thinner than the stored one writes nothing. Thinner means a detail field the specification's table names for that provider is filled in the stored @@ -1355,7 +1366,11 @@ Live requests go one at a time, at least one second apart. The read timeout is 360 seconds. The server's own retries can take about 225 seconds, so the client waits for them. A live request that still times out ends that provider for the command, so two requests to one provider -never overlap. A command makes at most 100 detail calls to one provider +never overlap. An HTTP 429 ends that provider the same way, because the +server has already spent its three retries on the vendor's limit. The +detail call that got 429 is `failed`. Ids whose detail was not yet called +are `deferred`. What the provider already returned is still written, and +the provider is `incomplete`. A command makes at most 100 detail calls to one provider and at most 20 to Strava. Ids with no stored detail go first, oldest start first. Strava's limit belongs to the whole application, so the deployment's own sync shares it. The review cited about 100 requests a @@ -1399,6 +1414,9 @@ Rejected alternatives: longer. The client would give up, and a rerun could send a second request while the first still runs. - Retry a live request that timed out. Rejected for the same reason. +- Keep calling a provider after a 429. Rejected. The server has already + waited about 105 seconds and retried three times, and more calls would + spend a limit the deployment's own sync shares. - Leave live reads on by default. Rejected. The server can change a token and revoke a connection while answering the GET. diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index 852d73b9..4b8a7275 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -145,7 +145,13 @@ the success sentence. `written` is true when any protected transaction in this command created or revised a counted record. An archive does not make `written` true. `database_changed` is true when any protected transaction or any archive transaction in this command committed a -change, including the first insert of the archive source. A later page +change, including the first insert of the archive source. A vendor page +in section 2 is a protected transaction. Its originals are `source_report` +records, so they add to `committed.source_report` as well as to +`vendor_workouts.originals` and that provider's counts. A committed vendor +page that creates or revises an original makes `written` true and +`database_changed` true, even when every stored page was unchanged. A +first `vendor_workout` source counts as a database change. A later page does not reset either flag or the counts from an earlier page. An empty ranged result can still store the personal record or the body snapshot. Those writes are counted as protected rows. They are not ranged rows. @@ -995,7 +1001,16 @@ finish those retries first. If a live request still times out, the server may still be working on it. The pull then sends no other request to that provider in this command, so two requests to one provider never overlap. That provider is `incomplete`. The next provider still runs, and it uses -a different vendor account and limit. A server whose provider timeout is +a different vendor account and limit. An HTTP 429 from a live request +stops that provider the same way. The server has already waited and +retried three times, so the vendor's limit is spent. No later list call, +window, or detail call goes to that provider in this command. The detail +call that got 429 counts as `failed`. Every listed id that had not had its +detail call yet counts as `deferred`, and a later command details it by +the order below. What the provider already returned is still written as that +provider's page: the list objects, and the details already fetched. A +later Garmin window after a 429 or a timeout is not sent, unlike a window +that failed another way. A server whose provider timeout is raised can outlast this timeout. The same rule covers that case. The stored reads keep 30 seconds to connect and 120 seconds to read, the values `src/runtime/garmin_pull.rs` uses. @@ -1144,6 +1159,13 @@ The start column names one field and how to read it: The start is stored and is not a filter. +The pull withholds credential values, by the rule in section 4, in each +list object and each detail before it compares anything. The detail +order, the `kept` check, the thinner check, and the owner-correction rule +all compare withheld copies. So a Garmin list object whose +`userAccessToken` changed between pulls still equals its stored copy, and +it gets no detail call. + For each listed id, the pull first reads the stored original, if there is one. That read is crate-private and lives in `src/import/provider.rs`. It returns whether the original exists, whether it is deleted, whether it @@ -1921,7 +1943,8 @@ to `estimated` and its archive estimates to `estimated_archive`. It does not add `outcome` across pages. `outcome` counts the source-device row in the same group. Filtering that row out of the totals does not make a preview equal a write. A preview page writes nothing, so page two does not -see page one. +see page one. A vendor page is a protected page. Its originals add to +`committed.source_report` and to the vendor counts. The command reads the saved key and `OPEN_WEARABLES_API_KEY` in this process, in `src/runtime/keyring.rs`. It has no `--key` flag. The @@ -2373,6 +2396,21 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: timeout shortened for the test, stops every later request to that provider in the command. The next provider still runs. The 360-second value is checked as a named constant +- five Strava ids with no stored detail, where the third detail call + answers HTTP 429. The fixture server sees no later Strava request. Ids + one and two store their details. Id three is `failed`. Ids four and five + are `deferred`. All five list objects are stored. Strava is + `incomplete`, the next provider still runs, and the exit is nonzero. A + 429 on a Garmin window sends no later window +- a Garmin list object with `userAccessToken` is pulled twice, with a + different token value the second time. The second pull counts it + `kept`, makes no detail call, and writes nothing for it +- an empty database is pulled once without `--vendor-workouts`, which + stores the personal record. A second pull of the same stored data with + the flag, whose only new rows are two Garmin originals, reports + `written` true and `database_changed` true, `committed.source_report` + new 2, and Garmin `originals` new 2. A third identical pull reports both + flags false - a Garmin list object with `userAccessToken` stores that original with the value `[withheld by ath]`. The record, the export, the text, and `--json` do not hold the token. `withheld` counts 1 and names the path. From 49ed30311527dd1c74d562e2ad6f0948c5970bfc Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 05:23:14 +0000 Subject: [PATCH 30/60] Keep the later window's copy of a Garmin activity seen twice Garmin windows select by upload time, so an activity uploaded again can appear in two windows. Keep the later window's object, count the earlier as superseded, and still refuse two different objects inside one window. Add the synthetic two-window fixture case to the tests. Co-authored-by: Michael Whitham --- build-history/v2.2.0/decisions.md | 12 +++++++++++- build-history/v2.2.0/spec.md | 23 ++++++++++++++++++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index 73c71f96..8d70c398 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -105,6 +105,9 @@ These edits answer the review of this plan at `d636d7a`: - D230 and D236. A committed vendor page is a protected write. It sets `written` and `database_changed`, and its originals add to `committed.source_report`. +- D243. When one Garmin activity id is in two windows with different + objects, the later window's copy is kept and the earlier is counted as + `superseded`. ## D227. Version 2.2.0 is one manual pull, and the program and the record share that number @@ -1379,7 +1382,11 @@ docs. The one-second pace keeps this command at 60 a minute or fewer. A vendor id is text. A JSON integer is written in decimal, so `123` and `"123"` are one id. An integer above 9007199254740991 is refused, because -D213 would change its digits. The start becomes `input_timestamp` by the +D213 would change its digits. When one Garmin activity id is in two +windows with different objects, the later window's copy is kept, because +windows select by upload time and the later window holds the later +upload. The earlier copy counts as `superseded`. Inside one window, two +different objects with one id are both refused. The start becomes `input_timestamp` by the rules in the specification: text keeps its offset or says it has none, and Unix seconds or milliseconds keep their digits. The start is stored and is not a filter. @@ -1425,6 +1432,9 @@ Rejected alternatives: failed provider must not hide a finished one. - Let the server split a Garmin range. Rejected. A failed window must be visible as incomplete. +- Refuse both copies when one Garmin id is in two windows with different + objects, as inside one response. Rejected. A re-upload is an ordinary + Garmin event, and the later window holds the later copy. - Drop an original whose start is outside the requested range. Rejected. The live methods do not filter by workout start, so a drop would hide a returned object. diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index 4b8a7275..84356830 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -1139,6 +1139,15 @@ reason. A refused object refuses only itself, and the count says why. Two different objects with one id in one provider's response refuse both, because the pull cannot tell which is right. Two equal objects are one. +Garmin is read in windows, and one activity can be in two windows when +Garmin received it again. A window selects by upload time, so the later +window holds the later copy. For Garmin only, an object in a later window +replaces a different object with the same id from an earlier window. The +earlier copy counts as `superseded` in `left_out`, and the later copy goes +through the detail rules. Equal copies in two windows are one object, and +nothing is counted. Inside one window, two different objects with one id +still refuse both as `duplicate_id`. + The start column names one field and how to read it: - Text with an offset or `Z`. The receipt is the one `input_receipt` in @@ -1292,8 +1301,8 @@ Each provider's line, and its object in `--json`, counts: - `details`: `stored`, `kept`, `deferred`, `failed`, `mismatch`, `thinner`, and `not_available`. - `left_out`: objects not written, by reason: `missing_id`, - `unusable_id`, `unsafe_number`, `duplicate_id`, `deleted_record`, - `deleted_source`, and `response_refused`. + `unusable_id`, `unsafe_number`, `duplicate_id`, `superseded`, + `deleted_record`, `deleted_source`, and `response_refused`. - `withheld`: values that section 4 withheld, with up to 20 paths. Each listed object is in exactly one detail count or one left-out count. @@ -1970,7 +1979,8 @@ system library. CI has no Open Wearables account, no API key, and no Docker Compose. The acceptance tests are the fixture server and the synthetic files already in `tests/fixtures/exports/open-wearables/`. Those files are on the public-data -list. A new file, if one is required for a two-page response, is synthetic, +list. A new file, such as a two-page response or the two-window Garmin +fixture below, is synthetic, invented, and added to `tools/public-data-allowlist.json` with its path and SHA-256. `tests/public_data.rs` enforces that list. No real export is copied. @@ -2377,6 +2387,13 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: as `unsafe_number`. A fractional id refuses only that object and counts it as `unusable_id`. Two different objects with one id are both refused as `duplicate_id` +- a synthetic Garmin fixture returns activity 555 in the first window with + `durationInSeconds` 1800 and in the second window with 1860. One original + is stored, and its `list` is the second window's object. Garmin's + `left_out` counts 1 `superseded`, and Garmin is `completed`. The same id + with equal objects in both windows stores one original and counts + nothing. The same id twice in one window, with different objects, + refuses both as `duplicate_id` - a three-day Garmin range sends four windows, three of 82,800 seconds and one of 10,800 seconds. Each window sends `summary_start_time` and `summary_end_time` as integer Unix seconds, and each starts where the From 9cf540ddce2a717b7b19651e7d05738387830c5c Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 05:24:47 +0000 Subject: [PATCH 31/60] Bound the total size of vendor originals A package writes vendor originals in its main document, current record and every revision, under the 512 MiB read cap. Add a 128 MiB total bound that refuses a page before a package would become unreadable, have export refuse a document over the read cap, and add the large round-trip test. Co-authored-by: Michael Whitham --- build-history/v2.2.0/decisions.md | 26 ++++++++++++- build-history/v2.2.0/spec.md | 63 ++++++++++++++++++++++++++++++- 2 files changed, 87 insertions(+), 2 deletions(-) diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index 8d70c398..00103186 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -108,6 +108,9 @@ These edits answer the review of this plan at `d636d7a`: - D243. When one Garmin activity id is in two windows with different objects, the later window's copy is kept and the earlier is counted as `superseded`. +- D242. Vendor originals have a 128 MiB total bound, because a package + holds them in its main document under the 512 MiB read cap. `ath export` + refuses to publish a document over that cap. ## D227. Version 2.2.0 is one manual pull, and the program and the record share that number @@ -1260,7 +1263,20 @@ every later pull from changing it. Each provider's line counts originals as new, changed, and unchanged. It counts owner corrections replaced, details by outcome, objects left out -by reason, and withheld values. Each listed object is in exactly one detail count or one left-out +by reason, and withheld values. + +Vendor originals have a total size bound, `MAX_VENDOR_ORIGINAL_BYTES`, +128 MiB, counted over every revision of every original. A native package +writes them in its main document, `athlete.ath.json`, with every record +that is not a measurement sample: the current record under `records` and +each revision under `record_revisions`. Only samples go to `series/` +files. Version 2.1.1 reads that document only up to 512 MiB, and a mapped +import file only up to 512 MiB. The bound keeps the originals near half of +the main document. A page that would pass it is refused, its objects +count as `size_cap`, and that provider is `incomplete`. A mapped import +uses the same bound. `ath export` gains a check that refuses to publish a +document over the 512 MiB read cap, because 2.1.1 can write a package it +cannot read back. Each listed object is in exactly one detail count or one left-out count, so no object is dropped without a count. The pull uses the published query parameters and does not add its own @@ -1281,6 +1297,14 @@ Rejected alternatives: - Store the list object and the detail as two records. Rejected. They describe one workout, and nothing in either object joins them except the id the envelope already uses. +- Store vendor originals with no size bound. Rejected. They share the + package's main document, and an export past its read cap could not be + restored. +- Store only the list object once the bound is near. Rejected. The pull + would drop details while it reported success. +- Store originals in their own package files now. Not chosen for this + release. It changes the package format. Section 9 of the specification + lists it. - Replace an owner correction whenever the candidate differs from the current record, as D182 does and as the first version of this decision did. Rejected. A pull repeats the same server data, so every pull would diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index 84356830..1e1b0e15 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -1267,6 +1267,41 @@ mapping reads. The match key is the writer, the sensor, the resource `vendor_workout`, the provider, and the vendor id, escaped by D181. So the Suunto record in section 7 has a key that ends `suunto|1001`. +Vendor originals have a total size bound. `MAX_VENDOR_ORIGINAL_BYTES` in +`src/input_policy.rs` is 128 MiB. It counts the bytes of `record_json` in +every revision of every vendor original, including a deleted one. A native +package writes these records in its main document, `athlete.ath.json`, +with every other record that is not a measurement sample. The current +record is under `records`, and each revision is under `record_revisions`. +Only measurement samples go to the `series/` files. So each original is in +that one document at least twice. Version 2.1.1 reads a package document +only up to `MAX_PACKAGE_DOCUMENT_BYTES`, which is 512 MiB, and a mapped +import file only up to `MAX_MAPPED_INPUT_BYTES`, also 512 MiB. The bound +keeps the originals near 256 MiB of the main document, and the rest is +left for every other record. A saved file of current envelopes is at most +128 MiB plus its JSON wrapping, so it fits the mapped-import cap. + +The matching step of a page with `vendor_workout` rows adds the page's +new and changed envelopes to the stored total. A page that would pass the +bound is refused. It writes nothing, its objects count as `size_cap` in +`left_out`, and that provider is `incomplete`. The line says the stored +vendor originals would pass 128 MiB, so a package holding them could not +be read back. `ath import --mapping open-wearables` uses the same bound. +A Polar detail with samples and a route for a one-hour outdoor workout is +a few hundred kilobytes, so the bound holds several hundred such workouts +with one revision each. Deleting an original does not lower the total, +because its revisions stay. `ath erase` removes the record and its +revisions, so it does. Storing originals in their own package files is +later work, in section 9. + +`ath export` in 2.1.1 writes the main document and the series files with +no size check, so it can publish a package that `src/package/load.rs` +refuses to read. The build adds that check to `src/package/export.rs`. +Export counts the bytes of each document it writes into its staging +folder. When one passes `MAX_PACKAGE_DOCUMENT_BYTES`, export fails before +the rename, removes the staging folder, publishes nothing, and names the +document that was too large. + The pull writes one provider's originals as one page, after that provider's list and detail calls finish. The page is one preview at one database revision. With `--yes` and without `--json`, it is then one @@ -1302,7 +1337,7 @@ Each provider's line, and its object in `--json`, counts: `thinner`, and `not_available`. - `left_out`: objects not written, by reason: `missing_id`, `unusable_id`, `unsafe_number`, `duplicate_id`, `superseded`, - `deleted_record`, `deleted_source`, and `response_refused`. + `deleted_record`, `deleted_source`, `response_refused`, and `size_cap`. - `withheld`: values that section 4 withheld, with up to 20 paths. Each listed object is in exactly one detail count or one left-out count. @@ -1577,6 +1612,10 @@ besides the typed writes in section 6. It gains nothing beyond those: owner correction, matching reads the newest `provider_import` revision of that record and compares the candidate with it. The page's report counts each replaced correction. +- In matching, for a page with `vendor_workout` rows, the size bound in + section 2. It sums the stored vendor-original revisions and refuses the + page when its new and changed envelopes would pass + `MAX_VENDOR_ORIGINAL_BYTES`. The pull reads the revision a preview matched at from `ProviderPreview::destination_database_revision`, which is already public. @@ -1874,6 +1913,8 @@ interactive open can preview, back up, ask, and then migrate. | Page counts by record type | a count beside `Staging::count` in `src/import/staging.rs`, exposed by `ProviderPreview` | | Owner-correction rule and its count | `match_keyed` and `record_by_import_key` in `src/import/provider.rs`, behind a `KeyedPolicy` flag that only route `open_wearables` sets | | Where a workout fix belongs | one paragraph in `skills/athletic-standard/SKILL.md`, under "Stable IDs and revisions" | +| Total size bound for vendor originals | `MAX_VENDOR_ORIGINAL_BYTES` in `src/input_policy.rs`, checked in the matching step in `src/import/provider.rs` | +| Export refuses a document over the package read cap | `src/package/export.rs`, before the staging folder is renamed | | Device-binding facts and the safety snapshot | new `src/import/binding.rs`, called from the matching step in `src/import/provider.rs` for route `open_wearables` | | Create or first-bind with the checked receipt, and refuse any other `device_binding` change | the staged plan and `ProviderPreview::apply` in `src/import/provider.rs` | | Stored-original read for the vendor detail rules | a crate-private read in `src/import/provider.rs` | @@ -2387,6 +2428,17 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: as `unsafe_number`. A fractional id refuses only that object and counts it as `unusable_id`. Two different objects with one id are both refused as `duplicate_id` +- a synthetic database whose vendor originals, with their revisions, total + just under `MAX_VENDOR_ORIGINAL_BYTES` exports with `ath export`. The + main document is under 512 MiB. `ath import` of that package into a + database made by `ath init --empty` keeps every record id, revision, + deletion, and import key. + The restored database passes `ath check`. A vendor page that would pass + the bound is refused, writes nothing, counts its objects as `size_cap`, + and makes that provider `incomplete`. A mapped import of the same + envelopes is refused the same way. An export whose main document would + pass the read cap, with that cap lowered for the test, fails before the + rename and publishes nothing - a synthetic Garmin fixture returns activity 555 in the first window with `durationInSeconds` 1800 and in the second window with 1860. One original is stored, and its `list` is the second window's object. Garmin's @@ -2622,6 +2674,10 @@ is in the build pull request. is separate work. The pull does not add one. - The mapping path rule is already `is_mapping_path` in `src/assets/mod.rs`. There is no duplicate to delete. +- Vendor originals live in the package's main document, under its 512 MiB + read cap. Storing them in their own package files, as samples are, would + lift the 128 MiB bound in section 2. That is a package format change, + and this release does not make it. No maintainability note under another name was found in the 2.1.0 or 2.1.1 decision logs. The sizes above are the code at 2.1.1, not a @@ -2668,6 +2724,11 @@ Risks: `open_wearables`, not only vendor originals. Other routes keep D182. - A deferred id that the provider stops listing is never detailed. Its list object stays stored, and the deferred count shows that it waits. +- Vendor originals share the main package document and its 512 MiB read + cap. The 128 MiB bound refuses a vendor page before a package would + become unreadable. A person with several hundred Polar workouts that + have routes can reach it. That provider then stays `incomplete` until + originals are erased, or a later version stores them in their own files. - Date-only bounds mean whatever Open Wearables decides. The docs and the 0.11.0 parser disagree about UTC. This release does not correct that server. - Section 2 stores returned periods, series, and snapshots. It does not From 815e69b0198afa346f1a15e9e1ad175dd741413a Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 05:27:41 +0000 Subject: [PATCH 32/60] Name the outcomes for Suunto without a key and for refused details A Suunto list object with no workoutKey gets no detail call and is not_available, because nothing shows the workoutId fallback works. A detail over the response cap is too_large and a detail the privacy scan refuses is refused; both leave the provider incomplete. Add a test for the 100-detail budget. Co-authored-by: Michael Whitham --- build-history/v2.2.0/decisions.md | 30 +++++++++++++---- build-history/v2.2.0/spec.md | 55 ++++++++++++++++++++++--------- 2 files changed, 63 insertions(+), 22 deletions(-) diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index 00103186..82029cd8 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -111,6 +111,10 @@ These edits answer the review of this plan at `d636d7a`: - D242. Vendor originals have a 128 MiB total bound, because a package holds them in its main document under the 512 MiB read cap. `ath export` refuses to publish a document over that cap. +- D243. A Suunto list object with no `workoutKey` gets no detail call and + is `not_available`. A detail over the response cap is `too_large`, and a + detail the privacy scan refuses is `refused`. Both make the provider + `incomplete`. ## D227. Version 2.2.0 is one manual pull, and the program and the record share that number @@ -1371,9 +1375,11 @@ is stored whole, and Garmin stays `completed`. Any other Garmin detail error is `failed`. An id that was `not_available` is detailed again after the new and changed ids, inside the same budget. The maintainer confirms this rule before approval. Polar's list omits samples, zones, and route, and detail -asks for all three. Suunto's detail is called at `workoutKey` when the -list object has one, and at `workoutId` otherwise. Its `payload` is -unwrapped, and the record key is `workoutId`. Whoop's response names its +asks for all three. Suunto's detail is called at `workoutKey`. A list +object with no `workoutKey` gets no detail call and is `not_available`, +because nothing this study read shows that Suunto's detail accepts a +`workoutId`. Its `payload` is unwrapped, and the record key is +`workoutId`. Whoop's response names its next page `next_token`. The request name, `nextToken`, is not sent. Sensorbio reads only the oldest 50 entries, and its line says so. @@ -1385,9 +1391,14 @@ object never replaces a stored detail. A new detail that is thinner than the stored one writes nothing. Thinner means a detail field the specification's table names for that provider is filled in the stored detail and empty in the new one. A deferred or failed detail keeps the -stored detail and adds no revision. A failed or mismatched detail makes -the provider `incomplete` and the exit nonzero. A deferred detail leaves -the provider `completed`, with a separate deferred count. +stored detail and adds no revision. A detail over the 10 MiB response cap +is `too_large`, because the detail route has no smaller page. A detail +the privacy scan refuses is `refused`. Neither is stored. A failed, +mismatched, too large, or refused detail makes the provider `incomplete` +and the exit nonzero, because a limit may refuse work but must not report +it as complete. A too large or refused id is retried after the new and +changed ids. A deferred detail leaves the provider `completed`, with a +separate deferred count. Live requests go one at a time, at least one second apart. The read timeout is 360 seconds. The server's own retries can take about 225 @@ -1456,6 +1467,13 @@ Rejected alternatives: failed provider must not hide a finished one. - Let the server split a Garmin range. Rejected. A failed window must be visible as incomplete. +- Call Suunto detail at `workoutId` when the list object has no + `workoutKey`, as the earlier text did. Rejected. No source this study + read shows that call works, and a wrong call would count as `failed` on + every command. +- Count a too large detail as `not_available`. Rejected. The vendor has + the detail, and this program's own cap refused it, so the provider did + not finish. - Refuse both copies when one Garmin id is in two windows with different objects, as inside one response. Rejected. A re-upload is an ordinary Garmin event, and the later window holds the later copy. diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index 1e1b0e15..4221b71a 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -218,7 +218,9 @@ the text. The object has no key, server, user id, or request path. "failed": 0, "mismatch": 0, "thinner": 0, - "not_available": 0 + "not_available": 0, + "too_large": 0, + "refused": 0 }, "left_out": { "total": 0, "by_reason": {} } } @@ -1046,7 +1048,7 @@ timeout above. |---|---|---|---|---|---|---|---|---| | Garmin | the JSON array | `activityId` | `startTimeInSeconds`, Unix seconds | `activityId` | the object | none named | every window; 100 details | 360 s | | Polar | the JSON array | `id` | `start_time`, text with no offset | `id` | the object | `samples`, `zones`, `route` | 1 list; 100 details | 360 s | -| Suunto | `payload` | `workoutId` | `startTime`, Unix milliseconds | `workoutKey`, else `workoutId` | `payload` | none named | list pages of 100; 100 details | 360 s | +| Suunto | `payload` | `workoutId` | `startTime`, Unix milliseconds | `workoutKey`. No call without it | `payload` | none named | at most 100 list pages of 100; 100 details | 360 s | | Whoop | `records` | `id` | `start`, text with offset | `id` | the object | none named | 1 list; 100 details | 360 s | | Fitbit | the JSON array. The method reads `activities` | `logId` | `startTime`, text with offset | no detail call | none | none | 1 list | 360 s | | Oura | `data` | `id` | `start_datetime`, text with offset | `id` | the object | none named | 1 list; 100 details | 360 s | @@ -1084,8 +1086,11 @@ timeout above. milliseconds, `filter_by_modification_time=false`, and `limit` 100, and pages `offset` until a short page. False means creation time. A page over the response cap is asked again with a smaller `limit`, down to 1. - The record key is `workoutId`. Detail is called at `workoutKey` when the - list object has one, and at `workoutId` otherwise. Detail unwraps + The record key is `workoutId`. Detail is called at `workoutKey`. A list + object with no `workoutKey` gets no detail call, and its detail is + `not_available`. The pinned detail method calls + `/v3/workouts/{workout_key}`, and nothing this study read shows that + Suunto accepts a `workoutId` there. Detail unwraps `payload`. A detail matches when its `workoutId` or its `workoutKey` equals the list object's. The pinned `WorkoutJSON` model has no `workoutKey`. The pinned tests and Suunto's own API use it, so the list @@ -1186,7 +1191,7 @@ The pull calls detail only when the provider has a detail call and its budget allows. It spends the budget in this order. First come ids with no stored detail that no earlier command marked `not_available`. Then come ids whose list object differs from the stored `list`. Then come ids an -earlier command marked `not_available`. Inside each group the oldest start +earlier command marked `not_available`, `too_large`, or `refused`. Inside each group the oldest start goes first. An id without a start instant goes last in its group, in list order. So a Garmin path that answers 404 for every id still lets new ids go first, and it costs at most the provider's budget in one command. An id whose original holds a @@ -1213,16 +1218,23 @@ What is written for one id depends on what this command got: `unchanged` and nothing is written. The id counts as `kept`. - No new detail, and none stored. The original is written with the list object alone. `detail_status` says why: `deferred`, `failed`, - `mismatch`, or `not_available`. The id counts under the same word. - `not_available` means the provider has no detail call, or Garmin - answered its detail call with 404 or 501. + `mismatch`, `not_available`, `too_large`, or `refused`. The id counts + under the same word. + `not_available` means the provider has no detail call, Garmin answered + its detail call with 404 or 501, or a Suunto list object has no + `workoutKey`. A detail response over `MAX_PULL_RESPONSE_BYTES` is + `too_large`, because the detail route has no smaller page. A detail + that the privacy scan in section 4 refuses, because it holds the key, + the origin, or the user id, is `refused`. Neither of those is stored, + and each is counted on the provider's line. - No new detail, but one is stored, and the list object changed. Nothing is written for that id, and no revision is added. The stored detail - stays. The id counts as `deferred`, `failed`, or `mismatch`. + stays. The id counts as `deferred`, `failed`, `mismatch`, `too_large`, + or `refused`. -A list-only object therefore never replaces a stored detail. A `failed` -or `mismatch` detail makes the provider `incomplete`, and the exit is -nonzero. A `not_available` detail leaves the provider `completed`. A +A list-only object therefore never replaces a stored detail. A `failed`, +`mismatch`, `too_large`, or `refused` detail makes the provider +`incomplete`, and the exit is nonzero. A `not_available` detail leaves the provider `completed`. A `deferred` detail leaves the provider `completed`, with the deferred count on its line, and the next command details those ids first. A deferred id that the provider stops listing is never detailed by a later @@ -1252,8 +1264,8 @@ the same object: - `list` is the list object. `list_parent` is present only for Sensorbio. - `detail` is the detail object after the table's detail unwrap. It is absent when no detail is stored. -- `detail_status` is `stored`, `deferred`, `failed`, `mismatch`, or - `not_available`. +- `detail_status` is `stored`, `deferred`, `failed`, `mismatch`, + `not_available`, `too_large`, or `refused`. - A value that section 4 withholds is replaced in place by its marker. Nothing else in `list`, `list_parent`, or `detail` is changed. @@ -1334,7 +1346,7 @@ Each provider's line, and its object in `--json`, counts: by the owner-correction rule above. Each is also counted as a changed original. - `details`: `stored`, `kept`, `deferred`, `failed`, `mismatch`, - `thinner`, and `not_available`. + `thinner`, `not_available`, `too_large`, and `refused`. - `left_out`: objects not written, by reason: `missing_id`, `unusable_id`, `unsafe_number`, `duplicate_id`, `superseded`, `deleted_record`, `deleted_source`, `response_refused`, and `size_cap`. @@ -2365,6 +2377,15 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: changed list object writes nothing and adds no revision. A detail that names another id is `mismatch`, is not stored, and also makes Polar `incomplete` +- a Polar detail over `MAX_PULL_RESPONSE_BYTES`, with the cap lowered for + the test, is `too_large`. The list object is stored alone, Polar is + `incomplete`, and the exit is nonzero. A Polar detail that holds the + selected user id is `refused`, is not stored, and makes Polar + `incomplete`. The list object of that id passed the scan and is stored. + On the next command, a new Polar id is detailed before either of them +- 101 Polar ids with no stored detail. The first pull makes 100 detail + calls, oldest start first, and the newest id is `deferred`. Polar stays + `completed` with `deferred` 1. The second pull details that id first - 45 Strava ids with no stored detail. The first pull details the 20 oldest starts and stores the other 25 with `detail_status` `deferred`. Strava stays `completed`, its line counts 25 deferred, and the exit is @@ -2422,7 +2443,9 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: - a Suunto list object `{"workoutId": 1001, "workoutKey": "abc"}` calls detail at `abc`. The detail's `payload` is unwrapped. One record is stored, and its key ends `suunto|1001`. A detail that names 1001 or - `abc` matches. A list object with no `workoutKey` calls detail at 1001 + `abc` matches. A list object with no `workoutKey` makes no detail call. + It is stored with `detail_status` `not_available`, and Suunto stays + `completed` - a Garmin `activityId` of `123` and a later `"123"` are one record. An integer above 9007199254740991 refuses only that object and counts it as `unsafe_number`. A fractional id refuses only that object and counts From c154521544d814a42479e0bbf651ae798647bd39 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 05:29:05 +0000 Subject: [PATCH 33/60] Make no detail calls in a preview, cap Suunto paging, state timing A preview now reads lists only, so a preview then --yes makes each detail call once and reads each list twice, and both texts say so. Strava's worst case drops to 24 requests with the 429 stop. One command sends at most 100 Suunto list requests. State that a detail can come minutes after its list object. Co-authored-by: Michael Whitham --- build-history/v2.2.0/decisions.md | 24 +++++++++--- build-history/v2.2.0/spec.md | 62 ++++++++++++++++++++++++++----- 2 files changed, 71 insertions(+), 15 deletions(-) diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index 82029cd8..1beec4e1 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -115,6 +115,10 @@ These edits answer the review of this plan at `d636d7a`: is `not_available`. A detail over the response cap is `too_large`, and a detail the privacy scan refuses is `refused`. Both make the provider `incomplete`. +- D243. A preview reads each list and makes no detail call, so a preview + then `--yes` reads each list twice and makes each detail call once. One + command sends at most 100 Suunto list requests. A detail can come + minutes after its list object, and the plan says so. ## D227. Version 2.2.0 is one manual pull, and the program and the record share that number @@ -1334,9 +1338,12 @@ procedure. `--vendor-workouts` is off unless the person passes it. Off, preview and `--json` call neither the connections route nor a live workout route. -On, those calls run for a preview too. The preview writes nothing in this -database and prints `vendor requests were made`. "Nothing stored" and -"nothing written" always mean this database. +On, a preview reads the connections list and each active provider's list, +and it makes no detail call. Its detail counts are estimates. The preview +writes nothing in this database and prints `vendor requests were made`. +"Nothing stored" and "nothing written" always mean this database. A +preview and then `--yes` read each list twice, and the preview and the +help say so. Running `--yes` alone reads each list once. The server, while answering the GET, can save a refreshed vendor token, revoke a connection, emit `connection.revoked`, write `token_refresh_lock` @@ -1379,7 +1386,9 @@ asks for all three. Suunto's detail is called at `workoutKey`. A list object with no `workoutKey` gets no detail call and is `not_available`, because nothing this study read shows that Suunto's detail accepts a `workoutId`. Its `payload` is unwrapped, and the record key is -`workoutId`. Whoop's response names its +`workoutId`. One command sends at most 100 Suunto list requests, +`MAX_VENDOR_LIST_PAGES`. A cap that stops a list after a full page makes +Suunto `incomplete`, and the objects already read are still written. Whoop's response names its next page `next_token`. The request name, `nextToken`, is not sent. Sensorbio reads only the oldest 50 entries, and its line says so. @@ -1398,7 +1407,10 @@ mismatched, too large, or refused detail makes the provider `incomplete` and the exit nonzero, because a limit may refuse work but must not report it as complete. A too large or refused id is retried after the new and changed ids. A deferred detail leaves the provider `completed`, with a -separate deferred count. +separate deferred count. A detail is read after the provider's whole +list, so it can come minutes after its list object, and the vendor can +change the workout in between. The envelope does not record when each +part was read. Live requests go one at a time, at least one second apart. The read timeout is 360 seconds. The server's own retries can take about 225 @@ -1471,6 +1483,8 @@ Rejected alternatives: `workoutKey`, as the earlier text did. Rejected. No source this study read shows that call works, and a wrong call would count as `failed` on every command. +- Make detail calls in a preview. Rejected. A preview and then `--yes` + would make every detail call twice, and Strava's limit is shared. - Count a too large detail as `not_available`. Rejected. The vendor has the detail, and this program's own cap refused it, so the provider did not finish. diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index 4221b71a..f21cfc1b 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -292,7 +292,9 @@ is otherwise unchanged, and it still writes without a preview. The flag's help in `src/cli/spec.rs` says: also read live vendor workouts; the server may refresh and save vendor tokens, revoke a connection, and -wait about 105 seconds on a rate limit. `src/cli/examples/pull.txt` repeats +wait about 105 seconds on a rate limit. It also says that a preview reads +each provider's list but makes no detail call, and that a preview and +then `--yes` read each list twice. `src/cli/examples/pull.txt` repeats those three effects and says that "nothing stored" means this database only. @@ -946,11 +948,22 @@ The following are not requested. Each line is the reason. `--vendor-workouts` is off by default. Off, the command makes no request to `/api/v1/users/{user_id}/connections` and no request to either live workout route. Preview and `--json` without the flag make those zero -requests. On, the same preview and `--json` do make them, write nothing -in this database, and print `vendor requests were made`. "Nothing stored" +requests. On, the same preview and `--json` read the connections list and +each active provider's list. They make no detail call, write nothing in +this database, and print `vendor requests were made`. "Nothing stored" and "nothing written" always mean this database. The server can still change, as the next paragraph says. +A preview's `details` counts are estimates from the stored originals. +`stored` counts the ids that `--yes` would detail now, and `deferred` the +ids past the budget. `kept` and `not_available` are counted as `--yes` +would count them. `failed`, `mismatch`, `thinner`, `too_large`, and +`refused` are zero in a preview, because only a detail call can find +them. A preview and then `--yes` read each provider's list twice. That is +one extra call for most providers, every window again for Garmin, and +every page again for Suunto. To read each list once, run `--yes` without +a separate preview. The preview and the flag's help say so. + A live call can change the server. `api_client.py` at the pinned commit can refresh a vendor token and save it, revoke a connection when refresh is missing or auth has failed for a day, and emit @@ -1031,10 +1044,14 @@ Budgets keep one command inside the providers' limits: - Strava's limit is per application, so the deployment's own sync shares it. Strava's rate-limit page, fetched 15 November 2026, gives a default of 100 read requests per 15 minutes and 1,000 a day. Strava calls them - non-upload requests. One list call and 20 detail calls can become 84 - requests when the server retries each one three times. That leaves 16 - for the deployment's own sync in the same 15 minutes. The Strava line - says that its limit is shared. + non-upload requests. One list call and 20 detail calls are 21 + requests. A 429 makes the server try that request four times, and the + pull then stops calling Strava. So one `--yes` command sends at most 24 + Strava requests. A 401 adds one attempt to that request after the server + reloads the token. That + leaves about 76 for the deployment's own sync in the same 15 minutes. A + preview first adds one list call. The Strava line says that its limit is + shared. The routes are `GET /api/v1/providers/{provider}/users/{user_id}/workouts` and @@ -1086,6 +1103,13 @@ timeout above. milliseconds, `filter_by_modification_time=false`, and `limit` 100, and pages `offset` until a short page. False means creation time. A page over the response cap is asked again with a smaller `limit`, down to 1. + One command sends at most `MAX_VENDOR_LIST_PAGES`, 100 Suunto list + requests, counting those smaller retries. When the cap stops a list + whose last page was full, Suunto is `incomplete`, `more` is true, and + the objects already read are still written. Each page waits for the + one-second pace, so the cap also bounds the list to about 100 seconds. + A later `--from` reads fewer pages, because `since` is the requested + start. The record key is `workoutId`. Detail is called at `workoutKey`. A list object with no `workoutKey` gets no detail call, and its detail is `not_available`. The pinned detail method calls @@ -1200,6 +1224,14 @@ original gets no detail call. A detail is fetched again only when the list object changed. A provider that changes a detail without changing the list object is not seen, and the line does not claim it. +A list object and its detail are not read at the same moment. The pull +reads a provider's whole list first, then its details one second apart, +so a detail can come minutes after its list object. A one-year Garmin +range sends 381 windows, more than six minutes, before its first detail. +The vendor can change the workout in between. A `kept` detail was read by +an earlier command. The envelope does not record when each part was read, +and the pull does not claim the two parts are one moment's copy. + The detail must name the same id. A detail that names another id is a `mismatch`, and it is not stored. @@ -1675,7 +1707,8 @@ as `src/runtime/garmin_pull.rs` does. A live vendor request uses 30 seconds to connect and 360 seconds to read, for the reason in section 2. The timeouts are named constants in `src/runtime/open_wearables.rs`. One response may be at most `MAX_PULL_RESPONSE_BYTES`, which is 10 MiB. One -read may be at most 1000 pages. Those limits are named constants in +read may be at most 1000 pages. One Suunto list may be at most +`MAX_VENDOR_LIST_PAGES`, which is 100 requests. Those limits are named constants in `src/input_policy.rs`, where 2.1.1 keeps every limit on untrusted input. In 2.1.1 the comment on `MAX_PULL_RESPONSE_BYTES` says it is the bytes of one Garmin personal connection response. The route list at the top of @@ -1930,7 +1963,7 @@ interactive open can preview, back up, ask, and then migrate. | Device-binding facts and the safety snapshot | new `src/import/binding.rs`, called from the matching step in `src/import/provider.rs` for route `open_wearables` | | Create or first-bind with the checked receipt, and refuse any other `device_binding` change | the staged plan and `ProviderPreview::apply` in `src/import/provider.rs` | | Stored-original read for the vendor detail rules | a crate-private read in `src/import/provider.rs` | -| Response cap and page cap, and the comment and route list that now name both pulls | named constants in `src/input_policy.rs` | +| Response cap, page cap, Suunto list cap, and the comment and route list that now name both pulls | named constants in `src/input_policy.rs` | | Receipt for a start in Unix seconds or milliseconds | a helper beside `offset_timestamp_receipt` in `src/import/candidate.rs` | | Measurement samples, source reports, paired null value and unit, and child withdrawal | `write_current_state` and `typed_columns` in `src/store/encode.rs`. Package restore, repair, and the record check use that encoder | | Step 6 with foreign keys off | its own transaction in `src/store/migrate.rs`, and `install_schema` in `src/store/mod.rs` | @@ -2419,7 +2452,11 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: the connections route and to both workout routes. `requests_made` is false, `notice` is empty, and every live line is `not_attempted`. With the flag, preview and `--json` still write nothing, `requests_made` is - true, and the text says vendor requests were made + true, and the text says vendor requests were made. The fixture server + sees the connections request and each list request, and no detail + request. The preview counts the ids `--yes` would detail as `stored`, + and says that a preview then `--yes` reads each list twice. A Strava + preview then `--yes` sends two list calls and at most 20 detail calls - every run with the flag, as a preview, under `--yes`, and with `--json`, says before its first live request that the server may refresh and save vendor tokens, may revoke a connection, and may wait about 105 seconds @@ -2446,6 +2483,11 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: `abc` matches. A list object with no `workoutKey` makes no detail call. It is stored with `detail_status` `not_available`, and Suunto stays `completed` +- a Suunto fixture that always returns full pages, with a small list cap + and a short pace passed into the loop as the 1000-page test does, stops + at the cap. Suunto is `incomplete`, `more` is true, the objects already + read are stored, and the exit is nonzero. `MAX_VENDOR_LIST_PAGES` is + checked as a named constant of 100 - a Garmin `activityId` of `123` and a later `"123"` are one record. An integer above 9007199254740991 refuses only that object and counts it as `unsafe_number`. A fractional id refuses only that object and counts From a6a4ce6a1f9c6e664f394af8e8f6d729a51169ac Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 05:29:39 +0000 Subject: [PATCH 34/60] Exempt page cursors and withhold URL user names and fragments Whoop and Oura name their next page next_token, which the credential pattern would withhold and turn from null into text. Exempt next_token and nextToken by exact name. Withhold a user name or password before the @ in a URL and credential-shaped pairs in its fragment. Co-authored-by: Michael Whitham --- build-history/v2.2.0/decisions.md | 11 ++++++++-- build-history/v2.2.0/spec.md | 34 ++++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index 1beec4e1..b1f957ad 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -119,6 +119,9 @@ These edits answer the review of this plan at `d636d7a`: then `--yes` reads each list twice and makes each detail call once. One command sends at most 100 Suunto list requests. A detail can come minutes after its list object, and the plan says so. +- D244. The page cursors `next_token` and `nextToken` are not + credential-shaped. A user name or password in a URL, and a + credential-shaped pair in a URL fragment, are withheld too. ## D227. Version 2.2.0 is one manual pull, and the program and the record share that number @@ -1512,8 +1515,12 @@ The value is replaced by the text `[withheld by ath]`, and the pull records the JSON path and counts it. A key is credential-shaped when its letters and digits, with case ignored and every other character dropped, end in `token` or `secret`, or are `apikey`, `authorization`, or -`password`. A query parameter with such a name inside a URL string is -withheld the same way, and the URL keeps its address. `polar_user` and a +`password`. The page cursors `next_token` and `nextToken`, matched +exactly, are not credential-shaped. Whoop and Oura name their next page +`next_token`, and withholding it would turn a null into text. A query +parameter or a fragment pair with a credential-shaped name inside a URL +string is withheld the same way, and so is a user name or password before +the `@`. The URL keeps its scheme, host, port, and path. `polar_user` and a coordinate are not credential-shaped. The rule covers stored reads and vendor reads alike. diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index f21cfc1b..0557911b 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -1121,10 +1121,10 @@ timeout above. object may carry it. Detail sends no `extensions` parameter. - Whoop. One call. The method caps `limit` at 25. The response's next-page field is `next_token`. The request parameter is `nextToken`, - and the route does not send it. `more` is true when the response has - `next_token`. + and the route does not send it. `more` is true when the response has a + `next_token` that is not null. - Oura. One call with no date and no `next_token`. `more` is true when the - response has `next_token`. + response has a `next_token` that is not null. - Strava. One list call at page 1. `per_page` is the server setting `strava_events_per_page`, default 200. `more` is true when the page length equals `per_page`. The detail object also carries `embed_token`. @@ -1727,10 +1727,23 @@ A key is credential-shaped when its letters and digits, with case ignored and every other character dropped, end in `token` or `secret`, or are `apikey`, `authorization`, or `password`. That covers `userAccessToken`, `access_token`, `refresh-token`, `id_token`, `session_token`, `token`, -`embed_token`, `client_secret`, and `apiKey`. The value is replaced by the +`embed_token`, `client_secret`, and `apiKey`. Two names that end in +`token` are page cursors, not credentials: `next_token` and `nextToken`, +matched exactly. Whoop's and Oura's responses name their next page +`next_token`. Whoop's model at the pin reads that key with no alias, and +Whoop's request parameter is `nextToken`. Those two keys keep their +values. The scan for the key, the origin, and the user id still covers +them. The pull reads `more` from the response before it withholds +anything, so a null `next_token` stays null. + +A withheld value is replaced by the text `[withheld by ath]`, whatever type it had. A string that is an -absolute URL keeps its address. Each query parameter in it whose name is -credential-shaped has its value replaced by the same text. The pull +absolute URL keeps its scheme, host, port, and path. A user name or +password in it, before the `@`, is replaced by the same text. Each query +parameter, and each `name=value` pair in the fragment after `#`, whose +name is credential-shaped has its value replaced by the same text. So +`#access_token=...` is withheld. A URL that does not parse keeps its +text, and the scan above still runs on it. The pull records the JSON path of each withheld value and counts them. It prints the count and up to 20 paths, and it says when that list was shortened. Nothing else in the object changes. The rule applies to every page, @@ -2551,9 +2564,16 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: The same holds for `access_token`, `refresh-token`, `id_token`, `session_token`, `token`, `embed_token`, `client_secret`, `apiKey`, `authorization`, and `password`, and for a `token` query parameter in a - URL string. The URL keeps its address and its other parameters. The API + URL string. The URL keeps its address and its other parameters. A user + name and password before the `@` in a URL, and an `access_token` pair in + a URL fragment, are withheld the same way. The API key under a credential-shaped key still refuses the page. A `polar_user` URL and a route coordinate are stored unchanged +- a Whoop response whose `next_token` is `"abc"` keeps that value, does + not count it as withheld, and sets `more` true. A null `next_token` + stays null and sets `more` false. An Oura response does the same. A key + named `NEXT_TOKEN` is still withheld, because the exemption matches the + two names exactly - a Sensorbio body stores `data[].activities[].id`, with the parent entry as `list_parent`. A missing id refuses that object, counts it as `missing_id`, and keeps the others. File import of the saved original, From d8ef1f0ec71264ccdba2ff0af455f765d189da52 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 05:31:35 +0000 Subject: [PATCH 35/60] Describe the receipt for Polar's no-offset start as 2.1.1 writes it offset_timestamp_receipt drops the meaning when the text has no offset, because the 2.1.1 receipt check refuses a meaning without offset text. Say which fields the receipt has instead of naming a meaning it never keeps. Co-authored-by: Michael Whitham --- build-history/v2.2.0/spec.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index 0557911b..399b5c28 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -1181,10 +1181,15 @@ The start column names one field and how to read it: - Text with an offset or `Z`. The receipt is the one `input_receipt` in `src/import/mapping.rs` writes. `reported_at` is that instant in UTC. -- Text with no offset, such as Polar's `start_time`. The receipt is - `offset_timestamp_receipt` in `src/import/candidate.rs` with - `meaning_not_documented`. It keeps the text and says the source gave no - offset. There is no `reported_at`. Polar's separate +- Text with no offset, such as Polar's `start_time`. The receipt is the + one `offset_timestamp_receipt` in `src/import/candidate.rs` writes for + such text. `timestamp_text` is the text, and `timestamp_basis` is + `source_offset_timestamp`, the basis 2.1.1 writes for provider text with + or without an offset. `utc_offset_missing_reason` is + `not_provided_by_source`. The receipt has no `utc_offset_text` and no + `utc_offset_meaning`, because the 2.1.1 receipt check refuses a meaning + without offset text, so the helper drops the meaning it is given. There + is no `reported_at`, because the text names no instant. Polar's separate `start_time_utc_offset` stays in `list`. This pull does not join the two. - Unix seconds or milliseconds. The receipt keeps the digits as `timestamp_text`, with `timestamp_basis` `source_instant` and From c8a4074de401ee98d5bd1d0c75962f1888ad7acd Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 05:32:17 +0000 Subject: [PATCH 36/60] State both daylight-saving directions for Garmin windows A forward change makes 24 real hours read as 25 naive local hours, and a backward change makes them read as 23, checked in America/Chicago. The 23-hour window holds where the clock moves by one hour; a two-hour zone such as Antarctica/Troll is not covered. Co-authored-by: Michael Whitham --- build-history/v2.2.0/appendix/open-wearables-api.md | 8 +++++++- build-history/v2.2.0/decisions.md | 13 ++++++++++--- build-history/v2.2.0/spec.md | 11 ++++++++--- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/build-history/v2.2.0/appendix/open-wearables-api.md b/build-history/v2.2.0/appendix/open-wearables-api.md index 37240bce..84807328 100644 --- a/build-history/v2.2.0/appendix/open-wearables-api.md +++ b/build-history/v2.2.0/appendix/open-wearables-api.md @@ -578,7 +578,13 @@ ISO 8601. It turns both into naive local times with goes to `get_workouts_historical`, which fetches 24-hour pieces and logs and skips a piece that fails. On a server whose local zone moves its clock forward, a true 24-hour window that crosses that change is 25 local -hours. So this plan sends windows of 82,800 seconds, 23 hours, or less. A +hours. When the clock moves back, it is 23 local hours. A 23-hour window +is at most 24 local hours where the clock moves by one hour. In +`Antarctica/Troll`, which moves its clock by two hours, a 23-hour window +is 25 local hours. Those numbers come from Python's +`datetime.fromtimestamp` with `TZ` set to `America/Chicago` and to +`Antarctica/Troll`, run on 15 November 2026 across the 2026 changes. +So this plan sends windows of 82,800 seconds, 23 hours, or less. A one-year range is 381 windows. Detail calls `/wellness-api/rest/activities/{activity_id}`. This study did not find that path in Garmin's public docs. `ActivityJSON` types `activityId` as an diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index b1f957ad..09928380 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -122,6 +122,10 @@ These edits answer the review of this plan at `d636d7a`: - D244. The page cursors `next_token` and `nextToken` are not credential-shaped. A user name or password in a URL, and a credential-shaped pair in a URL fragment, are withheld too. +- D243. The daylight-saving sentence names both directions. A forward + change makes 24 real hours read as 25 local hours, and a backward change + makes them read as 23. A zone that moves its clock by two hours is not + covered by the 23-hour window. ## D227. Version 2.2.0 is one manual pull, and the program and the record share that number @@ -1374,9 +1378,12 @@ One failure leaves that line `incomplete`. The others still run. Garmin is split by this program into windows of 82,800 seconds, 23 hours, or less, one call each. Each window sends integer Unix seconds. The pinned server splits a window it sees as longer than 24 hours and -drops a failed piece without saying so. It measures in naive local time, -so a true 24-hour window can look 25 hours long when the server's clock -moves forward. A 23-hour window cannot. Any failed window makes Garmin +drops a failed piece without saying so. It measures in naive local time. +When the server's clock moves forward an hour, 24 real hours read as 25 +local hours, and the server would split the window. When the clock moves +back, they read as 23. A 23-hour window reads as 24 at most where the +clock moves by one hour. A zone that moves it by two hours, such as +`Antarctica/Troll`, is not covered. Any failed window makes Garmin `incomplete`. The pull keeps calling Garmin detail at the pinned path, `/wellness-api/rest/activities/{activity_id}`. That path is not in Garmin's public docs, and this study did not find it there. For a Garmin diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index 399b5c28..d51cbea1 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -1079,9 +1079,14 @@ timeout above. `uploadEndTimeInSeconds`, so a window selects by upload time, not by start. Each window ends where the next begins. The pinned server splits a window it sees as longer than 24 hours, and it drops a failed piece - without saying so. It measures the window in naive local time, so on a - server whose clock moves forward, a true 24-hour window can look 25 - hours long. A 23-hour window cannot look longer than 24 hours. + without saying so. It measures the window in naive local time. When the + server's clock moves forward an hour, as in spring, 24 real hours read + as 25 local hours, so a 24-hour window would be split. When the clock + moves back, as in autumn, 24 real hours read as 23. A 23-hour window + reads as 24 hours at most, so it is never split where the clock moves + by one hour. A zone that moves its clock by two hours, such as + `Antarctica/Troll`, can make a 23-hour window read as 25 hours. The pull + does not know the server's zone. A failed window makes Garmin `incomplete`, and later windows still run. The pull calls Garmin detail at the pinned path, `/wellness-api/rest/activities/{activity_id}`. That path is not in From 1c2f868237eb1e57fc507e718120cca2ee48112c Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 05:33:41 +0000 Subject: [PATCH 37/60] Cite the __proto__ import refusal as 2.1.1 ships it keyed_candidate calls check_supplied_fields, which refuses an empty name and a __proto__ key at any depth (D191). D214 changed only the native reader, so the import refusal still applies, and it covers every vendor original because the envelope is kept in supplied_fields. Co-authored-by: Michael Whitham --- build-history/v2.2.0/decisions.md | 8 +++++++- build-history/v2.2.0/spec.md | 15 +++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index 09928380..7f5a0b8a 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -126,6 +126,9 @@ These edits answer the review of this plan at `d636d7a`: change makes 24 real hours read as 25 local hours, and a backward change makes them read as 23. A zone that moves its clock by two hours is not covered by the 23-hour window. +- D231. The `__proto__` citation names `check_supplied_fields`, which + still refuses the key at any depth on import. D214 in 2.1.1 changed only + the native reader. ## D227. Version 2.2.0 is one manual pull, and the program and the record share that number @@ -626,7 +629,10 @@ separate work. It is not required to make the pull correct. Making the Garmin key removable is separate work. `check_supplied_fields` is in `src/import/shared.rs`. A keyed import calls -it before it builds a candidate (D191). There is no `persist.rs` and no +it before it builds a candidate (D191). It refuses an empty name and a +`__proto__` key at any depth. Version 2.1.1's D214 changed only the +native reader, which keeps such a key and checks it, so the import +refusal still applies. There is no `persist.rs` and no `ath-core persist` command. The pull writes through `MappedPage` and the 2.1.1 import, so the import check covers it. A name check outside import is separate work. diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index d51cbea1..b943ce91 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -1450,7 +1450,15 @@ Everything after that is the mapping engine that 2.1.1 carries over from 2.1.0: match keys (D181), replace on change (D182) except for the owner corrections section 2 keeps, source and device (D183), one write transaction per page (D189), a deleted source left out -(D190), and field names refused when they are empty or `__proto__` (D191). +(D190), and the supplied-field check (D191). `keyed_candidate` in +`src/import/shared.rs` calls `check_supplied_fields` for every mapped +record, and a failure refuses the import. It refuses an empty name, and a key named +`__proto__` at any depth, in a record's `supplied_fields` and in each +route point's `supplied_fields`. Version 2.1.1's D214 changed only the +native reader, which now keeps a `__proto__` key and checks it like any +other key. D214 did not lift this import refusal, so it still applies. +A vendor original keeps its whole envelope in `supplied_fields`, so the +same check covers every vendor object. A Garmin file import remains a different `data_route`, so both copies of one workout stay (D161). A second pull of the same Open Wearables object, or an `ath import --mapping open-wearables` of a saved copy of that object, @@ -2395,7 +2403,10 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: `page-raw.json` is stored. RMSSD and SDNN stay different quantities - a changed end time keeps the record id and increases the revision -- a `__proto__` supplied field fails the page +- a `__proto__` key nested inside a supplied field fails the page, because + `check_supplied_fields` refuses it (D191). An empty supplied-field name + fails it too. A package that holds a `__proto__` key still restores, + because D214 keeps the key in the native reader - a literal key, a Unicode-escaped key in a nested unconsumed field, the key used as an object key, the selected origin, and the selected user id each reject the page before mapping. The database, its revisions, and the From c4dfb893c3a4eecfa52680fca15d8298043b2560 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 05:34:06 +0000 Subject: [PATCH 38/60] Say that a thinner detail replaces for providers with no named field Garmin, Suunto, Whoop, and Oura name no detail field, so the thinner check never holds a new detail back for them. Say that a detail with fewer fields replaces the stored one and that the stored detail stays in the record's history. Co-authored-by: Michael Whitham --- build-history/v2.2.0/decisions.md | 8 +++++++- build-history/v2.2.0/spec.md | 12 ++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index 7f5a0b8a..f0577437 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -129,6 +129,9 @@ These edits answer the review of this plan at `d636d7a`: - D231. The `__proto__` citation names `check_supplied_fields`, which still refuses the key at any depth on import. D214 in 2.1.1 changed only the native reader. +- D243. For Garmin, Suunto, Whoop, and Oura, which name no detail field, a + new detail with fewer fields replaces the stored one, and the stored + detail stays in the record's history. ## D227. Version 2.2.0 is one manual pull, and the program and the record share that number @@ -1415,7 +1418,10 @@ between pulls does not make a list object look changed. A list-only object never replaces a stored detail. A new detail that is thinner than the stored one writes nothing. Thinner means a detail field the specification's table names for that provider is filled in the stored -detail and empty in the new one. A deferred or failed detail keeps the +detail and empty in the new one. Garmin, Suunto, Whoop, and Oura name no +detail field, so a new detail from them replaces the stored one even when +it has fewer fields. The stored detail stays in the record's history as +the earlier revision. A deferred or failed detail keeps the stored detail and adds no revision. A detail over the 10 MiB response cap is `too_large`, because the detail route has no smaller page. A detail the privacy scan refuses is `refused`. Neither is stored. A failed, diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index b943ce91..95ae4a3e 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -1254,7 +1254,12 @@ What is written for one id depends on what this command got: stored original stays. The id counts as `thinner`. A detail is thinner when one of the provider's detail fields in the table is a nonempty value in the stored detail and is missing, null, or empty in the new one. A - provider with no named detail field has no thinner detail. + provider with no named detail field has no thinner detail. Garmin, + Suunto, Whoop, and Oura name none, so a new detail from them replaces + the stored one even when it has fewer fields. The stored detail is not + lost. It stays in the record's history as the earlier revision, and + `ath records show --history` shows it. The line does not + claim the new detail is complete. - No new detail call, because the stored detail is current. The pull sends the envelope with the stored detail, so the original counts as `unchanged` and nothing is written. The id counts as `kept`. @@ -2437,7 +2442,10 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: - a Strava detail with `laps`, `splits_metric`, `segment_efforts`, and `map` is stored. A later changed list object whose detail has no `segment_efforts` is `thinner` and writes nothing. A Whoop detail is - never `thinner`, because the table names no Whoop detail field + never `thinner`, because the table names no Whoop detail field. After a + changed Whoop list object, a new detail with fewer fields replaces the + stored one, and the earlier detail is still in the record's history. + Garmin, Suunto, and Oura behave the same - a failed Polar detail for a new id stores the list object with `detail_status` `failed`. Polar is `incomplete`, and the command exits nonzero. The same failure for an id that has a stored detail and a From 4cb57927fc76cfe218fe31308da38d5a639ee8dd Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 05:35:49 +0000 Subject: [PATCH 39/60] Name the owner's fix for each of the four page refusals A conflicting device id, unbound history, and a malformed receipt can be fixed with ath correct on the source. A changed workout kind has no fix that keeps the record; ath erase removes it and the next pull stores the new kind. Say where 2.2 has no fix, put the fix in the refusal text, and test each one. Co-authored-by: Michael Whitham --- build-history/v2.2.0/decisions.md | 10 ++++++- build-history/v2.2.0/spec.md | 44 ++++++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index f0577437..105abef5 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -132,6 +132,8 @@ These edits answer the review of this plan at `d636d7a`: - D243. For Garmin, Suunto, Whoop, and Oura, which name no detail field, a new detail with fewer fields replaces the stored one, and the stored detail stays in the record's history. +- D230. Each of the four page refusals names the owner's fix, or says + 2.2 has none. ## D227. Version 2.2.0 is one manual pull, and the program and the record share that number @@ -485,7 +487,13 @@ A failed read says to run the same command again. An identity refusal uses the sentence in the specification's section 3: a replacement id is blocked even at a new time, a 2.1.0 Open Wearables history cannot be refreshed until reconciliation, and -a rerun cannot repair either one. A preview that fails makes no database +a rerun cannot repair either one. Each page refusal also names the +owner's fix where 2.2 has one. `ath correct` on the source can set a new +`device_binding`, bind history that one device wrote, or replace a +malformed receipt. A changed workout kind has no fix that keeps the +record. `ath erase` removes it, and the next pull stores the new kind. A +bound source that receives rows with no id, and history from more than +one device, have no fix in 2.2. A preview that fails makes no database changes, including for pages that had already been counted. Before `MappedPage`, a cursor page and an offset page must be a JSON diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index 95ae4a3e..03f03335 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -788,6 +788,28 @@ receipt, and a workout kind that differs from the stored record. The archive is not attempted after a veto. A missing device id on a timeseries row is not this veto. +Each refusal names what the owner can do, and the text says the same: + +- A conflicting device id. If the new device replaces the old one, the + owner runs `ath correct` on the source and sets `device_binding` to the + new id. Later rows from the new device are then accepted. A new row + replaces an old one only where both have the same match key, which + includes the time. When the incoming id is missing, null, or blank, + 2.2 has no fix that keeps the source. Removing the key would make the + source unbound history, which is refused too. Deleting the source + leaves out every later row from it (D190). +- Unbound history. If one device wrote all of that history, the owner + runs `ath correct` on the source and adds `device_binding` with that + device's id. Nothing checks that claim. When more than one device wrote + it, 2.2 has no fix. Splitting that history is the later reconciliation. +- A malformed receipt. The owner runs `ath correct` on the source and + sets `device_binding` to the device's id as a nonempty string. +- A workout kind that differs from the stored record. 2.2 has no fix that + keeps the stored record. `ath erase` removes the record, its revisions, + and its import key, and the next pull stores the workout as a new + record of the new kind. Erase cannot be undone, and the skill describes + it as privacy removal. The refusal text says both. + A deleted source or a deleted record is not a veto. A row whose source the person deleted is left out, and the line says so (D190). A row whose match key names a record the person deleted is left out, and the line @@ -1559,7 +1581,9 @@ The call is one of these states: point values with a different id are still refused. A new timestamp does not make the new id acceptable. The text says the replacement device is blocked, including when the sample time is new, and that running the - command again cannot change the id. + command again cannot change the id. It names the fix in section 2: + when the new device replaces the old one, `ath correct` on the source + sets `device_binding` to the new id. - The source exists, the source key is absent, and any history exists. History includes a deleted record and a deleted source device, not only live rows. `existing_source` in `src/import/provider.rs` keeps @@ -1568,11 +1592,14 @@ The call is one of these states: refused. Hardware is not promoted. The text says this Open Wearables history cannot be refreshed until a separate reconciliation exists, and that running the command again cannot create - the binding. This is the block for 2.1.0 history. It is not the coverage + the binding. It also says that when one device wrote that history, + `ath correct` on the source can add `device_binding` with that device's + id. This is the block for 2.1.0 history. It is not the coverage choice in section 2. - The source key is present and is not a nonempty string. The call is refused. The stored value is left as it is. The text says this command - cannot use that binding, and a rerun cannot repair it. + cannot use that binding, a rerun cannot repair it, and `ath correct` on + the source can set it to the device's id. - The source is new for this call, or it already exists with the source key absent and with no history. Accepted rows that are only sleep and workouts, and that all lack an id, are stored. The source has no @@ -2219,6 +2246,17 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: stay two records. A preview of those two pages does not claim the conflict, because the first preview page wrote nothing. A confirmed second page does. +- each of the four page refusals prints the owner's fix from section 2, + and each fix works. After `ath correct` sets `device_binding` on a bound + source to a new id, the next pull accepts rows with that id, and a new + row replaces an old one only where the match keys are equal. After + `ath correct` adds `device_binding` to an unbound source written by + 2.1.0, the next pull refreshes that history. After `ath correct` + replaces a malformed receipt with a nonempty string, the next pull + goes on. A bound source that receives rows with no id stays refused, + and its text names no rebinding fix. After `ath erase` of a workout + whose kind changed, the next pull stores the new kind as a new record + with a new record id. - a missing device id beside a conflicting device id, in either row order, refuses the protected page and stores no capsule and no revision. The same veto holds for an unbound legacy history and a missing workout UUID From adc6fd9061de06399c47f7258898165d54430e87 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 05:36:31 +0000 Subject: [PATCH 40/60] Say not-null next_token in the Whoop and Oura more test The rule sets more only for a next_token that is not null. The test that lists each provider's next-page signal now says the same. Co-authored-by: Michael Whitham --- build-history/v2.2.0/spec.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index 03f03335..f2c0f520 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -2652,8 +2652,9 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: no `reported_at`, and its receipt says the source gave no offset. A Suunto start in Unix milliseconds keeps the digits and stores `reported_at` with milliseconds. Both receipts pass `ath check` -- a Whoop response with `next_token`, an Oura response with - `next_token`, a Sensorbio response with `links.next`, and a Strava page +- a Whoop response with a `next_token` that is not null, an Oura + response with a `next_token` that is not null, a Sensorbio response + with `links.next`, and a Strava page whose length equals `per_page` set `more` true. The fixture server sees no `nextToken` sent to Whoop. `covers_requested_range` is false - a vendor original that the person deleted is left out on every later From 8d66d858feed714be47d6e6d6da78d0a2acfd161 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 05:37:07 +0000 Subject: [PATCH 41/60] Record the pass after the review at d636d7a in the progress row Co-authored-by: Michael Whitham --- build-history/v2.2.0/progress.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-history/v2.2.0/progress.md b/build-history/v2.2.0/progress.md index fcf3b2bd..0ee2414f 100644 --- a/build-history/v2.2.0/progress.md +++ b/build-history/v2.2.0/progress.md @@ -5,7 +5,7 @@ program, the record, or the database has changed for 2.2.0. | Step | What | Status | |---|---|---| -| 0 | The plan: proposals D227–D244, and the Open Wearables study. The proposals were D198–D215 until 2.1.1 used D208–D226. Checked against 2.1.1 at `0de71bb` on 15 November 2026: a page is one import preview and one apply, and D237 uses the revision check. D239 through D241 stay. D242 and D243 answer the review at `e145fa6`. D244 withholds a credential-shaped value. Still not adopted. The new head needs a fresh four-role review | written, not approved | +| 0 | The plan: proposals D227–D244, and the Open Wearables study. The proposals were D198–D215 until 2.1.1 used D208–D226. Checked against 2.1.1 at `0de71bb` on 15 November 2026: a page is one import preview and one apply, and D237 uses the revision check. D239 through D241 stay. D242 and D243 answer the review at `e145fa6`. D244 withholds a credential-shaped value. The pass after the review at `d636d7a` amends D227, D230, D231, D236, D242, D243, and D244. Still not adopted. The new head needs a fresh four-role review | written, not approved | | 1 | Version 2.2.0 and migration step 6. Step 5 is the published 2.1.1 migration. No new column on an existing table. The root check gains `source_report` by the copy in D236. Summary and score values may be omitted in pairs (D227, D236) | not started | | 2 | `ath pull openwearables` in the `athleticstandard` crate, with the rewritten mapping (D228, D230, D236) | not started | | 3 | Key, server, and user id kept out of the record (D229) | not started | From bdf0c2c150ad03659465101002ceb1657a0c2cac Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 05:48:24 +0000 Subject: [PATCH 42/60] Point the storage-rule lines at spec section 2 Before the renumbering, these lines named the newest correction as the storage rule. That number became D237, which is now the archive timing rule, and later decisions added more storage rules. D232 says the specification's section 2 is the storage rule, so the lines say that. Co-authored-by: Michael Whitham --- build-history/v2.2.0/appendix/open-wearables-api.md | 12 +++++++----- build-history/v2.2.0/spec.md | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/build-history/v2.2.0/appendix/open-wearables-api.md b/build-history/v2.2.0/appendix/open-wearables-api.md index 84807328..8947bcf6 100644 --- a/build-history/v2.2.0/appendix/open-wearables-api.md +++ b/build-history/v2.2.0/appendix/open-wearables-api.md @@ -205,8 +205,8 @@ route files. A limit may still exist in middleware this study did not open. The same commit, `183e8cc4f6de897dbd288c93d49a691f2cf721ae`, was read again for every user data route. The OpenAPI file is `docs/openapi.json`, -`info.version` `0.11.0`. The storage rule is D237. This section records -what the source shows. +`info.version` `0.11.0`. The storage rule is section 2 of the +specification, as D232 says. This section records what the source shows. `SeriesType` is the enum in `backend/app/schemas/enums/series_types.py`. Each entry in `SERIES_TYPE_DEFINITIONS` is an id, a name, and a unit. @@ -258,8 +258,9 @@ listed rows. The personal-record response fields are `birth_date`, ## Contract read on 7 November 2026 The same commit was read again for the summary, score, meal, cycle, body, -and personal-record contracts. D237 is the storage rule. This section -records the source facts that rule uses. `SERIES_TYPE_DEFINITIONS` has 141 +and personal-record contracts. The storage rule is section 2 of the +specification, as D232 says. This section records the source facts that +rule uses. `SERIES_TYPE_DEFINITIONS` has 141 entries. Raw rows keep the 2.1.0 kind when the mapping already names one. Those @@ -268,7 +269,8 @@ series are `heart_rate_variability_rmssd`, `heart_rate_variability_sdnn`, `oxygen_saturation`, `heart_rate_recovery_one_minute`, `vo2_max`, `garmin_stress_level`, and `garmin_body_battery`. -The table below is the mapping for all 141 series. D237 is the storage rule. +The table below is the mapping for all 141 series. The storage rule is +section 2 of the specification. `input_value` and the input unit are the server's number and unit. `standard_value` equals `input_value` except where the conversion is `divide by 100`. A day row uses the day record in the last column. It is diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index f2c0f520..0b7417d5 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -322,8 +322,8 @@ gateway commands they are today. ## 2. What this pull stores -D237 is the storage rule. D232 keeps these values in this pull. D233 -corrected source, time, and score direction. D234 corrects units, day +This section is the storage rule, as D232 says. D232 keeps these values +in this pull. D233 corrected source, time, and score direction. D234 corrects units, day windows, sleep bounds, identity encoding, reported records, and child withdrawal. D235 corrects the root record type, numberless calculation inputs, recovery scales, required ids, workout provenance, hydration, From 3c3f6604bf0848ac35972c2f59480d070a2eeeff Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 05:48:31 +0000 Subject: [PATCH 43/60] Describe D237's archive timing without the old write lock The appendix said D237 writes the archive capsule after a locked safety read. Since the rework for 2.1.1, D237 writes it only at the database revision where the safety facts were read. Co-authored-by: Michael Whitham --- build-history/v2.2.0/appendix/open-wearables-api.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build-history/v2.2.0/appendix/open-wearables-api.md b/build-history/v2.2.0/appendix/open-wearables-api.md index 8947bcf6..263348e4 100644 --- a/build-history/v2.2.0/appendix/open-wearables-api.md +++ b/build-history/v2.2.0/appendix/open-wearables-api.md @@ -215,7 +215,8 @@ path in `timeseries_service.py` copies `recorded_at`, `zone_offset`, the type, the value, and `window_seconds`. It does not set `period_end` or `computed_by`. The response `metadata.resolution` is the raw or day label. A series row does not carry that label. The archive capsule -copies it. D237 writes that capsule only after the locked safety read. +copies it. D237 writes that capsule only at the database revision where +the safety facts were read. `_aggregated_timeseries` handles `1min`, `5min`, `15min`, and `1hour`. It sets `window_seconds` from `BUCKET_SIZES` and does not set `period_end`. From 8e6c812923c560ff48822496fe7d0ba1d094fb58 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 06:28:49 +0000 Subject: [PATCH 44/60] Say what a preview reads with --vendor-workouts The opening of the specification said the flag's calls run on a preview, which reads as if a preview also made detail calls. It now says a preview and --json read the connections list and each active provider's list and make no detail call. The help text and the examples say the same, and the preview test checks them. Co-authored-by: Michael Whitham --- build-history/v2.2.0/decisions.md | 10 ++++++++++ build-history/v2.2.0/spec.md | 25 +++++++++++++++---------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index 105abef5..6af97577 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -135,6 +135,16 @@ These edits answer the review of this plan at `d636d7a`: - D230. Each of the four page refusals names the owner's fix, or says 2.2 has none. +## Changes after the review at `3c3f660` + +These edits answer the reviews of this plan at `3c3f660`. No decision +number is added: + +- D243. The opening of the specification says what the flag reads on a + preview and on `--json`: the connections list and each active + provider's list, with no detail call. The help text, the examples, and + their test say the same. + ## D227. Version 2.2.0 is one manual pull, and the program and the record share that number `ath pull openwearables` reads the stored representations D232 lists from an diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index 0b7417d5..0983404c 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -51,10 +51,11 @@ environment when both are set. `--vendor-workouts` is off unless the person passes it. Without it, the command does not call the connections route or either live workout route. -With it, those calls run, including on a preview and on `--json`. The -server may then refresh and save vendor tokens, revoke a connection, and -wait about 105 seconds on a rate limit. The help text and every run with -the flag say so (section 2). +With it, the connections list and each active provider's list are read, +including on a preview and on `--json`. A preview makes no detail call. +The server may then refresh and save vendor tokens, revoke a connection, +and wait about 105 seconds on a rate limit. The help text and every run +with the flag say so (section 2). The first run writes nothing. `--json` writes nothing, including when `--yes` is also present. That is the same rule as `ath import --mapping`. @@ -292,11 +293,11 @@ is otherwise unchanged, and it still writes without a preview. The flag's help in `src/cli/spec.rs` says: also read live vendor workouts; the server may refresh and save vendor tokens, revoke a connection, and -wait about 105 seconds on a rate limit. It also says that a preview reads -each provider's list but makes no detail call, and that a preview and -then `--yes` read each list twice. `src/cli/examples/pull.txt` repeats -those three effects and says that "nothing stored" means this database -only. +wait about 105 seconds on a rate limit. It also says that a preview and +`--json` read the connections list and each active provider's list and +make no detail call, and that a preview and then `--yes` read each list +twice. `src/cli/examples/pull.txt` says the same things, and it says that +"nothing stored" means this database only. The saved key can read every user on that server. `ath key` shows whether a key is saved in the password store and whether `OPEN_WEARABLES_API_KEY` is @@ -2534,7 +2535,11 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: the flag, preview and `--json` still write nothing, `requests_made` is true, and the text says vendor requests were made. The fixture server sees the connections request and each list request, and no detail - request. The preview counts the ids `--yes` would detail as `stored`, + request. The help text of `--vendor-workouts` and + `src/cli/examples/pull.txt` say that a preview and `--json` read the + connections list and each active provider's list and make no detail + call, and the generated `skills/athletic-standard/references/cli.md` + matches them. The preview counts the ids `--yes` would detail as `stored`, and says that a preview then `--yes` reads each list twice. A Strava preview then `--yes` sends two list calls and at most 20 detail calls - every run with the flag, as a preview, under `--yes`, and with `--json`, From 4cfd7f9b5faaca58a96a7f0a9bf017a5cb25742e Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 06:30:38 +0000 Subject: [PATCH 45/60] Label every preview vendor count as estimated A preview showed vendor detail counts and owner-correction counts as if they were results, and its zero failures could read as none found. Every vendor count and both owner-correction counts in a preview now sit under an estimated key. The ids --yes would detail are would_detail, each provider line prints estimated, and the preview says it made no detail calls, in the text and in vendor_workouts.notice. A new test covers the three-id Polar case. Co-authored-by: Michael Whitham --- build-history/v2.2.0/decisions.md | 17 +++- build-history/v2.2.0/spec.md | 156 +++++++++++++++++++----------- 2 files changed, 110 insertions(+), 63 deletions(-) diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index 6af97577..76834b07 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -144,6 +144,11 @@ number is added: preview and on `--json`: the connections list and each active provider's list, with no detail call. The help text, the examples, and their test say the same. +- D243. A preview, which every `--json` run is, labels every vendor count + and both owner-correction counts `estimated`. It calls the count of ids + `--yes` would detail `would_detail`, prints `estimated` on each + provider line, and says that it made no detail calls, in the text and + in `vendor_workouts.notice`. ## D227. Version 2.2.0 is one manual pull, and the program and the record share that number @@ -1291,8 +1296,8 @@ an owner-corrected record with the newest revision an import wrote, basis `provider_import`. It does not compare with the owner's revision. Equal writes nothing, and the correction stays current. Different replaces the correction, and the count `owner_corrections_replaced` shows it on that -provider's line, in `--json`, and in the preview, which says `would -replace N owner corrections; delete an original to keep it`. The +provider's line, in `--json`, and in the preview, which says `estimated: +would replace N owner corrections; delete an original to keep it`. The correction stays in the history. The rule covers every record on that route, so a workout fix on the stored session also survives a pull of unchanged data. For that route it supersedes the D182 sentence that a @@ -1373,8 +1378,12 @@ procedure. `--vendor-workouts` is off unless the person passes it. Off, preview and `--json` call neither the connections route nor a live workout route. On, a preview reads the connections list and each active provider's list, -and it makes no detail call. Its detail counts are estimates. The preview -writes nothing in this database and prints `vendor requests were made`. +and it makes no detail call. Every vendor count it prints, and both +owner-correction counts, are labeled `estimated`, in the text and in +`--json`. The count of ids `--yes` would detail is `would_detail`. The +preview says that it made no detail calls, so detail failures, size +limits, and refusals are only known after `--yes`. The preview writes +nothing in this database and prints `vendor requests were made`. "Nothing stored" and "nothing written" always mean this database. A preview and then `--yes` read each list twice, and the preview and the help say so. Running `--yes` alone reads each list once. diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index 0983404c..879bf2d0 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -68,8 +68,9 @@ requires `--json` and `--json --yes` to leave the database unchanged. The committed result is the text of `--yes` without `--json`. A writing JSON report would be a different choice. It is not this proposal. -Preview text, and every `--json` result, labels counts `estimated`. Each -page is previewed against the database as it was before this command. A +Preview text, and every `--json` result, labels counts `estimated`. That +includes every vendor count and both owner-correction counts in section 2. +Each page is previewed against the database as it was before this command. A preview writes nothing. A match key that appears on two pages, or a server that changes between the preview and `--yes`, can make the estimate differ from the write. The estimate is not a promise of the final new, changed, and @@ -87,12 +88,16 @@ Preview text prints: - one line each for the live workout providers: `completed`, `incomplete`, or `not_attempted`, the connection status when it is not `active`, whether that limit covers the requested range, whether more data exists, - and the detail and left-out counts in section 2 + and the detail and left-out counts in section 2. Those counts follow the + word `estimated`, and the count of ids `--yes` would detail is `would + detail` - when `--vendor-workouts` is on, before the first live request: the three sentences about server changes in section 2 - when `--vendor-workouts` is on: `vendor requests were made` -- when `--vendor-workouts` is on: `vendor workout originals` with new, - changed, and unchanged counts +- when `--vendor-workouts` is on: `preview made no detail calls; detail + failures, size limits and refusals are only known after --yes` +- when `--vendor-workouts` is on: `vendor workout originals`, then + `estimated`, then new, changed, and unchanged counts - when a credential-shaped value was withheld: the count and up to 20 paths, as section 4 says - when `--vendor-workouts` is on, this sentence: a workout can appear twice, @@ -148,8 +153,8 @@ make `written` true. `database_changed` is true when any protected transaction or any archive transaction in this command committed a change, including the first insert of the archive source. A vendor page in section 2 is a protected transaction. Its originals are `source_report` -records, so they add to `committed.source_report` as well as to -`vendor_workouts.originals` and that provider's counts. A committed vendor +records, so they add to `committed.source_report` as well as to the +vendor originals count and that provider's counts. A committed vendor page that creates or revises an original makes `written` true and `database_changed` true, even when every stored page was unchanged. A first `vendor_workout` source counts as a database change. A later page @@ -198,12 +203,14 @@ the text. The object has no key, server, user id, or request path. }, "left_out": { "total": 0, "by_reason": {}, "examples": [], "shortened": false }, "withheld": { "total": 0, "paths": [], "shortened": false }, - "owner_corrections_replaced": 0, + "estimated_owner_corrections_replaced": 0, "vendor_workouts": { "requested": false, "requests_made": false, "notice": [], - "originals": { "new": 0, "changed": 0, "unchanged": 0 }, + "estimated": { + "originals": { "new": 0, "changed": 0, "unchanged": 0 } + }, "providers": { "garmin": { "status": "not_attempted", @@ -211,19 +218,21 @@ the text. The object has no key, server, user id, or request path. "covers_requested_range": false, "more": false, "limit": "not requested", - "owner_corrections_replaced": 0, - "details": { - "stored": 0, - "kept": 0, - "deferred": 0, - "failed": 0, - "mismatch": 0, - "thinner": 0, - "not_available": 0, - "too_large": 0, - "refused": 0 - }, - "left_out": { "total": 0, "by_reason": {} } + "estimated": { + "owner_corrections_replaced": 0, + "details": { + "would_detail": 0, + "kept": 0, + "deferred": 0, + "failed": 0, + "mismatch": 0, + "thinner": 0, + "not_available": 0, + "too_large": 0, + "refused": 0 + }, + "left_out": { "total": 0, "by_reason": {} } + } } } } @@ -232,20 +241,34 @@ the text. The object has no key, server, user id, or request path. `notice` is empty without the flag. With it, `notice` holds the three sentences about server changes in section 2, on every run, including a -preview. `connection_status` is `active`, `revoked`, `expired`, +preview. Every `--json` run is a preview, so with the flag `notice` also +holds `preview made no detail calls; detail failures, size limits and +refusals are only known after --yes`. `connection_status` is `active`, `revoked`, `expired`, `unknown status`, or `null` when the server listed no connection for that provider. -The top-level `owner_corrections_replaced` counts owner corrections of -stored records that the stored pages replace, by the owner-correction rule -in section 2. Each provider's `owner_corrections_replaced` counts its -vendor originals. In a preview both are estimates. When a provider's count -is above zero, the preview prints `would replace N owner corrections; +The top-level `estimated_owner_corrections_replaced` counts owner +corrections of stored records that the stored pages would replace, by the +owner-correction rule in section 2. Each provider's +`estimated.owner_corrections_replaced` counts its vendor originals. Both +are estimates, and their keys say so. When a provider's count is above +zero, the preview prints `estimated: would replace N owner corrections; delete an original to keep it` on that provider's line. When the top-level -count is above zero, it prints `would replace N owner corrections of -stored records because the server's data changed`. After `--yes` the same -lines say `replaced N owner corrections`, and that each correction stays -in the record's history. The text uses the singular when N is 1. +count is above zero, it prints `estimated: would replace N owner +corrections of stored records because the server's data changed`. After +`--yes` the same lines say `replaced N owner corrections`, without +`estimated`, and that each correction stays in the record's history. The +text uses the singular when N is 1. + +Every vendor count in a preview is under an `estimated` key: +`vendor_workouts.estimated.originals`, and each provider's `estimated` +object with its owner-correction count, its `details`, and its +`left_out`. A provider's status, connection status, coverage, `more`, and +limit describe the reads this command made, so they stay outside it. +`details.would_detail` counts the ids `--yes` would detail now. `--yes` +prints the same counts without `estimated`, and it says `stored` for the +details it wrote. `withheld` counts the values withheld from what this +command read, so a preview counts them in list objects only. The same record types are present for workouts, points, summaries, scores, and source reports. The example above is shortened. Polar, Suunto, Whoop, @@ -255,7 +278,8 @@ outcome. A preview does not say a snapshot was stored. The command returns a different outcome for `--yes` without `--json`. That outcome has the actual `committed` counts, the actual `archive_committed` -counts, the actual `owner_corrections_replaced` counts, +counts, the actual `owner_corrections_replaced` counts, the actual +vendor counts with `stored` in place of `would_detail`, `database_changed`, `protected_write`, `archive`, `range_complete`, and `snapshots_complete`. `committed` counts protected records only. `archive_committed` counts archive records only, including @@ -977,12 +1001,14 @@ this database, and print `vendor requests were made`. "Nothing stored" and "nothing written" always mean this database. The server can still change, as the next paragraph says. -A preview's `details` counts are estimates from the stored originals. -`stored` counts the ids that `--yes` would detail now, and `deferred` the -ids past the budget. `kept` and `not_available` are counted as `--yes` -would count them. `failed`, `mismatch`, `thinner`, `too_large`, and -`refused` are zero in a preview, because only a detail call can find -them. A preview and then `--yes` read each provider's list twice. That is +A preview's `details` counts are estimates from the stored originals, and +they are under the `estimated` key. `would_detail` counts the ids that +`--yes` would detail now, and `deferred` the ids past the budget. `kept` +and `not_available` are counted as `--yes` would count them. `failed`, +`mismatch`, `thinner`, `too_large`, and `refused` are zero in a preview, +because only a detail call can find them. The preview says so: `preview +made no detail calls; detail failures, size limits and refusals are only +known after --yes`. A preview and then `--yes` read each provider's list twice. That is one extra call for most providers, every window again for Garmin, and every page again for Suunto. To read each list once, run `--yes` without a separate preview. The preview and the flag's help say so. @@ -1409,14 +1435,16 @@ keeps the person's version in its history, and every later pull leaves that object out. A workout fix belongs on the stored session or in a note, not on the vendor original. The skill says so (section 6). -Each provider's line, and its object in `--json`, counts: +Each provider's line, and its object in `--json`, counts these. In a +preview they are estimates under `estimated`, as section 1 says. - `originals`: new, changed, and unchanged records. - `owner_corrections_replaced`: owner corrections that this page replaces, by the owner-correction rule above. Each is also counted as a changed original. -- `details`: `stored`, `kept`, `deferred`, `failed`, `mismatch`, - `thinner`, `not_available`, `too_large`, and `refused`. +- `details`: `stored`, which a preview calls `would_detail`, `kept`, + `deferred`, `failed`, `mismatch`, `thinner`, `not_available`, + `too_large`, and `refused`. - `left_out`: objects not written, by reason: `missing_id`, `unusable_id`, `unsafe_number`, `duplicate_id`, `superseded`, `deleted_record`, `deleted_source`, `response_refused`, and `size_cap`. @@ -2512,18 +2540,18 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: stays current, and Polar's `owner_corrections_replaced` is 0. That pull makes no detail call for the id, because the stored-original read uses the newest `provider_import` revision. After the server's list object - changes, the preview prints `would replace 1 owner correction; delete an - original to keep it`, and `--json` has Polar's - `owner_corrections_replaced` 1. `--yes` replaces the correction, counts - it as a changed original and as 1 replaced, and keeps the owner's - revision in the history. A deleted original is left out instead, and - the count stays 0 + changes, the preview prints `estimated: would replace 1 owner + correction; delete an original to keep it`, and `--json` has Polar's + `estimated.owner_corrections_replaced` 1. `--yes` replaces the + correction, counts it as a changed original and as 1 replaced, and + keeps the owner's revision in the history. A deleted original is left + out instead, and the count stays 0 - an owner corrects a stored sleep session. A pull with the same server - data keeps the correction, and the top-level `owner_corrections_replaced` - is 0. A pull whose session changed replaces it, and the count is 1 in - the preview, in `--json`, and after `--yes`. The preview says `would - replace 1 owner correction of stored records because the server's data - changed`. `ath import --mapping open-wearables` of a file that holds the + data keeps the correction, and `--json` has + `estimated_owner_corrections_replaced` 0. A pull whose session changed + replaces it, and the count is 1 in the preview, in `--json`, and after + `--yes`. The preview says `estimated: would replace 1 owner correction + of stored records because the server's data changed`. `ath import --mapping open-wearables` of a file that holds the same data also keeps the correction. Another route keeps its 2.1.1 rule - a record whose current revision came from an accepted package merge is an owner correction. A native export and restore keeps every revision's @@ -2539,9 +2567,18 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: `src/cli/examples/pull.txt` say that a preview and `--json` read the connections list and each active provider's list and make no detail call, and the generated `skills/athletic-standard/references/cli.md` - matches them. The preview counts the ids `--yes` would detail as `stored`, - and says that a preview then `--yes` reads each list twice. A Strava - preview then `--yes` sends two list calls and at most 20 detail calls + matches them. The preview counts the ids `--yes` would detail as + `would_detail`, and says that a preview then `--yes` reads each list + twice. A Strava preview then `--yes` sends two list calls and at most 20 + detail calls +- `--vendor-workouts --json` with three new Polar ids writes nothing, and + the fixture server sees no detail request. Every vendor count and both + owner-correction counts are under a key named `estimated`. Polar's + `would_detail` is 3, and no key that means stored is above zero. + `notice` holds the line that the preview made no detail calls. The text + preview prints that line, and its Polar line contains `estimated`. + `--yes` on the same data prints the same counts without `estimated`, + with `stored` 3 - every run with the flag, as a preview, under `--yes`, and with `--json`, says before its first live request that the server may refresh and save vendor tokens, may revoke a connection, and may wait about 105 seconds @@ -2676,9 +2713,10 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: and makes the provider `incomplete`. In every vendor test, each listed object is in exactly one detail count or one left-out count - `--json` includes `vendor_workouts.requested`, `requests_made`, - `notice`, `originals`, and each provider's `status`, - `connection_status`, `covers_requested_range`, `more`, `limit`, - `details`, and `left_out` + `notice`, `estimated.originals`, and each provider's `status`, + `connection_status`, `covers_requested_range`, `more`, `limit`, and + `estimated` with `owner_corrections_replaced`, `details`, and + `left_out` Migration tests, in the build gate: From 2c4574fae0315ea467840fd632822b5b0020e39b Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 06:32:49 +0000 Subject: [PATCH 46/60] Probe Garmin detail once per command The Garmin detail path is not in Garmin's public docs. If it is missing, the plan spent up to 100 detail calls on it in every command, and an answer other than 404 or 501 made Garmin incomplete every time. The first Garmin detail call is now a probe. A 400, 403, 404, 405, or 501 stops Garmin detail for that command, the other due ids wait as deferred, and Garmin stays completed with a line that says so. An id marked not_available is called again only when its list object changes. A 401 on any live request stops that provider, as a 429 does, so the server refreshes a token at most once per provider in a command. This is the plan's stated default, and the maintainer still has to confirm it. Co-authored-by: Michael Whitham --- .../v2.2.0/appendix/open-wearables-api.md | 8 +- build-history/v2.2.0/decisions.md | 48 ++++++-- build-history/v2.2.0/spec.md | 110 +++++++++++------- 3 files changed, 115 insertions(+), 51 deletions(-) diff --git a/build-history/v2.2.0/appendix/open-wearables-api.md b/build-history/v2.2.0/appendix/open-wearables-api.md index 263348e4..afcd23c1 100644 --- a/build-history/v2.2.0/appendix/open-wearables-api.md +++ b/build-history/v2.2.0/appendix/open-wearables-api.md @@ -564,7 +564,13 @@ uses. Client. `_make_api_request` in `services/providers/api_client.py` makes at most four attempts. Each attempt uses `provider_request_timeout_seconds`, which is 30 seconds by default and at most 300 in `config.py`. A 429 waits 15, then -30, then 60 seconds. A 401 reloads the token once and tries again. A +30, then 60 seconds. A 401 reloads the token once and tries again. That +reload can refresh the vendor token under `token_refresh_lock`, and a +refresh the vendor rejects revokes the connection. The second try is one +of the four attempts. A 401 or 403 that remains is noted in +`provider_auth_failing_since`. When one comes a day or more after the +first noted failure, with no success between, the server revokes the +connection. That day is `DEAD_GRANT_AFTER`. A success clears the note. A timeout or another transport error is not retried. A token refresh holds `token_refresh_lock` for up to 60 seconds and waits up to 10 seconds for it. So with the default timeout, one GET can take about 225 seconds, plus diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index 76834b07..9d6b90d6 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -149,6 +149,14 @@ number is added: `--yes` would detail `would_detail`, prints `estimated` on each provider line, and says that it made no detail calls, in the text and in `vendor_workouts.notice`. +- D243. The first Garmin detail call in a command is a probe. When it + answers 400, 403, 404, 405, or 501, no other Garmin detail call is made + in that command. The other due ids are `deferred`, Garmin stays + `completed`, and its line says detail is unavailable. An id that was + `not_available` is called again only when its list object changed. A + 401 on any live request stops that provider for the command, as a 429 + does. This is the stated default, and the maintainer still has to + confirm it. ## D227. Version 2.2.0 is one manual pull, and the program and the record share that number @@ -1422,12 +1430,18 @@ clock moves by one hour. A zone that moves it by two hours, such as `Antarctica/Troll`, is not covered. Any failed window makes Garmin `incomplete`. The pull keeps calling Garmin detail at the pinned path, `/wellness-api/rest/activities/{activity_id}`. That path is not in -Garmin's public docs, and this study did not find it there. For a Garmin -detail only, HTTP 404 or 501 counts as `not_available`: the list object -is stored whole, and Garmin stays `completed`. Any other Garmin detail -error is `failed`. An id that was `not_available` is detailed again after -the new and changed ids, inside the same budget. The maintainer confirms -this rule before approval. Polar's list omits samples, zones, and route, and detail +Garmin's public docs, and this study did not find it there. The first +Garmin detail call in a command is a probe. When it answers HTTP 400, +403, 404, 405, or 501, the pull makes no other Garmin detail call in that +command. The probed id is `not_available`, each other id still due a call +is `deferred`, every list object is stored, and Garmin stays +`completed`. The line says `Garmin detail unavailable (HTTP n); list +objects stored`. After any other answer to the probe, the calls go on, +and a later 404 or 501 is `not_available` for that id. Any other Garmin +detail error is `failed`. An id that was `not_available` is not called +again unless its list object changed. So a missing path costs one call +in a command, not the budget of 100. This is the stated default. The +maintainer still has to confirm it before approval. Polar's list omits samples, zones, and route, and detail asks for all three. Suunto's detail is called at `workoutKey`. A list object with no `workoutKey` gets no detail call and is `not_available`, because nothing this study read shows that Suunto's detail accepts a @@ -1439,7 +1453,8 @@ next page `next_token`. The request name, `nextToken`, is not sent. Sensorbio reads only the oldest 50 entries, and its line says so. A stored detail is never lost. A detail is fetched for an id with no -stored detail, and again only when the list object changed. Credential +stored detail, unless an earlier command marked it `not_available`, and +again only when the list object changed. Credential values (D244) are withheld before any comparison, so a token that changed between pulls does not make a list object look changed. A list-only object never replaces a stored detail. A new detail that is thinner than @@ -1466,8 +1481,11 @@ timeout is 360 seconds. The server's own retries can take about 225 seconds, so the client waits for them. A live request that still times out ends that provider for the command, so two requests to one provider never overlap. An HTTP 429 ends that provider the same way, because the -server has already spent its three retries on the vendor's limit. The -detail call that got 429 is `failed`. Ids whose detail was not yet called +server has already spent its three retries on the vendor's limit. An +HTTP 401 ends it the same way. The server has already reloaded or +refreshed the vendor token and tried once more, each later 401 would make +it do that again, and a refresh the vendor rejects revokes the +connection. The detail call that got 429 or 401 is `failed`. Ids whose detail was not yet called are `deferred`. What the provider already returned is still written, and the provider is `incomplete`. A command makes at most 100 detail calls to one provider and at most 20 to Strava. Ids with no stored detail go first, oldest @@ -1513,6 +1531,18 @@ Rejected alternatives: - Drop the Garmin detail call because the path is not in Garmin's public docs. Rejected. The pinned server calls it, and a deployment where it works would lose every Garmin detail. +- Call Garmin detail for every due id after a 404, as the earlier text + did. Rejected. A missing path would spend up to 100 calls in every + command. +- Mark every id the probe stopped as `not_available`. Rejected. Those ids + were not asked. A 404 can mean one missing activity, and the mark would + stop their details until their list objects changed. +- Treat a 401 on the probe as a missing path. Rejected. A 401 is what an + expired or revoked grant answers, so the person may need to reconnect + Garmin. Its line must not say only that detail is unavailable. +- Keep calling a provider after a 401. Rejected. Each call could make the + server refresh the vendor token, and a rejected refresh revokes the + connection. - Use a 30-second read timeout. Rejected. The server's own retries take longer. The client would give up, and a rerun could send a second request while the first still runs. diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index 879bf2d0..6b5dab01 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -1067,14 +1067,18 @@ provider in this command, so two requests to one provider never overlap. That provider is `incomplete`. The next provider still runs, and it uses a different vendor account and limit. An HTTP 429 from a live request stops that provider the same way. The server has already waited and -retried three times, so the vendor's limit is spent. No later list call, -window, or detail call goes to that provider in this command. The detail -call that got 429 counts as `failed`. Every listed id that had not had its -detail call yet counts as `deferred`, and a later command details it by -the order below. What the provider already returned is still written as that -provider's page: the list objects, and the details already fetched. A -later Garmin window after a 429 or a timeout is not sent, unlike a window -that failed another way. A server whose provider timeout is +retried three times, so the vendor's limit is spent. An HTTP 401 stops +that provider the same way. The server has already reloaded the vendor +token, or refreshed it, and tried once more. Each later request would +make it do that again, and a refresh the vendor rejects revokes the +connection. No later list call, window, or detail call goes to that +provider in this command. The detail call that got 429 or 401 counts as +`failed`. Every listed id that had not had its detail call yet counts as +`deferred`, and a later command details it by the order below. What the +provider already returned is still written as that provider's page: the +list objects, and the details already fetched. A later Garmin window +after a 429, a 401, or a timeout is not sent, unlike a window that failed +another way. A server whose provider timeout is raised can outlast this timeout. The same rule covers that case. The stored reads keep 30 seconds to connect and 120 seconds to read, the values `src/runtime/garmin_pull.rs` uses. @@ -1140,15 +1144,24 @@ timeout above. The pull calls Garmin detail at the pinned path, `/wellness-api/rest/activities/{activity_id}`. That path is not in Garmin's public docs. This study looked and did not find it, so the path - may not exist. For a Garmin detail only, HTTP 404 or HTTP 501 counts as - `not_available`. The list object is stored whole, with `detail_status` - `not_available`, and Garmin stays `completed`. Any other failed Garmin - detail is `failed`, and Garmin is `incomplete`. A 404 or 501 on a Garmin - list window is not this rule. It fails that window. Every other - provider's detail 404 is `failed`. The pinned client passes a vendor's - 404 through unchanged, and the route answers 501 only for a provider it - has no workout method for, so this study cannot tell a missing path - from a missing activity. + may not exist. The first Garmin detail call in a command is a probe. + When it answers HTTP 400, 403, 404, 405, or 501, the pull makes no other + Garmin detail call in that command. The probed id counts as + `not_available`. Each other id still due a detail call counts as + `deferred`, because it was not asked. Every list object is stored, + Garmin stays `completed`, and its line says `Garmin detail unavailable + (HTTP n); list objects stored`, with the status the probe got. So a + missing path costs one detail call in a command. After any other answer + to the probe, the later Garmin detail calls go on. A later Garmin detail + that answers 404 or 501 is `not_available` for that id, and the next id + is still called. Any other failed Garmin detail is `failed`, and Garmin + is `incomplete`. A 401, a 429, or a timeout stops Garmin as above. A 404 + or 501 on a Garmin list window is not this rule. It fails that window. + Every other provider's detail 404 is `failed`. The pinned client passes + a vendor's status through unchanged, and the route answers 501 only for + a provider it has no workout method for, so this study cannot tell a + missing path from a missing activity. This is the plan's stated + default. The maintainer still has to confirm it (D243). - Polar. The list sends `samples`, `zones`, and `route` false, the route's default, so the list stays small. Detail sends all three true. A list over the response cap fails that list, because the route has no smaller @@ -1274,11 +1287,13 @@ The pull calls detail only when the provider has a detail call and its budget allows. It spends the budget in this order. First come ids with no stored detail that no earlier command marked `not_available`. Then come ids whose list object differs from the stored `list`. Then come ids an -earlier command marked `not_available`, `too_large`, or `refused`. Inside each group the oldest start -goes first. An id without a start instant goes last in its group, in list -order. So a Garmin path that answers 404 for every id still lets new ids -go first, and it costs at most the provider's budget in one command. An id whose original holds a -detail and whose list object is unchanged gets no detail call. A deleted +earlier command marked `too_large` or `refused`. An id that an earlier +command marked `not_available`, and whose list object is unchanged, gets +no detail call. It counts as `not_available` again. Inside each group +the oldest start goes first. An id without a start instant goes last in +its group, in list order. So a Garmin path that answers 404 costs one +detail call in a command, and only when some id is due a call. An id +whose original holds a detail and whose list object is unchanged gets no detail call. A deleted original gets no detail call. A detail is fetched again only when the list object changed. A provider that changes a detail without changing the list object is not seen, and the line does not claim it. @@ -1316,17 +1331,18 @@ What is written for one id depends on what this command got: object alone. `detail_status` says why: `deferred`, `failed`, `mismatch`, `not_available`, `too_large`, or `refused`. The id counts under the same word. - `not_available` means the provider has no detail call, Garmin answered - its detail call with 404 or 501, or a Suunto list object has no - `workoutKey`. A detail response over `MAX_PULL_RESPONSE_BYTES` is - `too_large`, because the detail route has no smaller page. A detail + `not_available` means the provider has no detail call, the Garmin probe + answered 400, 403, 404, 405, or 501 for that id, a later Garmin detail + answered 404 or 501, or a Suunto list object has no `workoutKey`. A + detail response over `MAX_PULL_RESPONSE_BYTES` is `too_large`, because + the detail route has no smaller page. A detail that the privacy scan in section 4 refuses, because it holds the key, the origin, or the user id, is `refused`. Neither of those is stored, and each is counted on the provider's line. - No new detail, but one is stored, and the list object changed. Nothing is written for that id, and no revision is added. The stored detail - stays. The id counts as `deferred`, `failed`, `mismatch`, `too_large`, - or `refused`. + stays. The id counts as `deferred`, `failed`, `mismatch`, + `not_available`, `too_large`, or `refused`. A list-only object therefore never replaces a stored detail. A `failed`, `mismatch`, `too_large`, or `refused` detail makes the provider @@ -2639,14 +2655,24 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: last one ended. A date `--from` starts at midnight UTC. One failed window makes Garmin `incomplete` and never `completed`. A later window still runs -- a Garmin detail that answers HTTP 404 stores the list object whole with - `detail_status` `not_available`. Garmin is `completed`, its line counts - 1 `not_available`, and the command exits 0. HTTP 501 is the same. A - Garmin detail that answers HTTP 500 is `failed`, Garmin is +- three Garmin ids are due a detail call, and the first detail call + answers HTTP 404. The fixture server sees no second Garmin detail + request. The first id is stored with `detail_status` `not_available`, + and the other two with `deferred`. Garmin is `completed`, its line says + `Garmin detail unavailable (HTTP 404); list objects stored`, and the + command exits 0. HTTP 400, 403, 405, and 501 do the same. On the next + command, the `not_available` id, whose list object is unchanged, gets + no call and counts as `not_available` again, and the probe is the older + of the two deferred ids. When the probe gets a detail, a later Garmin + detail that answers 404 is `not_available`, and the next id is still + called. A Garmin detail that answers HTTP 500 is `failed`, Garmin is `incomplete`, and the exit is nonzero. A Polar detail that answers 404 - is `failed`. A Garmin list window that answers 404 fails that window. - On the next command, a new Garmin id is detailed before the id that was - `not_available` + is `failed`. A Garmin list window that answers 404 fails that window +- a live detail that answers HTTP 401, for Garmin and for Polar, counts + as `failed`. The fixture server sees no later request to that provider + in the command. Each id still due a call is `deferred`, the provider is + `incomplete`, and the exit is nonzero. A Garmin window that answers 401 + sends no later window - live requests go one at a time, at least one second apart by the fixture server's clock. A live request that times out, with the read timeout shortened for the test, stops every later request to that @@ -2906,12 +2932,14 @@ Risks: - Strava's limit is shared with the deployment's own sync. One command can use most of a 15-minute window. - The pinned Garmin detail path and the cited Garmin rate were not found - in Garmin's public docs. If the path does not exist, each Garmin detail - answers 404 or 501. Those count as `not_available`, Garmin stays - `completed`, and each Garmin original holds its list object only. Each - command still spends up to 100 Garmin detail calls on ids that were - `not_available`, after new ids. A deployment where that path works fills - those details in on later commands. + in Garmin's public docs. If the path does not exist, the first Garmin + detail call in a command answers an error such as 404. The pull then + makes no other Garmin detail call in that command, Garmin stays + `completed`, and each Garmin original holds its list object only. That + costs one detail call in each command that has a Garmin id due a call. + Where the path works, an id that once got 404 or 501 is not called + again until its list object changes. This is the stated default, and + the maintainer still has to confirm it. - A later pull replaces an owner correction when the server's data for that record changed since an import last wrote it. The preview and the result count each one. The correction stays in the history. Deleting From 6d666e40f15dbb4f89442c6d86032204969d548b Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 06:34:07 +0000 Subject: [PATCH 47/60] Keep the Garmin upload window in each envelope The rule that a later Garmin window's copy replaces an earlier one held only inside one command. A later command that read only an earlier window would store the older copy again, and it would count that as a server change that replaces an owner correction. Each Garmin envelope now keeps its upload window. A copy whose window ends at or before the start of the stored copy's window was uploaded first, so it is counted as superseded and writes nothing. Comparisons leave the window out, because windows depend on --from. A two-command fixture covers both orders. Co-authored-by: Michael Whitham --- build-history/v2.2.0/decisions.md | 24 ++++++++++++++--- build-history/v2.2.0/spec.md | 43 ++++++++++++++++++++++++++++--- 2 files changed, 60 insertions(+), 7 deletions(-) diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index 9d6b90d6..99c7bd90 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -157,6 +157,10 @@ number is added: 401 on any live request stops that provider for the command, as a 429 does. This is the stated default, and the maintainer still has to confirm it. +- D242 and D243. Each Garmin envelope keeps its `upload_window`. On a + later command, a copy from a window that ends at or before the start of + the stored copy's window is `superseded`. It writes nothing and never + replaces an owner correction. Comparisons leave the window out. ## D227. Version 2.2.0 is one manual pull, and the program and the record share that number @@ -1273,7 +1277,8 @@ measurement samples. Calculations do not read the original. Each original is one envelope. It holds `provider`, `vendor_id` as text, `start` and `start_kind` when the object has a start, `list`, `detail` when a detail is stored, and `detail_status`. Sensorbio adds -`list_parent`. The specification's section 2 shows the JSON. The whole +`list_parent`. Garmin adds `upload_window`, the window its object came +from. The specification's section 2 shows the JSON. The whole envelope is kept in `supplied_fields`, and `provider_record_id` is `vendor_id`. The match key is the writer, the sensor, the resource `vendor_workout`, the provider, and the vendor id, escaped by D181. @@ -1282,7 +1287,8 @@ The rewritten `mappings/open-wearables.md` gains a section named `vendor_workout`. It declares the record type, the kind, the subject, the writer, the sensor, the key, and the start. A saved file of envelopes imports through that section. File import writes each envelope as the -file holds it, as D182 does for every mapped import. The detail rules in +file holds it, as D182 does for every mapped import, except the Garmin +window rule in D243. The detail rules in D243 run before the mapping engine sees an envelope, so the mapping engine has no vendor exception. @@ -1500,7 +1506,12 @@ D213 would change its digits. When one Garmin activity id is in two windows with different objects, the later window's copy is kept, because windows select by upload time and the later window holds the later upload. The earlier copy counts as `superseded`. Inside one window, two -different objects with one id are both refused. The start becomes `input_timestamp` by the +different objects with one id are both refused. Each Garmin envelope +keeps its `upload_window`, so the rule also holds across commands. A copy +from a window that ends at or before the start of the stored copy's +window was uploaded first. It is `superseded`, it writes nothing, and it +is not a server change, so it replaces no owner correction. Comparisons +leave `upload_window` out, because windows depend on `--from`. The start becomes `input_timestamp` by the rules in the specification: text keeps its offset or says it has none, and Unix seconds or milliseconds keep their digits. The start is stored and is not a filter. @@ -1570,6 +1581,13 @@ Rejected alternatives: - Refuse both copies when one Garmin id is in two windows with different objects, as inside one response. Rejected. A re-upload is an ordinary Garmin event, and the later window holds the later copy. +- Compare Garmin windows only inside one command, as the earlier text + did. Rejected. A later command that reads only an earlier window would + store the older copy again, and it would count that as a server change + that replaces an owner correction. +- Count a different `upload_window` as a change. Rejected. Windows depend + on `--from`, so every pull with another range would revise every Garmin + original. - Drop an original whose start is outside the requested range. Rejected. The live methods do not filter by workout start, so a drop would hide a returned object. diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index 6b5dab01..641986ea 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -1244,6 +1244,26 @@ through the detail rules. Equal copies in two windows are one object, and nothing is counted. Inside one window, two different objects with one id still refuse both as `duplicate_id`. +Each Garmin envelope keeps the window its object came from, as +`upload_window`, so the same rule holds across commands. Take a Garmin +candidate that differs from the newest `provider_import` revision of its +original. When its window ends at or before the start of that revision's +window, the candidate is the older copy. A window holds only objects +uploaded inside it, so that copy was uploaded first. It counts as +`superseded`, and nothing is written. The stored-original read returns +the stored window, so the pull makes no detail call for it. It is not a +server change, so it never replaces an owner correction. When either side +has no `upload_window`, this rule does not apply. The rule runs in +matching for route `open_wearables`, so a mapped import of saved +envelopes follows it too. + +Every comparison of a vendor original on that route leaves +`upload_window` out: the 2.1.1 equality test, the owner-correction rule, +and the difference test above. The windows depend on `--from`, so an +unchanged object read through another window writes nothing. The stored +original keeps the window it was stored with, and that window still +holds its upload. + The start column names one field and how to read it: - Text with an offset or `Z`. The receipt is the one `input_receipt` in @@ -1279,7 +1299,7 @@ it gets no detail call. For each listed id, the pull first reads the stored original, if there is one. That read is crate-private and lives in `src/import/provider.rs`. It returns whether the original exists, whether it is deleted, whether it -holds a detail, and its stored `list`. It reads the newest revision with +holds a detail, its stored `list`, and, for Garmin, its `upload_window`. It reads the newest revision with basis `provider_import`, not an owner correction, so a person's edit does not look like a vendor change and does not spend a detail call. @@ -1374,6 +1394,9 @@ the same object: `unix_seconds`, or `unix_milliseconds`, from the table. It is absent when `start` is. - `list` is the list object. `list_parent` is present only for Sensorbio. +- `upload_window` is present only for Garmin. It holds `start` and `end`, + the integer Unix seconds of the window the list object came from, such + as `{ "start": 1767225600, "end": 1767308400 }`. - `detail` is the detail object after the table's detail unwrap. It is absent when no detail is stored. - `detail_status` is `stored`, `deferred`, `failed`, `mismatch`, @@ -1487,7 +1510,8 @@ whole envelope in `supplied_fields`. A saved file of envelopes, under `vendor_workout`, imports through that section with `ath import --mapping open-wearables`. File import does not apply the detail rules above. It writes each envelope as the file holds it, as D182 does for every mapped -import. Export and import keep one original id. +import, except the Garmin window rule above. Export and import keep one +original id. The provider table, the detail rules, and the thinner check live in `src/runtime/vendor_workouts.rs`. They run before the mapping engine sees @@ -1750,7 +1774,9 @@ besides the typed writes in section 6. It gains nothing beyond those: `record_by_import_key` also returns the current revision's basis. For an owner correction, matching reads the newest `provider_import` revision of that record and compares the candidate with it. The page's report counts - each replaced correction. + each replaced correction. For a `vendor_workout` row, matching leaves + `upload_window` out of each comparison and applies the Garmin window + rule in section 2. - In matching, for a page with `vendor_workout` rows, the size bound in section 2. It sums the stored vendor-original revisions and refuses the page when its new and changed envelopes would pass @@ -2064,7 +2090,7 @@ interactive open can preview, back up, ask, and then migrate. | Stage, match, and write each page | `preview_route` and `ProviderPreview::apply` in `src/import/provider.rs`. The revision a preview read is the public `destination_database_revision` | | A `connector` source with no vendor | new `connector_source` beside `route_source` in `src/import/provider.rs` | | Page counts by record type | a count beside `Staging::count` in `src/import/staging.rs`, exposed by `ProviderPreview` | -| Owner-correction rule and its count | `match_keyed` and `record_by_import_key` in `src/import/provider.rs`, behind a `KeyedPolicy` flag that only route `open_wearables` sets | +| Owner-correction rule and its count, and the Garmin window rule | `match_keyed` and `record_by_import_key` in `src/import/provider.rs`, behind a `KeyedPolicy` flag that only route `open_wearables` sets | | Where a workout fix belongs | one paragraph in `skills/athletic-standard/SKILL.md`, under "Stable IDs and revisions" | | Total size bound for vendor originals | `MAX_VENDOR_ORIGINAL_BYTES` in `src/input_policy.rs`, checked in the matching step in `src/import/provider.rs` | | Export refuses a document over the package read cap | `src/package/export.rs`, before the staging folder is renamed | @@ -2649,6 +2675,15 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: with equal objects in both windows stores one original and counts nothing. The same id twice in one window, with different objects, refuses both as `duplicate_id` +- a two-command Garmin fixture. The first command reads both windows and + stores the 1860 copy with the second window as its `upload_window`. A + second command reads only the first window and sees the 1800 copy. It + counts 1 `superseded`, makes no detail call for it, and writes nothing. + When the person had corrected that original, the correction stays + current, and `owner_corrections_replaced` is 0. In the other order, the + second command's later copy replaces the stored earlier copy as a + change. A third command with a different `--from` reads the unchanged + 1860 copy through a different window and writes nothing - a three-day Garmin range sends four windows, three of 82,800 seconds and one of 10,800 seconds. Each window sends `summary_start_time` and `summary_end_time` as integer Unix seconds, and each starts where the From 1cb8c95f75caab2222f19ae5e65460e26896493e Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 06:39:27 +0000 Subject: [PATCH 48/60] Count the vendor-original bound in exported bytes The bound counted 128 MiB of compact record_json. Export pretty-prints each item and writes each original at least twice, once as the record and once per revision. A synthetic one-hour Polar run with a route exports at 2.05 times its compact size, so the old bound could export to about 525 MiB, over the 512 MiB read cap. The bound is now half of that cap, 256 MiB, counted in the bytes export writes. It holds about 158 such workouts with one revision each. The appendix records the measurement. ath correct, the protocol writes, a package merge and a native restore check the bound too. Every pull prints the total used, in the text and in --json, and warns from 80% with the remedy and its cost. The export check also refuses an item past the 128-level nesting limit. Storing originals in their own files is listed as an open question for the maintainer. Co-authored-by: Michael Whitham --- .../v2.2.0/appendix/vendor-original-size.md | 68 ++++++ build-history/v2.2.0/decisions.md | 71 ++++-- build-history/v2.2.0/spec.md | 211 +++++++++++++----- 3 files changed, 275 insertions(+), 75 deletions(-) create mode 100644 build-history/v2.2.0/appendix/vendor-original-size.md diff --git a/build-history/v2.2.0/appendix/vendor-original-size.md b/build-history/v2.2.0/appendix/vendor-original-size.md new file mode 100644 index 00000000..8d28c270 --- /dev/null +++ b/build-history/v2.2.0/appendix/vendor-original-size.md @@ -0,0 +1,68 @@ +# Size of a vendor original in a package + +This study was measured on 16 November 2026 for D242. It used no real +data. Every value below is invented. + +## Method + +`ath export` at `0de71bb` writes each record and each revision with +`json::to_deterministic_pretty` in `src/json.rs`. That printer puts two +spaces before each level, sorts keys, and writes `": "` after each key. +`ArrayWriter::item` in `src/package/export.rs` then indents every line +four more spaces and writes `,` and a new line before each item. The +stored `record_revisions.record_json` is compact. A short Python script +copied those rules and the JavaScript number text for these values. It +then measured one synthetic original. + +The original follows the pinned Polar `ExerciseJSON` model in +`backend/app/schemas/providers/polar/exercise_import.py` at Open +Wearables commit `183e8cc4f6de897dbd288c93d49a691f2cf721ae`. It is a +one-hour run: + +- a route of 3,600 points, one a second. Each point has `latitude` and + `longitude` to six decimals, `time`, `satellites`, and `fix`. +- six sample strings with one value a second: heart rate, speed, + cadence, altitude, temperature, and distance +- five heart-rate zones, and the model's summary fields +- the envelope in section 2 of the specification. `list` has no samples, + zones, or route. `detail` has all three. +- the `source_report` fields around the envelope, with invented ids and + times + +A second shape drops the samples and the zones and keeps the route. + +## Results + +| Shape | Compact `record_json` | One exported item | Ratio | Exported, one revision | Exported, two revisions | +|---|---|---|---|---|---| +| Route, samples, and zones | 412,909 bytes | 847,259 bytes | 2.05 | 1,694,355 bytes | 2,541,611 bytes | +| Route only | 311,189 bytes | 744,471 bytes | 2.39 | 1,488,779 bytes | 2,233,247 bytes | + +An original with one revision is in the main document twice: once as its +current record and once as that revision. So it exports at about four +times its compact column bytes. Each later revision adds one more item. + +Under 256 MiB of exported bytes: + +- 158 originals of the first shape fit with one revision each, or 105 + with two. +- 180 originals of the route-only shape fit with one revision each, or + 120 with two. + +The earlier bound counted 128 MiB of compact `record_json`. With one +revision for each original, that is about 525 MiB of the first shape as +export writes it, and about 612 MiB of the route-only shape. Both are +over the 512 MiB package read cap. + +The deepest value is a route point's field, five levels inside the +record's `data`. In the package it is eight levels deep. The package read +limit is 128 levels. + +## What was not measured + +- A real vendor response. Route point text and sample strings differ by + device and by sport. +- Garmin, Strava, and Suunto details. Their laps, splits, and sample + arrays nest in other ways. +- How long measuring the stored originals takes in a database near the + bound. diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index 99c7bd90..770287c1 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -161,6 +161,15 @@ number is added: later command, a copy from a window that ends at or before the start of the stored copy's window is `superseded`. It writes nothing and never replaces an owner correction. Comparisons leave the window out. +- D242 and D231. The vendor-original bound is 256 MiB, half of the 512 MiB + read cap, counted in the bytes export writes. The earlier bound counted + 128 MiB of compact JSON, which could export to about 525 MiB. It holds + about 158 one-hour Polar workouts with routes and samples. `ath + correct`, the protocol writes, a package merge, and a native restore + check it too. Every pull prints the total used and warns from 80%. The + export check also refuses an item past the 128-level nesting limit. + Storing originals in their own files is an open question for the + maintainer. ## D227. Version 2.2.0 is one manual pull, and the program and the record share that number @@ -658,7 +667,9 @@ is refused. `write_current_state` in `src/store/encode.rs` is the only record-to-table mapping. Package restore, repair, and the record check use it. There is no TypeScript writer to update. D234 also allows `source_report` insert and update, and withdrawal of a child whose anchor -is in this response. Nothing beyond that is added to the store. Other +is in this response. D242 adds the vendor-original size check to +`apply_in` in `src/store/write.rs`, for a change that writes an original. +Nothing beyond that is added to the store. Other routes do not call the receipt operations. Splitting `mapping.rs` is separate work. It is not required to make the pull correct. @@ -1326,19 +1337,34 @@ Each provider's line counts originals as new, changed, and unchanged. It counts owner corrections replaced, details by outcome, objects left out by reason, and withheld values. -Vendor originals have a total size bound, `MAX_VENDOR_ORIGINAL_BYTES`, -128 MiB, counted over every revision of every original. A native package -writes them in its main document, `athlete.ath.json`, with every record -that is not a measurement sample: the current record under `records` and -each revision under `record_revisions`. Only samples go to `series/` -files. Version 2.1.1 reads that document only up to 512 MiB, and a mapped -import file only up to 512 MiB. The bound keeps the originals near half of -the main document. A page that would pass it is refused, its objects -count as `size_cap`, and that provider is `incomplete`. A mapped import -uses the same bound. `ath export` gains a check that refuses to publish a -document over the 512 MiB read cap, because 2.1.1 can write a package it -cannot read back. Each listed object is in exactly one detail count or one left-out -count, so no object is dropped without a count. +Vendor originals have a total size bound, `MAX_VENDOR_ORIGINAL_BYTES`. It +is half of the 512 MiB package read cap, 256 MiB, counted in the bytes +`ath export` writes for every revision of every original, including a +deleted one. A native package writes them in its main document, +`athlete.ath.json`, with every record that is not a measurement sample: +the current record under `records` and each revision under +`record_revisions`. Only samples go to `series/` files. Version 2.1.1 +reads that document only up to 512 MiB, and a mapped import file only up +to 512 MiB. Export pretty-prints each item, so the bound counts those +bytes and not the compact `record_json` column. One function measures an +item for both. A synthetic one-hour Polar run with a route exports at +2.05 times its compact size, and each original is in the document at +least twice. So the earlier bound, 128 MiB of compact JSON, could export +to about 525 MiB. The new bound holds about 158 such workouts with one +revision each, or about 105 with two. Evidence: +[appendix/vendor-original-size.md](appendix/vendor-original-size.md). + +Every write that adds a vendor-original revision checks the bound: a pull +page, a mapped import, `ath correct`, the protocol record writes, a +package merge, and a native restore. A page that would pass it is +refused, its objects count as `size_cap`, and that provider is +`incomplete`. Every pull prints how much of the bound the originals use, +in the text and in `--json`. From 80% it warns, and the warning names +`ath erase` and says the erase cannot be undone. `ath export` gains a +check that refuses to publish a document over the 512 MiB read cap or an +item past the 128-level nesting limit, because 2.1.1 can write a package +it cannot read back. Each listed object is in exactly one detail count or +one left-out count, so no object is dropped without a count. The pull uses the published query parameters and does not add its own retry. It does not call sync or historical sync. A completed provider @@ -1363,9 +1389,20 @@ Rejected alternatives: restored. - Store only the list object once the bound is near. Rejected. The pull would drop details while it reported success. -- Store originals in their own package files now. Not chosen for this - release. It changes the package format. Section 9 of the specification - lists it. +- Count the bound in compact `record_json` bytes, as the earlier text + did. Rejected. Export pretty-prints each item and writes each original + at least twice, so a database under that bound could not be exported + and read back. +- Give vendor originals more than half of the read cap. Not chosen. + Nothing bounds the other records in the main document, and a long + history of points, summaries, and sessions shares it. +- Check the bound only on pulls and mapped imports. Rejected. `ath + correct`, a merge, or a restore could then take a database past it, and + its export could become unreadable. +- Store originals in their own package files now. Not chosen in this + plan. It changes the package format. Section 9 of the specification + lists it, and section 10 leaves it as an open question for the + maintainer. - Replace an owner correction whenever the candidate differs from the current record, as D182 does and as the first version of this decision did. Rejected. A pull repeats the same server data, so every pull would diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index 641986ea..c7fa0c27 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -98,6 +98,9 @@ Preview text prints: failures, size limits and refusals are only known after --yes` - when `--vendor-workouts` is on: `vendor workout originals`, then `estimated`, then new, changed, and unchanged counts +- on every run: `vendor originals use X MiB of 256 MiB`, the total stored + before this command. It is not an estimate. From 80% of the bound, the + size warning in section 2 follows it - when a credential-shaped value was withheld: the count and up to 20 paths, as section 4 says - when `--vendor-workouts` is on, this sentence: a workout can appear twice, @@ -208,6 +211,8 @@ the text. The object has no key, server, user id, or request path. "requested": false, "requests_made": false, "notice": [], + "used_bytes": 0, + "bound_bytes": 268435456, "estimated": { "originals": { "new": 0, "changed": 0, "unchanged": 0 } }, @@ -239,13 +244,18 @@ the text. The object has no key, server, user id, or request path. } ``` -`notice` is empty without the flag. With it, `notice` holds the three -sentences about server changes in section 2, on every run, including a -preview. Every `--json` run is a preview, so with the flag `notice` also -holds `preview made no detail calls; detail failures, size limits and -refusals are only known after --yes`. `connection_status` is `active`, `revoked`, `expired`, -`unknown status`, or `null` when the server listed no connection for that -provider. +`notice` is empty without the flag, except for the size warning. With +the flag, `notice` holds the three sentences about server changes in +section 2, on every run, including a preview. Every `--json` run is a +preview, so with the flag `notice` also holds `preview made no detail +calls; detail failures, size limits and refusals are only known after +--yes`. From 80% of the bound, with or without the flag, `notice` also +holds the size warning in section 2. `used_bytes` is the vendor-original +total stored before this command, as export measures it, and +`bound_bytes` is `MAX_VENDOR_ORIGINAL_BYTES`. Both are facts, so they are +not under `estimated`. `connection_status` is `active`, `revoked`, +`expired`, `unknown status`, or `null` when the server listed no +connection for that provider. The top-level `estimated_owner_corrections_replaced` counts owner corrections of stored records that the stored pages would replace, by the @@ -1414,40 +1424,93 @@ mapping reads. The match key is the writer, the sensor, the resource `vendor_workout`, the provider, and the vendor id, escaped by D181. So the Suunto record in section 7 has a key that ends `suunto|1001`. -Vendor originals have a total size bound. `MAX_VENDOR_ORIGINAL_BYTES` in -`src/input_policy.rs` is 128 MiB. It counts the bytes of `record_json` in -every revision of every vendor original, including a deleted one. A native -package writes these records in its main document, `athlete.ath.json`, -with every other record that is not a measurement sample. The current -record is under `records`, and each revision is under `record_revisions`. -Only measurement samples go to the `series/` files. So each original is in -that one document at least twice. Version 2.1.1 reads a package document -only up to `MAX_PACKAGE_DOCUMENT_BYTES`, which is 512 MiB, and a mapped -import file only up to `MAX_MAPPED_INPUT_BYTES`, also 512 MiB. The bound -keeps the originals near 256 MiB of the main document, and the rest is -left for every other record. A saved file of current envelopes is at most -128 MiB plus its JSON wrapping, so it fits the mapped-import cap. - -The matching step of a page with `vendor_workout` rows adds the page's -new and changed envelopes to the stored total. A page that would pass the -bound is refused. It writes nothing, its objects count as `size_cap` in -`left_out`, and that provider is `incomplete`. The line says the stored -vendor originals would pass 128 MiB, so a package holding them could not -be read back. `ath import --mapping open-wearables` uses the same bound. -A Polar detail with samples and a route for a one-hour outdoor workout is -a few hundred kilobytes, so the bound holds several hundred such workouts -with one revision each. Deleting an original does not lower the total, -because its revisions stay. `ath erase` removes the record and its -revisions, so it does. Storing originals in their own package files is -later work, in section 9. +Vendor originals have a total size bound. A native package writes them in +its main document, `athlete.ath.json`, with every other record that is +not a measurement sample. The current record is under `records`, and each +revision is under `record_revisions`. Only measurement samples go to the +`series/` files. So each original is in that one document at least twice. +Version 2.1.1 reads a package document only up to +`MAX_PACKAGE_DOCUMENT_BYTES`, which is 512 MiB, and a mapped import file +only up to `MAX_MAPPED_INPUT_BYTES`, also 512 MiB. + +`MAX_VENDOR_ORIGINAL_BYTES` in `src/input_policy.rs` is half of +`MAX_PACKAGE_DOCUMENT_BYTES`, 256 MiB. It counts the bytes `ath export` +writes for vendor originals. For each original, including a deleted one, +that is its item under `records` and each of its items under +`record_revisions`. Export writes each item with +`json::to_deterministic_pretty`, two spaces for each level, and indents +every line four spaces more. The stored `record_json` is compact, so the +bound does not count it. One function beside the item writer in +`src/package/export.rs` measures an item, so the bound and export count +the same bytes. The originals therefore take at most half of the main +document. The other half is for every other record. Nothing bounds those +records, so the export check below is the last guard. + +A synthetic one-hour Polar run with a 3,600-point route, six sample +strings, and five zones is 413 KB as compact `record_json`. Each item of +it that export writes is 847 KB, 2.05 times as large. With one revision, +the original is in the document twice, 1.69 MB. So the bound holds about +158 such workouts with one revision each, or about 105 with two. The +earlier bound, 128 MiB of compact JSON, would export to about 525 MiB of +them, over the read cap. +[appendix/vendor-original-size.md](appendix/vendor-original-size.md) +records the measurement. + +Every write that adds a vendor-original revision checks the bound before +it writes: + +- A pull page and `ath import --mapping open-wearables`, in the matching + step. A page that would pass the bound is refused. It writes nothing, + its objects count as `size_cap` in `left_out`, and that provider is + `incomplete`. +- `ath correct` and the protocol record writes, for a change that creates + or revises a vendor original. The check is in `apply_in` in + `src/store/write.rs`, which `Store::apply` and `apply_with_attachments` + both call. +- A package merge and a native restore, in `src/package/restore.rs`. A + package that 2.2.0 exported always passes, because every write keeps + its database under the bound. + +Each refusal names the bound and the bytes the originals would use. It +says that a package holding them could not be read back. Deleting an +original does not lower the total, because its revisions stay. `ath +erase` removes the record and its revisions, so it does. + +Every run of `ath pull openwearables` prints `vendor originals use X MiB +of 256 MiB`, with X to one decimal. A preview prints the total stored +before this command, and `--yes` prints the total after it. `--json` has +`vendor_workouts.used_bytes` and `vendor_workouts.bound_bytes`. From 80% +of the bound, the run also prints a warning, and `--json` puts it in +`vendor_workouts.notice`. The warning says three things. At the bound, +new vendor pages are refused. `ath erase` of an original frees its space, +but it removes that original and its history and cannot be undone. +Storing originals in their own files is an open question for the +maintainer (section 10). + +The pull measures the stored originals once per command, in its first +vendor page's matching read, and adds what each committed page writes. A +later page whose matching read sees a database revision that the pull's +own last apply did not produce measures them again. A mapped import +measures them once. `ath export` in 2.1.1 writes the main document and the series files with no size check, so it can publish a package that `src/package/load.rs` refuses to read. The build adds that check to `src/package/export.rs`. Export counts the bytes of each document it writes into its staging -folder. When one passes `MAX_PACKAGE_DOCUMENT_BYTES`, export fails before -the rename, removes the staging folder, publishes nothing, and names the -document that was too large. +folder and the nesting depth of each item. A document may not pass +`MAX_PACKAGE_DOCUMENT_BYTES`, and an item may not nest deeper than +`MAX_PACKAGE_JSON_NESTING`, 128 levels, counted from the document. When +either happens, export fails before the rename, removes the staging +folder, publishes nothing, and names the document. The package puts a +vendor object up to five levels deeper than its response did: the +document, `records`, the item, `data`, and `supplied_fields`. serde_json, +which `src/json.rs` uses, refuses JSON nested 128 levels or more. So an +object 124 to 127 levels deep could be stored and then fail this check. +The pull does not refuse such an object itself. + +ath does not write a saved file of envelopes. Written compact or with a +two-space indent, such a file is smaller than its originals as export +writes them, so it fits the 512 MiB mapped-import cap. The pull writes one provider's originals as one page, after that provider's list and detail calls finish. The page is one preview at one @@ -1778,9 +1841,9 @@ besides the typed writes in section 6. It gains nothing beyond those: `upload_window` out of each comparison and applies the Garmin window rule in section 2. - In matching, for a page with `vendor_workout` rows, the size bound in - section 2. It sums the stored vendor-original revisions and refuses the - page when its new and changed envelopes would pass - `MAX_VENDOR_ORIGINAL_BYTES`. + section 2. It measures the stored vendor originals as export writes + them, adds the page's new and changed envelopes, and refuses the page + when the total would pass `MAX_VENDOR_ORIGINAL_BYTES`. The pull reads the revision a preview matched at from `ProviderPreview::destination_database_revision`, which is already public. @@ -2092,8 +2155,9 @@ interactive open can preview, back up, ask, and then migrate. | Page counts by record type | a count beside `Staging::count` in `src/import/staging.rs`, exposed by `ProviderPreview` | | Owner-correction rule and its count, and the Garmin window rule | `match_keyed` and `record_by_import_key` in `src/import/provider.rs`, behind a `KeyedPolicy` flag that only route `open_wearables` sets | | Where a workout fix belongs | one paragraph in `skills/athletic-standard/SKILL.md`, under "Stable IDs and revisions" | -| Total size bound for vendor originals | `MAX_VENDOR_ORIGINAL_BYTES` in `src/input_policy.rs`, checked in the matching step in `src/import/provider.rs` | -| Export refuses a document over the package read cap | `src/package/export.rs`, before the staging folder is renamed | +| Total size bound for vendor originals, in the bytes export writes | `MAX_VENDOR_ORIGINAL_BYTES` in `src/input_policy.rs`. One function beside `ArrayWriter::item` in `src/package/export.rs` measures an item. The bound is checked in the matching step in `src/import/provider.rs`, in `apply_in` in `src/store/write.rs`, and in `merge_in`, `resolve_in`, and native restore in `src/package/restore.rs` | +| The vendor-original total and its warning | the pull's text and `--json` outcome, from `pull` in `src/cli/commands/routes.rs` | +| Export refuses a document over the package read cap, or an item past the nesting limit | `src/package/export.rs`, before the staging folder is renamed | | Device-binding facts and the safety snapshot | new `src/import/binding.rs`, called from the matching step in `src/import/provider.rs` for route `open_wearables` | | Create or first-bind with the checked receipt, and refuse any other `device_binding` change | the staged plan and `ProviderPreview::apply` in `src/import/provider.rs` | | Stored-original read for the vendor detail rules | a crate-private read in `src/import/provider.rs` | @@ -2657,17 +2721,28 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: as `unsafe_number`. A fractional id refuses only that object and counts it as `unusable_id`. Two different objects with one id are both refused as `duplicate_id` -- a synthetic database whose vendor originals, with their revisions, total - just under `MAX_VENDOR_ORIGINAL_BYTES` exports with `ath export`. The - main document is under 512 MiB. `ath import` of that package into a - database made by `ath init --empty` keeps every record id, revision, - deletion, and import key. - The restored database passes `ath check`. A vendor page that would pass - the bound is refused, writes nothing, counts its objects as `size_cap`, - and makes that provider `incomplete`. A mapped import of the same - envelopes is refused the same way. An export whose main document would - pass the read cap, with that cap lowered for the test, fails before the - rename and publishes nothing +- a synthetic database of route-heavy Polar originals totals just under + `MAX_VENDOR_ORIGINAL_BYTES`, as export measures it. Each original has a + 3,600-point route, six sample strings, and five zones, and some have a + second revision. `ath export` succeeds, its main document is at most + 512 MiB, and the originals' items in it total the measured bytes. `ath + import` of that package into a database made by `ath init --empty` + keeps every record id, revision, deletion, and import key, and the + restored database passes `ath check`. One more original is refused by a + pull page, by a mapped import of the same envelopes, by `ath correct`, + by a protocol record write, by a package merge, and by a native + restore. Each refusal writes nothing. The page counts its objects as + `size_cap` and makes that provider `incomplete` +- the pull prints `vendor originals use X MiB of 256 MiB` on a run + without the flag, on a preview, and on `--yes`, and `--json` has + `used_bytes` and `bound_bytes`. Under 80% of the bound there is no size + warning. At 80% the text and `vendor_workouts.notice` hold the warning, + and it names `ath erase` and says the erase cannot be undone +- an export whose main document would pass the read cap, with that cap + lowered for the test, fails before the rename and publishes nothing. So + does an export whose item would nest deeper than + `MAX_PACKAGE_JSON_NESTING`, with that limit lowered for the test. An + item at the limit exports, and `ath import` reads it back - a synthetic Garmin fixture returns activity 555 in the first window with `durationInSeconds` 1800 and in the second window with 1860. One original is stored, and its `list` is the second window's object. Garmin's @@ -2933,8 +3008,11 @@ is in the build pull request. There is no duplicate to delete. - Vendor originals live in the package's main document, under its 512 MiB read cap. Storing them in their own package files, as samples are, would - lift the 128 MiB bound in section 2. That is a package format change, - and this release does not make it. + lift the 256 MiB bound in section 2. That is a package format change, + and this plan does not make it. The bound holds about 158 one-hour + Polar workouts with routes and samples, so whether 2.2.0 should store + originals in their own files is an open question for the maintainer, in + section 10. No maintainability note under another name was found in the 2.1.0 or 2.1.1 decision logs. The sizes above are the code at 2.1.1, not a @@ -2984,10 +3062,15 @@ Risks: - A deferred id that the provider stops listing is never detailed. Its list object stays stored, and the deferred count shows that it waits. - Vendor originals share the main package document and its 512 MiB read - cap. The 128 MiB bound refuses a vendor page before a package would - become unreadable. A person with several hundred Polar workouts that - have routes can reach it. That provider then stays `incomplete` until - originals are erased, or a later version stores them in their own files. + cap. The bound, 256 MiB as export writes them, refuses a vendor write + before a package would become unreadable. About 158 one-hour Polar + workouts with routes and samples reach it with one revision each, and + about 105 with two. Every pull shows the total, and from 80% it warns. + At the bound, that provider stays `incomplete` until originals are + erased, which removes them and their history, or until a later version + stores them in their own files. Nothing bounds the other half of the + document. A long history of other records can still reach the read + cap, and the export check then refuses to publish. - Date-only bounds mean whatever Open Wearables decides. The docs and the 0.11.0 parser disagree about UTC. This release does not correct that server. - Section 2 stores returned periods, series, and snapshots. It does not @@ -3087,3 +3170,15 @@ optional source key adds no column. `open_wearables`, an owner correction is kept until the server's data for that record changes, and each correction a page replaces is counted (D242, D243, D244). + +These questions stay open for the maintainer. The plan states a default +for each, and the default is not adopted: + +1. Garmin detail. The default probes the undocumented detail path once + per command. When the probe answers 400, 403, 404, 405, or 501, the + pull makes no other Garmin detail call in that command (D243). +2. The owner-correction scope. The default covers every record the + `open_wearables` pull writes. Other routes keep D182 (D242). +3. Storing vendor originals in their own package files. The default keeps + them in the main document under the 256 MiB bound, which holds about + 158 route-heavy one-hour Polar workouts (D242). From b2d39d8960e520198bf1b34727896833eb14839f Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 06:45:17 +0000 Subject: [PATCH 49/60] Answer the engineering review's R5 to R11 R5 and R6: a detail that timed out is failed, as one that got 429 or 401 is. Only ids still due a detail call become deferred, and an id due no call keeps its own count. Tests cover four Polar ids with a timeout and a sixth Strava id that stays kept. R7: each id goes in the first group of the detail order it matches. A too_large or refused id also has no stored detail, so the first group now leaves it out, or the third group could never be reached. R8: the server retries only a 429 and a 401, and the pull sees only the last answer. A command sends 24 Strava requests in the usual case, or 25 after a token reload, and at most 84. R9: a vendor object with a __proto__ key is refused alone as unusable_name, and the provider stays completed. The import check would otherwise fail that provider's page on every command. R10: the rebind fix says that it merges two devices' history on one source, and the source's history keeps the old binding. R11: the file-import sentences and the corrected-original test follow the owner-correction rule, and a vendor page's counts stay apart from archive_committed. Co-authored-by: Michael Whitham --- build-history/v2.2.0/decisions.md | 57 ++++++++++--- build-history/v2.2.0/spec.md | 133 +++++++++++++++++++++--------- 2 files changed, 140 insertions(+), 50 deletions(-) diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index 770287c1..74e4fddd 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -170,6 +170,22 @@ number is added: export check also refuses an item past the 128-level nesting limit. Storing originals in their own files is an open question for the maintainer. +- D243. A detail that timed out is `failed`, as one that got 429 or 401 + is. Only ids still due a detail call become `deferred`. An id due no + call keeps its own count. Each id goes in the first group of the detail + order it matches, and a `too_large` or `refused` id is no longer in the + first group. +- D243. One `--yes` command sends 24 Strava requests in the usual case, + or 25 after a token reload, which leaves about 75. The ceiling is 84, + because the pull cannot see a server retry that ended in success. +- D243 and D231. A vendor object with a `__proto__` key is refused alone + as `unusable_name`, and the provider stays `completed`. The import check + would otherwise fail that provider's page on every command. +- D230. The rebind fix says that it merges the two devices' history on + one source. The source's history keeps the old binding. +- D242. The file-import sentences and the corrected-original test follow + the owner-correction rule. A vendor page's counts stay apart from + `archive_committed`. ## D227. Version 2.2.0 is one manual pull, and the program and the record share that number @@ -526,7 +542,11 @@ reconciliation, and a rerun cannot repair either one. Each page refusal also names the owner's fix where 2.2 has one. `ath correct` on the source can set a new `device_binding`, bind history that one device wrote, or replace a -malformed receipt. A changed workout kind has no fix that keeps the +malformed receipt. A new `device_binding` puts the old device's history +and the new device's rows on one source, and a point carries no device +id, so they can no longer be told apart. That rebind is the owner's +explicit merge, and the refusal text says so. The source's history keeps +the old binding. A changed workout kind has no fix that keeps the record. `ath erase` removes it, and the next pull stores the new kind. A bound source that receives rows with no id, and history from more than one device, have no fix in 2.2. A preview that fails makes no database @@ -683,8 +703,9 @@ it before it builds a candidate (D191). It refuses an empty name and a native reader, which keeps such a key and checks it, so the import refusal still applies. There is no `persist.rs` and no `ath-core persist` command. The pull writes through `MappedPage` and the -2.1.1 import, so the import check covers it. A name check outside import -is separate work. +2.1.1 import, so the import check covers it. The vendor read in D243 runs +the same check on each vendor object first, so one object with the key is +refused alone. A name check outside import is separate work. `is_mapping_path` exists once, in `src/assets/mod.rs`. The pull uses `resolve_mapping` in that file. There is no second path rule to remove. @@ -1298,8 +1319,9 @@ The rewritten `mappings/open-wearables.md` gains a section named `vendor_workout`. It declares the record type, the kind, the subject, the writer, the sensor, the key, and the start. A saved file of envelopes imports through that section. File import writes each envelope as the -file holds it, as D182 does for every mapped import, except the Garmin -window rule in D243. The detail rules in +file holds it, as D182 does for every mapped import, except the +owner-correction rule below and the Garmin window rule in D243. The +detail rules in D243 run before the mapping engine sees an envelope, so the mapping engine has no vendor exception. @@ -1528,12 +1550,17 @@ server has already spent its three retries on the vendor's limit. An HTTP 401 ends it the same way. The server has already reloaded or refreshed the vendor token and tried once more, each later 401 would make it do that again, and a refresh the vendor rejects revokes the -connection. The detail call that got 429 or 401 is `failed`. Ids whose detail was not yet called -are `deferred`. What the provider already returned is still written, and -the provider is `incomplete`. A command makes at most 100 detail calls to one provider -and at most 20 to Strava. Ids with no stored detail go first, oldest -start first. Strava's limit belongs to the whole application, so the -deployment's own sync shares it. The review cited about 100 requests a +connection. The detail call that got 429 or 401, or that timed out, is +`failed`. Each id still due a detail call is `deferred`. An id that was +due no call keeps its own count, such as `kept`. What the provider +already returned is still written, and the provider is `incomplete`. A +command makes at most 100 detail calls to one provider and at most 20 to +Strava. Ids with no stored detail go first, oldest start first. Each id +goes in the first group of the order it matches. Strava's limit belongs +to the whole application, so the deployment's own sync shares it. The +server tries one request at most four times and the pull sees only the +last answer, so one command sends 24 or 25 Strava requests in the usual +case and at most 84. The review cited about 100 requests a minute for Garmin. This study did not find that number in Garmin's public docs. The one-second pace keeps this command at 60 a minute or fewer. @@ -1553,6 +1580,14 @@ rules in the specification: text keeps its offset or says it has none, and Unix seconds or milliseconds keep their digits. The start is stored and is not a filter. +A vendor object with a `__proto__` key at any depth is refused alone as +`unusable_name`, and the provider stays `completed`. The import check +(D191) refuses that key and fails the whole import. Vendor JSON is +outside ath's control, so one such object would otherwise fail that +provider's page on every command, with no count and no fix. The vendor +read runs the same check on each list object and each detail before the +page is staged. + Every returned original is stored, including a start outside `--from` and `--to`. The count is `vendor workout originals`. `range_complete` uses only the stored ranged reads. Each line says whether its limit covers the diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index c7fa0c27..5869b81a 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -829,8 +829,13 @@ Each refusal names what the owner can do, and the text says the same: owner runs `ath correct` on the source and sets `device_binding` to the new id. Later rows from the new device are then accepted. A new row replaces an old one only where both have the same match key, which - includes the time. When the incoming id is missing, null, or blank, - 2.2 has no fix that keeps the source. Removing the key would make the + includes the time. The old device's rows stay on that source, and the + binding then names only the new id. A point carries no device id, so + the two devices' rows on that source can no longer be told apart. The + rebind is the owner's explicit merge of the two histories. The + source's history keeps the old binding, and `ath records show + --history` shows it. When the incoming id is missing, null, + or blank, 2.2 has no fix that keeps the source. Removing the key would make the source unbound history, which is refused too. Deleting the source leaves out every later row from it (D190). - Unbound history. If one device wrote all of that history, the owner @@ -1082,11 +1087,13 @@ that provider the same way. The server has already reloaded the vendor token, or refreshed it, and tried once more. Each later request would make it do that again, and a refresh the vendor rejects revokes the connection. No later list call, window, or detail call goes to that -provider in this command. The detail call that got 429 or 401 counts as -`failed`. Every listed id that had not had its detail call yet counts as -`deferred`, and a later command details it by the order below. What the -provider already returned is still written as that provider's page: the -list objects, and the details already fetched. A later Garmin window +provider in this command. The detail call that got 429 or 401, or that +timed out, counts as `failed`. Every id still due a detail call by the +order below counts as `deferred`, and a later command details it. An id +that was due no call keeps its own count, such as `kept` or +`not_available`. What the provider already returned is still written as +that provider's page: the list objects, and the details already fetched. +A later Garmin window after a 429, a 401, or a timeout is not sent, unlike a window that failed another way. A server whose provider timeout is raised can outlast this timeout. The same rule covers that case. The @@ -1108,13 +1115,15 @@ Budgets keep one command inside the providers' limits: it. Strava's rate-limit page, fetched 15 November 2026, gives a default of 100 read requests per 15 minutes and 1,000 a day. Strava calls them non-upload requests. One list call and 20 detail calls are 21 - requests. A 429 makes the server try that request four times, and the - pull then stops calling Strava. So one `--yes` command sends at most 24 - Strava requests. A 401 adds one attempt to that request after the server - reloads the token. That - leaves about 76 for the deployment's own sync in the same 15 minutes. A - preview first adds one list call. The Strava line says that its limit is - shared. + requests. The server tries one request at most four times. It retries + a 429 up to three times, and a 401 once after it reloads the token. + The pull sees only the last answer, and it stops calling Strava after + a final 429. When only that last request was retried, one `--yes` + command sends 24 Strava requests, or 25 after a token reload. That + leaves about 75 for the deployment's own sync in the same 15 minutes. + The ceiling is 84, four tries for each of the 21 requests, because the + pull cannot see a retry that ended in success. A preview first adds one + list call. The Strava line says that its limit is shared. The routes are `GET /api/v1/providers/{provider}/users/{user_id}/workouts` and @@ -1245,6 +1254,19 @@ reason. A refused object refuses only itself, and the count says why. Two different objects with one id in one provider's response refuse both, because the pull cannot tell which is right. Two equal objects are one. +A vendor object that holds a key named `__proto__` at any depth is +refused as `unusable_name`. The import check in section 3 refuses that +key in any supplied field, and it fails the whole import. So +`src/runtime/vendor_workouts.rs` runs the same check on each list object +and each detail before the page is staged. A list object with the key +gets no detail call. A detail with the key refuses its whole object, list +object included. Only that object is refused, and the others are +written. The provider stays `completed`, as it does for the other refused +objects, because a rerun gets the same object. The person has no fix in +ath, because nothing is stored to delete. A later command reads the +object again. When only its detail holds the key, that command spends one +detail call on it again. + Garmin is read in windows, and one activity can be in two windows when Garmin received it again. A window selects by upload time, so the later window holds the later copy. For Garmin only, an object in a later window @@ -1315,11 +1337,14 @@ not look like a vendor change and does not spend a detail call. The pull calls detail only when the provider has a detail call and its budget allows. It spends the budget in this order. First come ids with no -stored detail that no earlier command marked `not_available`. Then come -ids whose list object differs from the stored `list`. Then come ids an -earlier command marked `too_large` or `refused`. An id that an earlier -command marked `not_available`, and whose list object is unchanged, gets -no detail call. It counts as `not_available` again. Inside each group +stored detail that no earlier command marked `not_available`, +`too_large`, or `refused`. Then come ids whose list object differs from +the stored `list`. Then come ids an earlier command marked `too_large` or +`refused`. Each id goes in the first group it matches. So an id that was +`not_available`, `too_large`, or `refused` and whose list object changed +is in the second group. An id that an earlier command +marked `not_available`, and whose list object is unchanged, gets no +detail call. It counts as `not_available` again. Inside each group the oldest start goes first. An id without a start instant goes last in its group, in list order. So a Garmin path that answers 404 costs one detail call in a command, and only when some id is due a call. An id @@ -1548,8 +1573,9 @@ preview they are estimates under `estimated`, as section 1 says. `deferred`, `failed`, `mismatch`, `thinner`, `not_available`, `too_large`, and `refused`. - `left_out`: objects not written, by reason: `missing_id`, - `unusable_id`, `unsafe_number`, `duplicate_id`, `superseded`, - `deleted_record`, `deleted_source`, `response_refused`, and `size_cap`. + `unusable_id`, `unsafe_number`, `unusable_name`, `duplicate_id`, + `superseded`, `deleted_record`, `deleted_source`, `response_refused`, + and `size_cap`. - `withheld`: values that section 4 withheld, with up to 20 paths. Each listed object is in exactly one detail count or one left-out count. @@ -1573,8 +1599,8 @@ whole envelope in `supplied_fields`. A saved file of envelopes, under `vendor_workout`, imports through that section with `ath import --mapping open-wearables`. File import does not apply the detail rules above. It writes each envelope as the file holds it, as D182 does for every mapped -import, except the Garmin window rule above. Export and import keep one -original id. +import, except the owner-correction rule and the Garmin window rule +above. Export and import keep one original id. The provider table, the detail rules, and the thinner check live in `src/runtime/vendor_workouts.rs`. They run before the mapping engine sees @@ -1617,14 +1643,17 @@ route point's `supplied_fields`. Version 2.1.1's D214 changed only the native reader, which now keeps a `__proto__` key and checks it like any other key. D214 did not lift this import refusal, so it still applies. A vendor original keeps its whole envelope in `supplied_fields`, so the -same check covers every vendor object. +same check covers every vendor object. The pull runs it on each vendor +object first and refuses only that object, as section 2 says. A saved +file of envelopes that holds the key still fails its import (D191). A Garmin file import remains a different `data_route`, so both copies of one workout stay (D161). A second pull of the same Open Wearables object, or an `ath import --mapping open-wearables` of a saved copy of that object, keeps the same rows. An identical vendor original changes no row. A -changed object replaces the stored one. The mapping engine has no vendor -exception. Section 2's detail rules decide which vendor envelopes reach -it. +changed object replaces the stored one, except under the owner-correction +rule and the Garmin window rule in section 2. The mapping engine has no +vendor exception. Section 2's detail rules decide which vendor envelopes +reach it. On a device source, the writer is `source.provider`. The sensor string is `source.device_type`, `source.device`, and `source.source`. Section 2's @@ -1715,7 +1744,9 @@ The call is one of these states: blocked, including when the sample time is new, and that running the command again cannot change the id. It names the fix in section 2: when the new device replaces the old one, `ath correct` on the source - sets `device_binding` to the new id. + sets `device_binding` to the new id. It also says that the fix merges + the old device's history and the new device's rows on that source, so + they can no longer be told apart. - The source exists, the source key is absent, and any history exists. History includes a deleted record and a deleted source device, not only live rows. `existing_source` in `src/import/provider.rs` keeps @@ -1745,8 +1776,9 @@ The call is one of these states: that accepts no rows creates no binding. A refused call is not applied, so it creates no source and binds none. -A second device is refused rather than merged. That refusal is not -archived. On `--yes`, an earlier committed page stays, the failed page +A second device is refused rather than merged. Only the owner's rebind +in section 2 merges two devices' history on one source. That refusal is +not archived. On `--yes`, an earlier committed page stays, the failed page makes no database changes, the range is not complete, and the exit is nonzero. File import refuses the whole call and writes nothing. `--json` and `--json --yes` make no database changes. Device reads @@ -2384,7 +2416,10 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: - each of the four page refusals prints the owner's fix from section 2, and each fix works. After `ath correct` sets `device_binding` on a bound source to a new id, the next pull accepts rows with that id, and a new - row replaces an old one only where the match keys are equal. After + row replaces an old one only where the match keys are equal. The + refusal text says the rebind merges the two devices' history on that + source, and `ath records show --history` shows the old + binding in the source's history. After `ath correct` adds `device_binding` to an unbound source written by 2.1.0, the next pull refreshes that history. After `ath correct` replaces a malformed receipt with a nonempty string, the next pull @@ -2585,6 +2620,11 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: `check_supplied_fields` refuses it (D191). An empty supplied-field name fails it too. A package that holds a `__proto__` key still restores, because D214 keeps the key in the native reader +- a Polar list of three objects, where one detail has a `__proto__` key + nested in a route point. Two originals are stored. Polar's `left_out` + counts 1 `unusable_name`, Polar is `completed`, and the page is not + refused. A Polar list object with the key gets no detail call and is + counted the same way - a literal key, a Unicode-escaped key in a nested unconsumed field, the key used as an object key, the selected origin, and the selected user id each reject the page before mapping. The database, its revisions, and the @@ -2788,12 +2828,24 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: timeout shortened for the test, stops every later request to that provider in the command. The next provider still runs. The 360-second value is checked as a named constant +- four Polar ids with no stored detail, with the read timeout shortened + for the test, where detail call two times out. Id one stores its + detail, id two is `failed`, and ids three and four are `deferred`. + Polar is `incomplete`, and the fixture server sees no third detail + request - five Strava ids with no stored detail, where the third detail call - answers HTTP 429. The fixture server sees no later Strava request. Ids - one and two store their details. Id three is `failed`. Ids four and five - are `deferred`. All five list objects are stored. Strava is - `incomplete`, the next provider still runs, and the exit is nonzero. A - 429 on a Garmin window sends no later window + answers HTTP 429, and a sixth id with a stored detail and an unchanged + list object. The fixture server sees no later Strava request. Ids one + and two store their details. Id three is `failed`. Ids four and five + are `deferred`. Id six stays `kept`. All six list objects are stored. + Strava is `incomplete`, the next provider still runs, and the exit is + nonzero. A 429 on a Garmin window sends no later window +- three Garmin ids: a new id, an id that was `not_available` whose list + object changed, and an id that was `not_available` whose list object is + unchanged. The new id is detailed first, then the changed id. The + unchanged id gets no detail call and counts `not_available`. An id that + was `too_large` and whose list object changed is detailed with the + changed ids, before an unchanged `too_large` id - a Garmin list object with `userAccessToken` is pulled twice, with a different token value the second time. The second pull counts it `kept`, makes no detail call, and writes nothing for it @@ -2839,10 +2891,13 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: pull, counted as `deleted_record`, and not recreated. A deleted `vendor_workout` source leaves out every object from that provider as `deleted_source`. An original that the person corrected gains a - revision with the server's envelope when a later envelope differs, and - the correction stays in its history. An equal envelope adds nothing + revision with the server's envelope when a later envelope differs from + the newest `provider_import` revision, and the correction stays in its + history. An envelope equal to that import revision writes nothing, even + though it differs from the correction, and the correction stays current - with the flag on, a run whose protected page is refused and archived - still writes the vendor page and keeps its counts apart. A refused + still writes the vendor page and keeps its counts apart from + `archive_committed`. A refused vendor page leaves the archive and the stored pages as they were - a vendor list response that the privacy scan refuses stores nothing from that response, counts its readable objects as `response_refused`, From 689616be466e5389ce563b036d8715365afea663 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 06:51:18 +0000 Subject: [PATCH 50/60] Answer the engineering review's Q1 to Q3 Q1: page counts come from one SQL count beside Staging::count. D228 now says so, and says why it does not count ProviderPreview::planned: that call copies each row's whole data_json, and a vendor page holds every original's envelope. A test checks that both give the same numbers. Q2: the owner-correction rule reads the revision column record_revisions.became_known_at_basis. It does not read changed_by, because ath grade writes the same tool actor as an import, with basis local_write. A protocol caller can choose the basis. Q3: the Suunto list cap is renamed MAX_SUUNTO_LIST_REQUESTS, because only Suunto's list is paged and the cap counts requests. Co-authored-by: Michael Whitham --- build-history/v2.2.0/decisions.md | 31 ++++++++++++++---- build-history/v2.2.0/spec.md | 53 +++++++++++++++++++++---------- 2 files changed, 62 insertions(+), 22 deletions(-) diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index 74e4fddd..0b7925f4 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -186,6 +186,13 @@ number is added: - D242. The file-import sentences and the corrected-original test follow the owner-correction rule. A vendor page's counts stay apart from `archive_committed`. +- D228 and D231. Page counts come from one SQL count beside + `Staging::count`, not from `ProviderPreview::planned`, which copies each + row's `data_json`. +- D242. The owner-correction rule reads + `record_revisions.became_known_at_basis`, not `changed_by`, because + `ath grade` writes the same tool actor as an import. +- D243. The Suunto list cap is named `MAX_SUUNTO_LIST_REQUESTS`. ## D227. Version 2.2.0 is one manual pull, and the program and the record share that number @@ -338,8 +345,12 @@ call. A comma-joined type string is still not sent. measurement samples. Workout `avg_heart_rate_bpm` and `max_heart_rate_bpm` stay as the file already maps them. -The pull counts each page by record type from its staged plan, which -`ProviderPreview::planned` already lists. The mapped-import report from +The pull counts each page by record type and action with one SQL count +over its staged plan, beside `Staging::count` in `src/import/staging.rs` +(D231). `ProviderPreview::planned` already lists each row's `record_type` +and `action`, but it also copies each row's whole `data_json`, and a +vendor page holds every original's whole envelope. The count reads no +record data. The mapped-import report from `report_value` in `src/import/provider.rs` keeps its `outcome` field. The pull adds the counts into the committed result for a page it applied, and into `estimated` for a page it only previewed. It does not add `outcome` @@ -672,7 +683,9 @@ only an `export_file` source that names a vendor. The writer `open_wearables` sources, the archive source, and each `vendor_workout` source are `connector` sources with no vendor. `Staging::count` in `src/import/staging.rs` counts by action only, so a count by record type -goes beside it for the page counts. The revision a preview read is +goes beside it for the page counts. D228 uses it instead of counting +`ProviderPreview::planned`, which copies each row's `data_json`. The +revision a preview read is already public as `ProviderPreview::destination_database_revision`. `Store::apply` in `src/store/write.rs` writes a whole record. There is no @@ -1339,8 +1352,14 @@ provider (D190). An owner correction is kept until the server's data changes. On route `open_wearables` only, a pull or a mapped import compares a candidate for -an owner-corrected record with the newest revision an import wrote, basis -`provider_import`. It does not compare with the owner's revision. Equal +an owner-corrected record with the newest revision an import wrote: the +newest one whose `record_revisions.became_known_at_basis` is +`provider_import`. The basis says how a revision became known. The rule +does not read `changed_by`, because an import writes the tool actor +`ath`, and `ath grade` writes that same actor with basis `local_write`. +A protocol caller can choose the basis, so a write that chooses +`provider_import` counts as an import. The rule does not compare with +the owner's revision. Equal writes nothing, and the correction stays current. Different replaces the correction, and the count `owner_corrections_replaced` shows it on that provider's line, in `--json`, and in the preview, which says `estimated: @@ -1512,7 +1531,7 @@ object with no `workoutKey` gets no detail call and is `not_available`, because nothing this study read shows that Suunto's detail accepts a `workoutId`. Its `payload` is unwrapped, and the record key is `workoutId`. One command sends at most 100 Suunto list requests, -`MAX_VENDOR_LIST_PAGES`. A cap that stops a list after a full page makes +`MAX_SUUNTO_LIST_REQUESTS`. A cap that stops a list after a full page makes Suunto `incomplete`, and the objects already read are still written. Whoop's response names its next page `next_token`. The request name, `nextToken`, is not sent. Sensorbio reads only the oldest 50 entries, and its line says so. diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index 5869b81a..4fb9cbde 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -862,8 +862,14 @@ An owner correction is kept until the server's data changes. This rule is new in 2.2.0. It covers every record on route `open_wearables`, from a pull or from `ath import --mapping open-wearables`. Every other route keeps D182 as it is. An import writes each revision with basis -`provider_import`. A revision with any other basis is an owner correction -here: `ath correct`, a protocol write, and an accepted package merge write +`provider_import`. The basis is the revision column +`record_revisions.became_known_at_basis`, which says how that revision +became known. The rule reads that column, not `changed_by`. An import's +`changed_by` is the tool actor `ath`. `ath grade` writes that same actor +when it corrects a link, with basis `local_write`, in +`src/prediction/grade.rs`. So `changed_by` cannot tell an import from +another write. A revision with any other basis is an owner +correction here: `ath correct`, a protocol write, and an accepted package merge write other bases. A native restore copies each revision's basis, so a restored database keeps the same answer. When a page's candidate names a stored record by its import key, and that record is not deleted: @@ -882,8 +888,9 @@ record by its import key, and that record is not deleted: The comparison is the 2.1.1 comparison, with the compared revision's `received_at`. Section 4 withholds credential values before the candidate -is built, so a withheld value is the same marker on both sides. A library -write that chooses basis `provider_import` counts as an import revision. +is built, so a withheld value is the same marker on both sides. A +protocol or library caller chooses the basis freely, so a write that +chooses `provider_import` counts as an import revision. The archive is allowed only when that snapshot has no veto, names no deleted source or record, and has one of these eligible facts: a @@ -1189,7 +1196,7 @@ timeout above. milliseconds, `filter_by_modification_time=false`, and `limit` 100, and pages `offset` until a short page. False means creation time. A page over the response cap is asked again with a smaller `limit`, down to 1. - One command sends at most `MAX_VENDOR_LIST_PAGES`, 100 Suunto list + One command sends at most `MAX_SUUNTO_LIST_REQUESTS`, 100 Suunto list requests, counting those smaller retries. When the cap stops a list whose last page was full, Suunto is `incomplete`, `more` is true, and the objects already read are still written. Each page waits for the @@ -1331,9 +1338,11 @@ it gets no detail call. For each listed id, the pull first reads the stored original, if there is one. That read is crate-private and lives in `src/import/provider.rs`. It returns whether the original exists, whether it is deleted, whether it -holds a detail, its stored `list`, and, for Garmin, its `upload_window`. It reads the newest revision with -basis `provider_import`, not an owner correction, so a person's edit does -not look like a vendor change and does not spend a detail call. +holds a detail, its stored `list`, and, for Garmin, its +`upload_window`. It reads the newest revision whose +`record_revisions.became_known_at_basis` is `provider_import`, not an +owner correction, so a person's edit does not look like a vendor change +and does not spend a detail call. The pull calls detail only when the provider has a detail call and its budget allows. It spends the budget in this order. First come ids with no @@ -1861,14 +1870,18 @@ besides the typed writes in section 6. It gains nothing beyond those: - In the preview, count the staged plan by record type and action. `Staging::count` in `src/import/staging.rs` counts by action only. A count by record type goes beside it, and `ProviderPreview` exposes it. Each - page's counts in section 1 come from that count. + page's counts in section 1 come from that count. It is one SQL count. + `ProviderPreview::planned` also lists each row's record type and + action, but it copies each row's whole `data_json`, so the counts do not + use it. - A crate-private read of a stored vendor original, for the detail rules in section 2. - In matching, for route `open_wearables` only, the owner-correction rule in section 2. `KeyedPolicy` gains a flag that only that route sets. - `record_by_import_key` also returns the current revision's basis. For an - owner correction, matching reads the newest `provider_import` revision of - that record and compares the candidate with it. The page's report counts + `record_by_import_key` also returns the current revision's + `record_revisions.became_known_at_basis`. For an owner correction, + matching reads the newest revision of that record whose basis is + `provider_import` and compares the candidate with it. The page's report counts each replaced correction. For a `vendor_workout` row, matching leaves `upload_window` out of each comparison and applies the Garmin window rule in section 2. @@ -1924,7 +1937,8 @@ seconds to connect and 360 seconds to read, for the reason in section 2. The timeouts are named constants in `src/runtime/open_wearables.rs`. One response may be at most `MAX_PULL_RESPONSE_BYTES`, which is 10 MiB. One read may be at most 1000 pages. One Suunto list may be at most -`MAX_VENDOR_LIST_PAGES`, which is 100 requests. Those limits are named constants in +`MAX_SUUNTO_LIST_REQUESTS`, which is 100 requests. Only Suunto's list is +paged, so the name says Suunto. Those limits are named constants in `src/input_policy.rs`, where 2.1.1 keeps every limit on untrusted input. In 2.1.1 the comment on `MAX_PULL_RESPONSE_BYTES` says it is the bytes of one Garmin personal connection response. The route list at the top of @@ -2641,6 +2655,9 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: workout remains a second source - `left_out` in the result is a total, a count for each reason, and at most 20 example lines. With 21 lines it says the list was shortened +- on a mixed page with new, matching, and changed rows of three record + types, the count beside `Staging::count` gives the same numbers as + counting `ProviderPreview::planned` by record type and action - a synthetic Polar list without samples, zones, and route, then one detail with all three true, stores one original with `detail_status` `stored`. The nested samples are not measurement samples. A second @@ -2697,8 +2714,12 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: `estimated_owner_corrections_replaced` 0. A pull whose session changed replaces it, and the count is 1 in the preview, in `--json`, and after `--yes`. The preview says `estimated: would replace 1 owner correction - of stored records because the server's data changed`. `ath import --mapping open-wearables` of a file that holds the - same data also keeps the correction. Another route keeps its 2.1.1 rule + of stored records because the server's data changed`. `ath import + --mapping open-wearables` of a file that holds the same data also keeps + the correction. Another route keeps its 2.1.1 rule. The matching unit + test reads the basis from `record_revisions.became_known_at_basis`. A + revision whose `changed_by` is the tool actor `ath` and whose basis is + `local_write` counts as an owner correction - a record whose current revision came from an accepted package merge is an owner correction. A native export and restore keeps every revision's basis, so the same pull reports the same counts before and after the @@ -2754,7 +2775,7 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: - a Suunto fixture that always returns full pages, with a small list cap and a short pace passed into the loop as the 1000-page test does, stops at the cap. Suunto is `incomplete`, `more` is true, the objects already - read are stored, and the exit is nonzero. `MAX_VENDOR_LIST_PAGES` is + read are stored, and the exit is nonzero. `MAX_SUUNTO_LIST_REQUESTS` is checked as a named constant of 100 - a Garmin `activityId` of `123` and a later `"123"` are one record. An integer above 9007199254740991 refuses only that object and counts it From e1be59f7ad62cf46e047795568b22910b384ed53 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 06:55:21 +0000 Subject: [PATCH 51/60] Name merge choices and the body-snapshot limit in the owner rule A package merge copies the package's revisions with their own bases, so a record merged without a conflict keeps its import revisions as imports. Only a conflict the person resolved writes a new revision with basis package_merge. The plan said every accepted merge counted. It now says only those resolved conflicts count as owner corrections, and the counts name them: merge_choices_replaced is the part of owner_corrections_replaced that were merge choices, and the line adds "(M of them merge choices)". Body-snapshot records rarely keep a correction, because the server averages over a window that ends at the request and the body records' keys have no date. The plan says so. The rule still covers every record the open_wearables pull writes, other routes keep D182, and the maintainer still has to confirm that scope. Co-authored-by: Michael Whitham --- build-history/v2.2.0/decisions.md | 53 ++++++++++++---- build-history/v2.2.0/spec.md | 101 +++++++++++++++++++++--------- 2 files changed, 115 insertions(+), 39 deletions(-) diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index 0b7925f4..84c4e309 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -193,6 +193,14 @@ number is added: `record_revisions.became_known_at_basis`, not `changed_by`, because `ath grade` writes the same tool actor as an import. - D243. The Suunto list cap is named `MAX_SUUNTO_LIST_REQUESTS`. +- D242. A package merge counts as an owner correction only where the + person resolved a conflict, because `merge_in` copies the package's + revisions with their own bases. The counts name that part + `merge_choices_replaced`, and the line adds `(M of them merge + choices)`. Body-snapshot records rarely keep a correction, because the + server's averaging window moves with every request. The rule still + covers every record the `open_wearables` pull writes, and other routes + keep D182. The maintainer still has to confirm that scope. ## D227. Version 2.2.0 is one manual pull, and the program and the record share that number @@ -1367,16 +1375,32 @@ would replace N owner corrections; delete an original to keep it`. The correction stays in the history. The rule covers every record on that route, so a workout fix on the stored session also survives a pull of unchanged data. For that route it supersedes the D182 sentence that a -mapped import replaces a changed object. Other routes keep D182. The -stored-original read in D243 uses the same import revision, so an owner's -edit does not trigger a detail call. The skill says that a workout fix -belongs on the session or in a note, not on the vendor original. -Deleting an original keeps the person's version in its history and stops -every later pull from changing it. +mapped import replaces a changed object. Other routes keep D182. That +scope is the stated default, and the maintainer still has to confirm it. +The stored-original read in D243 uses the same import revision, so an +owner's edit does not trigger a detail call. The skill says that a +workout fix belongs on the session or in a note, not on the vendor +original. Deleting an original keeps the person's version in its history +and stops every later pull from changing it. + +A package merge counts as an owner correction only where the person +resolved a conflict. `merge_in` in `src/package/restore.rs` copies the +package's revisions with their own bases, so a record merged without a +conflict keeps its import revisions as imports. `resolve_in` writes a +conflict the person resolved as a new revision with basis +`package_merge` and the athlete as actor. That is the person's choice, +so the rule keeps it as it keeps an edit. The counts name it accurately: +`merge_choices_replaced` is the part of `owner_corrections_replaced` that +were merge choices, and the line adds `(M of them merge choices)`. + +Body-snapshot records rarely keep a correction. The server averages +heart rate and HRV over a window that ends at the request, and the body +records' match keys have no date, so the snapshot almost always differs +from the last pull. The count shows each replacement. Each provider's line counts originals as new, changed, and unchanged. It -counts owner corrections replaced, details by outcome, objects left out -by reason, and withheld values. +counts owner corrections replaced, with the merge choices among them, +details by outcome, objects left out by reason, and withheld values. Vendor originals have a total size bound, `MAX_VENDOR_ORIGINAL_BYTES`. It is half of the 512 MiB package read cap, 256 MiB, counted in the bytes @@ -1455,6 +1479,12 @@ Rejected alternatives: pull. The maintainer can narrow it before approval. - Use the rule on every mapped route. Not chosen for this release. Other routes import a file the person chose, and D182 stays their rule. +- Treat a `package_merge` revision as an import. Rejected. It is a + conflict the person resolved, and a pull of changed data would replace + that choice with no count. +- Count merge choices only as owner corrections. Rejected. The line would + name an edit the person never made, so the counts name merge choices + as their own part. ## D243. A live vendor read is opt-in, and one failure stays on that provider @@ -1470,9 +1500,10 @@ procedure. `--vendor-workouts` is off unless the person passes it. Off, preview and `--json` call neither the connections route nor a live workout route. On, a preview reads the connections list and each active provider's list, -and it makes no detail call. Every vendor count it prints, and both -owner-correction counts, are labeled `estimated`, in the text and in -`--json`. The count of ids `--yes` would detail is `would_detail`. The +and it makes no detail call. Every vendor count it prints, and the +owner-correction and merge-choice counts, are labeled `estimated`, in +the text and in `--json`. The count of ids `--yes` would detail is +`would_detail`. The preview says that it made no detail calls, so detail failures, size limits, and refusals are only known after `--yes`. The preview writes nothing in this database and prints `vendor requests were made`. diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index 4fb9cbde..5384ec31 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -69,7 +69,8 @@ committed result is the text of `--yes` without `--json`. A writing JSON report would be a different choice. It is not this proposal. Preview text, and every `--json` result, labels counts `estimated`. That -includes every vendor count and both owner-correction counts in section 2. +includes every vendor count, and the owner-correction and merge-choice +counts, in section 2. Each page is previewed against the database as it was before this command. A preview writes nothing. A match key that appears on two pages, or a server that changes between the preview and `--yes`, can make the estimate differ from the @@ -207,6 +208,7 @@ the text. The object has no key, server, user id, or request path. "left_out": { "total": 0, "by_reason": {}, "examples": [], "shortened": false }, "withheld": { "total": 0, "paths": [], "shortened": false }, "estimated_owner_corrections_replaced": 0, + "estimated_merge_choices_replaced": 0, "vendor_workouts": { "requested": false, "requests_made": false, @@ -225,6 +227,7 @@ the text. The object has no key, server, user id, or request path. "limit": "not requested", "estimated": { "owner_corrections_replaced": 0, + "merge_choices_replaced": 0, "details": { "would_detail": 0, "kept": 0, @@ -261,14 +264,19 @@ The top-level `estimated_owner_corrections_replaced` counts owner corrections of stored records that the stored pages would replace, by the owner-correction rule in section 2. Each provider's `estimated.owner_corrections_replaced` counts its vendor originals. Both -are estimates, and their keys say so. When a provider's count is above -zero, the preview prints `estimated: would replace N owner corrections; -delete an original to keep it` on that provider's line. When the top-level -count is above zero, it prints `estimated: would replace N owner -corrections of stored records because the server's data changed`. After -`--yes` the same lines say `replaced N owner corrections`, without -`estimated`, and that each correction stays in the record's history. The -text uses the singular when N is 1. +are estimates, and their keys say so. Beside each, +`estimated_merge_choices_replaced` and `estimated.merge_choices_replaced` +count the part of it that were merge choices. A merge choice is a +conflict the person resolved in a package merge, as section 2 says. When +a provider's count is above zero, the preview prints `estimated: would +replace N owner corrections; delete an original to keep it` on that +provider's line. When the top-level count is above zero, it prints +`estimated: would replace N owner corrections of stored records because +the server's data changed`. When some were merge choices, each line adds +`(M of them merge choices)` after `owner corrections`. After `--yes` the +same lines say `replaced N owner corrections`, without `estimated`, and +that each correction stays in the record's history. The text uses the +singular when N or M is 1. Every vendor count in a preview is under an `estimated` key: `vendor_workouts.estimated.originals`, and each provider's `estimated` @@ -288,8 +296,9 @@ outcome. A preview does not say a snapshot was stored. The command returns a different outcome for `--yes` without `--json`. That outcome has the actual `committed` counts, the actual `archive_committed` -counts, the actual `owner_corrections_replaced` counts, the actual -vendor counts with `stored` in place of `would_detail`, +counts, the actual `owner_corrections_replaced` and +`merge_choices_replaced` counts, the actual vendor counts with `stored` +in place of `would_detail`, `database_changed`, `protected_write`, `archive`, `range_complete`, and `snapshots_complete`. `committed` counts protected records only. `archive_committed` counts archive records only, including @@ -861,16 +870,24 @@ of that page. An owner correction is kept until the server's data changes. This rule is new in 2.2.0. It covers every record on route `open_wearables`, from a pull or from `ath import --mapping open-wearables`. Every other route -keeps D182 as it is. An import writes each revision with basis +keeps D182 as it is. That scope is the plan's default, and the maintainer +still has to confirm it (section 10). An import writes each revision with basis `provider_import`. The basis is the revision column `record_revisions.became_known_at_basis`, which says how that revision became known. The rule reads that column, not `changed_by`. An import's `changed_by` is the tool actor `ath`. `ath grade` writes that same actor when it corrects a link, with basis `local_write`, in `src/prediction/grade.rs`. So `changed_by` cannot tell an import from -another write. A revision with any other basis is an owner -correction here: `ath correct`, a protocol write, and an accepted package merge write -other bases. A native restore copies each revision's basis, so a restored +another write. A revision with any other basis is an owner correction +here. `ath correct` writes basis `local_write`, and a protocol write uses +the basis its caller gives. A package merge copies the package's +revisions with their own bases, in `merge_in` in +`src/package/restore.rs`. So a record merged without a conflict keeps its +import revisions as imports. Only a conflict the person resolved in the +merge writes a new revision, in `resolve_in`, with basis `package_merge` +and the athlete as actor. That revision is a merge choice. It counts as +an owner correction, and the counts in section 1 also name it as a merge +choice. A native restore copies each revision's basis, so a restored database keeps the same answer. When a page's candidate names a stored record by its import key, and that record is not deleted: @@ -882,9 +899,18 @@ record by its import key, and that record is not deleted: Equal means the server has not changed that record since an import last wrote it. Nothing is written, and the correction stays current. Different means the server's data changed. The candidate replaces the - correction, and that counts as one `owner_corrections_replaced`. The - correction stays in the record's history. A record with no - `provider_import` revision is replaced and counted the same way. + correction, and that counts as one `owner_corrections_replaced`. When + the correction was a merge choice, it also counts as one + `merge_choices_replaced`. The correction stays in the record's + history. A record with no `provider_import` revision is replaced and + counted the same way. + +Body-snapshot records rarely keep a correction. The server averages heart +rate and HRV over a window that ends at the request, 7 days and 4 hours +by default, and the body records' match keys have no date. So the +snapshot almost always differs from the last pull. A correction of the +snapshot's original, or of a value the server averages, is replaced on +almost every pull, and the count shows it. The comparison is the 2.1.1 comparison, with the compared revision's `received_at`. Section 4 withholds credential values before the candidate @@ -1578,6 +1604,8 @@ preview they are estimates under `estimated`, as section 1 says. - `owner_corrections_replaced`: owner corrections that this page replaces, by the owner-correction rule above. Each is also counted as a changed original. +- `merge_choices_replaced`: the part of `owner_corrections_replaced` + that were merge choices. - `details`: `stored`, which a preview calls `would_detail`, `kept`, `deferred`, `failed`, `mismatch`, `thinner`, `not_available`, `too_large`, and `refused`. @@ -2720,10 +2748,19 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: test reads the basis from `record_revisions.became_known_at_basis`. A revision whose `changed_by` is the tool actor `ath` and whose basis is `local_write` counts as an owner correction -- a record whose current revision came from an accepted package merge is - an owner correction. A native export and restore keeps every revision's - basis, so the same pull reports the same counts before and after the - restore +- a package merge of two sleep sessions. The first had no conflict, and + its merged revision keeps basis `provider_import`, so a pull whose + session changed replaces it with no owner-correction count. The person + resolved a conflict on the second, so its current revision has basis + `package_merge`. A pull whose session changed replaces it, and both + `estimated_owner_corrections_replaced` and + `estimated_merge_choices_replaced` are 1. The preview line adds `(1 of + them a merge choice)`. A native export and restore keeps every + revision's basis, so the same pull reports the same counts before and + after the restore +- a body snapshot whose owner corrected its original, pulled again after + the server's averaging window moved, replaces the correction and counts + 1 `estimated_owner_corrections_replaced` - without `--vendor-workouts`, preview and `--json` make zero requests to the connections route and to both workout routes. `requests_made` is false, `notice` is empty, and every live line is `not_attempted`. With @@ -2739,8 +2776,9 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: twice. A Strava preview then `--yes` sends two list calls and at most 20 detail calls - `--vendor-workouts --json` with three new Polar ids writes nothing, and - the fixture server sees no detail request. Every vendor count and both - owner-correction counts are under a key named `estimated`. Polar's + the fixture server sees no detail request. Every vendor count, and the + owner-correction and merge-choice counts, are under a key named + `estimated`. Polar's `would_detail` is 3, and no key that means stored is above zero. `notice` holds the line that the preview made no detail calls. The text preview prints that line, and its Polar line contains `estimated`. @@ -2925,10 +2963,12 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: and makes the provider `incomplete`. In every vendor test, each listed object is in exactly one detail count or one left-out count - `--json` includes `vendor_workouts.requested`, `requests_made`, - `notice`, `estimated.originals`, and each provider's `status`, - `connection_status`, `covers_requested_range`, `more`, `limit`, and - `estimated` with `owner_corrections_replaced`, `details`, and - `left_out` + `notice`, `used_bytes`, `bound_bytes`, `estimated.originals`, and each + provider's `status`, `connection_status`, `covers_requested_range`, + `more`, `limit`, and `estimated` with `owner_corrections_replaced`, + `merge_choices_replaced`, `details`, and `left_out`. The top level has + `estimated_owner_corrections_replaced` and + `estimated_merge_choices_replaced` Migration tests, in the build gate: @@ -3135,6 +3175,11 @@ Risks: the record stops later pulls from changing it, and it also takes the record out of current data. This rule covers every record on route `open_wearables`, not only vendor originals. Other routes keep D182. + That scope is the stated default, and the maintainer still has to + confirm it. A conflict the person resolved in a package merge counts as + an owner correction, and the counts name it as a merge choice. A + body-snapshot correction rarely survives, because the server's + averaging window moves with every request. - A deferred id that the provider stops listing is never detailed. Its list object stays stored, and the deferred count shows that it waits. - Vendor originals share the main package document and its 512 MiB read From 57838e1c5702f9d5dc57068d2525e2536ed6fa56 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 06:56:46 +0000 Subject: [PATCH 52/60] Record the pass after the reviews at 3c3f660 Step 0 now says which decisions this pass amends, that it adds no decision number, and which three questions stay open for the maintainer. Co-authored-by: Michael Whitham --- build-history/v2.2.0/progress.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-history/v2.2.0/progress.md b/build-history/v2.2.0/progress.md index 0ee2414f..85a4d2d0 100644 --- a/build-history/v2.2.0/progress.md +++ b/build-history/v2.2.0/progress.md @@ -5,7 +5,7 @@ program, the record, or the database has changed for 2.2.0. | Step | What | Status | |---|---|---| -| 0 | The plan: proposals D227–D244, and the Open Wearables study. The proposals were D198–D215 until 2.1.1 used D208–D226. Checked against 2.1.1 at `0de71bb` on 15 November 2026: a page is one import preview and one apply, and D237 uses the revision check. D239 through D241 stay. D242 and D243 answer the review at `e145fa6`. D244 withholds a credential-shaped value. The pass after the review at `d636d7a` amends D227, D230, D231, D236, D242, D243, and D244. Still not adopted. The new head needs a fresh four-role review | written, not approved | +| 0 | The plan: proposals D227–D244, and the Open Wearables study. The proposals were D198–D215 until 2.1.1 used D208–D226. Checked against 2.1.1 at `0de71bb` on 15 November 2026: a page is one import preview and one apply, and D237 uses the revision check. D239 through D241 stay. D242 and D243 answer the review at `e145fa6`. D244 withholds a credential-shaped value. The pass after the review at `d636d7a` amends D227, D230, D231, D236, D242, D243, and D244. The pass after the reviews at `3c3f660` amends D228, D230, D231, D242, and D243 and adds no decision number. Three questions stay open for the maintainer, in section 10 of the specification: the Garmin detail default, the owner-correction scope, and storing vendor originals in their own files. Still not adopted. The new head needs a fresh review | written, not approved | | 1 | Version 2.2.0 and migration step 6. Step 5 is the published 2.1.1 migration. No new column on an existing table. The root check gains `source_report` by the copy in D236. Summary and score values may be omitted in pairs (D227, D236) | not started | | 2 | `ath pull openwearables` in the `athleticstandard` crate, with the rewritten mapping (D228, D230, D236) | not started | | 3 | Key, server, and user id kept out of the record (D229) | not started | From 0b04d70a49abba1f720981427a415e70156c4dc2 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 07:14:15 +0000 Subject: [PATCH 53/60] Plan 2.2.0: put Garmin windows on a fixed UTC grid and count other overlaps as ambiguous Each Garmin window starts at a multiple of 82,800 seconds from the epoch, and the first and last are widened to whole grid windows. Two commands then send equal windows or windows that do not overlap. A pull's new read of the stored window is a change. Any other overlap, which only a saved file can carry, keeps the stored copy and counts ambiguous_window. Adds the two-range fixture, the 12-hour --from test, and the saved-envelope test. Co-authored-by: Michael Whitham --- .../v2.2.0/appendix/open-wearables-api.md | 7 +- build-history/v2.2.0/decisions.md | 64 +++++++-- build-history/v2.2.0/spec.md | 126 +++++++++++++----- 3 files changed, 147 insertions(+), 50 deletions(-) diff --git a/build-history/v2.2.0/appendix/open-wearables-api.md b/build-history/v2.2.0/appendix/open-wearables-api.md index afcd23c1..20c46a87 100644 --- a/build-history/v2.2.0/appendix/open-wearables-api.md +++ b/build-history/v2.2.0/appendix/open-wearables-api.md @@ -593,8 +593,11 @@ is at most 24 local hours where the clock moves by one hour. In is 25 local hours. Those numbers come from Python's `datetime.fromtimestamp` with `TZ` set to `America/Chicago` and to `Antarctica/Troll`, run on 15 November 2026 across the 2026 changes. -So this plan sends windows of 82,800 seconds, 23 hours, or less. A -one-year range is 381 windows. Detail calls +So this plan sends windows of exactly 82,800 seconds, 23 hours, on a +fixed grid that starts at the Unix epoch. A one-year range is 381 or 382 +windows. A window of 24 local hours or less is sent to Garmin as +`uploadStartTimeInSeconds` and `uploadEndTimeInSeconds` with both +integers unchanged, so the grid reaches Garmin as sent. Detail calls `/wellness-api/rest/activities/{activity_id}`. This study did not find that path in Garmin's public docs. `ActivityJSON` types `activityId` as an integer or a string. The Garmin wellness models declare an optional diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index 84c4e309..698d3cfa 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -202,6 +202,20 @@ number is added: covers every record the `open_wearables` pull writes, and other routes keep D182. The maintainer still has to confirm that scope. +## Changes after the reviews at `57838e1` + +These edits answer the reviews of this plan at `57838e1`. No decision +number is added: + +- D243. Garmin windows sit on a fixed grid. Each starts at a multiple of + 82,800 seconds after the Unix epoch, and the first and last windows are + widened to whole grid windows. So two commands send equal windows or + windows that do not overlap, and the earlier-window test always + applies to a pull. A pull's new read of the stored window is a change. + Any other overlap, which only a saved file can carry, counts as + `ambiguous_window`. The stored copy is kept, and no owner correction + is replaced. + ## D227. Version 2.2.0 is one manual pull, and the program and the record share that number `ath pull openwearables` reads the stored representations D232 lists from an @@ -1534,10 +1548,19 @@ call could make the server try a refresh or a revoke. The order is Garmin, Polar, Suunto, Whoop, Fitbit, Oura, Strava, Withings, Sensorbio. One failure leaves that line `incomplete`. The others still run. -Garmin is split by this program into windows of 82,800 seconds, 23 -hours, or less, one call each. Each window sends integer Unix seconds. -The pinned server splits a window it sees as longer than 24 hours and -drops a failed piece without saying so. It measures in naive local time. +Garmin is read by this program in windows on a fixed grid, one call +each. Each window starts at a multiple of 82,800 seconds, 23 hours, +after the Unix epoch, and lasts 82,800 seconds. The first and last +windows are the grid windows that hold the range's first and last +seconds, so they can reach up to 23 hours past the range. Every command +uses the same grid, so windows from two commands are equal or do not +overlap. Windows that started at `--from`, as the earlier text had them, +overlapped only partly when two commands had different ranges. Each +window sends integer Unix seconds. The pinned server passes a window it +does not split to Garmin unchanged, so a grid window still reaches Garmin +as one 23-hour read. The pinned server splits a window it sees as longer +than 24 hours and drops a failed piece without saying so. It measures in +naive local time. When the server's clock moves forward an hour, 24 real hours read as 25 local hours, and the server would split the window. When the clock moves back, they read as 23. A 23-hour window reads as 24 at most where the @@ -1624,11 +1647,20 @@ different objects with one id are both refused. Each Garmin envelope keeps its `upload_window`, so the rule also holds across commands. A copy from a window that ends at or before the start of the stored copy's window was uploaded first. It is `superseded`, it writes nothing, and it -is not a server change, so it replaces no owner correction. Comparisons -leave `upload_window` out, because windows depend on `--from`. The start becomes `input_timestamp` by the -rules in the specification: text keeps its offset or says it has none, -and Unix seconds or milliseconds keep their digits. The start is stored -and is not a filter. +is not a server change, so it replaces no owner correction. A copy from a +window that starts at or after the stored window's end was uploaded +later, and a pull's new read of the stored window is a later read. Both +are changes. Any other pair of windows overlaps, or is equal in a mapped +import of saved envelopes, whose read time is unknown. Then the order of +the copies is unknown. The candidate counts as `ambiguous_window`, the +stored copy is kept, nothing is written, and no owner correction is +replaced. The grid means a pull never makes such a pair, but a saved +file can carry any window. Comparisons leave `upload_window` out, because +Garmin can return an unchanged object in a later window. + +The start becomes `input_timestamp` by the rules in the specification: +text keeps its offset or says it has none, and Unix seconds or +milliseconds keep their digits. The start is stored and is not a filter. A vendor object with a `__proto__` key at any depth is refused alone as `unusable_name`, and the provider stays `completed`. The import check @@ -1707,9 +1739,17 @@ Rejected alternatives: did. Rejected. A later command that reads only an earlier window would store the older copy again, and it would count that as a server change that replaces an owner correction. -- Count a different `upload_window` as a change. Rejected. Windows depend - on `--from`, so every pull with another range would revise every Garmin - original. +- Count a different `upload_window` as a change. Rejected. Garmin can + return an unchanged object in a later window, and that would revise an + original the vendor did not change. +- Start the windows at `--from`, as the earlier text did. Rejected. Two + commands with different ranges then send windows that overlap only + partly, and the earlier-window test cannot order the copies. A command + that read the older copy would replace the newer one and an owner + correction with it. +- Treat a partly overlapping window as a change. Rejected. Which copy is + newer is unknown, and a change would replace an owner correction with + what may be the older copy. - Drop an original whose start is outside the requested range. Rejected. The live methods do not filter by workout start, so a drop would hide a returned object. diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index 5384ec31..ad90efd9 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -1138,9 +1138,9 @@ Budgets keep one command inside the providers' limits: - The pace above keeps this command at 60 live requests a minute or fewer. The review cited about 100 a minute for Garmin. This study did not find that number in Garmin's public docs. -- Garmin is read in windows of 82,800 seconds, 23 hours, or less, one - call each. Every window is sent. A one-year range is 381 windows, so it - takes more than six minutes before any detail call. +- Garmin is read in windows of exactly 82,800 seconds, 23 hours, one + call each. Every window is sent. A one-year range is 381 or 382 + windows, so it takes more than six minutes before any detail call. - A command makes at most 100 detail calls to one provider, and at most 20 to Strava. Ids past the budget are `deferred`. The next paragraphs say which ids go first. @@ -1178,13 +1178,22 @@ timeout above. | Withings | the JSON array. The method reads `series` | `id` | `startdate`, Unix seconds | no detail call | none | none | 1 list | 360 s | | Sensorbio | `data[].activities[]`. The parent is kept as `list_parent` | `id` on the nested activity | `start_time`, Unix milliseconds | no detail call | none | none | 1 list | 360 s | -- Garmin. The pull splits the range into windows and sends - `summary_start_time` and `summary_end_time` as integer Unix seconds. The - server puts those values in `uploadStartTimeInSeconds` and +- Garmin. The pull reads the range in windows on a fixed grid. Each + window starts at a multiple of 82,800 seconds after the Unix epoch and + lasts 82,800 seconds. The first window holds the range's first second, + and the last window holds its last second. So the first can start up + to 23 hours early, and the last can end up to 23 hours late. Every + command uses the same grid, so a window from one command either equals + a window from another or does not overlap it. The pull + sends `summary_start_time` and `summary_end_time` as integer Unix + seconds. The server puts those values in `uploadStartTimeInSeconds` and `uploadEndTimeInSeconds`, so a window selects by upload time, not by - start. Each window ends where the next begins. The pinned server splits - a window it sees as longer than 24 hours, and it drops a failed piece - without saying so. It measures the window in naive local time. When the + start. Each window ends where the next begins. The last window can end + after the command runs, as a date `--to` of today already does. The + pinned server sends a window it does not split to Garmin with both + numbers unchanged, so Garmin gets the grid as sent. It splits a window + it sees as longer than 24 hours, and it drops a failed piece without + saying so. It measures the window in naive local time. When the server's clock moves forward an hour, as in spring, 24 real hours read as 25 local hours, so a 24-hour window would be split. When the clock moves back, as in autumn, 24 real hours read as 23. A 23-hour window @@ -1274,8 +1283,9 @@ parameters are numbers. A date `--from` is midnight UTC that day. A date `--to` ends at midnight UTC after that day. That is the rule the Open Wearables API introduction gives for a date-only bound. A timestamp bound converts exactly. A fraction of a second rounds down for the start and up -for the end, so the windows cover the whole range. The stored reads still -send `--from` and `--to` unchanged. +for the end, so the windows cover the whole range. Garmin then widens the +range to whole grid windows, as the Garmin row above says. The stored +reads still send `--from` and `--to` unchanged. A vendor id is text. A JSON string is used as it is, unless it is empty. A JSON integer is written in decimal. So `123` and `"123"` are one id and @@ -1312,22 +1322,36 @@ still refuse both as `duplicate_id`. Each Garmin envelope keeps the window its object came from, as `upload_window`, so the same rule holds across commands. Take a Garmin candidate that differs from the newest `provider_import` revision of its -original. When its window ends at or before the start of that revision's -window, the candidate is the older copy. A window holds only objects -uploaded inside it, so that copy was uploaded first. It counts as -`superseded`, and nothing is written. The stored-original read returns -the stored window, so the pull makes no detail call for it. It is not a -server change, so it never replaces an owner correction. When either side -has no `upload_window`, this rule does not apply. The rule runs in -matching for route `open_wearables`, so a mapped import of saved -envelopes follows it too. +original, when both have an `upload_window`. A window holds only objects +uploaded inside it, so the windows order the two copies: + +- The candidate's window ends at or before the start of the stored + window. The candidate was uploaded first. It counts as `superseded`, + and nothing is written. +- The candidate's window starts at or after the end of the stored window. + The candidate was uploaded later, and it is a change. +- A pull reads the stored window again. The candidate is a later read of + the same window, and it is a change. +- Any other pair of windows. They overlap, or they are equal in a mapped + import of saved envelopes, whose read time is unknown. The pull's grid + never makes such a pair, but a saved file can carry any window. The + order of the two copies is unknown. The candidate counts as + `ambiguous_window`, the stored copy is kept, and nothing is written. + +A `superseded` or `ambiguous_window` candidate is not a server change, so +it never replaces an owner correction. The stored-original read returns +the stored window, so the pull makes no detail call for that candidate. +When either side has no `upload_window`, this rule does not apply. The +rule runs in matching for route `open_wearables`, so a mapped import of +saved envelopes follows it too. Every comparison of a vendor original on that route leaves `upload_window` out: the 2.1.1 equality test, the owner-correction rule, -and the difference test above. The windows depend on `--from`, so an -unchanged object read through another window writes nothing. The stored -original keeps the window it was stored with, and that window still -holds its upload. +and the difference test above. Garmin can return an unchanged object in a +later window, and a saved file can carry any window. So an unchanged +object read through another window writes nothing. The stored original +keeps the window it was stored with, and that window still holds its +upload. The start column names one field and how to read it: @@ -1391,7 +1415,8 @@ list object is not seen, and the line does not claim it. A list object and its detail are not read at the same moment. The pull reads a provider's whole list first, then its details one second apart, so a detail can come minutes after its list object. A one-year Garmin -range sends 381 windows, more than six minutes, before its first detail. +range sends 381 or 382 windows, more than six minutes, before its first +detail. The vendor can change the workout in between. A `kept` detail was read by an earlier command. The envelope does not record when each part was read, and the pull does not claim the two parts are one moment's copy. @@ -1465,8 +1490,8 @@ the same object: when `start` is. - `list` is the list object. `list_parent` is present only for Sensorbio. - `upload_window` is present only for Garmin. It holds `start` and `end`, - the integer Unix seconds of the window the list object came from, such - as `{ "start": 1767225600, "end": 1767308400 }`. + the integer Unix seconds of the grid window the list object came from, + such as `{ "start": 1767200400, "end": 1767283200 }`. - `detail` is the detail object after the table's detail unwrap. It is absent when no detail is stored. - `detail_status` is `stored`, `deferred`, `failed`, `mismatch`, @@ -1611,8 +1636,8 @@ preview they are estimates under `estimated`, as section 1 says. `too_large`, and `refused`. - `left_out`: objects not written, by reason: `missing_id`, `unusable_id`, `unsafe_number`, `unusable_name`, `duplicate_id`, - `superseded`, `deleted_record`, `deleted_source`, `response_refused`, - and `size_cap`. + `superseded`, `ambiguous_window`, `deleted_record`, `deleted_source`, + `response_refused`, and `size_cap`. - `withheld`: values that section 4 withheld, with up to 20 paths. Each listed object is in exactly one detail count or one left-out count. @@ -2856,13 +2881,42 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: When the person had corrected that original, the correction stays current, and `owner_corrections_replaced` is 0. In the other order, the second command's later copy replaces the stored earlier copy as a - change. A third command with a different `--from` reads the unchanged - 1860 copy through a different window and writes nothing -- a three-day Garmin range sends four windows, three of 82,800 seconds and - one of 10,800 seconds. Each window sends `summary_start_time` and - `summary_end_time` as integer Unix seconds, and each starts where the - last one ended. A date `--from` starts at midnight UTC. One failed - window makes Garmin `incomplete` and never `completed`. A later window + change. A third command reads the unchanged 1860 copy through a later + window, as when Garmin received it again, and writes nothing +- a Garmin fixture with two ranges one day apart. Activity 557 was + uploaded at 22:30 UTC on 16 January 2026, and again with a different + `durationInSeconds` at 06:00 UTC on 17 January. The first command, + `--from 2026-01-16 --to 2026-01-17`, sends four windows, from 02:00 UTC + on 15 January to 22:00 UTC on 18 January. It stores the 06:00 copy with + the window from 00:00 to 23:00 UTC on 17 January, and it counts the + 22:30 copy `superseded`. The person then corrects that original. The + second command, `--from 2026-01-15 --to 2026-01-16`, sends three + windows, from 03:00 UTC on 14 January to 00:00 UTC on 17 January. Its + last window returns the 22:30 copy and ends where the stored window + starts. That copy counts 1 `superseded` and gets no detail call. + Nothing is written, and `owner_corrections_replaced` is 0 +- two Garmin commands whose `--from` timestamps are 12 hours apart, + `2026-01-16T00:00:00Z` and `2026-01-16T12:00:00Z`, each for two days. + Each window both commands send has the same `summary_start_time` and + `summary_end_time` in both, and each is a multiple of 82,800. The + second command gets activity 558 with a different object in one of + those windows. Its copy is a later read of the same window, so it + replaces the stored copy as a change. When an owner correction was + current, it is replaced, and `owner_corrections_replaced` is 1 +- a mapped import of a saved Garmin envelope with a different object, + whose `upload_window` overlaps the stored copy's window without being + equal. It counts 1 `ambiguous_window`, writes nothing, and keeps the + stored copy and any owner correction, so `owner_corrections_replaced` + is 0. A saved envelope with a different object and the stored window + counts the same way +- a three-day Garmin range, `--from 2026-01-01 --to 2026-01-03`, sends + four windows of 82,800 seconds. The first starts at 1767200400, 17:00 + UTC on 31 December 2025, and the last ends at 13:00 UTC on 4 January. + Each window sends `summary_start_time` and `summary_end_time` as + integer Unix seconds. Each start is a multiple of 82,800, and each + window starts where the last one ended. A date `--from` starts at + midnight UTC. One failed window makes Garmin `incomplete` and never + `completed`. A later window still runs - three Garmin ids are due a detail call, and the first detail call answers HTTP 404. The fixture server sees no second Garmin detail From 250c1f7c4740f61323191bb9234eeb40a68c400b Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 07:21:58 +0000 Subject: [PATCH 54/60] Plan 2.2.0: only 404 and 501 on the Garmin probe mark an id not_available, and recheck after 30 days Any other error status on the probe, except 401 and 429, defers every due id, and the next command probes again. A 5xx also makes Garmin incomplete. An id that got 404 or 501 keeps the answer time as detail_checked_at and is asked again after 30 days, or sooner when its list object changes. Ids a command does not ask keep their mark, so a missing path does not rewrite them. Adds the 403/503 probe test and the 30-day recheck test. Co-authored-by: Michael Whitham --- build-history/v2.2.0/decisions.md | 62 ++++++++++---- build-history/v2.2.0/spec.md | 135 +++++++++++++++++++++--------- 2 files changed, 143 insertions(+), 54 deletions(-) diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index 698d3cfa..64d646c5 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -215,6 +215,13 @@ number is added: Any other overlap, which only a saved file can carry, counts as `ambiguous_window`. The stored copy is kept, and no owner correction is replaced. +- D243. Only a 404 or 501 on the Garmin probe marks the probed id + `not_available`. Any other error status, except 401 and 429, defers + every due id, and the next command probes again. A 5xx also makes + Garmin `incomplete`. An id that got 404 or 501 keeps the time as + `detail_checked_at` and is asked again after 30 days, or sooner when its + list object changes. An original with a current owner correction is + asked again only when its list object changes. ## D227. Version 2.2.0 is one manual pull, and the program and the record share that number @@ -1345,7 +1352,8 @@ Each original is one envelope. It holds `provider`, `vendor_id` as text, `start` and `start_kind` when the object has a start, `list`, `detail` when a detail is stored, and `detail_status`. Sensorbio adds `list_parent`. Garmin adds `upload_window`, the window its object came -from. The specification's section 2 shows the JSON. The whole +from, and `detail_checked_at` when a detail call answered 404 or 501. +The specification's section 2 shows the JSON. The whole envelope is kept in `supplied_fields`, and `provider_record_id` is `vendor_id`. The match key is the writer, the sensor, the resource `vendor_workout`, the provider, and the vendor id, escaped by D181. @@ -1569,17 +1577,32 @@ clock moves by one hour. A zone that moves it by two hours, such as `incomplete`. The pull keeps calling Garmin detail at the pinned path, `/wellness-api/rest/activities/{activity_id}`. That path is not in Garmin's public docs, and this study did not find it there. The first -Garmin detail call in a command is a probe. When it answers HTTP 400, -403, 404, 405, or 501, the pull makes no other Garmin detail call in that -command. The probed id is `not_available`, each other id still due a call -is `deferred`, every list object is stored, and Garmin stays -`completed`. The line says `Garmin detail unavailable (HTTP n); list -objects stored`. After any other answer to the probe, the calls go on, -and a later 404 or 501 is `not_available` for that id. Any other Garmin -detail error is `failed`. An id that was `not_available` is not called -again unless its list object changed. So a missing path costs one call -in a command, not the budget of 100. This is the stated default. The -maintainer still has to confirm it before approval. Polar's list omits samples, zones, and route, and detail +Garmin detail call in a command is a probe. When it answers HTTP 404 or +501, the pull makes no other Garmin detail call in that command. The +probed id is `not_available`, each other id still due a call is +`deferred`, every list object is stored, and Garmin stays `completed`. +The line says `Garmin detail unavailable (HTTP n); list objects stored`. +Any other error status on the probe, except 401 and 429, also stops the +Garmin detail calls, and every due id is `deferred`, the probed id +included. A 400, 403, or 405 does not show that the activity has no +detail, so the next command probes that id again. Garmin stays +`completed` after a 4xx status. It is `incomplete` after a 5xx status, +because the server reported a fault. After a 2xx answer to the probe, +the calls go on, and a later 404 or 501 is `not_available` for that id. +Any other Garmin detail error is `failed`. + +An id that got 404 or 501 keeps the time of that answer as +`detail_checked_at`. It is asked again when its list object changes, or +30 days after that time, after every other due id. A repeat answer writes +the new time. An id a command does not ask keeps `not_available` and its +time, so a missing path does not rewrite those originals. An original +with a current owner correction is asked again only when its list object +changes, because a repeat answer would not be written over the +correction. So a missing path costs one call in a command, not the +budget of 100. This is the stated default. The maintainer still has to +confirm it before approval. + +Polar's list omits samples, zones, and route, and detail asks for all three. Suunto's detail is called at `workoutKey`. A list object with no `workoutKey` gets no detail call and is `not_available`, because nothing this study read shows that Suunto's detail accepts a @@ -1591,8 +1614,8 @@ next page `next_token`. The request name, `nextToken`, is not sent. Sensorbio reads only the oldest 50 entries, and its line says so. A stored detail is never lost. A detail is fetched for an id with no -stored detail, unless an earlier command marked it `not_available`, and -again only when the list object changed. Credential +stored detail, unless an earlier command marked it `not_available` less +than 30 days before, and again only when the list object changed. Credential values (D244) are withheld before any comparison, so a token that changed between pulls does not make a list object look changed. A list-only object never replaces a stored detail. A new detail that is thinner than @@ -1702,6 +1725,17 @@ Rejected alternatives: - Mark every id the probe stopped as `not_available`. Rejected. Those ids were not asked. A 404 can mean one missing activity, and the mark would stop their details until their list objects changed. +- Mark the probed id `not_available` after a 400, 403, or 405, as the + earlier text did. Rejected. Those statuses do not show that the + activity has no detail. A permission not yet granted would leave that + workout list-only until its list object changed. +- Ask a `not_available` id again only when its list object changes, as + the earlier text did. Rejected. Where the path works, one passing 404 + would leave that workout list-only for good. +- Ask a `not_available` id again on every command. Rejected. Each + activity with no detail would spend a call on every command. +- Keep the recheck time outside the envelope. Rejected. A restore would + lose it, and the export would not hold all of the record's state. - Treat a 401 on the probe as a missing path. Rejected. A 401 is what an expired or revoked grant answers, so the person may need to reconnect Garmin. Its line must not say only that detail is unavailable. diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index ad90efd9..f7a738c6 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -1124,7 +1124,8 @@ provider in this command. The detail call that got 429 or 401, or that timed out, counts as `failed`. Every id still due a detail call by the order below counts as `deferred`, and a later command details it. An id that was due no call keeps its own count, such as `kept` or -`not_available`. What the provider already returned is still written as +`not_available`, and so does a Garmin id due only for its 30-day recheck. +What the provider already returned is still written as that provider's page: the list objects, and the details already fetched. A later Garmin window after a 429, a 401, or a timeout is not sent, unlike a window that failed @@ -1206,14 +1207,24 @@ timeout above. `/wellness-api/rest/activities/{activity_id}`. That path is not in Garmin's public docs. This study looked and did not find it, so the path may not exist. The first Garmin detail call in a command is a probe. - When it answers HTTP 400, 403, 404, 405, or 501, the pull makes no other - Garmin detail call in that command. The probed id counts as - `not_available`. Each other id still due a detail call counts as - `deferred`, because it was not asked. Every list object is stored, - Garmin stays `completed`, and its line says `Garmin detail unavailable - (HTTP n); list objects stored`, with the status the probe got. So a - missing path costs one detail call in a command. After any other answer - to the probe, the later Garmin detail calls go on. A later Garmin detail + When it answers HTTP 404 or 501, the pull makes no other Garmin detail + call in that command. The probed id counts as `not_available`. Each + other id still due a detail call counts as `deferred`, because it was + not asked. An id due only for its 30-day recheck keeps `not_available` + instead, as the detail order below says. Every list object is stored, + Garmin stays `completed`, and + its line says `Garmin detail unavailable (HTTP n); list objects + stored`, with the status the probe got. So a missing path costs one + detail call in a command. When the probe answers any other error + status, except 401 and 429, the pull also makes no other Garmin detail + call, and the line is the same. Every id due a call counts as + `deferred`, the probed id included, except an id due only for its + 30-day recheck. A status such as 400, 403, or 405 + does not show that the activity has no detail, so the next command + probes the same oldest id again. After a 4xx status Garmin stays + `completed`. After a 5xx status Garmin is `incomplete`, and the exit is + nonzero, because the server reported a fault. After a 2xx answer to the + probe, the later Garmin detail calls go on. A later Garmin detail that answers 404 or 501 is `not_available` for that id, and the next id is still called. Any other failed Garmin detail is `failed`, and Garmin is `incomplete`. A 401, a 429, or a timeout stops Garmin as above. A 404 @@ -1351,7 +1362,10 @@ and the difference test above. Garmin can return an unchanged object in a later window, and a saved file can carry any window. So an unchanged object read through another window writes nothing. The stored original keeps the window it was stored with, and that window still holds its -upload. +upload. The owner-correction rule and the difference test also leave +`detail_checked_at` out, because only this program's clock changed it. +The 2.1.1 equality test keeps it, so a repeat 404 or 501 is written and +its 30 days start again. The start column names one field and how to read it: @@ -1399,18 +1413,34 @@ budget allows. It spends the budget in this order. First come ids with no stored detail that no earlier command marked `not_available`, `too_large`, or `refused`. Then come ids whose list object differs from the stored `list`. Then come ids an earlier command marked `too_large` or -`refused`. Each id goes in the first group it matches. So an id that was -`not_available`, `too_large`, or `refused` and whose list object changed -is in the second group. An id that an earlier command -marked `not_available`, and whose list object is unchanged, gets no -detail call. It counts as `not_available` again. Inside each group -the oldest start goes first. An id without a start instant goes last in -its group, in list order. So a Garmin path that answers 404 costs one -detail call in a command, and only when some id is due a call. An id -whose original holds a detail and whose list object is unchanged gets no detail call. A deleted -original gets no detail call. A detail is fetched again only when the list -object changed. A provider that changes a detail without changing the -list object is not seen, and the line does not claim it. +`refused`. Last come Garmin ids that a 404 or 501 marked `not_available` +at least 30 days before this command started, by their +`detail_checked_at`. An original whose current revision is an owner +correction is not in that last group, because a repeat answer would not +be written over the correction, and its time would never move. Each id +goes in the first group it matches. So an id that was `not_available`, +`too_large`, or `refused` and whose list object changed is in the second +group. Any other id marked `not_available` whose list object is unchanged +gets no detail call. It counts as `not_available` again. Inside each +group the oldest start goes first. An id without a start instant goes +last in its group, in list order. So a Garmin path that answers 404 +costs one detail call in a command, and only when some id is due a call. +An id whose original holds a detail and whose list object is unchanged +gets no detail call. A deleted original gets no detail call. A detail is +fetched again only when the list object changed. A provider that changes +a detail without changing the list object is not seen, and the line does +not claim it. + +A Garmin id that got 404 or 501 is asked again after 30 days, or sooner +when its list object changes. A repeat 404 or 501 writes the original +again with the new `detail_checked_at` and the stored `upload_window`. It +counts as `not_available` and as a changed original. An id in the last +group that this command does not ask, for any reason, keeps +`not_available` and its time. That covers a probe that stopped Garmin, a +401, 429, or timeout that stopped it, and a spent budget. The id does not +count as `deferred`, so a missing path does not rewrite those originals. +Any other `not_available` comes from a provider with no detail call or a +Suunto object with no `workoutKey`, so there is no call to make again. A list object and its detail are not read at the same moment. The pull reads a provider's whole list first, then its details one second apart, @@ -1446,9 +1476,9 @@ What is written for one id depends on what this command got: object alone. `detail_status` says why: `deferred`, `failed`, `mismatch`, `not_available`, `too_large`, or `refused`. The id counts under the same word. - `not_available` means the provider has no detail call, the Garmin probe - answered 400, 403, 404, 405, or 501 for that id, a later Garmin detail - answered 404 or 501, or a Suunto list object has no `workoutKey`. A + `not_available` means the provider has no detail call, a Garmin detail + call for that id answered 404 or 501, or a Suunto list object has no + `workoutKey`. A detail response over `MAX_PULL_RESPONSE_BYTES` is `too_large`, because the detail route has no smaller page. A detail that the privacy scan in section 4 refuses, because it holds the key, @@ -1496,6 +1526,9 @@ the same object: absent when no detail is stored. - `detail_status` is `stored`, `deferred`, `failed`, `mismatch`, `not_available`, `too_large`, or `refused`. +- `detail_checked_at` is present only when a Garmin detail answered 404 + or 501 and `detail_status` is `not_available`. It holds the integer Unix + seconds of that answer, by the pull's clock. - A value that section 4 withholds is replaced in place by its marker. Nothing else in `list`, `list_parent`, or `detail` is changed. @@ -1936,8 +1969,9 @@ besides the typed writes in section 6. It gains nothing beyond those: matching reads the newest revision of that record whose basis is `provider_import` and compares the candidate with it. The page's report counts each replaced correction. For a `vendor_workout` row, matching leaves - `upload_window` out of each comparison and applies the Garmin window - rule in section 2. + `upload_window` out of each comparison, leaves `detail_checked_at` out + of the owner-correction rule and the window test, and applies the + Garmin window rule in section 2. - In matching, for a page with `vendor_workout` rows, the size bound in section 2. It measures the stored vendor originals as export writes them, adds the page's new and changed envelopes, and refuses the page @@ -2920,17 +2954,34 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: still runs - three Garmin ids are due a detail call, and the first detail call answers HTTP 404. The fixture server sees no second Garmin detail - request. The first id is stored with `detail_status` `not_available`, - and the other two with `deferred`. Garmin is `completed`, its line says - `Garmin detail unavailable (HTTP 404); list objects stored`, and the - command exits 0. HTTP 400, 403, 405, and 501 do the same. On the next - command, the `not_available` id, whose list object is unchanged, gets - no call and counts as `not_available` again, and the probe is the older - of the two deferred ids. When the probe gets a detail, a later Garmin - detail that answers 404 is `not_available`, and the next id is still - called. A Garmin detail that answers HTTP 500 is `failed`, Garmin is - `incomplete`, and the exit is nonzero. A Polar detail that answers 404 - is `failed`. A Garmin list window that answers 404 fails that window + request. The first id is stored with `detail_status` `not_available` + and a `detail_checked_at` equal to the test clock, and the other two + with `deferred`. Garmin is `completed`, its line says `Garmin detail + unavailable (HTTP 404); list objects stored`, and the command exits 0. + HTTP 501 does the same. On the next command, the `not_available` id, + whose list object is unchanged, gets no call and counts as + `not_available` again, and the probe is the older of the two deferred + ids. When the probe gets a detail, a later Garmin detail that answers + 404 is `not_available`, and the next id is still called. A later Garmin + detail that answers HTTP 500 is `failed`, Garmin is `incomplete`, and + the exit is nonzero. A Polar detail that answers 404 is `failed`. A + Garmin list window that answers 404 fails that window +- three Garmin ids are due a detail call, and the probe answers HTTP 403. + The fixture server sees one Garmin detail request. All three ids are + stored with `deferred`, none is `not_available`, Garmin is + `completed`, and the exit is 0. The next command probes the same oldest + id again. HTTP 400 and 405 do the same. A probe that answers HTTP 503 + also defers all three, and Garmin is `incomplete` with a nonzero exit +- a Garmin id that a 404 marked `not_available`, with an unchanged list + object and the command's clock passed in. At 29 days after its + `detail_checked_at` it gets no call. At 30 days it is called after every + other group. A repeat 404 writes one revision with the new + `detail_checked_at` and the stored `upload_window`, and it counts + `not_available` 1 and one changed original. A detail stores it. When + the probe answers 404 for another id first, the recheck id keeps + `not_available` and its time, and nothing is written for it. When the + original's current revision is an owner correction, it gets no call at + 30 days - a live detail that answers HTTP 401, for Garmin and for Polar, counts as `failed`. The fixture server sees no later request to that provider in the command. Each id still due a call is `deferred`, the provider is @@ -3220,6 +3271,8 @@ Risks: makes no other Garmin detail call in that command, Garmin stays `completed`, and each Garmin original holds its list object only. That costs one detail call in each command that has a Garmin id due a call. + An id that got 404 or 501 is asked again after 30 days. Each repeat + answer writes one small revision of that original. Where the path works, an id that once got 404 or 501 is not called again until its list object changes. This is the stated default, and the maintainer still has to confirm it. @@ -3350,8 +3403,10 @@ These questions stay open for the maintainer. The plan states a default for each, and the default is not adopted: 1. Garmin detail. The default probes the undocumented detail path once - per command. When the probe answers 400, 403, 404, 405, or 501, the - pull makes no other Garmin detail call in that command (D243). + per command. When the probe answers an error status other than 401 or + 429, the pull makes no other Garmin detail call in that command. Only + 404 and 501 mark the probed id `not_available`, and such an id is + asked again after 30 days (D243). 2. The owner-correction scope. The default covers every record the `open_wearables` pull writes. Other routes keep D182 (D242). 3. Storing vendor originals in their own package files. The default keeps From 8d41a9dc08402c22cbd5845f0b4494b1c1fd2e29 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 07:26:28 +0000 Subject: [PATCH 55/60] Plan 2.2.0: store the clean list object when only a detail holds __proto__, and name refusals A detail with a __proto__ key is refused as unusable_name, and its list object is stored with refused_by and refused_path. The detail is asked for again only when the list object changes, and the provider stays completed. Each refused object and refused detail is named in left_out.examples by provider, vendor id, reason, and key path. Extends the Polar three-object test. Co-authored-by: Michael Whitham --- build-history/v2.2.0/decisions.md | 42 ++++++++++++---- build-history/v2.2.0/spec.md | 83 ++++++++++++++++++++----------- 2 files changed, 87 insertions(+), 38 deletions(-) diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index 64d646c5..799f2d3b 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -222,6 +222,11 @@ number is added: `detail_checked_at` and is asked again after 30 days, or sooner when its list object changes. An original with a current owner correction is asked again only when its list object changes. +- D243 and D231. When only a detail holds a `__proto__` key, the clean + list object is stored with `detail_status` `refused` and `refused_by` + `unusable_name`, and the detail is asked for again only when the list + object changes. Each refused object and refused detail is named in + `left_out.examples` by provider, vendor id, reason, and key path. ## D227. Version 2.2.0 is one manual pull, and the program and the record share that number @@ -746,8 +751,9 @@ native reader, which keeps such a key and checks it, so the import refusal still applies. There is no `persist.rs` and no `ath-core persist` command. The pull writes through `MappedPage` and the 2.1.1 import, so the import check covers it. The vendor read in D243 runs -the same check on each vendor object first, so one object with the key is -refused alone. A name check outside import is separate work. +the same check on each vendor object first. A list object with the key is +refused alone. A detail with the key is refused, and its clean list +object is stored. A name check outside import is separate work. `is_mapping_path` exists once, in `src/assets/mod.rs`. The pull uses `resolve_mapping` in that file. There is no second path rule to remove. @@ -1627,11 +1633,13 @@ it has fewer fields. The stored detail stays in the record's history as the earlier revision. A deferred or failed detail keeps the stored detail and adds no revision. A detail over the 10 MiB response cap is `too_large`, because the detail route has no smaller page. A detail -the privacy scan refuses is `refused`. Neither is stored. A failed, -mismatched, too large, or refused detail makes the provider `incomplete` -and the exit nonzero, because a limit may refuse work but must not report -it as complete. A too large or refused id is retried after the new and -changed ids. A deferred detail leaves the provider `completed`, with a +the privacy scan refuses is `refused` by `privacy_scan`. Neither is +stored. A failed, mismatched, too large, or privacy-refused detail makes +the provider `incomplete` and the exit nonzero, because a limit may +refuse work but must not report it as complete. A too large or +privacy-refused id is retried after the new and changed ids. A detail +with a `__proto__` key is `refused` as `unusable_name`, as the next +paragraphs say. A deferred detail leaves the provider `completed`, with a separate deferred count. A detail is read after the provider's whole list, so it can come minutes after its list object, and the vendor can change the workout in between. The envelope does not record when each @@ -1685,13 +1693,18 @@ The start becomes `input_timestamp` by the rules in the specification: text keeps its offset or says it has none, and Unix seconds or milliseconds keep their digits. The start is stored and is not a filter. -A vendor object with a `__proto__` key at any depth is refused alone as -`unusable_name`, and the provider stays `completed`. The import check +A vendor list object with a `__proto__` key at any depth is refused alone +as `unusable_name`, and the provider stays `completed`. The import check (D191) refuses that key and fails the whole import. Vendor JSON is outside ath's control, so one such object would otherwise fail that provider's page on every command, with no count and no fix. The vendor read runs the same check on each list object and each detail before the -page is staged. +page is staged. When only the detail holds the key, the clean list object +is stored with `detail_status` `refused`, `refused_by` `unusable_name`, +and the key's path in `refused_path`. That detail is asked for again only +when its list object changes, because a rerun gets the same detail. Each +refused object and refused detail is named in `left_out.examples`, inside +its 20-line bound, by provider, vendor id, reason, and key path. Every returned original is stored, including a start outside `--from` and `--to`. The count is `vendor workout originals`. `range_complete` uses @@ -1787,6 +1800,15 @@ Rejected alternatives: - Drop an original whose start is outside the requested range. Rejected. The live methods do not filter by workout start, so a drop would hide a returned object. +- Refuse the list object too when only its detail holds a `__proto__` + key, as the earlier text did. Rejected. Nothing would be stored, and + every command would spend a detail call on that id again. +- Ask for a name-refused detail again after the new and changed ids, as + a privacy-refused one is. Rejected. The vendor returns the same detail, + so the call would be spent on every command for no gain. +- Count refused objects without naming them. Rejected. With the provider + `completed`, a count alone does not tell the person which workout or + which key. ## D244. Vendor originals stay whole. The maintainer can change this diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index f7a738c6..e26a0cac 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -1052,9 +1052,11 @@ change, as the next paragraph says. A preview's `details` counts are estimates from the stored originals, and they are under the `estimated` key. `would_detail` counts the ids that `--yes` would detail now, and `deferred` the ids past the budget. `kept` -and `not_available` are counted as `--yes` would count them. `failed`, -`mismatch`, `thinner`, `too_large`, and `refused` are zero in a preview, -because only a detail call can find them. The preview says so: `preview +and `not_available` are counted as `--yes` would count them, and so is +an `unusable_name` refusal whose list object is unchanged. `failed`, +`mismatch`, `thinner`, and `too_large` are zero in a preview, and so is +any other `refused`, because only a detail call can find them. The +preview says so: `preview made no detail calls; detail failures, size limits and refusals are only known after --yes`. A preview and then `--yes` read each provider's list twice. That is one extra call for most providers, every window again for Garmin, and @@ -1308,18 +1310,27 @@ reason. A refused object refuses only itself, and the count says why. Two different objects with one id in one provider's response refuse both, because the pull cannot tell which is right. Two equal objects are one. -A vendor object that holds a key named `__proto__` at any depth is -refused as `unusable_name`. The import check in section 3 refuses that -key in any supplied field, and it fails the whole import. So -`src/runtime/vendor_workouts.rs` runs the same check on each list object -and each detail before the page is staged. A list object with the key -gets no detail call. A detail with the key refuses its whole object, list -object included. Only that object is refused, and the others are -written. The provider stays `completed`, as it does for the other refused -objects, because a rerun gets the same object. The person has no fix in -ath, because nothing is stored to delete. A later command reads the -object again. When only its detail holds the key, that command spends one -detail call on it again. +A vendor list object that holds a key named `__proto__` at any depth is +refused as `unusable_name`, and it gets no detail call. The import check +in section 3 refuses that key in any supplied field, and it fails the +whole import. So `src/runtime/vendor_workouts.rs` runs the same check on +each list object and each detail before the page is staged. When only +the detail holds the key, the clean list object is stored with +`detail_status` `refused`, `refused_by` `unusable_name`, and the key's +path in `refused_path`. The detail is not stored. A later command asks +for that detail again only when the list object changes, so the call is +not spent on every command. Only that object is refused, and the others +are written. The provider stays `completed`, as it does for the other +refused objects, because a rerun gets the same object. A refused list +object is not stored, so a later command reads it and refuses it again, +with no detail call. + +Each object refused this way is named in `left_out.examples`, inside the +20-line bound. The line gives the provider, the vendor id as a JSON +string or `no id`, the reason, and the JSON path of the key, in the form +the withheld paths use. For example: `polar "1002": unusable_name at +detail.samples[3].__proto__`. A refused detail is named the same way, +though its original is stored and its count is under `details`. Garmin is read in windows, and one activity can be in two windows when Garmin received it again. A window selects by upload time, so the later @@ -1412,8 +1423,9 @@ The pull calls detail only when the provider has a detail call and its budget allows. It spends the budget in this order. First come ids with no stored detail that no earlier command marked `not_available`, `too_large`, or `refused`. Then come ids whose list object differs from -the stored `list`. Then come ids an earlier command marked `too_large` or -`refused`. Last come Garmin ids that a 404 or 501 marked `not_available` +the stored `list`. Then come ids an earlier command marked `too_large`, +or `refused` with `refused_by` `privacy_scan`. Last come Garmin ids that +a 404 or 501 marked `not_available` at least 30 days before this command started, by their `detail_checked_at`. An original whose current revision is an owner correction is not in that last group, because a repeat answer would not @@ -1421,7 +1433,8 @@ be written over the correction, and its time would never move. Each id goes in the first group it matches. So an id that was `not_available`, `too_large`, or `refused` and whose list object changed is in the second group. Any other id marked `not_available` whose list object is unchanged -gets no detail call. It counts as `not_available` again. Inside each +gets no detail call. It counts as `not_available` again. So does an id +`refused` as `unusable_name`, which counts as `refused` again. Inside each group the oldest start goes first. An id without a start instant goes last in its group, in list order. So a Garmin path that answers 404 costs one detail call in a command, and only when some id is due a call. @@ -1482,17 +1495,20 @@ What is written for one id depends on what this command got: detail response over `MAX_PULL_RESPONSE_BYTES` is `too_large`, because the detail route has no smaller page. A detail that the privacy scan in section 4 refuses, because it holds the key, - the origin, or the user id, is `refused`. Neither of those is stored, - and each is counted on the provider's line. + the origin, or the user id, is `refused` by `privacy_scan`. A detail + with a `__proto__` key is `refused` as `unusable_name`. None of those + is stored, and each is counted on the provider's line. - No new detail, but one is stored, and the list object changed. Nothing is written for that id, and no revision is added. The stored detail stays. The id counts as `deferred`, `failed`, `mismatch`, `not_available`, `too_large`, or `refused`. A list-only object therefore never replaces a stored detail. A `failed`, -`mismatch`, `too_large`, or `refused` detail makes the provider -`incomplete`, and the exit is nonzero. A `not_available` detail leaves the provider `completed`. A -`deferred` detail leaves the provider `completed`, with the +`mismatch`, or `too_large` detail, or one `refused` by the privacy scan, +makes the provider `incomplete`, and the exit is nonzero. A detail +refused as `unusable_name` leaves the provider `completed`, because a +rerun gets the same detail. A `not_available` detail leaves the provider +`completed`. A `deferred` detail leaves the provider `completed`, with the deferred count on its line, and the next command details those ids first. A deferred id that the provider stops listing is never detailed by a later command. The deferred count shows how many are waiting. @@ -1529,6 +1545,11 @@ the same object: - `detail_checked_at` is present only when a Garmin detail answered 404 or 501 and `detail_status` is `not_available`. It holds the integer Unix seconds of that answer, by the pull's clock. +- `refused_by` is present only when `detail_status` is `refused`. It is + `privacy_scan` or `unusable_name`. `refused_path` is present only with + `unusable_name`. It is the JSON path of the key in the detail, and it + names keys and indexes, never a value. The privacy scan runs first, so + the path never holds the key, the origin, or the user id. - A value that section 4 withholds is replaced in place by its marker. Nothing else in `list`, `list_parent`, or `detail` is changed. @@ -2722,10 +2743,16 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: fails it too. A package that holds a `__proto__` key still restores, because D214 keeps the key in the native reader - a Polar list of three objects, where one detail has a `__proto__` key - nested in a route point. Two originals are stored. Polar's `left_out` - counts 1 `unusable_name`, Polar is `completed`, and the page is not - refused. A Polar list object with the key gets no detail call and is - counted the same way + nested in a route point. All three originals are stored. The one with + the bad detail holds its list object, `detail_status` `refused`, + `refused_by` `unusable_name`, and the key's path in `refused_path`. + Polar's details count 1 `refused`, Polar is `completed`, the exit is 0, + and the page is not refused. One `left_out.examples` line names + `polar`, that vendor id, and the key's path. A second pull with the + same list objects makes no detail call for that id and counts it + `refused` again. A Polar list object with the key gets no detail call, + is not stored, counts 1 `unusable_name` in `left_out`, and is named the + same way - a literal key, a Unicode-escaped key in a nested unconsumed field, the key used as an object key, the selected origin, and the selected user id each reject the page before mapping. The database, its revisions, and the @@ -2772,7 +2799,7 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: - a Polar detail over `MAX_PULL_RESPONSE_BYTES`, with the cap lowered for the test, is `too_large`. The list object is stored alone, Polar is `incomplete`, and the exit is nonzero. A Polar detail that holds the - selected user id is `refused`, is not stored, and makes Polar + selected user id is `refused` by `privacy_scan`, is not stored, and makes Polar `incomplete`. The list object of that id passed the scan and is stored. On the next command, a new Polar id is detailed before either of them - 101 Polar ids with no stored detail. The first pull makes 100 detail From 429580df2904ab96052bf46b3e43f5b1929e0629 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 07:31:34 +0000 Subject: [PATCH 56/60] Plan 2.2.0: refuse vendor objects nested 123 levels or more as too_deep The package puts a vendor object five levels down, and the read parses with serde_json, which refuses 128 levels even though check_nesting allows 128. So the pull refuses an object nested 123 levels or more as too_deep, counts it, and names it with its depth. A deep detail keeps its clean list object. The export check now refuses an item that reaches 128 levels. Adds the 125-level Polar test with export and read-back, and the 122 and 123 boundary. Co-authored-by: Michael Whitham --- .../v2.2.0/appendix/vendor-original-size.md | 5 +- build-history/v2.2.0/decisions.md | 27 ++++++- build-history/v2.2.0/spec.md | 80 +++++++++++++------ 3 files changed, 83 insertions(+), 29 deletions(-) diff --git a/build-history/v2.2.0/appendix/vendor-original-size.md b/build-history/v2.2.0/appendix/vendor-original-size.md index 8d28c270..9718b461 100644 --- a/build-history/v2.2.0/appendix/vendor-original-size.md +++ b/build-history/v2.2.0/appendix/vendor-original-size.md @@ -55,8 +55,9 @@ export writes it, and about 612 MiB of the route-only shape. Both are over the 512 MiB package read cap. The deepest value is a route point's field, five levels inside the -record's `data`. In the package it is eight levels deep. The package read -limit is 128 levels. +record's `data`. In the package it is eight levels deep. A package reads +back at 127 levels or fewer. `check_nesting` allows 128, but serde_json +1.0.154 refuses 128 when the read parses the document. ## What was not measured diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index 799f2d3b..653ed67c 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -227,6 +227,12 @@ number is added: `unusable_name`, and the detail is asked for again only when the list object changes. Each refused object and refused detail is named in `left_out.examples` by provider, vendor id, reason, and key path. +- D243 and D242. A vendor object nested 123 levels or more is refused as + `too_deep`, counted, and named with its depth. A deep detail keeps its + clean list object, as a `__proto__` detail does. The read refuses 128 + levels, though `check_nesting` allows 128, so the export check now + refuses an item that reaches 128. That is why the cut is 123 and not + 124. ## D227. Version 2.2.0 is one manual pull, and the program and the record share that number @@ -1455,8 +1461,12 @@ refused, its objects count as `size_cap`, and that provider is in the text and in `--json`. From 80% it warns, and the warning names `ath erase` and says the erase cannot be undone. `ath export` gains a check that refuses to publish a document over the 512 MiB read cap or an -item past the 128-level nesting limit, because 2.1.1 can write a package -it cannot read back. Each listed object is in exactly one detail count or +item that reaches 128 levels, because 2.1.1 can write a package it +cannot read back. The read parses with serde_json, which refuses 128 +levels, though `check_nesting` allows 128. The package puts a vendor +object five levels down, so the pull refuses a vendor object nested 123 +levels or more as `too_deep`, and no vendor original trips that check. +Each listed object is in exactly one detail count or one left-out count, so no object is dropped without a count. The pull uses the published query parameters and does not add its own @@ -1706,6 +1716,12 @@ when its list object changes, because a rerun gets the same detail. Each refused object and refused detail is named in `left_out.examples`, inside its 20-line bound, by provider, vendor id, reason, and key path. +A vendor object nested 123 levels or more is refused the same way as +`too_deep`, and it is named with its depth. The package puts the object +five levels down, and the read refuses 128 levels, so storing it would +make every later export fail until the person erased the original. A +saved envelope that deep is left out of a mapped import too. + Every returned original is stored, including a start outside `--from` and `--to`. The count is `vendor workout originals`. `range_complete` uses only the stored ranged reads. Each line says whether its limit covers the @@ -1809,6 +1825,13 @@ Rejected alternatives: - Count refused objects without naming them. Rejected. With the provider `completed`, a count alone does not tell the person which workout or which key. +- Store a vendor object of any depth and let export refuse it, as the + earlier text did. Rejected. One deep object would block every export + until the person erased it. +- Refuse from 124 levels, which the reviews proposed from the 128 that + `check_nesting` allows. Rejected. serde_json refuses 128 levels when + the read parses the document, so a 123-level object would be stored + and then fail to read back. ## D244. Vendor originals stay whole. The maintainer can change this diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index e26a0cac..36f8e242 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -1053,7 +1053,8 @@ A preview's `details` counts are estimates from the stored originals, and they are under the `estimated` key. `would_detail` counts the ids that `--yes` would detail now, and `deferred` the ids past the budget. `kept` and `not_available` are counted as `--yes` would count them, and so is -an `unusable_name` refusal whose list object is unchanged. `failed`, +an `unusable_name` or `too_deep` refusal whose list object is unchanged. +`failed`, `mismatch`, `thinner`, and `too_large` are zero in a preview, and so is any other `refused`, because only a detail call can find them. The preview says so: `preview @@ -1434,7 +1435,8 @@ goes in the first group it matches. So an id that was `not_available`, `too_large`, or `refused` and whose list object changed is in the second group. Any other id marked `not_available` whose list object is unchanged gets no detail call. It counts as `not_available` again. So does an id -`refused` as `unusable_name`, which counts as `refused` again. Inside each +`refused` as `unusable_name` or `too_deep`, which counts as `refused` +again. Inside each group the oldest start goes first. An id without a start instant goes last in its group, in list order. So a Garmin path that answers 404 costs one detail call in a command, and only when some id is due a call. @@ -1506,12 +1508,13 @@ What is written for one id depends on what this command got: A list-only object therefore never replaces a stored detail. A `failed`, `mismatch`, or `too_large` detail, or one `refused` by the privacy scan, makes the provider `incomplete`, and the exit is nonzero. A detail -refused as `unusable_name` leaves the provider `completed`, because a -rerun gets the same detail. A `not_available` detail leaves the provider -`completed`. A `deferred` detail leaves the provider `completed`, with the -deferred count on its line, and the next command details those ids first. -A deferred id that the provider stops listing is never detailed by a later -command. The deferred count shows how many are waiting. +refused as `unusable_name` or `too_deep` leaves the provider `completed`, +because a rerun gets the same detail. A `not_available` detail leaves the +provider `completed`. A `deferred` detail leaves the provider +`completed`, with the deferred count on its line, and the next command +details those ids first. A deferred id that the provider stops listing is +never detailed by a later command. The deferred count shows how many are +waiting. Each original is one envelope. The pull builds it, and a saved file holds the same object: @@ -1546,7 +1549,8 @@ the same object: or 501 and `detail_status` is `not_available`. It holds the integer Unix seconds of that answer, by the pull's clock. - `refused_by` is present only when `detail_status` is `refused`. It is - `privacy_scan` or `unusable_name`. `refused_path` is present only with + `privacy_scan`, `unusable_name`, or `too_deep`. `refused_path` is + present only with `unusable_name`. It is the JSON path of the key in the detail, and it names keys and indexes, never a value. The privacy scan runs first, so the path never holds the key, the origin, or the user id. @@ -1637,15 +1641,29 @@ no size check, so it can publish a package that `src/package/load.rs` refuses to read. The build adds that check to `src/package/export.rs`. Export counts the bytes of each document it writes into its staging folder and the nesting depth of each item. A document may not pass -`MAX_PACKAGE_DOCUMENT_BYTES`, and an item may not nest deeper than +`MAX_PACKAGE_DOCUMENT_BYTES`, and an item may not reach `MAX_PACKAGE_JSON_NESTING`, 128 levels, counted from the document. When either happens, export fails before the rename, removes the staging -folder, publishes nothing, and names the document. The package puts a -vendor object up to five levels deeper than its response did: the -document, `records`, the item, `data`, and `supplied_fields`. serde_json, -which `src/json.rs` uses, refuses JSON nested 128 levels or more. So an -object 124 to 127 levels deep could be stored and then fail this check. -The pull does not refuse such an object itself. +folder, publishes nothing, and names the document. `check_nesting` in +`src/package/load.rs` allows 128 levels. But the read then parses with +serde_json through `src/json.rs`, and serde_json refuses 128 levels. With +serde_json 1.0.154, the version in `Cargo.lock`, 127 levels parse and +128 do not. So 127 is the deepest package that reads back. + +The package puts a vendor object five levels down: the document, +`records` or `record_revisions`, the item, `data`, and +`supplied_fields`. So a vendor object nested 123 levels or more would +reach 128 in the package. The pull refuses such an object as `too_deep`, +by the same rules as `unusable_name`. A list object or list parent that +deep is not stored and gets no detail call. A detail that deep is not +stored, and the clean list object is stored with `detail_status` +`refused` and `refused_by` `too_deep`. That detail is asked for again +only when the list object changes. The provider stays `completed`. Each +such object is named in `left_out.examples` with its depth instead of a +path, such as `polar "1003": too_deep at 125 levels`. A mapped import of +saved envelopes leaves out an envelope whose `list`, `list_parent`, or +`detail` is that deep, as `too_deep`. So no vendor original can make +export fail by its depth. ath does not write a saved file of envelopes. Written compact or with a two-space indent, such a file is smaller than its originals as export @@ -1690,8 +1708,8 @@ preview they are estimates under `estimated`, as section 1 says. `too_large`, and `refused`. - `left_out`: objects not written, by reason: `missing_id`, `unusable_id`, `unsafe_number`, `unusable_name`, `duplicate_id`, - `superseded`, `ambiguous_window`, `deleted_record`, `deleted_source`, - `response_refused`, and `size_cap`. + `too_deep`, `superseded`, `ambiguous_window`, `deleted_record`, + `deleted_source`, `response_refused`, and `size_cap`. - `withheld`: values that section 4 withheld, with up to 20 paths. Each listed object is in exactly one detail count or one left-out count. @@ -1715,8 +1733,8 @@ whole envelope in `supplied_fields`. A saved file of envelopes, under `vendor_workout`, imports through that section with `ath import --mapping open-wearables`. File import does not apply the detail rules above. It writes each envelope as the file holds it, as D182 does for every mapped -import, except the owner-correction rule and the Garmin window rule -above. Export and import keep one original id. +import, except the owner-correction rule, the Garmin window rule, and +the depth check above. Export and import keep one original id. The provider table, the detail rules, and the thinner check live in `src/runtime/vendor_workouts.rs`. They run before the mapping engine sees @@ -2307,11 +2325,12 @@ interactive open can preview, back up, ask, and then migrate. | Stage, match, and write each page | `preview_route` and `ProviderPreview::apply` in `src/import/provider.rs`. The revision a preview read is the public `destination_database_revision` | | A `connector` source with no vendor | new `connector_source` beside `route_source` in `src/import/provider.rs` | | Page counts by record type | a count beside `Staging::count` in `src/import/staging.rs`, exposed by `ProviderPreview` | -| Owner-correction rule and its count, and the Garmin window rule | `match_keyed` and `record_by_import_key` in `src/import/provider.rs`, behind a `KeyedPolicy` flag that only route `open_wearables` sets | +| Owner-correction rule and its count, the Garmin window rule, and the depth check for saved envelopes | `match_keyed` and `record_by_import_key` in `src/import/provider.rs`, behind a `KeyedPolicy` flag that only route `open_wearables` sets | | Where a workout fix belongs | one paragraph in `skills/athletic-standard/SKILL.md`, under "Stable IDs and revisions" | | Total size bound for vendor originals, in the bytes export writes | `MAX_VENDOR_ORIGINAL_BYTES` in `src/input_policy.rs`. One function beside `ArrayWriter::item` in `src/package/export.rs` measures an item. The bound is checked in the matching step in `src/import/provider.rs`, in `apply_in` in `src/store/write.rs`, and in `merge_in`, `resolve_in`, and native restore in `src/package/restore.rs` | | The vendor-original total and its warning | the pull's text and `--json` outcome, from `pull` in `src/cli/commands/routes.rs` | -| Export refuses a document over the package read cap, or an item past the nesting limit | `src/package/export.rs`, before the staging folder is renamed | +| Export refuses a document over the package read cap, or an item that reaches the nesting limit | `src/package/export.rs`, before the staging folder is renamed | +| The pull's `__proto__` and depth checks on each vendor object | `src/runtime/vendor_workouts.rs`, before the page is staged | | Device-binding facts and the safety snapshot | new `src/import/binding.rs`, called from the matching step in `src/import/provider.rs` for route `open_wearables` | | Create or first-bind with the checked receipt, and refuse any other `device_binding` change | the staged plan and `ProviderPreview::apply` in `src/import/provider.rs` | | Stored-original read for the vendor detail rules | a crate-private read in `src/import/provider.rs` | @@ -2925,9 +2944,20 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: and it names `ath erase` and says the erase cannot be undone - an export whose main document would pass the read cap, with that cap lowered for the test, fails before the rename and publishes nothing. So - does an export whose item would nest deeper than - `MAX_PACKAGE_JSON_NESTING`, with that limit lowered for the test. An - item at the limit exports, and `ath import` reads it back + does an export whose item would reach `MAX_PACKAGE_JSON_NESTING`, 128 + levels, from a record the test writes straight into the database. An + item 127 levels deep exports, and `ath import` reads it back +- a Polar list of three objects, where one detail is nested 125 levels. + That detail is not stored. Its list object is stored with + `detail_status` `refused` and `refused_by` `too_deep`, and the other two + originals are stored. Polar's details count 1 `refused`, Polar is + `completed`, the exit is 0, and one `left_out.examples` line names + `polar`, that vendor id, and 125 levels. `ath export` then succeeds, + and `ath import` reads the package back. A detail nested 122 levels is + stored, exports, and reads back. One nested 123 levels is refused. A + list object nested 125 levels is not stored, gets no detail call, and + counts 1 `too_deep` in `left_out`. A mapped import of a saved envelope + whose `detail` is nested 125 levels leaves it out as `too_deep` - a synthetic Garmin fixture returns activity 555 in the first window with `durationInSeconds` 1800 and in the second window with 1860. One original is stored, and its `list` is the second window's object. Garmin's From 43de4481d93e647d7a0dd4221a5429aa6f84e473 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 07:35:45 +0000 Subject: [PATCH 57/60] Plan 2.2.0: keep each vendor original's export size so a write measures only what it writes Step 6 creates vendor_original_sizes, one row for each original with its current item's size and the sum of its revision items, as export writes them. A new revision measures two items, a delete measures one, and a merge or restore measures what it writes. The bound and the usage line read the sum. Only ath check measures every original again, and ath repair fixes a row that differs. Adds the test that the stored total equals the bytes export writes. Co-authored-by: Michael Whitham --- .../v2.2.0/appendix/vendor-original-size.md | 4 +- build-history/v2.2.0/decisions.md | 21 ++++++-- build-history/v2.2.0/spec.md | 54 +++++++++++++++---- 3 files changed, 64 insertions(+), 15 deletions(-) diff --git a/build-history/v2.2.0/appendix/vendor-original-size.md b/build-history/v2.2.0/appendix/vendor-original-size.md index 9718b461..4435e7cb 100644 --- a/build-history/v2.2.0/appendix/vendor-original-size.md +++ b/build-history/v2.2.0/appendix/vendor-original-size.md @@ -65,5 +65,5 @@ back at 127 levels or fewer. `check_nesting` allows 128, but serde_json device and by sport. - Garmin, Strava, and Suunto details. Their laps, splits, and sample arrays nest in other ways. -- How long measuring the stored originals takes in a database near the - bound. +- How long `ath check` takes to measure every original in a database + near the bound. A write measures only the items it writes. diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index 653ed67c..95c03964 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -233,6 +233,12 @@ number is added: levels, though `check_nesting` allows 128, so the export check now refuses an item that reaches 128. That is why the cut is 123 and not 124. +- D242. Step 6 creates `vendor_original_sizes`, one row for each + original with its current item's size and the sum of its revision + items, as export writes them. A write measures only the items it + writes, and the bound and the usage line read the sum. Only `ath check` + measures every original again, and `ath repair` fixes a row that + differs. ## D227. Version 2.2.0 is one manual pull, and the program and the record share that number @@ -1446,9 +1452,12 @@ the current record under `records` and each revision under reads that document only up to 512 MiB, and a mapped import file only up to 512 MiB. Export pretty-prints each item, so the bound counts those bytes and not the compact `record_json` column. One function measures an -item for both. A synthetic one-hour Polar run with a route exports at -2.05 times its compact size, and each original is in the document at -least twice. So the earlier bound, 128 MiB of compact JSON, could export +item for both. The database keeps each original's size in +`vendor_original_sizes`: its current item, and the sum of its revision +items. A write measures only the items it writes, and only `ath check` +measures every original again. A synthetic one-hour Polar run with a +route exports at 2.05 times its compact size, and each original is in +the document at least twice. So the earlier bound, 128 MiB of compact JSON, could export to about 525 MiB. The new bound holds about 158 such workouts with one revision each, or about 105 with two. Evidence: [appendix/vendor-original-size.md](appendix/vendor-original-size.md). @@ -1502,6 +1511,12 @@ Rejected alternatives: - Check the bound only on pulls and mapped imports. Rejected. `ath correct`, a merge, or a restore could then take a database past it, and its export could become unreadable. +- Measure every stored original on each write, as the earlier text did. + Rejected. Near the bound, one `ath correct` would first pretty-print + about 256 MiB. +- Keep one cached total. Rejected. A new revision also changes the + original's current item, and one total cannot say how much of the old + item to take away. - Store originals in their own package files now. Not chosen in this plan. It changes the package format. Section 9 of the specification lists it, and section 10 leaves it as an open question for the diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index 36f8e242..6e85bcd7 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -1630,11 +1630,31 @@ but it removes that original and its history and cannot be undone. Storing originals in their own files is an open question for the maintainer (section 10). -The pull measures the stored originals once per command, in its first -vendor page's matching read, and adds what each committed page writes. A -later page whose matching read sees a database revision that the pull's -own last apply did not produce measures them again. A mapped import -measures them once. +The database keeps each original's size, so no write measures them all. +Step 6 creates the table `vendor_original_sizes`. It has one row for +each vendor original, deleted ones included. The row holds `record_id`, +`record_item_bytes`, and `revision_items_bytes`. `record_item_bytes` is +the original's item under `records` as export writes it. +`revision_items_bytes` is the sum of its items under `record_revisions`. +The row references `records` with `ON DELETE CASCADE`, so `ath erase` +removes it with the record. The table is not in the package. It is kept +in step with the record, the way the typed tables are. + +Every write that changes an original updates its row in the same +transaction. A new revision measures two items: the new revision item, +which is added to `revision_items_bytes`, and the new current item, which +replaces `record_item_bytes`. A delete measures the current item again, +because its `is_deleted` value changes. A package merge and a native +restore measure each item they write. Revision items never change after +they are written, so no write measures an old one. The bound check reads +the sum of every row, takes away the old rows of the originals the write +changes, and adds their new sizes. The pull's usage line reads the same +sum. + +Only `ath check` measures every original again. It compares each with +its row, and a difference is an error that names the record. A missing +row or a row with no original is an error too. `ath repair` writes the +measured sizes, makes a verified backup first, and adds no revision. `ath export` in 2.1.1 writes the main document and the series files with no size check, so it can publish a package that `src/package/load.rs` @@ -2012,9 +2032,11 @@ besides the typed writes in section 6. It gains nothing beyond those: of the owner-correction rule and the window test, and applies the Garmin window rule in section 2. - In matching, for a page with `vendor_workout` rows, the size bound in - section 2. It measures the stored vendor originals as export writes - them, adds the page's new and changed envelopes, and refuses the page - when the total would pass `MAX_VENDOR_ORIGINAL_BYTES`. + section 2. It reads the stored total from `vendor_original_sizes`, + measures the items the page's new and changed envelopes would write, + and refuses the page when the total would pass + `MAX_VENDOR_ORIGINAL_BYTES`. The apply writes those rows in the same + transaction. The pull reads the revision a preview matched at from `ProviderPreview::destination_database_revision`, which is already public. @@ -2149,7 +2171,8 @@ runner arm. Step 5 is already `athleticstandard_version` to `2.2.0` and `sql_schema_version` to 6. No column is added to an existing table. The contract adds `source_report` to the `records.record_type` check, creates -`source_reports`, and rebuilds `provider_summaries` and +`source_reports` and `vendor_original_sizes`, and rebuilds +`provider_summaries` and `provider_scores` as section 2 describes. Files `001` through `005` stay byte-identical. The check is not removed, and ordinary store writes do not turn foreign keys off. @@ -2222,7 +2245,9 @@ Inside that one transaction the order is fixed. `record_erasure_blocks_current_record_update`. 6. Recreate the two views and the two cross-table triggers from that same text, unchanged. -7. Create `source_reports` and its type trigger. +7. Create `source_reports` and its type trigger, and + `vendor_original_sizes`. A 2.1.1 database has no vendor original, so + the new table starts empty. 8. `PRAGMA foreign_key_check` is empty and `PRAGMA integrity_check` is `ok`. 9. Set the version rows and `user_version` 6. @@ -2328,6 +2353,7 @@ interactive open can preview, back up, ask, and then migrate. | Owner-correction rule and its count, the Garmin window rule, and the depth check for saved envelopes | `match_keyed` and `record_by_import_key` in `src/import/provider.rs`, behind a `KeyedPolicy` flag that only route `open_wearables` sets | | Where a workout fix belongs | one paragraph in `skills/athletic-standard/SKILL.md`, under "Stable IDs and revisions" | | Total size bound for vendor originals, in the bytes export writes | `MAX_VENDOR_ORIGINAL_BYTES` in `src/input_policy.rs`. One function beside `ArrayWriter::item` in `src/package/export.rs` measures an item. The bound is checked in the matching step in `src/import/provider.rs`, in `apply_in` in `src/store/write.rs`, and in `merge_in`, `resolve_in`, and native restore in `src/package/restore.rs` | +| Stored sizes of vendor originals | `vendor_original_sizes`, created by the step 6 SQL file. The rows are written beside the typed rows in `src/store/write.rs` and `src/package/restore.rs`. `ath check` compares them in `src/store/check.rs`, and `ath repair` rewrites them in `src/store/repair.rs` | | The vendor-original total and its warning | the pull's text and `--json` outcome, from `pull` in `src/cli/commands/routes.rs` | | Export refuses a document over the package read cap, or an item that reaches the nesting limit | `src/package/export.rs`, before the staging folder is renamed | | The pull's `__proto__` and depth checks on each vendor object | `src/runtime/vendor_workouts.rs`, before the page is staged | @@ -2937,6 +2963,14 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: by a protocol record write, by a package merge, and by a native restore. Each refusal writes nothing. The page counts its objects as `size_cap` and makes that provider `incomplete` +- after a pull, an `ath correct` of one original, a delete, a package + merge, a native restore, and an `ath erase` in the size fixtures, the + sum of `vendor_original_sizes` equals the bytes `ath export` writes for + vendor-original items under `records` and `record_revisions`. The test + counts those bytes in the exported main document. `ath check` passes + after each step. A row changed by hand fails `ath check`, which names + the record, and `ath repair` puts the measured size back. An `ath + correct` of one original measures two items - the pull prints `vendor originals use X MiB of 256 MiB` on a run without the flag, on a preview, and on `--yes`, and `--json` has `used_bytes` and `bound_bytes`. Under 80% of the bound there is no size From c2474044497dc90c1df51a3780f26f0d1c56da58 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 07:38:51 +0000 Subject: [PATCH 58/60] Plan 2.2.0: wording for the Garmin deferred count, the 401 line, merge choices, Strava, and the 80% warning The Garmin deferred count adds (not asked: detail unavailable this run) when the probe stops Garmin. A 401 line says to reconnect the provider in Open Wearables if this repeats. A merge choice is a conflict resolved as imported or corrected. Strava's usual case is 21 requests. The 80% warning says a later version may lift the bound and names no plan question. Co-authored-by: Michael Whitham --- build-history/v2.2.0/decisions.md | 47 ++++++++++++++-------- build-history/v2.2.0/spec.md | 67 ++++++++++++++++++------------- 2 files changed, 70 insertions(+), 44 deletions(-) diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index 95c03964..646b0baa 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -175,9 +175,10 @@ number is added: call keeps its own count. Each id goes in the first group of the detail order it matches, and a `too_large` or `refused` id is no longer in the first group. -- D243. One `--yes` command sends 24 Strava requests in the usual case, - or 25 after a token reload, which leaves about 75. The ceiling is 84, - because the pull cannot see a server retry that ended in success. +- D243. One `--yes` command sends 24 Strava requests when only the last + request was retried, or 25 after a token reload, which leaves about 75. + The ceiling is 84, because the pull cannot see a server retry that + ended in success. - D243 and D231. A vendor object with a `__proto__` key is refused alone as `unusable_name`, and the provider stays `completed`. The import check would otherwise fail that provider's page on every command. @@ -239,6 +240,13 @@ number is added: writes, and the bound and the usage line read the sum. Only `ath check` measures every original again, and `ath repair` fixes a row that differs. +- D243 and D242. Wording. When the probe stops Garmin, its deferred + count adds `(not asked: detail unavailable this run)`. After a 401, the + provider's line says to reconnect the provider in Open Wearables if + this repeats. A merge choice is a conflict resolved as imported or + corrected, because choosing the local side writes nothing. Strava's + usual case is 21 requests. The 80% warning says that a later version + may lift the bound, and it names no plan question. ## D227. Version 2.2.0 is one manual pull, and the program and the record share that number @@ -1424,11 +1432,12 @@ original. Deleting an original keeps the person's version in its history and stops every later pull from changing it. A package merge counts as an owner correction only where the person -resolved a conflict. `merge_in` in `src/package/restore.rs` copies the -package's revisions with their own bases, so a record merged without a -conflict keeps its import revisions as imports. `resolve_in` writes a -conflict the person resolved as a new revision with basis -`package_merge` and the athlete as actor. That is the person's choice, +resolved a conflict as imported or corrected. `merge_in` in +`src/package/restore.rs` copies the package's revisions with their own +bases, so a record merged without a conflict keeps its import revisions +as imports. `resolve_in` writes such a resolution as a new revision with +basis `package_merge` and the athlete as actor. Choosing the local side +writes nothing. That is the person's choice, so the rule keeps it as it keeps an edit. The counts name it accurately: `merge_choices_replaced` is the part of `owner_corrections_replaced` that were merge choices, and the line adds `(M of them merge choices)`. @@ -1457,9 +1466,9 @@ item for both. The database keeps each original's size in items. A write measures only the items it writes, and only `ath check` measures every original again. A synthetic one-hour Polar run with a route exports at 2.05 times its compact size, and each original is in -the document at least twice. So the earlier bound, 128 MiB of compact JSON, could export -to about 525 MiB. The new bound holds about 158 such workouts with one -revision each, or about 105 with two. Evidence: +the document at least twice. So the earlier bound, 128 MiB of compact +JSON, could export to about 525 MiB. The new bound holds about 158 such +workouts with one revision each, or about 105 with two. Evidence: [appendix/vendor-original-size.md](appendix/vendor-original-size.md). Every write that adds a vendor-original revision checks the bound: a pull @@ -1468,7 +1477,9 @@ package merge, and a native restore. A page that would pass it is refused, its objects count as `size_cap`, and that provider is `incomplete`. Every pull prints how much of the bound the originals use, in the text and in `--json`. From 80% it warns, and the warning names -`ath erase` and says the erase cannot be undone. `ath export` gains a +`ath erase`, says the erase cannot be undone, and says that a later +version may lift the bound. It is written for the person, so it names no +plan question. `ath export` gains a check that refuses to publish a document over the 512 MiB read cap or an item that reaches 128 levels, because 2.1.1 can write a package it cannot read back. The read parses with serde_json, which refuses 128 @@ -1612,7 +1623,8 @@ Garmin detail call in a command is a probe. When it answers HTTP 404 or 501, the pull makes no other Garmin detail call in that command. The probed id is `not_available`, each other id still due a call is `deferred`, every list object is stored, and Garmin stays `completed`. -The line says `Garmin detail unavailable (HTTP n); list objects stored`. +The line says `Garmin detail unavailable (HTTP n); list objects stored`, +and its deferred count adds `(not asked: detail unavailable this run)`. Any other error status on the probe, except 401 and 429, also stops the Garmin detail calls, and every due id is `deferred`, the probed id included. A 400, 403, or 405 does not show that the activity has no @@ -1679,7 +1691,9 @@ server has already spent its three retries on the vendor's limit. An HTTP 401 ends it the same way. The server has already reloaded or refreshed the vendor token and tried once more, each later 401 would make it do that again, and a refresh the vendor rejects revokes the -connection. The detail call that got 429 or 401, or that timed out, is +connection. After a 401 the provider's line tells the person to +reconnect the provider in Open Wearables if this repeats. The detail +call that got 429 or 401, or that timed out, is `failed`. Each id still due a detail call is `deferred`. An id that was due no call keeps its own count, such as `kept`. What the provider already returned is still written, and the provider is `incomplete`. A @@ -1688,8 +1702,9 @@ Strava. Ids with no stored detail go first, oldest start first. Each id goes in the first group of the order it matches. Strava's limit belongs to the whole application, so the deployment's own sync shares it. The server tries one request at most four times and the pull sees only the -last answer, so one command sends 24 or 25 Strava requests in the usual -case and at most 84. The review cited about 100 requests a +last answer. So one command sends 21 Strava requests in the usual case, +24 or 25 when only the last request was retried, and at most 84. The +review cited about 100 requests a minute for Garmin. This study did not find that number in Garmin's public docs. The one-second pace keeps this command at 60 a minute or fewer. diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index 6e85bcd7..1e2bf17d 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -267,7 +267,8 @@ owner-correction rule in section 2. Each provider's are estimates, and their keys say so. Beside each, `estimated_merge_choices_replaced` and `estimated.merge_choices_replaced` count the part of it that were merge choices. A merge choice is a -conflict the person resolved in a package merge, as section 2 says. When +conflict the person resolved as imported or corrected in a package +merge, as section 2 says. When a provider's count is above zero, the preview prints `estimated: would replace N owner corrections; delete an original to keep it` on that provider's line. When the top-level count is above zero, it prints @@ -883,9 +884,10 @@ here. `ath correct` writes basis `local_write`, and a protocol write uses the basis its caller gives. A package merge copies the package's revisions with their own bases, in `merge_in` in `src/package/restore.rs`. So a record merged without a conflict keeps its -import revisions as imports. Only a conflict the person resolved in the -merge writes a new revision, in `resolve_in`, with basis `package_merge` -and the athlete as actor. That revision is a merge choice. It counts as +import revisions as imports. Only a conflict the person resolved as +imported or corrected writes a new revision, in `resolve_in`, with basis +`package_merge` and the athlete as actor. Choosing the local side writes +nothing. That revision is a merge choice. It counts as an owner correction, and the counts in section 1 also name it as a merge choice. A native restore copies each revision's basis, so a restored database keeps the same answer. When a page's candidate names a stored @@ -1123,7 +1125,9 @@ that provider the same way. The server has already reloaded the vendor token, or refreshed it, and tried once more. Each later request would make it do that again, and a refresh the vendor rejects revokes the connection. No later list call, window, or detail call goes to that -provider in this command. The detail call that got 429 or 401, or that +provider in this command. After a 401, the provider's line says, for +example, `Garmin answered 401: reconnect the provider in Open Wearables +if this repeats`. The detail call that got 429 or 401, or that timed out, counts as `failed`. Every id still due a detail call by the order below counts as `deferred`, and a later command details it. An id that was due no call keeps its own count, such as `kept` or @@ -1155,9 +1159,10 @@ Budgets keep one command inside the providers' limits: requests. The server tries one request at most four times. It retries a 429 up to three times, and a 401 once after it reloads the token. The pull sees only the last answer, and it stops calling Strava after - a final 429. When only that last request was retried, one `--yes` - command sends 24 Strava requests, or 25 after a token reload. That - leaves about 75 for the deployment's own sync in the same 15 minutes. + a final 429. In the usual case nothing is retried, and one `--yes` + command sends 21 Strava requests. When only the last request was + retried, it sends 24, or 25 after a token reload. That still leaves + about 75 for the deployment's own sync in the same 15 minutes. The ceiling is 84, four tries for each of the 21 requests, because the pull cannot see a retry that ended in success. A preview first adds one list call. The Strava line says that its limit is shared. @@ -1215,16 +1220,17 @@ timeout above. other id still due a detail call counts as `deferred`, because it was not asked. An id due only for its 30-day recheck keeps `not_available` instead, as the detail order below says. Every list object is stored, - Garmin stays `completed`, and - its line says `Garmin detail unavailable (HTTP n); list objects - stored`, with the status the probe got. So a missing path costs one - detail call in a command. When the probe answers any other error - status, except 401 and 429, the pull also makes no other Garmin detail - call, and the line is the same. Every id due a call counts as - `deferred`, the probed id included, except an id due only for its - 30-day recheck. A status such as 400, 403, or 405 - does not show that the activity has no detail, so the next command - probes the same oldest id again. After a 4xx status Garmin stays + Garmin stays `completed`, and its line says `Garmin detail unavailable + (HTTP n); list objects stored`, with the status the probe got. The + deferred count on that line reads `N deferred (not asked: detail + unavailable this run)`, so the person does not wait for those details. + So a missing path costs one detail call in a command. When the probe + answers any other error status, except 401 and 429, the pull also makes + no other Garmin detail call, and the line is the same. Every id due a + call counts as `deferred`, the probed id included, except an id due + only for its 30-day recheck. A status such as 400, 403, or 405 does not + show that the activity has no detail, so the next command probes the + same oldest id again. After a 4xx status Garmin stays `completed`. After a 5xx status Garmin is `incomplete`, and the exit is nonzero, because the server reported a fault. After a 2xx answer to the probe, the later Garmin detail calls go on. A later Garmin detail @@ -1626,9 +1632,10 @@ before this command, and `--yes` prints the total after it. `--json` has of the bound, the run also prints a warning, and `--json` puts it in `vendor_workouts.notice`. The warning says three things. At the bound, new vendor pages are refused. `ath erase` of an original frees its space, -but it removes that original and its history and cannot be undone. -Storing originals in their own files is an open question for the -maintainer (section 10). +but it removes that original and its history and cannot be undone. A +later version may lift the bound. The warning names no person and no +plan question. Whether this release stores originals in their own files +instead is open in section 10. The database keeps each original's size, so no write measures them all. Step 6 creates the table `vendor_original_sizes`. It has one row for @@ -2882,8 +2889,8 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: - a package merge of two sleep sessions. The first had no conflict, and its merged revision keeps basis `provider_import`, so a pull whose session changed replaces it with no owner-correction count. The person - resolved a conflict on the second, so its current revision has basis - `package_merge`. A pull whose session changed replaces it, and both + resolved a conflict on the second as imported, so its current revision + has basis `package_merge`. A pull whose session changed replaces it, and both `estimated_owner_corrections_replaced` and `estimated_merge_choices_replaced` are 1. The preview line adds `(1 of them a merge choice)`. A native export and restore keeps every @@ -2974,8 +2981,9 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: - the pull prints `vendor originals use X MiB of 256 MiB` on a run without the flag, on a preview, and on `--yes`, and `--json` has `used_bytes` and `bound_bytes`. Under 80% of the bound there is no size - warning. At 80% the text and `vendor_workouts.notice` hold the warning, - and it names `ath erase` and says the erase cannot be undone + warning. At 80% the text and `vendor_workouts.notice` hold the warning. + It names `ath erase`, says the erase cannot be undone, and says that a + later version may lift the bound. It does not say `maintainer` - an export whose main document would pass the read cap, with that cap lowered for the test, fails before the rename and publishes nothing. So does an export whose item would reach `MAX_PACKAGE_JSON_NESTING`, 128 @@ -3048,7 +3056,8 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: request. The first id is stored with `detail_status` `not_available` and a `detail_checked_at` equal to the test clock, and the other two with `deferred`. Garmin is `completed`, its line says `Garmin detail - unavailable (HTTP 404); list objects stored`, and the command exits 0. + unavailable (HTTP 404); list objects stored` and `2 deferred (not + asked: detail unavailable this run)`, and the command exits 0. HTTP 501 does the same. On the next command, the `not_available` id, whose list object is unchanged, gets no call and counts as `not_available` again, and the probe is the older of the two deferred @@ -3076,8 +3085,10 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: - a live detail that answers HTTP 401, for Garmin and for Polar, counts as `failed`. The fixture server sees no later request to that provider in the command. Each id still due a call is `deferred`, the provider is - `incomplete`, and the exit is nonzero. A Garmin window that answers 401 - sends no later window + `incomplete`, and the exit is nonzero. The Garmin line says `Garmin + answered 401: reconnect the provider in Open Wearables if this + repeats`, and the Polar line says the same with `Polar`. A Garmin + window that answers 401 sends no later window - live requests go one at a time, at least one second apart by the fixture server's clock. A live request that times out, with the read timeout shortened for the test, stops every later request to that From a6982b07c57bbb79de45265f56261e8135d22eca Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 16 Nov 2026 07:43:38 +0000 Subject: [PATCH 59/60] Plan 2.2.0: progress row for the pass after the reviews at 57838e1 The pass amends D231, D242, and D243 and adds no decision number. Co-authored-by: Michael Whitham --- build-history/v2.2.0/progress.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-history/v2.2.0/progress.md b/build-history/v2.2.0/progress.md index 85a4d2d0..1ecd193f 100644 --- a/build-history/v2.2.0/progress.md +++ b/build-history/v2.2.0/progress.md @@ -5,7 +5,7 @@ program, the record, or the database has changed for 2.2.0. | Step | What | Status | |---|---|---| -| 0 | The plan: proposals D227–D244, and the Open Wearables study. The proposals were D198–D215 until 2.1.1 used D208–D226. Checked against 2.1.1 at `0de71bb` on 15 November 2026: a page is one import preview and one apply, and D237 uses the revision check. D239 through D241 stay. D242 and D243 answer the review at `e145fa6`. D244 withholds a credential-shaped value. The pass after the review at `d636d7a` amends D227, D230, D231, D236, D242, D243, and D244. The pass after the reviews at `3c3f660` amends D228, D230, D231, D242, and D243 and adds no decision number. Three questions stay open for the maintainer, in section 10 of the specification: the Garmin detail default, the owner-correction scope, and storing vendor originals in their own files. Still not adopted. The new head needs a fresh review | written, not approved | +| 0 | The plan: proposals D227–D244, and the Open Wearables study. The proposals were D198–D215 until 2.1.1 used D208–D226. Checked against 2.1.1 at `0de71bb` on 15 November 2026: a page is one import preview and one apply, and D237 uses the revision check. D239 through D241 stay. D242 and D243 answer the review at `e145fa6`. D244 withholds a credential-shaped value. The pass after the review at `d636d7a` amends D227, D230, D231, D236, D242, D243, and D244. The pass after the reviews at `3c3f660` amends D228, D230, D231, D242, and D243 and adds no decision number. The pass after the reviews at `57838e1` amends D231, D242, and D243 and adds no decision number. Three questions stay open for the maintainer, in section 10 of the specification: the Garmin detail default, the owner-correction scope, and storing vendor originals in their own files. Still not adopted. The new head needs a fresh review | written, not approved | | 1 | Version 2.2.0 and migration step 6. Step 5 is the published 2.1.1 migration. No new column on an existing table. The root check gains `source_report` by the copy in D236. Summary and score values may be omitted in pairs (D227, D236) | not started | | 2 | `ath pull openwearables` in the `athleticstandard` crate, with the rewritten mapping (D228, D230, D236) | not started | | 3 | Key, server, and user id kept out of the record (D229) | not started | From 2fc072dddc5f47fa5c90a8bd712ae98b8708213d Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 24 Nov 2026 04:05:07 +0000 Subject: [PATCH 60/60] Move the 2.2.0 plan past version 2.1.3. Version 2.1.3 published migration step 7 and decisions D254 through D271. The plan's migration is step 8, and its proposals are D272 through D289, in the same order. Co-authored-by: Michael Whitham --- .../v2.2.0/appendix/open-wearables-api.md | 12 +- .../v2.2.0/appendix/vendor-original-size.md | 3 +- build-history/v2.2.0/decisions.md | 447 +++++++++--------- build-history/v2.2.0/progress.md | 10 +- build-history/v2.2.0/spec.md | 229 ++++----- 5 files changed, 364 insertions(+), 337 deletions(-) diff --git a/build-history/v2.2.0/appendix/open-wearables-api.md b/build-history/v2.2.0/appendix/open-wearables-api.md index 264c00cd..4b24f8ae 100644 --- a/build-history/v2.2.0/appendix/open-wearables-api.md +++ b/build-history/v2.2.0/appendix/open-wearables-api.md @@ -51,7 +51,7 @@ file, and this plan does not call it. ## The reads this plan uses -D259 names every read. The paths below are the ones this study opened +D277 names every read. The paths below are the ones this study opened first. Each is under `/api/v1` and takes a user id in the path. The user id is an Open Wearables UUID. Dates are required on the paged reads. @@ -136,7 +136,7 @@ schema. `zone_offset` is a separate string, `+01:00` or `-05:30`, or null. The 2.1.0 mapping file's timeseries lines do not name `heart_rate`. In Athletic Standard, `heart_rate` is a series quantity (`series_quantity_unit` in `src/model/data.rs`, unchanged in 2.1.1). It is not one of the point -quantities the 2.1.0 mapping engine writes. D259 stores that stream as +quantities the 2.1.0 mapping engine writes. D277 stores that stream as measurement samples. The 2.1.0 file, by itself, still has nowhere to put it. ## Time bounds @@ -206,7 +206,7 @@ route files. A limit may still exist in middleware this study did not open. The same commit, `183e8cc4f6de897dbd288c93d49a691f2cf721ae`, was read again for every user data route. The OpenAPI file is `docs/openapi.json`, `info.version` `0.11.0`. The storage rule is section 2 of the -specification, as D259 says. This section records what the source shows. +specification, as D277 says. This section records what the source shows. `SeriesType` is the enum in `backend/app/schemas/enums/series_types.py`. Each entry in `SERIES_TYPE_DEFINITIONS` is an id, a name, and a unit. @@ -215,7 +215,7 @@ path in `timeseries_service.py` copies `recorded_at`, `zone_offset`, the type, the value, and `window_seconds`. It does not set `period_end` or `computed_by`. The response `metadata.resolution` is the raw or day label. A series row does not carry that label. The archive capsule -copies it. D264 writes that capsule only at the database revision where +copies it. D282 writes that capsule only at the database revision where the safety facts were read. `_aggregated_timeseries` handles `1min`, `5min`, `15min`, and `1hour`. It @@ -241,7 +241,7 @@ the value is null for current rows because they come from WHOOP and WHOOP's HRV there is RMSSD. The class prose calls `recovery_score` deprecated, WHOOP-only, and 0 to 100. The recovery query selects by category, not by WHOOP, and copies `provider` and `value` unchanged. -Polar writes recovery scores on the 1 to 6 range. D262 uses that range +Polar writes recovery scores on the 1 to 6 range. D280 uses that range table and the copied provider. It does not use the prose as the scale. `BodyLatest` has `skin_temperature_celsius` and `skin_temperature_measured_at`. `BodyAveraged` has `period_start`, @@ -260,7 +260,7 @@ listed rows. The personal-record response fields are `birth_date`, The same commit was read again for the summary, score, meal, cycle, body, and personal-record contracts. The storage rule is section 2 of the -specification, as D259 says. This section records the source facts that +specification, as D277 says. This section records the source facts that rule uses. `SERIES_TYPE_DEFINITIONS` has 141 entries. diff --git a/build-history/v2.2.0/appendix/vendor-original-size.md b/build-history/v2.2.0/appendix/vendor-original-size.md index 316515bd..d9c7080a 100644 --- a/build-history/v2.2.0/appendix/vendor-original-size.md +++ b/build-history/v2.2.0/appendix/vendor-original-size.md @@ -1,6 +1,7 @@ # Size of a vendor original in a package -This study was measured on 16 November 2026 for D269. It used no real +This study was measured on 16 November 2026 for the live-original proposal, +now D287. It used no real data. Every value below is invented. ## Method diff --git a/build-history/v2.2.0/decisions.md b/build-history/v2.2.0/decisions.md index 798dfcfb..6384407a 100644 --- a/build-history/v2.2.0/decisions.md +++ b/build-history/v2.2.0/decisions.md @@ -7,7 +7,7 @@ D-number. ## Numbering -These proposals are D254 through D271. They were first written as D198 +These proposals are D272 through D289. They were first written as D198 through D215, when D197 was the last decision on `main`. Version 2.1.1 then used D208 through D226. D224 keeps D198 through D207 reserved for the unapproved 2.1.1 draft in @@ -15,128 +15,132 @@ unapproved 2.1.1 draft in they are never reused. On 15 November 2026 each proposal moved to the next free number, D227 through D244, in the same order. Version 2.1.2 then used D227 through D253. On 21 November 2026 each proposal moved again, to D254 -through D271, in the same order. In this folder, D208 through D226 mean -the 2.1.1 decisions, and D227 through D253 mean the 2.1.2 decisions. -Reviews written before 15 November 2026 use the first numbers. Reviews -written from that day until 21 November 2026 use the middle numbers. - -| First | Middle | Now | Subject | -|---|---|---|---| -| D198 | D227 | D254 | Version 2.2.0 and one manual pull | -| D199 | D228 | D255 | Pages, and the shipped mapping writes the records | -| D200 | D229 | D256 | The key, the server, and the user id | -| D201 | D230 | D257 | A page is atomic and a repeat is safe | -| D202 | D231 | D258 | Work left out of this build | -| D203 | D232 | D259 | Stored measurements are kept | -| D204 | D233 | D260 | Meaning, source, and time | -| D205 | D234 | D261 | Units, windows, reported records, and identities | -| D206 | D235 | D262 | The new record type and refused originals | -| D207 | D236 | D263 | The migration rename, the counts, and the archive | -| D208 | D237 | D264 | The archive's safety facts | -| D209 | D238 | D265 | A typed workout is a session | -| D210 | D239 | D266 | Skin-temperature times | -| D211 | D240 | D267 | Heart-rate recovery of zero | -| D212 | D241 | D268 | A manual session window | -| D213 | D242 | D269 | A live workout original | -| D214 | D243 | D270 | The live vendor read | -| D215 | D244 | D271 | Vendor originals and credentials | +through D271, in the same order. Version 2.1.3 then used D254 through D271. +On 24 November 2026 each proposal moved again, to D272 through D289, in the +same order. In this folder, D208 through D226 mean the 2.1.1 decisions, +D227 through D253 mean the 2.1.2 decisions, and D254 through D271 mean the +2.1.3 decisions. Reviews written before 15 November 2026 use the first +numbers. Reviews written from that day until 21 November 2026 use the +second numbers. Reviews written from 21 November 2026 until 24 November +2026 use the third numbers. + +| First | After 2.1.1 | After 2.1.2 | Now | Subject | +|---|---|---|---|---| +| D198 | D227 | D254 | D272 | Version 2.2.0 and one manual pull | +| D199 | D228 | D255 | D273 | Pages, and the shipped mapping writes the records | +| D200 | D229 | D256 | D274 | The key, the server, and the user id | +| D201 | D230 | D257 | D275 | A page is atomic and a repeat is safe | +| D202 | D231 | D258 | D276 | Work left out of this build | +| D203 | D232 | D259 | D277 | Stored measurements are kept | +| D204 | D233 | D260 | D278 | Meaning, source, and time | +| D205 | D234 | D261 | D279 | Units, windows, reported records, and identities | +| D206 | D235 | D262 | D280 | The new record type and refused originals | +| D207 | D236 | D263 | D281 | The migration rename, the counts, and the archive | +| D208 | D237 | D264 | D282 | The archive's safety facts | +| D209 | D238 | D265 | D283 | A typed workout is a session | +| D210 | D239 | D266 | D284 | Skin-temperature times | +| D211 | D240 | D267 | D285 | Heart-rate recovery of zero | +| D212 | D241 | D268 | D286 | A manual session window | +| D213 | D242 | D269 | D287 | A live workout original | +| D214 | D243 | D270 | D288 | The live vendor read | +| D215 | D244 | D271 | D289 | Vendor originals and credentials | ## Changes on 15 November 2026 The plan was read again against `main` at `0de71bb`, the merge of 2.1.1. These edits follow from that reading: -- D257 and D264. A page is one 2.1.1 import preview and one apply. The +- D275 and D282. A page is one 2.1.1 import preview and one apply. The preview never writes. The apply refuses the page when the database revision moved after the preview. The earlier text counted a page inside a write transaction, rolled the count back, and read the safety facts a second time under the write lock. Version 2.1.1 has no such step. -- D263 and D264. A deleted source or a deleted record leaves its rows out, +- D281 and D282. A deleted source or a deleted record leaves its rows out, as D182 and D190 say. It no longer refuses the page. It still stops the archive of that page. -- D254 and D263. Step 7 runs on the store's own connection. Foreign keys +- D272 and D281. Step 7 runs on the store's own connection. Foreign keys are turned off before its transaction starts, in `src/store/migrate.rs`. -- D255. The pull gives each page to a reader that holds the page in +- D273. The pull gives each page to a reader that holds the page in memory. `MappedReader` in 2.1.1 reads a file path. -- D256. The Open Wearables key is a third `KeyAccount`, beside the gateway +- D274. The Open Wearables key is a third `KeyAccount`, beside the gateway keys and the Garmin token. `ath key clear garmin` stays refused, as it is in 2.1.1. -- D257, D259, D260, and D270. Limits and timeouts are named constants, as +- D275, D277, D278, and D288. Limits and timeouts are named constants, as 2.1.1 does. One response may be at most `MAX_PULL_RESPONSE_BYTES`, which is 10 MiB. The earlier text said 8 MiB. -- D258. The source rules go in `src/import/provider.rs` and a new +- D276. The source rules go in `src/import/provider.rs` and a new `src/import/binding.rs`, where 2.1.1 stages and applies an import. They no longer go in `src/store/write.rs`. The protocol's record writes join the owner writes that store a whole source record. -- D259, D262, and D263. Sentences that called the new migration step 5 now +- D277, D280, and D281. Sentences that called the new migration step 5 now say step 6. Step 5 is the published 2.1.1 migration. These edits answer the thirteen findings of the review at `e145fa6`: -- D269. The stored original's JSON layout, its key, its counts, and owner +- D287. The stored original's JSON layout, its key, its counts, and owner deletion and correction. -- D270. Connections, statuses, Suunto keys, detail rules, timeouts, request +- D288. Connections, statuses, Suunto keys, detail rules, timeouts, request budgets, Garmin windows, id spelling, start times, and the count of every object left out. Garmin windows are 23 hours, not 24, because the pinned server measures a window in naive local time. -- D271. A credential-shaped value is withheld and counted. It no longer +- D289. A credential-shaped value is withheld and counted. It no longer refuses the page. ## Changes after the review at `d636d7a` These edits answer the review of this plan at `d636d7a`: -- D254. A new database runs its migrations on the connection +- D272. A new database runs its migrations on the connection `Store::create` opened, not through `Store::transaction`. The two 2.1.1 checks that expect one transaction to reach the last schema are named, with the check that replaces each. -- D257. The 2.1.1 comment on the 10 MiB response cap names only Garmin. +- D275. The 2.1.1 comment on the 10 MiB response cap names only Garmin. The build rewrites it and the route list to name both pulls. -- D258. The `src/import/provider.rs` list is complete. It adds a +- D276. The `src/import/provider.rs` list is complete. It adds a `connector` source call, because `route_source` stages only `export_file` sources, and a count by record type in `src/import/staging.rs`. The revision a preview read is already public. -- D270. A Garmin detail that answers 404 or 501 is `not_available`, not +- D288. A Garmin detail that answers 404 or 501 is `not_available`, not `failed`. Garmin stays `completed`, and the list object is stored whole. The pinned detail path is not in Garmin's public docs. -- D269. On route `open_wearables`, an owner correction is replaced only +- D287. On route `open_wearables`, an owner correction is replaced only when the server's data differs from the newest revision an import wrote. Each replaced correction is counted per provider and for stored records, in the text, in `--json`, and in the preview. The skill says where a workout fix belongs. -- D270. An HTTP 429 stops that provider for the command, as a timeout +- D288. An HTTP 429 stops that provider for the command, as a timeout does. Credential values are withheld before any comparison. -- D257 and D263. A committed vendor page is a protected write. It sets +- D275 and D281. A committed vendor page is a protected write. It sets `written` and `database_changed`, and its originals add to `committed.source_report`. -- D270. When one Garmin activity id is in two windows with different +- D288. When one Garmin activity id is in two windows with different objects, the later window's copy is kept and the earlier is counted as `superseded`. -- D269. Vendor originals have a 128 MiB total bound, because a package +- D287. Vendor originals have a 128 MiB total bound, because a package holds them in its main document under the 512 MiB read cap. `ath export` refuses to publish a document over that cap. -- D270. A Suunto list object with no `workoutKey` gets no detail call and +- D288. A Suunto list object with no `workoutKey` gets no detail call and is `not_available`. A detail over the response cap is `too_large`, and a detail the privacy scan refuses is `refused`. Both make the provider `incomplete`. -- D270. A preview reads each list and makes no detail call, so a preview +- D288. A preview reads each list and makes no detail call, so a preview then `--yes` reads each list twice and makes each detail call once. One command sends at most 100 Suunto list requests. A detail can come minutes after its list object, and the plan says so. -- D271. The page cursors `next_token` and `nextToken` are not +- D289. The page cursors `next_token` and `nextToken` are not credential-shaped. A user name or password in a URL, and a credential-shaped pair in a URL fragment, are withheld too. -- D270. The daylight-saving sentence names both directions. A forward +- D288. The daylight-saving sentence names both directions. A forward change makes 24 real hours read as 25 local hours, and a backward change makes them read as 23. A zone that moves its clock by two hours is not covered by the 23-hour window. -- D258. The `__proto__` citation names `check_supplied_fields`, which +- D276. The `__proto__` citation names `check_supplied_fields`, which still refuses the key at any depth on import. D214 in 2.1.1 changed only the native reader. -- D270. For Garmin, Suunto, Whoop, and Oura, which name no detail field, a +- D288. For Garmin, Suunto, Whoop, and Oura, which name no detail field, a new detail with fewer fields replaces the stored one, and the stored detail stays in the record's history. -- D257. Each of the four page refusals names the owner's fix, or says +- D275. Each of the four page refusals names the owner's fix, or says 2.2 has none. ## Changes after the review at `3c3f660` @@ -144,16 +148,16 @@ These edits answer the review of this plan at `d636d7a`: These edits answer the reviews of this plan at `3c3f660`. No decision number is added: -- D270. The opening of the specification says what the flag reads on a +- D288. The opening of the specification says what the flag reads on a preview and on `--json`: the connections list and each active provider's list, with no detail call. The help text, the examples, and their test say the same. -- D270. A preview, which every `--json` run is, labels every vendor count +- D288. A preview, which every `--json` run is, labels every vendor count and both owner-correction counts `estimated`. It calls the count of ids `--yes` would detail `would_detail`, prints `estimated` on each provider line, and says that it made no detail calls, in the text and in `vendor_workouts.notice`. -- D270. The first Garmin detail call in a command is a probe. When it +- D288. The first Garmin detail call in a command is a probe. When it answers 400, 403, 404, 405, or 501, no other Garmin detail call is made in that command. The other due ids are `deferred`, Garmin stays `completed`, and its line says detail is unavailable. An id that was @@ -161,11 +165,11 @@ number is added: 401 on any live request stops that provider for the command, as a 429 does. This is the stated default, and the maintainer still has to confirm it. -- D269 and D270. Each Garmin envelope keeps its `upload_window`. On a +- D287 and D288. Each Garmin envelope keeps its `upload_window`. On a later command, a copy from a window that ends at or before the start of the stored copy's window is `superseded`. It writes nothing and never replaces an owner correction. Comparisons leave the window out. -- D269 and D258. The vendor-original bound is 256 MiB, half of the 512 MiB +- D287 and D276. The vendor-original bound is 256 MiB, half of the 512 MiB read cap, counted in the bytes export writes. The earlier bound counted 128 MiB of compact JSON, which could export to about 525 MiB. It holds about 158 one-hour Polar workouts with routes and samples. `ath @@ -174,31 +178,31 @@ number is added: export check also refuses an item past the 128-level nesting limit. Storing originals in their own files is an open question for the maintainer. -- D270. A detail that timed out is `failed`, as one that got 429 or 401 +- D288. A detail that timed out is `failed`, as one that got 429 or 401 is. Only ids still due a detail call become `deferred`. An id due no call keeps its own count. Each id goes in the first group of the detail order it matches, and a `too_large` or `refused` id is no longer in the first group. -- D270. One `--yes` command sends 24 Strava requests when only the last +- D288. One `--yes` command sends 24 Strava requests when only the last request was retried, or 25 after a token reload, which leaves about 75. The ceiling is 84, because the pull cannot see a server retry that ended in success. -- D270 and D258. A vendor object with a `__proto__` key is refused alone +- D288 and D276. A vendor object with a `__proto__` key is refused alone as `unusable_name`, and the provider stays `completed`. The import check would otherwise fail that provider's page on every command. -- D257. The rebind fix says that it merges the two devices' history on +- D275. The rebind fix says that it merges the two devices' history on one source. The source's history keeps the old binding. -- D269. The file-import sentences and the corrected-original test follow +- D287. The file-import sentences and the corrected-original test follow the owner-correction rule. A vendor page's counts stay apart from `archive_committed`. -- D255 and D258. Page counts come from one SQL count beside +- D273 and D276. Page counts come from one SQL count beside `Staging::count`, not from `ProviderPreview::planned`, which copies each row's `data_json`. -- D269. The owner-correction rule reads +- D287. The owner-correction rule reads `record_revisions.became_known_at_basis`, not `changed_by`, because `ath grade` writes the same tool actor as an import. -- D270. The Suunto list cap is named `MAX_SUUNTO_LIST_REQUESTS`. -- D269. A package merge counts as an owner correction only where the +- D288. The Suunto list cap is named `MAX_SUUNTO_LIST_REQUESTS`. +- D287. A package merge counts as an owner correction only where the person resolved a conflict, because `merge_in` copies the package's revisions with their own bases. The counts name that part `merge_choices_replaced`, and the line adds `(M of them merge @@ -212,7 +216,7 @@ number is added: These edits answer the reviews of this plan at `57838e1`. No decision number is added: -- D270. Garmin windows sit on a fixed grid. Each starts at a multiple of +- D288. Garmin windows sit on a fixed grid. Each starts at a multiple of 82,800 seconds after the Unix epoch, and the first and last windows are widened to whole grid windows. So two commands send equal windows or windows that do not overlap, and the earlier-window test always @@ -220,31 +224,31 @@ number is added: Any other overlap, which only a saved file can carry, counts as `ambiguous_window`. The stored copy is kept, and no owner correction is replaced. -- D270. Only a 404 or 501 on the Garmin probe marks the probed id +- D288. Only a 404 or 501 on the Garmin probe marks the probed id `not_available`. Any other error status, except 401 and 429, defers every due id, and the next command probes again. A 5xx also makes Garmin `incomplete`. An id that got 404 or 501 keeps the time as `detail_checked_at` and is asked again after 30 days, or sooner when its list object changes. An original with a current owner correction is asked again only when its list object changes. -- D270 and D258. When only a detail holds a `__proto__` key, the clean +- D288 and D276. When only a detail holds a `__proto__` key, the clean list object is stored with `detail_status` `refused` and `refused_by` `unusable_name`, and the detail is asked for again only when the list object changes. Each refused object and refused detail is named in `left_out.examples` by provider, vendor id, reason, and key path. -- D270 and D269. A vendor object nested 123 levels or more is refused as +- D288 and D287. A vendor object nested 123 levels or more is refused as `too_deep`, counted, and named with its depth. A deep detail keeps its clean list object, as a `__proto__` detail does. The read refuses 128 levels, though `check_nesting` allows 128, so the export check now refuses an item that reaches 128. That is why the cut is 123 and not 124. -- D269. Step 7 creates `vendor_original_sizes`, one row for each +- D287. Step 7 creates `vendor_original_sizes`, one row for each original with its current item's size and the sum of its revision items, as export writes them. A write measures only the items it writes, and the bound and the usage line read the sum. Only `ath check` measures every original again, and `ath repair` fixes a row that differs. -- D270 and D269. Wording. When the probe stops Garmin, its deferred +- D288 and D287. Wording. When the probe stops Garmin, its deferred count adds `(not asked: detail unavailable this run)`. After a 401, the provider's line says to reconnect the provider in Open Wearables if this repeats. A merge choice is a conflict resolved as imported or @@ -257,71 +261,86 @@ number is added: Version 2.1.2 merged on 21 November 2026. It adopted D227 through D253 and published migration step 6. Step 6 stores `2.1.2` and SQL schema 6 in `spec/sql/migrations/006-version-2-1-2.sql`. These proposals moved to -D254 through D271. The migration this plan adds is step 7. It stores -`2.2.0` and SQL schema 7. Steps 1 through 6 stay as published. The 15 -November note above still says that the edit that day changed the -planned migration from step 5 to step 6. That sentence records that -day. The migration in the proposals is step 7. The rest of this plan -is still the reading against version 2.1.1 at `0de71bb`, except the -decision numbers, the migration step, and the version lists. - -## D254. Version 2.2.0 is one manual pull, and the program and the record share that number - -`ath pull openwearables` reads the stored representations D259 lists from an +D254 through D271. The migration this plan then added was step 7. It would +have stored `2.2.0` and SQL schema 7. Steps 1 through 6 stayed as published. +The 15 November note above still says that the edit that day changed the +planned migration from step 5 to step 6. That sentence records that day. +The next section is the reading after version 2.1.3. + +## Changes after version 2.1.3 + +Version 2.1.3 merged on 24 November 2026. It adopted D254 through D271 +and published migration step 7. Step 7 stores `2.1.3` and SQL schema 7 +in `spec/sql/migrations/007-version-2-1-3.sql`. It adds three internal +tables and no athlete-owned column. These proposals moved to D272 through +D289. The migration this plan adds is step 8. It stores `2.2.0` and SQL +schema 8. Steps 1 through 7 stay as published. The section above records +the step 7 plan. The migration in the proposals is step 8. The rest of +this plan is still the reading against version 2.1.1 at `0de71bb`, except +the decision numbers, the migration step, and the version lists. + +## D272. Version 2.2.0 is one manual pull, and the program and the record share that number + +`ath pull openwearables` reads the stored representations D277 lists from an Open Wearables server the person runs, for one user and one range they name. The command is manual. The person runs it. The program does not schedule it, retry a failed request, or sign the person in to a device maker. The program, the record, and the database become `2.2.0` together. D152 made those one number. D184 kept that rule. Version 2.1.1 kept it too. Version -2.1.2 kept it too. Migration step 5 is already published. It stores `2.1.1` -and SQL schema 5 in `spec/sql/migrations/005-version-2-1-1.sql`. Migration -step 6 is already published. It stores `2.1.2` and SQL schema 6 in -`spec/sql/migrations/006-version-2-1-2.sql`. This pull adds step 7. Step 7 -stores `2.2.0` and SQL schema 7. It adds no column to an existing table. It +2.1.2 kept it too. Version 2.1.3 kept it too. Migration step 5 is already +published. It stores `2.1.1` and SQL schema 5 in +`spec/sql/migrations/005-version-2-1-1.sql`. Migration step 6 is already +published. It stores `2.1.2` and SQL schema 6 in +`spec/sql/migrations/006-version-2-1-2.sql`. Migration step 7 is already +published. It stores `2.1.3` and SQL schema 7 in +`spec/sql/migrations/007-version-2-1-3.sql`. This pull adds step 8. Step 8 +stores `2.2.0` and SQL schema 8. It adds no column to an existing table. It rebuilds `provider_summaries` and `provider_scores`, and it creates -`source_reports`, as D261 describes. D263 drops the record views and +`source_reports`, as D279 describes. D281 drops the record views and the two cross-table triggers around the root rename. Existing rows keep -their numbers. Steps 1 through 6 are not edited (D165). Step 6 adds -`athlete_reports.workout_session_id`. Step 7 does not rebuild -`athlete_reports`, so that column stays. +their numbers. Steps 1 through 7 are not edited (D165). Step 6 adds +`athlete_reports.workout_session_id`. Step 7 adds three internal tables and +no athlete-owned column. Step 8 does not rebuild `athlete_reports` or those +internal tables, so that column and those tables stay. -In 2.1.2, `install_schema` in `src/store/mod.rs` runs the whole chain in one +In 2.1.3, `install_schema` in `src/store/mod.rs` runs the whole chain in one transaction with foreign keys on. `Store::create` calls it on a new connection before any `Store` exists, and it opens its own transaction. `ath migrate` and `apply_pending_without_backup` run their steps inside `Store::transaction`, which refuses to write when foreign keys are off. -Step 7 needs them off while it rebuilds tables that other tables point to. -So `install_schema` commits steps 1 through 6 first, and step 7 runs in its -own transaction on the same connection. Step 7 is one function in +Step 8 needs them off while it rebuilds tables that other tables point to. +So `install_schema` commits steps 1 through 7 first, and step 8 runs in its +own transaction on the same connection. Step 8 is one function in `src/store/migrate.rs` that takes the connection, so init and migrate both call it. It turns foreign keys off before that transaction begins, because SQLite ignores the setting inside a transaction, and reads the setting back. The step runs `PRAGMA foreign_key_check` and refuses any row it returns. It sets -`user_version` 7 and commits. Foreign keys are turned on again and read +`user_version` 8 and commits. Foreign keys are turned on again and read back, whether the step committed or not. -Two checks in 2.1.2 expect one transaction to reach the last schema. +Two checks in 2.1.3 expect one transaction to reach the last schema. `install_schema` refuses unless the metadata reads `SQL_SCHEMA_VERSION` -and `ATHLETIC_STANDARD_VERSION` (`src/store/mod.rs`, lines 625 through -629 at `073f9bc`). `apply_steps` refuses unless its last step reached -`SQL_SCHEMA_VERSION` (`src/store/migrate.rs`, lines 327 through 331). With -the constant at 7, both would fail once steps 1 through 6 commit at schema -6. So the first transaction checks for schema 6 and `2.1.2`. `apply_steps` -checks for the last step it was given. The step-7 function checks for -schema 7, `2.2.0`, and `user_version` 7 before it commits. +and `ATHLETIC_STANDARD_VERSION` (`src/store/mod.rs`, lines 628 through +631 at `a3d3eba`). `apply_steps` refuses unless its last step reached +`SQL_SCHEMA_VERSION` (`src/store/migrate.rs`, lines 333 through 337). With +the constant at 8, both would fail once steps 1 through 7 commit at schema +7. So the first transaction checks for schema 7 and `2.1.3`. `apply_steps` +checks for the last step it was given. The step-8 function checks for +schema 8, `2.2.0`, and `user_version` 8 before it commits. `ath migrate` keeps its verified -backup. Inside the step-7 transaction it checks again that the file, the +backup. Inside the step-8 transaction it checks again that the file, the database ID, the schema, and the database revision are the ones its earlier steps left. `MIGRATION_CHAIN` in that file and `spec/sql/contract.json` gain the step. `packages/npm/package.json` exports point at `schema/2.2.0/`. `READABLE_DATABASE_VERSIONS` and `ACCEPTED_RECORD_VERSIONS` keep `1.0.0`, -`2.0.0`, `2.1.0`, `2.1.1`, and `2.1.2`, and gain `2.2.0`. `IMPORTABLE_PACKAGE_VERSIONS` -gains `2.2.0` and keeps `2.0.0`, `2.1.0`, `2.1.1`, and `2.1.2`. A `2.1.2` package -still imports. A `2.1.2` database does not open until `ath migrate`. +`2.0.0`, `2.1.0`, `2.1.1`, `2.1.2`, and `2.1.3`, and gain `2.2.0`. +`IMPORTABLE_PACKAGE_VERSIONS` gains `2.2.0` and keeps `2.0.0`, `2.1.0`, +`2.1.1`, `2.1.2`, and `2.1.3`. A `2.1.3` package still imports. A `2.1.3` +database does not open until `ath migrate`. The build is one pull request after this plan is approved. It is not split into a version change, a client, and a mapping change. @@ -329,13 +348,13 @@ into a version change, a client, and a mapping change. The version numbers below are proposals. They are not specs, and they are not adopted. -- 2.2.0 is this pull. D259 says which stored measurements it keeps. +- 2.2.0 is this pull. D277 says which stored measurements it keeps. - 2.3.0 is a proposed Junction pull. This release does not call Junction. - 2.4.0 is proposed automatic incremental sync, saved sign-in refresh, retries, and backfill. This release has none of those. A smaller page - after the local response cap, described in D259, is not that retry. + after the local response cap, described in D277, is not that retry. - An earlier draft of this plan left day aggregates and the heart-rate - stream out and suggested 2.5.0 for them. D259 supersedes that draft. + stream out and suggested 2.5.0 for them. D277 supersedes that draft. D88 still forbids a fabricated instant. It does not forbid keeping a bound the server sent. - A connector interface that every future source would implement is not @@ -360,12 +379,12 @@ Rejected alternatives: The later version numbers are proposals, not adopted assignments. - Leave day aggregates and the heart-rate stream for a later version, or request them while still calling that later version their home. Superseded - by D259. The current proposal stores them in this pull and says so. + by D277. The current proposal stores them in this pull and says so. -## D255. The pull fetches pages and the shipped mapping writes the records +## D273. The pull fetches pages and the shipped mapping writes the records New module `src/runtime/open_wearables.rs` requests the reads -in D259 and gives each page to the mapping engine. In 2.1.1, `MappedReader` +in D277 and gives each page to the mapping engine. In 2.1.1, `MappedReader` in `src/import/mapping.rs` reads a JSON file from a path. The pull adds a second reader beside it, `MappedPage`, that holds one decoded page in memory. It runs the same checks as `MappedReader::read` and the same @@ -398,7 +417,7 @@ pull does not drop one row and keep its neighbors. The API key, the server's origin or the selected user id echoed in a response, a same-key `device_id` collision, or a bad envelope rejects the whole page first. A value under a credential-shaped key is withheld and counted instead, as -D271 says. A manual workout is written. D265 stores +D289 says. A manual workout is written. D283 stores it as a workout session. The other rows in that page are still written. The timeseries query's `types` list is the `type.` lines in the @@ -412,17 +431,17 @@ no second copy of those names. On Open Wearables 0.11.0 the route defaults `types` to an empty list, and the repository applies a type filter only when the list is nonempty (`data_point_series_repository.py`). An empty list therefore returns every -series. D259 omits `types` on the raw read and the day read for that +series. D277 omits `types` on the raw read and the day read for that reason. A mapping that cannot store those series fails before any network call. A comma-joined type string is still not sent. -`heart_rate` is a series quantity. D259 stores the raw stream as +`heart_rate` is a series quantity. D277 stores the raw stream as measurement samples. Workout `avg_heart_rate_bpm` and `max_heart_rate_bpm` stay as the file already maps them. The pull counts each page by record type and action with one SQL count over its staged plan, beside `Staging::count` in `src/import/staging.rs` -(D258). `ProviderPreview::planned` already lists each row's `record_type` +(D276). `ProviderPreview::planned` already lists each row's `record_type` and `action`, but it also copies each row's whole `data_json`, and a vendor page holds every original's whole envelope. The count reads no record data. The mapped-import report from @@ -435,21 +454,21 @@ when the same match key appears on two pages, or when the server changes between runs. The write still follows D182. This proposal does not keep a command-wide preview overlay. -The read order is the order in D259. A failure in a later read +The read order is the order in D277. A failure in a later read leaves the earlier read's pages committed and the reads after the failure -`not_attempted`. The result says so. See D257. +`not_attempted`. The result says so. See D275. -D259 is the coverage rule. An earlier draft of this decision left the day +D277 is the coverage rule. An earlier draft of this decision left the day rows, the summaries, and the heart-rate stream unrequested. That draft is superseded. D88 still forbids inventing a midnight. The period type in -D259 stores the bound the server sent. An Open Wearables window is not +D277 stores the bound the server sent. An Open Wearables window is not labeled as a Whoop cycle or an Oura day. Sleep requests `include=stages`. Workouts request `include=zones` and `include=segments`. Stage minute totals return either way. The timeline, the zones, and the segments are null when the expansion is omitted, so omitting it would drop them before `supplied_fields` can keep them. A page -over the response cap is handled as D259 says. +over the response cap is handled as D277 says. Rejected alternatives: @@ -460,13 +479,13 @@ Rejected alternatives: the current page rule would leave the page out. The check is `page_rows` and `row_fits` in `src/import/mapping.rs`. - Request every series type and let `left_out` drop the ones the mapping - cannot store. Rejected. D259 stores them. `left_out` remains a row the + cannot store. Rejected. D277 stores them. `left_out` remains a row the server returned and this program refused for a named reason. - Map `heart_rate` samples as points, or map a day summary onto midnight. Rejected. `heart_rate` is stored as a measurement sample. A day row is - stored as a reporting window (D88, D110, D259). + stored as a reporting window (D88, D110, D277). - Refuse an empty `types` list in order to avoid heart rate and location. - Superseded by D259. Omitting `types` is how 0.11.0 returns every series, + Superseded by D277. Omitting `types` is how 0.11.0 returns every series, and those series are stored. A comma-joined string is still not a member of the enum. - Put `device_id` on the sensor string, and therefore on the match key, for @@ -483,7 +502,7 @@ Rejected alternatives: today, because that path is removed as hardware. - Put the receipt in `supplied_fields`, under `device_binding` or another name. Rejected. D185 keeps that object for names the source sent. A 2.1.0 - source may already hold an arbitrary value at that name, and step 7 must + source may already hold an arbitrary value at that name, and step 8 must not turn that value into authority. The receipt is the source object's own key `device_binding`. - Treat a nonempty string at the new key as proof no matter who wrote it, @@ -492,7 +511,7 @@ Rejected alternatives: package restore, and an accepted package merge store the whole source the owner supplied. A hand-edited database file is outside this proposal. -## D256. The key, the server, and the user id stay out of the record +## D274. The key, the server, and the user id stay out of the record The API key is an administrator key for every user on that deployment. The pull sends it only as the header `X-Open-Wearables-API-Key`. It is saved with @@ -536,7 +555,7 @@ the specification's section 9 lists it as a separate follow-up. The server is `--base-url` or `OPEN_WEARABLES_BASE_URL`. The user id is `--user` or `OPEN_WEARABLES_USER_ID`. Neither is written into the database, the export, a config file, or a log line. The pull never calls `GET /users`. -D260 reads the personal record and drops its `user_id` before the scan. +D278 reads the personal record and drops its `user_id` before the scan. Birth date, gender, and sex are stored. One command reads one user. `--base-url` is an origin: scheme, host, and optional port. No user name, no @@ -544,7 +563,7 @@ password, no path other than empty or `/`, no query, and no fragment. `http` is allowed only for `localhost`, `127.0.0.1`, and `::1`. Any other host requires `https`. The pull appends `/api/v1` itself. Redirects are not followed. A timeout, a non-JSON body, or an HTTP error becomes the page -failure in D257. The printed error is a fixed sentence and the HTTP status. A problem `code` +failure in D275. The printed error is a fixed sentence and the HTTP status. A problem `code` is printed only when it is one short token and does not contain the key, the origin, or the user id. Otherwise it is withheld. A transport error or a parser error is replaced with a fixed sentence that has no URL, no path, @@ -554,7 +573,7 @@ After the body is read inside the size cap and parsed, and before the page reaches `MappedPage`, `open_wearables.rs` walks every object key and every string. A value that contains the API key, the selected origin, or the selected user id rejects the whole page. The row is not rewritten. A value -under a credential-shaped key is a different case. D271 withholds that one +under a credential-shaped key is a different case. D289 withholds that one value and counts it. A scan of the raw text misses a Unicode escape. The raw-text scan and the check before printing stay as defense in depth. They are not what keeps the key out of a committed @@ -579,7 +598,7 @@ Rejected alternatives: - List users and pull every user the key can see. Rejected because the key sees the whole deployment, and this record is one athlete. -## D257. A page is atomic, a missing row is not a deletion, and the same command is safe to repeat +## D275. A page is atomic, a missing row is not a deletion, and the same command is safe to repeat Each response page is one 2.1.1 import preview and, under `--yes`, one apply. `preview_route` in `src/import/provider.rs` stages and matches the @@ -594,7 +613,7 @@ D189. A committed page does not mean the pull is complete. The command previews unless `--yes` is present. `--json` does not write, with or without `--yes`, matching `ath import --mapping`. `--yes` without `--json` writes each protected page as that page succeeds. A refused -page is not a success. The pull-only archive in D264 is a separate +page is not a success. The pull-only archive in D282 is a separate preview and apply. It goes ahead only when the database revision has not moved since the protected preview. @@ -605,7 +624,7 @@ confirmed `--yes` has the actual protected and archive counts. `written` is true when a protected transaction in the command created or revised a counted record. An archive does not make it true. `database_changed` is true when a protected transaction or an archive transaction committed a -change. A vendor page (D269) is a protected transaction, so a committed +change. A vendor page (D287) is a protected transaction, so a committed vendor original makes both flags true even when every stored page was unchanged. A successful repeat of an unchanged command has both flags false. The command prints the @@ -650,21 +669,21 @@ true. The personal record and the body snapshot can still be written. Those writes are counted. They are not ranged rows. A repeat uses the match key from D181 and the replace from D182, so an unchanged row is not written again. An owner correction on this route is kept until the server's data -for that record changes (D269). A rerun after a partial write leaves the committed rows in place, +for that record changes (D287). A rerun after a partial write leaves the committed rows in place, runs the failed read again, and runs any read that was `not_attempted`. `has_more: false` is the successful end of a cursor read and of the offset read. A repeated cursor, a null cursor while `has_more` is true, and the 1000-page cap fail that read. An offset retry uses the same offset. A body over the response cap, `MAX_PULL_RESPONSE_BYTES` in `src/input_policy.rs`, -is handled by D260. The failed page is not written. Later reads are +is handled by D278. The failed page is not written. Later reads are `not_attempted`. The success line is not printed. A cursor with the `prev_` prefix is not sent. `limit` starts at 1000. One attempt is made per -request, except the smaller page D260 sends after the response cap. A +request, except the smaller page D278 sends after the response cap. A transport error is not retried. The stored reads use a 30-second connect timeout and a 120-second read timeout, the values `src/runtime/garmin_pull.rs` uses. Live vendor requests use 30 and 360 -seconds, for the reason in D270. Each timeout is a named constant. In +seconds, for the reason in D288. Each timeout is a named constant. In 2.1.1 the comment on `MAX_PULL_RESPONSE_BYTES` calls it one Garmin personal connection response, and the route list above it names only the Garmin pull. The build rewrites both to name the Open Wearables pull too. @@ -685,7 +704,7 @@ records the disagreement between the docs and the 0.11.0 parser. The queries are the table in the specification's section 2. An earlier draft of this proposal listed three reads and treated every page as a -cursor envelope. D260 supersedes that draft. `source_selection` is not +cursor envelope. D278 supersedes that draft. `source_selection` is not sent. On 0.11.0 the parameter does not exist. On current `main`, omitting it returns every device when the priority flag is false. Summary routes still select a source. That selection is not a client filter. @@ -710,7 +729,7 @@ Rejected alternatives: because D88 forbids rewriting a source bound into a timezone the source did not use. -## D258. The Windows cleanup and the maintainability notes are not part of this build +## D276. The Windows cleanup and the maintainability notes are not part of this build Checked again on version 2.1.1 at `0de71bbd6474916af0408a4090bc2c74a1a3aed2`, the merge of pull request 44. The earlier check was version 2.1.0 at @@ -725,16 +744,16 @@ after that. Neither path collects abandoned temporary directories first. working data uses it. The database file is not one of those directories. Version 2.1.0 spec section 12 left the production database cleanup out and named no later version. Version 2.1.1 did not take that work. The cleanup -does not run on a pull. This build does not change it. D264 rolls a failed -step 7 back before this cleanup runs. +does not run on a pull. This build does not change it. D282 rolls a failed +step 8 back before this cleanup runs. `src/import/mapping.rs` is 1703 lines and `src/import/provider.rs` is 1297. The store is already several files. `src/store/mod.rs` is 848 lines, `src/store/write.rs` is 508, `src/store/encode.rs` is 549, and `src/store/check.rs` is 1044. `persist.rs` is gone. The pull is a new module so `mapping.rs` and the store files do not grow for HTTP. -`mapping.rs` may add `MappedPage`, which D255 names, and the -`vendor_workout` section, which D269 names. D259 also adds the +`mapping.rs` may add `MappedPage`, which D273 names, and the +`vendor_workout` section, which D287 names. D277 also adds the measurement-sample target, the reporting-window write, and the segment copy. Nothing beyond that is added to `mapping.rs`. @@ -752,13 +771,13 @@ That first bind is a source correction with the source's expected revision. `ProviderPreview::apply` refuses any other staged change to `device_binding`. Those writes keep every other source field and the normal revision and `data_json` bookkeeping. `provider.rs` also gains the -crate-private read of a stored vendor original that D270 uses. It gains +crate-private read of a stored vendor original that D288 uses. It gains `connector_source` beside `route_source`, because `route_source` stages only an `export_file` source that names a vendor. The writer `open_wearables` sources, the archive source, and each `vendor_workout` source are `connector` sources with no vendor. `Staging::count` in `src/import/staging.rs` counts by action only, so a count by record type -goes beside it for the page counts. D255 uses it instead of counting +goes beside it for the page counts. D273 uses it instead of counting `ProviderPreview::planned`, which copies each row's `data_json`. The revision a preview read is already public as `ProviderPreview::destination_database_revision`. @@ -769,20 +788,20 @@ library writes store a whole source record: `ath correct`, the protocol operations `records.write`, `records.write_changes`, and `records.correct`, native package restore, and an accepted package merge. They keep the receipt the caller supplied. `Store` keeps its connection private (D223). -D260 also allows `measurement_sample` insert and update, and a null value +D278 also allows `measurement_sample` insert and update, and a null value and unit pair on provider summaries and provider scores. A half-null pair is refused. `write_current_state` in `src/store/encode.rs` is the only record-to-table mapping. Package restore, repair, and the record check use -it. There is no TypeScript writer to update. D261 also allows +it. There is no TypeScript writer to update. D279 also allows `source_report` insert and update, and withdrawal of a child whose anchor -is in this response. D269 adds the vendor-original size check to +is in this response. D287 adds the vendor-original size check to `apply_in` in `src/store/write.rs`, for a change that writes an original. Nothing beyond that is added to the store. Other routes do not call the receipt operations. Splitting `mapping.rs` is separate work. It is not required to make the pull correct. `ath key clear garmin` is refused in 2.1.1, because `key_clear` in -`src/cli/commands/model.rs` accepts only gateway names. D256 keeps that. +`src/cli/commands/model.rs` accepts only gateway names. D274 keeps that. Making the Garmin key removable is separate work. `check_supplied_fields` is in `src/import/shared.rs`. A keyed import calls @@ -791,7 +810,7 @@ it before it builds a candidate (D191). It refuses an empty name and a native reader, which keeps such a key and checks it, so the import refusal still applies. There is no `persist.rs` and no `ath-core persist` command. The pull writes through `MappedPage` and the -2.1.1 import, so the import check covers it. The vendor read in D270 runs +2.1.1 import, so the import check covers it. The vendor read in D288 runs the same check on each vendor object first. A list object with the key is refused alone. A detail with the key is refused, and its clean list object is stored. A name check outside import is separate work. @@ -811,14 +830,14 @@ Rejected alternatives: write, and the one automatic source writer is `ProviderPreview::apply`. A rule in `Store::apply` would also block the owner's own correction. -## D259. Stored Open Wearables measurements are kept in this pull +## D277. Stored Open Wearables measurements are kept in this pull -D260 supersedes the classification, source identity, time, score, endpoint, -and size sentences in this proposal. D261 supersedes D260 where they +D278 supersedes the classification, source identity, time, score, endpoint, +and size sentences in this proposal. D279 supersedes D278 where they disagree. The decision to keep the returned health data in this pull -stands. Where a paragraph below disagrees with D264, D264 is the proposal. +stands. Where a paragraph below disagrees with D282, D282 is the proposal. -This supersedes the earlier draft, inside D254 and D255, that left day +This supersedes the earlier draft, inside D272 and D273, that left day values, the heart-rate stream, sleep and recovery summaries, meals, and workout segments out of this pull. Those drafts are not deleted above. They are not the current proposal. The specification's section 2 is the @@ -857,29 +876,29 @@ Rejected alternatives: make a reporting window look like one instant (D88, D110). - Drop latitude, longitude, segments, or a large series to keep a response under the response cap. Rejected. The smaller page in the specification - stores the rows. D260 states the minimum-page limit without naming a + stores the rows. D278 states the minimum-page limit without naming a series type. - Call the live provider workout proxy or the totals routes so the pull can say it hit every path. Rejected. Those routes are not the stored - measurements. D260 does read the personal record. An earlier sentence + measurements. D278 does read the personal record. An earlier sentence in this list left it out. That sentence is superseded. - Invent a midnight, a zero, or an SDNN value from an RMSSD value. Rejected. A null stays absent. `RecoverySummary` at the pinned commit has no skin-temperature field. A health-score component can still carry - one. D260 says so. + one. D278 says so. -## D260. Returned values keep their meaning, source, and time +## D278. Returned values keep their meaning, source, and time -D261 supersedes the sentences below that call dietary or index series +D279 supersedes the sentences below that call dietary or index series provider summaries, that store a day row as the same class as its raw sample, that build a sensor by joining parts with `:` and `-`, that put main-sleep bounds on a summed field, that leave a missing device id as `left_out`, that omit a manual workout, and that treat `received_at` as the time a revision was written. The values stay in this pull. The -device-receipt rules stay. Where this proposal disagrees with D261, D261 +device-receipt rules stay. Where this proposal disagrees with D279, D279 is the proposal. -This corrects D259. The corrections that D261 does not replace are the +This corrects D277. The corrections that D279 does not replace are the contracts in the specification's section 2. A device source is still the 2.1.0 sensor, and its receipt rules are @@ -944,20 +963,20 @@ Rejected alternatives: - Stop a day read at `limit` 1 and report one oversized series. Rejected. That limit counts periods, and one period can hold many rows. -## D261. Units, windows, reported records, and identities stay distinct +## D279. Units, windows, reported records, and identities stay distinct -D262 supersedes the sentences below that put every source-present series +D280 supersedes the sentences below that put every source-present series through the device check, that compare null-source rows by type and timestamp alone, that leave a refused original unstored in every case, that map `heart_rate_recovery_one_minute` to a quantity of that same name, and that call `hydration` a measurement sample. The units, day -windows, sleep bounds, and reported-record direction stay. D263 -supersedes D262 where they disagree. D264 supersedes D263 where they -disagree. Where this proposal disagrees with D264, D264 is the proposal, +windows, sleep bounds, and reported-record direction stay. D281 +supersedes D280 where they disagree. D282 supersedes D281 where they +disagree. Where this proposal disagrees with D282, D282 is the proposal, except the sentences that store a manual workout as a source report. -D265 supersedes those sentences. +D283 supersedes those sentences. -This corrects D260. The returned health data stays in this pull. The +This corrects D278. The returned health data stays in this pull. The specification's section 2 and the appendix series table are the contract. Every series has an input number, an input unit, a standard number, and a @@ -996,7 +1015,7 @@ nutrient numbers, index, age, and effort series, personal-record fields, predicted and coded cycle content, BMI, calculated age, and an unbounded health score use this type. The eight range calculations and `provider-period-summary` do not read it. A manual workout is a workout -session. D265 is that rule. An automatic workout stays a measured +session. D283 is that rule. An automatic workout stays a measured session on the device source. A new sensor is `ow1:` plus a JSON array with no spaces. JSON `null`, an @@ -1009,7 +1028,7 @@ Two unequal payloads at the same type and time refuse the call. The personal record uses `["personal_record"]` and that same writer. A meal or cycle uses the event array even when `device_id` is present. That id stays in the array and in the original object. It does not establish -`device_binding`. A manual workout does not use that array. D265 puts it +`device_binding`. A manual workout does not use that array. D283 puts it on the manual source. A raw or day row whose `source` object has no `device_id` is an incoming @@ -1056,23 +1075,23 @@ Rejected alternatives: SPEC section 5.4 and D161 keep those measured types for measured records. A source report preserves the object without making it a measurement. -- Call a manual workout a provider summary. Rejected. D265 stores it as +- Call a manual workout a provider summary. Rejected. D283 stores it as a workout session. It is not a provider summary. - Leave a removed nutrient current because the store compares emitted keys. Rejected. The same object no longer contains that number. -## D262. The new record type, numberless inputs, and refused originals stay separable +## D280. The new record type, numberless inputs, and refused originals stay separable -D263 supersedes the sentences below that leave the record views in place +D281 supersedes the sentences below that leave the record views in place during the rename, that set `written` false for an archive without defining `database_changed`, that archive a page from the first error, that hash the series row without its resolution, and that give a null-source reported series both the report sensor and the unattributed sensor. The root check, the numberless readers, and the reported-record -direction stay. D264 supersedes D263 where they disagree. Where this -proposal disagrees with D264, D264 is the proposal. +direction stay. D282 supersedes D281 where they disagree. Where this +proposal disagrees with D282, D282 is the proposal. -This corrects D261. The returned health data stays in this pull. The +This corrects D279. The returned health data stays in this pull. The specification is the contract. `records.record_type` is a closed check. `source_report` is not in it. @@ -1082,7 +1101,7 @@ not edit migrations 001 through 006, and it does not drop the check. Ordinary writes keep foreign keys on. The migration connection may turn them off only before its own transaction, rebuild `records` and the two nullable typed tables by copy, rename, and recreate, then require -`foreign_key_check` and `integrity_check` before commit. D263 drops the +`foreign_key_check` and `integrity_check` before commit. D281 drops the two record views and the two cross-table triggers before that rename and recreates them unchanged. A drop of `records` inside the ordinary foreign-key transaction is not the @@ -1116,8 +1135,8 @@ id with a different kind refuses the page. A refused protected page is not applied, so it writes nothing. For a missing device id on a device-targeted series row, and for unequal null-source payloads of one full match key, a later archive preview and -apply stores kind `original` with no amount and no device receipt. D264 -is when that archive may write. D263 is the capsule and the command counts. `written` stays false when only the archive +apply stores kind `original` with no amount and no device receipt. D282 +is when that archive may write. D281 is the capsule and the command counts. `written` stays false when only the archive changed. The command exits nonzero. Credential failures, invalid ids, conflicting device ids, legacy history, and kind changes are not archived. Those originals are @@ -1148,15 +1167,15 @@ Rejected alternatives: second transaction with a failed protected-write status. The other refusal reasons stay unstored. -## D263. The migration rename, the command counts, and the archive decision stay consistent +## D281. The migration rename, the command counts, and the archive decision stay consistent -D264 supersedes the sentences below that classify database facts before +D282 supersedes the sentences below that classify database facts before either transaction, that leave the archive with only an archive-source check, and that leave a failed init file in place. The migration graph, the command counts, the capsule, and the report routing stay. Where this -proposal disagrees with D264, D264 is the proposal. +proposal disagrees with D282, D282 is the proposal. -This corrects D262. The returned health data stays in this pull. The +This corrects D280. The returned health data stays in this pull. The specification is the contract. Step 7 drops `sql_v1_current_records`, `sql_v1_active_records`, and the @@ -1181,7 +1200,7 @@ and leaves earlier commits. The pull text for a new archive-only change is `Protected write refused; N originals archived; database changed; pull incomplete.` -D264 reads database-dependent vetoes in the protected preview, at one +D282 reads database-dependent vetoes in the protected preview, at one database revision. The archive goes ahead only at that same revision. A veto there, including on a `left_out` row, forbids the archive. A deleted source or a deleted record leaves its rows out (D182, D190) and also @@ -1215,9 +1234,9 @@ Rejected alternatives: - Hash the series row and infer the resolution later. Rejected. The resolution is on the response, not on the row. -## D264. The archive goes ahead only at the revision where the safety facts were read +## D282. The archive goes ahead only at the revision where the safety facts were read -This corrects D263. The returned health data stays in this pull. The +This corrects D281. The returned health data stays in this pull. The specification is the contract. The first version of this decision read the safety facts under one write lock and read them again under a second one. Version 2.1.1 has no write-locked preview, so this version uses the @@ -1249,11 +1268,11 @@ archive identity. A deleted archive source is not recreated. A deleted capsule is not replaced. If the page names a row the bounded read cannot cover, the page is not archived. There is no retry. -A failed step 7 during init rolls back to the committed step 6 schema -before the existing init cleanup runs. Init fails. D258's cleanup is -unchanged. A migrate of an existing 2.1.2 database keeps that file and -schema 6 when step 7 rolls back. An older database keeps the steps that -committed before step 7, as D254 says. +A failed step 8 during init rolls back to the committed step 7 schema +before the existing init cleanup runs. Init fails. D276's cleanup is +unchanged. A migrate of an existing 2.1.3 database keeps that file and +schema 7 when step 8 rolls back. An older database keeps the steps that +committed before step 8, as D272 says. Rejected alternatives: @@ -1267,13 +1286,13 @@ Rejected alternatives: - Recheck only the archive source before the archive. Rejected. The owner can delete the original source or record in between, and the payload would be stored under a new identity. -- Leave a failed init file at step 6. Rejected. The existing caller +- Leave a failed init file at step 7. Rejected. The existing caller removes that file, and this build does not change that cleanup. -## D265. A workout the person typed is a workout session +## D283. A workout the person typed is a workout session -This supersedes only the sentences in D254 and D261 that store a manual -workout as a source report or leave it out. D254 through D264 otherwise +This supersedes only the sentences in D272 and D279 that store a manual +workout as a source report or leave it out. D272 through D282 otherwise stay as written. The specification is the contract. `entry_source` `manual` is a `workout_session`. Its source type is @@ -1284,7 +1303,7 @@ workout on the watch's source. The server workout id is the match key, so a later pull updates the same workout. Name, type, start, end, distance, heart rate, elevation, zones, and segments are stored the same way they are stored on an automatic workout. `activity_type` still -records that Open Wearables normalized the sport name. D268 corrects the +records that Open Wearables normalized the sport name. D286 corrects the next rule. The numbers on this session do not enter the eight range calculations or `provider-period-summary`. `workout-drift` may use the session's start and end when the caller names that session. The samples @@ -1304,7 +1323,7 @@ Rejected alternatives: - Treat `unknown`, JSON null, or a missing `entry_source` as manual. Rejected. Those values are not the self-reported entry. -## D266. A body skin-temperature time is not an instant by itself +## D284. A body skin-temperature time is not an instant by itself This corrects the sentence that treats a non-null `skin_temperature_measured_at` as a measurement instant. The other body @@ -1327,7 +1346,7 @@ Rejected alternatives: - Drop the timestamp. Rejected. The original object keeps what the server sent. -## D267. A finite heart-rate recovery stays, including zero +## D285. A finite heart-rate recovery stays, including zero This corrects the positive point gate for one quantity. The quantity, the unit, and the import key stay `hr_recovery` and `bpm`. @@ -1349,9 +1368,9 @@ Rejected alternatives: zero for this quantity. - Allow zero for every point. Rejected. The other positive checks stay. -## D268. A manual session can set a window, and its numbers stay out +## D286. A manual session can set a window, and its numbers stay out -This corrects the D265 sentence that says the calculations do not read a +This corrects the D283 sentence that says the calculations do not read a manual workout. It does not change the calculation code. `read_inputs` and `read_period` exclude `source_type` `manual`. They have @@ -1375,9 +1394,9 @@ Rejected alternatives: - Let a manual heart rate enter a baseline when `include_manual` is set. Rejected. The calculation SQL has no such switch. -## D269. A provider-live workout is kept as an original +## D287. A provider-live workout is kept as an original -D270 is the live-read procedure. D271 is the privacy choice. Where this +D288 is the live-read procedure. D289 is the privacy choice. Where this proposal disagrees with either, those decisions are the proposal. The stored workout list is the normalized session. The provider route @@ -1410,14 +1429,14 @@ The rewritten `mappings/open-wearables.md` gains a section named writer, the sensor, the key, and the start. A saved file of envelopes imports through that section. File import writes each envelope as the file holds it, as D182 does for every mapped import, except the -owner-correction rule below and the Garmin window rule in D270. The +owner-correction rule below and the Garmin window rule in D288. The detail rules in -D270 run before the mapping engine sees an envelope, so the mapping +D288 run before the mapping engine sees an envelope, so the mapping engine has no vendor exception. The pull writes one provider's originals as one page, after that provider's list and detail calls finish. That page is one preview and, -under `--yes`, one apply, as D257 says for every page. A vendor page +under `--yes`, one apply, as D275 says for every page. A vendor page never holds a stored row or an archive capsule. A failed or refused vendor page leaves that provider `incomplete`. It does not change the stored pages or the archive. @@ -1446,7 +1465,7 @@ route, so a workout fix on the stored session also survives a pull of unchanged data. For that route it supersedes the D182 sentence that a mapped import replaces a changed object. Other routes keep D182. That scope is the stated default, and the maintainer still has to confirm it. -The stored-original read in D270 uses the same import revision, so an +The stored-original read in D288 uses the same import revision, so an owner's edit does not trigger a detail call. The skill says that a workout fix belongs on the session or in a note, not on the vendor original. Deleting an original keeps the person's version in its history @@ -1571,9 +1590,9 @@ Rejected alternatives: name an edit the person never made, so the counts name merge choices as their own part. -## D270. A live vendor read is opt-in, and one failure stays on that provider +## D288. A live vendor read is opt-in, and one failure stays on that provider -This supersedes the D269 sentences that said a live GET does not write on +This supersedes the D287 sentences that said a live GET does not write on the server, that a failed provider stops the later providers, that Polar's list asks for samples, zones, and route, that a start outside the range is dropped, and that the server splits a Garmin range. @@ -1680,7 +1699,7 @@ Sensorbio reads only the oldest 50 entries, and its line says so. A stored detail is never lost. A detail is fetched for an id with no stored detail, unless an earlier command marked it `not_available` less than 30 days before, and again only when the list object changed. Credential -values (D271) are withheld before any comparison, so a token that changed +values (D289) are withheld before any comparison, so a token that changed between pulls does not make a list object look changed. A list-only object never replaces a stored detail. A new detail that is thinner than the stored one writes nothing. Thinner means a detail field the @@ -1884,7 +1903,7 @@ Rejected alternatives: the read parses the document, so a 123-level object would be stored and then fail to read back. -## D271. Vendor originals stay whole. The maintainer can change this +## D289. Vendor originals stay whole. The maintainer can change this This is a labeled choice. The default in this proposal is to keep each vendor object whole, including account ids, Polar user URLs, and full GPS diff --git a/build-history/v2.2.0/progress.md b/build-history/v2.2.0/progress.md index ab50c0bc..42f1de02 100644 --- a/build-history/v2.2.0/progress.md +++ b/build-history/v2.2.0/progress.md @@ -5,10 +5,10 @@ program, the record, or the database has changed for 2.2.0. | Step | What | Status | |---|---|---| -| 0 | The plan: proposals D254–D271, and the Open Wearables study. The proposals were D198–D215 until 2.1.1 used D208–D226, then D227–D244 until 2.1.2 used D227–D253. Checked against 2.1.1 at `0de71bb` on 15 November 2026: a page is one import preview and one apply, and D264 uses the revision check. D266 through D268 stay. D269 and D270 answer the review at `e145fa6`. D271 withholds a credential-shaped value. The pass after the review at `d636d7a` amends D254, D257, D258, D263, D269, D270, and D271. The pass after the reviews at `3c3f660` amends D255, D257, D258, D269, and D270 and adds no decision number. The pass after the reviews at `57838e1` amends D258, D269, and D270 and adds no decision number. Three questions stay open for the maintainer, in section 10 of the specification: the Garmin detail default, the owner-correction scope, and storing vendor originals in their own files. Still not adopted. The new head needs a fresh review | written, not approved | -| 1 | Version 2.2.0 and migration step 7. Step 5 is the published 2.1.1 migration. Step 6 is the published 2.1.2 migration. No new column on an existing table. The root check gains `source_report` by the copy in D263. Summary and score values may be omitted in pairs (D254, D263) | not started | -| 2 | `ath pull openwearables` in the `athleticstandard` crate, with the rewritten mapping (D255, D257, D263) | not started | -| 3 | Key, server, and user id kept out of the record (D256) | not started | +| 0 | The plan: proposals D272–D289, and the Open Wearables study. The proposals were D198–D215 until 2.1.1 used D208–D226, then D227–D244 until 2.1.2 used D227–D253, then D254–D271 until 2.1.3 used D254–D271. Checked against 2.1.1 at `0de71bb` on 15 November 2026: a page is one import preview and one apply, and D282 uses the revision check. D284 through D286 stay. D287 and D288 answer the review at `e145fa6`. D289 withholds a credential-shaped value. The pass after the review at `d636d7a` amends D272, D275, D276, D281, D287, D288, and D289. The pass after the reviews at `3c3f660` amends D273, D275, D276, D287, and D288 and adds no decision number. The pass after the reviews at `57838e1` amends D276, D287, and D288 and adds no decision number. Three questions stay open for the maintainer, in section 10 of the specification: the Garmin detail default, the owner-correction scope, and storing vendor originals in their own files. Still not adopted. The new head needs a fresh review | written, not approved | +| 1 | Version 2.2.0 and migration step 8. Step 5 is the published 2.1.1 migration. Step 6 is the published 2.1.2 migration. Step 7 is the published 2.1.3 migration. No new column on an existing table. The root check gains `source_report` by the copy in D281. Summary and score values may be omitted in pairs (D272, D281) | not started | +| 2 | `ath pull openwearables` in the `athleticstandard` crate, with the rewritten mapping (D273, D275, D281) | not started | +| 3 | Key, server, and user id kept out of the record (D274) | not started | | 4 | Fixture tests, with no live key in CI | not started | | 5 | Generated schema, demo athlete, skill command reference, and the public-data list | not started | | 6 | Laptop card and the proof in the build pull request | not started | @@ -17,4 +17,4 @@ The build, after approval, is one pull request. It is not three. The Windows failed-init cleanup, the size of `src/import/mapping.rs`, a way to clear the Garmin key, and a name check outside import stay out of -that pull request (D258). `persist.rs` is already gone. +that pull request (D276). `persist.rs` is already gone. diff --git a/build-history/v2.2.0/spec.md b/build-history/v2.2.0/spec.md index bab4f226..a2fda863 100644 --- a/build-history/v2.2.0/spec.md +++ b/build-history/v2.2.0/spec.md @@ -6,7 +6,7 @@ Status: **plan only. The maintainer has not approved it. Not approved for build. Wearables server they run. When `--vendor-workouts` is passed, it also reads the live workout list and detail. It writes the stored reads with the mapping this release ships. It writes a live original only when that -flag is on and the person confirms the write. The proposals are D254 through D271 in +flag is on and the person confirms the write. The proposals are D272 through D289 in [decisions.md](decisions.md). They are not adopted. The evidence is [appendix/open-wearables-api.md](appendix/open-wearables-api.md), checked on 6, 7, 8, and 14 November 2026. @@ -21,9 +21,13 @@ software this plan is read against. That commit is the merge of pull request `8db90b42ac654767e9e9570a121bbbd4fde3348a`, the merge of pull request 39. Version 2.1.2 on `main` `073f9bce8537b9f720e8dd5365919ef99684f116` is the -software now. That commit is the merge of pull request 45. It adopted -D227 through D253 and published migration step 6. This plan's proposals -are D254 through D271, and the migration it adds is step 7. The reading +merge of pull request 45. It adopted D227 through D253 and published +migration step 6. + +Version 2.1.3 on `main` `a3d3ebafa4bff45aca1a8642ac91be999c10db60` is the +software now. That commit is the merge of pull request 47. It adopted +D254 through D271 and published migration step 7. This plan's proposals +are D272 through D289, and the migration it adds is step 8. The reading below is still against version 2.1.1, except the decision numbers, the migration step, and the version lists. @@ -337,7 +341,7 @@ only for `openwearables`, and they are flags, not environment variables. `--base-url` and `--user` are required for `openwearables` unless the environment named above supplies them. `--base-url` already exists for `garmin`, where it names a test server's API root. For `openwearables` it -names the server origin, as D256 says. `ath pull garmin --date YYYY-MM-DD` +names the server origin, as D274 says. `ath pull garmin --date YYYY-MM-DD` is otherwise unchanged, and it still writes without a preview. `ath pull` with any other name still fails. The failure text `pull currently reads garmin` becomes `pull reads garmin or openwearables`. @@ -374,21 +378,21 @@ gateway commands they are today. ## 2. What this pull stores -This section is the storage rule, as D259 says. D259 keeps these values -in this pull. D260 corrected source, time, and score direction. D261 corrects units, day +This section is the storage rule, as D277 says. D277 keeps these values +in this pull. D278 corrected source, time, and score direction. D279 corrects units, day windows, sleep bounds, identity encoding, reported records, and child -withdrawal. D262 corrects the root record type, numberless calculation +withdrawal. D280 corrects the root record type, numberless calculation inputs, recovery scales, required ids, workout provenance, hydration, -and the archive of a refused original. D263 corrects the migration +and the archive of a refused original. D281 corrects the migration dependencies, the command counts, the archive capsule, and null-source -report routing. D264 corrects when the archive reads the database, and -the failed-init sentence. D265 stores a workout the person typed as a -workout session. D266 keeps a body skin-temperature time unknown when the -response does not say it is an instant. D267 keeps a finite -`hr_recovery`, including zero and a negative number. D268 keeps the -current manual-session calculation rule. D269 stores the live -workout list and detail as originals. D270 is the live-read procedure. -D271 keeps each vendor object whole. An earlier draft +report routing. D282 corrects when the archive reads the database, and +the failed-init sentence. D283 stores a workout the person typed as a +workout session. D284 keeps a body skin-temperature time unknown when the +response does not say it is an instant. D285 keeps a finite +`hr_recovery`, including zero and a negative number. D286 keeps the +current manual-session calculation rule. D287 stores the live +workout list and detail as originals. D288 is the live-read procedure. +D289 keeps each vendor object whole. An earlier draft left day values, the heart-rate stream, summaries, and workout segments for a later version. That draft is superseded. File imports stay. The Garmin pull stays. A Junction pull is proposed as 2.3.0. Automatic sync, retries, token refresh, and backfill are proposed as @@ -1249,7 +1253,7 @@ timeout above. a vendor's status through unchanged, and the route answers 501 only for a provider it has no workout method for, so this study cannot tell a missing path from a missing activity. This is the plan's stated - default. The maintainer still has to confirm it (D270). + default. The maintainer still has to confirm it (D288). - Polar. The list sends `samples`, `zones`, and `route` false, the route's default, so the list stays small. Detail sends all three true. A list over the response cap fails that list, because the route has no smaller @@ -2077,7 +2081,7 @@ built without that field. Day rows carry it, and those rows are stored. ## 4. Credentials, privacy, and the network -D256 is the rule. The key never enters the athlete database, the export, the +D274 is the rule. The key never enters the athlete database, the export, the preview, or an error line. The pull reads the paths in section 2. Connections and the two live workout routes are included only when `--vendor-workouts` is on. It does not list users. A raw HTTP personal-record response includes `user_id`. That field must @@ -2144,7 +2148,7 @@ an optional `userAccessToken`. The pinned server declares it on its Garmin wellness models, and the live route returns Garmin's objects unchanged. Refusing the page would refuse every Garmin page that carries it. `polar_user` and a route coordinate are not credential-shaped. -D271 keeps the rest of the vendor object, including account ids, Polar +D289 keeps the rest of the vendor object, including account ids, Polar user URLs, and full routes. The matching personal-record `user_id` is the only field of a stored read that is dropped before this walk. Any other copy of the user id still rejects the page. The connections list is not @@ -2177,20 +2181,22 @@ reads in section 2, no user list. ## 5. Version, migration, and what stays compatible The build sets `2.2.0` on the package, the record, and the -`athleticstandard` crate, by the same constants 2.1.2 uses. +`athleticstandard` crate, by the same constants 2.1.3 uses. `ATHLETIC_STANDARD_VERSION` is in `src/model/package.rs`. `SQL_SCHEMA_VERSION` is in -`src/store/migrate.rs`. Migration step 7 is a new SQL file and a narrow +`src/store/migrate.rs`. Migration step 8 is a new SQL file and a narrow runner arm. Step 5 is already `spec/sql/migrations/005-version-2-1-1.sql`. Step 6 is already -`spec/sql/migrations/006-version-2-1-2.sql`. Step 7 updates -`athleticstandard_version` to `2.2.0` and `sql_schema_version` to 7. No +`spec/sql/migrations/006-version-2-1-2.sql`. Step 7 is already +`spec/sql/migrations/007-version-2-1-3.sql`. Step 8 updates +`athleticstandard_version` to `2.2.0` and `sql_schema_version` to 8. No column is added to an existing table. The contract adds `source_report` to the `records.record_type` check, creates `source_reports` and `vendor_original_sizes`, and rebuilds `provider_summaries` and -`provider_scores` as section 2 describes. Files `001` through `006` stay +`provider_scores` as section 2 describes. Files `001` through `007` stay byte-identical. Step 6's nullable `athlete_reports.workout_session_id` -stays. Step 7 does not rebuild that table. The check is not removed, and +stays. Step 7's three internal tables stay. Step 8 does not rebuild those +tables. The check is not removed, and ordinary store writes do not turn foreign keys off. SQLite cannot change that check in place. `records` and @@ -2202,28 +2208,28 @@ attachments, reporting periods, and the other child tables, use `records`. `PRAGMA foreign_keys` does not change inside a transaction. `configure` in `src/store/mod.rs` requires foreign keys on before `install_schema` runs. A `DROP TABLE records` inside that transaction -would fail or cascade through the children. Step 7 does not do that. +would fail or cascade through the children. Step 8 does not do that. `write_transaction` in the same file refuses to write when foreign keys are off. `Store::transaction` uses it. `ath migrate` and -`apply_pending_without_backup` run steps 2 through 6 through +`apply_pending_without_backup` run steps 2 through 7 through `Store::transaction`. A new database does not. `Store::create` opens a connection, runs `configure` and `enable_wal`, and calls `install_schema` on that connection before any `Store` exists. `install_schema` opens its own transaction with `rusqlite::Transaction::new_unchecked`. -Today `install_schema` runs the whole chain, steps 1 through 6, in that +Today `install_schema` runs the whole chain, steps 1 through 7, in that one transaction. It sets `user_version` to `SQL_SCHEMA_VERSION`. Then it refuses unless the metadata reads `SQL_SCHEMA_VERSION` and -`ATHLETIC_STANDARD_VERSION`, in `src/store/mod.rs` lines 625 through 629 -at `073f9bc`. `apply_steps` in `src/store/migrate.rs` has the same kind of -final check, in lines 327 through 331. It refuses unless the last step it -ran reached `SQL_SCHEMA_VERSION`. When the constant becomes 7 and steps 1 -through 6 commit at schema 6, both checks would fail. So the build changes -both. The first `install_schema` transaction stops after step 6, sets -`user_version` 6, checks for schema 6 and `2.1.2`, and commits. +`ATHLETIC_STANDARD_VERSION`, in `src/store/mod.rs` lines 628 through 631 +at `a3d3eba`. `apply_steps` in `src/store/migrate.rs` has the same kind of +final check, in lines 333 through 337. It refuses unless the last step it +ran reached `SQL_SCHEMA_VERSION`. When the constant becomes 8 and steps 1 +through 7 commit at schema 7, both checks would fail. So the build changes +both. The first `install_schema` transaction stops after step 7, sets +`user_version` 7, checks for schema 7 and `2.1.3`, and commits. `apply_steps` checks that it reached the last step it was given. The -step-7 function makes the final check before it commits: schema 7, -`2.2.0`, and `user_version` 7. +step-8 function makes the final check before it commits: schema 8, +`2.2.0`, and `user_version` 8. Step 7 is one function in `src/store/migrate.rs`. It takes the connection and opens its own transaction. At init it runs on the @@ -2262,11 +2268,11 @@ Inside that one transaction the order is fixed. 6. Recreate the two views and the two cross-table triggers from that same text, unchanged. 7. Create `source_reports` and its type trigger, and - `vendor_original_sizes`. A 2.1.2 database has no vendor original, so + `vendor_original_sizes`. A 2.1.3 database has no vendor original, so the new table starts empty. 8. `PRAGMA foreign_key_check` is empty and `PRAGMA integrity_check` is `ok`. -9. Set the version rows and `user_version` 7. +9. Set the version rows and `user_version` 8. `sql_v1_database_info`, `sql_v1_record_revisions`, and `sql_v1_record_deletions` do not name `records`, so they stay through the @@ -2280,22 +2286,22 @@ cross-table triggers, the old check, the rows, and the version. The D124 backup is already on disk. Device receipts stay in the copied source JSON. They are not rewritten. -A new database commits migration steps 1 through 6, then runs step 7. -Item 9 in the list above sets `user_version`. If step 7 fails during init, that transaction -rolls back to the committed step 6 schema before the existing failed-init +A new database commits migration steps 1 through 7, then runs step 8. +Item 9 in the list above sets `user_version`. If step 8 fails during init, that transaction +rolls back to the committed step 7 schema before the existing failed-init cleanup runs. Init reports failure. `Store::create` still calls `remove_partial_database`, which deletes the new file, the wal file, and -the shm file. D258 leaves that cleanup in place, and this build does not +the shm file. D276 leaves that cleanup in place, and this build does not change it. A file that cleanup does not delete is not left with the views dropped. A migrate of a database that already existed is a separate case. `apply_after_backup` and `apply_pending_without_backup` in -`src/store/migrate.rs` run the steps up to 6 in `Store::transaction`, as -2.1.2 does, and commit. They then run step 7 in its own transaction. For a -2.1.2 database, a step 7 rollback leaves the file at schema 6 with foreign +`src/store/migrate.rs` run the steps up to 7 in `Store::transaction`, as +2.1.3 does, and commit. They then run step 8 in its own transaction. For a +2.1.3 database, a step 8 rollback leaves the file at schema 7 with foreign keys on. For an older database, the earlier steps stay committed, so the -file is now a 2.1.2 database. The message says which schema the file is +file is now a 2.1.3 database. The message says which schema the file is at and names the verified backup. Running `ath migrate` again runs only -step 7. `apply_step` keeps its signature for steps 2 through 6. Step 7 is +step 8. `apply_step` keeps its signature for steps 2 through 7. Step 8 is a separate function in that file. `MIGRATION_CHAIN` in that file and `spec/sql/contract.json` gain the step. The native tests check that the contract matches the embedded SQL. @@ -2303,15 +2309,15 @@ The native tests check that the contract matches the embedded SQL. point at `schema/2.2.0/`. `READABLE_DATABASE_VERSIONS` and `ACCEPTED_RECORD_VERSIONS` become `1.0.0`, -`2.0.0`, `2.1.0`, `2.1.1`, `2.1.2`, and `2.2.0`. Both sets already contain `1.0.0`. +`2.0.0`, `2.1.0`, `2.1.1`, `2.1.2`, `2.1.3`, and `2.2.0`. Both sets already contain `1.0.0`. Dropping it would make a 1.0.0 database unloadable, so migrate could not -open it. `IMPORTABLE_PACKAGE_VERSIONS` is `2.0.0`, `2.1.0`, `2.1.1`, and `2.1.2` -today. It gains `2.2.0` and keeps those four. `Store::open` rejects a -`2.1.2` database until `ath migrate`, with the refusal it already uses for -an older database. A `2.1.2` database will not open until that migrate. +open it. `IMPORTABLE_PACKAGE_VERSIONS` is `2.0.0`, `2.1.0`, `2.1.1`, `2.1.2`, +and `2.1.3` today. It gains `2.2.0` and keeps those five. `Store::open` rejects a +`2.1.3` database until `ath migrate`, with the refusal it already uses for +an older database. A `2.1.3` database will not open until that migrate. -The build generates `schema/2.2.0/` and does not rewrite `schema/2.1.2/`, -`schema/2.1.1/`, `schema/2.1.0/`, or `schema/2.0.0/`. The 2.2.0 source object gains optional `device_binding`. +The build generates `schema/2.2.0/` and does not rewrite `schema/2.1.3/`, +`schema/2.1.2/`, `schema/2.1.1/`, `schema/2.1.0/`, or `schema/2.0.0/`. The 2.2.0 source object gains optional `device_binding`. `ProviderReportingPeriodType` gains `open_wearables_reporting_window`. `ValueBasis` gains `aggregator`. Series quantities gain the sample series whose units are in the appendix table. Intake, index, age, and effort @@ -2348,7 +2354,7 @@ This plan's edits to `AGENTS.md` and `build-history/README.md` only point at the plan. -A database from 2.1.1 needs `ath migrate` before the pull. The migrate +A database from 2.1.3 needs `ath migrate` before the pull. The migrate command still previews, backs up, and asks (D124). `Store::open` only refuses. A noninteractive open and an open with `--json` do not migrate. An interactive open can preview, back up, ask, and then migrate. @@ -2369,7 +2375,7 @@ interactive open can preview, back up, ask, and then migrate. | Owner-correction rule and its count, the Garmin window rule, and the depth check for saved envelopes | `match_keyed` and `record_by_import_key` in `src/import/provider.rs`, behind a `KeyedPolicy` flag that only route `open_wearables` sets | | Where a workout fix belongs | one paragraph in `skills/athletic-standard/SKILL.md`, under "Stable IDs and revisions" | | Total size bound for vendor originals, in the bytes export writes | `MAX_VENDOR_ORIGINAL_BYTES` in `src/input_policy.rs`. One function beside `ArrayWriter::item` in `src/package/export.rs` measures an item. The bound is checked in the matching step in `src/import/provider.rs`, in `apply_in` in `src/store/write.rs`, and in `merge_in`, `resolve_in`, and native restore in `src/package/restore.rs` | -| Stored sizes of vendor originals | `vendor_original_sizes`, created by the step 7 SQL file. The rows are written beside the typed rows in `src/store/write.rs` and `src/package/restore.rs`. `ath check` compares them in `src/store/check.rs`, and `ath repair` rewrites them in `src/store/repair.rs` | +| Stored sizes of vendor originals | `vendor_original_sizes`, created by the step 8 SQL file. The rows are written beside the typed rows in `src/store/write.rs` and `src/package/restore.rs`. `ath check` compares them in `src/store/check.rs`, and `ath repair` rewrites them in `src/store/repair.rs` | | The vendor-original total and its warning | the pull's text and `--json` outcome, from `pull` in `src/cli/commands/routes.rs` | | Export refuses a document over the package read cap, or an item that reaches the nesting limit | `src/package/export.rs`, before the staging folder is renamed | | The pull's `__proto__` and depth checks on each vendor object | `src/runtime/vendor_workouts.rs`, before the page is staged | @@ -2710,7 +2716,7 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: absent, null, or non-string `user_id` on the HTTP object refuses the page. The canonical envelope without `user_id` imports. The athlete profile is unchanged -- step 7 keeps an old summary's id, number, unit, `data_json`, import key, +- step 8 keeps an old summary's id, number, unit, `data_json`, import key, revisions, and tombstone. A numeric summary can be corrected to numberless and back. A half-null value and unit is refused. A sample repeats and corrects. `ath check`, export, native import, and restore @@ -3188,50 +3194,51 @@ Rust tests, run by the existing `cargo test` job on Linux, macOS, and Windows: Migration tests, in the build gate: -- a synthetic 2.1.2 database makes `Store::open` refuse before any network +- a synthetic 2.1.3 database makes `Store::open` refuse before any network call. `ath migrate` previews without writing. It still previews, backs up, and asks, as D124 requires. The target it names is `2.2.0` - a confirmed migrate backs up, then sets the record version to `2.2.0`, - SQL schema 7, and `user_version` 7. Record ids, revisions, deletions, + SQL schema 8, and `user_version` 8. Record ids, revisions, deletions, attachments, import keys, reporting periods, and device receipts are unchanged. `PRAGMA foreign_key_check` is empty. A deleted row and its history are still there. The upgraded database is populated, including a tombstone. `sql_v1_current_records` and `sql_v1_active_records` still return rows. An insert that would make a revision type disagree with its record is still rejected. A second - migrate does nothing. A failure injected before the step 7 commit + migrate does nothing. A failure injected before the step 8 commit leaves the old views, the two cross-table triggers, the rows, the version, and `foreign_keys` read back as on. A successful migrate leaves `foreign_keys` on. A source report can then be created, revised, checked, exported, restored, and repaired from `data_json` without becoming a measured type -- `ath init` creates a database that is already `2.2.0`, SQL schema 7, and - `user_version` 7, and `ath check` exits 0. The fresh database accepts a +- `ath init` creates a database that is already `2.2.0`, SQL schema 8, and + `user_version` 8, and `ath check` exits 0. The fresh database accepts a source report, the same two views are queryable, and a mismatched - revision type is rejected. A failed init rolls step 7 back and then the - existing cleanup removes the new file. A failed step 7 migrate of a - populated 2.1.2 database leaves that file, schema 6, the views, and - foreign-key enforcement. Step 6 still - writes `2.1.2` and schema 6, and `install_schema` commits that - transaction before step 7. Its check accepts schema 6 and `2.1.2` there. - A step 7 that is made to stop before it sets the version rows fails the - step-7 check for schema 7 and `2.2.0`, and init fails. Init runs on the + revision type is rejected. A failed init rolls step 8 back and then the + existing cleanup removes the new file. A failed step 8 migrate of a + populated 2.1.3 database leaves that file, schema 7, the views, and + foreign-key enforcement. Step 7 still + writes `2.1.3` and schema 7, and `install_schema` commits that + transaction before step 8. Its check accepts schema 7 and `2.1.3` there. + A step 8 that is made to stop before it sets the version rows fails the + step-8 check for schema 8 and `2.2.0`, and init fails. Init runs on the connection `Store::create` opened and never calls `Store::transaction` -- `apply_steps` given steps 2 through 6 passes its final check at schema 6. - Given a list that ends before 6, it still refuses when the database +- `apply_steps` given steps 2 through 7 passes its final check at schema 7. + Given a list that ends before 7, it still refuses when the database stops short of the last step in that list -- a 2.0.0 database whose step 7 is made to fail after steps 3 to 6 - committed is a 2.1.2 database at schema 6. The message says so and names - the verified backup. A second `ath migrate` runs only step 7 and +- a 2.0.0 database whose step 8 is made to fail after steps 3 to 7 + committed is a 2.1.3 database at schema 7. The message says so and names + the verified backup. A second `ath migrate` runs only step 8 and finishes. `Store::transaction` still refuses a write while foreign keys - are off, and step 7 does not use it + are off, and step 8 does not use it - `ath migrate` re-checks the file, the database ID, the schema, and the - revision its earlier steps left before step 7. A change made between the - two transactions stops step 7 and changes nothing more -- databases at `1.0.0`, `2.0.0`, `2.1.0`, and `2.1.1` still open for migrate. Packages at - `2.0.0`, `2.1.0`, `2.1.1`, and `2.1.2` still import. `spec/sql/migrations/004-version-2-1.sql`, - `spec/sql/migrations/005-version-2-1-1.sql`, `spec/sql/migrations/006-version-2-1-2.sql`, and the folders `schema/2.0.0/`, - `schema/2.1.0/`, `schema/2.1.1/`, and `schema/2.1.2/` stay byte-identical + revision its earlier steps left before step 8. A change made between the + two transactions stops step 8 and changes nothing more +- databases at `1.0.0`, `2.0.0`, `2.1.0`, `2.1.1`, and `2.1.2` still open for migrate. Packages at + `2.0.0`, `2.1.0`, `2.1.1`, `2.1.2`, and `2.1.3` still import. `spec/sql/migrations/004-version-2-1.sql`, + `spec/sql/migrations/005-version-2-1-1.sql`, `spec/sql/migrations/006-version-2-1-2.sql`, + `spec/sql/migrations/007-version-2-1-3.sql`, and the folders `schema/2.0.0/`, + `schema/2.1.0/`, `schema/2.1.1/`, `schema/2.1.2/`, and `schema/2.1.3/` stay byte-identical Rust tests use `MemorySecretStore` in `src/runtime/keyring.rs` and do not open the real password store. They cover: @@ -3310,14 +3317,14 @@ This plan pull request has no screenshots and no video. ## 9. Separate follow-ups -D258 records the check. None of these is a prerequisite for the pull, and none +D276 records the check. None of these is a prerequisite for the pull, and none is in the build pull request. - Failed `ath init` and failed `Store::create` still delete the database file in the same process that closed it, without the abandoned-directory cleanup `make_owned_temporary_directory` uses. On Windows that delete can fail with `EBUSY`. Version 2.1.0 spec section 12 left it out - and named no later version. Version 2.1.1 did not take it. A failed step 7 + and named no later version. Version 2.1.1 did not take it. A failed step 8 rolls back before that cleanup. This build does not replace the cleanup. - `src/import/mapping.rs` is 1703 lines, `src/import/provider.rs` is 1297, and `src/store/check.rs` is 1044. The pull does not add HTTP to them. @@ -3358,7 +3365,7 @@ measured run for this pull. Risks: - A server newer than 0.11.0 can add a default that hides a second device. - Current `main` does not, when the queries in D257 are sent. The client is + Current `main` does not, when the queries in D275 are sent. The client is tested against the stored fixture. That fixture is not a live response, and a live timestamp without an offset is left out. A breaking envelope needs a new fixture before the pull trusts it. @@ -3366,9 +3373,9 @@ Risks: again with a smaller limit. A 429 or another transport failure still stops that read, keeps earlier pages, and withholds the success line. The study did not read the rate-limit middleware. -- A failed step 7 on a database older than 2.1.2 leaves it at 2.1.2, +- A failed step 8 on a database older than 2.1.3 leaves it at 2.1.3, because the earlier steps committed first. The message says so and names - the verified backup, and a second `ath migrate` finishes. Step 7 needs + the verified backup, and a second `ath migrate` finishes. Step 8 needs foreign keys off, and the earlier steps run with them on, so they cannot share one transaction. - A live read can change the server. It can refresh a token, revoke a @@ -3423,7 +3430,7 @@ Risks: is to avoid copying the key into the record. The build, after approval, is one pull request in this order. First the -schema and step 7: the root `record_type` check, the period type, the +schema and step 8: the root `record_type` check, the period type, the `aggregator` basis, the sample series quantities in the appendix table, the `source_report` type and table, the paired null value and unit, and the time-unknown summary. The point check in `src/model/data.rs` and the @@ -3438,45 +3445,45 @@ cycle filter, the smaller-page split, and the tests in section 7. The laptop card and the phone proof are part of that same pull request. This plan pull request has no media. -The maintainer approves or rejects this plan before any build. D254 through -D271 are the proposal. They are not adopted. The stored workout and the +The maintainer approves or rejects this plan before any build. D272 through +D289 are the proposal. They are not adopted. The stored workout and the live original stay separate records, because the public stored -workout has no vendor id. That split is part of this proposal. D271 is the +workout has no vendor id. That split is part of this proposal. D289 is the privacy choice, and the maintainer can change it before approval. Reviews of earlier heads were incorporated here. None of those reviews approves this revision. The next head needs re-review. An earlier review accepted a migration with no new column, under D152 and D184. That acceptance does not -adopt D254. The +adopt D272. The optional source key adds no column. -1. One number, 2.2.0. Readable sets keep `1.0.0`. Step 7 runs on create and +1. One number, 2.2.0. Readable sets keep `1.0.0`. Step 8 runs on create and on migrate. Step 5 stays the published 2.1.1 migration. Step 6 stays the - published 2.1.2 migration. The device - receipt adds no column. Step 7 extends the + published 2.1.2 migration. Step 7 stays the published 2.1.3 migration. The device + receipt adds no column. Step 8 extends the root check with `source_report` by the copy in section 5, creates `source_reports`, and rebuilds `provider_summaries` and `provider_scores` so a numberless object can omit `value` and its unit together. Existing ids and rows are copied. Before the root rename, - step 7 drops and later recreates `sql_v1_current_records`, + step 8 drops and later recreates `sql_v1_current_records`, `sql_v1_active_records`, and the two `record_revisions` triggers that - read `records`. Foreign keys stay on for ordinary writes. Step 7 turns + read `records`. Foreign keys stay on for ordinary writes. Step 8 turns them off on the store's own connection, only before its transaction, and reads them back on after every exit. A - `2.1.2` database does not open until `ath migrate`. This release does + `2.1.3` database does not open until `ath migrate`. This release does not schedule a pull, add its own token refresh, backfill, or store a - cursor (D254). A live read can still make the server refresh a vendor - token (D270). + cursor (D272). A live read can still make the server refresh a vendor + token (D288). 2. Store the returned representations in section 2. Device receipts stay on device sources. Summaries without a device id use their own sensors. Null stays null. A missing response is not called provider-unavailable. - The omissions in section 2 are the ones with a reason (D259, D262). + The omissions in section 2 are the ones with a reason (D277, D280). 3. The key, the selected origin, and the selected user id are rejected in decoded JSON before a page is mapped. Failure text uses a fixed sentence. `ath key clear` with no name still clears only the gateway keys and says when the Open Wearables key remains. Named clear removes the saved key only. It does not unset the environment and it does not revoke the server - key (D256). A credential-shaped value is withheld and counted. It does - not refuse the page (D271). + key (D274). A credential-shaped value is withheld and counted. It does + not refuse the page (D289). 4. Preview is the default and its counts are estimates. `--json` does not write. `--yes` commits each successful page under D189, and a committed page is not a completed pull. The text of `--yes` shows retained counts @@ -3488,7 +3495,7 @@ optional source key adds no column. The receipt is the source key `device_binding`. A 2.1.0 supplied field of that name does not become the receipt. Unbound history is refused and left in place. `ath correct`, the protocol record writes, and a native - 2.2.0 package restore are the owner's whole source record (D257, D258). + 2.2.0 package restore are the owner's whole source record (D275, D276). 5. The Windows cleanup, the Garmin key removal, and the maintainability notes stay separate. `src/import/mapping.rs` gains `MappedPage`, the `vendor_workout` section, and the preservation writes in section 2. @@ -3501,7 +3508,7 @@ optional source key adds no column. and `src/calculate/range.rs` gains the null filter. The pull command builds the archive preview and applies it only at the snapshot's revision. `mapping.rs` does not start it. Failed-init cleanup stays as - it is (D258, D264). + it is (D276, D282). 6. The live vendor read is off by default and warns before its first request. It calls only active connections and never stores the connections list. It keeps every stored detail, counts every object it @@ -3509,7 +3516,7 @@ optional source key adds no column. workout and the vendor original stay two records. On route `open_wearables`, an owner correction is kept until the server's data for that record changes, and each correction a page replaces is counted - (D269, D270, D271). + (D287, D288, D289). These questions stay open for the maintainer. The plan states a default for each, and the default is not adopted: @@ -3518,9 +3525,9 @@ for each, and the default is not adopted: per command. When the probe answers an error status other than 401 or 429, the pull makes no other Garmin detail call in that command. Only 404 and 501 mark the probed id `not_available`, and such an id is - asked again after 30 days (D270). + asked again after 30 days (D288). 2. The owner-correction scope. The default covers every record the - `open_wearables` pull writes. Other routes keep D182 (D269). + `open_wearables` pull writes. Other routes keep D182 (D287). 3. Storing vendor originals in their own package files. The default keeps them in the main document under the 256 MiB bound, which holds about - 158 route-heavy one-hour Polar workouts (D269). + 158 route-heavy one-hour Polar workouts (D287).