Skip to content

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

Open
Aftabbs wants to merge 1 commit into
comet-ml:mainfrom
Aftabbs:fix/experiment-url-v2
Open

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

Conversation

@Aftabbs

@Aftabbs Aftabbs commented Jul 23, 2026

Copy link
Copy Markdown

Details

get_experiment_url_by_id was generating a session-redirect URL
(v1/session/redirect/experiments/?experiment_id=...&dataset_id=...) that
routes through the user's session context. This surfaced the experiment under
the wrong scope in the UI instead of opening the compare view directly.

The fix replaces the session-redirect URL with the direct compare-page URL
pattern used by get_dataset_url_by_id and get_test_suite_url_by_id (added
in #7467):

{domain_root}opik/{workspace}/experiments/{dataset_id}/compare?experiments=["{experiment_id}"]

The workspace is added as a new parameter (available as client._workspace
at all call sites in evaluator.py).

Change checklist

  • User facing

Issues

AI-WATERMARK

AI-WATERMARK: yes

  • Tools: Claude Code
  • Model(s): claude-sonnet-4-6
  • Scope: url_helpers.py (function signature + implementation), evaluator.py (5 call sites), test_url_helpers.py (3 new parametrized cases)
  • Human verification: diff reviewed; test cases verified against the URL pattern used by get_dataset_url_by_id

Testing

New test: test_get_experiment_url_by_id__returns_direct_workspace_scoped_url
— 3 parametrized cases (localhost, localhost with trailing slash, cloud URL).

Run with:

cd sdks/python
pytest tests/unit/test_url_helpers.py -v

Documentation

No documentation change required — this fixes an internal log/link URL, not a public API.

…t link in evaluate()

Replaces the legacy session-redirect URL with the same direct URL pattern
used by get_dataset_url_by_id and get_test_suite_url_by_id. The
session-redirect URL surfaces the experiment under the wrong scope; the
direct URL opens the compare page immediately in the correct workspace.

Closes comet-ml#7462
@Aftabbs
Aftabbs requested a review from a team as a code owner July 23, 2026 10:28
@github-actions github-actions Bot added python Pull requests that update Python code tests Including test files, or tests related like configuration. Python SDK labels Jul 23, 2026
Comment on lines 605 to +609
experiment_url = url_helpers.get_experiment_url_by_id(
experiment_id=experiment.id,
dataset_id=dataset.id,
url_override=client.config.url_override,
base_url=client.config.url_override,
workspace=client._workspace,

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.

Placeholder workspace builds wrong URLs

_evaluate_task() and the other evaluator link sites pass workspace=client._workspace into url_helpers.get_experiment_url_by_id(), so when OpikConfig.workspace is the "default" placeholder the compare link points at /opik/default/... instead of the resolved workspace — should we route this through Opik._dereferenced_workspace() first?

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/evaluation/evaluator.py around lines 549-630 inside
`_evaluate_task`, the `experiment_url = url_helpers.get_experiment_url_by_id(...)` call
passes `workspace=client._workspace`, which embeds the raw workspace placeholder into
the URL. Refactor it to pass the dereferenced/resolved workspace (e.g.,
`workspace=client._dereferenced_workspace()` or an equivalent public accessor) so when
the configured workspace is "default" the generated link targets the actual workspace.
Apply the same fix to the other `url_helpers.get_experiment_url_by_id()` occurrences in
this file: `__internal_api__run_test_suite__` (~lines 408-415), `evaluate_prompt`
(~1192-1199), `evaluate_experiment` (~886-892), and `_evaluate_test_suite_task`
(~739-745).

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.

Undocumented public URL contract

get_experiment_url_by_id() now uses workspace to build the compare-page link, but the public contract isn't documented, so callers can't tell that workspace is required or what URL shape they get — can we add a short docstring covering that?

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, update the public function
`get_experiment_url_by_id` (new signature with `dataset_id`, `experiment_id`,
`base_url`, `workspace`) to include a short docstring. Explain that `workspace` is
required to scope the returned link and that the function returns the direct experiments
compare page URL in the form
`...opik/{workspace}/experiments/{dataset_id}/compare?experiments=...`. Keep it
consistent with the surrounding URL helper documentation so callers can rely on the
documented contract.

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