Build images / sign-extension (push) Successful in 4s
Build images / build-agent (push) Successful in 11s
Build images / build-ml (push) Successful in 32s
Build images / build-web (push) Successful in 26s
CI / lint (push) Successful in 3s
CI / extension-version (push) Successful in 3s
CI / frontend-build (push) Successful in 20s
CI / backend-lint-and-test (push) Successful in 30s
CI / integration (push) Successful in 3m44s
extension / lint (pull_request) Successful in 24s
A structural sweep of the deployed schema, run AFTER 0088 got the models and the chain to exact agreement. That agreement is what 0088 achieved, and it is worth naming what it does not prove: a models-vs-chain diff shows the two describe the same schema, not that the schema is right. Everything here was wrong in BOTH. The one that matters: image_tag has PRIMARY KEY (image_record_id, tag_id) and no other index, so tag_id is unindexed. That is the gallery's tag filter (tag_query.py builds `image_tag.c.tag_id == tid`) and the ON DELETE CASCADE from tag, both scanning the largest table in the schema. Six more FKs were unindexed on smaller tables; presentation_review.tag_id also CASCADEs. Dropped, on the other side: ix_image_record_sha256 was an exact duplicate of the index uq_image_record_sha256 already builds — two btrees on the same column of the highest-insert-rate table. The other six are single-column indexes a later composite superseded without the narrow one being retired; a btree on (a,b) already serves lookups on a. 0088 deliberately taught the models to declare BOTH sha256 indexes so they would describe reality. This changes the reality instead, and the models change with it — otherwise the next baseline.yml run reintroduces exactly the drift 0088 removed. CONCURRENTLY throughout, so building the image_tag index does not hold an ACCESS EXCLUSIVE lock over every write for the duration. The cost is that the migration cannot run in a transaction and so is not atomic: every statement is IF NOT EXISTS / IF EXISTS, making a re-run after a partial failure safe. The docstring carries the query for finding an INVALID index left by an interrupted CONCURRENTLY build. What the sweep found clean, for the record: all 43 tables have a primary key; all 51 FKs declare an explicit ON DELETE, so none silently blocks a delete; the three enum CHECKs match the code that writes them (rule 36). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017QHszn9H8VBvx5Ke8x1hvw
57 lines
2.5 KiB
Python
57 lines
2.5 KiB
Python
"""PresentationReview — a system-tag the auto-apply sweep applied that ALSO looked
|
|
like real content, flagged for operator review (milestone 141 + #1464).
|
|
|
|
When a sweep applies a system tag but the image ALSO scores highly on a content
|
|
head, it still applies the tag but records this row so a review strip can surface
|
|
it ("⚠ also looks like <conflict tag>"). Two modes (#1464): 'chrome' (banner —
|
|
image is HIDDEN, review is keep-hidden / un-hide) and 'process' (wip / editor
|
|
screenshot — image stays VISIBLE, review is confirm / remove-tag). Resolved rows
|
|
are pruned by retention.
|
|
"""
|
|
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import DateTime, Float, ForeignKey, Index, String, func
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from .base import Base
|
|
|
|
|
|
class PresentationReview(Base):
|
|
__tablename__ = "presentation_review"
|
|
|
|
|
|
__table_args__ = (
|
|
Index("ix_presentation_review_resolved_at", "resolved_at"),
|
|
# Both FKs to tag were unindexed (#3300); tag_id CASCADEs, so a tag
|
|
# delete had to scan this table to find its rows.
|
|
Index("ix_presentation_review_tag_id", "tag_id"),
|
|
Index("ix_presentation_review_conflict_tag_id", "conflict_tag_id"),
|
|
)
|
|
image_record_id: Mapped[int] = mapped_column(
|
|
ForeignKey("image_record.id", ondelete="CASCADE"), primary_key=True
|
|
)
|
|
# The presentation tag that was auto-applied (banner / editor screenshot).
|
|
tag_id: Mapped[int] = mapped_column(
|
|
ForeignKey("tag.id", ondelete="CASCADE"), primary_key=True
|
|
)
|
|
# The content tag the image ALSO scored high on — the "concerning" signal.
|
|
# SET NULL (not CASCADE): losing the conflict tag shouldn't erase the flag.
|
|
conflict_tag_id: Mapped[int | None] = mapped_column(
|
|
ForeignKey("tag.id", ondelete="SET NULL"), nullable=True
|
|
)
|
|
conflict_score: Mapped[float] = mapped_column(Float, nullable=False)
|
|
# Which sweep flagged this (#1464): 'chrome' (banner, hidden) or 'process'
|
|
# (wip / editor screenshot, shown). Drives which review strip surfaces it and
|
|
# what "resolve" means (un-hide vs remove-tag). Existing rows backfill 'chrome'.
|
|
mode: Mapped[str] = mapped_column(
|
|
String(16), nullable=False, default="chrome", server_default="chrome"
|
|
)
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime(timezone=True), nullable=False, server_default=func.now()
|
|
)
|
|
# Set when the operator keeps-hidden or un-hides; retention prunes resolved.
|
|
resolved_at: Mapped[datetime | None] = mapped_column(
|
|
DateTime(timezone=True), nullable=True
|
|
)
|