Skip to content

FEAT: sources in the registry (scorer phase 13) - #3528

Merged
Richard Lundeen (richlundeen) merged 3 commits into
microsoft:mainfrom
WatchTree-19:feat/source-registry
Nov 9, 2026
Merged

Richard Lundeen (richlundeen) merged 3 commits into
microsoft:mainfrom
WatchTree-19:feat/source-registry

Conversation

@WatchTree-19

Copy link
Copy Markdown
Contributor

Description

Implements phase 13 of the scorer design and roadmap. Observation sources are now registry-constructible, as targets, converters, and scorers already are, so a source can be named and configured from a scenario or the backend instead of only being wired in Python.

SourceRegistry

SourceRegistry discovers the source classes exported from pyrit.score.observation (ConversationSource, LocalFileSurfaceSource, OtelTraceSource, and ProgramExecutionSource from #3218) and holds configured instances under .instances. ObservationSource is a protocol, so sources share no base class to walk. The registry reads the package exports instead and keeps the classes that satisfy the protocol, which is now @runtime_checkable. Protocols, abstract classes, and private classes are skipped. It is reset with the other setup registries.

Scorers take a source by name

ComponentType.SOURCE is wired into reference resolution, and ScorerIdentifier declares source as a reference, so ScorerRegistry.create_instance("FileWriteScorer", source="workspace") resolves the registered source. This applies to FileWriteScorer, OtelToolCallScorer, and ProgramExecutionScorer. A live source still passes through unchanged, and an unknown name fails with the usual "not found" error.

The reference is declared through a new constructor_references class variable on the identifier rather than as a promoted source field. A promoted child gets its own persistence column and table, and the source identity already lives in children["source"], so this way no stored identity, identity hash, eval hash, or memory schema changes. A test checks both hashes on the typed projection.

Instance container bound

InstanceHoldingRegistry and DefaultInstanceRegistry were bound to Identifiable, while sources implement get_identifier() structurally. The bound is now a small SupportsIdentifier protocol, which every Identifiable satisfies and which is the one method the container calls.

The roadmap decision

This gives sources their own namespace rather than joining the scorer namespace. A source is configured independently of the scorer that reads it, one source can serve several scorers, and the scorer catalog stays limited to classes that score. Happy to move them under the scorer namespace if you would rather have that.

Tests and documentation

tests/unit/registry/test_source_registry.py covers discovery, building and holding sources, rejecting non-sources, scorer resolution by name and by instance, unknown names, the setup reset, and hash stability. The classification spec in test_resolution.py now includes SOURCE. Each production change was reverted in turn and the new tests fail without it.

On Python 3.13, tests/unit/registry, models, score, setup, backend, memory, and docs pass (13,574 passed, rebased on main after #3218). Ruff is clean, and ty reports nothing new (the remaining diagnostics are the optional torch, a2a, copilot, and litellm imports). The registry doc has a new Source Registry section.

Adds SourceRegistry, which discovers the observation sources exported from
pyrit.score.observation and holds configured instances, and wires
ComponentType.SOURCE into reference resolution so a source-backed scorer can
be built from a registered source name. ScorerIdentifier declares source as a
constructor reference rather than a promoted field, so stored identities,
hashes and the memory schema are unchanged.
Preserve source and scenario-suite registry exports and align source imports with main's public API contract.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 9, 2026 22:16

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.

Automated review completed. No blocking concerns remain. This review records source coverage; it does not authorize merge.

Copilot AI left a comment

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.

🔵 Needs a closer look

One or more reviewer sessions failed, leaving the review evidence incomplete.

No open issues 🎉

What changed in this PR

Implements scorer roadmap phase 13 by making observation sources registry-constructible. Sources gain their own namespace, allowing source-backed scorers to reference configured instances by name without changing persisted scorer identities or hashes.

Changes:

  • Adds SourceRegistry with structural discovery, instance storage, public exports, and setup reset support.
  • Wires source-name resolution into scorer construction and broadens instance containers to accept structural identifiers.
  • Adds registry tests, frontend reference typing, and source configuration documentation.
File Description
tests/​unit/​registry/​test_source_registry.py Tests discovery, construction, references, resets, and identity stability.
tests/​unit/​registry/​test_resolution.py Adds sources to reference-resolution classification tests.
pyrit/​setup/​initialization.py Resets the source registry with other setup registries.
pyrit/​score/​observation/​observation_source.py Makes the source protocol runtime-checkable.
pyrit/​registry/​resolution.py Maps source references to SourceRegistry.
pyrit/​registry/​registry.py Uses the structural identifier bound for held instances.
pyrit/​registry/​instance_registry.py Introduces the SupportsIdentifier protocol.
pyrit/​registry/​components/​source_registry.py Implements source discovery, construction, and storage.
pyrit/​registry/​components/​__init__.py Lazily exports source registry classes.
pyrit/​registry/​__init__.py Exposes source registry classes through the public package.
pyrit/​models/​parameter.py Adds the source component type.
pyrit/​models/​identifiers/​scorer_identifier.py Declares the scorer’s source constructor reference.
pyrit/​models/​identifiers/​component_identifier.py Supports constructor references without promoted identity fields.
frontend/​src/​types/​index.ts Adds source to parameter reference types.
doc/​code/​registry/​0_registry.md Documents source registration and named scorer references.

Review effort: Balanced

@richlundeen
Richard Lundeen (richlundeen) added this pull request to the merge queue Nov 9, 2026
Merged via the queue into microsoft:main with commit 2a6db34 Nov 9, 2026
60 checks passed
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.

3 participants