CI & Build / Python lint (push) Successful in 3s
CI & Build / Plugin hooks (push) Successful in 13s
CI & Build / TypeScript typecheck (push) Successful in 54s
CI & Build / integration (push) Successful in 58s
CI & Build / Python tests (push) Successful in 1m38s
CI & Build / Build & push image (push) Successful in 27s
Step 2 of #4251. A System's `description` is a charter — several hundred words saying what belongs in that area and what does not — and it is the answer to "which part of this codebase does X live in". There was no semantic path to one: `list_systems` enumerates, and `search(system_id=…)` uses a System as a FILTER over notes. So a System could narrow a search and could never be the answer to one, and an agent asking where a record belonged had to read every charter or guess. ITS OWN SEARCH, not a `content_type` over notes, for the reason note 3163 gives about milestones: the row could be shared, the search cannot. A charter competing with the whole note corpus for one top-k is outranked by the records filed under it — the right answer crowded out by its own contents — and "where does this belong?" is a different question from "what prior art is there?", which a caller asking one should not have to read past answers to. So `system_embeddings` (0107) joins note_, rule_ and milestone_embeddings as the fourth sibling, with `system_document`, `upsert_system_embedding`, `semantic_search_systems`, a startup backfill and `search(content_type= "system")`. Scoped like milestones: with a project_id, that project's Systems if the caller can read the project (rule 78); without one, the caller's own. Archived Systems are excluded — an archived area is one the operator has said is no longer where things go, which is exactly the question being asked. `system_document` is the plainest of the four shapes on purpose. A charter is already written as the thing this search has to match, in the words someone asking would use — so there is no trigger to synthesise as `rule_document` must, and no second record to gather as `task_document` must. The stored charter IS the sharp document, the way a snippet's is. `color`, `status` and `order_index` stay out: presentation and bookkeeping, and a vector carrying them would be answering a question nobody asks of a charter. The search publishes `report["best_chunk"]` from the start rather than being retrofitted, which is what #4251 asked of any fourth search. It matters more here than anywhere: a charter runs long and a result shows its NAME, so a match on the paragraph that actually decides where a record belongs would otherwise be previewed by two words that cannot say. The id that comes back is the one `system_id`, `system_ids` and `list_system_records` already take, so the answer to "where does this belong?" is directly usable as "show me what is there" and as "file it here". `embed_system` sits beside `notes.embed_note` at the service for #2056's reason — every door gets it by construction. Not called on delete: that is a soft delete and the search joins through `System`, so the vectors are already unreachable, and leaving them means a restore is findable again immediately. `system_embeddings` is declared in backup's `_NOT_INCLUDED` as derived, beside its three siblings. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01821k5B3Ysecp9fNYs92Kuy
85 lines
4.4 KiB
Python
85 lines
4.4 KiB
Python
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
|
|
from sqlalchemy.orm import DeclarativeBase
|
|
|
|
from scribe.config import Config
|
|
|
|
# Named rather than inlined so the deadline below is READABLE. SQLAlchemy
|
|
# captures `connect_args` in a closure and merges it at connect time, so an
|
|
# inline dict cannot be recovered from the engine — and a guard that cannot
|
|
# read the value it guards is a guard that passes forever.
|
|
_CONNECT_ARGS: dict = {
|
|
# A DEADLINE ON ESTABLISHING A CONNECTION (#4181, rule 156).
|
|
#
|
|
# asyncpg's `timeout` bounds the CONNECT — the TCP handshake plus session
|
|
# setup — and nothing else. Against a host whose storage has wedged, that
|
|
# handshake does not fail, it waits, and without this the wait is
|
|
# asyncpg's own 60-second default: the entire lifespan budget spent before
|
|
# a single query is even sent. Ten seconds is far longer than a healthy
|
|
# local connect (single-digit milliseconds) and short enough to leave room
|
|
# to fail usefully rather than be killed.
|
|
#
|
|
# WHAT THIS DOES NOT COVER, said plainly so the next reader doesn't assume
|
|
# it does: a query on an already-open connection, which includes
|
|
# `pool_pre_ping`'s liveness check. Bounding those is `command_timeout`,
|
|
# and that is deliberately NOT set here — it would apply to every
|
|
# statement, and this app legitimately runs long ones (the embedding
|
|
# backfills, VACUUM ANALYZE). A blanket statement deadline would trade
|
|
# this failure mode for a worse one. Callers that must not hang — the
|
|
# lifespan hook above all — bound their own await instead; see
|
|
# `_STARTUP_READ_TIMEOUT` in services/db_maintenance_scheduler.py.
|
|
"timeout": 10,
|
|
}
|
|
|
|
engine = create_async_engine(
|
|
Config.DATABASE_URL,
|
|
echo=False,
|
|
pool_pre_ping=True,
|
|
pool_recycle=1800,
|
|
connect_args=_CONNECT_ARGS,
|
|
)
|
|
async_session = async_sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)
|
|
|
|
|
|
class Base(DeclarativeBase):
|
|
pass
|
|
|
|
|
|
from scribe.models.base import CreatedAtMixin, TimestampMixin # noqa: E402, F401
|
|
|
|
|
|
from scribe.models.note import Note, TaskPriority, TaskStatus # noqa: E402, F401
|
|
from scribe.models.setting import Setting # noqa: E402, F401
|
|
from scribe.models.user import User # noqa: E402, F401
|
|
from scribe.models.app_log import AppLog # noqa: E402, F401
|
|
from scribe.models.password_reset import PasswordResetToken # noqa: E402, F401
|
|
from scribe.models.invitation import InvitationToken # noqa: E402, F401
|
|
from scribe.models.embedding import ( # noqa: E402, F401
|
|
MilestoneEmbedding, NoteEmbedding, RuleEmbedding, SystemEmbedding,
|
|
)
|
|
from scribe.models.retrieval_log import RetrievalLog # noqa: E402, F401
|
|
from scribe.models.retrieval_tuning import RetrievalTuningEvent # noqa: E402, F401
|
|
from scribe.models.note_usage import NoteUsageEvent # noqa: E402, F401
|
|
from scribe.models.rule_usage import RuleUsageEvent # noqa: E402, F401
|
|
from scribe.models.project import Project # noqa: E402, F401
|
|
from scribe.models.milestone import Milestone # noqa: E402, F401
|
|
from scribe.models.task_log import TaskLog # noqa: E402, F401
|
|
from scribe.models.note_draft import NoteDraft # noqa: E402, F401
|
|
from scribe.models.note_version import NoteVersion # noqa: E402, F401
|
|
from scribe.models.rule_version import RuleVersion # noqa: E402, F401
|
|
from scribe.models.note_supersession import NoteSupersession # noqa: E402, F401
|
|
from scribe.models.group import Group, GroupMembership # noqa: E402, F401
|
|
from scribe.models.share import NoteShare, ProjectShare # noqa: E402, F401
|
|
from scribe.models.notification import Notification # noqa: E402, F401
|
|
from scribe.models.api_key import ApiKey # noqa: E402, F401
|
|
from scribe.models.user_profile import UserProfile # noqa: E402, F401
|
|
# Imported before rulebook: rule_systems foreign-keys canonical_systems.
|
|
from scribe.models.canonical_system import CanonicalSystem # noqa: E402, F401
|
|
from scribe.models.rulebook import ( # noqa: E402, F401
|
|
Rulebook, RulebookTopic, Rule, RuleRelation, rule_systems,
|
|
)
|
|
from scribe.models.repo_binding import RepoBinding # noqa: E402, F401
|
|
from scribe.models.forge_connection import ForgeConnection # noqa: E402, F401
|
|
from scribe.models.code_shape import CodeShape, CodeShapeConsumer, CodeShapeEvent, CodeShapeUse # noqa: E402, F401
|
|
from scribe.models.system import System, RecordSystem # noqa: E402, F401
|
|
from scribe.models.design_system import DesignSystem, DesignToken # noqa: E402, F401
|