constitution · epochs · watch · epoch 3

comparison

c_a896b2dc05d5 (tommy-mor) vs c_48fcbcde8f88 (tommy-mor)

download prompt · raw event · cmp_44d9ec8f5eaf26

council reasoning

~anthropic/claude-sonnet-latest · winner A · 6:4 · permalink

Side A changes the durable storage schema (Deque -> List) with a real design rationale (avoiding a costly truncate-on-write, moving the cap to read-time), removes now-dead code paths, bumps schema version, and adds a targeted test validating the new capping behavior—this is substantive production logic. Side B is a pure test-suite refactor (deduplicating HTTP/OAuth helpers across bb test scripts) which improves maintainability but has no runtime/product impact.

~x-ai/grok-latest · winner A · 3:1 · permalink

Commit A redesigns core projection storage (Deque→List, trim-on-write→cap-on-read, schema bump, reducer/apply path cleanup) and adds a regression test, which is lasting production behavior. Commit B only consolidates duplicated Babashka test helpers/OAuth fixtures without changing product semantics, so it is useful hygiene but lower lasting value.

openai/gpt-chat-latest · winner A · 4:1 · permalink

Side A changes the project's storage design by replacing the durable recent-vote deque with an append-only list, removing per-apply trimming, moving the cap to query time, bumping the schema version, and adding a regression test that verifies only the newest 200 votes are loaded. Side B is a useful refactoring of the integration test infrastructure (shared HTTP/OAuth helpers, common build/env functions, and reduced duplication), but it primarily improves test maintainability rather than changing core project behavior.

sides

A — c_a896b2dc05d5 (tommy-mor)

message

[1531154d] dequeue -> vec

diff preview

diff --git a/server/src/projection_apply.rs b/server/src/projection_apply.rs
index 9c8990a8af927f35d3344c8d0872a516aba56b86..ad404bacb8bcdd5ae0e682cff97f974fd44528ea 100644
--- a/server/src/projection_apply.rs
+++ b/server/src/projection_apply.rs
@@ -6,8 +6,6 @@
 //! batch as the (non-idempotent) edge merges guarantees exactly-once application
 //! across replay.
 
-use std::collections::BTreeSet;
-
 use crate::{
     event_log::EventLogError,
     events::{Event, EventRecord},
@@ -44,7 +42,6 @@ pub fn apply_records(
 
     let db = projection_store.db();
     let mut batch = db.batch();
-    let mut vote_parents: BTreeSet<ItemId> = BTreeSet::new();
     let mut last_seq = 0u64;
 
     for record in records {
@@ -70,7 +67,6 @@ pub fn apply_records(
                     *ts,
                 )
                 .map_err(|e| EventLogError::Apply(e.to_string()))?;
-                vote_parents.insert(parent);
             }
             Event::NodeEnsured { id } => {
                 let parsed = parse_event_id(id)?;
@@ -85,11 +81,5 @@ pub fn apply_records(
         .commit_with(durable::Durability::DisableWal)
         .map_err(|e| EventLogError::Apply(e.to_string()))?;
 
-    for parent in vote_parents {
-        projection_store
-            .trim_recent_votes(&parent)
-            .map_err(|e| EventLogError::Apply(e.to_string()))?;
-    }
-
     Ok(())
 }
diff --git a/server/src/projection_store.rs b/server/src/projection_store.rs
index 8576d671f351004426207894ac35594ddb0f70cf..9a8953d010029d3639dc3987687554bab8b7663e 100644
--- a/server/src/projection_store.rs
+++ b/server/src/projection_store.rs
@@ -18,7 +18,7 @@ use crate::{
 
 const PROJECTION_CURSOR_KEY: &str = "cursor";
 const PROJECTION_SCHEMA_KEY: &str = "schema_version";
-const PROJECTION_SCHEMA_VERSION: u64 = 3;
+const PROJECTION_SCHEMA_VERSION: u64 = 4;
 
 #[derive(Debug, thiserror::Error)]
 pub enum ProjectionStoreError {
@@ -142,16 +142,6 @@ impl ProjectionStore {
         Ok(tree)
     }
 
-    /// Cap a node's recent-vote window after applying votes (best-effort, blind).
-    pub(crate) fn trim_recent_votes(&self, parent: &ItemId) -> Result<(), ProjectionStoreError> {
-        node(parent).recent_votes().truncate_back(
-            &self.db,
-            crate::storage_schema::RECENT_VOTES_CAP,
-            Durability::DisableWal,
-        )?;
-        Ok(())
-    }
-
     /// Cache Reddit display content outside the event log (must be evicted per policy).
     pub fn put_ephemeral_content(
         &self,
diff --git a/server/src/reducer.rs b/server/src/reducer.rs
index 0c75c85150bb9e5f578bbadf58b3e43f8a80be4b..759918b8c0eb8f8bf1ed0911d8877adaa55c8ea6 100644
--- a/server/src/reducer.rs
+++ b/server/src/reducer.rs
@@ -1,4 +1,4 @@
-use std::collections::{HashMap, HashSet, VecDeque};
+use std::collections::{HashMap, HashSet};
 
 use serde::{Deserialize, Serialize};
 
@@ -52,7 +52,7 @@ pub struct GroupState {
     pub idx_to_item: Vec<ItemId>,
     pub edges: HashMap<(usize, usize), f64>,
     pub voted_pairs: HashSet<(usize, usize)>,
-    pub recent_votes: VecDeque<VoteData>,
+    pub recent_votes: Vec<VoteData>,
 }
 
 impl GroupState {
@@ -62,7 +62,7 @@ impl GroupState {
             idx_to_item: Vec::new(),
             edges: HashMap::new(),
             voted_pairs: HashSet::new(),
-            recent_votes: VecDeque::with_capacity(200),
+            recent_votes: Vec::new(),
         }
     }
 
@@ -111,10 +111,7 @@ impl GroupState {
         self.add_edge_weight(b_idx, a_idx, w_a);
         self.add_edge_weight(a_idx, b_idx, w_b);
 
-        self.recent_votes.push_front(vote);
-        while self.recent_votes.len() > 200 {
-            self.recent_votes.pop_back();
-        }
+        self.recent_votes.push(vote);
     }
 }
 
diff --git a/server/src/storage_dto.rs b/server/src/storage_dto.rs
index 9dfb13c53efe4389277625a6ab3bfc18f566a453..3fd6db5cb909ac4896bd8a3ecace796de5f08781 100644
--- a/server/src/storage_dto.rs
+++ b/server/src/storage_dto.rs
@@ -39,7 +39,7 @@ pub struct StoredEntityDataV1 {
     pub link_url: Option<String>,
 }
 
-/// One vote stored in a node's `recent_votes` deque.
+/// One vote stored in a node's `recent_votes` list.
 #[derive(Debug, Clone, Serialize, Deserialize)]
 pub struct StoredVoteV1 {
     pub version: u32,
diff --git a/server/src/storage_schema.rs b/server/src/storage_schema.rs
index bd26e665e084b95b10fdfff091c31e8dc84d07b8..5d2bb1d56927fb61c7c6d2d8602bd6882327f862 100644
--- a/server/src/storage_schema.rs
+++ b/server/src/storage_schema.rs
@@ -2,13 +2,13 @@
 //! durable collections instead of one blob per node.
 //!
 //! A vote updates a handful of keys: a few edge-weight merges, a voted-pair flag,
-//! a recent-vote deque push, and child-link set entries. The in-memory
+//! a recent-vote list append, and child-link set entries. The in-memory
 //! [`crate::reducer::GroupState`] is reconstructed from these keys on read for
 //! rank-centrality.
 
 use std::collections::{BTreeSet, HashMap, HashSet};
 
-use durable::{Batch, Db, Deque, Durable, Leaf, Map, Sum};
+use durable::{Batch, Db, Durable, Leaf, List, Map, Sum};
 
 use crate::{
     path_types::ItemId,
@@ -38,8 +38,8 @@ pub struct NodeSchema {
     pub edges: Map<EdgeKey, Sum<f64>>,
     /// Voted pairs `(min, max) -> true`.
     pub voted_pairs: Map<PairKey, Leaf<bool>>,
-    /// Recent votes, newest at the front (capped on write).
-    pub recent_votes: Deque<Leaf<StoredVoteV1>>,
+    /// Recent votes, append-only oldest-first (cap applied on read).
+    pub recent_votes: List<Leaf<StoredVoteV1>>,
     /// When ephemeral Reddit display content was last fetched (ms); absent after eviction.
     pub fetched_at: Leaf<i64>,
 }
@@ -55,7 +55,7 @@ pub struct Store {
     pub view_meta: Map<String, Leaf<u64>>,
 }
 
-/// Cap on the per-node recent-vote window (matches the in-memory reducer).
+/// Max recent votes returned when loading a node (query-time cap only).
 pub const RECENT_VOTES_CAP: u64 = 200;
 
 fn id_key(id: &ItemId) -> String {
@@ -148,11 +148,14 @@ fn build_group_state(
         }
     }
 
-    // Deque is front=newest; in-memory VecDeque is also front=newest.
-    let mut recent_votes = std::collections::VecDeque::new();
-    for stored in np.recent_votes().iter(db)? {
-        recent_votes.push_back(decode_vote(stored).map_err(durable::Error::Deserialize)?);
-    }
+    // List is index order (oldest first); keep the newest RECENT_VOTES_CAP entries.
+    let stored = np.recent_votes().iter(db)?;
+    let cap = RECENT_VOTES_CAP as usize;
+    let start = stored.len().saturating_sub(cap);
+    let recent_votes = stored[start..]
+        .iter()
+        .map(|s| decode_vote(s.clone()).map_err(durable::Error::Deserialize))
+        .collect::<Result<Vec<_>, _>>()?;
 
     Ok(GroupState {
         item_to_idx,
@@ -248,7 +251,7 @@ pub fn vote_writes(
     };
     batch.write(pnode.voted_pairs().key(&(lo, hi)).set(&true));
 
-    // Recent votes (newest at front).
+    // Recent votes (append-only; cap on read).
     let stored = encode_vote(&VoteData {
         ts,
         a: a_id,
@@ -260,7 +263,7 @@ pub fn vote_writes(
         delegate: None,
         thread_tag: "default".to_string(),
     });
-    batch.push_front(&pnode.recent_votes(), &stored)?;
+    batch.push(&pnode.recent_votes(), &stored)?;
     Ok(())
 }
 
@@ -314,6 +317,35 @@ mod tests {
         assert!(load_node_state(&db, &parent).unwrap().is_none());
     }
 
+    #[test]
+    fn load_caps_recent_votes_at_query_time() {
+        let dir = tempfile::tempdir().unwrap();
+        let db = Db::open(dir.path()).unwrap();
+        let parent = ItemId::root();
+
+        let mut batch = db.batch();
+        for i in 0..RECENT_VOTES_CAP + 10 {
+            vote_writes(&mut batch, &parent, "alpha", "beta", 1, 0, i as i64).unwrap();
+        }
+        batch.commit().unwrap();
+
+        assert_eq!(
+            node(&parent).recent_votes().len(&db).unwrap(),
+            RECENT_VOTES_CAP + 10
+        );
+
+        let node_state = load_node_state(&db, &parent).unwrap().unwrap();
+        assert_eq!(node_state.local_ranking.recent_votes.len(), RECENT_VOTES_CAP as usize);
+        assert_eq!(
+            node_state.local_ranking.recent_votes.first().map(|v| v.ts),
+            Some(10)
+        );
+        assert_eq!(
+            node_state.local_ranking.recent_votes.last().map(|v| v.ts),
+            Some(RECENT_VOTES_CAP as i64 + 9)
+        );
+    }
+
     #[test]
     fn missing_node_is_none() {
         let dir = tempfile::tempdir().unwrap();

download full diff A

B — c_48fcbcde8f88 (tommy-mor)

message

[b32c92f2] consolidated shared functions in tests (composer 2 fast)

diff preview

diff --git a/test/auth.bb b/test/auth.bb
index a67cc1de763434176d2f68e419dd37a8cd328395..78cffc875ffe83f512bca253f4a7489227311da4 100644
--- a/test/auth.bb
+++ b/test/auth.bb
@@ -3,113 +3,14 @@
   (:require [babashka.process :as p]
             [babashka.fs :as fs]
             [cheshire.core :as json]
-            [org.httpkit.server :as http]
-            [test.common :as common]))
+            [clojure.string :as str]
+            [test.common :as common]
+            [test.oauth :as oauth]))
 
-(def ^:private ansi-green "\033[32m")
-(def ^:private ansi-red   "\033[31m")
-(def ^:private ansi-reset "\033[0m")
 (def ^:private counts (atom {:pass 0 :fail 0}))
 
-(defn- pass [msg]
-  (swap! counts update :pass inc)
-  (println (str ansi-green "  ✓ " ansi-reset msg)))
-
-(defn- fail [msg]
-  (swap! counts update :fail inc)
-  (println (str ansi-red "  ✗ " ansi-reset msg)))
-
 (defn- assert! [pred msg]
-  (if pred
-    (pass msg)
-    (do (fail msg)
-        (throw (ex-info (str "FAIL: " msg) {})))))
-
-(defn- http-client []
-  (-> (java.net.http.HttpClient/newBuilder)
-      (.followRedirects java.net.http.HttpClient$Redirect/ALWAYS)
-      (.build)))
-
-(defn- http-get [url & {:keys [headers]}]
-  (let [b (java.net.http.HttpRequest/newBuilder (java.net.URI/create url))]
-    (doseq [[k v] (or headers {})]
-      (.header b k v))
-    (let [req (-> b (.GET) (.build))
-          resp (.send (http-client) req (java.net.http.HttpResponse$BodyHandlers/ofString))]
-      {:status (.statusCode resp) :body (.body resp) :headers (.map (.headers resp))})))
-
-(defn- http-post-json [url data & {:keys [headers]}]
-  (let [body (json/generate-string data)
-        b (java.net.http.HttpRequest/newBuilder (java.net.URI/create url))]
-    (.header b "Content-Type" "application/json")
-    (doseq [[k v] (or headers {})]
-      (.header b k v))
-    (let [req (-> b
-                  (.POST (java.net.http.HttpRequest$BodyPublishers/ofString body))
-                  (.build))
-          resp (.send (http-client) req (java.net.http.HttpResponse$BodyHandlers/ofString))]
-      {:status (.statusCode resp) :body (.body resp) :headers (.map (.headers resp))})))
-
-(defn- http-post-form [url form]
-  (let [pairs (->> form
-                   (map (fn [[k v]]
-                          (str (java.net.URLEncoder/encode (name k) "UTF-8")
-                               "="
-                               (java.net.URLEncoder/encode (str v) "UTF-8"))))
-                   (clojure.string/join "&"))
-        b (java.net.http.HttpRequest/newBuilder (java.net.URI/create url))]
-    (.header b "Content-Type" "application/x-www-form-urlencoded")
-    (let [req (-> b
-                  (.POST (java.net.http.HttpRequest$BodyPublishers/ofString pairs))
-                  (.build))
-          resp (.send (http-client) req (java.net.http.HttpResponse$BodyHandlers/ofString))]
-      {:status (.statusCode resp) :body (.body resp) :headers (.map (.headers resp))})))
-
-(defn- parse-query [s]
-  (into {}
-        (for [part (clojure.string/split (or s "") #"&")
-              :when (not (clojure.string/blank? part))]
-          (let [[k v] (clojure.string/split part #"=" 2)]
-            [(keyword (java.net.URLDecoder/decode k "UTF-8"))
-             (some-> v (java.net.URLDecoder/decode "UTF-8"))]))))
-
-(defn- b64url [s]
-  (-> (java.util.Base64/getUrlEncoder)
-      (.withoutPadding)
-      (.encodeToString (.getBytes s "UTF-8"))))
-
-(defn- make-id-token [sub]
-  (str (b64url "{\"alg\":\"RS256\",\"typ\":\"JWT\"}")
-       "."
-       (b64url (json/generate-string {:sub sub}))
-       ".fakesig"))
-
-(defn- start-mock-google [port]
-  (let [google-users ["google-user-1" "google-user-2"]
-        !call-count (atom 0)
-        handler
-        (fn [req]
-          (cond
-            (and (= :get (:request-method req))
-                 (= "/o/oauth2/v2/auth" (:uri req)))
-            (let [q (parse-query (:query-string req))
-                  redirect-uri (:redirect_uri q)
-                  state (:state q)
-                  loc (str redirect-uri "?code=mockcode&state=" state)]
-              {:status 302 :headers {"Location" loc} :body ""})
-
-            (and (= :post (:request-method req))
-                 (= "/token" (:uri req)))
-            (let [n   (swap! !call-count inc)
-                  sub (nth google-users (mod (dec n) (count google-users)))]
-              {:status 200
-               :headers {"Content-Type" "application/json"}
-               :body (json/generate-string {:id_token (make-id-token sub)})})
-
-            :else
-            {:status 404 :body "not found"}))
-        stop-fn (http/run-server handler {:port port})]
-    {:stop-fn stop-fn :port port}))
+  (common/test-assert! counts pred msg))
 
 (defn auth-test [& _args]
   (println "\n━━━ auth v3 integration check ━━━\n")
@@ -117,8 +18,7 @@
 
   (println "building server + CLI binaries…")
   (common/letlocals
-   (bind build @(p/process [(common/cargo-bin) "build" "--release" "-p" "slugsocial-server" "-p" "slugsocial"]
-                           {:inherit true :env common/base-env}))
+   (bind build (common/run-cargo-build-release! ["slugsocial-server" "slugsocial"]))
    (assert! (zero? (:exit build)) "cargo build succeeds")
    (bind server-bin "target/release/slugsocial-server")
    (bind cli-bin "target/release/slugsocial")
@@ -134,19 +34,10 @@
    (bind !server (atom nil))
    (bind !google (atom nil))
 
-   (bind server-env (merge common/base-env
-                           {"SLUG_DATA_DIR" tmp-dir
-                            "SLUG_KEYS"     "test:test"
-                            "PORT"          (str slug-port)
-                            "RUST_LOG"      "warn"
-                            "SLUG_PUBLIC_URL" base-url
-                            "SLUG_GOOGLE_AUTH_URL" (str google-url "/o/oauth2/v2/auth")
-                            "SLUG_GOOGLE_TOKEN_URL" (str google-url "/token")
-                            "SLUG_GOOGLE_CLIENT_ID" "mock"
-                            "SLUG_GOOGLE_CLIENT_SECRET" "mock"}))
+   (bind server-env (common/slug-server-env tmp-dir base-url google-url slug-port))
    (try
      (println (str "\nstarting mock google on :" google-port))
-     (reset! !google (start-mock-google google-port))
+     (reset! !google (oauth/start-mock-google google-port :google-users ["google-user-1" "google-user-2"]))
      (assert! (some? (:stop-fn @!google)) "mock google started")
 
      (println (str "starting server on :" slug-port))
@@ -154,34 +45,33 @@
      (assert! (common/wait-for-server base-url 10000) "server responds to /healthz")
 
      (println "\nstarting pending session…")
-     (let [start-resp (http-post-json (str base-url "/api/v0/pending-session")
-                                      {:agent "00000000-0000-0000-0000-000000000000:bb:local/dev"})
+     (let [start-resp (oauth/http-post-json (str base-url "/api/v0/pending-session")
+                                            {:agent "00000000-0000-0000-0000-000000000000:bb:local/dev"})
            _ (assert! (= 200 (:status start-resp)) "pending-session start returns 200")
            start-json (json/parse-string (:body start-resp) true)]
-       (assert! (clojure.string/starts-with? (:session start-json) "p_") "session id has p_ prefix")
-       (assert! (clojure.string/includes? (:login_url start-json) "/auth/login") "login_url provided")
+       (assert! (str/starts-with? (:session start-json) "p_") "session id has p_ prefix")
+       (assert! (str/includes? (:login_url start-json) "/auth/login") "login_url provided")
 
        (println "\nsimulating browser oauth redirects…")
-       ;; This will follow redirects: /auth/login -> mock google -> /auth/callback -> /auth/choose-username
-       (let [login-get (http-get (:login_url start-json))]
+       (let [login-get (oauth/http-get (:login_url start-json))]
          (assert! (= 200 (:status login-get)) "choose-username page reachable after oauth callback"))
 
        (println "\nchoosing username…")
-       (let [choose (http-post-form (str base-url "/auth/choose-username")
-                                    {:session (:session start-json) :username "bbuser"})]
+       (let [choose (oauth/http-post-form (str base-url "/auth/choose-username")
+                                          {:session (:session start-json) :username "bbuser"})]
          (assert! (= 200 (:status choose)) "choose-username POST returns 200"))
 
        (println "\npolling pending session…")
-       (let [poll (http-get (str base-url "/api/v0/pending-session/" (:session start-json)))]
+       (let [poll (oauth/http-get (str base-url "/api/v0/pending-session/" (:session start-json)))]
          (assert! (= 200 (:status poll)) "pending-session poll returns 200")
          (let [poll-json (json/parse-string (:body poll) true)]
            (assert! (:complete poll-json) "pending session complete=true")
            (assert! (= "bbuser" (:user poll-json)) "poll returns stored username bbuser")
-           (assert! (clojure.string/starts-with? (:token poll-json) "slug_") "poll returns bearer token")
+           (assert! (str/starts-with? (:token poll-json) "slug_") "poll returns bearer token")
 
            (println "\nwhoami…")
-           (let [who (http-get (str base-url "/api/v0/whoami")
-                               :headers {"Authorization" (str "Bearer " (:token poll-json))})]
+           (let [who (oauth/http-get (str base-url "/api/v0/whoami")
+                                     :headers {"Authorization" (str "Bearer " (:token poll-json))})]
              (assert! (= 200 (:status who)) "whoami returns 200")
              (let [who-json (json/parse-string (:body who) true)]
                (assert! (= "bbuser" (:user who-json)) "whoami user is bbuser (stored form)"))))))
@@ -195,11 +85,11 @@
                   (str "identity start exits 0 (stderr: " (:err start-proc) ")"))
          (let [start-cli (json/parse-string (:out start-proc) true)]
            (assert! (= "present_oauth_url_to_user" (:phase start-cli)) "identity start --json phase")
-           (assert! (clojure.string/starts-with? (:session start-cli) "p_") "CLI start session id")
-           (let [login-get (http-get (:login_url start-cli))]
+           (assert! (str/starts-with? (:session start-cli) "p_") "CLI start session id")
+           (let [login-get (oauth/http-get (:login_url start-cli))]
              (assert! (= 200 (:status login-get)) "CLI login_url redirect chain succeeds"))
-           (let [choose (http-post-form (str base-url "/auth/choose-username")
-                                        {:session (:session start-cli) :username "cliuser"})]
+           (let [choose (oauth/http-post-form (str base-url "/auth/choose-username")
+                                              {:session (:session start-cli) :username "cliuser"})]
              (assert! (= 200 (:status choose)) "choose-username for cliuser"))
            (let [poll-proc @(p/process [cli-bin "identity" "poll" (:session start-cli)
                                         "--poll-interval-ms" "100" "--max-wait-secs" "30" "--json"]
@@ -209,10 +99,10 @@
              (let [poll-cli (json/parse-string (:out poll-proc) true)]
                (assert! (= "complete" (:phase poll-cli)) "identity poll --json phase")
                (assert! (= "cliuser" (:user poll-cli)) "CLI poll user (stored form)")
-               (assert! (clojure.string/starts-with? (:token poll-cli) "slug_") "CLI poll token")
+               (assert! (str/starts-with? (:token poll-cli) "slug_") "CLI poll token")
                (let [token-path (str cli-home "/.config/slugsocial/token")]
                  (assert! (fs/exists? token-path) "token written under isolated HOME")
-                 (assert! (= (clojure.string/trim (slurp token-path)) (:token poll-cli))
+                 (assert! (= (str/trim (slurp token-path)) (:token poll-cli))
                           "token file matches poll JSON"))
      

… preview truncated; 24,704 characters omitted

download full diff B

Hardlinks — judgments / attempts / prompt

prompt download

judgments

attempts

Prompt text is loaded only by the download route.