All gates re-verified green. Report: - **Verified (all 4 tasks already complete; this was the final pass):** `effective_settings` resolves the 3 brand strings panel-row → tab-row → env (`applied_override_keys`, presence-not-value); `PUT /api/ui-settings` ignores string body fields; Theme-tab form is colors-only (17 pickers, no `#theme-app-name`/`#theme-placeholder`/`#theme-footer`); the ONE shared `applyBrandFromConfig` re-applies title/`.brand-text`/footer/placeholder after a panel save-reset and a tab save-reset; boot path byte-identical (single `/api/config`). - **Completion criteria:** - strings order panel→tab→env, both branches — ✅ `tests/unit/test_theming.py::test_effective_app_name_prefers_settings_panel_row_over_ui_settings_row`, `..._fall_back_to_ui_settings_row_without_panel_row`, `..._per_field_panel_then_tab_then_env`, `..._ignore_panel_rows_when_the_overlay_is_off` - PUT ignores string fields + no 3 inputs in the tab — ✅ `tests/integration/test_ui_settings_api.py::test_put_ignores_string_fields_in_body` (+2) and the E2E `test_theme_tab_dom_is_colors_only` - live apply without reload + incident regression — ✅ `tests/e2e/test_app_name_settings_fix.py` tests 1–4 - byte-identical boot, no double-apply — ✅ `tests/unit/test_brand_live.py` markers + E2E "exactly one /api/config" - suite green, coverage >90%, ruff+pyright clean — ✅ - no behavior change in prior phases — ✅ (palette, phase-168 panel, env fallback suites all green) - atomic commit — **left to the harness** (pipeline rule overrides per-phase committing; no git write run) - **Gates:** `uv run pytest --cov=app --cov-report=term-missing` → **4630 passed, TOTAL 6941 16 99%**, exit 0 · `uv run pytest tests/e2e/test_app_name_settings_fix.py -v --no-cov` → **6 passed** in isolation · regression E2E (isolated, one process each, all exit 0): `test_smoke` `test_configurable_brand` `test_admin_theme_tab` `test_theme_save_and_coverage` `test_theme_semantic_completion` `test_themed_favicon` `test_dark_tech_theme` `test_admin_settings_panel` `test_admin_settings_layout` `test_settings_mobile_value_width` · `uv run ruff check .` → All checks passed · `uv run pyright` → 0 errors. - **Documentation:** README — fixed "saving one repaints *every* open page" (only the open document repaints; other pages on next load) and a broken paragraph wrap in *Customizing the look*; AGENTS.md rule 16 — `test_chunks_hnsw_recall.py` now described accurately (index paths forced with `enable_seqscan`/`indexonlyscan`/`bitmapscan` off, unforced plan asserted only on a pristine relation); `tests/unit/test_theme_frontend.py` — two stale section headers ("20 form fields"/"20 inputs" → 17 color). No AGENTS.md settings-overlay/resolution-order clause exists, so per the phase none was added. Full env-var cross-check (`BOR_*` in `app/config.py` vs README) → 0 gaps; 0 missing file references. - **Notable:** the working tree also carries this phase's flake hardening of the phase-188 `tests/integration/test_chunks_hnsw_recall.py` (verified legit and green). Live infra untouched; shared DB left clean (0 `app_settings`, 0 `ui_settings`). **Flagged, not changed:** `settings_overlay.applied_override_keys` lets a `ProgrammingError` (missing `app_settings`) propagate from public `GET /api/config`, where `load_overrides` deliberately fails soft — only reachable on an un-migrated (0027) DB, outside this phase's pinned A1 semantics, so left for the owner to rule on rather than silently deviating. - **Next pending phase:** `191_source_name_labels_tags`.
21 KiB
AGENTS.md — Operating Rules for All Agents on This Repo
-
Always read
.agents/PLAN.mdfirst. It contains the architecture, the LOCKED DECISIONS, the UI/UX standards, the data model, and the roadmap. Do not design anything that contradicts it. -
Follow the phased execution protocol in
.agents/phases/. Work through.agents/phases/todo/in numeric order. When a phase is complete, move its directory to.agents/phases/complete/. -
Strictly adhere to the LOCKED DECISIONS (PLAN §2). If you believe a LOCKED decision is wrong, stop and flag it — do not silently deviate.
-
"One Story, One Phase": each user story in
.agents/user_stories/corresponds to a distinct execution phase, and every phase — story-driven or owner-directed — includes its own dedicated Playwright E2E test suite (one test file for the phase, run in isolation). -
"UI Structure Check": before finalizing any UI component, verify that it follows the layout principles in
.agents/PLAN.md§7 (proper container usage, the 72rem centered reading column — every page rides the 72rem container at every viewport; phase 100 supersedes §7.1's 46rem chat column, full-width tables on the catalogue pages — no skinny wasted-space lists; the catalogue tables (RAG, Sources, History) are bounded scroll panels —max-height: min(70vh, 64rem)— with a sticky header row; a clipped action label shows an ellipsis hint (.cell-clip) with the full text kept reachable via the control's aria-label (phase 156); an in-flight turn never paints an empty answer bubble — the box is created empty as the reasoning anchor and.msg .bubble:empty { display: none }hides it until the first answer token (phase 166); an answer's inline[text](url),and####+ heading render through the ONE shared renderer into an allowlist-gateda.md-link(underlined, never ajavascript:/data:element), a container-cappedimg.md-img(max-width: 100%— no horizontal overflow at 375px) and anh5/h6sized into the existing type scale — never printed reference text (phase 180); an SVG document paints as a graphic — the viewer's image block adds.doc-image-img--vector(width: 100%,object-fit: contain) whenformatissvgso aviewBox-only drawing spans the.doc-imagecard instead of the 300×150 default box, while the chat figure and RAG-table thumbnail keep their fixed caps and the bytes stay an<img>src (never inlined) (phase 181); the document viewer's page strip is CLASS-scoped — the primary class shows the strip in place of the text, the additive class never hides the text: Text/Pages toggle group (aria-pressed, Text default) with the strip behind it (phase 163); a lazily-drilled KB-tree level keeps the level the user is ON rendered while its node fetch runs, and its ONE in-flight row (role="status") / alert + Retry row (role="alert", a real<button>) sits inside that same bounded scroll panel — and the stat cards read the server'stotals, never a walk of a depth-limited tree (phase 167); an answer's code block is EITHER verbatim-and-badged OR plainly the model's — never a silently-substituted hybrid: the```borlocator fence renders through the ONE shared renderer as.verbatim[data-bor-locator]with the model's body DROPPED (renderMarkdown(md, { verbatim: true }), off by default so every other surface is byte-identical), styled from palette variables only with amin(40rem, 70vh)scroll body, a stickysource/pathcaption and auser-select: noneline-number gutter, while the plain.code-blockwrapper carries a Copy button and no badge (phase 182); those placeholders hydrate against the frame'sanswer_textthrough the ONE panel client (frontend/assets/verbatim.js— a classic script loaded AFTERmarkdown.json the chat AND shared pages, no second locator grammar, a plain string compare against the server's canonicallocator, the caption's numbers always the SERVER's extent, an unresolvable locator painting the pinned sentenceI could not verify this against the knowledge basewith no badge, no body and none of the model's bytes, no panel left at "Retrieving the exact text…" after a terminal frame (theerrorframe, the 300 s guard, Stop and the failure funnel all settle it), the Copy button's clipboard content equal to the server string exactly, and the shared page's panel Copy button + plain/document.htmllink the ONE owner-directed exception to that page's zero-controls rule) — phase 182 task 07), and the sync's peak-memory clause is TRAILING TEXT on the result line that already exists (· peak <N> MBon the RAG page's#sync-progresscounts line or "Sync cancelled", written by the ONEfmtSyncPeakClauseoffrss_peak_mb ?? rss_mb— no new control, no new live region, no new element, no clause in a running label or in the failed terminal's empty box, and NOTHING rendered when the pair is null — phase 187 task 03) and meets WCAG 2.1 AA basics (semantic landmarks, labels, contrast ≥4.5:1, focus-visible, aria-live for the stream). -
"No CDN Rule": all CSS, JS, fonts, and images must be served statically from within the FastAPI application. No
<script src="https://…">or<link href="https://…">tags in HTML templates unless bundled locally. An integration test enforces this on every served page except/doc-edit.html(the parametrized no-CDN check intests/integration/test_api.py— the shell, the viewer, the login and the shared page). -
"Debugpy Check": any new entrypoint must keep the conditional import —
debugpyis imported only whenDEBUGPY=1(seeapp/core/debugging.py); default off, never imported otherwise. -
Git protocol: Git is mandatory. One atomic, professional commit per completed phase (Conventional Commits, e.g.
feat(rag): stream RAG answers over SSE with source citations). Always append--no-gpg-sign(the repo also setscommit.gpgsign=false)..agents/is tracked and committed with the phase — only runtime artifacts (.agents/phase-sessions/,.agents/pipeline.log) are gitignored. -
Test gates are non-negotiable: a phase is complete only when unit + integration tests pass,
app/coverage is >90% (uv run pytest --cov=app --cov-report=term-missing), and the phase's Playwright E2E file passes in isolation (uv run pytest tests/e2e/test_<story>.py -v --no-cov). -
Amply log, visibly feed back: server-side, log the required per-turn line (PLAN §9 — phase 182 appends
verbatim_blocks=Nafterscaffold_stripped=N: the verbatim display blocks actually SENT on thedoneframe,0on every turn without them, deflected included) and the per-response byte-budget line (app/core/response_budget.py— oneapi method=… path=… status=… bytes=… enc=… duration_ms=…line per/api/*response, INFO at/overBOR_LOG_LARGE_RESPONSE_BYTES, read it withgrep ' :: api ', audit it withuv run python -m scripts.api_payload_audit, phase 167) and the sync's memory fields (phase 187 —app/core/memory.pyreads PROCESS RSS, never the host's cgroup figure, and never raises: aNonerenders?through the ONEfmt_mbhelper.rss_mb=is appended tosync: started …and to the importer'simport: summary …, andrss_mb=+rss_peak_mb=to all three terminals (sync: done …,sync: cancelled by user …, and the sanitized one-linesync: failed state=failed … error=…that sits beside — never in place of — thelogger.exceptiontraceback). Append-only: no pre-existing field renamed, reordered or re-typed, so every older grep still matches; read them withgrep ' :: ' server.log | grep ' rss_peak_mb='. Phase 187 task 03 puts the SAME pair on the status:SyncStatus.rss_mb/rss_peak_mb, written by the ONE_sample_rss— forced at the run start, at everyphasetransition and in every terminal (which keep the FINAL pair beside the final counts, the phase-64 convention, and log exactly what the payload reports) — and throttled to one read per_RSS_SAMPLE_INTERVAL_S(5 s) from the per-file progress hook, so a 27k-file walk costs ~600/procreads and not 27k (LOCKED A4).GET /api/sync/statusreports both ADDITIVELY asrss_mb/rss_peak_mb(int | null;nullis "no reading", never 0) and the failed funnel samples too, because the run that died is the run whose memory matters. That ONE sampler also owns the pair's invariant: the kernel refreshesru_maxrsslazily, so a raw peak can sit BELOW the rawVmRSS(measured 164 vs 162) and_sample_rsslifts it to the current reading — every surface (both lines, the payload, the page's clause) therefore satisfiespeak >= current, never a peak below the run's own footprint, and an unknowable peak is never fabricated from the current reading); UI-side, honor the "never stale" feedback contract (PLAN §7.4). Phase 188 adds the retrieval tier's ONE operator-visible line: whenBOR_RETRIEVAL_EF_SEARCHsits below the A7 candidate count_vector_candidateslogsretrieval: ef_search=%d raised to %d (A7 candidate count)at WARNING and runs the search at the candidate count anyway — the clamp is never silent, and the healthy (ef_search >= candidate count) turn logs nothing. The value itself reaches Postgres asSET LOCAL hnsw.ef_searchinside the turn's own transaction (LOCKED A4: no global GUC, nothing survives the request or a pool recycle). Task 04's live gate (the 1,000-document live-replica KB, the live embedding endpoint, question vectors PINNED so the access path is the one variable —benchmarks/phase188_live_gate/) found no A8, top-5 ortop_scoredifference at any depth and shippedretrieval_ef_search = 400: at the candidate count the graph recovered the exact top-100 for 0.9814 of rows on average (0.94 worst), at 400 for all of them, and NO threshold (relevance_threshold,lexical_support_floor,name_hit_bonus,hybrid_top_k,hybrid_vector_candidates) moved to get there (LOCKED A3). Two things the operator needs from the same run: building the index costs ~161 s per 417k chunks and ~1.6 GB (3.9 KB/row atm = 16, 768-dim), andmaintenance_work_mem = '512MB'is NOT applicable in this container —/dev/shmis 63 MB, so a raise above that dies withcould not resize shared memory segment … No space left on deviceand leaves an INVALID index for the migration's self-heal to drop and rebuild (observed live); the container's 64 MB default builds it fine. -
Never block the event loop: anything blocking (a
subprocess, synchronous file/network I/O, a heavy walk) reached from anasynchandler or a spawned background coroutine goes throughasyncio.to_thread(orcreate_subprocess_exec). The sync's git calls do (phase 179: a longgit cloneused to park the single uvicorn loop and freeze the whole HTTP surface, the 2 sGET /api/sync/statuspoll included — pinned bytests/integration/test_sync_git_freeze.pywith a 3 s stub and bytests/e2e/test_sync_git_freeze.pywith a real ~9 sfile://clone). A cooperative cancel unblocks the run at theto_threadawait; the worker thread itself runs to completion (threads are not interruptible) while the loop keeps serving — pinned by the same E2E module's cancel-during-clone test. Since phase 186scripts/git_sync.pyhas two git spawn sites — the bufferedrun_gitand the streamingstream_git_lines(the commit-date walk yieldsgit logline by line instead of holding the whole history in RAM) — and both are off-loop viaasyncio.to_thread; thesubprocess.single-site intent survives as "one per shape, both owned there", enforced bytests/unit/test_git_sync.py::test_only_two_git_spawn_sites, and the owner-visible date contract through the stream (last-commit dates, the mtime fallback, the D1 manual lock) bytests/e2e/test_git_log_stream_dates.py. -
Never hydrate what you delete:
Document.chunksispassive_deletes=True(phase 183), so deleting a document removes its chunk rows in the database (chunks_document_id_fkeyisON DELETE CASCADE, alembic 0001) and a mass prune costs O(documents). The importer's prune and the source-removal endpoint both rely on it. Do not remove the keyword, and do not add a delete path that SELECTschunks(or aChunk.embedding) on its way to deleting them — one hydrated 768-dim embedding is ~24.8 KiB of Python, which is how the 2026-10-15 sync's 3,008-document prune reached 4 GB and locked up the VM. Pinned bytests/integration/test_prune_cascade_statements.py(statement count, zero orphan chunk rows, and a live-FK drift guard that fails the suite if the cascade clause ever disappears — because thenpassive_deletes=Truewould silently orphan rows). Thedoc.chunks = [...]re-embed path is the deliberate, documented exception (collection replacement legitimately needs the loaded collection; changed files only). -
Release the sync session at the proven-safe points only: an import run holds one session and
expire_on_commit=False(app/db.py) means a commit releases nothing, so_unchanged_doc'sfile_hashstamp keeps every walkedDocument— content included — resident in the session's own strongdirtyset (not collectable): memory grew with the KB. The cadence is thereforesession.expunge_all()everyBOR_SYNC_SESSION_RESET_FILESfiles at the TOP of the per-file loop and once per source before the two post-passes (phase 184;0= never, the pre-phase rollback).expunge_allDISCARDS unflushed changes, so never move it into_index_file,_unchanged_doc,_store_summaryor a post-pass — their locals are live across statements — and never add a reset before a file's per-file commit. Pinned bytests/integration/test_import_session_retention.py(bounded with the cadence on, unbounded with it0, byte-identical summaries and DB) and through the UI bytests/e2e/test_sync_session_reset.py(two module apps, one per cadence: every document exactly once, the all-unchangedre-sync, and the0-cadence run byte-identical to the3-cadence one). -
The prune reads six columns and commits in batches:
_pruneselects its candidates throughload_only(id, source, path, is_image, image_path, page_count)order_by(Document.id)— the exact set the phase-122 images-off guard, the phase-126 parent-PDF rule and the image/page copy cleanup read, and NOTcontent(252 MB of markdown per full KB walk) — and commits everyBOR_SYNC_PRUNE_BATCHdeletes (0= the pre-phase single commit; phase 184). Never read anotherDocumentattribute inside that loop (a deferred column costs one lazy SELECT per document and unbounds the walk — noraiseloadpaper-over, add the column instead), and never swap the per-documentsession.delete(doc)for a bulkdelete()(the guards,changed_pathsand the log line depend on the per-document shape). A non-zero batch deliberately trades the all-or-nothing prune for a prefix (LOCKED A2):seenis recomputed from disk, so the next sync converges. Pinned bytests/integration/test_import_session_retention.py(the capturedSELECT's column list, exactly one document-wideSELECTper prune (a second one is a per-row lazy load), the commit counts at10and0, both guards on light rows) andtests/e2e/test_sync_session_reset.py(the five-document prune at batch2through the RAG page (/sources.html): both folders cleared, the survivors' chunks intact, zero orphan chunk rows). -
The unchanged fast path reads metadata, never markdown: the four row lookups that share it (
_index_file,_index_pdf_file,_index_one_embedded_image,_index_image_file) all go through the ONE statement_doc_row_stmt(app/rag/importer.py), which defersDocument.contentand NOTHING ELSE (phase 185, LOCKED A1) — the row load is the only place the fast path gets its row, and hydratingcontentfor every inspected file is what put ~252.6 MB of markdown in front of a run that re-indexed 217 of ~27k files. Do not add a fifth whole-entityselect(Document).where(Document.source == …, Document.path == …), do not swap thedeferfor aload_onlyallowlist (a future column would silently become lazy and resurface as an N+1), and do not addraiseload/noload(LOCKED A2):_unchanged_doc's phase-118 summary-NULL backfill genuinely readsdoc.contentand must pay one per-row, one-time SELECT instead of raising. Pinned bytests/integration/test_import_fast_path_columns.py(the captured fast-pathSELECTnames nodocuments.content, exactly oneSELECTper unchanged file with a summary, exactly one PK follow-up for the backfill),tests/unit/test_importer_defer_content.py(contentis the only deferred column, the four loads share the helper, noraiseload/noloadin the importer) andtests/e2e/test_fast_path_deferred_content.py(the owner-visible parity: the summary-NULL backfill survives the deferral with exactly oneis_summarychunk, an unchanged doc's viewer shows the full stored text, a changed file re-indexes and the fast path still fires after). -
The cosine tier is indexed — keep it indexed, and keep
0029the ONE definition of that index:ix_chunks_embedding_hnsw(HNSW overchunks.embedding,vector_cosine_ops,m = 16,ef_construction = 64) exists because every turn'sORDER BY embedding <=> :vec LIMIT 100full-scanned ~3 GB on the interactive path (phase 188). Build and drop it ONLY through migration0029(CREATE/DROP INDEX CONCURRENTLYinsideop.get_context().autocommit_block(), which pre-drops an INVALID remnant and raises if the build does not validate) — never an inlineCREATE INDEXin app code, a test, or a runbook step; never a second vector index, ahalfveccast, or a rewrittenORDER BY(the<=>operator is what the graph serves, LOCKED A3/A6). A test that needs the index OFF moves the SCHEMA (command.downgrade(cfg, "0028")/command.upgrade(cfg, "0029")) after rolling back its own session — an open snapshot parks aCONCURRENTLYbuild indefinitely — and asserts the catalog state it claims (pg_index.indisvalid,pg_get_indexdef).hnsw.ef_searchis set withSET LOCALinside the turn's own transaction and theint()-coerced setting is the only source (no globalSET, no pool-wide state, nothing survives a recycle); the shipped default is 400 because that is the depth the live gate measured exact-top-100 parity at, so "tuning" it back to the candidate count is a recall change, and closing a recall gap by moving an honesty threshold is forbidden (LOCKED A3). Theef_searcha turn gets ismax(retrieval_ef_search, hybrid_vector_candidates)with a WARNING when clamped. Pinned bytests/integration/test_chunks_hnsw_index.py(DDL round trip + INVALID self-heal + drift guard),tests/integration/test_chunks_hnsw_recall.py(the tier's captured statement names the index,SET LOCALreaches the connection, recall at the shipped depth with the index paths forced —enable_seqscan,enable_indexonlyscanANDenable_bitmapscanoff, because a bitmap scan throughix_chunks_document_idotherwise disguises a full read and flips the plan on a shared dev DB — and the unforced plan asserted only when the relation holds nothing but the module's own corpus), andtests/e2e/test_vector_index_recall.py(the owner-visible arm: the SAME cited document with the index dropped and restored, the index VALID after a real importer run, the near-miss still deflecting in both arms, and the clamp read off the app's own captured stdout at=150/=50). That suite's sentinels are calibrated againsttests/fixtures/hnswkb/— an 11-note tracked KB whose BYTES own the quoted cosine/lexical margins, so editing a note there moves the numbers in the module docstring and the pins together.
Quick reference
podman compose up -d db # start Postgres 17 + pgvector
cp .env.example .env # once; then edit
uv run alembic upgrade head # apply migrations
uv run uvicorn app.main:app --reload # dev server (add DEBUGPY=1 to debug)
uv run pytest # unit + integration
uv run pytest --cov=app --cov-report=term-missing
uv run playwright install chromium # once
uv run pytest tests/e2e/test_smoke.py -v --no-cov
uv run ruff check . && uv run pyright # lint + types
uv run python -m scripts.eval_retrieval --from-file tests/fixtures/retrieval_battery.txt # retrieval regression battery (phases 119/162)
uv run python -m scripts.api_payload_audit # endpoint byte audit vs the 256 KB budget (phase 167; app must be running)