Skip to content

FEAT: Save targets from the Registry (part 9) - #4027

Open
varunj-msft wants to merge 164 commits into
microsoft:mainfrom
varunj-msft:varunj-msft/13178-Save-From-Registry
Open

varunj-msft wants to merge 164 commits into
microsoft:mainfrom
varunj-msft:varunj-msft/13178-Save-From-Registry

Conversation

@varunj-msft

@varunj-msft varunj-msft commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Description

Part 9 of saving Registry entries across restarts. Stacked on part 8 (#4026); part 10 (#4028) builds on it, and so do the side branches part 16 (#4068) and part 19 (#4070). This PR's own changes: varunj-msft/PyRIT@varunj-msft/13178-Save-Targets...varunj-msft/13178-Save-From-Registry

Design: 1. The contract, 4.8 Names. Where every part fits: PR map.

This is one of the changes for saving Registry entries across restarts. It builds on #4026, which saves targets created through the API. Until the earlier PRs merge, the diff here also shows their changes.

Problem. The New Target dialog in Registry > Targets still makes targets that are gone after the backend restarts. It sends no name, so the backend makes one up (compat_<hex>), and the Targets table doesn't say which targets will come back.

Change.

  • The dialog has a Registry Name field. Until the user edits it, it suggests a name from the type and model that no listed target has (openai_chat_gpt_4o). The model tells saved targets apart and keeps the suggestion off names the startup scripts register, such as openai_chat. The field checks the same rule the backend uses for saved names. A name the Targets list already has, or one the backend says is taken (409), shows on the field and holds Save until the name changes.
  • The dialog saves by default (persist: true). When a target can't be saved, the button reads Create as Temporary and a warning says why, and that a Temporary target is gone after the backend restarts or is reinitialized. The dialog says so before submitting when the backend's type list already tells it: the type can't be saved, the chosen sign-in can't be saved (an API key, for now), a credential is typed in, or a round robin uses a Temporary target. Otherwise the backend's refusal turns the button into Create as Temporary for those exact values, and changing any of them goes back to Save Target. No other error offers Temporary.
  • A new target starts with Microsoft Entra ID, or No key, when a saved target of its type can use it, so the usual case saves. This also applies when the type's details arrive after the type was picked. Picking another type resets the choice and clears a typed key. For an OpenAI endpoint that isn't on Azure, the Entra ID error now says to choose No key for a server that needs no key, such as a local one. It shows once the endpoint field is left, not while the address is typed.
  • GET /api/targets/types adds saveable_auth_modes and not_saveable_reason to each type. They come from the checks a save runs (the class check, and the server-setting check for each auth mode with those settings turned off), so the dialog keeps no copy of the credential rules.
  • A refused save gets a typed 400 ("type": "/errors/not-saveable"), so the dialog doesn't read messages. When the only problem is an endpoint that isn't a full http(s) or ws(s) address, the request gets a plain 400 instead, since a Temporary target with that address wouldn't work either.
  • The warning and the Entra ID error use role="status" so screen readers read them out. Fluent's message bars only announce through an announcer the app doesn't render.
  • The Targets table labels each target Saved, From configuration or Temporary, and the round robin member list marks Temporary members.
  • The GUI doc says where saved targets are kept, how to remove one for now, and what happens if a startup script later registers the same name.

What stays the same. API callers that don't send persist get Temporary targets as before, and may still leave out the name. Permission checks still come first, and restore is unchanged.

Not covered.

  • Showing who saved a target, and a Mine / All filter. That's FEAT: Show who saved each target and list only your own (part 10) #4028 (part 10).
  • Picking a server credential, and keeping typed keys in a key vault. Until then a target that uses an API key is Temporary.
  • Saving converters, scorers and techniques, and deleting saved entries. Those come in parts 12 to 14 and part 20.

Tests and Documentation

  • tests/unit/registry/test_registry_recipe_rules.py: check_saveable_class lists the auth modes a saved target of each type can use, refuses a class that can never be saved, and agrees with the check a save runs for every registered target type and auth mode.
  • tests/unit/backend/test_target_service.py: the type list says which auth modes a saved target can use and why a type can't be saved; saving a type that can't be saved is refused; an endpoint that isn't a full web address is an error to fix, not a refusal.
  • tests/unit/backend/test_api_routes.py: a refused save is a 400 with "type": "/errors/not-saveable"; other bad requests stay untyped.
  • CreateTargetDialog.test.tsx (new "CreateTargetDialog saving" block): saving by default with Entra ID or No key, also when the type details arrive late; the suggested name from the type and model until it's edited; names already listed or taken (409) held on the field; when Create as Temporary is offered and why (an API key, a typed credential, a type that can't be saved, a round robin with a Temporary member), and only after a typed refusal for those exact values; no Temporary offer on 409, 422, 403 or other errors; the warning and the Entra ID error as live regions; starting over after the dialog closes; the Entra ID error once the endpoint field is left.
  • TargetTable.test.tsx: the Saved, From configuration and Temporary labels. registryName.test.ts and errors.test.ts: the name suggestion and the typed refusal check.
  • frontend/e2e/config.spec.ts (mock): saving through the dialog sends Entra ID and persist: true. frontend/e2e/registry.spec.ts (seeded, real backend): a target saved from the dialog is still Saved after a reload.
  • Each of the 64 ways I tried to break the dialog, the labels or the saveability check fails at least one of these tests.
  • uv run --frozen --extra all python -m pytest -n 8 --dist=loadfile tests/unit/registry tests/unit/backend tests/unit/prompt_target tests/unit/models tests/unit/setup tests/unit/converter tests/unit/score: 19,599 passed, 9 skipped, 4 xfailed
  • cd frontend && npm run test:coverage: 184 suites, 4,557 tests passed
  • cd frontend && npx playwright test --project=mock e2e/config.spec.ts e2e/registry.spec.ts: 28 passed
  • cd frontend && E2E_SEEDED_MODE=true npx playwright test --project=seeded: 109 passed
  • npx tsc --noEmit, npx eslint on the changed files, and pre-commit (ruff, ty, docs checks): passed
  • Run against a real backend in a real browser, with the server using its own Entra ID credential: saved an Entra ID chat target on Azure OpenAI and a local No key target from the dialog. A target with an API key, a round robin using a Temporary target, and a target created through the API without persist came out Temporary, with the reason shown. After a backend restart the saved targets came back as Saved, the Temporary ones were gone, and a message sent through the restored Entra ID target got an answer. No key was in any saved file.
  • doc/gui/0_gui.md (Registry): saving a target, where saved targets are kept, how to remove one for now, and what happens when a startup script registers the same name. pyrit/backend/README.md: the new type fields and the typed 400.

No JupyText changes.

…API input

External construction now rejects a parameter whose type includes Path unless the
calling service passes the name in allowed_path_params after making the value safe.
The converter service allows its upload parameters once they are stored, and the
target service allows the server-set upload folder and the GitHubCopilotTarget
working directory. The scorer-only check is removed, and the "Valid parameters"
list leaves out path parameters callers cannot set.
The target catalog now applies the path rule to required parameters too, so a
target that needs a disallowed path is left out instead of listed without the
field, matching the scorer catalog. allowed_path_params is typed frozenset[str]
so a bare string cannot turn the allow-list into a substring match.
The target catalog still lists a target whose required path parameter is its
server-set upload folder when the server has one, and leaves it out otherwise.
# Conflicts:
#	tests/unit/backend/test_converter_service.py
@varunj-msft varunj-msft changed the title FEAT: Save targets from the Registry FEAT: Save targets from the Registry (part 9) Nov 9, 2026
FileDocumentStorage now raises DocumentStorageUnavailableError when the
folder or container can't be used, and DocumentUnreadableError when one
document exists but can't be read. The message names the location, with
any SAS token hidden, and a short reason. One backend handler maps both to
503 and logs the location and reason, with the traceback at debug level,
so the per-route storage helpers are gone.

A single read, a conditional save and a delete now follow the listing's
rules: a folder, pipe or broken link named like a document is unreadable
rather than missing, and on Blob only a deleted blob counts as missing.
Blob sign-in, permission, network and missing-container errors stop the
listing instead of marking every file unreadable. Each unreadable report
keeps the real file name and the original error, and the listing's
documents are read-only.

Initializer delete removes a script that can't be read or decoded, and
registering one no longer turns a storage write failure into a 400.
Tests patch module-level aliases instead of os.
List recipes escapes the OS text it reports, such as a file name that
isn't UTF-8, and a recipe whose JSON holds an unpaired surrogate escape
is reported as invalid, so the models no longer need a JSON-only
serializer. Recipes may start with a byte-order mark. A document without
schema_version reads as version 1, and each file is checked against the
format version of the model that reads it. Validation summaries shorten
each location part and the whole message, since a location can repeat a
stored key.

Recipes and StoredRecipe are no longer frozen, since their params and
tags never were, and StoredRecipe checks that its recipe type matches its
registry. The listing's recipes are read-only, and it keeps the error
behind each recipe that couldn't be read, for the log.
Listing catches only storage errors, so a bug is raised instead of being
reported as unreadable storage, and a bug while planning is a build
error rather than an invalid recipe. Each failure is logged once, with
the error behind it and URL credentials removed. The report shows the
error's text with each URL's user name, query and fragment removed, any
SAS signature hidden, and the length capped.

A class that moved within PyRIT is restored; one now registered from
outside PyRIT still fails. A technique whose name or tag clashes is a
name clash, and anything else registration refuses is an invalid
recipe. A recipe that sets a server file or folder is refused before it
is built. Class metadata comes from the registry's cache. The class
docstring lists the steps the API's create runs that restore skips.
The runtime becomes ready even when some saved entries fail; the
failures stay in the runtime status. Each failed entry keeps its name in
its registry: looking it up, or taking the name, raises
SavedEntryUnavailableError, which the backend answers with 409, so
nothing else stands in for it. Administrators see the full message and
everyone else a fixed explanation of the reason. A folder that can't be
listed holds every unregistered name of its kind, and each entry it left
unbuilt is reported.

While a saved technique is held, a launch or estimate that picks
techniques by all, default or a tag is refused with 409 for scenarios
whose techniques come from the registry, since the broken technique's
tags may be unknown. Naming techniques still works; naming the held one
fails with its reason. Route catch-alls let the error through instead of
turning it into a 500.
A launch script that registers a name held for a saved entry that
couldn't be restored is refused, and the refusal is recorded even when
the script catches it, so the launch stops instead of running with the
script's entry in the saved one's place. A suite entry that fails on a
held entry, or on a broad technique selection, shows the reason without
the error's details.
The OpenAI SDK adds that variable's headers to every request, so a saved
OpenAI target would send whatever the server puts there, which can be a
credential. While it's set, saving an OpenAI target is refused and a
saved one isn't restored; the message names the variable, never its
value. Targets declare such variables in server_header_variables.

This branch has not been deployed

No deployments
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