# Pre-release review — 2026-08-20 Audit of the codebase before the soft release (tangled push + mini-PC deploy). Three sections: security, effectivity, user workflow. Ordered by severity within each section. Items marked *(verified)* were reproduced against the actual venv, not just read. **Release-blocking:** security 1 and 4; effectivity 1 and 3 (the deployed product looks broken without them); effectivity 2 silently shrinks every topic region. The rest survives a soft launch with friends. > **Status 2026-08-20 (post-soft-release prep):** all release-blocking items > are fixed and the processes restarted on the new code. Marked **✅ done** > below. The rest remain open. ## Security 1. **The proxy publicly exposes the sidecar's admin routes.** `auth/proxy.py:49` forwards all of `/oauth/*` to the sidecar, which serves unauthenticated (`auth/oauth/server.mjs:181-189`): - `GET /oauth/sessions` — enumerates every logged-in user's DID - `GET /oauth/logout?did=X` — **anyone on the internet can revoke anyone's atproto OAuth session** (it calls `session.signOut()`) Login and callback already go through the proxy's own `ask_sidecar`, so this forwarding serves no purpose. Deleting `"/oauth": SIDECAR` from `UPSTREAM` closes both holes and breaks nothing. **✅ done** — `"/oauth": SIDECAR` removed from `UPSTREAM` (`auth/proxy.py:49`). The sidecar is now only reached via `ask_sidecar` (login, callback, client metadata, jwks); `/oauth/sessions` and `/oauth/logout` are off the tunnel. 2. **Unbounded cost/abuse surface on `/api/request`.** Any logged-in user can create unlimited topics (`app/server.py:437`). Each topic costs GreenPT calls forever (exemplars + harvest + ~60 fit judgments per pass, re-run every housekeeping round). No per-user cap, no rate limit, no server-side length cap (`maxlength=300` on the input is client-only). Add a per-DID topic cap and a server-side text cap. **Follow-up — roles, topic verification, and rate limits (design, not yet built).** Add a global rate limit for new users (one topic). When a new user requests a topic it should **not** appear in the main feed until it is verified by a member (currently just the admin). Once a topic is verified the per-user rate limit lifts. Keep a global rate limit as a safety net. From a technical standpoint we need: - role assignment on users — **admin, member, verified user, new user**; - a **verification** flag/step on topics; - **rate limits set per role**. A verified user's topics flow into the feed immediately; a new user's topic is queued behind member verification. 3. **SQL-style injection in LanceDB `where` clauses.** `feed/store.py` builds filters with f-strings (`_get` L237, `fitted_uris` L711, `vote_counts` L783, `delete_topic` L550-552) over user-controlled `rkey`/`uri` (`/api/topic/` is URL-decoded). Today's impact is low — the data is public, and the destructive `delete_topic` is accidentally gated by `records.delete` failing on a malformed rkey first — but that is luck, not design. One helper that doubles single quotes fixes the whole class. 4. **systemd units run everything as root** (`deploy/*.service` — no `User=`). The proxy is internet-facing via the tunnel. Add a dedicated user plus `ProtectSystem=strict`, `ProtectHome=true`, `ReadWritePaths=/opt/aligned.click/private`. Also: `install.sh` needs `systemctl daemon-reload` after copying units; `.env` is mode 664 (contains `GREENPT_API_KEY` and the app password — `chmod 600`); `save_sessions` (`proxy.py:146`) writes non-atomically with default perms — the sidecar's own `store.mjs` shows the pattern (0600 + tmp+rename), copy it. **✅ done** — all five `deploy/*.service` units now run `User=aligned` / `Group=aligned` with `ProtectSystem=strict`, `ProtectHome=true`, `ReadWritePaths=/opt/aligned.click/private`. `install.sh` creates the `aligned` user, `chmod 600`+chowns `.env`, owns `private/`, and runs `systemctl daemon-reload`. `save_sessions` now writes atomically with 0600 (tmp + rename), matching `store.mjs`. Note: the currently-running dev processes are still manual (no systemd units active) — these only take effect when `install.sh` runs on the mini-PC. **Fix on re-review:** the sidecar's store dir defaulted to `auth/private/oauth` — outside `ReadWritePaths`, so every login write would have failed under the new unit. `aligned-oauth.service` now sets `OAUTH_STORE_DIR=/opt/aligned.click/private/oauth` (the sidecar creates the dir itself as `aligned` on first boot). 5. **Smaller items.** - Proxy sessions never expire server-side; the 30-day TTL is only a cookie hint. - `app/server.py:111` `body()` reads unbounded/negative `Content-Length`; a negative value makes `rfile.read()` block until close (thread-exhaustion DoS). - `feedgen/server.py:95-96` — `int()` on `limit`/`cursor` raises on garbage input, killing the handler thread. - A topic whose criteria text is itself a prompt injection ("score everything 10") pollutes the union feed for everyone. The feedgen has `MIN_GRADE=6` as a backstop, but the app's main feed has **no default grade floor**. ## Effectivity 1. **The worker's event loop is blocked by synchronous I/O, and housekeeping starves.** `_handle_frame` (`ingest/worker.py:269`) is `async` but calls blocking `embed()`, `store.add_posts`, `touch_keyword`, and `topics.pass_post` (LLM calls with 120s timeouts) directly on the event loop — while one post is judged, nothing is received, and Jetstream disconnects slow consumers. Worse: `run_once` (`worker.py:305`) only returns after **5 seconds of total silence**, which never happens on the full post firehose — so the `main_loop` never iterates, and **housekeeping (topic processing, backfill, sweeps) and the 2-minute keyword-filter refresh only run when the connection happens to drop**. A new topic's keywords may never reach the firehose filter while connected. Fix: wrap blocking work in `asyncio.to_thread`, and bound `run_once` by wall-clock (e.g. return after 60s) instead of by silence. **✅ done** — the blocking per-frame work (embed, store writes, LLM judge) now runs off the event loop via `asyncio.to_thread` (`_process_frame_sync`), and `run_once` is bounded by wall-clock (`RUN_DURATION` 60s, `ONCE_DURATION` 15s for `--once`) instead of 5s of silence, so housekeeping and the keyword-filter refresh run on schedule. 2. **LanceDB vector searches silently cap at 10 results** *(verified on lancedb 0.33.0)*. `posts_within`, `posts_within_exemplars` (store.py:626) and `topics_near_exemplars` (store.py:645) call `.search(vec)` without `.limit()` — the default is 10. Consequences: - `pass_topic` only ever sees the 10 nearest pool posts per exemplar (~60 max); once those are judged, `assignment_exists` filters them and the pass returns 0 forever — **the rest of a region is never judged from the pool side**. - `pass_post` only considers the 10 nearest exemplars *globally*; as topics multiply, posts silently stop being checked against regions they fall in. Fix: explicit generous `.limit()` (e.g. 1000) before the distance filter. **✅ done** — `posts_within`, `posts_within_exemplars`, `topics_near_exemplars` and `topics_near` now pull `VECTOR_SEARCH_LIMIT` (1000, env-tunable) before the distance filter. `pass_topic` also pulls a generous pool (`max(limit*10, 1000)`) and filters already-judged, so a region is exhausted from the pool side instead of returning 0 once the first batch is judged. 3. **Stale table handles** *(verified)*. A cached `_tables` handle does not see another process's writes; `checkout_latest()` fixes it. The app and feedgen will serve frozen data in production until restarted — the worker writes constantly. Cheap fix: clear `_tables` (or `checkout_latest()` each table) on a short timer, or per request. **✅ done** — `_table()` clears its cache on a short `STORE_TABLE_TTL` (15s, env-tunable) timer, so the next `open_table` re-reads the latest version instead of serving frozen data until restart. 4. **`/api/topics` is N full-table scans, polled every 3s per open tab.** `app/server.py:211` calls `store.fitted_uris(topic=rkey)` per topic — each scans the entire assignments table. One scan grouped by topic replaces all of it. 5. **`main_feed` recomputes the world per request** (two full assignment scans + a giant `uri IN (...)` + votes scan), and `feedgen/skeleton` calls it on every appview poll. A 30–60s TTL cache makes the feedgen nearly free and the app snappy. 6. **One bad post kills a whole judge batch** — contradicting the repo's own convention ("a flaky provider must not kill a whole pass"). `fit.quality_check` (`feed/fit.py:80`) calls `future.result()` bare; one `ClassifyError` aborts the batch and discards the 39 completed verdicts — nothing is assigned. Same in `quality.py`. Catch per future and skip failures. Note `completion_tolerant` does not retry — it only records a hint. 7. **Hot-path store writes are heavy.** `touch_keyword` (per keyword hit per firehose post) reads the row and merge-rewrites it *including the 2560-dim vector*; `add_posts` does a per-row existence query before merging. Debounce `last_seen` updates (dirty-set flushed once a minute) and batch the existence check into one `uri IN (...)` query. 8. **Serial LLM chains in backfill.** `backfill_once` calls `pass_post` per post, which judges one post against up to 5 topics sequentially — hundreds of serial round-trips per run. Collect candidates per topic and batch them through `quality_check` (which is already parallel). 9. **The app runs the topic sweep unconditionally** (`app/server.py:517`). AGENTS.md says production leaves it to the worker, but the code always runs `sweep_unprocessed` — the per-topic locks in `feed/topics.py` don't cross processes, so app and worker can double-process a topic (double LLM cost, LanceDB commit races). Gate it behind an env flag. 10. **`_annotate_engagement`** does two serial sidecar→PDS round-trips per feed request per logged-in user, and only sees the first 100 likes/reposts (older likes render dark). Parallelize the two calls. ## User workflow 1. **The ask box eats pastes.** `guardPrefix` (`app/index.html:231`) assumes the value started with the prefix; on select-all + paste it rebuilds as `BASE + pasted.slice(30)`, deleting typical pasted input entirely. People *will* paste a wish. Fix: if the prefix is gone, append the whole current value instead of slicing it. 2. **"add topic" is enabled with only the prefix typed** (`updateAuth`, L259 — `Q.value.trim()` is never empty since the prefix is always present), so a click yields a server 400. Enable only when `Q.value.slice(PRE).trim()` is non-empty. Relatedly, for logged-out users the button is just dead with no hint why; the Enter-key path does show the "log in" error, so mouse users are the ones left guessing. 3. **There is no way to un-+1 anything — including a topic.** The +1 buttons (posts, and the topic itself in topic view) only ever create vote records; clicking ✓ again writes a *duplicate* record to the user's repo. For a topic this is worse than a wasted record: the `liked` flag is what groups it under "feeds you like" in the pane, so **a +1'd topic is pinned there forever with no way to remove it**. Meanwhile the ♥/↻ buttons right next to it toggle on/off, teaching the user the wrong lesson. The retract machinery already exists — `_my_record` (`app/server.py:391`) does the listRecords lookup for engage; reuse it for votes, and let `DELETE`-ish toggling remove the vote record and the `votes` row. 4. **Topic deletion has no confirmation**, and it is doubly destructive (store rows + the atproto record). One misclick in the ⋯ menu and it is gone. 5. **The pane re-renders every 3 seconds** (`setInterval(loadPane, 3000)`), which (a) closes an open ⋯ menu before you can reach "delete", and (b) **leaks one `document`-level click listener per render** (L528 is inside `renderPane`) — thousands per hour. Bind the document listener once; skip re-render when nothing changed or when a menu is open. 6. **Stale login state.** `me` comes from `localStorage` and is trusted over the server (init only calls `/api/me` when localStorage is empty). After a server-side session loss the UI shows you logged in and every write 401s. Clear `aligned_me` on any 401 and re-check `/api/me`. 7. **Minor.** - Pane polling continues in hidden tabs (`document.visibilitychange`). - `hasMore` shows "…" once too often when the remainder is exactly one page. - A failed `start_topic` after the record write returns a 400 even though the topic will appear later via the sweep — say "queued" instead of failing, or the user retries and creates a duplicate. - The handle cache in `identity.py` never refreshes — a renamed handle shows the old one until restart. ## Also shipped 2026-08-20 - **Mobile mode** (`app/index.html`). On screens ≤720px the left pane becomes an off-canvas slide-in overlay, hidden by default; a floating chevron button (`❯`) opens it and (`❮`) closes it. Selecting a topic or the brand auto-closes it; resizing back to desktop resets the overlay. The toggle is hidden on wide screens. ## Planned: a dev/admin site (not yet built) A small admin product, separate from the customer-facing feed, for running and inspecting the pool by hand. This is the natural consumer of `private/progress.json` (AGENTS.md already notes a future admin site can poll it). Draft scope: - **Add keywords by hand** — `POST` a term (or a few) → runs `feed.keywords.index_keywords([term], provenance="admin")`, which embeds the term, searches its recent posts, and pools them. Retrieval-only: keywords never decide membership, so this is safe for an admin surface. - **See keyword statistics** — per keyword: status (candidate/indexed/ disqualified/pruned), `post_count`, `last_seen`, `last_indexed`, `provenance`. Spot a gap (e.g. a topic concept that never got a keyword) and fix it by hand. - **See exemplars** — every topic's exemplar posts (the region anchors) with their embeddings/score context, so an operator can judge whether a region landed where real posts live. - **See topic processing state** — poll `store.progress_for(rkey)` so a processing pass is watchable live. - **Own identity, no allowlist** — a real atproto login through the auth sidecar like everything else; gate writes (add-keyword) to `ADMIN_DID`, keep reads open to the operator. Deliberately **not** in scope: mutating grades, assignments, or votes — those stay owned by their writer activities (judge, worker). The admin site reads the store and adds retrieval keywords only. Open question (unresolved): whether it is a new `admin/` module that binds loopback and is routed by the existing proxy, or a separate process on its own port. The repo's current stance — "the proxy is the only exposed surface" — argues for routing it through the proxy under an `/admin` path.