Skip to content

API Reference parrot.knowledge.ontology.schema_overlay.service

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.knowledge.ontology.schema_overlay.service

View source

Schema Overlay Service (FEAT-159 TASK-1095).

Sole SQL writer for ontology_schema_overlay, ontology_schema_audit, and ontology_schema_outbox. Implements the five-state machine with a mandatory dry-run gate on every approve call.

State machine

::

proposed ──[submit]──→ pending_review ──[approve]──→ approved ──[deprecate]──→ deprecated
     ↑                      ↓ [reject]                                 ↑
     └──────────────────── rejected ←──────────────────────────────────┘
                             │ [restore]
                             └──────────────────→ proposed

Mandatory dry-run gate

approve always calls dry_run_overlay() before updating state. If the dry-run fails, state stays at pending_review, the dry_run_report column is updated, and DryRunFailedError is raised.

Alias DryRunFailedError

Re-exported from parrot.knowledge.ontology.exceptions.DryRunFailedError.

Alias DryRunReport

Re-exported from parrot.knowledge.ontology.schema_overlay.models.DryRunReport.

Alias InvalidTransitionError

Re-exported from parrot.knowledge.ontology.exceptions.InvalidTransitionError.

Alias OntologyMerger

Re-exported from parrot.knowledge.ontology.merger.OntologyMerger.

Alias SchemaOverlayRow

Re-exported from parrot.knowledge.ontology.schema_overlay.models.SchemaOverlayRow.

Class SchemaOverlayService

Operational truth for per-tenant schema overlays.

Parameter Type Default Description
pg_pool Any asyncpg connection pool.
tenant_manager TenantOntologyManager TenantOntologyManager for dry-run YAML resolution.
merger OntologyMerger OntologyMerger instance used in dry-runs.

Method SchemaOverlayService.propose

Create a new schema overlay in proposed state.

propose(tenant_id: str, overlay_kind: str, name: str, definition: dict[str, Any], asserted_by: str, rationale: str | None = None) -> UUID

Parameter Type Default Description
tenant_id str Owning tenant.
overlay_kind str One of entity_type, relation_type, traversal_pattern.
name str Unique name for the overlay item.
definition dict[str, Any] JSONB definition dict.
asserted_by str Identity of the proposer.
rationale str | None None Optional free-text reason.

Returns: UUID — UUID of the newly created overlay row.

Method SchemaOverlayService.submit

Transition overlay to pending_review.

submit(overlay_id: UUID, actor: str) -> None

Parameter Type Default Description
overlay_id UUID UUID of the overlay row.
actor str Identity of the submitter.

Method SchemaOverlayService.approve

Approve a schema overlay — dry-run gate is mandatory.

The dry-run runs outside the transaction so it can read the live YAML chain without holding locks. If it fails, the row's dry_run_report column is updated inside a separate transaction and DryRunFailedError is raised.

approve(overlay_id: UUID, actor: str, reason: str | None = None) -> None

Parameter Type Default Description
overlay_id UUID UUID of the overlay to approve.
actor str Identity of the reviewer.
reason str | None None Optional approval rationale.

Raises:

  • DryRunFailedError — If the dry-run validation fails.
  • InvalidTransitionError — If the current state does not allow approve.

Method SchemaOverlayService.reject

Reject an overlay from proposed or pending_review.

reject(overlay_id: UUID, actor: str, reason: str | None = None) -> None

Parameter Type Default Description
overlay_id UUID UUID of the overlay.
actor str Identity of the reviewer.
reason str | None None Optional rejection rationale.

Method SchemaOverlayService.deprecate

Deprecate an approved overlay.

deprecate(overlay_id: UUID, actor: str, reason: str | None = None) -> None

Parameter Type Default Description
overlay_id UUID UUID of the overlay.
actor str Identity of the actor.
reason str | None None Optional rationale.

Method SchemaOverlayService.restore

Restore a deprecated or rejected overlay to proposed.

restore(overlay_id: UUID, actor: str) -> None

Parameter Type Default Description
overlay_id UUID UUID of the overlay.
actor str Identity of the actor.

Method SchemaOverlayService.get_pending

Return overlay rows in proposed or pending_review state.

get_pending(tenant_id: str) -> list[SchemaOverlayRow]

Parameter Type Default Description
tenant_id str Tenant to filter by.

Returns: list[SchemaOverlayRow] — List of SchemaOverlayRow instances.

Method SchemaOverlayService.get_overlay_by_id

Fetch a single schema overlay by primary key, scoped to tenant.

S4 fix: efficient single-row lookup used by HTTP handlers instead of fetching all overlays and filtering in Python.

get_overlay_by_id(tenant_id: str, overlay_id: UUID) -> SchemaOverlayRow | None

Parameter Type Default Description
tenant_id str Owning tenant (used for access scoping).
overlay_id UUID UUID primary key.

Returns: SchemaOverlayRow | None — SchemaOverlayRow if found, else None.

Method SchemaOverlayService.get_approved

Return overlay rows in approved state for ontology composition.

C6 fix: get_pending intentionally excludes approved rows. This method is for callers (such as TenantOntologyManager.resolve_with_overlay) that need the approved overlays to compose into the merged ontology.

get_approved(tenant_id: str) -> list[SchemaOverlayRow]

Parameter Type Default Description
tenant_id str Tenant to filter by.

Returns: list[SchemaOverlayRow] — List of approved SchemaOverlayRow instances.

Method SchemaOverlayService.get_history

Return the audit trail for an overlay, newest first.

get_history(overlay_id: UUID) -> list[dict[str, Any]]

Parameter Type Default Description
overlay_id UUID UUID of the overlay.

Returns: list[dict[str, Any]] — List of audit record dicts.

Alias TenantOntologyManager

Re-exported from parrot.knowledge.ontology.tenant.TenantOntologyManager.

Alias dry_run_overlay

Re-exported from parrot.knowledge.ontology.schema_overlay.validator.dry_run_overlay.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally