Skip to content

Score: persist full versioned ScoringExpectation (Phase 3, PR A) - #2556

Open
Richard Lundeen (rlundeen2) wants to merge 7 commits into
microsoft:mainfrom
rlundeen2:rlundeen2-pr-a-expectation-persistence
Open

Score: persist full versioned ScoringExpectation (Phase 3, PR A)#2556
Richard Lundeen (rlundeen2) wants to merge 7 commits into
microsoft:mainfrom
rlundeen2:rlundeen2-pr-a-expectation-persistence

Conversation

@rlundeen2

@rlundeen2 Richard Lundeen (rlundeen2) commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Summary

PR A of a two-PR split of Phase 3 scoring work. It makes every Score durably record the complete, versioned ScoringExpectation it was judged against (objective and typed conditions), instead of only an objective string.

Design context: Phase 3 scoring persistence and replay design.

What changes

  • Score.scored_expectation stores the full versioned expectation. Score.objective is a read-only compatibility view derived from scored_expectation.objective; conflicting explicit values are rejected.
  • Pydantic scoring models make the contract reusable in REST and frontend payloads:
    • Every concrete Condition declares a stable single-value condition_type Literal and is registered independently of its import path.
    • Condition.model_validate(...) dispatches tagged dictionaries to the registered concrete subtype, which then uses normal Pydantic validation.
    • Extra fields, direct base Condition instances, missing or unknown discriminators, and invalid discriminator declarations are rejected.
    • Generated JSON Schema exposes registered condition subtypes as a discriminator-tagged oneOf.
    • ScoringExpectation uses strict persisted schema-version validation and provides a stable canonical fingerprint for PR B.
  • Persistence replaces the legacy ScoreEntries.objective column with JSON scored_expectation; ScoreEntry.to_dict() still exposes a derived objective.
  • Migration (1b3d5f7a9c2e, down revision 0f2e4d6c8b1a) backfills non-null objectives into {schema_version: 1, objective, conditions: []} in bounded keyset batches of 500. Downgrade restores only the objective and intentionally drops conditions that the old schema cannot represent.
  • Scorer stamping records the effective expectation on returned scores before persistence, including objective inference in MessageScorer.

Not in scope

Observations, replay, score_observation_async, response-handler fingerprints, Score.observation_ids, json_retry changes, and observation tables follow in PR B.

Testing

  • Scoped model, memory, migration, and scorer tests pass.
  • Executor regression suites affected by strict Score mocks pass.
  • ruff, ty, frontend lint, and frontend TypeScript checks pass.
  • The ScenarioRunPage dialog test now waits for asynchronous portal rendering.

Copilot AI and others added 7 commits September 3, 2026 11:36
Every Score now durably records the complete versioned ScoringExpectation it was judged against (objective + typed conditions) in a new scored_expectation field/column. Score.objective becomes a read-only, derived compatibility view over scored_expectation.objective. A one-way-reversible Alembic migration folds the legacy objective column into a serialized scored_expectation and restores it (dropping condition-only data) on downgrade. Scorers stamp the expectation they used onto returned scores before persistence.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Convert Condition/MatchesObjective/ScoringExpectation from frozen dataclasses to Pydantic BaseModels so they serialize natively (model_dump/model_validate), stay consistent with the rest of pyrit.models, and are reusable in REST/frontend payloads. The open condition hierarchy keeps a stable 'condition_type' discriminator (a per-subclass Literal field) plus a registry, and ScoringExpectation carries conditions as SerializeAsAny so subclass fields survive a round trip. Score now nests ScoringExpectation natively, removing the custom field validator/serializer and the bespoke to_dict/from_dict helpers. Net -180 lines. Also revert the overly specific framework.md note.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: acca9c84-99f3-447d-93e5-37575f07e45d
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: acca9c84-99f3-447d-93e5-37575f07e45d
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: acca9c84-99f3-447d-93e5-37575f07e45d
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: acca9c84-99f3-447d-93e5-37575f07e45d
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