Skip to content

studio: expose launcher capability bits on unauth /api/health - #5486

Merged
danielhanchen merged 4 commits into
mainfrom
studio-health-launcher-bits
May 18, 2026
Merged

danielhanchen merged 4 commits into
mainfrom
studio-health-launcher-bits

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

The hardening pass in #5375 reduced the unauthenticated /api/health response to {status, timestamp} only. That broke three downstream consumers that legitimately read this payload before any token exists:

  • The Tauri watchdog (src-tauri/src/commands.rs:274 and desktop_backend_owner.rs:105-112) needs service == "Unsloth UI Backend" and studio_root_id to re-adopt its own backend across restarts. Without them it kills its own healthy backend and spawns a new one.
  • The SPA bootstrap (src/config/env.ts:49, features/native-intents/use-native-readiness.ts:21, features/settings/tabs/about-tab.tsx:51) bare-fetches /api/health unauth. With the reduced payload, chat_only defaults false on Linux/Windows (full Studio shows in chat-only installs), native file leases never enable, and About reports Package 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, the desktop_* capability flags, and native_path_leases_supported do not leak the install path or version.

What changed

studio/backend/main.py:health_check now splits the response into two layers:

  • unauth -- 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, plus desktop_owner when present
  • authed (valid bearer + not must-change-password) -- adds version, studio_version, device_type

Must-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::TestHealthAuthGate updated to pin the new contract. All 3 subtests pass.
  • Whole test_middleware.py + test_desktop_auth.py pass (39 tests).
  • Live curl against a running Studio:
    • unauth GET /api/health returns launcher bits, no version
    • authed with bootstrap user (must_change_password=True) returns launcher bits, no version (gate still active)
    • authed with rotated password returns launcher bits + version: "2026.5.2", studio_version, device_type: "linux"

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread studio/backend/main.py
Comment on lines 521 to +522
if not auth.lower().startswith("bearer "):
return minimal
return base

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread studio/backend/main.py
Comment on lines 534 to +535
except Exception:
return minimal
return base

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
except Exception:
return minimal
return base
except Exception:
logger.exception("Unexpected error during health check auth")
return base
References
  1. 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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread studio/backend/main.py
Comment on lines 521 to +522
if not auth.lower().startswith("bearer "):
return minimal
return base

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

@danielhanchen
danielhanchen merged commit 2fbbf8a into main May 18, 2026
34 checks passed
@danielhanchen
danielhanchen deleted the studio-health-launcher-bits branch May 18, 2026 04:29
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