Skip to content

feat(cloud): statistics come with FTW Cloud only, accepted once - #2112

Merged
frahlg merged 2 commits into
masterfrom
cloud-stats-one-grant
Nov 28, 2026
Merged

frahlg merged 2 commits into
masterfrom
cloud-stats-one-grant

Conversation

@frahlg

@frahlg frahlg commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Problem

Fredrik decided on 28 November 2026:

  • Statistics are part of FTW Cloud and nothing else. With Cloud on, the project statistics are included in its terms; without Cloud, nothing is sent. No separate switch.
  • Accept once. Accepting at pairing on the phone or in the web app is the acceptance; the box must not ask again.
  • An assistant's default access length is 90 days everywhere.

Core did otherwise:

  • A box without Cloud sent the daily fleet report by default (statistics/share_v1 = default, set by MigrateStatistics), could share by a local yes, and kept an old statistics-only Cloud link running.
  • Settings → FTW app had a "Share anonymous statistics" checkbox.
  • With Cloud on but not under the current terms, the Overview showed a "Review FTW Cloud terms" prompt, and Settings showed the same panel.
  • Access blocked with "Accept FTW Cloud terms above … Statistics-only sharing gives no assistant remote access …".
  • The box page started an assistant grant at a week and an invitation at 7 days; a grant posted with no length got 30 days.

Change

Core (go/internal/cloudlink, go/cmd/ftw):

  • Link.SharesStatistics is the one answer: FTW Cloud on under the current terms (ftw-cloud-2026-10-v3), and nothing else. It gates the hourly upload, the fleet report, the energy report and the public driver counts. With no Cloud link, nothing is sent. The package-level SharesStatistics(kv), SaidYesToStatistics and MigrateStatistics go.
  • Stats refuses without Cloud (ErrNotGranted, 409) and changes nothing under the current terms. StopStats still refuses under the current terms and still strips statistics from older grants.
  • /api/cloud/stats-policy says standalone: false, local_optional: false, local_default: "off"; its retention line names only turning Cloud off.
  • A grant posted to /api/agents without ttlS lasts 90 days (was 30).

Box pages:

  • web/project-statistics.js: no Overview prompt in any state. The Cloud panel shows facts once the current terms are accepted ("FTW Cloud is on. Its terms include project statistics." and Turn FTW Cloud off). Only Cloud under earlier terms offers "Accept the current terms", in Settings. The Access panel offers "Accept Cloud terms and turn it on" only while Cloud is off, which is the first and only acceptance for an owner with no phone.
  • web/settings/tabs/fleet.js: the checkbox goes and the section is now "Statistics". It says the hourly reports are linked to the Cloud home for 48 hours so Sourceful can delete them, and the daily reports carry no box id; "anonymous" was untrue for the hourly ones. One bold line states the case: "On, as part of FTW Cloud…", "Off. FTW Cloud runs under earlier terms…" or "Off. This box does not use FTW Cloud, so nothing is sent." The payload previews stay.
  • web/settings/tabs/app.js: the pairing line stays one line and now names the statistics: "…which keeps a readable copy of your energy data and takes project statistics. Pairing accepts its terms."
  • web/settings/tabs/access.js: defaultLength picks 90 days, or the longest offered when less (a box without longestMs still gives 30). Invitations offer 1, 7, 30, 90 days and a year, starting at 90. A renewal of an ended grant starts at 90. The Cloud blocker reads cloudReady(cloud): link on and current terms accepted, which a phone's grant at pairing satisfies.
  • Script and style versions bumped to terms3.

No relay runs: comments in main.go and the energyreport package doc, the energy-report paragraph on the panel, config.example.yaml, ADR 0008 and protocol-cloud.md now say the fleet report goes straight to FTW Cloud, which sees the address, and the energy report is not sent.

Docs: ADR 0008 amendment (28 November), protocol-cloud.md routes and policy note, architecture.md, agents.md (90 days), ADR 0011 line, config.example.yaml, the fleet_ping comment in config.go.

Stored state

  • statistics/share_v1 ("on", "default" or "off") is written "off" at every start (cloudlink.RetireLocalStatistics) and read by nothing. "Off" also keeps a rollback to an older release from sending without Cloud; under the current Cloud terms an older release still sends, as this one does.
  • A statistics-only grant from an earlier release ends at start (ReconcileStatistics → End), so the service deletes its rows. A grant under older terms that still carries stats loses it; Cloud keeps running.
  • cloud/statistics_decision_v1 is no longer written or read.
  • fleet_ping.enabled is not read at all. fleet_ping.endpoint still picks the collector, but a household's own collector without FTW Cloud now gets nothing. The changeset, config.example.yaml and config.go say so.

Contract notes for the clients

No registry change and no new field.

  • GET /api/cloud: same fields. statistics and statisticsRequired are now equal, true only with Cloud on under the current terms. statisticsDecisionRequired stays false. statisticsOnly reads false after the first start.
  • GET /api/cloud/stats-policy: policy, cloud_policy, cloud_includes_statistics and available unchanged, which is what the iPhone and Android apps check. standalone, local_optional and local_default change as above.
  • POST /api/cloud/grant: unchanged. A phone's grant at pairing makes cloudTermsAccepted true and the box asks nothing more, on the Overview, in Settings or in Access.
  • POST /api/cloud/stats: 409 without Cloud (was 200 with a saved local yes). Only the apps' demo boxes call it.
  • POST /api/agents without ttlS: 90 days.
  • contract/registry.yaml lines 192 to 194 still say "a box without Cloud keeps its own statistics answer". I left the comment alone, since changing it means copying the file into both clients; fix it in the next paired registry change.

With #2007: merge this first

Merge #2112 before #2007, then rebase #2007. git merge-tree with energy-report-direct now conflicts in three places, all prose this PR had to correct because no relay runs:

#2007's energyLine says "if sharing were on"; "with FTW Cloud on" matches the fleet line. Its tests do not depend on this PR's answer. Together, the energy report goes straight to FTW Cloud only from a box with Cloud on under the current terms, since its Enabled reads the same answer, so the address FTW Cloud sees is one it already has.

Paired with srcfl/ftw-web#50 (privacy page). The iPhone, Android and web apps get their side in separate PRs.

Evidence

go test ./internal/cloudlink/                     # ok (77.9 s)
go test ./cmd/ftw/ -run 'Report|Fleet|Statistic|Saving|Relay|Without'   # ok
go test ./internal/api/ -run 'Cloud|Statistic|FleetPing|Agents|BoxPage|Length'   # ok
node --test web/project-statistics.test.mjs web/fleet-ping-tab.test.mjs web/app-link-tab.test.mjs web/app-link-sharing.test.mjs web/settings/tabs/access*.test.mjs   # all pass
npm test                                          # 1071 pass, 0 fail
nice -n 10 make verify                            # "verify: vet + test + build clean"

After the review fixes (46759e8): go test ./internal/cloudlink/ ./cmd/ftw/ ./internal/api/ ./internal/config/ ./internal/energyreport/ ./internal/fleetping/ ok; npm test 1072 pass, 0 fail.

New or rewritten tests: TestWithoutCloudStatisticsAreRefusedAndNothingIsShared, TestEveryEarlierLocalAnswerIsRetiredAsOff, TestTheOldLocalAnswerCountsForNothing, TestAStatisticsOnlyLinkSendsNothingAndEnds, TestOlderTermsLoseALeftoverStatsPurpose, TestABuildWithoutAServiceSharesNothing, TestBothReportsReadTheOneStatisticsAnswer (real link: no Cloud, old local yes, current terms, retired fleet switch, partner site, Cloud off), TestWithoutALinkNothingIsSent, TestTheStatisticsTermsComeOnlyWithCloud, and the web tests for each panel state, cloudReady and the 90-day defaults.

A local Core with a test config (no drivers, no Cloud): GET /api/fleet-ping says enabled: false; a stored statistics/share_v1 = default reads off after a restart; POST /api/cloud/stats answers 409. I looked at Settings → FTW app and Settings → Access in a browser, on that Core, with /api/cloud stubbed in the page for the Cloud-on, earlier-terms and paired states: no Overview prompt, the one-line pairing note, the facts-only panel once accepted, the single accept button under earlier terms, Access ready once accepted, and an invitation at 90 days.

🤖 Generated with Claude Code

Fredrik decided on 28 November 2026: either no cloud at all, or FTW
Cloud with the anonymous statistics included; the terms are accepted
once, at pairing on the phone or the web app, and the box does not ask
again. An assistant's default access length is 90 days everywhere.

Statistics:
- The one answer (Link.SharesStatistics) is FTW Cloud on under the
  current terms and nothing else. It gates the hourly upload, the fleet
  report, the energy report and the public driver counts. A box without
  Cloud sends none of them.
- Stored state: statistics/share_v1 is written "off" once at start and
  read by nothing, so a rollback cannot start sending without Cloud. A
  statistics-only link an earlier release left ends, so the service
  deletes its rows; a grant under older terms loses a leftover stats
  purpose. fleet_ping.enabled is no longer read.
- POST /api/cloud/stats answers 409 without Cloud; stats-policy says
  standalone and local_optional false.

Box pages:
- The Overview prompt and the "Share anonymous statistics" checkbox go.
  Settings → FTW app → Anonymous statistics states which case holds.
- The Cloud panel shows facts once the terms are accepted. Only Cloud
  under earlier terms offers the current ones, in Settings.
- Access counts the phone's acceptance; its blocker no longer mentions
  statistics-only sharing.
- Assistant grants and invitations start at 90 days; a grant posted
  without a length lasts 90 days.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-28T11:26:11.856039Z 46f4042 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

…runs

Review of #2112:
- The hourly reports carry a statistics id so Sourceful can delete them,
  so "anonymous statistics" was untrue for them. The Cloud panel, the
  pairing line and the section say "project statistics"; the section is
  now Settings → FTW app → Statistics and says which reports are linked
  to the Cloud home for 48 hours and which carry no box id.
- No release names an Oblivious HTTP relay, yet comments and the energy
  report paragraph spoke as if one hid the address. main.go, the
  energyreport package doc, the panel, the config example, ADR 0008 and
  protocol-cloud.md now say the fleet report goes straight to FTW Cloud
  and the energy report is not sent.
- A collector set in fleet_ping.endpoint gets no daily report without
  FTW Cloud; the changeset, config.example.yaml and config.go say so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>
@frahlg
frahlg merged commit 915f6fa into master Nov 28, 2026
22 of 23 checks passed
frahlg added a commit that referenced this pull request Nov 28, 2026
The energy report waited for an independent relay that never came, so no
box sent one and stats.ftw.energy showed no energy. The box now posts it to
https://cloud.ftw.energy/v1/energy, as the fleet report goes to /v1/fleet
(Fredrik, 12 November 2026). The body is the padded inner request
(reportwire), unsealed, as message/bhttp; only a 204 counts. FTW Cloud sees
the box's address while the request is open and keeps neither the address
nor the report.

It goes only with FTW Cloud on under the current terms and never for a site
a partner controls: the sender reads the one statistics answer from #2112.

The energy report has no sealed path any more: FTW Cloud's OHTTP gateway is
gone (srcfl/ftw-cloud#72), so the sender always uses the direct client and
the Settings preview drops its relay field. The sealed half of statsrelay
stays, since fleetping.RelayProvider still calls it.

Rebased onto master after #2112 and #2114. Settings, the config example,
main.go, ADR 0008, architecture.md and protocol-cloud.md say where the
report goes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Fredrik Ahlgren <[email protected]>
frahlg added a commit that referenced this pull request Nov 28, 2026
The energy report waited for an independent relay that never came, so no
box sent one and stats.ftw.energy showed no energy. The box now posts it to
https://cloud.ftw.energy/v1/energy, as the fleet report goes to /v1/fleet
(Fredrik, 12 November 2026). The body is the padded inner request
(reportwire), unsealed, as message/bhttp; only a 204 counts. FTW Cloud sees
the box's address while the request is open and keeps neither the address
nor the report.

It goes only with FTW Cloud on under the current terms and never for a site
a partner controls: the sender reads the one statistics answer from #2112.

The energy report has no sealed path any more: FTW Cloud's OHTTP gateway is
gone (srcfl/ftw-cloud#72), so the sender always uses the direct client and
the Settings preview drops its relay field. The sealed half of statsrelay
stays, since fleetping.RelayProvider still calls it.

Rebased onto master after #2112 and #2114. Settings, the config example,
main.go, ADR 0008, architecture.md and protocol-cloud.md say where the
report goes.

Signed-off-by: Fredrik Ahlgren <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant