Skip to content

core: Fail sign-in at once where no link can bring the callback back - #2722

Merged
huacnlee merged 2 commits into
longbridge:mainfrom
hmziqrs:auth-session-without-links
Nov 21, 2026
Merged

huacnlee merged 2 commits into
longbridge:mainfrom
hmziqrs:auth-session-without-links

Conversation

@hmziqrs

@hmziqrs hmziqrs commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Closes #2709

Description

open_auth_session in a Rust app that claims its callback scheme waited forever on the platforms that hand the app no links of its schemes: the web (a page hears only its own address), and the GPUI and terminal backends (no URL-scheme events at all). #2285 meant such a session to fail at once with ERR_FEATURE_UNAVAILABLE_ON_PLATFORM, and rust.md and open_auth_session's doc say so. It now does.

This takes the first of the two ways #2709 offers, since os == Os::Web alone would leave GPUI and the terminal backend waiting:

  • nsh_core::platform::Environment::scheme_links: Option<bool>, with Environment::scheme_links(). It follows clipboard_images: None (the default) is as NSH's native backends on os, every OS but the web. The GPUI backend (initial_environment) and the terminal backend (AppView::new) say Some(false). A platform built outside NSH that hears no links says Some(false) too: platform-extensions.md's example and docs/dev/platforms.md now say so. The Mini Program platform reports iOS or Android, so it needs that one line to get the immediate failure; until it has it, it behaves as today.
  • I chose a default that follows the OS over one that is off (which runtime: open_auth_session never answers where no link can bring its callback back (the web, GPUI, the terminal platform) #2709 also floated) so that nothing changes for headless runs, embedders or platforms built outside NSH that do deliver links.
  • The engine hands the resolved value to the core (nsh_core::element::Environment::scheme_links: bool, in ui_environment), and start_auth_session refuses a session the platform does not show itself (Environment::auth_session) where scheme_links is false, before the claimed-scheme check, with its own message: "openAuthSession: no in-app sign-in here, and no link of myapp: can reach the app on this platform".
  • iOS and Android show sessions in the app, so the check never applies there. macOS, Windows and Linux leave the field None and resolve to true, as do headless runs (Os::default()).
  • Docs: the auth_session module doc, open_auth_session's and AuthSessionError::unavailable's doc, Headless::on_auth_session's doc, docs/dev/platforms.md, docs/dev/api-naming.md's decision row, and rust.md and platform-extensions.md in en and zh-CN.

Making sign-in complete on the web is a separate question, as #2709 says.

Public API

  • nsh_core::platform::Environment::scheme_links: Option<bool>: whether the platform hands the app links of the schemes it claims; None follows os.
  • nsh_core::platform::Environment::scheme_links(&self) -> bool: the field, or by the OS (all but the web).
  • nsh_core::element::Environment::scheme_links: bool: the resolved value the core reads.

Breaking Changes

  • Both Environment structs gain a public field and are not #[non_exhaustive], so a struct literal without ..Default::default() outside NSH no longer compiles, as with tab_bar, clipboard_images, shaders and auth_session before it. Every literal in the repository uses ...
  • Behavior: on the web and the GPUI and terminal backends, open_auth_session with a claimed scheme now fails at once instead of opening the page and never answering. No JS API changes (open_auth_session is Rust only).
 // A platform built outside NSH, or a test, that writes `Environment` out in full:
 Environment {
     os: Os::Ios,
     platform: Some("miniprogram"),
+    // It hands the app no links of its schemes:
+    scheme_links: Some(false),
-    // (every other field)
+    ..Environment::default()
 }

How to Test

  • cargo test -p nsh-testing --lib -- session: 4 passed, including the new where_no_link_of_the_apps_schemes_comes_the_session_fails_at_once: the web refuses at once and opens nothing; Some(false) refuses on an OS that would otherwise hear links; Some(true) on the web opens the page and the callback link ends the session; a session the platform shows itself needs no link.
  • cargo test -p nsh-core --lib -- scheme_links auth_session: scheme_links_follow_the_os_unless_the_platform_says covers every Os with None, Some(false) and Some(true).
  • Seen to fail: with the new check disabled in start_auth_session, and with ui_environment handing the core true, the headless test fails (the session waits).
  • cargo test with core CI's packages and features (-p nsh-core -p nsh-macros -p nsh-js -p nsh-base -p nsh-engine -p nsh-bundler -p nsh-package -p nsh-testing --features nsh-bundler/bundle,nsh-testing/bundle,nsh-testing/agent, --no-fail-fast): all pass but two that fail the same way on main (228a4eb) on this Mac: nsh-core's lib tests abort with a stack overflow in a spawned thread, and nsh-base's rich_editor::view_features::selection_boxes_are_drawn_in_task_items_and_code_blocks.
  • cargo test -p nsh-platform-tui: passes.
  • cargo clippy --all-targets -p nsh-core -p nsh-engine -p nsh-testing -p nsh-platform-tui --features nsh-testing/bundle,nsh-testing/agent -- -D warnings: clean.
  • GPUI: cargo clippy --manifest-path crates/gpui/Cargo.toml -p nsh-platform-gpui --all-targets --features runtime-shaders -- -D warnings: clean (runtime-shaders because this Mac has no Metal toolchain). cargo test --manifest-path crates/gpui/Cargo.toml -p nsh-platform-gpui --features runtime-shaders: 301 passed.
  • cargo +nightly fmt --all -- --check: nothing in the changed files (its only diff is nsh-platform-linux/src/text.rs, as on main).
  • Not run: a browser, a GPUI window or a terminal by hand; the change there is the field each sets, covered through the headless test.

Checklist

  • I have read the CONTRIBUTING document and followed the guidelines.
  • Reviewed the changes in this PR and confirmed AI generated code (if any) is accurate.
  • Passed cargo test --workspace, cargo +nightly fmt --all and clippy (including the Catalyst and Android runs for platform code): core CI's test command, clippy and fmt above; not the whole workspace, Catalyst or Android (iOS and Android are not touched).
  • Changes to what apps use keep what released versions shipped and come with a case in tests/compat/ (cargo xtask compat): no JS change.
  • Ran the related examples/gallery demos on iOS and Android (if the change is visible or platform-specific): not touched on iOS or Android.

@huacnlee

Copy link
Copy Markdown
Member

💡 Needs the maintainer's call on a new public field: nsh_core::platform::Environment::scheme_links: Option<bool> (+ scheme_links() and a resolved bool on the element env).

Reviewed 9370660. The fix is right: on the web, GPUI and TUI backends an openAuthSession that relies on a scheme callback waited forever; now it fails at once with ERR_FEATURE_UNAVAILABLE_ON_PLATFORM. The field follows the existing clipboard_images: Option<bool> precedent (None = by OS), so it is consistent and opt-in for platform authors only, not app-facing. The smaller alternative (os == Web only) would leave GPUI/TUI hanging. Ran cargo test -p nsh-core scheme_links and cargo test -p nsh-testing where_no_link: pass.

🤖 Noop (reviewer) · AI agent acting for @huacnlee

@huacnlee huacnlee left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

✅ API accepted: Environment::scheme_links follows the existing clipboard_images pattern and is only set by platform backends.

The maintainers accepted the new field after the earlier 💡 review (head 9370660, unchanged). Ready to merge once CI is green.

🤖 Noop (reviewer) · AI agent acting for @huacnlee

@huacnlee
huacnlee merged commit bef26b2 into longbridge:main Nov 21, 2026
7 of 22 checks passed
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.

runtime: open_auth_session never answers where no link can bring its callback back (the web, GPUI, the terminal platform)

3 participants