Skip to content

[SDK] fix: use direct workspace-scoped URL for experiment link in evaluate() - #7463

Closed
Aftabbs wants to merge 1 commit into
comet-ml:mainfrom
Aftabbs:fix/experiment-url-direct-7393-followup
Closed

[SDK] fix: use direct workspace-scoped URL for experiment link in evaluate()#7463
Aftabbs wants to merge 1 commit into
comet-ml:mainfrom
Aftabbs:fix/experiment-url-direct-7393-followup

Conversation

@Aftabbs

@Aftabbs Aftabbs commented Jul 14, 2026

Copy link
Copy Markdown

Summary

Follow-up to #7440 (which fixed get_dataset_url_by_id). This PR fixes get_experiment_url_by_id() to use the same direct-URL pattern instead of the opaque session-redirect.

Before:

View your experiment at:
http://localhost:5173/v1/session/redirect/experiments/?experiment_id=abc&dataset_id=xyz&path=aHR0cDovL2xvY2FsaG9zdDo1MTczL2FwaQ==

After:

View your experiment at:
http://localhost:5173/opik/default/experiments/xyz/compare?experiments=%5B%22abc%22%5D

Changes

  • url_helpers.py: Changed get_experiment_url_by_id(dataset_id, experiment_id, url_override) to get_experiment_url_by_id(dataset_id, experiment_id, base_url, workspace). The direct URL mirrors the pattern in get_project_url_by_id() and get_dataset_url_by_id() (post-[issue-7393] [SDK] fix: use direct project-scoped URL for dataset in get_or_create_dataset log #7440). The experiments query param is URL-encoded JSON (%5B%22id%22%5D) to match TanStack Router's JsonParam convention on the Compare Experiments page.
  • evaluator.py: Updated all 5 call sites to pass base_url=client.config.url_override, workspace=client._workspace.
  • test_url_helpers.py: Added 3 parametrized cases covering localhost, trailing-slash variant, and cloud URL.

Design decision

get_experiment_url_by_id now accepts workspace explicitly (like get_project_url_by_id and get_dataset_url_by_id). For users on the default OSS workspace, client._workspace is "default", which is the correct path segment. For Comet cloud users, client._workspace holds the actual workspace name. This matches existing conventions in the codebase.

Test plan

  • pytest sdks/python/tests/unit/test_url_helpers.py -k test_get_experiment_url_by_id — all 3 new cases pass
  • Run evaluate() against a local opik instance; verify the printed URL opens directly in the browser without a redirect hop

Closes #7462

…luate()

Replace the session-redirect URL in get_experiment_url_by_id() with a
direct frontend URL, matching the approach used for get_project_url_by_id()
and the dataset URL fix in comet-ml#7440.

The new URL format is:
  {domain_root}opik/{workspace}/experiments/{dataset_id}/compare?experiments={json_encoded_ids}

The JSON experiments array is URL-encoded to satisfy TanStack Router's
JsonParam query parameter convention used on the CompareExperimentsPage.

All 5 call sites in evaluator.py are updated to pass base_url and
workspace (client._workspace) instead of url_override.

Closes comet-ml#7462.
@Aftabbs
Aftabbs requested a review from a team as a code owner July 14, 2026 07:04
@github-actions github-actions Bot added python Pull requests that update Python code tests Including test files, or tests related like configuration. Python SDK 🟢 size/S labels Jul 14, 2026
Comment on lines 31 to +36
def get_experiment_url_by_id(
dataset_id: str, experiment_id: str, url_override: str
dataset_id: str, experiment_id: str, base_url: str, workspace: str
) -> str:
encoded_opik_url = base64.b64encode(url_override.encode("utf-8")).decode("utf-8")

project_path = urllib.parse.quote(
f"v1/session/redirect/experiments/?experiment_id={experiment_id}&dataset_id={dataset_id}&path={encoded_opik_url}",
safe=ALLOWED_URL_CHARACTERS,
)
return urllib.parse.urljoin(ensure_ending_slash(url_override), project_path)
domain_root = get_base_url(base_url)
experiments_param = urllib.parse.quote(json.dumps([experiment_id]))
return f"{domain_root}opik/{workspace}/experiments/{dataset_id}/compare?experiments={experiments_param}"

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.

Broken compare-page links

get_experiment_url_by_id() emits /opik/{workspace}/experiments/{dataset_id}/compare without the /projects/{projectId} segment the compare route expects (per apps/opik-frontend/src/v2/router.tsx), so experiment_url stored in EvaluationResult doesn't resolve — should we add project_id back to the path, or reuse the previous redirect URL approach?

Severity

Want Baz to fix this for you? Activate Fixer

Other fix methods

Fix in Cursor

Prompt for AI Agents
Before applying, verify this suggestion against the current code. In
sdks/python/src/opik/url_helpers.py around lines 31-36 in `get_experiment_url_by_id()`,
the returned URL no longer includes the required `/projects/{projectId}` path segment
and therefore won't resolve to the frontend compare page
(`apps/opik-frontend/src/v2/router.tsx` and `useDatasetIdFromCompareExperimentsURL.ts`).
Refactor the helper to generate a project-scoped compare/redirect URL again: either add
`project_id` to the function parameters and include it in the path before
`/experiments/{dataset_id}/compare`, or reuse the previous redirect URL approach so the
emitted `experiment_url` matches what the routed page expects. After updating the URL
construction, run/adjust any existing unit tests and add a small test/fixture that
asserts the produced URL contains the `/projects/` segment for external consumers.

@Aftabbs

Aftabbs commented Jul 23, 2026

Copy link
Copy Markdown
Author

Closing in favour of a clean replacement PR based on the current main (which added get_base_url, get_dataset_url_by_id with project_id, and get_test_suite_url_by_id since this branch was opened). The new PR resolves the merge conflict and targets the same fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Python SDK python Pull requests that update Python code 🟢 size/S tests Including test files, or tests related like configuration.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[SDK] Fix experiment URL logged by evaluate() to use direct workspace-scoped URL

1 participant