{"messages":[{"content":"You are a constitutional council ranking individual git commits for ownership allocation.\n\nCompare these two commits. Decide which contributed more lasting value to the project.\n\nJudge substance, not spectacle:\n- Prefer correct, lasting design and real bugfixes over churn, formatting, renames, or generated noise.\n- Prefer clarity and necessity over sheer line count. A small precise change can beat a large diffuse one.\n- Do not favor a side merely because its patch is longer or noisier.\n- Weight what the change does for the project, not the contributor's name.\n\nReturn ONLY a JSON object: {\"winner\": \"A\" or \"B\", \"ratio\": \"N:M\", \"explanation\": \"...\"}\nThe explanation must cite concrete differences in the patches (1-3 sentences).\n\nSide A — contributor: tommy-mor\nSide A — commit message:\n[1c914c6e] stage set\n\nSide A — unified diff (full patch):\ndiff --git a/plan.md b/plan.md\nnew file mode 100644\nindex 0000000000000000000000000000000000000000..00d6867a1e0ed144a16a020ea037f685ce646c73\n--- /dev/null\n+++ b/plan.md\n@@ -0,0 +1,155 @@\n+# Plan: `ItemId` + `RouteContext` (identity vs hrefs)\n+\n+This document is for **the next agent** to continue the refactor without re-deriving context from chat. It supersedes ad-hoc notes: treat it as the checklist of record until the work lands and this file is deleted or trimmed.\n+\n+## Goal\n+\n+- **Identity** (what lives in the reducer graph, votes, indexes) becomes a **structural `ItemId` enum** in `slug-types`, not a canonical `String` / `CanonicalItemUrl` newtype.\n+- **Presentation** (tilde / dash display, breadcrumbs) derives from `ItemId` via explicit methods, not string stripping.\n+- **Routing** (browser `href`s for public vs room) goes through **`RouteContext`** (started in `server/src/html/routing.rs`) so Maud/handlers do not stitch `/r/…` vs `/~` ad hoc.\n+\n+**Non-goals for v1 of the migration:** backward-compatible JSONL or dual-read of old canonical strings in the event log (project has accepted breaking changes). If you reintroduce compat, document it here.\n+\n+## Current state (as of this plan)\n+\n+- **`CanonicalItemUrl`** (`types/src/paths.rs`): newtype around `String`; `parse` / `parent` / `display_path` / `tilde_tail` / etc. Reducer `ContentState`, `VoteData`, ranking, RPC, search, garden, breadcrumbs all use it or `String` keys derived from it.\n+- **`ThreadNav`** (`server/src/html/forum/nav.rs`): encodes scope prefixes for threads and garden URLs; **`RouteContext`** now wraps `ThreadNav` (`server/src/html/routing.rs`, re-exported from `server/src/html/mod.rs`) but **most HTML still takes `&ThreadNav` directly** — migration incomplete.\n+- **URL normalization** lives in `types/src/url_normalize.rs` + `canonicalize_item` / `finalize_external_identity_url` in `paths.rs` (YouTube, sorted query params, room path `room_route_segment` in `paths.rs`).\n+- **Room HTTP paths** are `/r/{short}{slug}` (fused segment); wire **`room_id`** remains `short/slug` for RPC/events.\n+\n+## Target architecture\n+\n+### `ItemId` (types)\n+\n+Suggested shape (adjust after profiling `Ord` / `Hash` / serde size):\n+\n+```text\n+ItemId::Root — tilde ontology root (today `SLUG_TILDE_ONTOLOGY_ROOT`)\n+ItemId::Local { segments } — slug.social ~/… path as Vec (lowercase segments, non-empty for non-root)\n+ItemId::External { url: Url } — normalized `url::Url` (crate `url` already in `slug-types`)\n+```\n+\n+**API surface (minimum):**\n+\n+- `ItemId::parse(&str) -> Option` — single entry from DSL / user input / legacy wire (internally may call `canonicalize_item` + structured split).\n+- `ItemId::to_wire_url(&self) -> String` — only for **external** boundaries if needed (HTTP fetch, rare assertions); avoid using as the primary key once maps use `ItemId`.\n+- `parent`, `display_path`, `tilde_tail` / `tilde_http_tail`, `tilde_segments`, `last_segment`, `normalized_storage` — port from `CanonicalItemUrl`.\n+- **`Ord` + `Hash` + `Eq`** stable for `BTreeSet` / `HashMap` (see `write_actor` scope-rank snapshots).\n+- **`Serialize` / `Deserialize`** — decide **tagged JSON** for any persisted or API-carried structs (e.g. `VoteData` in tests). If RPC must stay stringy for clients, use a **DTO layer** that converts `ItemId` ↔ wire at the boundary only.\n+\n+**Remove:** `CanonicalItemUrl` type and all `path_types::CanonicalItemUrl` / `slug_types::paths::CanonicalItemUrl` exports once call sites are migrated. **`Borrow`** on the old newtype goes away; update `nav!` / any code that assumed map keys borrowed as `str`.\n+\n+### `RouteContext` (server HTML)\n+\n+- **File:** `server/src/html/routing.rs` — **`RouteContext(ThreadNav)`** with `item_href`, `item_href_raw`, `thread_url`, `garden_root_url`, `room_url`, `From`/`Into` `ThreadNav`.\n+- **Direction:** new code and refactored Maud should take **`&RouteContext`** (or owned where appropriate) instead of `&ThreadNav` when building links. Long term, **`item_href(&ItemId)`** should not parse strings — it should pattern-match `ItemId` and append tilde tail or `/-/…` external tail using the same rules as today’s `ThreadNav::garden_item_url`.\n+\n+### Axum / garden routes\n+\n+- **No** single catch-all route (explicit decision): keep the existing router layout in `server/src/lib.rs`.\n+- Room routes stay **`/r/:room_key/...`** with `room_key` fused; parsing via `slug_types::room_id_from_route_segment` / `room_route_segment` in `paths.rs`.\n+\n+## Phased execution (recommended order)\n+\n+### Phase 0 — Preconditions (quick)\n+\n+1. Read **`AGENTS.md`** (UI contract, durability matrix, `RpcCommand` vs `HtmlUiAction`).\n+2. Run **`cargo test --workspace`** and **`./scripts/clj-test.sh`** on clean `main` before large diffs; repeat after each phase.\n+\n+### Phase 1 — `ItemId` in `slug-types` (no server yet)\n+\n+1. Add **`ItemId`** (new file e.g. `types/src/item_id.rs` **or** inline at bottom of `paths.rs` — see **Module cycle** below).\n+2. Implement **`ItemId::parse`** using existing **`canonicalize_item`** + normalization; port **`CanonicalItemUrl`** methods to **`ItemId`** with tests ported from `paths.rs` `#[cfg(test)] mod tests`.\n+3. **`GardenItemUrl::from_stored(&ItemId, room_wire)`** (and thread helpers) — build absolute hrefs from structure, not from re-parsing a canonical string.\n+4. **`TildeHttpPathTail::to_item_id`** (rename from `to_canonical`) / **`tilde_http_path_to_item_id`**.\n+5. **`TildeOntologyPath::from_stored(&ItemId)`**.\n+6. Export **`ItemId`** from **`types/src/lib.rs`**; update **`server/src/path_types.rs`** re-exports.\n+7. **Delete `CanonicalItemUrl`** and fix all **in-crate** references in `types` only until `cargo test` passes for `slug-types`.\n+\n+**Module cycle trap:** `item_id.rs` must not `use crate::paths::{...}` if `paths.rs` also imports `ItemId` for `GardenItemUrl` in the same module. **Fix one of:**\n+\n+- **A)** Put `ItemId` **inside `paths.rs`** below `canonicalize_item` / helpers (simplest, large file), or \n+- **B)** Split **`canonicalize_item`** (+ dash host helpers + `finalize_external_identity_url`) into **`types/src/item_wire.rs`**, then `paths.rs` + `item_id.rs` both depend on `item_wire` only (cleaner, more files).\n+\n+### Phase 2 — Reducer + ranking (server core)\n+\n+1. **`server/src/reducer.rs`**: `ContentState` / `GroupState` / **`VoteData`** — replace **`CanonicalItemUrl`** with **`ItemId`** on all maps, sets, deques, vectors.\n+2. **`apply_vote`**: normalize `a`/`b` via **`ItemId::parse`** or **`ItemId`**-aware logic (remove string round-trip).\n+3. **`apply_ingest_to_content`**: **`dsl`** still yields strings for item titles in statements; normalize to **`ItemId`** at ingest boundary via **`ItemId::parse`** once per item.\n+4. **`server/src/ranking.rs`**, **`server/src/scope_rank.rs`**, **`server/src/api/write_actor.rs`** (including **`BTreeSet`** ordering), **`server/src/api/validate.rs`**, **`server/src/api/helpers.rs`** — propagate **`ItemId`**.\n+5. **`server/tests/basic.rs`** and any reducer tests constructing **`VoteData`** — use **`ItemId::parse(...).unwrap()`** or helpers.\n+\n+### Phase 3 — RPC + search + external resolver\n+\n+1. **`server/src/api/rpc.rs`**: rank/pair/matchup/search payloads; today many paths use **`GardenItemUrl::from_storage_str(item.as_str(), …)`** — switch to **`ItemId`** + **`GardenItemUrl::from_stored(&item_id, …)`** (or equivalent).\n+2. **`server/src/html/search.rs`**: scoring uses item path strings — derive from **`ItemId::display_path`** / **`to_wire_url`** only at the scoring boundary if needed.\n+3. **`server/src/external_resolver.rs`**: take **`&ItemId`** or **`ItemId::external_url()`** instead of **`&CanonicalItemUrl`**.\n+\n+### Phase 4 — HTML / Maud\n+\n+1. **`ThreadNav::garden_item_url`**: overload or replace with **`garden_item_href(&self, item: &ItemId)`** (no `CanonicalItemUrl::parse` inside).\n+2. **`RouteContext`**: extend **`item_href(&ItemId)`**; migrate call sites from **`ThreadNav`** to **`RouteContext`** where only link-building is needed (keep **`ThreadNav`** where scope / auth helpers need the full struct).\n+3. **`server/src/html/garden.rs`**, **`breadcrumb_path.rs`**, **`forum/*`**, **`editor.rs`**: replace **`CanonicalItemUrl`** with **`ItemId`**; breadcrumbs should walk **`ItemId::parent`** without string `rsplit`.\n+4. **`types` JSON types** (`RankRow`, etc.): decide whether **`GardenItemUrl`** stays string for JSON or becomes a structured field; keep **one** wire format for the public API.\n+\n+### Phase 5 — Cleanup + docs\n+\n+1. Remove dead **`canonical_path`** / **`breadcrumb_path`** string logic if fully superseded.\n+2. Update **`AGENTS.md`** if durability, `POST /ui`, or command surfaces change.\n+3. Delete or shrink **`plan.md`** when done.\n+\n+## File / symbol checklist (non-exhaustive — grep-driven)\n+\n+Run periodically:\n+\n+```bash\n+rg \"CanonicalItemUrl\" -g'*.rs'\n+rg \"path_types::CanonicalItemUrl\" -g'*.rs'\n+rg \"tilde_http_path_to_canonical\" -g'*.rs'\n+```\n+\n+**High-touch files (from prior exploration):**\n+\n+| Area | Files |\n+|------|--------|\n+| Types | `types/src/paths.rs`, `types/src/lib.rs`, `types/src/url_normalize.rs`, (optional) `types/src/item_id.rs`, `types/src/item_wire.rs` |\n+| Server re-exports | `server/src/path_types.rs`, `server/src/canonical_path.rs` |\n+| Reducer / ingest | `server/src/reducer.rs`, `server/src/dsl.rs` (parse output types if changed) |\n+| Ranking | `server/src/ranking.rs`, `server/src/scope_rank.rs` |\n+| Writer / RPC | `server/src/api/write_actor.rs`, `server/src/api/rpc.rs`, `server/src/api/helpers.rs`, `server/src/api/validate.rs` |\n+| HTML | `server/src/html/garden.rs`, `server/src/html/breadcrumb_path.rs`, `server/src/html/forum/nav.rs`, `server/src/html/routing.rs`, `server/src/html/search.rs`, `server/src/html/editor.rs`, `server/src/html/forum/ingest.rs`, … |\n+| Tests | `server/tests/basic.rs`, `server/tests/integration.rs`, `types/src/paths.rs` tests, Clojure under `test/` if URLs/assertions mention canonical shapes |\n+\n+## Events / JSONL\n+\n+- **`Ingest`** events store **`raw` DSL** only — no change required for item identity inside the event.\n+- If any future event type stores item ids as strings, migrate to **structured `ItemId` serde** or accept string only at the event boundary with immediate parse into **`ItemId`** on `apply_event`.\n+\n+## `nav!` macro (`server/src/paths.rs`)\n+\n+- Macros use **`keypath($key)`** with **`.clone()`** — **`ItemId`** must be **`Clone`** (already for enums). Remove any reliance on **`Borrow`** for map keys.\n+\n+## Testing gate\n+\n+After each phase:\n+\n+```bash\n+cargo test --workspace\n+./scripts/clj-test.sh\n+```\n+\n+## Risks / gotchas\n+\n+1. **`Ord` on `ItemId`**: must match prior **`CanonicalItemUrl`** / `String` ordering wherever **`BTreeSet`** is used (e.g. deterministic scope-rank snapshots in **`write_actor`**).\n+2. **External `ItemId`**: **`Url`** equality / hashing — normalization is already centralized in **`url_normalize`**; ensure **`ItemId::parse`** always inserts normalized **`Url`** into **`External`**.\n+3. **Fake parent URLs** in garden (e.g. **`https://.`** for external root ranking): find all **`parse(\"https://.\")`** style hacks and express as **`ItemId`** or a dedicated sentinel.\n+4. **Serde**: tests and any RPC clients that snapshot JSON may need expectation updates if **`VoteData`** shape changes.\n+\n+## Optional follow-ups (not blocking `ItemId`)\n+\n+- More **domain normalizers** in **`url_normalize.rs`** (e.g. `music.youtube.com`, Spotify, etc.).\n+- **Room wire** vs **HTTP segment** helpers already in **`paths.rs`** (`ROOM_SHORT_ID_LEN`, `room_route_segment`, `room_id_from_route_segment`).\n+\n+---\n+\n+**End state criteria:** `rg CanonicalItemUrl` returns nothing; reducer maps use **`ItemId`**; HTML link generation for items goes through **`RouteContext` + `ItemId`**; tests and Kaocha green.\ndiff --git a/server/src/html/mod.rs b/server/src/html/mod.rs\nindex c3dccd03dc6da2a2f6f6fa828657e33a951884b1..668403a35c415e6f091362b28c63ac294057fb6d 100644\n--- a/server/src/html/mod.rs\n+++ b/server/src/html/mod.rs\n@@ -15,6 +15,7 @@ mod breadcrumb_path;\n mod editor;\n mod forum;\n mod garden;\n+pub mod routing;\n mod search;\n pub mod ui_action;\n use breadcrumb_path::{ExternalOntologyPath, OntologyPath};\n@@ -35,6 +36,7 @@ pub use garden::{\n external_garden_index, external_ontology_path, garden_index, ontology_path, room_external_garden_index,\n room_external_ontology_path, room_garden_index, room_ontology_path,\n };\n+pub use routing::RouteContext;\n pub use search::{search_page, search_results_fragment};\n pub use forum::user_profile_page;\n pub use ui_action::{parse_html_ui_from_form, HtmlUiAction, HtmlUiParseError, UI_RPC_FIELD};\ndiff --git a/server/src/html/routing.rs b/server/src/html/routing.rs\nnew file mode 100644\nindex 0000000000000000000000000000000000000000..13e9ae0cbe32d454e34a7737edf8234d2a558502\n--- /dev/null\n+++ b/server/src/html/routing.rs\n@@ -0,0 +1,71 @@\n+//! Scoped browser paths for HTML. **RouteContext** is the intended single place to build `href`s\n+//! given public vs room scope (the original blueprint name); today it wraps [`ThreadNav`].\n+//!\n+//! Prefer `RouteContext::item_href` / [`RouteContext::thread_url`] in new Maud over stitching\n+//! `/r/…` vs `/~` manually. Call sites can migrate incrementally from passing `&ThreadNav`.\n+\n+use crate::path_types::CanonicalItemUrl;\n+\n+use super::forum::ThreadNav;\n+\n+#[derive(Clone)]\n+pub struct RouteContext(ThreadNav);\n+\n+impl RouteContext {\n+ #[inline]\n+ pub fn public() -> Self {\n+ Self(ThreadNav::public())\n+ }\n+\n+ #[inline]\n+ pub fn from_room_id(room_id: &str) -> Option {\n+ ThreadNav::from_room_id(room_id).map(Self)\n+ }\n+\n+ #[inline]\n+ pub fn thread_nav(&self) -> &ThreadNav {\n+ &self.0\n+ }\n+\n+ #[inline]\n+ pub fn into_thread_nav(self) -> ThreadNav {\n+ self.0\n+ }\n+\n+ /// Relative path for a stored canonical item in this scope’s garden.\n+ pub fn item_href(&self, item: &CanonicalItemUrl) -> String {\n+ self.0.garden_item_url(item.as_str())\n+ }\n+\n+ /// Same as [`Self::item_href`] but parses `item` first (raw DSL / user paste).\n+ pub fn item_href_raw(&self, item: &str) -> String {\n+ self.0.garden_item_url(item)\n+ }\n+\n+ #[inline]\n+ pub fn thread_url(&self, tag: &str) -> String {\n+ self.0.thread_url(tag)\n+ }\n+\n+ #[inline]\n+ pub fn garden_root_url(&self) -> &str {\n+ self.0.garden_root_url()\n+ }\n+\n+ #[inline]\n+ pub fn room_url(&self) -> &str {\n+ self.0.room_url()\n+ }\n+}\n+\n+impl From for RouteContext {\n+ fn from(nav: ThreadNav) -> Self {\n+ Self(nav)\n+ }\n+}\n+\n+impl From for ThreadNav {\n+ fn from(ctx: RouteContext) -> Self {\n+ ctx.0\n+ }\n+}\n\n\nSide B — contributor: tommy-mor\nSide B — commit message:\n[1d14ff09] Ephemeral Reddit content; log structure only (#46)\n\n* Keep Reddit content ephemeral; log structure only\n\nRemove EntityImported and EntityStore. Reddit fetches write display\ncontent directly to the projection with a fetched_at timestamp, while\nthe event log records NodeEnsured for discovered identities only.\n\nA background task evicts cached display content after 48 hours. Votes,\ntree structure, and ItemIds remain in the log and projection.\n\nCo-authored-by: tommy \n\n* Fix reddit import test assertions and Clojure syntax\n\nCo-authored-by: tommy \n\n---------\n\nCo-authored-by: Cursor Agent \n\nSide B — unified diff (full patch):\ndiff --git a/server/src/bin/storage_bench.rs b/server/src/bin/storage_bench.rs\nindex 4762d0d23bc8e2df439afe09a3235ba7f72bd486..3d988416ad36b27a7d3dc84280cfdbdcafa43e69 100644\n--- a/server/src/bin/storage_bench.rs\n+++ b/server/src/bin/storage_bench.rs\n@@ -6,8 +6,8 @@ use std::{\n };\n \n use sorter2_server::{\n- entity_store::EntityStore, event_log::EventLog, events::Event, journal::JournalClient,\n- projection_apply, projection_store::ProjectionStore,\n+ event_log::EventLog, events::Event, journal::JournalClient, projection_apply,\n+ projection_store::ProjectionStore,\n };\n \n #[tokio::main]\n@@ -18,12 +18,10 @@ async fn main() -> Result<(), Box> {\n let data_dir = opts.data_dir.to_string_lossy().into_owned();\n let event_log = Arc::new(EventLog::new(format!(\"{data_dir}/events.jsonl\")));\n let db = durable::Db::open(opts.data_dir.join(\"store\"))?;\n- let entity_store = EntityStore::from_db(&db)?;\n let projection_store = ProjectionStore::from_db(&db)?;\n \n let journal = JournalClient::spawn(\n event_log.clone(),\n- entity_store.clone(),\n projection_store.clone(),\n event_log.last_sequence().await? + 1,\n );\n@@ -46,12 +44,9 @@ async fn main() -> Result<(), Box> {\n drop(journal);\n \n let rebuild_start = Instant::now();\n- entity_store.reset()?;\n projection_store.reset()?;\n let rebuild = event_log\n- .replay(|record| {\n- projection_apply::apply_records(&projection_store, &entity_store, &[record])\n- })\n+ .replay(|record| projection_apply::apply_records(&projection_store, &[record]))\n .await?;\n let rebuild_elapsed = rebuild_start.elapsed();\n \ndiff --git a/server/src/entity_store.rs b/server/src/entity_store.rs\ndeleted file mode 100644\nindex d29f39aecca6f12cdcf263cf77c3654eb4ee6cfa..0000000000000000000000000000000000000000\n--- a/server/src/entity_store.rs\n+++ /dev/null\n@@ -1,134 +0,0 @@\n-//! Off-heap storage for full entity payloads (Reddit API JSON).\n-//!\n-//! Derived [`crate::reducer::EntityData`] is stored on the node; the raw JSON\n-//! lives here, in the shared durable [`Store`] schema.\n-\n-use std::path::Path;\n-\n-use durable::{Batch, Db, Durability};\n-use serde_json::Value;\n-\n-use crate::{\n- path_types::ItemId,\n- storage_dto::{decode_entity_payload, encode_entity_payload},\n- storage_schema::{Store, StoreFields},\n-};\n-\n-const ENTITY_SCHEMA_KEY: &str = \"schema_version\";\n-const ENTITY_SCHEMA_VERSION: u64 = 2;\n-\n-#[derive(Debug, thiserror::Error)]\n-pub enum EntityStoreError {\n- #[error(\"durable error: {0}\")]\n- Durable(#[from] durable::Error),\n- #[error(\"json error: {0}\")]\n- Json(#[from] serde_json::Error),\n- #[error(\"storage decode error: {0}\")]\n- Storage(String),\n- #[error(\"io error: {0}\")]\n- Io(#[from] std::io::Error),\n-}\n-\n-/// Disk-backed map of entity id → raw JSON payload.\n-#[derive(Clone)]\n-pub struct EntityStore {\n- db: Db,\n-}\n-\n-impl EntityStore {\n- /// Open (or create) the entity database under `dir`.\n- pub fn open(dir: &Path) -> Result {\n- std::fs::create_dir_all(dir)?;\n- let db = Db::open(dir)?;\n- Self::from_db(&db)\n- }\n-\n- /// Create an entity store backed by an already-open database.\n- pub fn from_db(db: &Db) -> Result {\n- let store = Self { db: db.clone() };\n- let version = Store::root()\n- .entity_meta()\n- .key(&ENTITY_SCHEMA_KEY.to_string())\n- .get(db)?;\n- if version != Some(ENTITY_SCHEMA_VERSION) {\n- store.reset()?;\n- }\n- Ok(store)\n- }\n-\n- /// Clear rebuildable entity payloads and reset storage schema metadata.\n- pub fn reset(&self) -> Result<(), EntityStoreError> {\n- let root = Store::root();\n- self.db.apply(\n- &[root.entities().clear(), root.entity_meta().clear()],\n- Durability::SyncWal,\n- )?;\n- self.db.run(\n- root.entity_meta()\n- .key(&ENTITY_SCHEMA_KEY.to_string())\n- .set(&ENTITY_SCHEMA_VERSION),\n- Durability::SyncWal,\n- )?;\n- Ok(())\n- }\n-\n- /// Persist a payload for `id` (overwrites any existing entry).\n- pub fn put(&self, id: &ItemId, payload: &Value) -> Result<(), EntityStoreError> {\n- self.db.run(\n- Store::root()\n- .entities()\n- .key(&id.as_str().to_string())\n- .set(&encode_entity_payload(payload)),\n- Durability::SyncWal,\n- )?;\n- Ok(())\n- }\n-\n- /// Add a payload write to the caller's batch.\n- pub fn put_in_batch(\n- &self,\n- batch: &mut Batch,\n- id: &ItemId,\n- payload: &Value,\n- ) -> Result<(), EntityStoreError> {\n- batch.write(\n- Store::root()\n- .entities()\n- .key(&id.as_str().to_string())\n- .set(&encode_entity_payload(payload)),\n- );\n- Ok(())\n- }\n-\n- /// Load a stored payload, if present.\n- pub fn get(&self, id: &ItemId) -> Result, EntityStoreError> {\n- match Store::root()\n- .entities()\n- .key(&id.as_str().to_string())\n- .get(&self.db)?\n- {\n- Some(record) => decode_entity_payload(record)\n- .map(Some)\n- .map_err(EntityStoreError::Storage),\n- None => Ok(None),\n- }\n- }\n-}\n-\n-#[cfg(test)]\n-mod tests {\n- use super::*;\n- use serde_json::json;\n-\n- #[test]\n- fn round_trip_payload() {\n- let tmp = tempfile::tempdir().unwrap();\n- let store = EntityStore::open(tmp.path()).unwrap();\n- let id = ItemId::from_url(\"https://reddit.com/r/rust\").unwrap();\n- let payload = json!({\"kind\": \"t5\", \"data\": {\"display_name\": \"rust\"}});\n-\n- store.put(&id, &payload).unwrap();\n- let loaded = store.get(&id).unwrap().unwrap();\n- assert_eq!(loaded, payload);\n- }\n-}\ndiff --git a/server/src/events.rs b/server/src/events.rs\nindex a3d88e285c645a96d33e6f0aed1b487b843aceb8..d76c3bb4277216b0d39c9422ba7a50db10a95e05 100644\n--- a/server/src/events.rs\n+++ b/server/src/events.rs\n@@ -1,5 +1,4 @@\n use serde::{Deserialize, Serialize};\n-use serde_json::Value;\n \n /// Schema version for JSONL log records. Bump when event semantics change.\n pub const CURRENT_LOG_SCHEMA: u32 = 1;\n@@ -30,7 +29,7 @@ pub type ViewRecord = LogRecord;\n /// Wall-clock timestamp carried on the log envelope for domain events.\n pub fn event_timestamp(event: &Event) -> i64 {\n match event {\n- Event::VoteRecorded { ts, .. } | Event::EntityImported { ts, .. } => *ts,\n+ Event::VoteRecorded { ts, .. } => *ts,\n Event::NodeEnsured { .. } => crate::fetch::now_ms(),\n }\n }\n@@ -57,6 +56,4 @@ pub enum Event {\n },\n /// Register a node path in the fractal tree (no external fetch).\n NodeEnsured { id: String },\n- /// Full upstream API payload for a node (domain-specific view derived at replay/render time).\n- EntityImported { id: String, ts: i64, payload: Value },\n }\ndiff --git a/server/src/journal.rs b/server/src/journal.rs\nindex 50bc89f976edb82b7b0e49e954a8eccbbe82bf87..d50023aca7c3e74068de988449b11baee32d1ecf 100644\n--- a/server/src/journal.rs\n+++ b/server/src/journal.rs\n@@ -5,7 +5,6 @@ use std::sync::Arc;\n use tokio::sync::{mpsc, oneshot};\n \n use crate::{\n- entity_store::EntityStore,\n event_log::EventLog,\n events::{event_timestamp, Event, EventRecord},\n projection_apply,\n@@ -25,7 +24,6 @@ pub struct JournalClient {\n impl JournalClient {\n pub fn spawn(\n event_log: Arc,\n- entity_store: EntityStore,\n projection_store: ProjectionStore,\n next_seq: u64,\n ) -> Self {\n@@ -33,7 +31,6 @@ impl JournalClient {\n tokio::spawn(journal_worker(\n rx,\n event_log,\n- entity_store,\n projection_store,\n next_seq,\n ));\n@@ -62,7 +59,6 @@ impl JournalClient {\n async fn journal_worker(\n mut rx: mpsc::Receiver,\n event_log: Arc,\n- entity_store: EntityStore,\n projection_store: ProjectionStore,\n mut next_seq: u64,\n ) {\n@@ -75,7 +71,6 @@ async fn journal_worker(\n let result = append_and_project_batch(\n &event_log,\n &projection_store,\n- &entity_store,\n &mut next_seq,\n &batch,\n )\n@@ -99,7 +94,6 @@ async fn journal_worker(\n async fn append_and_project_batch(\n event_log: &EventLog,\n projection_store: &ProjectionStore,\n- entity_store: &EntityStore,\n next_seq: &mut u64,\n commands: &[JournalCommand],\n ) -> Result<(), String> {\n@@ -117,7 +111,7 @@ async fn append_and_project_batch(\n .await\n .map_err(|e| e.to_string())?;\n *next_seq = seq;\n- projection_apply::apply_records(projection_store, entity_store, &records)\n+ projection_apply::apply_records(projection_store, &records)\n .map_err(|e| format!(\"projection apply failed after durable append: {e}\"))\n }\n \n@@ -132,10 +126,9 @@ mod tests {\n let log_path = tmp.path().join(\"events.jsonl\");\n let event_log = Arc::new(EventLog::new(log_path));\n let db = durable::Db::open(tmp.path().join(\"store\")).unwrap();\n- let entity_store = EntityStore::from_db(&db).unwrap();\n let projection_store = ProjectionStore::from_db(&db).unwrap();\n \n- let journal = JournalClient::spawn(event_log, entity_store, projection_store.clone(), 1);\n+ let journal = JournalClient::spawn(event_log, projection_store.clone(), 1);\n \n let j1 = journal.clone();\n let j2 = journal.clone();\n@@ -177,11 +170,9 @@ mod tests {\n .unwrap();\n \n let db = durable::Db::open(tmp.path().join(\"store\")).unwrap();\n- let entity_store = EntityStore::from_db(&db).unwrap();\n let projection_store = ProjectionStore::from_db(&db).unwrap();\n projection_apply::apply_records(\n &projection_store,\n- &entity_store,\n &[EventRecord::new(\n 1,\n 1,\n@@ -196,7 +187,6 @@ mod tests {\n \n let journal = JournalClient::spawn(\n event_log.clone(),\n- entity_store,\n projection_store.clone(),\n next_seq,\n );\n@@ -219,10 +209,9 @@ mod tests {\n let log_path = tmp.path().join(\"events.jsonl\");\n let event_log = Arc::new(EventLog::new(log_path));\n let db = durable::Db::open(tmp.path().join(\"store\")).unwrap();\n- let entity_store = EntityStore::from_db(&db).unwrap();\n let projection_store = ProjectionStore::from_db(&db).unwrap();\n let journal =\n- JournalClient::spawn(event_log.clone(), entity_store, projection_store.clone(), 1);\n+ JournalClient::spawn(event_log.clone(), projection_store.clone(), 1);\n \n journal\n .append_many(vec![\ndiff --git a/server/src/lib.rs b/server/src/lib.rs\nindex 5c02c8e704e4664453bad75d819df8a067668176..3dfc7c8acb8ed61bb73ade63e72768e402042cc5 100644\n--- a/server/src/lib.rs\n+++ b/server/src/lib.rs\n@@ -1,5 +1,4 @@\n pub mod api;\n-pub mod entity_store;\n pub mod event_log;\n pub mod events;\n pub mod fetch;\ndiff --git a/server/src/projection_apply.rs b/server/src/projection_apply.rs\nindex 5644557a41b3e9497c7421b444155ae629fa79f1..9c8990a8af927f35d3344c8d0872a516aba56b86 100644\n--- a/server/src/projection_apply.rs\n+++ b/server/src/projection_apply.rs\n@@ -1,22 +1,20 @@\n //! Apply event-log records to the durable projection as precise point updates.\n //!\n //! Each batch of records lowers to reified durable writes (edge merges, child\n-//! links, voted-pair flags, recent-vote pushes, entity payloads) plus a cursor\n-//! advance, all committed in one atomic `DisableWal` batch. The cursor moving in\n-//! the same batch as the (non-idempotent) edge merges guarantees exactly-once\n-//! application across replay.\n+//! links, voted-pair flags, recent-vote pushes) plus a cursor advance, all\n+//! committed in one atomic `DisableWal` batch. The cursor moving in the same\n+//! batch as the (non-idempotent) edge merges guarantees exactly-once application\n+//! across replay.\n \n use std::collections::BTreeSet;\n \n use crate::{\n- entity_store::EntityStore,\n event_log::EventLogError,\n events::{Event, EventRecord},\n path_types::ItemId,\n projection_store::ProjectionStore,\n- reddit::entity_view_from_payload,\n reducer::VoteData,\n- storage_schema::{ensure_path_writes, entity_view_writes, vote_writes},\n+ storage_schema::{ensure_path_writes, vote_writes},\n };\n \n fn parse_event_id(id: &str) -> Result {\n@@ -38,7 +36,6 @@ fn parent_from_event_scope(scope: &str) -> ItemId {\n \n pub fn apply_records(\n projection_store: &ProjectionStore,\n- entity_store: &EntityStore,\n records: &[EventRecord],\n ) -> Result<(), EventLogError> {\n if records.is_empty() {\n@@ -79,14 +76,6 @@ pub fn apply_records(\n let parsed = parse_event_id(id)?;\n ensure_path_writes(&mut batch, &parsed);\n }\n- Event::EntityImported { id, payload, .. } => {\n- let parsed = parse_event_id(id)?;\n- let view = entity_view_from_payload(&parsed, payload);\n- entity_view_writes(&mut batch, &parsed, view.as_ref());\n- entity_store\n- .put_in_batch(&mut batch, &parsed, payload)\n- .map_err(|e| EventLogError::Apply(e.to_string()))?;\n- }\n }\n last_seq = record.seq;\n }\ndiff --git a/server/src/projection_store.rs b/server/src/projection_store.rs\nindex 30ee478f953e80d7322bdbfa521ae559ff08fa51..8576d671f351004426207894ac35594ddb0f70cf 100644\n--- a/server/src/projection_store.rs\n+++ b/server/src/projection_store.rs\n@@ -9,13 +9,16 @@ use durable::{Db, Durability, Write};\n \n use crate::{\n path_types::ItemId,\n- reducer::{GlobalTree, NodeState},\n- storage_schema::{load_node_state, node, NodeSchemaFields, Store, StoreFields},\n+ reducer::{EntityData, GlobalTree, NodeState},\n+ storage_schema::{\n+ entity_content_clear_writes, entity_content_writes, load_node_state, node, NodeSchemaFields,\n+ Store, StoreFields,\n+ },\n };\n \n const PROJECTION_CURSOR_KEY: &str = \"cursor\";\n const PROJECTION_SCHEMA_KEY: &str = \"schema_version\";\n-const PROJECTION_SCHEMA_VERSION: u64 = 2;\n+const PROJECTION_SCHEMA_VERSION: u64 = 3;\n \n #[derive(Debug, thiserror::Error)]\n pub enum ProjectionStoreError {\n@@ -148,6 +151,45 @@ impl ProjectionStore {\n )?;\n Ok(())\n }\n+\n+ /// Cache Reddit display content outside the event log (must be evicted per policy).\n+ pub fn put_ephemeral_content(\n+ &self,\n+ id: &ItemId,\n+ view: &EntityData,\n+ fetched_at: i64,\n+ ) -> Result<(), ProjectionStoreError> {\n+ let mut batch = self.db.batch();\n+ entity_content_writes(&mut batch, id, view, fetched_at);\n+ batch\n+ .commit_with(Durability::DisableWal)\n+ .map_err(ProjectionStoreError::from)?;\n+ Ok(())\n+ }\n+\n+ /// Drop cached display content older than `cutoff_ms` (votes and tree structure remain).\n+ pub fn evict_content_older_than(&self, cutoff_ms: i64) -> Result {\n+ let keys = Store::root().nodes().keys(&self.db)?;\n+ let mut batch = self.db.batch();\n+ let mut evicted = 0usize;\n+ for key in keys {\n+ let id = parse_node_key(&key)?;\n+ let np = node(&id);\n+ let Some(fetched_at) = np.fetched_at().get(&self.db)? else {\n+ continue;\n+ };\n+ if fetched_at > 0 && fetched_at < cutoff_ms {\n+ entity_content_clear_writes(&mut batch, &id);\n+ evicted += 1;\n+ }\n+ }\n+ if evicted > 0 {\n+ batch\n+ .commit_with(Durability::DisableWal)\n+ .map_err(ProjectionStoreError::from)?;\n+ }\n+ Ok(evicted)\n+ }\n }\n \n fn parse_node_key(key: &str) -> Result {\n@@ -162,7 +204,7 @@ fn parse_node_key(key: &str) -> Result {\n #[cfg(test)]\n mod tests {\n use super::*;\n- use crate::{entity_store::EntityStore, events::Event, projection_apply};\n+ use crate::{events::Event, projection_apply, reducer::EntityData};\n \n fn record(seq: u64, event: Event) -> crate::events::EventRecord {\n crate::events::EventRecord::new(seq, crate::events::event_timestamp(&event), event)\n@@ -172,7 +214,6 @@ mod tests {\n fn applies_and_loads_reducer_nodes() {\n let tmp = tempfile::tempdir().unwrap();\n let db = Db::open(tmp.path()).unwrap();\n- let entity_store = EntityStore::from_db(&db).unwrap();\n let store = ProjectionStore::from_db(&db).unwrap();\n \n let event = Event::VoteRecorded {\n@@ -183,7 +224,7 @@ mod tests {\n ratio_right: 1,\n scope: String::new(),\n };\n- projection_apply::apply_records(&store, &entity_store, &[record(1, event)]).unwrap();\n+ projection_apply::apply_records(&store, &[record(1, event)]).unwrap();\n assert_eq!(store.last_applied_event_count().unwrap(), 1);\n \n let loaded = store.load_tree().unwrap();\n@@ -196,7 +237,6 @@ mod tests {\n fn hydrates_scope_with_child_nodes() {\n let tmp = tempfile::tempdir().unwrap();\n let db = Db::open(tmp.path()).unwrap();\n- let entity_store = EntityStore::from_db(&db).unwrap();\n let store = ProjectionStore::from_db(&db).unwrap();\n \n let event = Event::VoteRecorded {\n@@ -207,11 +247,36 @@ mod tests {\n ratio_right: 1,\n scope: String::new(),\n };\n- projection_apply::apply_records(&store, &entity_store, &[record(1, event)]).unwrap();\n+ projection_apply::apply_records(&store, &[record(1, event)]).unwrap();\n \n let scoped = store.scope_tree(&ItemId::root()).unwrap();\n let root = scoped.get(&ItemId::root()).unwrap();\n assert_eq!(root.children.len(), 2);\n assert!(scoped.get(&ItemId::opaque(\"alpha\")).is_some());\n }\n+\n+ #[test]\n+ fn evicts_stale_ephemeral_content() {\n+ let tmp = tempfile::tempdir().unwrap();\n+ let db = Db::open(tmp.path()).unwrap();\n+ let store = ProjectionStore::from_db(&db).unwrap();\n+ let id = ItemId::from_url(\"https://reddit.com/r/rust\").unwrap();\n+ store\n+ .put_ephemeral_content(\n+ &id,\n+ &EntityData {\n+ title: \"Rust\".into(),\n+ author: None,\n+ body_html: None,\n+ thumb_url: None,\n+ image_url: None,\n+ link_url: None,\n+ },\n+ 1_000,\n+ )\n+ .unwrap();\n+ assert!(store.load_node(&id).unwrap().unwrap().data.is_some());\n+ assert_eq!(store.evict_content_older_than(2_000).unwrap(), 1);\n+ assert!(store.load_node(&id).unwrap().unwrap().data.is_none());\n+ }\n }\ndiff --git a/server/src/reddit.rs b/server/src/reddit.rs\nindex 20b7f9e3f8be39268a1767d09f5cf81eaa6ae0df..a874814f8927192ee62cab2d0db1efd27dcd57b7 100644\n--- a/server/src/reddit.rs\n+++ b/server/src/reddit.rs\n@@ -9,10 +9,13 @@ use serde_json::Value;\n use tokio::sync::{mpsc, oneshot};\n \n use crate::{\n- entity_store::EntityStore, events::Event, fetch::now_ms, journal::JournalClient,\n- path_types::ItemId, reducer::GlobalTree,\n+ events::Event, fetch::now_ms, journal::JournalClient,\n+ path_types::ItemId, projection_store::ProjectionStore,\n };\n \n+/// Reddit display content must not be retained longer than this (API policy).\n+pub const REDDIT_CONTENT_TTL: std::time::Duration = std::time::Duration::from_secs(48 * 3600);\n+\n #[derive(Debug, Clone, PartialEq, Eq)]\n pub enum FetchJobResult {\n /// Number of entities written (1 for self, N for children).\n@@ -70,7 +73,11 @@ struct OAuthToken {\n }\n \n impl RedditBroker {\n- pub fn spawn(journal: JournalClient, config: RedditApiConfig) -> Self {\n+ pub fn spawn(\n+ journal: JournalClient,\n+ projection_store: ProjectionStore,\n+ config: RedditApiConfig,\n+ ) -> Self {\n let (tx, rx) = mpsc::channel(100);\n \n let mut headers = header::HeaderMap::new();\n@@ -93,7 +100,7 @@ impl RedditBroker {\n \"reddit worker started\"\n );\n \n- tokio::spawn(reddit_worker(rx, journal, client, config));\n+ tokio::spawn(reddit_worker(rx, journal, projection_store, client, config));\n \n Self { tx }\n }\n@@ -189,27 +196,50 @@ pub fn entity_view_from_payload(\n None\n }\n \n-pub fn apply_entity_import(\n- tree: &mut GlobalTree,\n- store: &EntityStore,\n- id: &ItemId,\n- payload: Value,\n-) -> Result<(), String> {\n- let view = entity_view_from_payload(id, &payload);\n- store.put(id, &payload).map_err(|e| e.to_string())?;\n- tree.apply_entity(id, view);\n- Ok(())\n-}\n-\n fn notify(done: Option>, result: FetchJobResult) {\n if let Some(tx) = done {\n let _ = tx.send(result);\n }\n }\n \n+async fn import_fetched_payload(\n+ kind: FetchKind,\n+ fetch_id: &ItemId,\n+ payload: Value,\n+ projection_store: &ProjectionStore,\n+ journal: &JournalClient,\n+) -> Result {\n+ let fetched_at = now_ms();\n+ let imports: Vec<(ItemId, Value)> = match kind {\n+ FetchKind::SelfEntity => vec![(fetch_id.clone(), payload)],\n+ FetchKind::Children => parse_children(fetch_id, &payload),\n+ };\n+\n+ for (id, child_payload) in &imports {\n+ if let Some(view) = entity_view_from_payload(id, child_payload) {\n+ projection_store\n+ .put_ephemeral_content(id, &view, fetched_at)\n+ .map_err(|e| e.to_string())?;\n+ }\n+ }\n+\n+ let events: Vec = imports\n+ .iter()\n+ .map(|(id, _)| Event::NodeEnsured {\n+ id: id.as_str().to_string(),\n+ })\n+ .collect();\n+ let written = events.len();\n+ if !events.is_empty() {\n+ journal.append_many(events).await?;\n+ }\n+ Ok(written)\n+}\n+\n async fn reddit_worker(\n mut rx: mpsc::Receiver,\n journal: JournalClient,\n+ projection_store: ProjectionStore,\n client: Client,\n config: RedditApiConfig,\n ) {\n@@ -276,33 +306,20 @@ async fn reddit_worker(\n \n match outcome {\n Ok(FetchOutcome::Payload(payload)) => {\n- let imports: Vec<(ItemId, Value)> = match kind {\n- FetchKind::SelfEntity => vec![(fetch_id.clone(), payload)],\n- FetchKind::Children => parse_children(&fetch_id, &payload),\n- };\n tracing::debug!(\n item = %fetch_id,\n ?kind,\n- count = imports.len(),\n- \"reddit fetch got payload, importing\"\n+ \"reddit fetch got payload, caching ephemerally\"\n );\n \n- let events: Vec = imports\n- .into_iter()\n- .map(|(child_id, child_payload)| Event::EntityImported {\n- id: child_id.as_str().to_string(),\n- ts: now_ms(),\n- payload: child_payload,\n- })\n- .collect();\n- let written = events.len();\n-\n- match journal.append_many(events).await {\n+ match import_fetched_payload(kind, &fetch_id, payload, &projection_store, &journal)\n+ .await\n+ {\n Err(e) => {\n- tracing::warn!(item = %fetch_id, err = %e, \"reddit import journal failed\");\n+ tracing::warn!(item = %fetch_id, err = %e, \"reddit import failed\");\n notify(done, FetchJobResult::Failed(e));\n }\n- Ok(()) => {\n+ Ok(written) => {\n recently_fetched.insert(key.clone(), Instant::now());\n current_delay = Duration::from_millis(600);\n tracing::info!(item = %fetch_id, ?kind, written, \"reddit import complete\");\ndiff --git a/server/src/reducer.rs b/server/src/reducer.rs\nindex 1352a8f0771add3d868a1b30109b087a2a6dba6f..0c75c85150bb9e5f578bbadf58b3e43f8a80be4b 100644\n--- a/server/src/reducer.rs\n+++ b/server/src/reducer.rs\n@@ -136,8 +136,7 @@ pub struct EntityData {\n #[derive(Debug, Clone, Default, Serialize, Deserialize)]\n pub struct NodeState {\n pub id: ItemId,\n- /// Domain-specific view derived from imported payload (e.g. Reddit title/author).\n- /// Raw JSON lives in [`crate::entity_store::EntityStore`].\n+ /// Ephemeral display view (Reddit title/author/etc.; not event-logged).\n pub data: Option,\n pub children: HashSet,\n pub local_ranking: GroupState,\ndiff --git a/server/src/state.rs b/server/src/state.rs\nindex e44849eec46123072b238afd40a1fdd51ce19bd9..247b9047a57956f76c4b6bef691662101e62a8f9 100644\n--- a/server/src/state.rs\n+++ b/server/src/state.rs\n@@ -1,14 +1,14 @@\n use std::{error::Error, sync::Arc};\n \n use crate::{\n- entity_store::EntityStore,\n event_log::EventLog,\n events::Event,\n+ fetch::now_ms,\n journal::JournalClient,\n path_types::ItemId,\n projection_apply,\n projection_store::ProjectionStore,\n- reddit::{RedditApiConfig, RedditBroker},\n+ reddit::{RedditApiConfig, RedditBroker, REDDIT_CONTENT_TTL},\n reducer::{GlobalTree, VoteData},\n view_log::ViewLog,\n views::ViewStore,\n@@ -45,7 +45,6 @@ pub fn normalize_scope(raw: &str) -> String {\n \n async fn catch_up_projection(\n event_log: &EventLog,\n- entity_store: &EntityStore,\n projection_store: &ProjectionStore,\n ) -> Result<(), crate::event_log::EventLogError> {\n let after_seq = projection_store\n@@ -54,7 +53,7 @@ async fn catch_up_projection(\n \n let stats = event_log\n .replay_from(after_seq, |record| {\n- projection_apply::apply_records(projection_store, entity_store, &[record])\n+ projection_apply::apply_records(projection_store, &[record])\n })\n .await?;\n if after_seq > stats.last_seq {\n@@ -67,22 +66,34 @@ async fn catch_up_projection(\n Ok(())\n }\n \n+fn spawn_content_evictor(projection_store: ProjectionStore) {\n+ tokio::spawn(async move {\n+ let mut interval = tokio::time::interval(std::time::Duration::from_secs(15 * 60));\n+ interval.tick().await;\n+ loop {\n+ interval.tick().await;\n+ let cutoff = now_ms() - REDDIT_CONTENT_TTL.as_millis() as i64;\n+ match projection_store.evict_content_older_than(cutoff) {\n+ Ok(0) => {}\n+ Ok(n) => tracing::info!(evicted = n, \"reddit display content TTL eviction\"),\n+ Err(e) => tracing::warn!(err = %e, \"reddit content TTL eviction failed\"),\n+ }\n+ }\n+ });\n+}\n+\n pub async fn rebuild_projection(\n cfg: &AppConfig,\n ) -> Result> {\n let event_log = EventLog::new(cfg.event_log_path.clone());\n let store_path = format!(\"{}/store\", cfg.data_dir);\n let db = durable::Db::open(std::path::Path::new(&store_path))?;\n- let entity_store = EntityStore::from_db(&db)?;\n let projection_store = ProjectionStore::from_db(&db)?;\n \n- entity_store.reset()?;\n projection_store.reset()?;\n \n let stats = event_log\n- .replay(|record| {\n- projection_apply::apply_records(&projection_store, &entity_store, &[record])\n- })\n+ .replay(|record| projection_apply::apply_records(&projection_store, &[record]))\n .await?;\n let cursor = projection_store.last_applied_event_count()?;\n if cursor != stats.last_seq {\n@@ -132,7 +143,6 @@ pub struct AppState {\n pub cfg: Arc,\n pub event_log: Arc,\n pub view_log: Arc,\n- pub entity_store: EntityStore,\n pub projection_store: ProjectionStore,\n pub views: ViewStore,\n journal: JournalClient,\n@@ -145,7 +155,6 @@ impl AppState {\n let view_log = Arc::new(ViewLog::new(cfg.views_log_path.clone()));\n let store_path = format!(\"{}/store\", cfg.data_dir);\n let db = durable::Db::open(std::path::Path::new(&store_path))?;\n- let entity_store = EntityStore::from_db(&db)?;\n let projection_store = ProjectionStore::from_db(&db)?;\n let views = ViewStore::from_db(&db)?;\n \n@@ -157,22 +166,25 @@ impl AppState {\n }\n views.spawn_worker(view_log.clone());\n \n- catch_up_projection(&event_log, &entity_store, &projection_store).await?;\n+ catch_up_projection(&event_log, &projection_store).await?;\n let next_seq = event_log.last_sequence().await? + 1;\n \n let journal = JournalClient::spawn(\n event_log.clone(),\n- entity_store.clone(),\n projection_store.clone(),\n next_seq,\n );\n- let reddit = RedditBroker::spawn(journal.clone(), RedditApiConfig::from_env());\n+ let reddit = RedditBroker::spawn(\n+ journal.clone(),\n+ projection_store.clone(),\n+ RedditApiConfig::from_env(),\n+ );\n+ spawn_content_evictor(projection_store.clone());\n \n Ok(Self {\n cfg: Arc::new(cfg),\n event_log,\n view_log,\n- entity_store,\n projection_store,\n views,\n journal,\n@@ -248,54 +260,72 @@ impl AppState {\n mod tests {\n use super::{normalize_scope, parse_item_param, AppConfig, AppState};\n use crate::{\n- entity_store::EntityStore, event_log::EventLog, events::Event, path_types::ItemId,\n- projection_apply, projection_store::ProjectionStore,\n+ event_log::EventLog, events::Event, path_types::ItemId, projection_apply,\n+ projection_store::ProjectionStore, reducer::EntityData,\n };\n- use serde_json::json;\n \n fn event_record(seq: u64, event: Event) -> crate::events::EventRecord {\n crate::events::EventRecord::new(seq, crate::events::event_timestamp(&event), event)\n }\n \n #[tokio::test]\n- async fn replay_entity_imported_restores_view() {\n+ async fn rebuild_projection_drops_ephemeral_content() {\n let tmp = tempfile::tempdir().unwrap();\n- let log_path = tmp.path().join(\"events.jsonl\");\n- let log = EventLog::new(log_path.to_string_lossy().into_owned());\n- let payload = json!({\"kind\":\"t5\",\"data\":{\"title\":\"Rust\",\"display_name\":\"rust\"}});\n- let event = Event::EntityImported {\n- id: \"https://reddit.com/r/rust\".into(),\n- ts: 1,\n- payload: payload.clone(),\n- };\n- log.append(&event_record(1, event)).await.unwrap();\n+ let data_dir = tmp.path().to_string_lossy().into_owned();\n+ let log = EventLog::new(format!(\"{data_dir}/events.jsonl\"));\n+ log.append(&event_record(\n+ 1,\n+ Event::NodeEnsured {\n+ id: \"https://reddit.com/r/rust\".into(),\n+ },\n+ ))\n+ .await\n+ .unwrap();\n \n let db = durable::Db::open(tmp.path().join(\"store\")).unwrap();\n- let entity_store = EntityStore::from_db(&db).unwrap();\n let projection_store = ProjectionStore::from_db(&db).unwrap();\n- super::catch_up_projection(&log, &entity_store, &projection_store)\n+ super::catch_up_projection(&log, &projection_store)\n .await\n .unwrap();\n- let tree = projection_store\n- .scope_tree(&ItemId::parse(\"https://reddit.com/r/rust\").unwrap())\n- .unwrap();\n- let node = tree\n- .get(&ItemId::parse(\"https://reddit.com/r/rust\").unwrap())\n- .unwrap();\n- assert_eq!(node.data.as_ref().unwrap().title, \"Rust\");\n- let stored = entity_store\n- .get(&ItemId::parse(\"https://reddit.com/r/rust\").unwrap())\n- .unwrap()\n+ let id = ItemId::parse(\"https://reddit.com/r/rust\").unwrap();\n+ projection_store\n+ .put_ephemeral_content(\n+ &id,\n+ &EntityData {\n+ title: \"Rust\".into(),\n+ author: None,\n+ body_html: None,\n+ thumb_url: None,\n+ image_url: None,\n+ link_url: None,\n+ },\n+ 1,\n+ )\n .unwrap();\n- assert_eq!(stored[\"data\"][\"display_name\"], \"rust\");\n+ assert!(projection_store.load_node(&id).unwrap().unwrap().data.is_some());\n+ drop(projection_store);\n+ drop(db);\n+\n+ super::rebuild_projection(&AppConfig {\n+ data_dir: data_dir.clone(),\n+ event_log_path: format!(\"{data_dir}/events.jsonl\"),\n+ views_log_path: format!(\"{data_dir}/views.jsonl\"),\n+ port: 0,\n+ })\n+ .await\n+ .unwrap();\n+\n+ let db = durable::Db::open(tmp.path().join(\"store\")).unwrap();\n+ let projection_store = ProjectionStore::from_db(&db).unwrap();\n+ let node = projection_store.load_node(&id).unwrap().unwrap();\n+ assert!(node.data.is_none());\n }\n \n #[tokio::test]\n- async fn rebuild_projection_restores_nodes_payloads_and_cursor_from_jsonl() {\n+ async fn rebuild_projection_restores_structure_and_cursor_from_jsonl() {\n let tmp = tempfile::tempdir().unwrap();\n let data_dir = tmp.path().to_string_lossy().into_owned();\n let log = EventLog::new(format!(\"{data_dir}/events.jsonl\"));\n- let payload = json!({\"kind\":\"t5\",\"data\":{\"title\":\"Rust\",\"display_name\":\"rust\"}});\n log.append_batch(&[\n event_record(\n 1,\n@@ -305,16 +335,8 @@ mod tests {\n ),\n event_record(\n 2,\n- Event::EntityImported {\n- id: \"https://reddit.com/r/rust\".into(),\n- ts: 2,\n- payload: payload.clone(),\n- },\n- ),\n- event_record(\n- 3,\n Event::VoteRecorded {\n- ts: 3,\n+ ts: 2,\n a: \"alpha\".into(),\n b: \"beta\".into(),\n ratio_left: 2,\n@@ -328,11 +350,9 @@ mod tests {\n \n {\n let db = durable::Db::open(tmp.path().join(\"store\")).unwrap();\n- let entity_store = EntityStore::from_db(&db).unwrap();\n let projection_store = ProjectionStore::from_db(&db).unwrap();\n projection_apply::apply_records(\n &projection_store,\n- &entity_store,\n &[event_record(\n 1,\n Event::NodeEnsured {\n@@ -352,13 +372,12 @@ mod tests {\n })\n .await\n .unwrap();\n- assert_eq!(stats.applied, 3);\n- assert_eq!(stats.last_seq, 3);\n+ assert_eq!(stats.applied, 2);\n+ assert_eq!(stats.last_seq, 2);\n \n let db = durable::Db::open(tmp.path().join(\"store\")).unwrap();\n- let entity_store = EntityStore::from_db(&db).unwrap();\n let projection_store = ProjectionStore::from_db(&db).unwrap();\n- assert_eq!(projection_store.last_applied_event_count().unwrap(), 3);\n+ assert_eq!(projection_store.last_applied_event_count().unwrap(), 2);\n let tree = projection_store.scope_tree(&ItemId::root()).unwrap();\n let root = tree.get(&ItemId::root()).unwrap();\n assert!(root.children.contains(&ItemId::parse(\"alpha\").unwrap()));\n@@ -366,11 +385,6 @@ mod tests {\n .load_node(&ItemId::parse(\"https://reddit.com/r/stale\").unwrap())\n .unwrap()\n .is_none());\n- let stored = entity_store\n- .get(&ItemId::parse(\"https://reddit.com/r/rust\").unwrap())\n- .unwrap()\n- .unwrap();\n- assert_eq!(stored[\"data\"][\"display_name\"], \"rust\");\n }\n \n #[tokio::test]\n@@ -389,12 +403,9 @@ mod tests {\n \n {\n let db = durable::Db::open(tmp.path().join(\"store\")).unwrap();\n- let entity_store = EntityStore::from_db(&db).unwrap();\n let projection_store = ProjectionStore::from_db(&db).unwrap();\n- // Advance the projection cursor to 2 while the log tail is only 1.\n projection_apply::apply_records(\n &projection_store,\n- &entity_store,\n &[event_record(\n 2,\n Event::NodeEnsured {\n@@ -403,7 +414,7 @@ mod tests {\n )],\n )\n .unwrap();\n- let err = super::catch_up_projection(&log, &entity_store, &projection_store)\n+ let err = super::catch_up_projection(&log, &projection_store)\n .await\n .unwrap_err();\n assert!(err\n@@ -432,10 +443,9 @@ mod tests {\n .unwrap();\n \n let db = durable::Db::open(tmp.path().join(\"store\")).unwrap();\n- let entity_store = EntityStore::from_db(&db).unwrap();\n let projection_store = ProjectionStore::from_db(&db).unwrap();\n \n- super::catch_up_projection(&log, &entity_store, &projection_store)\n+ super::catch_up_projection(&log, &projection_store)\n .await\n .unwrap();\n assert_eq!(projection_store.last_applied_event_count().unwrap(), 1);\n@@ -444,7 +454,7 @@ mod tests {\n let first_edge_total: f64 = first_root.local_ranking.edges.values().sum();\n assert_eq!(first_edge_total, 3.0);\n \n- super::catch_up_projection(&log, &entity_store, &projection_store)\n+ super::catch_up_projection(&log, &projection_store)\n .await\n .unwrap();\n assert_eq!(projection_store.last_applied_event_count().unwrap(), 1);\n@@ -556,9 +566,8 @@ mod tests {\n .unwrap();\n {\n let db = durable::Db::open(tmp.path().join(\"store\")).unwrap();\n- let entity_store = EntityStore::from_db(&db).unwrap();\n let projection_store = ProjectionStore::from_db(&db).unwrap();\n- super::catch_up_projection(&log, &entity_store, &projection_store)\n+ super::catch_up_projection(&log, &projection_store)\n .await\n .unwrap();\n }\n@@ -605,9 +614,8 @@ mod tests {\n .unwrap();\n {\n let db = durable::Db::open(tmp.path().join(\"store\")).unwrap();\n- let entity_store = EntityStore::from_db(&db).unwrap();\n let projection_store = ProjectionStore::from_db(&db).unwrap();\n- super::catch_up_projection(&log, &entity_store, &projection_store)\n+ super::catch_up_projection(&log, &projection_store)\n .await\n .unwrap();\n }\ndiff --git a/server/src/storage_dto.rs b/server/src/storage_dto.rs\nindex de5ed995797ae306d3a71394a4d9d245ffd5771d..9dfb13c53efe4389277625a6ab3bfc18f566a453 100644\n--- a/server/src/storage_dto.rs\n+++ b/server/src/storage_dto.rs\n@@ -3,17 +3,15 @@\n //! Node structure (children, edges, voted pairs, recent votes) is no longer a\n //! single blob — it lives as point-addressable durable collections (see\n //! [`crate::storage_schema`]). This module only defines the small leaf values:\n-//! the derived entity view, raw entity payloads, and individual votes.\n+//! ephemeral entity views and individual votes.\n \n use serde::{Deserialize, Serialize};\n-use serde_json::Value;\n \n use crate::{\n path_types::ItemId,\n reducer::{EntityData, VoteData},\n };\n \n-pub const ENTITY_RECORD_VERSION: u32 = 1;\n pub const VOTE_RECORD_VERSION: u32 = 1;\n pub const ENTITY_DATA_VERSION: u32 = 1;\n \n@@ -29,14 +27,7 @@ impl Versioned {\n }\n }\n \n-pub type StoredEntityRecord = Versioned;\n-\n-#[derive(Debug, Clone, Serialize, Deserialize)]\n-pub struct StoredEntityV1 {\n- pub json: Value,\n-}\n-\n-/// Derived entity view stored at a node's `data` leaf.\n+/// Derived entity view stored at a node's `data` leaf (ephemeral; not logged).\n #[derive(Debug, Clone, Serialize, Deserialize)]\n pub struct StoredEntityDataV1 {\n pub version: u32,\n@@ -63,25 +54,6 @@ pub struct StoredVoteV1 {\n pub thread_tag: String,\n }\n \n-pub fn encode_entity_payload(payload: &Value) -> StoredEntityRecord {\n- Versioned::new(\n- ENTITY_RECORD_VERSION,\n- StoredEntityV1 {\n- json: payload.clone(),\n- },\n- )\n-}\n-\n-pub fn decode_entity_payload(record: StoredEntityRecord) -> Result {\n- if record.version != ENTITY_RECORD_VERSION {\n- return Err(format!(\n- \"unsupported entity record version: {}\",\n- record.version\n- ));\n- }\n- Ok(record.payload.json)\n-}\n-\n pub fn encode_entity_data(data: &EntityData) -> StoredEntityDataV1 {\n StoredEntityDataV1 {\n version: ENTITY_DATA_VERSION,\ndiff --git a/server/src/storage_schema.rs b/server/src/storage_schema.rs\nindex 76bf7bc74a2c5ef4f78678a333b7661778f5b835..bd26e665e084b95b10fdfff091c31e8dc84d07b8 100644\n--- a/server/src/storage_schema.rs\n+++ b/server/src/storage_schema.rs\n@@ -15,7 +15,7 @@ use crate::{\n reducer::{EntityData, GroupState, NodeState, VoteData},\n storage_dto::{\n decode_entity_data, decode_vote, encode_entity_data, encode_vote, parse_stored_id,\n- StoredEntityDataV1, StoredEntityRecord, StoredVoteV1,\n+ StoredEntityDataV1, StoredVoteV1,\n },\n };\n \n@@ -40,17 +40,17 @@ pub struct NodeSchema {\n pub voted_pairs: Map>,\n /// Recent votes, newest at the front (capped on write).\n pub recent_votes: Deque>,\n+ /// When ephemeral Reddit display content was last fetched (ms); absent after eviction.\n+ pub fetched_at: Leaf,\n }\n \n-/// The single database root: nodes, raw payloads, view counts, and per-concern\n-/// metadata maps (cursors and schema versions).\n+/// The single database root: nodes, view counts, and per-concern metadata maps\n+/// (cursors and schema versions).\n #[derive(Durable)]\n #[allow(dead_code)]\n pub struct Store {\n pub nodes: Map,\n pub proj_meta: Map>,\n- pub entities: Map>,\n- pub entity_meta: Map>,\n pub view_counts: Map>,\n pub view_meta: Map>,\n }\n@@ -264,12 +264,17 @@ pub fn vote_writes(\n Ok(())\n }\n \n-/// Reified writes for an imported entity view (node data + path wiring).\n-pub fn entity_view_writes(batch: &mut Batch, id: &ItemId, view: Option<&EntityData>) {\n+/// Reified writes for ephemeral Reddit display content (not event-logged).\n+pub fn entity_content_writes(batch: &mut Batch, id: &ItemId, view: &EntityData, fetched_at: i64) {\n ensure_path_writes(batch, id);\n- if let Some(view) = view {\n- batch.write(node(id).data().set(&encode_entity_data(view)));\n- }\n+ batch.write(node(id).data().set(&encode_entity_data(view)));\n+ batch.write(node(id).fetched_at().set(&fetched_at));\n+}\n+\n+/// Clear cached display content for one node (structure/votes are untouched).\n+pub fn entity_content_clear_writes(batch: &mut Batch, id: &ItemId) {\n+ batch.write(node(id).data().delete());\n+ batch.write(node(id).fetched_at().delete());\n }\n \n #[cfg(test)]\ndiff --git a/test/reddit_import.clj b/test/reddit_import.clj\nindex b476488526252c13fd73bdda76e5201678e4a714..6d8c5bca7ebad0b5abfddecd4ea48cc09d738ebe 100644\n--- a/test/reddit_import.clj\n+++ b/test/reddit_import.clj\n@@ -59,9 +59,10 @@\n \"curl\" \"-sf\" browse-url))\n log (slurp (io/file log-path))]\n (is (str/includes? after \"The Rust Programming Language\"))\n- (is (str/includes? log \"\\\"type\\\":\\\"entity_imported\\\"\"))\n- (is (str/includes? log \"\\\"subscribers\\\":350000\"))\n- (is (str/includes? log \"\\\"display_name\\\":\\\"rust\\\"\")))\n+ (is (str/includes? log \"\\\"type\\\":\\\"node_ensured\\\"\"))\n+ (is (not (str/includes? log \"\\\"subscribers\\\"\")))\n+ (is (not (str/includes? log \"\\\"display_name\\\"\")))\n+ (is (not (str/includes? log \"entity_imported\"))))\n (let [children-sse (curl-fetch-ui-sse app-base \"reddit.com/r/rust\" \"children\")]\n (is (zero? (:exit children-sse)) \"POST /ui fetch_entity (children) SSE succeeds\")\n (is (str/includes? (:out children-sse) \"Idiomorph.morph\"))\n@@ -71,10 +72,12 @@\n log2 (slurp (io/file log-path))]\n (is (str/includes? after-children \"Announcing Rust 1.99\"))\n (is (str/includes? after-children \"Unranked\"))\n- (is (str/includes? log2 \"announcing_rust_199\")))))\n+ (is (str/includes? log2 \"\\\"type\\\":\\\"node_ensured\\\"\"))\n+ (is (str/includes? log2 \"/comments/\"))\n+ (is (not (str/includes? log2 \"\\\"selftext\\\"\"))))))\n \n (deftest reddit-fetch-via-mock-api\n- (testing \"Fetch more queues import; event log stores full payload; page shows title\"\n+ (testing \"Fetch caches display content ephemerally; log records structure only\"\n (let [root (repo-root)\n fixtures (mock-reddit/fixtures-dir root)\n data-dir (.getAbsolutePath\n","role":"user"}],"model":"~anthropic/claude-sonnet-latest"}