Skip to content

Use vscode:// deep links for session URLs in VS Code - #194

Open
ajma wants to merge 10 commits into
mainfrom
worktree-vscode-session-links
Open

Use vscode:// deep links for session URLs in VS Code#194
ajma wants to merge 10 commits into
mainfrom
worktree-vscode-session-links

Conversation

@ajma

@ajma ajma commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • When running inside VS Code (VSCODE_PID set), session detail messages/links now show both a Cloud Console link and a vscode://googlecloudtools.datacloud/dataproc/sessions/<id>?project=<project>&location=<region> deep link, instead of trying to detect which one to show.
  • Reliably detecting whether the extension is installed turned out to be impractical: code --list-extensions isn't always on PATH, its behavior is unreliable when forwarded through the Remote-SSH shim, extensions directories differ across forks/code-server, and even a correct disk scan can't confirm client-side installation state from a remote backend. Rather than chase that, we just always show both links and let the extension's own URI handler be the point of failure if it's missing.
  • Labeled clearly: "Managed Spark Session (Cloud Console)" and "Managed Spark Session (Data Agent Kit)".
  • Applied to the three call sites that build the exact .../dataproc/interactive/{region}/{session_id}?project={project_id} URL shape: the new-session-created message, the reattach-to-existing-session message, and the notebook _repr_html_ (which now shows both session links plus "Spark UI").
  • Left unchanged: the Colab Enterprise-only "View Session Details" button (unreachable from VS Code) and the Spark UI / per-operation links (different URL shape, not in scope).

Test plan

  • Added/updated tests for _display_session_link_on_creation, _get_exiting_active_session, and _repr_html_ asserting both links are present when in VS Code, and a test confirming no vscode link when not.
  • uv run pyink --check clean on all changed files.
  • uv run pytest tests/unit/ — 165 passed, 1 pre-existing unrelated failure (test_create_session_without_application_default_credentials, fails identically on main).

When running inside VS Code, session detail links now point to the
googlecloudtools.datacloud extension's session view instead of the
Cloud Console, for the session-creation message, existing-session
reattach message, and the notebook repr's session link.

@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 introduces a helper function _build_session_details_url to dynamically generate VS Code-specific session URLs when running in a VS Code environment, updating several display and print locations to use this helper. Unit tests are also added to verify this behavior. The feedback suggests updating the type hints of the helper's parameters to Optional[str] to prevent static analysis errors, and registering cleanups for mock.patch.dict calls in the unit tests to avoid test environment pollution.

Comment thread google/cloud/managed_spark_connect/session.py Outdated
Comment thread tests/unit/test_session.py
Comment thread tests/unit/test_session.py
Comment thread tests/unit/test_session.py
Comment thread google/cloud/managed_spark_connect/session.py Outdated
Address review feedback: the url was being assembled partly in
_repr_html_ and partly inline in the <a href>; build it in full where
the other session-related urls are constructed.
region and project_id are always passed self._region/self._project_id,
which are Optional[str] until a session connects.
Comment thread google/cloud/managed_spark_connect/session.py Outdated
)

_VSCODE_SESSION_URI_BASE = (
"vscode://googlecloudtools.datacloud/dataproc/sessions"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This only works if they have DAK installed, it will fail confusingly otherwise.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch — fixed in 48d68a3. Added environment.is_vscode_extension_installed(), which shells out to code --list-extensions (cached, fails closed on any error/timeout/missing CLI), and _build_session_details_url now only uses the vscode:// link when the extension is actually installed, falling back to the Cloud Console url otherwise.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

code --list-extensions only works for VS Code, not for its various forks (agy-ide, etc.). Sorry for not having more helpful suggestions, but I'm worried there is no reliable way to tell what IDE it's running in. I don't even know if VSCODE_PID is reliable...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah, I'm struggling to find another solution too. let me poke around a bit more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Follow-up on this: code may not be on PATH even when VS Code and the extension are installed (e.g. macOS before running "Shell Command: Install 'code' command in PATH", or a remote/SSH session). Added a fallback in eb35825 that scans the on-disk extensions directories (~/.vscode/extensions, ~/.vscode-server/extensions, etc.) directly when the CLI check doesn't find it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

One more follow-up: on a vscode-server (Remote-SSH) backend, code --list-extensions goes through a client-forwarding shim whose behavior for that flag isn't reliable, so in 6bb6ffa I skip the CLI check entirely when running on a detected remote backend (~/.vscode-server present) and trust only the ~/.vscode-server/extensions disk scan there.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Simplified this in 4eed13d: dropped the extension-detection logic entirely (it kept growing more edge cases — PATH, Remote-SSH shim reliability, forks, code-server). Now we just always show both the Cloud Console link and the vscode:// link when running inside VS Code, and let the extension's own URI handler be the failure point if it's not installed.

The vscode:// deep link only resolves if googlecloudtools.datacloud is
installed; otherwise VS Code shows a generic, confusing error. Check
via `code --list-extensions` and fall back to the Cloud Console url
when it's not present or the check can't run.
@ajma
ajma force-pushed the worktree-vscode-session-links branch from 48d68a3 to 728f341 Compare September 10, 2026 21:58
code may not be on PATH even when VS Code and the extension are
installed (e.g. macOS before running "Shell Command: Install 'code'
command in PATH", or a remote/SSH session using .vscode-server). Scan
the on-disk extensions directories as a fallback so the vscode:// link
still shows up in those cases.
On a remote backend, code runs through a client-forwarding shim whose
--list-extensions behavior isn't reliable, so only the on-disk
~/.vscode-server/extensions scan is trusted there.
Reliably detecting whether the Data Analytics Kit extension is
installed proved impractical across local VS Code, Remote-SSH, and
forks. Simplify by always showing both the Cloud Console link and the
vscode:// deep link whenever running inside VS Code, and let the
extension's own URI handler be the point of failure if it's missing.
Rename the link labels to "Managed Spark Session (Cloud Console)" and
"Managed Spark Session (Data Agent Kit)" so it's clear which link goes
where.
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.

2 participants