Skip to content

[FIX] Keep the Prompt Studio back-reference in tool registry listing; drop dead adapter-choices route#2204

Open
hari-kuriakose wants to merge 2 commits into
mainfrom
fix/registry-back-reference-dead-adapter-choices
Open

[FIX] Keep the Prompt Studio back-reference in tool registry listing; drop dead adapter-choices route#2204
hari-kuriakose wants to merge 2 commits into
mainfrom
fix/registry-back-reference-dead-adapter-choices

Conversation

@hari-kuriakose

@hari-kuriakose hari-kuriakose commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Purpose

Fixes two small, self-contained backend bugs in the tool registry surface.


1. Registry listing drops the back-reference to the Prompt Studio project

There is no way to correlate a registry entry with the project that produced it. fetch_json_for_registry projects only four keys — name, description, icon, function_name — where function_name is the prompt_registry_id, a fresh UUID, not the Prompt Studio tool_id. Callers are forced to match on name, which is ambiguous whenever two projects share one.

The data is already present and simply discarded: PromptStudioRegistry has a custom_tool OneToOneField pointing back at the project, and PromptStudioRegistrySerializer is fields = "__all__", so custom_tool is already in pi_serializer.data. The projection just never copied it across.

The frontend already pays for the omission. In CreateApiDeploymentFromPromptStudio.jsx:

tool.function_name === toolDetails.tool_id || tool.name === toolDetails.tool_name

The first clause can never be true (a registry UUID compared against a Prompt Studio tool_id), so correlation silently falls through to the ambiguous name comparison. Exposing custom_tool lets callers correlate exactly.

custom_tool is null=True, so legacy rows report None rather than failing. Additive only — no existing key changes, so nothing consuming this listing breaks.

2. prompt-studio/adapter-choices/ routes to a method that does not exist

Returns 500 server_error on every call.

prompt_studio_adapter_choices = PromptStudioCoreView.as_view(
    {"get": "get_adapter_choices"}
)

get_adapter_choices is not defined — not on PromptStudioCoreView, not anywhere in the backend. The route resolves, the handler is missing, every request 500s.

Fix: remove it, so the path 404s honestly instead of 500ing. The only two references in the repo were the as_view registration and the URL entry itself, and no frontend code calls it. Listing LLM adapters is already available server-side via the adapter list endpoint filtered by type.


Verification

  • A repo-wide search for adapter_choices / adapter-choices returns nothing after the change.
  • urls.py parses cleanly.
  • ruff and ruff-format pass at the version pinned in .pre-commit-config.yaml (v0.3.4).

Impact

  • The registry listing can offer real tool_id filtering, and the frontend's dead first clause can be replaced with a correct comparison in a follow-up.
  • A dead endpoint stops returning 500.

Related

Part of a set of independent Prompt Studio / registry fixes: #2203 (profile fallback + challenge-off deploy), #2206 (registry delete + API-key ergonomics), #2209 (challenge-on deploy). No code dependency between them.

🤖 Generated with Claude Code

… drop dead adapter-choices route

1. `tool` listing dropped the link back to the Prompt Studio project

After `export-tool` there was no way to correlate a registry entry with the
project that produced it. `fetch_json_for_registry` projected only four keys -
`name`, `description`, `icon`, `function_name` - where `function_name` is the
`prompt_registry_id`, a fresh UUID, not the Prompt Studio `tool_id`. Callers
were left matching on `name`, which is ambiguous whenever two projects share
one.

The data was already there and simply discarded: `PromptStudioRegistry` has a
`custom_tool` OneToOneField pointing straight back at the project, and the
serializer is `fields = "__all__"`, so it is already present in the serialized
data. The listing now carries it.

The frontend shows the cost of the omission today:

    tool.function_name === toolDetails.tool_id || tool.name === toolDetails.tool_name

The first clause can never match (a registry UUID is compared against a Prompt
Studio tool_id), so correlation silently falls through to the ambiguous name
comparison. With `custom_tool` exposed, callers can correlate exactly.

`custom_tool` is `null=True`, so legacy rows report `None` rather than failing.
Additive only - no existing key changes.

2. `prompt-studio/adapter-choices/` routed to a method that does not exist

The URL mapped `get` to `get_adapter_choices`, which is not defined on
`PromptStudioCoreView` or anywhere else in the backend. The route resolved, the
handler was missing, and every request returned 500 `server_error`.

Removed the route and its `as_view` registration so the path 404s honestly
instead of 500ing. Verified there are no other references: the only two in the
repo were the route registration and the URL entry, and no frontend code calls
it. `adapter list --adapter-type LLM` already covers this server-side.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

The changes remove the Prompt Studio adapter-choices endpoint and add a custom_tool schema key whose value is included in registry tool metadata, with regression tests covering the updated projection.

Changes

Prompt Studio registry and routing

Layer / File(s) Summary
Preserve custom-tool registry references
backend/prompt_studio/prompt_studio_registry_v2/constants.py, backend/prompt_studio/prompt_studio_registry_v2/prompt_studio_registry_helper.py, backend/prompt_studio/prompt_studio_registry_v2/tests/test_fetch_json_for_registry.py
Adds JsonSchemaKey.CUSTOM_TOOL, projects the serialized back-reference into tool metadata, and tests identity preservation, legacy rows, row isolation, and duplicate names.
Remove adapter-choices endpoint
backend/prompt_studio/prompt_studio_core_v2/urls.py
Removes the DRF view binding and URL pattern for prompt-studio/adapter-choices/.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the fixes, but it does not follow the required template and omits sections like What/Why/How, breakage, migrations, env config, and checklist. Rewrite the PR description to match the repository template and fill in all required sections, especially breakage impact, migrations, env config, testing, and checklist.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title accurately summarizes both changes: preserving the registry back-reference and removing the dead adapter-choices route.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/registry-back-reference-dead-adapter-choices

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Removes a dead Prompt Studio adapter-choices route and preserves the source Prompt Studio project ID in tool-registry listings.

  • Adds custom_tool to projected Prompt Studio registry metadata.
  • Adds regression coverage for the registry projection and legacy null references.
  • Removes the URL registration for the nonexistent adapter-choices handler.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failures remain.

Important Files Changed

Filename Overview
backend/prompt_studio/prompt_studio_core_v2/urls.py Removes the route and registration for an undefined, unreferenced adapter-choices action.
backend/prompt_studio/prompt_studio_registry_v2/constants.py Adds the constant used to project the Prompt Studio project back-reference.
backend/prompt_studio/prompt_studio_registry_v2/prompt_studio_registry_helper.py Adds the source CustomTool identifier to each user-scoped Prompt Studio registry-list entry.
backend/prompt_studio/prompt_studio_registry_v2/tests/test_fetch_json_for_registry.py Adds regression tests covering the back-reference, existing fields, nullable legacy rows, and duplicate project names.

Reviews (2): Last reviewed commit: "[TEST] Pin the Prompt Studio back-refere..." | Re-trigger Greptile

Regression tests for the `custom_tool` projection added in this PR.

Exercises the real `fetch_json_for_registry` body, stubbing only the
ORM/serializer boundary, since the function is a pure projection over
already-serialized rows. Django is not importable in a plain checkout, so the
body is extracted from source - mirroring
`prompt_studio_core_v2/tests/test_build_index_payload.py`.

Coverage:
  - the listing carries `custom_tool` (the Prompt Studio tool_id)
  - `function_name` remains the registry UUID and is distinct from
    `custom_tool`, pinning the distinction that made the back-reference
    necessary and guarding against "fixing" the frontend's dead comparison by
    redefining `function_name` instead
  - existing keys are preserved, so the change stays additive
  - an unlinked legacy row (`custom_tool` is nullable) reports None rather than
    raising, and is not dropped
  - rows do not bleed into each other: the loop reuses one dict and resets it
    per row, and a missing reset would smear one project's back-reference onto
    the next - callers would then correlate confidently and wrongly
  - two projects sharing a name stay distinguishable, which is the scenario the
    old four-key projection could not represent

Verified by mutation: removing the `custom_tool` projection fails five of the
six tests, with the sixth (existing-keys) correctly unaffected.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

Unstract test results

Per-group results

Status Group Tier Passed Failed Errors Skipped Duration (s)
e2e-api-deployment e2e 3 0 0 0 20.6
e2e-coowners e2e 1 0 0 0 1.6
e2e-etl e2e 1 0 0 0 8.4
e2e-login e2e 2 0 0 0 1.3
e2e-prompt-studio e2e 1 0 0 0 4.7
e2e-smoke e2e 2 0 0 0 1.1
e2e-workflow e2e 1 0 0 0 18.1
integration-backend integration 162 0 0 26 40.0
integration-connectors integration 1 0 0 7 7.9
integration-workers integration 0 0 0 141 98.4
unit-backend unit 283 0 0 1 37.1
unit-connectors unit 63 0 0 0 10.1
unit-core unit 33 0 0 0 1.4
unit-platform-service unit 15 0 0 0 2.7
unit-rig unit 86 0 0 0 4.3
unit-sdk1 unit 480 0 0 0 24.0
unit-workers unit 1312 0 0 0 96.5
TOTAL 2446 0 0 175 378.0

Critical paths

⚠️ Critical paths not yet covered

  • workflow-execution-fan-out — Multi-file workflow execution fans out to file-processing workers and rejoins. (declared coverage: no groups declared)
✅ Covered critical paths
  • auth-login — covered by e2e-login
  • adapter-register-llm — covered by integration-backend
  • workflow-author — covered by integration-backend
  • co-owner-manage — covered by integration-backend, e2e-coowners
  • workflow-create-execute — covered by e2e-workflow
  • api-deployment-provision — covered by integration-backend
  • api-deployment-auth — covered by integration-backend
  • api-deployment-run — covered by e2e-api-deployment
  • prompt-studio-author — covered by integration-backend
  • prompt-studio-fetch-response — covered by e2e-prompt-studio
  • connector-register-test — covered by integration-backend
  • pipeline-etl-execute — covered by e2e-etl
  • usage-aggregate-read — covered by integration-backend
  • usage-token-tracking — covered by e2e-api-deployment
  • callback-result-delivery — covered by e2e-api-deployment

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.

1 participant