π OpenHands: AI-Driven Development
fix(telemetry): retry automation consent sync (#16959)
Engel Nysteefa2ddfa7f1
diff --git a/.agents/skills/verify-openhands/SKILL.md b/.agents/skills/verify-openhands/SKILL.mdindex e9da8c2c14..52864f2177 100644--- a/.agents/skills/verify-openhands/SKILL.md+++ b/.agents/skills/verify-openhands/SKILL.md@@ -123,7 +123,9 @@ control-openhands stop # stops only this run; evidence sbackend restart: persistence and reconnection) and `restart --rotate-key`(stale session key). `restart` keeps the browser on its page. While a serviceis stopped, a reload replaces the page with the backend-unavailable screen, so- drive backend-down states on the page that was already loaded. `browser+ drive backend-down states on the page that was already loaded.+ `service pause automation` and `service resume automation` queue and release+ real requests for in-flight race checks. Resume before stopping the run. `browsernetwork` (with `--bodies`, what the page sent, credentials redacted),`browser toasts` and `browser media` observe requests by origin, toasts andsound without changing anything; `click --observe SEL` and `scrolldiff --git a/.agents/skills/verify-openhands/references/feature-map/F16-application-settings.md b/.agents/skills/verify-openhands/references/feature-map/F16-application-settings.mdindex 666aa8b1ff..212ad1fd12 100644--- a/.agents/skills/verify-openhands/references/feature-map/F16-application-settings.md+++ b/.agents/skills/verify-openhands/references/feature-map/F16-application-settings.md@@ -56,6 +56,8 @@ Preconditions:- **Colour theme (`F16.color-theme`).** Run `control-openhands browser click 'testid=color-theme-input'`, `control-openhands browser snapshot 'role=listbox'` (OpenHands-DeepSea, OpenHands-Neutral [selected], OpenHands-Neo, Light+, Solarized Light), `control-openhands browser click 'role=option[name="Light+"]'`, then `control-openhands browser eval "document.documentElement.style.colorScheme + ' ' + localStorage.getItem('openhands-color-theme')"` (`light light-plus`) and `control-openhands browser enabled 'testid=submit-button'` (`false`: no Save needed). `control-openhands browser screenshot --feature F16.color-theme --name light-plus` shows a white page. Second views: `control-openhands browser reload` then `control-openhands browser value 'testid=color-theme-input'` (`Light+`); `control-openhands browser goto /` then `control-openhands browser eval "getComputedStyle(document.body).backgroundColor + ' ' + document.documentElement.style.colorScheme"` (`rgb(255, 255, 255) light`); `control-openhands api GET /api/settings` contains no theme key. Restore on `/settings/app` (`control-openhands browser goto /settings/app`; the second view left `/`) by choosing `role=option[name="OpenHands-Neutral"]` the same way (`dark openhands-neutral`).- **Analytics consent (`F16.analytics`).** Run `control-openhands browser click 'testid=app-settings-screen >> text=Send anonymous usage data'`, read the switch with the `eval` from Preconditions (`true`), `control-openhands browser click 'testid=submit-button'`, `control-openhands browser wait-text 'Settings saved'`, `control-openhands browser reload`, read the switch again (`true`), `control-openhands api GET /api/settings` (`user_consents_to_analytics: true`) and `control-openhands browser eval "localStorage.getItem('openhands-telemetry-consent')"` (`granted`). Restore by clicking the label again and saving; consent reads `denied` and the API `false`.- **Cloud forces analytics (`F16.analytics-cloud`).** Blocked: needs a Cloud backend selected in the backend selector. Expected: `control-openhands browser enabled 'testid=enable-analytics-switch'` is `false` and the switch reads checked.+- **Consent reversal with an in-flight Automation write (`F16.analytics`).** With a non-DNT build using a dummy PostHog key and loopback-only `VITE_POSTHOG_HOST` (no external analytics delivery), save opt-in and confirm its consent POST returned 200. Run `service pause automation`, save opt-out then opt-in through the same switch, and `service resume automation` before the five-second request timeout. Record the UI transitions and read `browser network --filter 'telemetry/consent' --bodies`; the final granted value must be posted and acknowledged. Resume before `stop`. The default hard-DNT build cannot exercise this reversal.+- **Sound notifications (`F16.sound`).** Run `control-openhands browser click 'testid=app-settings-screen >> text=Sound Notifications'`, `control-openhands browser click 'testid=submit-button'`, `control-openhands browser wait-text 'Settings saved'`, `control-openhands browser reload`, read `enable-sound-notifications-switch` (`true`) and `control-openhands api GET /api/settings` (`enable_sound_notifications: true`). Restore by toggling and saving again (`false`). Audible half: with the switch on and saved, `control-openhands conversation start --prompt "Reply with only the word ok. Do not run any tools." --wait --timeout 180`, then `control-openhands browser media`: `plays` lists one `/assets/notification-<hash>.mp3` at the moment the conversation finished. With the switch off, the same check after a conversation reads `plays: []` (the `F16.git-identity` conversation below doubles as that negative check). Turn the switch off and save afterwards (`control-openhands browser goto /settings/app` first: `conversation start` left the browser on the conversation).- **Getting Started checklist (`F16.checklist`).** Run `control-openhands browser count 'testid=sidebar-onboarding-checklist'` (`1`), `control-openhands browser click 'testid=app-settings-screen >> text=Show Getting Started checklist'`, then the same `count` (`0`, immediately) and `control-openhands browser enabled 'testid=submit-button'` (`false`). `control-openhands browser screenshot --feature F16.checklist --name hidden` shows the sidebar without the "Getting started" card. `control-openhands browser reload` keeps the count at `0` and the switch unchecked. Click the label again to restore; the count returns to `1`.- **Title generation model (`F16.title-model`).** Run `control-openhands browser click 'testid=title-llm-profile-input'` and `control-openhands browser snapshot 'role=listbox'`: options `Automatic (recommended)`, `deepseek-flash Β· deepseek/deepseek-flash`, `deepseek-pro Β· deepseek/deepseek-v4-pro`. Run `control-openhands browser click 'role=option >> has-text=deepseek-pro'`, `control-openhands browser click 'testid=submit-button'`, `control-openhands browser wait-text 'Settings saved'`, `control-openhands browser reload`, `control-openhands browser value 'testid=title-llm-profile-input'` (`deepseek-pro Β· deepseek/deepseek-v4-pro`) and `control-openhands api GET /api/settings` (`title_llm_profile: "deepseek-pro"`). Then `control-openhands conversation start --prompt "Reply with only the word ok. Do not run any tools." --wait --timeout 180` and, a few seconds later, `control-openhands conversation status <id>` with the `id` it printed: `title` is a generated title: an emoji and a short phrase whose wording varies (for example `π§ Acknowledge with ok only`). The start output's own `title` may already be set; when it is still `null`, the title is written a few seconds after the run finishes. Return with `control-openhands browser goto /settings/app`, choose `role=option[name="Automatic (recommended)"]`, save; `title_llm_profile` is then absent from `app_preferences`.@@ -89,5 +91,5 @@ Preconditions:- `browser eval` wraps its argument as an expression: statements separated by `;` fail with `SyntaxError: Unexpected token ';'`; wrap them in `(() => { ...; return x; })()`.- With `service stop agent-server`, a `browser reload` of `/settings/app` shows the backend-unavailable screen (`agent-server-onboarding-screen`, Manage backends), not the form: stop the service only after the page is loaded, and `restart` afterwards.- Known product bugs (repro candidates): git identity never reaches the agent (#17899); switches are not keyboard reachable or announced (#17900); a failed save discards the user's edits (`F16.save-states`) (#17927).-- The harness builds with `VITE_DO_NOT_TRACK=1`, so PostHog never starts: `browser network --filter 'posthog|z\.openhands\.dev'` reports `total` `0`, also after analytics consent is granted (#18086). A browser-only Do Not Track setting, and a non-DNT build where consent starts PostHog, cannot be driven with the harness (`F16.analytics`).+- The harness builds with `VITE_DO_NOT_TRACK=1`, so PostHog never starts: `browser network --filter 'posthog|z\.openhands\.dev'` reports `total` `0`, also after analytics consent is granted (#18086). A browser-only Do Not Track setting is outside this recipe. Consent reversal requires the explicit non-DNT build and loopback-only analytics configuration described above, served with `launch --build never` (`F16.analytics`).- The title model's clear button has no test id: the recipe's xpath relies on DOM nesting to skip the unnamed `Show suggestions` button. If both ever match, Playwright's strict mode fails the click instead of pressing the wrong one; report it as harness drift.diff --git a/.agents/skills/verify-openhands/scripts/control-openhands.mjs b/.agents/skills/verify-openhands/scripts/control-openhands.mjsindex cd0af5710f..556d9f731d 100755--- a/.agents/skills/verify-openhands/scripts/control-openhands.mjs+++ b/.agents/skills/verify-openhands/scripts/control-openhands.mjs@@ -1062,7 +1062,7 @@ async function cmdService({ positional, flags }) {out({ ok: true, launcherAlive: groupAlive(run.launcherPgid), services });return;}- if (sub === "stop") {+ if (["stop", "pause", "resume"].includes(sub)) {const pattern = SERVICES[name];if (!pattern) {usage(@@ -1070,7 +1070,7 @@ async function cmdService({ positional, flags }) {"control-openhands service stop automation",);}- // Only processes inside this run's own process group are candidates.+ // Only descendants of this run's launcher are candidates.const targets = procs.filter((p) => pattern.test(p.args) && p.pid !== run.launcherPid,);@@ -1083,11 +1083,23 @@ async function cmdService({ positional, flags }) {// Signal each service's own process group (uv and its Python child).for (const pgid of new Set(targets.map((t) => t.pgid))) {try {- process.kill(-pgid, "SIGTERM");+ process.kill(+ -pgid,+ { stop: "SIGTERM", pause: "SIGSTOP", resume: "SIGCONT" }[sub],+ );} catch {// already gone}}+ if (sub !== "stop") {+ out({+ ok: true,+ action: sub,+ signalled: targets.map((t) => t.pid),+ launcherAlive: groupAlive(run.launcherPgid),+ });+ return;+ }await delay(2000);out({ok: true,@@ -1098,7 +1110,7 @@ async function cmdService({ positional, flags }) {return;}usage(- "Usage: control-openhands service status | service stop automation|agent-server|frontend",+ "Usage: control-openhands service status | service stop|pause|resume automation|agent-server|frontend","control-openhands service stop automation",);}@@ -4005,7 +4017,10 @@ first, so the browser's stored key becomes stale (public mode then shows theAPI-key prompt again). Reload the browser afterwards.`,service: `control-openhands service status-control-openhands service stop automation|agent-server|frontend+control-openhands service stop|pause|resume automation|agent-server|frontend++Pause queues real requests without replacing responses; resume lets the service process them.+Always resume a paused service before stopping the run.Stops one service inside this run's own process group so unavailable/backend-downstates can be driven through the UI. Bring everything back with restart.@@ -4025,7 +4040,7 @@ Lifecycledoctor Read-only health check; run first and after any surprisestatus Show the current run's ports, revision and livenessrestart Restart this run's stack in place (same state); --rotate-key for stale-key states- service status | stop automation|agent-server|frontend (drive backend-down states)+ service status | stop|pause|resume automation|agent-server|frontend (unavailable/slow states)stop Stop this run's browser and launcher process group (keeps evidence)runs List runs under $OH_VERIFY_HOMEenv Print export lines for this rundiff --git a/.agents/skills/verify-openhands/scripts/control-openhands.test.mjs b/.agents/skills/verify-openhands/scripts/control-openhands.test.mjsindex c47c575a53..9690da8fea 100755--- a/.agents/skills/verify-openhands/scripts/control-openhands.test.mjs+++ b/.agents/skills/verify-openhands/scripts/control-openhands.test.mjs@@ -2,7 +2,7 @@// They run with the rest of the suite (`npm test`), or alone:// npx vitest run .agents/skills/verify-openhandsimport assert from "node:assert/strict";-import { spawnSync } from "node:child_process";+import { spawn, spawnSync } from "node:child_process";import {existsSync,mkdirSync,@@ -15,6 +15,7 @@ import { createServer } from "node:net";import { tmpdir } from "node:os";import { dirname, join, relative, resolve } from "node:path";import { fileURLToPath } from "node:url";+import { setTimeout as delay } from "node:timers/promises";import { test } from "vitest";import { buildIdentity } from "./lib/build-id.mjs";import { BUILD_INPUTS } from "./lib/build-inputs.mjs";@@ -1774,3 +1775,72 @@ test("browser help documents record", () => {);assert.notEqual(bad.status, 0);});++test.skipIf(process.platform === "win32")(+ "service pause and resume affect only the selected run's descendants",+ async () => {+ const dir = mkdtempSync(join(tmpdir(), "cov-service-"));+ const serviceFile = join(dir, "static-server.mjs");+ writeFileSync(+ serviceFile,+ `import { writeFileSync } from "node:fs"; setInterval(() => writeFileSync(process.argv[2], String(Date.now())), 20);`,+ );+ const ownBeat = join(dir, "own-beat");+ const otherBeat = join(dir, "other-beat");+ const childPidFile = join(dir, "child-pid");+ const launcher = spawn(+ process.execPath,+ [+ "--input-type=module",+ "-e",+ `import { spawn } from "node:child_process"; import { writeFileSync } from "node:fs"; const child = spawn(process.execPath, ${JSON.stringify([serviceFile, ownBeat])}, { detached: true, stdio: "ignore" }); writeFileSync(${JSON.stringify(childPidFile)}, String(child.pid)); setInterval(() => {}, 1000);`,+ ],+ { detached: true, stdio: "ignore" },+ );+ const unrelated = spawn(process.execPath, [serviceFile, otherBeat], {+ detached: true,+ stdio: "ignore",+ });+ let childPid;+ try {+ for (let attempts = 0; attempts < 50 && !existsSync(ownBeat); attempts++)+ await delay(20);+ childPid = Number(readFileSync(childPidFile, "utf8"));+ assert.ok(existsSync(ownBeat) && existsSync(otherBeat));+ writeFileSync(+ join(dir, "run.json"),+ JSON.stringify({+ launcherPid: launcher.pid,+ launcherPgid: launcher.pid,+ }),+ );+ const paused = run(["service", "pause", "frontend", "--run", dir]);+ assert.equal(paused.status, 0);+ assert.deepEqual(paused.json.signalled, [childPid]);+ assert.equal(paused.json.launcherAlive, true);+ const frozen = readFileSync(ownBeat, "utf8");+ const otherBefore = readFileSync(otherBeat, "utf8");+ await delay(100);+ assert.equal(readFileSync(ownBeat, "utf8"), frozen);+ assert.notEqual(readFileSync(otherBeat, "utf8"), otherBefore);+ const resumed = run(["service", "resume", "frontend", "--run", dir]);+ assert.equal(resumed.status, 0);+ assert.deepEqual(resumed.json.signalled, [childPid]);+ await delay(100);+ assert.notEqual(readFileSync(ownBeat, "utf8"), frozen);+ } finally {+ if (!childPid && existsSync(childPidFile))+ childPid = Number(readFileSync(childPidFile, "utf8"));+ for (const pid of [childPid, unrelated.pid, launcher.pid].filter(+ Boolean,+ )) {+ try {+ process.kill(-pid, "SIGCONT");+ process.kill(-pid, "SIGTERM");+ } catch {+ /* already gone */+ }+ }+ }+ },+);diff --git a/.github/pr-assets/pr-16959-telemetry-consent-retry.svg b/.github/pr-assets/pr-16959-telemetry-consent-retry.svgnew file mode 100644index 0000000000..db47cc4ea9--- /dev/null+++ b/.github/pr-assets/pr-16959-telemetry-consent-retry.svg@@ -0,0 +1,15 @@+<svg xmlns="http://www.w3.org/2000/svg" width="1260" height="470" role="img" aria-label="Automation telemetry consent retry verification">+ <rect width="100%" height="100%" rx="18" fill="#0b1020"/>+ <circle cx="34" cy="32" r="8" fill="#ff5f56"/>+ <circle cx="60" cy="32" r="8" fill="#ffbd2e"/>+ <circle cx="86" cy="32" r="8" fill="#27c93f"/>+ <text x="28" y="78" fill="#d7e2ff" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="21">Regression: initial Automation consent POST rejects</text>+ <text x="28" y="116" fill="#ff9b91" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="21">Before: the attempt was marked complete; the unchanged consent was never retried</text>+ <text x="28" y="164" fill="#d7e2ff" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="21">After: rejection β 1 s backoff β retry succeeds; successful keys remain deduplicated</text>+ <text x="28" y="218" fill="#d7e2ff" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="18">$ npx vitest run use-sync-automation-telemetry-consent automation-service telemetry</text>+ <text x="28" y="256" fill="#8ef0a1" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="21">Test Files 3 passed (3) Β· Tests 75 passed (75)</text>+ <text x="28" y="310" fill="#d7e2ff" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="21">$ npm test</text>+ <text x="28" y="348" fill="#8ef0a1" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="21">Test Files 623 passed (623) Β· Tests 5276 passed | 4 skipped | 7 todo</text>+ <text x="28" y="402" fill="#d7e2ff" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="21">$ npm run lint && npm run build && npm run build:lib</text>+ <text x="28" y="440" fill="#8ef0a1" font-family="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace" font-size="21">Passed on merged main Β· Node 24.19.0</text>+</svg>diff --git a/.pr/consent-review-verification-2026-10-12/README.md b/.pr/consent-review-verification-2026-10-12/README.mdnew file mode 100644index 0000000000..b0e144cb97--- /dev/null+++ b/.pr/consent-review-verification-2026-10-12/README.md@@ -0,0 +1,72 @@+# Live consent reversal β 12 October 2026++The pre-fix production Canvas left Automation opted out after the user returned to opt-in. The fixed Canvas persisted the final opt-in choice.++| Version | Frontend source | Final browser choice | Real Automation database |+| --- | --- | --- | --- |+| Before | `9f5eb1e2e709ba18b91bea663397c553ab042c2c` | `granted` | `[false]` |+| After | `a67ec1709627b6ca978ff727b8a2a422c880be0c` | `granted` | `[true]` |++The source links are [before](https://github.com/enyst/playground/blob/9f5eb1e2e709ba18b91bea663397c553ab042c2c/src/hooks/use-sync-automation-telemetry-consent.ts) and [after](https://github.com/enyst/playground/blob/a67ec1709627b6ca978ff727b8a2a422c880be0c/src/hooks/use-sync-automation-telemetry-consent.ts). The verification harness adds run-owned `service pause|resume` controls in the same evidence commit, documented in its help and skill, and tested with actual child processes including an unrelated service that must keep running.++## Production setup++Both versions used separate fresh browser profiles and private homes, real Agent Server/SDK 1.53.0 and the same pinned Automation service. No API responses were mocked. No model or automation execution was needed or started. Doctor passed before each check; its only warning was the unused model without an API key. The prebuilt SPA was served by the real launcher. Both runs used http://127.0.0.1:18800 sequentially.++The default harness build hard-disables telemetry and cannot produce this consent transition. These two builds explicitly enabled the consent store while pointing the supported PostHog host configuration at an unused loopback port with a dummy public project key. This exercises real Canvas consent and real Automation integration; it does not test analytics delivery. The Automation process retained the harness's server-side hard telemetry opt-out. No real analytics host or model provider was used.++Build each checkout with:++```sh+VITE_DO_NOT_TRACK=0 DO_NOT_TRACK=0 \+VITE_POSTHOG_API_KEY=phc_local_review_verification \+VITE_POSTHOG_HOST=http://127.0.0.1:19980 \+VITE_POSTHOG_UI_HOST=http://127.0.0.1:19980 npm run build:app+node --input-type=module -e 'import { buildIdentity } from "./.agents/skills/verify-openhands/scripts/lib/build-id.mjs"; import {writeFileSync} from "node:fs"; writeFileSync("build/verify-revision.txt", buildIdentity(process.cwd()) + "\n")'+control-openhands launch --new --build never --sdk-version 1.53.0+```++The marker was written only after a successful build of that source. The after build was built at `a67ec17096`, saved while the baseline was built, then restored after the baseline was stopped. Doctor verified both served identities. On this Mac, launch's free-memory threshold was lowered deliberately to 256 MB after `memory_pressure` reported 48% available memory; only one stack ran at a time.++## UI recipe++Export the exact run directory printed by launch as `OH_VERIFY_RUN`. Use the same recipe on each build:++```sh+control-openhands doctor+control-openhands onboard --skip+control-openhands browser goto /settings/app+control-openhands browser click 'testid=app-settings-screen >> text=Send anonymous usage data'+control-openhands browser click 'testid=submit-button'+control-openhands browser wait '[data-testid="submit-button"]:disabled'+control-openhands browser network --filter 'telemetry/consent' --bodies+# Confirm initial granted POST is acknowledged before the reversal.+control-openhands browser network --clear --filter 'telemetry/consent'+control-openhands browser record start --feature F16.analytics --name consent-reversal --fps 5+control-openhands service pause automation+control-openhands browser click 'testid=app-settings-screen >> text=Send anonymous usage data'+control-openhands browser click 'testid=submit-button'+control-openhands browser wait '[data-testid="submit-button"]:disabled'+control-openhands browser click 'testid=app-settings-screen >> text=Send anonymous usage data'+control-openhands browser click 'testid=submit-button'+control-openhands browser wait '[data-testid="submit-button"]:disabled'+control-openhands service resume automation+control-openhands browser scroll 'testid=app-settings-screen >> text=Send anonymous usage data'+control-openhands browser network --filter 'telemetry/consent' --bodies+control-openhands browser eval '({consent:localStorage.getItem("openhands-telemetry-consent")})'+control-openhands browser record stop --gif+control-openhands stop+```++Pause sends SIGSTOP only to the run's Automation descendants; Agent Server remains active, so both settings saves complete normally. Resume sends SIGCONT. The reversal takes less than the consent request's five-second timeout. One preliminary run used a mistyped selector and was discarded; the published recordings and results come from the corrected recipe.++## Results and limits++[Before video](before-consent-reversal.mp4) / [GIF](before-consent-reversal.gif) and [after video](after-consent-reversal.mp4) / [GIF](after-consent-reversal.gif) show the real privacy control and settings saves. The backend sync is invisible in the UI; the original network outputs and database reads establish the resulting state.++- Before: the acknowledged initial granted value was suppressed after the intervening denial. The reversal emitted only one consent POST (`false`, HTTP 200). Browser consent remained `granted`; Automation stored `false`.+- After: the reversal emitted denial and granted POSTs, both HTTP 200. Browser consent remained `granted`; Automation stored `true`.+- The database was inspected read-only with SQLite: `SELECT value FROM automation_service_metadata WHERE key='posthog_frontend_consent_by_distinct_id'`. The public outputs retain only the consent booleans; no keys or private state are published.+- Both cleanup results confirm launcher/browser stopped and all five owned ports closed.++This live check proves the return-to-acknowledged-value guard regression. Deliberately processing the older write *after* the new acknowledgement is covered by controlled-promise regression tests in both consent directions; this live run does not claim that separate ordering. Existing startup recovery media remains linked in the PR. Cloud consent and analytics delivery are outside this check.diff --git a/.pr/consent-review-verification-2026-10-12/after-consent-reversal.gif b/.pr/consent-review-verification-2026-10-12/after-consent-reversal.gifnew file mode 100644index 0000000000..49a5404021Binary files /dev/null and b/.pr/consent-review-verification-2026-10-12/after-consent-reversal.gif differdiff --git a/.pr/consent-review-verification-2026-10-12/after-consent-reversal.mp4 b/.pr/consent-review-verification-2026-10-12/after-consent-reversal.mp4new file mode 100644index 0000000000..3ba64f851eBinary files /dev/null and b/.pr/consent-review-verification-2026-10-12/after-consent-reversal.mp4 differdiff --git a/.pr/consent-review-verification-2026-10-12/after-doctor.json b/.pr/consent-review-verification-2026-10-12/after-doctor.jsonnew file mode 100644index 0000000000..59e8355752--- /dev/null+++ b/.pr/consent-review-verification-2026-10-12/after-doctor.json@@ -0,0 +1,26 @@+{+ "ok": true,+ "run": "/private/tmp/enyst-review-live-20261012/consent-after",+ "baseUrl": "http://127.0.0.1:18800",+ "failed": [],+ "warnings": [+ "LLM configured: model=gpt-5.6 without an API key: `control-openhands llm preset deepseek`"+ ],+ "passed": [+ "launcher process group alive: /opt/homebrew/Cellar/node/25.9.0_1/bin/node /Users/enyst/.codex/worktrees/enyst-pr-ci-maintenance/odie/bin/agent-canvas.",+ "launcher is this run's agent-canvas: /opt/homebrew/Cellar/node/25.9.0_1/bin/node /Users/enyst/.codex/worktrees/enyst-pr-ci-maintenance/odie/bin/agent-canvas.",+ "port ingress:18800 listening: open",+ "port agentServer:18801 listening: open",+ "port automation:18802 listening: open",+ "port frontend:18803 listening: open",+ "served build matches this checkout's build inputs: served=29483238ae56d29c run=29483238ae56d29c revision=a67ec1709627",+ "checkout build inputs unchanged since launch: launch=29483238ae56d29c now=29483238ae56d29c",+ "unauthenticated API rejected: status=401",+ "authenticated settings readable: status=200",+ "agent-server reachable: version=1.53.0",+ "agent-server matches pin: server=1.53.0, chosen by OH_AGENT_SERVER_VERSION (default pin 1.53.0)",+ "agent-server meets the UI minimum: server=1.53.0 minimum=1.51.0",+ "automation healthy: status=200",+ "UI loads without page errors: markers=first-run-onboarding-screen,onboarding-modal,telemetry-consent-form pageErrors=0 testidsInDom=165 (hidden included)"+ ]+}diff --git a/.pr/consent-review-verification-2026-10-12/after-final-ui.json b/.pr/consent-review-verification-2026-10-12/after-final-ui.jsonnew file mode 100644index 0000000000..f656cb0ef2--- /dev/null+++ b/.pr/consent-review-verification-2026-10-12/after-final-ui.json@@ -0,0 +1,6 @@+{+ "ok": true,+ "value": {+ "consent": "granted"+ }+}diff --git a/.pr/consent-review-verification-2026-10-12/after-initial-network.json b/.pr/consent-review-verification-2026-10-12/after-initial-network.jsonnew file mode 100644index 0000000000..61f0da51b9--- /dev/null+++ b/.pr/consent-review-verification-2026-10-12/after-initial-network.json@@ -0,0 +1,39 @@+{+ "ok": true,+ "total": 3,+ "byOrigin": {+ "http://127.0.0.1:18800": 3+ },+ "recent": [+ {+ "ts": "2026-10-12T01:24:27.823Z",+ "origin": "http://127.0.0.1:18800",+ "path": "/api/automation/v1/telemetry/consent",+ "method": "POST",+ "type": "xhr",+ "app": true,+ "status": 200,+ "body": "{\"consent_granted\":false,\"frontend_distinct_id\":\"01a12db5-f50f-7911-98c5-10cc6e4c4b0c\"}"+ },+ {+ "ts": "2026-10-12T01:24:28.043Z",+ "origin": "http://127.0.0.1:18800",+ "path": "/api/automation/v1/telemetry/consent",+ "method": "POST",+ "type": "xhr",+ "app": true,+ "status": 200,+ "body": "{\"consent_granted\":false,\"frontend_distinct_id\":\"01a12db5-f50f-7911-98c5-10cc6e4c4b0c\"}"+ },+ {+ "ts": "2026-10-12T01:24:29.090Z",+ "origin": "http://127.0.0.1:18800",+ "path": "/api/automation/v1/telemetry/consent",+ "method": "POST",+ "type": "xhr",+ "app": true,+ "status": 200,+ "body": "{\"consent_granted\":true,\"frontend_distinct_id\":\"01a12db5-f50f-7911-98c5-10cc6e4c4b0c\"}"+ }+ ]+}diff --git a/.pr/consent-review-verification-2026-10-12/after-reversal-network.json b/.pr/consent-review-verification-2026-10-12/after-reversal-network.jsonnew file mode 100644index 0000000000..c7138a448b--- /dev/null+++ b/.pr/consent-review-verification-2026-10-12/after-reversal-network.json@@ -0,0 +1,29 @@+{+ "ok": true,+ "total": 2,+ "byOrigin": {+ "http://127.0.0.1:18800": 2+ },+ "recent": [+ {+ "ts": "2026-10-12T01:24:57.184Z",+ "origin": "http://127.0.0.1:18800",+ "path": "/api/automation/v1/telemetry/consent",+ "method": "POST",+ "type": "xhr",+ "app": true,+ "status": 200,+ "body": "{\"consent_granted\":false,\"frontend_distinct_id\":\"01a12db5-f50f-7911-98c5-10cc6e4c4b0c\"}"+ },+ {+ "ts": "2026-10-12T01:24:57.566Z",+ "origin": "http://127.0.0.1:18800",+ "path": "/api/automation/v1/telemetry/consent",+ "method": "POST",+ "type": "xhr",+ "app": true,+ "status": 200,+ "body": "{\"consent_granted\":true,\"frontend_distinct_id\":\"01a12db5-f50f-7911-98c5-10cc6e4c4b0c\"}"+ }+ ]+}diff --git a/.pr/consent-review-verification-2026-10-12/after-server-consent.json b/.pr/consent-review-verification-2026-10-12/after-server-consent.jsonnew file mode 100644index 0000000000..a789ebcb7b--- /dev/null+++ b/.pr/consent-review-verification-2026-10-12/after-server-consent.json@@ -0,0 +1,5 @@+{+ "consent_values": [+ true+ ]+}\ No newline at end of filediff --git a/.pr/consent-review-verification-2026-10-12/after-stop.json b/.pr/consent-review-verification-2026-10-12/after-stop.jsonnew file mode 100644index 0000000000..005faeed84--- /dev/null+++ b/.pr/consent-review-verification-2026-10-12/after-stop.json@@ -0,0 +1,17 @@+{+ "run": "/private/tmp/enyst-review-live-20261012/consent-after",+ "browser": {+ "stopped": true,+ "pid": 94373+ },+ "launcherStopped": true,+ "ports": {+ "ingress": "closed",+ "agentServer": "closed",+ "automation": "closed",+ "frontend": "closed",+ "vscode": "closed"+ },+ "evidenceFiles": 2,+ "ok": true+}diff --git a/.pr/consent-review-verification-2026-10-12/before-consent-reversal.gif b/.pr/consent-review-verification-2026-10-12/before-consent-reversal.gifnew file mode 100644index 0000000000..38b89bcc4cBinary files /dev/null and b/.pr/consent-review-verification-2026-10-12/before-consent-reversal.gif differdiff --git a/.pr/consent-review-verification-2026-10-12/before-consent-reversal.mp4 b/.pr/consent-review-verification-2026-10-12/before-consent-reversal.mp4new file mode 100644index 0000000000..39a514bc19Binary files /dev/null and b/.pr/consent-review-verification-2026-10-12/before-consent-reversal.mp4 differdiff --git a/.pr/consent-review-verification-2026-10-12/before-doctor.json b/.pr/consent-review-verification-2026-10-12/before-doctor.jsonnew file mode 100644index 0000000000..f68ba23003--- /dev/null+++ b/.pr/consent-review-verification-2026-10-12/before-doctor.json@@ -0,0 +1,26 @@+{+ "ok": true,+ "run": "/private/tmp/enyst-review-live-20261012/consent-before",+ "baseUrl": "http://127.0.0.1:18800",+ "failed": [],+ "warnings": [+ "LLM configured: model=gpt-5.6 without an API key: `control-openhands llm preset deepseek`"+ ],+ "passed": [+ "launcher process group alive: /opt/homebrew/Cellar/node/25.9.0_1/bin/node /Users/enyst/.codex/worktrees/enyst-pr-ci-maintenance/odie/bin/agent-canvas.",+ "launcher is this run's agent-canvas: /opt/homebrew/Cellar/node/25.9.0_1/bin/node /Users/enyst/.codex/worktrees/enyst-pr-ci-maintenance/odie/bin/agent-canvas.",+ "port ingress:18800 listening: open",+ "port agentServer:18801 listening: open",+ "port automation:18802 listening: open",+ "port frontend:18803 listening: open",+ "served build matches this checkout's build inputs: served=c99f280fbb64b329 run=c99f280fbb64b329 revision=9f5eb1e2e709",+ "checkout build inputs unchanged since launch: launch=c99f280fbb64b329 now=c99f280fbb64b329",+ "unauthenticated API rejected: status=401",+ "authenticated settings readable: status=200",+ "agent-server reachable: version=1.53.0",+ "agent-server matches pin: server=1.53.0, chosen by OH_AGENT_SERVER_VERSION (default pin 1.53.0)",+ "agent-server meets the UI minimum: server=1.53.0 minimum=1.51.0",+ "automation healthy: status=200",+ "UI loads without page errors: markers=first-run-onboarding-screen,onboarding-modal,telemetry-consent-form pageErrors=0 testidsInDom=165 (hidden included)"+ ]+}diff --git a/.pr/consent-review-verification-2026-10-12/before-final-ui.json b/.pr/consent-review-verification-2026-10-12/before-final-ui.jsonnew file mode 100644index 0000000000..f656cb0ef2--- /dev/null+++ b/.pr/consent-review-verification-2026-10-12/before-final-ui.json@@ -0,0 +1,6 @@+{+ "ok": true,+ "value": {+ "consent": "granted"+ }+}diff --git a/.pr/consent-review-verification-2026-10-12/before-initial-network.json b/.pr/consent-review-verification-2026-10-12/before-initial-network.jsonnew file mode 100644index 0000000000..eb0a3d7c88--- /dev/null+++ b/.pr/consent-review-verification-2026-10-12/before-initial-network.json@@ -0,0 +1,59 @@+{+ "ok": true,+ "total": 6,+ "byOrigin": {+ "http://127.0.0.1:18800": 6+ },+ "recent": [+ {+ "ts": "2026-10-12T01:21:23.136Z",+ "origin": "http://127.0.0.1:18800",+ "path": "/api/automation/v1/telemetry/consent",+ "method": "POST",+ "type": "xhr",+ "app": true+ },+ {+ "ts": "2026-10-12T01:21:29.143Z",+ "origin": "http://127.0.0.1:18800",+ "path": "/api/automation/v1/telemetry/consent",+ "method": "POST",+ "type": "xhr",+ "app": true+ },+ {+ "ts": "2026-10-12T01:21:36.145Z",+ "origin": "http://127.0.0.1:18800",+ "path": "/api/automation/v1/telemetry/consent",+ "method": "POST",+ "type": "xhr",+ "app": true+ },+ {+ "ts": "2026-10-12T01:21:45.147Z",+ "origin": "http://127.0.0.1:18800",+ "path": "/api/automation/v1/telemetry/consent",+ "method": "POST",+ "type": "xhr",+ "app": true+ },+ {+ "ts": "2026-10-12T01:22:30.346Z",+ "origin": "http://127.0.0.1:18800",+ "path": "/api/automation/v1/telemetry/consent",+ "method": "POST",+ "type": "xhr",+ "app": true,+ "status": 200+ },+ {+ "ts": "2026-10-12T01:22:42.965Z",+ "origin": "http://127.0.0.1:18800",+ "path": "/api/automation/v1/telemetry/consent",+ "method": "POST",+ "type": "xhr",+ "app": true,+ "status": 200+ }+ ]+}diff --git a/.pr/consent-review-verification-2026-10-12/before-reversal-network.json b/.pr/consent-review-verification-2026-10-12/before-reversal-network.jsonnew file mode 100644index 0000000000..2dae97a212--- /dev/null+++ b/.pr/consent-review-verification-2026-10-12/before-reversal-network.json@@ -0,0 +1,19 @@+{+ "ok": true,+ "total": 1,+ "byOrigin": {+ "http://127.0.0.1:18800": 1+ },+ "recent": [+ {+ "ts": "2026-10-12T01:22:44.508Z",+ "origin": "http://127.0.0.1:18800",+ "path": "/api/automation/v1/telemetry/consent",+ "method": "POST",+ "type": "xhr",+ "app": true,+ "status": 200,+ "body": "{\"consent_granted\":false,\"frontend_distinct_id\":\"01a12db1-e756-7dea-854a-7b83ca48b387\"}"+ }+ ]+}diff --git a/.pr/consent-review-verification-2026-10-12/before-server-consent.json b/.pr/consent-review-verification-2026-10-12/before-server-consent.jsonnew file mode 100644index 0000000000..cd5c252cc7--- /dev/null+++ b/.pr/consent-review-verification-2026-10-12/before-server-consent.json@@ -0,0 +1,5 @@+{+ "consent_values": [+ false+ ]+}\ No newline at end of filediff --git a/.pr/consent-review-verification-2026-10-12/before-stop.json b/.pr/consent-review-verification-2026-10-12/before-stop.jsonnew file mode 100644index 0000000000..fe74da2539--- /dev/null+++ b/.pr/consent-review-verification-2026-10-12/before-stop.json@@ -0,0 +1,17 @@+{+ "run": "/private/tmp/enyst-review-live-20261012/consent-before",+ "browser": {+ "stopped": true,+ "pid": 91239+ },+ "launcherStopped": true,+ "ports": {+ "ingress": "closed",+ "agentServer": "closed",+ "automation": "closed",+ "frontend": "closed",+ "vscode": "closed"+ },+ "evidenceFiles": 4,+ "ok": true+}diff --git a/.pr/telemetry-verification-2026-10-09/README.md b/.pr/telemetry-verification-2026-10-09/README.mdnew file mode 100644index 0000000000..4f01b3ceb5--- /dev/null+++ b/.pr/telemetry-verification-2026-10-09/README.md@@ -0,0 +1,86 @@+# Automation consent recovery β 9 October 2026++Verified executable source: `3900865bbfcb80ee7a399bc04a6a115ab4d5babd` (#16959).+Baseline: `95dcdcdf12bd78f02c52b80cccf2f5f4f35242a4` (main).+Both used isolated production `bin/agent-canvas.mjs` stacks, real Agent Server/SDK+1.53.0, the same pinned Automation service, Node 25.9.0, installed Google Chrome,+English UI and 1440Γ1000 viewports. Doctor verified stack health before the outage.+No API response was mocked and no model was configured or executed.++## Result++**The real startup race reproduces on main and recovers with this PR.**++Both browsers mounted while only their owned Automation service was stopped,+with consent denied. Both sent the actual POST to+`/api/automation/v1/telemetry/consent` and received HTTP 502. The service was then+restored with `control-openhands restart`, retaining the browser page, keys and+state. Neither browser was reloaded after its initial failed sync, and effective+consent remained denied.++- Main: one failed POST at 19:55:17.691 UTC, no subsequent attempt by the final+ observation at 19:56:23 UTC, although Automation was healthy again.+- PR: requests at 19:53:33.406, 34.425, 36.429, 40.433, 48.436 and 19:54:04.445 UTC.+ The final request received HTTP 200. Two restart-window requests have no HTTP+ response recorded; they are not counted as acknowledgements. No additional+ consent POST appeared through the final observation after acknowledgement.+- Original observed payload on every request:+ `{"consent_granted":false,"frontend_distinct_id":null}`.+- Both real Automation health reads returned HTTP 200 with `status=ok`.+- External analytics requests: zero in both browsers. The builds use+ `VITE_DO_NOT_TRACK=1`, so capture stays disabled and no real actor ID is used.++Original safe observations: [main request timeline](main-final-network.json),+[PR request timeline](head-final-network.json), [main health](main-healthy.json),+[PR health](head-healthy.json), [main analytics check](main-analytics-network.json),+[PR analytics check](head-analytics-network.json).++## Reproduction commands++Start fresh isolated runs on the two exact revisions. Do not use someone else's+stack or browser. Keep `OH_VERIFY_RUN` set to each returned run directory.++```sh+export PATH="$PWD/.agents/skills/verify-openhands/scripts:$PATH"+export OH_VERIFY_RUN=$(control-openhands launch --new --print-run)+control-openhands doctor+control-openhands onboard --skip+control-openhands browser goto /settings/app+control-openhands service stop automation+control-openhands browser network --clear+control-openhands browser record start --feature F16.analytics --name startup+control-openhands browser reload+control-openhands browser network --filter /api/automation/v1/telemetry/consent --bodies+control-openhands browser record pause+control-openhands restart+control-openhands api GET /api/automation/health --pick status+# Leave the page mounted and consent unchanged; allow the capped backoff to run.+control-openhands browser network --filter /api/automation/v1/telemetry/consent --bodies+control-openhands browser record resume+control-openhands browser record stop --gif+control-openhands browser network --filter 'posthog|z\.openhands\.dev'+control-openhands stop --purge-private+```++The baseline fixture's visible analytics preference was restored to off before+its final recorded attempt, matching the draft. Hard opt-out kept effective+consent denied in both. No consent mutation, page reload or UI doctor probe was+used between the failed sync and the recorded recovery result; a probe would+mount another app and contaminate the original page's request timeline.++## Reviewed media and limits++[Main recording](main-startup-consent.mp4), [PR recording](head-startup-consent.mp4),+[main UI](main-consent-ui.png), [PR UI](head-consent-ui.png). GIFs preview the same+recordings. These background requests do not change the form's visible controls;+the real request timestamps and statuses establish retry ordering and recovery.+Long service-restoration waits were cut from the videos, as shown above.++This proves denied-consent startup recovery and stop-after-acknowledgement against+real services. It does not claim live Cloud consent, analytics emission, identity+reset, or privacy-clear actor revocation; the existing regression suite covers+those supported state transitions. No automation was created or dispatched.+All owned stacks were stopped, owned ports closed, and private state purged while+review evidence remained available. Raw logs, storage and keys are not published.++Verification performed by an AI agent for Engel Nyst (@enyst).diff --git a/.pr/telemetry-verification-2026-10-09/head-analytics-network.json b/.pr/telemetry-verification-2026-10-09/head-analytics-network.jsonnew file mode 100644index 0000000000..afdad5dd23--- /dev/null+++ b/.pr/telemetry-verification-2026-10-09/head-analytics-network.json@@ -0,0 +1,6 @@+{+ "ok": true,+ "total": 0,+ "byOrigin": {},+ "recent": []+}diff --git a/.pr/telemetry-verification-2026-10-09/head-consent-ui.png b/.pr/telemetry-verification-2026-10-09/head-consent-ui.pngnew file mode 100644index 0000000000..5d212d1d76Binary files /dev/null and b/.pr/telemetry-verification-2026-10-09/head-consent-ui.png differdiff --git a/.pr/telemetry-verification-2026-10-09/head-final-network.json b/.pr/telemetry-verification-2026-10-09/head-final-network.jsonnew file mode 100644index 0000000000..6b044fe9ee--- /dev/null+++ b/.pr/telemetry-verification-2026-10-09/head-final-network.json@@ -0,0 +1,67 @@+{+ "ok": true,+ "total": 6,+ "byOrigin": {+ "http://127.0.0.1:18900": 6+ },+ "recent": [+ {+ "ts": "2026-10-09T19:53:33.406Z",+ "origin": "http://127.0.0.1:18900",+ "path": "/api/automation/v1/telemetry/consent",+ "method": "POST",+ "type": "xhr",+ "app": true,+ "status": 502,+ "body": "{\"consent_granted\":false,\"frontend_distinct_id\":null}"+ },+ {+ "ts": "2026-10-09T19:53:34.425Z",+ "origin": "http://127.0.0.1:18900",+ "path": "/api/automation/v1/telemetry/consent",+ "method": "POST",+ "type": "xhr",+ "app": true,+ "status": 502,+ "body": "{\"consent_granted\":false,\"frontend_distinct_id\":null}"+ },+ {+ "ts": "2026-10-09T19:53:36.429Z",+ "origin": "http://127.0.0.1:18900",+ "path": "/api/automation/v1/telemetry/consent",+ "method": "POST",+ "type": "xhr",+ "app": true,+ "body": "{\"consent_granted\":false,\"frontend_distinct_id\":null}"+ },+ {+ "ts": "2026-10-09T19:53:40.433Z",+ "origin": "http://127.0.0.1:18900",+ "path": "/api/automation/v1/telemetry/consent",+ "method": "POST",+ "type": "xhr",+ "app": true,+ "body": "{\"consent_granted\":false,\"frontend_distinct_id\":null}"+ },+ {+ "ts": "2026-10-09T19:53:48.436Z",+ "origin": "http://127.0.0.1:18900",+ "path": "/api/automation/v1/telemetry/consent",+ "method": "POST",+ "type": "xhr",+ "app": true,+ "status": 502,+ "body": "{\"consent_granted\":false,\"frontend_distinct_id\":null}"+ },+ {+ "ts": "2026-10-09T19:54:04.445Z",+ "origin": "http://127.0.0.1:18900",+ "path": "/api/automation/v1/telemetry/consent",+ "method": "POST",+ "type": "xhr",+ "app": true,+ "status": 200,+ "body": "{\"consent_granted\":false,\"frontend_distinct_id\":null}"+ }+ ]+}diff --git a/.pr/telemetry-verification-2026-10-09/head-healthy.json b/.pr/telemetry-verification-2026-10-09/head-healthy.jsonnew file mode 100644index 0000000000..54f7cf6128--- /dev/null+++ b/.pr/telemetry-verification-2026-10-09/head-healthy.json@@ -0,0 +1,6 @@+{+ "ok": true,+ "status": 200,+ "pick": "status",+ "value": "ok"+}diff --git a/.pr/telemetry-verification-2026-10-09/head-startup-consent.gif b/.pr/telemetry-verification-2026-10-09/head-startup-consent.gifnew file mode 100644index 0000000000..c9e891c966Binary files /dev/null and b/.pr/telemetry-verification-2026-10-09/head-startup-consent.gif differdiff --git a/.pr/telemetry-verification-2026-10-09/head-startup-consent.mp4 b/.pr/telemetry-verification-2026-10-09/head-startup-consent.mp4new file mode 100644index 0000000000..5bcb5dba47Binary files /dev/null and b/.pr/telemetry-verification-2026-10-09/head-startup-consent.mp4 differdiff --git a/.pr/telemetry-verification-2026-10-09/main-analytics-network.json b/.pr/telemetry-verification-2026-10-09/main-analytics-network.jsonnew file mode 100644index 0000000000..afdad5dd23--- /dev/null+++ b/.pr/telemetry-verification-2026-10-09/main-analytics-network.json@@ -0,0 +1,6 @@+{+ "ok": true,+ "total": 0,+ "byOrigin": {},+ "recent": []+}diff --git a/.pr/telemetry-verification-2026-10-09/main-consent-ui.png b/.pr/telemetry-verification-2026-10-09/main-consent-ui.pngnew file mode 100644index 0000000000..99260666d2Binary files /dev/null and b/.pr/telemetry-verification-2026-10-09/main-consent-ui.png differdiff --git a/.pr/telemetry-verification-2026-10-09/main-final-network.json b/.pr/telemetry-verification-2026-10-09/main-final-network.jsonnew file mode 100644index 0000000000..4307bdbac2--- /dev/null+++ b/.pr/telemetry-verification-2026-10-09/main-final-network.json@@ -0,0 +1,19 @@+{+ "ok": true,+ "total": 1,+ "byOrigin": {+ "http://127.0.0.1:18920": 1+ },+ "recent": [+ {+ "ts": "2026-10-09T19:55:17.691Z",+ "origin": "http://127.0.0.1:18920",+ "path": "/api/automation/v1/telemetry/consent",+ "method": "POST",+ "type": "xhr",+ "app": true,+ "status": 502,+ "body": "{\"consent_granted\":false,\"frontend_distinct_id\":null}"+ }+ ]+}diff --git a/.pr/telemetry-verification-2026-10-09/main-healthy.json b/.pr/telemetry-verification-2026-10-09/main-healthy.jsonnew file mode 100644index 0000000000..54f7cf6128--- /dev/null+++ b/.pr/telemetry-verification-2026-10-09/main-healthy.json@@ -0,0 +1,6 @@+{+ "ok": true,+ "status": 200,+ "pick": "status",+ "value": "ok"+}diff --git a/.pr/telemetry-verification-2026-10-09/main-startup-consent.gif b/.pr/telemetry-verification-2026-10-09/main-startup-consent.gifnew file mode 100644index 0000000000..4410b6aef8Binary files /dev/null and b/.pr/telemetry-verification-2026-10-09/main-startup-consent.gif differdiff --git a/.pr/telemetry-verification-2026-10-09/main-startup-consent.mp4 b/.pr/telemetry-verification-2026-10-09/main-startup-consent.mp4new file mode 100644index 0000000000..6e81b71142Binary files /dev/null and b/.pr/telemetry-verification-2026-10-09/main-startup-consent.mp4 differdiff --git a/__tests__/hooks/use-sync-automation-telemetry-consent.test.ts b/__tests__/hooks/use-sync-automation-telemetry-consent.test.tsindex 2a0552ce22..4127b26168 100644--- a/__tests__/hooks/use-sync-automation-telemetry-consent.test.ts+++ b/__tests__/hooks/use-sync-automation-telemetry-consent.test.ts@@ -1,5 +1,6 @@+import React from "react";import { act, renderHook } from "@testing-library/react";-import { beforeEach, describe, expect, it, vi } from "vitest";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";const syncTelemetryConsentMock = vi.fn();const state = {@@ -7,6 +8,7 @@ const state = {backendKind: "local" as "local" | "cloud",backendHost: "http://localhost:8000",backendApiKey: "key-1",+ backendConnectionRevision: 0,consent: "pending" as "pending" | "granted" | "denied",pendingRevocationId: null as string | null,};@@ -26,6 +28,7 @@ vi.mock("#/contexts/active-backend-context", () => ({kind: state.backendKind,host: state.backendHost,apiKey: state.backendApiKey,+ connectionRevision: state.backendConnectionRevision,},}),}));@@ -44,18 +47,24 @@ import { useSyncAutomationTelemetryConsent } from "#/hooks/use-sync-automation-tdescribe("useSyncAutomationTelemetryConsent", () => {beforeEach(() => {+ vi.useRealTimers();vi.clearAllMocks();syncTelemetryConsentMock.mockResolvedValue(undefined);listeners.clear();state.backendId = "local-1";state.backendHost = "http://localhost:8000";state.backendApiKey = "key-1";+ state.backendConnectionRevision = 0;state.backendKind = "local";state.consent = "pending";state.pendingRevocationId = null;});+ afterEach(() => {+ vi.useRealTimers();+ });+it("does not call the local automation consent API while consent is pending", () => {renderHook(() => useSyncAutomationTelemetryConsent());@@ -118,10 +127,254 @@ describe("useSyncAutomationTelemetryConsent", () => {const { rerender } = renderHook(() => useSyncAutomationTelemetryConsent());state.backendApiKey = "key-2";+ state.backendConnectionRevision = 1;rerender();expect(syncTelemetryConsentMock).toHaveBeenCalledTimes(2);expect(syncTelemetryConsentMock).toHaveBeenNthCalledWith(1, "granted");expect(syncTelemetryConsentMock).toHaveBeenNthCalledWith(2, "granted");});++ it("syncs after a launcher key rotation reloads the app", () => {+ state.consent = "granted";+ const { unmount } = renderHook(() => useSyncAutomationTelemetryConsent());++ unmount();+ state.backendApiKey = "key-2";+ renderHook(() => useSyncAutomationTelemetryConsent());++ expect(syncTelemetryConsentMock).toHaveBeenCalledTimes(2);+ expect(syncTelemetryConsentMock).toHaveBeenLastCalledWith("granted");+ });++ it("retries a failed sync with backoff until it succeeds", async () => {+ vi.useFakeTimers();+ state.consent = "granted";+ syncTelemetryConsentMock+ .mockRejectedValueOnce(new Error("temporarily unavailable"))+ .mockResolvedValueOnce(undefined);++ const { rerender } = renderHook(() => useSyncAutomationTelemetryConsent());+ await act(async () => Promise.resolve());++ expect(syncTelemetryConsentMock).toHaveBeenCalledTimes(1);++ await act(async () => vi.advanceTimersByTimeAsync(1000));+ expect(syncTelemetryConsentMock).toHaveBeenCalledTimes(2);++ rerender();+ expect(syncTelemetryConsentMock).toHaveBeenCalledTimes(2);+ });++ it("retries the pending revocation after a privacy clear", async () => {+ vi.useFakeTimers();+ state.consent = "denied";+ state.pendingRevocationId = "user-before-reset";+ syncTelemetryConsentMock+ .mockRejectedValueOnce(new Error("offline"))+ .mockRejectedValueOnce(new Error("still offline"))+ .mockResolvedValueOnce(undefined);++ renderHook(() => useSyncAutomationTelemetryConsent());+ await act(async () => Promise.resolve());++ act(() => {+ state.consent = "pending";+ listeners.forEach((listener) => listener());+ });+ await act(async () => Promise.resolve());++ expect(syncTelemetryConsentMock).toHaveBeenCalledTimes(2);+ await act(async () => vi.advanceTimersByTimeAsync(1000));+ expect(syncTelemetryConsentMock).toHaveBeenCalledTimes(3);+ expect(syncTelemetryConsentMock).toHaveBeenNthCalledWith(3, "denied");+ });++ it("caps retry backoff while consent remains unacknowledged", async () => {+ vi.useFakeTimers();+ state.consent = "denied";+ syncTelemetryConsentMock.mockRejectedValue(new Error("offline"));++ renderHook(() => useSyncAutomationTelemetryConsent());+ await act(async () => Promise.resolve());++ const retryDelays = [1000, 2000, 4000, 8000, 16_000, 30_000, 30_000];+ for (const [index, delay] of retryDelays.entries()) {+ await act(async () => vi.advanceTimersByTimeAsync(delay - 1));+ expect(syncTelemetryConsentMock).toHaveBeenCalledTimes(index + 1);++ await act(async () => vi.advanceTimersByTimeAsync(1));+ expect(syncTelemetryConsentMock).toHaveBeenCalledTimes(index + 2);+ }+ });++ it("lets a consent change supersede an older in-flight sync", async () => {+ let rejectFirst: ((reason?: unknown) => void) | undefined;+ const firstRequest = new Promise<void>((_resolve, reject) => {+ rejectFirst = reject;+ });+ syncTelemetryConsentMock+ .mockReturnValueOnce(firstRequest)+ .mockResolvedValueOnce(undefined);+ state.consent = "granted";++ renderHook(() => useSyncAutomationTelemetryConsent());+ act(() => {+ state.consent = "denied";+ listeners.forEach((listener) => listener());+ });++ expect(syncTelemetryConsentMock).toHaveBeenCalledTimes(2);+ expect(syncTelemetryConsentMock).toHaveBeenNthCalledWith(1, "granted");+ expect(syncTelemetryConsentMock).toHaveBeenNthCalledWith(2, "denied");++ await act(async () => {+ rejectFirst?.(new Error("stale request failed"));+ await Promise.resolve();+ });++ // A failed response does not prove that the older write was never applied.+ // Reassert the current denial after that attempt settles.+ expect(syncTelemetryConsentMock).toHaveBeenNthCalledWith(3, "denied");+ });++ it.each([+ ["granted", "denied"],+ ["denied", "granted"],+ ] as const)(+ "restores %s after a late %s acknowledgement overwrites it",+ async (currentConsent, interveningConsent) => {+ let serverConsent: "granted" | "denied" | undefined;+ let acknowledgeIntervening: (() => void) | undefined;+ const interveningRequest = new Promise<void>((resolve) => {+ acknowledgeIntervening = () => {+ serverConsent = interveningConsent;+ resolve();+ };+ });+ syncTelemetryConsentMock.mockImplementation((consent) => {+ if (consent === interveningConsent) return interveningRequest;+ serverConsent = consent;+ return Promise.resolve();+ });+ state.consent = currentConsent;+ const { rerender } = renderHook(() =>+ useSyncAutomationTelemetryConsent(),+ );+ await act(async () => Promise.resolve());++ act(() => {+ state.consent = interveningConsent;+ listeners.forEach((listener) => listener());+ });+ act(() => {+ state.consent = currentConsent;+ listeners.forEach((listener) => listener());+ });+ await act(async () => Promise.resolve());+ await act(async () => {+ acknowledgeIntervening?.();+ await Promise.resolve();+ });+ rerender();++ expect(serverConsent).toBe(currentConsent);+ expect(+ syncTelemetryConsentMock.mock.calls.map(([consent]) => consent),+ ).toEqual([+ currentConsent,+ interveningConsent,+ currentConsent,+ currentConsent,+ ]);+ },+ );++ it("does not reassert consent on another backend after an old request settles", async () => {+ let acknowledgeOldBackend: (() => void) | undefined;+ const oldRequest = new Promise<void>((resolve) => {+ acknowledgeOldBackend = resolve;+ });+ syncTelemetryConsentMock+ .mockReturnValueOnce(oldRequest)+ .mockResolvedValueOnce(undefined);+ state.consent = "granted";+ const { rerender } = renderHook(() => useSyncAutomationTelemetryConsent());++ state.backendId = "local-2";+ rerender();+ await act(async () => Promise.resolve());+ await act(async () => {+ acknowledgeOldBackend?.();+ await Promise.resolve();+ });++ expect(syncTelemetryConsentMock).toHaveBeenCalledTimes(2);+ });++ it("does not reassert consent after unmount with an older write pending", async () => {+ let acknowledgeOldWrite: (() => void) | undefined;+ const oldRequest = new Promise<void>((resolve) => {+ acknowledgeOldWrite = resolve;+ });+ syncTelemetryConsentMock+ .mockReturnValueOnce(oldRequest)+ .mockResolvedValueOnce(undefined);+ state.consent = "granted";+ const { unmount } = renderHook(() => useSyncAutomationTelemetryConsent());+ act(() => {+ state.consent = "denied";+ listeners.forEach((listener) => listener());+ });+ await act(async () => Promise.resolve());++ unmount();+ await act(async () => {+ acknowledgeOldWrite?.();+ await Promise.resolve();+ });++ expect(syncTelemetryConsentMock).toHaveBeenCalledTimes(2);+ });++ it("cancels the prior retry when the backend changes", async () => {+ vi.useFakeTimers();+ state.consent = "granted";+ syncTelemetryConsentMock+ .mockRejectedValueOnce(new Error("backend one unavailable"))+ .mockResolvedValueOnce(undefined);+ const { rerender } = renderHook(() => useSyncAutomationTelemetryConsent());+ await act(async () => Promise.resolve());++ state.backendId = "local-2";+ rerender();+ expect(syncTelemetryConsentMock).toHaveBeenCalledTimes(2);++ await act(async () => vi.advanceTimersByTimeAsync(30_000));+ expect(syncTelemetryConsentMock).toHaveBeenCalledTimes(2);+ });++ it("does not retry after unmount", async () => {+ vi.useFakeTimers();+ state.consent = "granted";+ syncTelemetryConsentMock.mockRejectedValueOnce(new Error("offline"));+ const { unmount } = renderHook(() => useSyncAutomationTelemetryConsent());+ await act(async () => Promise.resolve());++ unmount();+ await act(async () => vi.advanceTimersByTimeAsync(30_000));++ expect(syncTelemetryConsentMock).toHaveBeenCalledTimes(1);+ });++ it("does not duplicate an in-flight request during Strict Mode replay", () => {+ state.consent = "granted";+ syncTelemetryConsentMock.mockReturnValue(new Promise<void>(() => {}));+ const wrapper = ({ children }: React.PropsWithChildren) =>+ React.createElement(React.StrictMode, null, children);++ renderHook(() => useSyncAutomationTelemetryConsent(), { wrapper });++ expect(syncTelemetryConsentMock).toHaveBeenCalledTimes(1);+ });});diff --git a/src/api/automation-service/automation-service.api.test.ts b/src/api/automation-service/automation-service.api.test.tsindex 793af7a138..d2f7b8d42e 100644--- a/src/api/automation-service/automation-service.api.test.ts+++ b/src/api/automation-service/automation-service.api.test.ts@@ -185,6 +185,16 @@ describe("AutomationService.syncTelemetryConsent", () => {);});+ it("keeps a pending local revocation when consent sync fails", async () => {+ localAxios.post.mockRejectedValueOnce(new Error("automation unavailable"));++ await expect(+ AutomationService.syncTelemetryConsent("denied"),+ ).rejects.toThrow("automation unavailable");++ expect(clearPendingLocalTelemetryRevocation).not.toHaveBeenCalled();+ });+it("skips cloud backends because cloud consent is handled by auth", async () => {setRegisteredBackends([cloudBackend]);setActiveSelection({ backendId: cloudBackend.id, orgId: "org-1" });diff --git a/src/hooks/use-sync-automation-telemetry-consent.ts b/src/hooks/use-sync-automation-telemetry-consent.tsindex c597f28cde..d8522d1bee 100644--- a/src/hooks/use-sync-automation-telemetry-consent.ts+++ b/src/hooks/use-sync-automation-telemetry-consent.ts@@ -7,6 +7,15 @@ import {subscribeTelemetryConsent,} from "#/services/telemetry";+const INITIAL_RETRY_DELAY_MS = 1000;+const MAX_RETRY_DELAY_MS = 30_000;++interface DesiredConsentSync {+ key: string;+ connectionKey: string;+ consent: "granted" | "denied";+}+export function useSyncAutomationTelemetryConsent() {const { backend } = useActiveBackend();const consent = React.useSyncExternalStore(@@ -14,26 +23,118 @@ export function useSyncAutomationTelemetryConsent() {getTelemetryConsent,() => "pending" as const,);- const lastSyncKeyRef = React.useRef<string | null>(null);+ const desiredSyncRef = React.useRef<DesiredConsentSync | null>(null);+ const syncCurrentRef = React.useRef<(() => void) | null>(null);+ const inFlightKeysRef = React.useRef(new Set<string>());+ const lastSuccessfulKeyRef = React.useRef<string | null>(null);+ const retryStateRef = React.useRef<{+ key: string;+ failureCount: number;+ } | null>(null);+ const retryTimerRef = React.useRef<ReturnType<typeof setTimeout> | null>(+ null,+ );React.useEffect(() => {+ const clearRetryTimer = () => {+ if (retryTimerRef.current !== null) {+ clearTimeout(retryTimerRef.current);+ retryTimerRef.current = null;+ }+ };+const pendingRevocationId =consent === "pending" ? getPendingLocalTelemetryRevocationId() : null;if (backend.kind !== "local" ||(consent === "pending" && !pendingRevocationId)) {- return;+ desiredSyncRef.current = null;+ syncCurrentRef.current = null;+ clearRetryTimer();+ retryStateRef.current = null;+ return undefined;}const resolvedConsent = consent === "granted" ? "granted" : "denied";const pendingActor = consent === "pending" ? pendingRevocationId : "";- const syncKey = `${backend.id}:${backend.host}:${backend.apiKey ?? ""}:${resolvedConsent}:${pendingActor}`;- if (lastSyncKeyRef.current === syncKey) return;- lastSyncKeyRef.current = syncKey;-- void AutomationService.syncTelemetryConsent(resolvedConsent).catch(- () => {},- );- }, [backend.apiKey, backend.host, backend.id, backend.kind, consent]);+ const connectionKey = `${backend.id}:${backend.connectionRevision ?? 0}`;+ const syncKey = `${connectionKey}:${resolvedConsent}:${pendingActor}`;+ desiredSyncRef.current = {+ key: syncKey,+ connectionKey,+ consent: resolvedConsent,+ };++ if (retryStateRef.current?.key !== syncKey) {+ clearRetryTimer();+ retryStateRef.current = { key: syncKey, failureCount: 0 };+ }++ const startSync = () => {+ const desired = desiredSyncRef.current;+ if (+ desired?.key !== syncKey ||+ retryTimerRef.current !== null ||+ lastSuccessfulKeyRef.current === syncKey ||+ inFlightKeysRef.current.has(syncKey)+ ) {+ return;+ }++ inFlightKeysRef.current.add(syncKey);+ // An intervening write makes the prior acknowledgement insufficient if+ // the user returns to that value while this request is still in flight.+ lastSuccessfulKeyRef.current = null;++ void AutomationService.syncTelemetryConsent(desired.consent)+ .then(() => {+ if (desiredSyncRef.current?.key !== syncKey) return;+ lastSuccessfulKeyRef.current = syncKey;+ retryStateRef.current = null;+ clearRetryTimer();+ })+ .catch(() => {+ if (desiredSyncRef.current?.key !== syncKey) return;++ const failureCount =+ retryStateRef.current?.key === syncKey+ ? retryStateRef.current.failureCount + 1+ : 1;+ retryStateRef.current = { key: syncKey, failureCount };+ const retryDelay = Math.min(+ INITIAL_RETRY_DELAY_MS * 2 ** Math.min(failureCount - 1, 10),+ MAX_RETRY_DELAY_MS,+ );+ clearRetryTimer();+ retryTimerRef.current = setTimeout(() => {+ retryTimerRef.current = null;+ startSync();+ }, retryDelay);+ })+ .finally(() => {+ inFlightKeysRef.current.delete(syncKey);+ const latest = desiredSyncRef.current;+ if (+ latest?.connectionKey === connectionKey &&+ latest.key !== syncKey+ ) {+ // The older write may have reached the server after the latest+ // acknowledgement, even if its response failed. Reassert the+ // current consent once it settles, scoped to this connection.+ lastSuccessfulKeyRef.current = null;+ }+ syncCurrentRef.current?.();+ });+ };++ syncCurrentRef.current = startSync;+ startSync();++ return () => {+ desiredSyncRef.current = null;+ syncCurrentRef.current = null;+ clearRetryTimer();+ };+ }, [backend.connectionRevision, backend.id, backend.kind, consent]);}