{"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[1531154d] dequeue -> vec\n\nSide A — unified diff (full patch):\ndiff --git a/server/src/projection_apply.rs b/server/src/projection_apply.rs\nindex 9c8990a8af927f35d3344c8d0872a516aba56b86..ad404bacb8bcdd5ae0e682cff97f974fd44528ea 100644\n--- a/server/src/projection_apply.rs\n+++ b/server/src/projection_apply.rs\n@@ -6,8 +6,6 @@\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 event_log::EventLogError,\n events::{Event, EventRecord},\n@@ -44,7 +42,6 @@ pub fn apply_records(\n \n let db = projection_store.db();\n let mut batch = db.batch();\n- let mut vote_parents: BTreeSet = BTreeSet::new();\n let mut last_seq = 0u64;\n \n for record in records {\n@@ -70,7 +67,6 @@ pub fn apply_records(\n *ts,\n )\n .map_err(|e| EventLogError::Apply(e.to_string()))?;\n- vote_parents.insert(parent);\n }\n Event::NodeEnsured { id } => {\n let parsed = parse_event_id(id)?;\n@@ -85,11 +81,5 @@ pub fn apply_records(\n .commit_with(durable::Durability::DisableWal)\n .map_err(|e| EventLogError::Apply(e.to_string()))?;\n \n- for parent in vote_parents {\n- projection_store\n- .trim_recent_votes(&parent)\n- .map_err(|e| EventLogError::Apply(e.to_string()))?;\n- }\n-\n Ok(())\n }\ndiff --git a/server/src/projection_store.rs b/server/src/projection_store.rs\nindex 8576d671f351004426207894ac35594ddb0f70cf..9a8953d010029d3639dc3987687554bab8b7663e 100644\n--- a/server/src/projection_store.rs\n+++ b/server/src/projection_store.rs\n@@ -18,7 +18,7 @@ use crate::{\n \n const PROJECTION_CURSOR_KEY: &str = \"cursor\";\n const PROJECTION_SCHEMA_KEY: &str = \"schema_version\";\n-const PROJECTION_SCHEMA_VERSION: u64 = 3;\n+const PROJECTION_SCHEMA_VERSION: u64 = 4;\n \n #[derive(Debug, thiserror::Error)]\n pub enum ProjectionStoreError {\n@@ -142,16 +142,6 @@ impl ProjectionStore {\n Ok(tree)\n }\n \n- /// Cap a node's recent-vote window after applying votes (best-effort, blind).\n- pub(crate) fn trim_recent_votes(&self, parent: &ItemId) -> Result<(), ProjectionStoreError> {\n- node(parent).recent_votes().truncate_back(\n- &self.db,\n- crate::storage_schema::RECENT_VOTES_CAP,\n- Durability::DisableWal,\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,\ndiff --git a/server/src/reducer.rs b/server/src/reducer.rs\nindex 0c75c85150bb9e5f578bbadf58b3e43f8a80be4b..759918b8c0eb8f8bf1ed0911d8877adaa55c8ea6 100644\n--- a/server/src/reducer.rs\n+++ b/server/src/reducer.rs\n@@ -1,4 +1,4 @@\n-use std::collections::{HashMap, HashSet, VecDeque};\n+use std::collections::{HashMap, HashSet};\n \n use serde::{Deserialize, Serialize};\n \n@@ -52,7 +52,7 @@ pub struct GroupState {\n pub idx_to_item: Vec,\n pub edges: HashMap<(usize, usize), f64>,\n pub voted_pairs: HashSet<(usize, usize)>,\n- pub recent_votes: VecDeque,\n+ pub recent_votes: Vec,\n }\n \n impl GroupState {\n@@ -62,7 +62,7 @@ impl GroupState {\n idx_to_item: Vec::new(),\n edges: HashMap::new(),\n voted_pairs: HashSet::new(),\n- recent_votes: VecDeque::with_capacity(200),\n+ recent_votes: Vec::new(),\n }\n }\n \n@@ -111,10 +111,7 @@ impl GroupState {\n self.add_edge_weight(b_idx, a_idx, w_a);\n self.add_edge_weight(a_idx, b_idx, w_b);\n \n- self.recent_votes.push_front(vote);\n- while self.recent_votes.len() > 200 {\n- self.recent_votes.pop_back();\n- }\n+ self.recent_votes.push(vote);\n }\n }\n \ndiff --git a/server/src/storage_dto.rs b/server/src/storage_dto.rs\nindex 9dfb13c53efe4389277625a6ab3bfc18f566a453..3fd6db5cb909ac4896bd8a3ecace796de5f08781 100644\n--- a/server/src/storage_dto.rs\n+++ b/server/src/storage_dto.rs\n@@ -39,7 +39,7 @@ pub struct StoredEntityDataV1 {\n pub link_url: Option,\n }\n \n-/// One vote stored in a node's `recent_votes` deque.\n+/// One vote stored in a node's `recent_votes` list.\n #[derive(Debug, Clone, Serialize, Deserialize)]\n pub struct StoredVoteV1 {\n pub version: u32,\ndiff --git a/server/src/storage_schema.rs b/server/src/storage_schema.rs\nindex bd26e665e084b95b10fdfff091c31e8dc84d07b8..5d2bb1d56927fb61c7c6d2d8602bd6882327f862 100644\n--- a/server/src/storage_schema.rs\n+++ b/server/src/storage_schema.rs\n@@ -2,13 +2,13 @@\n //! durable collections instead of one blob per node.\n //!\n //! A vote updates a handful of keys: a few edge-weight merges, a voted-pair flag,\n-//! a recent-vote deque push, and child-link set entries. The in-memory\n+//! a recent-vote list append, and child-link set entries. The in-memory\n //! [`crate::reducer::GroupState`] is reconstructed from these keys on read for\n //! rank-centrality.\n \n use std::collections::{BTreeSet, HashMap, HashSet};\n \n-use durable::{Batch, Db, Deque, Durable, Leaf, Map, Sum};\n+use durable::{Batch, Db, Durable, Leaf, List, Map, Sum};\n \n use crate::{\n path_types::ItemId,\n@@ -38,8 +38,8 @@ pub struct NodeSchema {\n pub edges: Map>,\n /// Voted pairs `(min, max) -> true`.\n pub voted_pairs: Map>,\n- /// Recent votes, newest at the front (capped on write).\n- pub recent_votes: Deque>,\n+ /// Recent votes, append-only oldest-first (cap applied on read).\n+ pub recent_votes: List>,\n /// When ephemeral Reddit display content was last fetched (ms); absent after eviction.\n pub fetched_at: Leaf,\n }\n@@ -55,7 +55,7 @@ pub struct Store {\n pub view_meta: Map>,\n }\n \n-/// Cap on the per-node recent-vote window (matches the in-memory reducer).\n+/// Max recent votes returned when loading a node (query-time cap only).\n pub const RECENT_VOTES_CAP: u64 = 200;\n \n fn id_key(id: &ItemId) -> String {\n@@ -148,11 +148,14 @@ fn build_group_state(\n }\n }\n \n- // Deque is front=newest; in-memory VecDeque is also front=newest.\n- let mut recent_votes = std::collections::VecDeque::new();\n- for stored in np.recent_votes().iter(db)? {\n- recent_votes.push_back(decode_vote(stored).map_err(durable::Error::Deserialize)?);\n- }\n+ // List is index order (oldest first); keep the newest RECENT_VOTES_CAP entries.\n+ let stored = np.recent_votes().iter(db)?;\n+ let cap = RECENT_VOTES_CAP as usize;\n+ let start = stored.len().saturating_sub(cap);\n+ let recent_votes = stored[start..]\n+ .iter()\n+ .map(|s| decode_vote(s.clone()).map_err(durable::Error::Deserialize))\n+ .collect::, _>>()?;\n \n Ok(GroupState {\n item_to_idx,\n@@ -248,7 +251,7 @@ pub fn vote_writes(\n };\n batch.write(pnode.voted_pairs().key(&(lo, hi)).set(&true));\n \n- // Recent votes (newest at front).\n+ // Recent votes (append-only; cap on read).\n let stored = encode_vote(&VoteData {\n ts,\n a: a_id,\n@@ -260,7 +263,7 @@ pub fn vote_writes(\n delegate: None,\n thread_tag: \"default\".to_string(),\n });\n- batch.push_front(&pnode.recent_votes(), &stored)?;\n+ batch.push(&pnode.recent_votes(), &stored)?;\n Ok(())\n }\n \n@@ -314,6 +317,35 @@ mod tests {\n assert!(load_node_state(&db, &parent).unwrap().is_none());\n }\n \n+ #[test]\n+ fn load_caps_recent_votes_at_query_time() {\n+ let dir = tempfile::tempdir().unwrap();\n+ let db = Db::open(dir.path()).unwrap();\n+ let parent = ItemId::root();\n+\n+ let mut batch = db.batch();\n+ for i in 0..RECENT_VOTES_CAP + 10 {\n+ vote_writes(&mut batch, &parent, \"alpha\", \"beta\", 1, 0, i as i64).unwrap();\n+ }\n+ batch.commit().unwrap();\n+\n+ assert_eq!(\n+ node(&parent).recent_votes().len(&db).unwrap(),\n+ RECENT_VOTES_CAP + 10\n+ );\n+\n+ let node_state = load_node_state(&db, &parent).unwrap().unwrap();\n+ assert_eq!(node_state.local_ranking.recent_votes.len(), RECENT_VOTES_CAP as usize);\n+ assert_eq!(\n+ node_state.local_ranking.recent_votes.first().map(|v| v.ts),\n+ Some(10)\n+ );\n+ assert_eq!(\n+ node_state.local_ranking.recent_votes.last().map(|v| v.ts),\n+ Some(RECENT_VOTES_CAP as i64 + 9)\n+ );\n+ }\n+\n #[test]\n fn missing_node_is_none() {\n let dir = tempfile::tempdir().unwrap();\n\n\nSide B — contributor: tommy-mor\nSide B — commit message:\n[595b3850] Fix star-topology ranking by using degree-based d_max (#146).\n\nA pure forward star at the default `>` ratio (2:1) produced uniform 1/3\nscores, and the alphabetical-fallback sort placed the unambiguous winner\nlast. Root cause: `compute_scores_from_edges` divided by the max sum of\npairwise-normalized weights, so every node ended up with P_ii = 0 — a\nbipartite Markov chain whose power iteration oscillated and, after the\nconfigured even iteration count, returned to the uniform initial state.\n\nSwitch the divisor to the unweighted max neighbor degree, matching the\ncanonical Rank Centrality definition in Negahban–Oh–Shah 2012 §3.1\n(arXiv:1209.1688, eq. defP and the d_max definition in §6). This gives\nevery non-saturated node a positive self-loop, makes the chain aperiodic,\nand converges the star to π_zebra = 1/2, π_alpha = π_beta = 1/4.\n\nAdd Rust regression test and a Clojure test that drives the sorterc\nbinary against four .sorter fixtures (star, inverse star, chain, cycle).\n\nCo-Authored-By: Claude Opus 4.7 (1M context) \n\nSide B — unified diff (full patch):\ndiff --git a/server/src/ranking.rs b/server/src/ranking.rs\nindex 3710c9f64437f5bef3b2121905b6f3bcb7611047..38e6d09b4370e5f8cbae09c0e5760b4e7f1ef7db 100644\n--- a/server/src/ranking.rs\n+++ b/server/src/ranking.rs\n@@ -1,4 +1,4 @@\n-use std::collections::HashMap;\n+use std::collections::{HashMap, HashSet};\n \n use crate::path_types::ItemId;\n use crate::reducer::GroupState;\n@@ -143,23 +143,35 @@ fn compute_scores_from_edges(n: usize, edges: impl Iterator 0 for every non-maximum-degree node, and for max-degree\n+ // nodes whenever any neighbor weight is below 1 (i.e. not a unanimous\n+ // loss). Without this, regular comparison graphs (e.g. a pure star at\n+ // ratio 2:1) produce a bipartite chain that oscillates instead of\n+ // converging — see issue #146.\n let mut out_edges: Vec> = vec![Vec::new(); n];\n- let mut out_deg: Vec = vec![0.0; n];\n+ let mut neighbors: Vec> = vec![HashSet::new(); n];\n \n for ((src, dst), w) in &normalized {\n out_edges[*src].push((*dst, *w));\n- out_deg[*src] += w;\n+ neighbors[*src].insert(*dst);\n+ neighbors[*dst].insert(*src);\n }\n \n- let mut max_out = 0.0f64;\n- for &d in &out_deg {\n- if d > max_out {\n- max_out = d;\n- }\n- }\n- if max_out <= 1e-12 {\n+ let weight_sum: Vec = out_edges\n+ .iter()\n+ .map(|es| es.iter().map(|(_, w)| *w).sum())\n+ .collect();\n+ let d_max = neighbors.iter().map(|s| s.len()).max().unwrap_or(0);\n+ if d_max == 0 {\n return vec![1.0 / n as f64; n];\n }\n+ let d_max_f = d_max as f64;\n \n let mut scores = vec![1.0 / n as f64; n];\n let mut next = vec![0.0f64; n];\n@@ -167,14 +179,14 @@ fn compute_scores_from_edges(n: usize, edges: impl Iterator` ratio (2:1).\n+ /// Under the old (sum-of-weights) divisor every node had P_ii = 0 and the\n+ /// chain was bipartite; power iteration oscillated and returned the\n+ /// uniform initial distribution after an even number of steps. Using the\n+ /// paper's degree-based d_max gives every node a positive self-loop and\n+ /// the chain converges to the correct stationary distribution.\n+ #[test]\n+ fn star_topology_winner_at_top_via_subset() {\n+ let mut g = mk_group();\n+ g.apply_vote(vote(1, \"zebra\", \"alpha\", 2, 1));\n+ g.apply_vote(vote(2, \"zebra\", \"beta\", 2, 1));\n+\n+ let mut items: Vec<(usize, String)> = g\n+ .idx_to_item\n+ .iter()\n+ .enumerate()\n+ .map(|(i, it)| (i, it.as_str().to_string()))\n+ .collect();\n+ items.sort_by(|a, b| a.1.cmp(&b.1));\n+ let idxs: Vec = items.iter().map(|(i, _)| *i).collect();\n+\n+ let ranked = ranked_items_subset(&g, &idxs, 10000, 1e-8);\n+ for r in &ranked {\n+ eprintln!(\"{}: {}\", r.item.as_str(), r.score);\n+ }\n+ assert_eq!(\n+ ranked[0].item.as_str(),\n+ \"https://slug.social/zebra\",\n+ \"zebra won both votes and should rank #1\"\n+ );\n+ }\n+\n #[test]\n fn group_ranking_cache_dirty_flow() {\n let mut g = mk_group();\ndiff --git a/test/fixtures/ranking/chain.sorter b/test/fixtures/ranking/chain.sorter\nnew file mode 100644\nindex 0000000000000000000000000000000000000000..912a96bdc08f631be27f3c9afc7e05004a2457c0\n--- /dev/null\n+++ b/test/fixtures/ranking/chain.sorter\n@@ -0,0 +1,10 @@\n+#t3\n+\n+~/t3/a { head of chain }\n+~/t3/b { middle }\n+~/t3/c { tail }\n+\n+{ a > b }\n+~/t3/a > ~/t3/b\n+{ b > c }\n+~/t3/b > ~/t3/c\ndiff --git a/test/fixtures/ranking/cycle.sorter b/test/fixtures/ranking/cycle.sorter\nnew file mode 100644\nindex 0000000000000000000000000000000000000000..771731ae176e5d77e00ab89767ff2d7465bb7c6b\n--- /dev/null\n+++ b/test/fixtures/ranking/cycle.sorter\n@@ -0,0 +1,12 @@\n+#t4\n+\n+~/t4/a { node a }\n+~/t4/b { node b }\n+~/t4/c { node c }\n+\n+{ a > b }\n+~/t4/a > ~/t4/b\n+{ b > c }\n+~/t4/b > ~/t4/c\n+{ c > a }\n+~/t4/c > ~/t4/a\ndiff --git a/test/fixtures/ranking/star.sorter b/test/fixtures/ranking/star.sorter\nnew file mode 100644\nindex 0000000000000000000000000000000000000000..135c9f9097d57b73c7ab18fac737ed3598d76fbe\n--- /dev/null\n+++ b/test/fixtures/ranking/star.sorter\n@@ -0,0 +1,11 @@\n+#repro\n+\n+~/repro/zebra { winner — beats both others }\n+~/repro/alpha { loser — alphabetically first }\n+~/repro/beta { loser — alphabetically middle }\n+\n+{ zebra beats alpha }\n+~/repro/zebra > ~/repro/alpha\n+\n+{ zebra beats beta }\n+~/repro/zebra > ~/repro/beta\ndiff --git a/test/fixtures/ranking/star_inverse.sorter b/test/fixtures/ranking/star_inverse.sorter\nnew file mode 100644\nindex 0000000000000000000000000000000000000000..dab842fa924e5124865ee216b9565f6c7471c812\n--- /dev/null\n+++ b/test/fixtures/ranking/star_inverse.sorter\n@@ -0,0 +1,11 @@\n+#t2\n+\n+~/t2/win { source of incoming edges (loses both) }\n+~/t2/loss-a { winner }\n+~/t2/loss-b { winner }\n+\n+{ loss-a beats win }\n+~/t2/loss-a > ~/t2/win\n+\n+{ loss-b beats win }\n+~/t2/loss-b > ~/t2/win\ndiff --git a/test/ranking.clj b/test/ranking.clj\nnew file mode 100644\nindex 0000000000000000000000000000000000000000..e1358783a84a264ee633bd79151ba29750b717cf\n--- /dev/null\n+++ b/test/ranking.clj\n@@ -0,0 +1,74 @@\n+(ns test.ranking\n+ \"Drives sorterc on .sorter fixtures and asserts ranking properties.\n+\n+ Regression coverage for issue #146 — pure forward star at default ratio\n+ (2:1 for `>`) used to produce tied uniform scores because the random walk\n+ on the normalized edge weights was bipartite. Fixed by switching to the\n+ degree-based d_max from Negahban–Oh–Shah rank centrality (§3.1).\"\n+ (:require [clojure.test :refer [deftest is testing]]\n+ [babashka.process :as p]\n+ [cheshire.core :as json]\n+ [clojure.java.io :as io]))\n+\n+(def sorterc-bin\n+ \"Path to the locally-built sorterc binary. Builds on demand if missing.\"\n+ (let [dbg \"target/debug/sorterc\"\n+ release \"target/release/sorterc\"]\n+ (cond\n+ (.exists (io/file release)) release\n+ (.exists (io/file dbg)) dbg\n+ :else\n+ (do (println \"building sorterc…\")\n+ (let [r (p/shell {:out :string :err :string :continue true}\n+ \"cargo build -p sorterc\")]\n+ (when-not (zero? (:exit r))\n+ (throw (ex-info \"cargo build -p sorterc failed\"\n+ {:stderr (:err r)}))))\n+ dbg))))\n+\n+(defn compile-sorter [fixture-path]\n+ (let [{:keys [out exit]} (p/shell {:out :string :err :string :continue true}\n+ sorterc-bin \"compile\" fixture-path)]\n+ (when-not (zero? exit)\n+ (throw (ex-info \"sorterc exit nonzero\" {:fixture fixture-path :out out})))\n+ (json/parse-string out true)))\n+\n+(defn first-component-ranking [result]\n+ (-> result :rankings first :components first :ranking))\n+\n+(defn item-leaf [item]\n+ (last (clojure.string/split item #\"/\")))\n+\n+(deftest chain-ranks-head-first\n+ (let [ranking (first-component-ranking (compile-sorter \"test/fixtures/ranking/chain.sorter\"))\n+ names (mapv (comp item-leaf :item) ranking)]\n+ (is (= [\"a\" \"b\" \"c\"] names)\n+ \"chain a>b>c should rank a, b, c in order\")\n+ (is (apply > (map :score ranking))\n+ \"scores should attenuate strictly down the chain\")))\n+\n+(deftest inverse-star-puts-winners-on-top\n+ (let [ranking (first-component-ranking (compile-sorter \"test/fixtures/ranking/star_inverse.sorter\"))\n+ names (mapv (comp item-leaf :item) ranking)]\n+ (is (= \"win\" (last names))\n+ \"the item that lost to both others should be ranked last\")))\n+\n+(deftest cycle-produces-uniform-scores\n+ (let [ranking (first-component-ranking (compile-sorter \"test/fixtures/ranking/cycle.sorter\"))\n+ scores (map :score ranking)]\n+ (is (every? #(< (Math/abs (- % 1/3)) 1e-3) scores)\n+ \"a perfectly symmetric 3-cycle should give every node ~1/3\")))\n+\n+(deftest star-topology-winner-at-top\n+ ;; Issue #146 regression: source-only star at default `>` ratio (2:1).\n+ ;; Pre-fix produced uniform 1/3 scores; alphabetical fallback put the\n+ ;; unambiguous winner at the bottom. Post-fix the chain is aperiodic and\n+ ;; converges to π_zebra = 1/2, π_alpha = π_beta = 1/4.\n+ (let [ranking (first-component-ranking (compile-sorter \"test/fixtures/ranking/star.sorter\"))\n+ names (mapv (comp item-leaf :item) ranking)\n+ by-name (into {} (map (juxt (comp item-leaf :item) :score) ranking))]\n+ (is (= \"zebra\" (first names))\n+ \"zebra won both votes and should rank #1\")\n+ (is (< (Math/abs (- (by-name \"zebra\") 0.5)) 1e-3))\n+ (is (< (Math/abs (- (by-name \"alpha\") 0.25)) 1e-3))\n+ (is (< (Math/abs (- (by-name \"beta\") 0.25)) 1e-3))))\n","role":"user"}],"model":"openai/gpt-chat-latest"}