Skip to content

[OPIK-6838] [FE] fix: link Playground prompt versions to experiments and traces#7017

Merged
awkoy merged 10 commits into
mainfrom
fix/opik-6838-prompt-linkage
Jun 10, 2026
Merged

[OPIK-6838] [FE] fix: link Playground prompt versions to experiments and traces#7017
awkoy merged 10 commits into
mainfrom
fix/opik-6838-prompt-linkage

Conversation

@awkoy

@awkoy awkoy commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Details

Experiments and traces created from the Playground over a regular Dataset (or via a direct run) silently lost their Prompt Library version link, while runs over a Test Suite kept it. Root cause: the dataset/"log" path collected only per-message TEXT prompt versions and ignored the loaded CHAT prompt version (loadedChatPromptVersionId), whereas the test-suite/"execute" path collected both. This produced an empty "Prompt commit" column, dataset experiments missing from a prompt's Experiments tab, and no prompt reference in the single-experiment view.

This PR removes that drift by introducing one shared version collector used by both paths, surfaces the prompt-version link in the Configuration tab, and keeps the trace↔prompt reference even after a loaded prompt is edited. Frontend-only — no backend, migrations, or v1 changes.

  • Extract collectPromptVersionRefs + buildPromptLibraryMetadata into a shared, unit-tested src/api/playground/promptLinkage.ts (single source of truth); reuse it in both the execute and log paths.
  • Dataset/log path now links CHAT prompt versions → fixes the empty "Prompt commit" column and dataset experiments missing from the prompt's Experiments tab.
  • Add a prompt-version link in the single-experiment Configuration tab (deep-links to the experiment's exact version via activeVersionId).
  • Trace linkage (metadata.opik_prompts, a frontend-only field) now keeps the reference for edited prompts with a modified flag, plus a "modified" badge on the trace's Prompts card; TEXT path anchors to the message's own version instead of latest.

Change checklist

  • User facing
  • Documentation update

Issues

  • OPIK-6838

AI-WATERMARK

AI-WATERMARK: yes

  • Tools: Claude-Code
  • Model: Opus-4.8
  • Scope: All files
  • Human verification: Yes — reproduced all 4 issues as broken on main, then verified each fixed in the running app (local, OpenAI provider, Chrome).

Testing

Commands (from apps/opik-frontend):

  • npm run typecheck — clean (project-wide)
  • npm run lint — 0 warnings (project-wide)
  • npm run test -- src/api/playground — pass, including new promptLinkage.test.ts (9 cases)
  • npx vitest run (full suite) — 1751 passed. The only failures (23 in src/lib/ls-migrations/*) are a pre-existing happy-dom localStorage.clear env issue, unrelated to this change (they fail in isolation and touch none of the changed files).

Manual UI (local process mode, OpenAI provider, Chrome) — loaded a CHAT library prompt into the Playground and ran an experiment over a regular Dataset:

Not run: a live screenshot of the modified: true badge — local ClickHouse trace-list ingestion lag prevented surfacing the edited-run trace in time. The modified flag is confirmed present in trace metadata and the badge rendering is covered by code review.

Documentation

N/A — no user-facing docs change.

🤖 Generated with Claude Code

awkoy and others added 7 commits June 10, 2026 12:21
…e path (OPIK-6838)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ed flag (OPIK-6838 #4)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…838 #2)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…on in Configuration tab (OPIK-6838)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@awkoy
awkoy requested a review from a team as a code owner June 10, 2026 13:34
Comment thread apps/opik-frontend/src/v2/pages/PlaygroundPage/useHydratePromptMetadata.ts Outdated
…er (OPIK-6838)

Addresses the Baz review comment plus the multi-agent final-review findings:
- Dedupe the version-resolution logic shared by the CHAT and TEXT paths in
  useHydratePromptMetadata into a single tested helper.
- Resolve the embedded latest_version without an extra fetch when no explicit
  version is requested (restores pre-refactor perf parity for the TEXT path).
- Pass the resolved PromptVersion straight to buildPromptLibraryMetadata
  instead of re-spreading its fields at both call sites.
- Add unit tests for resolvePromptVersionForLink, metadata pass-through, and
  multi-message collection.
Comment on lines +94 to +98
export const resolvePromptVersionForLink = async (
promptData: { latest_version?: PromptVersion } | undefined,
explicitVersionId: string | undefined,
fetchPromptVersion: FetchPromptVersion,
): Promise<PromptVersion | undefined> => {

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.

resolvePromptVersionForLink duplicates the version-resolution/fetch logic in v1 useHydratePromptMetadata, so should we reuse this helper there too or extract a shared function?

Severity

Want Baz to fix this for you? Activate Fixer

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.

Commit 2c53828 addressed this comment by extracting the prompt-version linkage logic into shared helpers in promptLinkage.ts, which matches the suggested “extract a shared function” refactor. That removes the duplicated version-selection logic from the old per-path implementation.

@awkoy awkoy added the test-environment Deploy Opik adhoc environment label Jun 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔄 Test environment deployment process has started

Phase 1: Deploying base version 2.0.61-5585 (from main branch) if environment doesn't exist
Phase 2: Building new images from PR branch fix/opik-6838-prompt-linkage
Phase 3: Will deploy newly built version after build completes

You can monitor the progress here.

…vation (OPIK-6838)

Replace the compound ternary (compare-guard + optional chaining + .length
truthiness + empty fallback) with a clear compare-vs-single branch; the
consumer maps the array, so an empty array renders nothing.
Comment on lines 67 to 73
const isCompare = experimentsIds.length > 1;

// Prompt-version links only make sense for a single experiment; in compare
// mode we don't show them. An empty array simply renders nothing.
const promptVersions = isCompare ? [] : experiments[0]?.prompt_versions ?? [];

const [columnsWidth, setColumnsWidth] = useLocalStorageState<

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.

promptVersions/NavigationTag prompt-link rendering duplicates CompareExperimentsDetails.tsx, should we extract a shared helper/component so both tabs stay in sync?

Severity

Want Baz to fix this for you? Activate Fixer

@CometActions

Copy link
Copy Markdown
Collaborator

Test environment is now available!

To configure additional Environment variables for your environment, run [Deploy Opik AdHoc Environment workflow] (https://github.com/comet-ml/comet-deployment/actions/workflows/deploy_opik_adhoc_env.yaml)

Access Information

The deployment has completed successfully and the version has been verified.

Comment on lines +39 to +42
const versionRefs = collectPromptVersionRefs(prompt);
const promptVersions = versionRefs.length
? versionRefs.map((ref) => ({ id: ref.id, prompt_id: ref.promptId }))
: undefined;

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.

Lines 39-42 duplicate the collectPromptVersionRefs(prompt) -> prompt_versions/promptLibraryVersions mapping from usePromptDatasetItemCombination.ts; should we move this into promptLinkage.ts as something like buildPromptVersionsPayload so both paths share the same {id, prompt_id?} shape?

Severity

Want Baz to fix this for you? Activate Fixer

@aadereiko aadereiko left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM :)

@awkoy
awkoy merged commit b332629 into main Jun 10, 2026
10 checks passed
@awkoy
awkoy deleted the fix/opik-6838-prompt-linkage branch June 10, 2026 15:39
awkoy added a commit that referenced this pull request Jun 11, 2026
Follow-up to PR #7017. Review feedback on the prompt-linkage work flagged
that experiment surfaces show the raw prompt commit hash, which users don't
recognize. Show the human-readable version (version_number, e.g. v3) next to
the prompt name, mirroring the already-approved Prompt Library experiments
tab, and fall back to the commit hash only when no version number is
available (null for masks).

Surfaces updated (all v2, display-only — no data-layer/BE change):
- ExperimentsPage/GeneralDatasetsTab: "Prompt commit" column -> "Prompt",
  rendering "<name> (<version>)" via version_label.
- CompareExperimentsPage/ConfigurationTab: NavigationTag label built from
  version_number ?? commit instead of commit.
- dashboards/ExperimentsLeaderboardWidget: same column fix (caught in review;
  identical commit-hash issue on the dashboard leaderboard).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
awkoy added a commit that referenced this pull request Jun 12, 2026
…sh in experiment views (#7031)

* [OPIK-6838] [FE] fix: show prompt name + version instead of commit hash

Follow-up to PR #7017. Review feedback on the prompt-linkage work flagged
that experiment surfaces show the raw prompt commit hash, which users don't
recognize. Show the human-readable version (version_number, e.g. v3) next to
the prompt name, mirroring the already-approved Prompt Library experiments
tab, and fall back to the commit hash only when no version number is
available (null for masks).

Surfaces updated (all v2, display-only — no data-layer/BE change):
- ExperimentsPage/GeneralDatasetsTab: "Prompt commit" column -> "Prompt",
  rendering "<name> (<version>)" via version_label.
- CompareExperimentsPage/ConfigurationTab: NavigationTag label built from
  version_number ?? commit instead of commit.
- dashboards/ExperimentsLeaderboardWidget: same column fix (caught in review;
  identical commit-hash issue on the dashboard leaderboard).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* [OPIK-6838] [FE] refactor: extract shared formatPromptVersionLabel helper

Address review feedback (baz): the "<name> (<version>)" formatting was
duplicated across the three surfaces. Centralize it in a single tested
helper in lib/experiments.ts and reuse it from the Experiments table column,
the single-experiment Configuration tab, and the dashboard leaderboard widget
so the display rule changes in one place.

Also adds unit tests for the version-number/commit fallback and the
no-version case.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
jverre pushed a commit that referenced this pull request Jun 12, 2026
…and traces (#7017)

* feat(playground): add shared prompt-version linkage helpers (OPIK-6838)

* refactor(playground): reuse shared prompt-version collector in execute path (OPIK-6838)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(playground): link CHAT prompt versions on dataset experiment runs (OPIK-6838 #1,#3)

* fix(playground): keep trace prompt link on edited prompts with modified flag (OPIK-6838 #4)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(traces): show modified badge on edited playground prompt link (OPIK-6838 #4)

* feat(experiments): link prompt version from Configuration tab (OPIK-6838 #2)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(playground): anchor TEXT prompt version + link experiment's version in Configuration tab (OPIK-6838)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* refactor(playground): extract shared resolvePromptVersionForLink helper (OPIK-6838)

Addresses the Baz review comment plus the multi-agent final-review findings:
- Dedupe the version-resolution logic shared by the CHAT and TEXT paths in
  useHydratePromptMetadata into a single tested helper.
- Resolve the embedded latest_version without an extra fetch when no explicit
  version is requested (restores pre-refactor perf parity for the TEXT path).
- Pass the resolved PromptVersion straight to buildPromptLibraryMetadata
  instead of re-spreading its fields at both call sites.
- Add unit tests for resolvePromptVersionForLink, metadata pass-through, and
  multi-message collection.

* refactor(experiments): simplify Configuration tab promptVersions derivation (OPIK-6838)

Replace the compound ternary (compare-guard + optional chaining + .length
truthiness + empty fallback) with a clear compare-vs-single branch; the
consumer maps the array, so an empty array renders nothing.

* refactor(playground): hoist prompt_versions request mapping to a named const (OPIK-6838)

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
jverre pushed a commit that referenced this pull request Jun 12, 2026
…sh in experiment views (#7031)

* [OPIK-6838] [FE] fix: show prompt name + version instead of commit hash

Follow-up to PR #7017. Review feedback on the prompt-linkage work flagged
that experiment surfaces show the raw prompt commit hash, which users don't
recognize. Show the human-readable version (version_number, e.g. v3) next to
the prompt name, mirroring the already-approved Prompt Library experiments
tab, and fall back to the commit hash only when no version number is
available (null for masks).

Surfaces updated (all v2, display-only — no data-layer/BE change):
- ExperimentsPage/GeneralDatasetsTab: "Prompt commit" column -> "Prompt",
  rendering "<name> (<version>)" via version_label.
- CompareExperimentsPage/ConfigurationTab: NavigationTag label built from
  version_number ?? commit instead of commit.
- dashboards/ExperimentsLeaderboardWidget: same column fix (caught in review;
  identical commit-hash issue on the dashboard leaderboard).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* [OPIK-6838] [FE] refactor: extract shared formatPromptVersionLabel helper

Address review feedback (baz): the "<name> (<version>)" formatting was
duplicated across the three surfaces. Centralize it in a single tested
helper in lib/experiments.ts and reuse it from the Experiments table column,
the single-experiment Configuration tab, and the dashboard leaderboard widget
so the display rule changes in one place.

Also adds unit tests for the version-number/commit fallback and the
no-version case.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Frontend test-environment Deploy Opik adhoc environment typescript *.ts *.tsx

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants