Repository navigation
studio: expose launcher capability bits on unauth /api/health - #5486
Conversation
PR #5375 reduced the unauthenticated /api/health response to {status, timestamp} only, on the theory that the rest of the payload was useful fingerprinting. That was too aggressive: the Tauri watchdog reads `service == "Unsloth UI Backend"` and `studio_root_id` to re-adopt its own backend across restarts (src-tauri/src/desktop_backend_owner.rs and commands.rs), and the SPA bootstrap fetches the same payload unauth to detect chat-only mode and native path lease support before any token is available (frontend src/config/env.ts and features/native-intents/use-native-readiness.ts). With the post-#5375 shape, the watchdog kills its own healthy backend, the SPA never flips out of "full Studio" mode on chat-only Linux/Windows, and the About tab shows "dev" in place of the real version. The actual fingerprint-ish fields are `version` / `studio_version` / `device_type` (and to a lesser extent the hostname inside `device_type`). `service`, `studio_root_id` (already a hex digest of the install path, not the raw path), `chat_only`, the desktop_* capability flags, and `native_path_leases_supported` do not leak the install path or version. This patch keeps the auth gate but rebalances which fields sit on each side of it: unauth service, studio_root_id, chat_only, desktop_protocol_version, desktop_manageability_version, supports_desktop_auth, supports_desktop_backend_ownership, native_path_leases_supported, desktop_owner (when present) authed + version, studio_version, device_type Existing must-change-password sessions still fall through to the base payload because get_current_subject (strict) rejects them; that matches prior behaviour. test_middleware.py is updated to pin the new contract: launcher bits present unauth, fingerprint fields present only with a valid bearer.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 91ddab550d
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if not auth.lower().startswith("bearer "): | ||
| return minimal | ||
| return base |
There was a problem hiding this comment.
Expose version to unauth desktop probes
When the Tauri preflight probes /api/health it does so without an Authorization header (studio/src-tauri/src/preflight/backend.rs::backend_health), but after this return path it now gets service and the other capability fields without version. That makes backend_capability_stale_reason() call backend_version_stale_reason(None), so an otherwise current backend is classified as Old { reason: "desktop_backend_version_missing" } instead of Ready, breaking the re-adopt/owned-ready path this change is trying to enable. Either include a non-fingerprinting version field for unauth desktop probes or update the Tauri version gate to not require it on this unauth health response.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Code Review
This pull request updates the /api/health endpoint to expose launcher capability bits to unauthenticated callers, facilitating frontend and launcher integration, while maintaining authentication requirements for sensitive host fingerprinting data. The changes include a refactor of the health check logic and updated test coverage. A review comment suggests adding logging to a broad exception handler in the health check to improve observability during authentication failures.
| except Exception: | ||
| return minimal | ||
| return base |
There was a problem hiding this comment.
The broad except Exception block silently returns the base payload. Per the general rules, unexpected exceptions should be logged (e.g., at a debug or warning level) to assist with troubleshooting if the authentication logic fails unexpectedly.
| except Exception: | |
| return minimal | |
| return base | |
| except Exception: | |
| logger.exception("Unexpected error during health check auth") | |
| return base |
References
- Avoid using broad, silent exception handlers like
except Exception: pass. Instead, log the exception, even if at a debug level, to aid in future debugging.
…t tab Reviewer follow-ups to the unauth /api/health launcher bits split. Tauri preflight: backend_capability_stale_reason() fell through to backend_version_stale_reason(health.version.as_deref()) when capability bits were present but version was absent. With the unauth payload now exposing service + studio_root_id + desktop_* bits but gating version behind a bearer, the desktop watchdog was reading the new payload, parsing all capability bits, then classifying the same-root backend as desktop_backend_version_missing and refusing to adopt it. A backend that exposes desktop_protocol_version=1, desktop_manageability_version>=1, supports_desktop_auth=true and supports_desktop_backend_ownership=true was introduced together with MIN_DESKTOP_BACKEND_VERSION=2026.5.3 in #5341, so a present capability bitset is itself a version-compatibility signal. Skip the version sub-check when version is None/empty; keep it for non-empty values so genuinely-too-old backends that do echo a version still get desktop_backend_version_too_old. About tab: fetchStudioVersions() did a bare fetch(apiUrl("/api/health")), which the unauth payload no longer carries version/studio_version for, so Settings -> About kept rendering "dev"/"dev" for any logged-in user. Attach Authorization: Bearer <token> when getAuthToken() returns one; fall back to bare fetch (still 200, just truncated payload) for the not-logged-in case. No new endpoint. Comment: studio_root_id is no longer a hex digest of the install path; it is an opaque per-install id written by the launcher. Updated the inline comment to match. Test: - python -m pytest studio/backend/tests/test_middleware.py::TestHealthAuthGate studio/backend/tests/test_desktop_auth.py -q -> 29 passed - npm run typecheck clean, npm run build produces fresh dist
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0acddb69f1
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if not auth.lower().startswith("bearer "): | ||
| return minimal | ||
| return base |
There was a problem hiding this comment.
Keep adopted backends from looking stale
When this unauthenticated path returns base without version, the owned-backend adoption probe still fails its readiness gate: desktop_backend_owner::fetch_health() does a bare GET, and ready_for_use_status() still calls backend_version_stale_reason(health.version.as_deref()), so None becomes desktop_backend_version_missing and the verified backend is reported as OwnedStale instead of OwnedReady. Fresh evidence after the previous review is that preflight/backend.rs now special-cases missing versions, but the separate owned-backend readiness path in desktop_backend_owner.rs:534-537 was not updated, so re-adopted desktop-owned backends still won't reach the ready/watchdog path.
Useful? React with 👍 / 👎.
Summary
The hardening pass in #5375 reduced the unauthenticated
/api/healthresponse to{status, timestamp}only. That broke three downstream consumers that legitimately read this payload before any token exists:src-tauri/src/commands.rs:274anddesktop_backend_owner.rs:105-112) needsservice == "Unsloth UI Backend"andstudio_root_idto re-adopt its own backend across restarts. Without them it kills its own healthy backend and spawns a new one.src/config/env.ts:49,features/native-intents/use-native-readiness.ts:21,features/settings/tabs/about-tab.tsx:51) bare-fetches/api/healthunauth. With the reduced payload,chat_onlydefaults false on Linux/Windows (full Studio shows in chat-only installs), native file leases never enable, and About reportsPackage Version: dev.The real fingerprint-shaped fields are
version/studio_version/device_type.service,studio_root_id(already a hex digest of the install path, not the raw path),chat_only, thedesktop_*capability flags, andnative_path_leases_supporteddo not leak the install path or version.What changed
studio/backend/main.py:health_checknow splits the response into two layers:status,timestamp,service,studio_root_id,chat_only,desktop_protocol_version,desktop_manageability_version,supports_desktop_auth,supports_desktop_backend_ownership,native_path_leases_supported, plusdesktop_ownerwhen presentversion,studio_version,device_typeMust-change-password sessions still fall through to the unauth payload because
get_current_subject(strict) rejects them. That preserves prior behaviour.Test plan
studio/backend/tests/test_middleware.py::TestHealthAuthGateupdated to pin the new contract. All 3 subtests pass.test_middleware.py+test_desktop_auth.pypass (39 tests).GET /api/healthreturns launcher bits, no versionversion: "2026.5.2",studio_version,device_type: "linux"