<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: subhansh</title>
    <description>The latest articles on DEV Community by subhansh (@subhansh).</description>
    <link>https://dev.to/subhansh</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3932783%2Fec98af63-4dd3-4af0-85ce-d5c0b76ebf45.png</url>
      <title>DEV Community: subhansh</title>
      <link>https://dev.to/subhansh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/subhansh"/>
    <language>en</language>
    <item>
      <title>[Boost]</title>
      <dc:creator>subhansh</dc:creator>
      <pubDate>Thu, 23 Jul 2026 15:12:45 +0000</pubDate>
      <link>https://dev.to/subhansh/-1jm3</link>
      <guid>https://dev.to/subhansh/-1jm3</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/subhansh/i-benchmarked-19-retrieval-pipelines-head-to-head-and-the-results-were-surprisingly-honest-3efe" class="crayons-story__hidden-navigation-link"&gt;I Benchmarked 19 Retrieval Pipelines Head-to-Head and the Results Were Surprisingly Honest&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/subhansh" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3932783%2Fec98af63-4dd3-4af0-85ce-d5c0b76ebf45.png" alt="subhansh profile" class="crayons-avatar__image" width="81" height="76"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/subhansh" class="crayons-story__secondary fw-medium m:hidden"&gt;
              subhansh
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                subhansh
                
              
              &lt;div id="story-author-preview-content-4216200" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/subhansh" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3932783%2Fec98af63-4dd3-4af0-85ce-d5c0b76ebf45.png" class="crayons-avatar__image" alt="" width="81" height="76"&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;subhansh&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/subhansh/i-benchmarked-19-retrieval-pipelines-head-to-head-and-the-results-were-surprisingly-honest-3efe" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Jul 23&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/subhansh/i-benchmarked-19-retrieval-pipelines-head-to-head-and-the-results-were-surprisingly-honest-3efe" id="article-link-4216200"&gt;
          I Benchmarked 19 Retrieval Pipelines Head-to-Head and the Results Were Surprisingly Honest
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/subhansh/i-benchmarked-19-retrieval-pipelines-head-to-head-and-the-results-were-surprisingly-honest-3efe" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/exploding-head-daceb38d627e6ae9b730f36a1e390fca556a4289d5a41abb2c35068ad3e2c4b5.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/multi-unicorn-b44d6f8c23cdd00964192bedc38af3e82463978aa611b4365bd33a0f1f4f3e97.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;5&lt;span class="hidden s:inline"&gt;&amp;nbsp;reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/subhansh/i-benchmarked-19-retrieval-pipelines-head-to-head-and-the-results-were-surprisingly-honest-3efe#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

              &lt;span class="hidden s:inline"&gt;Add&amp;nbsp;Comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            3 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


</description>
    </item>
    <item>
      <title>I Benchmarked 19 Retrieval Pipelines Head-to-Head and the Results Were Surprisingly Honest</title>
      <dc:creator>subhansh</dc:creator>
      <pubDate>Thu, 23 Jul 2026 15:09:01 +0000</pubDate>
      <link>https://dev.to/subhansh/i-benchmarked-19-retrieval-pipelines-head-to-head-and-the-results-were-surprisingly-honest-3efe</link>
      <guid>https://dev.to/subhansh/i-benchmarked-19-retrieval-pipelines-head-to-head-and-the-results-were-surprisingly-honest-3efe</guid>
      <description>&lt;p&gt;I got tired of retrieval papers claiming their pipeline is "state-of-the-art" without significance tests, without telling you what dataset they ran on, and without reproducible code. So I built &lt;a href="https://github.com/subhansh-dev/raven-retrieval" rel="noopener noreferrer"&gt;raven-retrieval&lt;/a&gt; -- 19 retrieval pipelines, real BEIR datasets, Bonferroni-corrected bootstrap significance tests, all the numbers whether they look good or not. MIT licensed, open source.&lt;/p&gt;

&lt;h2&gt;
  
  
  What It Does
&lt;/h2&gt;

&lt;p&gt;The core question: does ColBERT-style late interaction scoring at every level of a RAPTOR hierarchical tree actually improve retrieval over simpler approaches? To answer that properly you need the same datasets, same chunking, same metrics, same significance tests for every pipeline. Otherwise you're comparing apples to oranges.&lt;/p&gt;

&lt;p&gt;The framework implements 19 pipelines and benchmarks them all on BEIR datasets (SciFact, HotpotQA) on equal footing. No cherry-picking.&lt;/p&gt;

&lt;h2&gt;
  
  
  The 19 Pipelines (Quick Summary)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Core:&lt;/strong&gt; Naive Dense RAG, Hybrid RAG (BM25+Dense+RRF), ColBERT Late Interaction, RAPTOR+Late Interaction (novel combination).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Research (2024-2025):&lt;/strong&gt; HyDE, SPLADE, SPLADE+Dense, BM25+Rocchio PRF, Contextual Retrieval, Contextual Hybrid, Late Chunking, RAPTOR+Late Traversal, Agentic Multi-Hop, Reflection Retriever, Graph Retrieval, Two-Stage Dense+Reranker, Approximate Late Interaction, Contextual Dense, Contextual BM25.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Composition modules:&lt;/strong&gt; Cross-Encoder Reranker, Two-Stage Retriever, Document Graph, Residual Compressor (~30x storage reduction).&lt;/p&gt;

&lt;p&gt;The novel one is &lt;strong&gt;RAPTOR + Late Interaction&lt;/strong&gt;: build a RAPTOR hierarchical summary tree, then apply ColBERT MaxSim scoring at every node (leaf chunks AND summary nodes). Nobody has published on this combination before.&lt;/p&gt;

&lt;h2&gt;
  
  
  How MaxSim Works
&lt;/h2&gt;

&lt;p&gt;ColBERT's scoring: for each query token, find the most similar document token (cosine), then sum those maximums across all query tokens. Every query token gets a vote for its best-matching document token. This captures fine-grained token-level relevance that single-vector cosine misses entirely. Implemented in pure numpy, no torch needed for scoring.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Benchmark Results
&lt;/h2&gt;

&lt;p&gt;Run on Google Colab T4 GPU, seed=42, two datasets.&lt;/p&gt;

&lt;h3&gt;
  
  
  SciFact (100 queries, single-hop scientific claims)
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pipeline&lt;/th&gt;
&lt;th&gt;nDCG@10&lt;/th&gt;
&lt;th&gt;Per-Query&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;HyDE&lt;/td&gt;
&lt;td&gt;0.712&lt;/td&gt;
&lt;td&gt;19ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Naive Dense&lt;/td&gt;
&lt;td&gt;0.696&lt;/td&gt;
&lt;td&gt;32ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Contextual Hybrid&lt;/td&gt;
&lt;td&gt;0.682&lt;/td&gt;
&lt;td&gt;93ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Hybrid RAG&lt;/td&gt;
&lt;td&gt;0.667&lt;/td&gt;
&lt;td&gt;87ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;BM25+PRF&lt;/td&gt;
&lt;td&gt;0.529&lt;/td&gt;
&lt;td&gt;43ms&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Key finding:&lt;/strong&gt; Top 4 are &lt;strong&gt;statistically indistinguishable&lt;/strong&gt; (all pairwise p &amp;gt; 0.05 after Bonferroni). BM25+PRF is significantly worse (p ~ 0.000). The "winner" HyDE is only 2 points above Dense -- within noise.&lt;/p&gt;

&lt;h3&gt;
  
  
  HotpotQA (50 queries, multi-hop reasoning)
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pipeline&lt;/th&gt;
&lt;th&gt;nDCG@10&lt;/th&gt;
&lt;th&gt;Per-Query&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Hybrid RAG&lt;/td&gt;
&lt;td&gt;0.925&lt;/td&gt;
&lt;td&gt;22ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Contextual Hybrid&lt;/td&gt;
&lt;td&gt;0.923&lt;/td&gt;
&lt;td&gt;22ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Naive Dense&lt;/td&gt;
&lt;td&gt;0.906&lt;/td&gt;
&lt;td&gt;12ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;HyDE&lt;/td&gt;
&lt;td&gt;0.892&lt;/td&gt;
&lt;td&gt;26ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;BM25+PRF&lt;/td&gt;
&lt;td&gt;0.869&lt;/td&gt;
&lt;td&gt;8ms&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;The ranking flips completely.&lt;/strong&gt; HyDE drops from 1st to 4th. Hybrid RAG wins because BM25+Dense fusion catches different reasoning hops. A single hypothetical document can't bridge two separate reasoning steps.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The most important finding:&lt;/strong&gt; No single pipeline dominates across task types. Single-hop favors semantic (HyDE). Multi-hop favors hybrid. Anyone claiming universal superiority hasn tested on enough datasets.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Bugs I Found
&lt;/h2&gt;

&lt;p&gt;Before v0.3, 13 bugs (6 critical) silently corrupted results:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;ColBERT matched against PAD tokens&lt;/strong&gt; -- attention mask wasn used, padding tokens got MaxSim votes alongside real content&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;RAPTOR clustering used wrong embedding space&lt;/strong&gt; -- centroids from ColBERT means while scoring with SBERT vectors&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Per-query nDCG was all zeros&lt;/strong&gt; -- BEIR evaluate() returns averaged floats, not per-query; significance tests fed zeros and reported "no difference" everywhere (false negatives)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reflection evaluated keyword coverage over doc ID strings&lt;/strong&gt; ("doc_1", "doc_42") instead of actual text, triggering endless reformulation loops&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;RAPTOR pipelines crashed&lt;/strong&gt; -- UMAP bug when local clusters had 3 samples (k &amp;gt;= N), burned 189 minutes of Colab time&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These don crash your program. They just make your results wrong in ways you can see from final numbers alone.&lt;/p&gt;

&lt;h2&gt;
  
  
  Known Limitations
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;ColBERT projection head is Xavier-initialized (untrained). Late interaction scores ~0.58 without training, worse than Dense at 0.696. Training support exists (&lt;code&gt;ColbertContrastiveEncoder&lt;/code&gt; with InfoNCE) but no trained checkpoint in default benchmark yet.&lt;/li&gt;
&lt;li&gt;GMM soft-clustering converges to near-hard assignment on ~100-token chunks (matches Stanford CS224N reproduction).&lt;/li&gt;
&lt;li&gt;Late Chunking limited by BERT's 512-token window -- needs long-context model to really shine.&lt;/li&gt;
&lt;li&gt;HotpotQA scores are on 2,000-doc subsample, not the full 5.2M corpus. Real retrieval is harder than these numbers suggest.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/subhansh-dev/raven-retrieval.git
&lt;span class="nb"&gt;cd &lt;/span&gt;raven-retrieval
pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;".[full]"&lt;/span&gt;
python run_enhanced_benchmark.py &lt;span class="nt"&gt;--dataset&lt;/span&gt; scifact &lt;span class="nt"&gt;--top-k&lt;/span&gt; 10 &lt;span class="nt"&gt;--seed&lt;/span&gt; 42
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;CLI entry points: &lt;code&gt;raven-benchmark&lt;/code&gt;, &lt;code&gt;raven-report&lt;/code&gt;. Low-RAM? Use &lt;code&gt;--max-docs&lt;/code&gt;. Want trained ColBERT? Use &lt;code&gt;--colbert-checkpoint&lt;/code&gt;. All 55 tests pass.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why This Matters
&lt;/h2&gt;

&lt;p&gt;Retrieval benchmarks have a credibility problem. Papers claim improvements without significance tests, without multiple datasets, without reproducible code. Raven-retrieval fixes all of that. The honest answer -- that top pipelines are tied, that rankings flip between datasets, that BM25+PRF is bad on scientific text -- is more useful than cherry-picked claims of universal superiority.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/subhansh-dev/raven-retrieval" rel="noopener noreferrer"&gt;github.com/subhansh-dev/raven-retrieval&lt;/a&gt; | &lt;a href="http://subhansh.dev" rel="noopener noreferrer"&gt;subhansh.dev&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>[Boost]</title>
      <dc:creator>subhansh</dc:creator>
      <pubDate>Sat, 18 Jul 2026 13:54:05 +0000</pubDate>
      <link>https://dev.to/subhansh/-3mh2</link>
      <guid>https://dev.to/subhansh/-3mh2</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/subhansh/i-built-a-programming-language-because-c-almost-killed-my-drone-34l7" class="crayons-story__hidden-navigation-link"&gt;I built a programming language because C++ almost killed my drone&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/subhansh" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3932783%2Fec98af63-4dd3-4af0-85ce-d5c0b76ebf45.png" alt="subhansh profile" class="crayons-avatar__image"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/subhansh" class="crayons-story__secondary fw-medium m:hidden"&gt;
              subhansh
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                subhansh
                
              
              &lt;div id="story-author-preview-content-4127476" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/subhansh" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3932783%2Fec98af63-4dd3-4af0-85ce-d5c0b76ebf45.png" class="crayons-avatar__image" alt=""&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;subhansh&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/subhansh/i-built-a-programming-language-because-c-almost-killed-my-drone-34l7" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Jul 12&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/subhansh/i-built-a-programming-language-because-c-almost-killed-my-drone-34l7" id="article-link-4127476"&gt;
          I built a programming language because C++ almost killed my drone
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/programming"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;programming&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/rust"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;rust&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/robotics"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;robotics&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/compilers"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;compilers&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/subhansh/i-built-a-programming-language-because-c-almost-killed-my-drone-34l7" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/multi-unicorn-b44d6f8c23cdd00964192bedc38af3e82463978aa611b4365bd33a0f1f4f3e97.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/fire-f60e7a582391810302117f987b22a8ef04a2fe0df7e3258a5f49332df1cec71e.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;11&lt;span class="hidden s:inline"&gt;&amp;nbsp;reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/subhansh/i-built-a-programming-language-because-c-almost-killed-my-drone-34l7#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

              3&lt;span class="hidden s:inline"&gt;&amp;nbsp;comments&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            5 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


</description>
    </item>
    <item>
      <title>I Built a Full Raft Consensus Engine in Rust at 17 — Here's Every Gritty Detail</title>
      <dc:creator>subhansh</dc:creator>
      <pubDate>Fri, 17 Jul 2026 16:24:04 +0000</pubDate>
      <link>https://dev.to/subhansh/i-built-a-full-raft-consensus-engine-in-rust-at-17-heres-every-gritty-detail-56ii</link>
      <guid>https://dev.to/subhansh/i-built-a-full-raft-consensus-engine-in-rust-at-17-heres-every-gritty-detail-56ii</guid>
      <description>&lt;h1&gt;
  
  
  I Built a Full Raft Consensus Engine in Rust at 17 — Here's Every Gritty Detail
&lt;/h1&gt;




&lt;p&gt;I'm 17. This is my first distributed systems project.&lt;/p&gt;

&lt;p&gt;Raft is the consensus algorithm that powers etcd, Consul, TiKV, and a dozen other production systems. The paper makes it look straightforward — leader election, log replication, snapshots. But implementing it from scratch? Every paragraph in the paper expands into dozens of edge cases. Figure 8 alone (the "previous term entries can't be committed directly" rule) caused me three rewrites.&lt;/p&gt;

&lt;p&gt;This implementation is &lt;strong&gt;4,400+ lines of Rust across 7 crates, 52 tests, real gRPC networking, disk persistence with sled, log compaction via InstallSnapshot, and a chaos harness that kills nodes and partitions networks&lt;/strong&gt;. No etcd code. No TiKV dependencies. Pure paper-to-production.&lt;/p&gt;




&lt;h2&gt;
  
  
  What This Actually Is
&lt;/h2&gt;

&lt;p&gt;A complete, tested Raft implementation that you can run right now:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# In-process 3-node demo&lt;/span&gt;
cargo run &lt;span class="nt"&gt;--example&lt;/span&gt; kv-demo

&lt;span class="c"&gt;# Or run a real cluster across 3 terminals&lt;/span&gt;
cargo build &lt;span class="nt"&gt;--release&lt;/span&gt;
&lt;span class="c"&gt;# Terminal 1: cargo run --release -p raft-node -- --node-id 1 --peers 2@127.0.0.1:8081,3@127.0.0.1:8082 --port 8080&lt;/span&gt;
&lt;span class="c"&gt;# Terminal 2: cargo run --release -p raft-node -- --node-id 2 --peers 1@127.0.0.1:8080,3@127.0.0.1:8082 --port 8081&lt;/span&gt;
&lt;span class="c"&gt;# Terminal 3: cargo run --release -p raft-node -- --node-id 3 --peers 1@127.0.0.1:8080,2@127.0.0.1:8081 --port 8082&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;What works:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Leader election with randomized timeouts (300-500ms) and proper log-up-to-date checks&lt;/li&gt;
&lt;li&gt;Log replication with Figure 8 compliance — previous-term entries commit indirectly only&lt;/li&gt;
&lt;li&gt;Fast backup optimization — followers return &lt;code&gt;conflict_term&lt;/code&gt;/&lt;code&gt;conflict_index&lt;/code&gt;, leader skips entire terms in one RTT&lt;/li&gt;
&lt;li&gt;Persistence before RPC replies (Figure 2 requirement) — &lt;code&gt;current_term&lt;/code&gt;, &lt;code&gt;voted_for&lt;/code&gt;, log entries flushed to sled&lt;/li&gt;
&lt;li&gt;Snapshotting with InstallSnapshot RPC — log compaction, boundary handling, 15 tests&lt;/li&gt;
&lt;li&gt;Chaos testing — network partitions, node kills, leader isolation, process-level chaos with 5 real OS processes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What's not done (honest gaps):&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dynamic membership changes (joint consensus)&lt;/li&gt;
&lt;li&gt;ReadIndex/LeaseRead for linearizable reads&lt;/li&gt;
&lt;li&gt;WAN optimization / batching&lt;/li&gt;
&lt;li&gt;WAL-based persistence (sled works but isn't crash-consistent like a WAL)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Architecture — 7 Crates, Clean Boundaries
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;raft/
├── Cargo.toml
├── crates/
│   ├── raft-core/          # Pure logic — 40 unit tests
│   │   ├── types.rs
│   │   ├── state.rs
│   │   ├── election.rs
│   │   ├── replication.rs
│   │   └── snapshot.rs
│   ├── raft-rpc/           # gRPC transport (tonic)
│   ├── raft-storage/       # Persistence abstraction
│   │   ├── RaftStorage trait
│   │   ├── SledStorage
│   │   └── MemStorage
│   ├── raft-node/          # Standalone binary
│   └── raft-chaos/         # Chaos harness
└── examples/
    ├── kv-demo/
    └── process-chaos/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Why this separation matters:&lt;/strong&gt; The core logic has &lt;em&gt;zero&lt;/em&gt; I/O. No network, no disk, no time. Pure functions. Unit tests are deterministic and fast. Storage backends are swappable without touching consensus logic. The chaos harness injects failures at the network layer — not the logic layer.&lt;/p&gt;




&lt;h2&gt;
  
  
  Leader Election — The Part Everyone Gets Wrong
&lt;/h2&gt;

&lt;p&gt;The paper says: "If election timeout elapses without receiving AppendEntries, become candidate." Simple, right?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Wrong.&lt;/strong&gt; Here's what actually happens in &lt;code&gt;election.rs&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;on_election_timeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Vec&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;NodeAction&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="nf"&gt;.become_candidate&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;  &lt;span class="c1"&gt;// term++, vote for self&lt;/span&gt;

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;RequestVoteArgs&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;term&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.current_term&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;candidate_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;last_log_index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="nf"&gt;.last_log_index&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
        &lt;span class="n"&gt;last_log_term&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="nf"&gt;.last_log_term&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.peers&lt;/span&gt;&lt;span class="nf"&gt;.iter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="nf"&gt;.map&lt;/span&gt;&lt;span class="p"&gt;(|&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;peer&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="nn"&gt;NodeAction&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;SendRequestVote&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;peer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="nf"&gt;.clone&lt;/span&gt;&lt;span class="p"&gt;()))&lt;/span&gt;
        &lt;span class="nf"&gt;.collect&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But the &lt;em&gt;vote granting&lt;/em&gt; logic is where bugs live (§5.4.1):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;is_log_up_to_date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;candidate_last_term&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;candidate_last_index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u64&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;my_last_term&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="nf"&gt;.last_log_term&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;my_last_index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="nf"&gt;.last_log_index&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;candidate_last_term&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;my_last_term&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;candidate_last_term&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;my_last_term&lt;/span&gt;  &lt;span class="c1"&gt;// Higher term wins&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;candidate_last_index&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;my_last_index&lt;/span&gt;  &lt;span class="c1"&gt;// Same term? Longer log wins&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The subtlety that catches everyone:&lt;/strong&gt; A candidate with term 3 and log length 1 beats a follower with term 2 and log length 100. Term &lt;em&gt;always&lt;/em&gt; wins. This prevents the "stale leader with massive log" problem.&lt;/p&gt;

&lt;p&gt;My test suite hammers this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;12 election tests covering grants, rejections, stale terms, split votes, term conversion&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;test_no_two_leaders_same_term&lt;/code&gt; spins up 5 nodes simultaneously — all become candidates, all vote for themselves, &lt;em&gt;none&lt;/em&gt; win (majority = 3, each has 1 vote). Beautiful.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Log Replication — Where Figure 8 Bites You
&lt;/h2&gt;

&lt;p&gt;Leader receives command → appends to local log → sends AppendEntries → majority replicates → commit → apply. Standard stuff.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Except Figure 8.&lt;/strong&gt; The paper shows a scenario where a leader commits an entry from a &lt;em&gt;previous&lt;/em&gt; term, then crashes. New leader doesn't have that entry. Data loss.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The rule:&lt;/strong&gt; A leader can &lt;em&gt;only&lt;/em&gt; directly commit entries from its &lt;strong&gt;current term&lt;/strong&gt;. Previous-term entries commit &lt;em&gt;indirectly&lt;/em&gt; when a current-term entry after them commits.&lt;/p&gt;

&lt;p&gt;My implementation in &lt;code&gt;replication.rs&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;advance_commit_index&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.state&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="nn"&gt;NodeState&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;Leader&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;match_indices&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Vec&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;u64&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.match_index&lt;/span&gt;&lt;span class="nf"&gt;.values&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.copied&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.collect&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="n"&gt;match_indices&lt;/span&gt;&lt;span class="nf"&gt;.push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="nf"&gt;.last_log_index&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
    &lt;span class="n"&gt;match_indices&lt;/span&gt;&lt;span class="nf"&gt;.sort_unstable_by&lt;/span&gt;&lt;span class="p"&gt;(|&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="nf"&gt;.cmp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;match_indices&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.commit_index&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nf"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="nf"&gt;.get_entry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="c1"&gt;// FIGURE 8 RULE: only commit current-term entries directly&lt;/span&gt;
                &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="py"&gt;.term&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.current_term&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;replicated&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;match_indices&lt;/span&gt;&lt;span class="nf"&gt;.iter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.filter&lt;/span&gt;&lt;span class="p"&gt;(|&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;idx&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="n"&gt;idx&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;.count&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
                    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="nf"&gt;.is_majority&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;replicated&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                        &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.commit_index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                        &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                    &lt;span class="p"&gt;}&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The test that proves it works&lt;/strong&gt; (&lt;code&gt;test_advance_commit_index_figure8&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Leader has: index 1 (term 1), index 2-3 (term 2)&lt;/span&gt;
&lt;span class="c1"&gt;// Followers replicated up to index 1 (term 1 entry)&lt;/span&gt;
&lt;span class="n"&gt;leader&lt;/span&gt;&lt;span class="py"&gt;.match_index&lt;/span&gt;&lt;span class="nf"&gt;.insert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;leader&lt;/span&gt;&lt;span class="py"&gt;.match_index&lt;/span&gt;&lt;span class="nf"&gt;.insert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;leader&lt;/span&gt;&lt;span class="nf"&gt;.advance_commit_index&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="c1"&gt;// commit_index stays 0 — term 1 entry NOT committed directly&lt;/span&gt;

&lt;span class="c1"&gt;// Now followers replicate index 2 (term 2)&lt;/span&gt;
&lt;span class="n"&gt;leader&lt;/span&gt;&lt;span class="py"&gt;.match_index&lt;/span&gt;&lt;span class="nf"&gt;.insert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;leader&lt;/span&gt;&lt;span class="py"&gt;.match_index&lt;/span&gt;&lt;span class="nf"&gt;.insert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;leader&lt;/span&gt;&lt;span class="nf"&gt;.advance_commit_index&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="c1"&gt;// commit_index = 2 — term 2 entry commits, drags term 1 along indirectly&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This test alone caught 3 bugs in my early implementation. &lt;strong&gt;Write the Figure 8 test first. Always.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Fast Backup — The Optimization That Makes Raft Practical
&lt;/h2&gt;

&lt;p&gt;Without fast backup, a follower 10,000 entries behind takes 10,000 round-trips to catch up. The paper's appendix describes the fix: followers return &lt;code&gt;conflict_term&lt;/code&gt; and &lt;code&gt;conflict_index&lt;/code&gt; on rejection. Leader jumps &lt;code&gt;next_index&lt;/code&gt; past the entire conflicting term.&lt;/p&gt;

&lt;p&gt;My implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;handle_append_entries_reply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;peer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;NodeId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;reply&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;AppendEntriesReply&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Option&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;NodeAction&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;reply&lt;/span&gt;&lt;span class="py"&gt;.success&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Update match_index, next_index normally&lt;/span&gt;
        &lt;span class="o"&gt;...&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// FAST BACKUP&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nf"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;conflict_term&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;reply&lt;/span&gt;&lt;span class="py"&gt;.conflict_term&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;new_next&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;reply&lt;/span&gt;&lt;span class="py"&gt;.conflict_index&lt;/span&gt;&lt;span class="nf"&gt;.unwrap_or&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;entry&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.log&lt;/span&gt;&lt;span class="nf"&gt;.iter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.rev&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="py"&gt;.term&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;conflict_term&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="n"&gt;new_next&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="py"&gt;.index&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  &lt;span class="c1"&gt;// Jump PAST the term&lt;/span&gt;
                    &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.next_index&lt;/span&gt;&lt;span class="nf"&gt;.insert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;peer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;new_next&lt;/span&gt;&lt;span class="nf"&gt;.max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nf"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;conflict_index&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;reply&lt;/span&gt;&lt;span class="py"&gt;.conflict_index&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.next_index&lt;/span&gt;&lt;span class="nf"&gt;.insert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;peer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;conflict_index&lt;/span&gt;&lt;span class="nf"&gt;.max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// Fallback: decrement by 1 (slow path)&lt;/span&gt;
            &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.next_index&lt;/span&gt;&lt;span class="nf"&gt;.get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;peer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;.copied&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="nf"&gt;.unwrap_or&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.next_index&lt;/span&gt;&lt;span class="nf"&gt;.insert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;peer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;current&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;.max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;...&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Test proof&lt;/strong&gt; (&lt;code&gt;test_fast_backup_convergence&lt;/code&gt;):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Leader has terms: [1, 1, 3, 5] at indices [1, 2, 3, 4]&lt;/li&gt;
&lt;li&gt;Follower rejects at index 4, says "I have term 1 at index 4, first index of term 1 is 1"&lt;/li&gt;
&lt;li&gt;Leader jumps &lt;code&gt;next_index&lt;/code&gt; from 5 → 3 (skips all of term 1 in one round-trip)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Real-world impact:&lt;/strong&gt; A node 1M entries behind catches up in ~log(terms) round-trips, not O(entries). This is the difference between "toy" and "production."&lt;/p&gt;




&lt;h2&gt;
  
  
  Persistence — The "Before Reply" Rule
&lt;/h2&gt;

&lt;p&gt;Figure 2 is explicit: &lt;strong&gt;persist before responding.&lt;/strong&gt; My &lt;code&gt;grpc_server.rs&lt;/code&gt; enforces this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;request_vote&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Request&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;ProtoRequestVoteArgs&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;...&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;core_args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;proto_to_core_request_vote_args&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.state.node&lt;/span&gt;&lt;span class="nf"&gt;.write&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="k"&gt;.await&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;reply&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="nf"&gt;.handle_request_vote&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;core_args&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// PERSIST BEFORE REPLY — Figure 2 requirement&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.state.storage&lt;/span&gt;&lt;span class="nf"&gt;.save_current_term&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="py"&gt;.current_term&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.state.storage&lt;/span&gt;&lt;span class="nf"&gt;.save_voted_for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="py"&gt;.voted_for&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nf"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nn"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;core_request_vote_reply_to_proto&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reply&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;append_entries&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Request&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;ProtoAppendEntriesArgs&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;...&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;core_args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;proto_to_core_append_entries_args&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.state.node&lt;/span&gt;&lt;span class="nf"&gt;.write&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="k"&gt;.await&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;reply&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="nf"&gt;.handle_append_entries&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;core_args&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Persist log entries BEFORE responding&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;reply&lt;/span&gt;&lt;span class="py"&gt;.success&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;entry&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="py"&gt;.log&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="py"&gt;.index&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;core_args&lt;/span&gt;&lt;span class="py"&gt;.prev_log_index&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.state.storage&lt;/span&gt;&lt;span class="nf"&gt;.save_log_entry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.state.storage&lt;/span&gt;&lt;span class="nf"&gt;.save_current_term&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="py"&gt;.current_term&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nf"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nn"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;core_append_entries_reply_to_proto&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reply&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;SledStorage&lt;/strong&gt; uses bincode serialization with a 64MB cache. Each write flushes to disk. On restart, the node loads &lt;code&gt;current_term&lt;/code&gt;, &lt;code&gt;voted_for&lt;/code&gt;, and the full log — resumes exactly where it left off.&lt;/p&gt;

&lt;p&gt;Crash recovery test: Kill a node mid-replication, restart it, verify it has the same committed state. Works.&lt;/p&gt;




&lt;h2&gt;
  
  
  Snapshotting — Log Compaction Done Right
&lt;/h2&gt;

&lt;p&gt;Logs grow forever. Snapshots fix this. Figure 12 + Figure 7.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Leader side&lt;/strong&gt; (&lt;code&gt;state.rs&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;snapshot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;include_index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u64&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Option&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Vec&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;u8&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;u64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;u64&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Validations: must be committed, applied, past last snapshot&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;include_index&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.last_included_index&lt;/span&gt;
        &lt;span class="p"&gt;||&lt;/span&gt; &lt;span class="n"&gt;include_index&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.commit_index&lt;/span&gt;
        &lt;span class="p"&gt;||&lt;/span&gt; &lt;span class="n"&gt;include_index&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.last_applied&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;None&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Collect all applied commands up to include_index&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;Vec&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;entry&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.log&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="py"&gt;.index&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;include_index&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="nf"&gt;.extend_from_slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="py"&gt;.command&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="nf"&gt;.push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sc"&gt;b'\n'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;last_included_term&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="nf"&gt;.get_entry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;include_index&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nf"&gt;.map_or&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.last_included_term&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="py"&gt;.term&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Discard compacted entries&lt;/span&gt;
    &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.log&lt;/span&gt;&lt;span class="nf"&gt;.retain&lt;/span&gt;&lt;span class="p"&gt;(|&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="py"&gt;.index&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;include_index&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.last_included_index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;include_index&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.last_included_term&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;last_included_term&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.last_applied&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;include_index&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.last_applied&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;include_index&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nf"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;include_index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;last_included_term&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Follower side&lt;/strong&gt; (&lt;code&gt;handle_install_snapshot&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;handle_install_snapshot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;InstallSnapshotArgs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;InstallSnapshotReply&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Rule 1: Stale term → reject&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="py"&gt;.term&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.current_term&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="o"&gt;...&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Rule 2: Higher term → become follower&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="py"&gt;.term&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.current_term&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="nf"&gt;.become_follower&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="py"&gt;.term&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Rule 3: Snapshot behind our snapshot → reject (stale)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="py"&gt;.last_included_index&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.last_included_index&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="o"&gt;...&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Rule 4: Install it&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;existing_term&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="nf"&gt;.get_entry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="py"&gt;.last_included_index&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;.map&lt;/span&gt;&lt;span class="p"&gt;(|&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="py"&gt;.term&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// If boundary matches, keep entries after; else discard ALL log&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;existing_term&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nf"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="py"&gt;.last_included_term&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.log&lt;/span&gt;&lt;span class="nf"&gt;.retain&lt;/span&gt;&lt;span class="p"&gt;(|&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="py"&gt;.index&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="py"&gt;.last_included_index&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.log&lt;/span&gt;&lt;span class="nf"&gt;.clear&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.last_included_index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="py"&gt;.last_included_index&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.last_included_term&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="py"&gt;.last_included_term&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// Advance commit/applied past snapshot&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.last_applied&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="py"&gt;.last_included_index&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.last_applied&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="py"&gt;.last_included_index&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.commit_index&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="py"&gt;.last_included_index&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.commit_index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="py"&gt;.last_included_index&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="n"&gt;InstallSnapshotReply&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;term&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.current_term&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;reset_election_timer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;snapshot_data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="py"&gt;.data&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="n"&gt;last_included_index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;Some&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="py"&gt;.last_included_index&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;15 snapshot tests&lt;/strong&gt; cover: basic compaction, stale rejection, uncommitted rejection, unapplied rejection, boundary preservation, empty log after compact, InstallSnapshot basic, stale term/index rejection, log discard, matching boundary kept, mismatched boundary discarded, term_at_index with snapshot, apply after snapshot, multiple snapshots.&lt;/p&gt;




&lt;h2&gt;
  
  
  Chaos Testing — Breaking It On Purpose
&lt;/h2&gt;

&lt;p&gt;Unit tests verify &lt;em&gt;correctness&lt;/em&gt;. Chaos tests verify &lt;em&gt;resilience&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;raft-chaos&lt;/code&gt; spins up real nodes (in-process or real processes), then:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Partitions&lt;/strong&gt; networks bidirectionally (&lt;code&gt;HashSet&amp;lt;(NodeId, NodeId)&amp;gt;&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Kills&lt;/strong&gt; nodes (clears peers, sets to follower)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Heals&lt;/strong&gt; partitions&lt;/li&gt;
&lt;li&gt;Verifies safety (no split-brain) and liveness (new leader elected)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;The 5 chaos tests:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Test&lt;/th&gt;
&lt;th&gt;What It Verifies&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;test_chaos_leader_election&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;3-node cluster elects leader within 5s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;test_chaos_command_submission&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Commands replicate to all nodes' state machines&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;test_chaos_node_survives_majority&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Kill leader → new election in majority partition&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;test_chaos_partition_minority_cannot_commit&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;2-node minority partitioned → no commits, majority continues&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;test_chaos_partition_leader_isolated&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Isolate leader → majority elects new leader → heal → old leader steps down&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Process chaos&lt;/strong&gt; (&lt;code&gt;examples/process-chaos&lt;/code&gt;): Spawns 5 &lt;strong&gt;real OS processes&lt;/strong&gt; via &lt;code&gt;cargo run --release -p raft-node&lt;/code&gt;, kills the leader process, verifies new election. This catches bugs the in-process harness misses (file descriptor limits, port binding races, sled locking).&lt;/p&gt;




&lt;h2&gt;
  
  
  The KV Demo — See It Run
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cargo run &lt;span class="nt"&gt;--example&lt;/span&gt; kv-demo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;=== 3-node Raft cluster started ===
Nodes on ports [9001, 9002, 9003]
Waiting for leader election...
Leader elected: node 2
Submitted: "name Alice" -&amp;gt; index=1, term=1
Submitted: "name Bob" -&amp;gt; index=2, term=1
Submitted: "lang Rust" -&amp;gt; index=3, term=1
Submitted: "lang Python" -&amp;gt; index=4, term=1

=== Cluster state ===
Node 1: state=Follower, term=1, log_len=4, commit=4, applied=4, store={"name": "Bob", "lang": "Python"}
Node 2: state=Leader, term=1, log_len=4, commit=4, applied=4, store={"name": "Bob", "lang": Python"}
Node 3: state=Follower, term=1, log_len=4, commit=4, applied=4, store={"name": "Bob", "lang": "Python"}

All nodes consistent: true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Real consensus. Real replication. Real state machines.&lt;/p&gt;




&lt;h2&gt;
  
  
  Spec Reference
&lt;/h2&gt;

&lt;p&gt;Built from &lt;strong&gt;Ongaro &amp;amp; Ousterhout's "In Search of an Understandable Consensus Algorithm" (2014)&lt;/strong&gt; — the Raft paper. Every field name, every rule, follows Figure 2 directly.&lt;/p&gt;

&lt;p&gt;Test plan follows &lt;strong&gt;MIT 6.5840 (Distributed Systems) Raft lab structure&lt;/strong&gt; — each stage isolates a bug class:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Stage A: Leader election&lt;/li&gt;
&lt;li&gt;Stage B: Log replication&lt;/li&gt;
&lt;li&gt;Stage C: Persistence + crash recovery&lt;/li&gt;
&lt;li&gt;Stage D: Log compaction / snapshotting&lt;/li&gt;
&lt;li&gt;Stage E: Chaos testing&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a href="https://github.com/subhansh-dev/raft-rs" rel="noopener noreferrer"&gt;https://github.com/subhansh-dev/raft-rs&lt;/a&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Email:&lt;/strong&gt; &lt;a href="mailto:me@subhansh.dev"&gt;me@subhansh.dev&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;portfolio:&lt;/strong&gt; &lt;a href="https://subhansh.dev" rel="noopener noreferrer"&gt;https://subhansh.dev&lt;/a&gt;&lt;/p&gt;

</description>
      <category>rust</category>
      <category>raft</category>
      <category>consensus</category>
      <category>distributedsystems</category>
    </item>
    <item>
      <title>I built a programming language because C++ almost killed my drone</title>
      <dc:creator>subhansh</dc:creator>
      <pubDate>Sun, 12 Jul 2026 19:00:41 +0000</pubDate>
      <link>https://dev.to/subhansh/i-built-a-programming-language-because-c-almost-killed-my-drone-34l7</link>
      <guid>https://dev.to/subhansh/i-built-a-programming-language-because-c-almost-killed-my-drone-34l7</guid>
      <description>&lt;p&gt;I'm 17. Last year I was writing drone firmware in C++ and Python. One afternoon my ultrasonic sensor returned &lt;code&gt;null&lt;/code&gt; during a landing sequence. The code didn't check for it. The drone tried to divide by zero, the motor controller panicked, and my DJI Tello-sized quadcopter dropped from 3 meters onto concrete.&lt;/p&gt;

&lt;p&gt;That was a $400 lesson in why runtime errors in robotics aren't just bugs. They're physics problems.&lt;/p&gt;

&lt;p&gt;So I built a programming language.&lt;/p&gt;




&lt;h2&gt;
  
  
  The problem nobody talks about
&lt;/h2&gt;

&lt;p&gt;When you're writing a web app and something crashes, you reload the page. When you're writing drone code and something crashes, the drone crashes. Into whatever's below it. Usually something expensive or fragile or alive.&lt;/p&gt;

&lt;p&gt;C++ and Python dominate robotics. Both assume you'll handle edge cases yourself. Sensor returns &lt;code&gt;null&lt;/code&gt;? That's your problem. Timing deadline missed? Good luck. No fallback path for when the lidar fails over water? Figure it out.&lt;/p&gt;

&lt;p&gt;ROS (Robot Operating System) helps with some of this, but it's an entire infrastructure layer. What I wanted was something simpler: a language where the compiler catches the stuff that kills robots before you ever compile it.&lt;/p&gt;

&lt;p&gt;Here's what I mean. In C++, you write:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="n"&gt;distance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sensor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;read&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="n"&gt;speed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;target_distance&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;distance&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;motor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;speed&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If &lt;code&gt;distance&lt;/code&gt; is 0, you get a division by zero. If &lt;code&gt;sensor.read()&lt;/code&gt; returns &lt;code&gt;NaN&lt;/code&gt;, you get &lt;code&gt;NaN&lt;/code&gt; propagation through your motor controller. The compiler doesn't care. It'll happily compile this and let your drone fall out of the sky.&lt;/p&gt;

&lt;p&gt;In Fabric (the language I built), you'd write:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="n"&gt;sensor&lt;/span&gt; &lt;span class="n"&gt;distance&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Sensor&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;f32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="err"&gt;±&lt;/span&gt;&lt;span class="mf"&gt;0.02&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="n"&gt;actuator&lt;/span&gt; &lt;span class="n"&gt;motor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Motor&lt;/span&gt;

&lt;span class="k"&gt;loop&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;speed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;target_distance&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;distance&lt;/span&gt;
    &lt;span class="n"&gt;motor&lt;/span&gt;&lt;span class="nf"&gt;.write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;speed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you try to use &lt;code&gt;distance&lt;/code&gt; without checking that the sensor returned a valid reading, the compiler throws an error. If &lt;code&gt;distance&lt;/code&gt; could be zero and you didn't add a fallback path, the compiler throws an error. If your sensor has an uncertainty bound of ±0.02 and you're doing math that could amplify that uncertainty past a safety threshold, the compiler throws an error.&lt;/p&gt;

&lt;p&gt;The compiler knows about physics. Not perfectly, but enough to catch the stuff that actually kills robots.&lt;/p&gt;




&lt;h2&gt;
  
  
  How it works under the hood
&lt;/h2&gt;

&lt;p&gt;I wrote the whole thing in Rust. About 4,500 lines across 8 crates. Here's the pipeline:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.fab source → Lexer → Parser → AST → Type Checker → Fallback Graph → IPET Timing → CodeGen → .py / .c
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each step catches a different category of mistakes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The type system&lt;/strong&gt; tracks sensor uncertainty as a first-class concept. When you declare &lt;code&gt;Sensor&amp;lt;f32, ±0.02&amp;gt;&lt;/code&gt;, that &lt;code&gt;±0.02&lt;/code&gt; isn't decoration. It propagates through every math operation. Add two sensors with ±0.02 uncertainty and the result has ±0.04. Multiply by a constant and the uncertainty scales accordingly. If the final result's uncertainty exceeds what's safe for your actuator, the compiler catches it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The fallback graph&lt;/strong&gt; checks that every sensor has a plan B. Not just declared, but actually reachable. If your fallback function A calls fallback function B, and B calls A, that's a cycle. The compiler detects it. If sensor X has no fallback at all, the compiler refuses to build.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;IPET timing analysis&lt;/strong&gt; uses an Integer Linear Program to prove worst-case execution time at compile time. It builds a control flow graph, assigns cycle costs to each instruction (ARM Cortex-M4 model: ALU = 1 cycle, float division = 14 cycles, sensor read = 2 cycles), and solves for the maximum possible execution time across all code paths including loops.&lt;/p&gt;

&lt;p&gt;I didn't come up with this technique. It's from Li &amp;amp; Malik's 1994 paper on implicit path enumeration. But I implemented it in Rust using a pure-Rust ILP solver called &lt;code&gt;good_lp&lt;/code&gt; with the &lt;code&gt;microlp&lt;/code&gt; backend. No external solver dependency. No C FFI. Just Rust solving linear programs.&lt;/p&gt;

&lt;p&gt;The solver maximizes &lt;code&gt;sum(cost_i * x_i)&lt;/code&gt; subject to flow conservation constraints. If the solver fails (which happens on really complex control flow), the system falls back to a conservative estimate instead of crashing.&lt;/p&gt;




&lt;h2&gt;
  
  
  The two-target code generation
&lt;/h2&gt;

&lt;p&gt;Fabric compiles to two backends: Python for Webots simulation, and C for ARM Cortex-M hardware.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Python output&lt;/strong&gt; generates a Webots controller class with sensor initialization, motor setup, fallback state tracking, and all the logic. You can test your drone code in simulation before touching hardware.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C output&lt;/strong&gt; generates code that includes a &lt;code&gt;hal.h&lt;/code&gt; hardware abstraction layer. Static sensor handles, &lt;code&gt;#define TIMEOUT_MS&lt;/code&gt; for fallback deadlines, proper C types (&lt;code&gt;float&lt;/code&gt;, &lt;code&gt;int&lt;/code&gt;), and deadline enforcement using &lt;code&gt;hal_get_time_ms()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Same source file, two completely different targets. No &lt;code&gt;#ifdef&lt;/code&gt; in your code. No conditional compilation. The compiler handles the target-specific stuff.&lt;/p&gt;




&lt;h2&gt;
  
  
  What I'd do differently
&lt;/h2&gt;

&lt;p&gt;The parser is hand-rolled. About 700 lines of Pratt parser with recursive descent for statements. I started with chumsky (a Rust parser combinator library) but their API changed between versions and the documentation was sparse when I needed it most. So I wrote my own.&lt;/p&gt;

&lt;p&gt;It's fine. But it means every time I want to add a new syntax construct, I'm writing parser code by hand. A proper parser generator would've saved time in the long run, even with the initial investment.&lt;/p&gt;

&lt;p&gt;The loop bound estimation is a heuristic. If your loop body has 1-3 statements, the compiler assumes it runs 10 times. 4-6 statements? 5 times. 7+? 3 times. This is obviously wrong for real programs. Proper static bound analysis would make the IPET results much more accurate. It's on my list.&lt;/p&gt;

&lt;p&gt;The C output references a &lt;code&gt;clamp()&lt;/code&gt; function that it never defines. If you actually try to compile the generated C code on hardware, you'll get a linker error. I know about it. I just haven't fixed it yet.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why I'm publishing this
&lt;/h2&gt;

&lt;p&gt;I put all 8 crates on crates.io. The lexer, parser, type checker, everything. The repo is at github.com/subhansh-dev/fabric.&lt;/p&gt;

&lt;p&gt;Partly because I want other people to try it. If you're working on robotics or drones and you've been bitten by runtime errors, Fabric might save you some pain.&lt;/p&gt;

&lt;p&gt;Mostly because I think the idea matters more than my implementation. The safety-critical systems world has had formal methods and static analysis for decades. But it's all locked behind expensive tools and enterprise licenses. I wanted to build something that a 17-year-old with a Raspberry Pi could use.&lt;/p&gt;

&lt;p&gt;Is my implementation perfect? No. The IPET loop bounds are guesses. The C backend doesn't handle drone swarms. The match expression codegen references some variables it doesn't always generate. I know about all of these. They're bugs, not features, and I'll fix them.&lt;/p&gt;

&lt;p&gt;But the core idea is sound: compile-time safety for robotics shouldn't require a $50,000 license for Simulink. Sometimes the right answer to "how do we prevent this bug" isn't "write better tests" or "add more runtime checks." Sometimes it's "make the compiler say no."&lt;/p&gt;




&lt;h2&gt;
  
  
  What's next
&lt;/h2&gt;

&lt;p&gt;I'm working on adding hardware-in-the-loop testing support. The idea is that Fabric could instrument your actual hardware and compare runtime sensor readings against the compile-time uncertainty bounds. If reality diverges from what the compiler predicted, you get a warning before your next flight.&lt;/p&gt;

&lt;p&gt;Also working on proper static loop bound analysis. The current heuristic is fine for demos but useless for real deployments. I'm looking at abstract interpretation techniques to actually prove bounds instead of guessing.&lt;/p&gt;

&lt;p&gt;If any of this sounds interesting, check out the repo. Open an issue. Try it on your own robot. Break it and tell me how.&lt;/p&gt;

&lt;p&gt;That's how this gets better.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Fabric is MIT licensed. The crates are published on crates.io. The docs are in the README because I'm 17 and haven't written proper docs yet.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;gh repo link :- &lt;a href="https://github.com/subhansh-dev/fabric" rel="noopener noreferrer"&gt;https://github.com/subhansh-dev/fabric&lt;/a&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>rust</category>
      <category>robotics</category>
      <category>compilers</category>
    </item>
    <item>
      <title>[Boost]</title>
      <dc:creator>subhansh</dc:creator>
      <pubDate>Wed, 08 Jul 2026 17:48:55 +0000</pubDate>
      <link>https://dev.to/subhansh/-kl3</link>
      <guid>https://dev.to/subhansh/-kl3</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/subhansh/i-built-a-free-toolkit-that-makes-any-ai-coding-agent-write-better-code-3c0g" class="crayons-story__hidden-navigation-link"&gt;I Built a Free Toolkit That Makes Any AI Coding Agent Write Better Code&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/subhansh" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3932783%2Fec98af63-4dd3-4af0-85ce-d5c0b76ebf45.png" alt="subhansh profile" class="crayons-avatar__image" width="81" height="76"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/subhansh" class="crayons-story__secondary fw-medium m:hidden"&gt;
              subhansh
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                subhansh
                
              
              &lt;div id="story-author-preview-content-4099300" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/subhansh" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3932783%2Fec98af63-4dd3-4af0-85ce-d5c0b76ebf45.png" class="crayons-avatar__image" alt="" width="81" height="76"&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;subhansh&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/subhansh/i-built-a-free-toolkit-that-makes-any-ai-coding-agent-write-better-code-3c0g" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Jul 8&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/subhansh/i-built-a-free-toolkit-that-makes-any-ai-coding-agent-write-better-code-3c0g" id="article-link-4099300"&gt;
          I Built a Free Toolkit That Makes Any AI Coding Agent Write Better Code
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/ai"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;ai&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/productivity"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;productivity&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/opensource"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;opensource&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/agentskills"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;agentskills&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/subhansh/i-built-a-free-toolkit-that-makes-any-ai-coding-agent-write-better-code-3c0g" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;1&lt;span class="hidden s:inline"&gt;&amp;nbsp;reaction&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/subhansh/i-built-a-free-toolkit-that-makes-any-ai-coding-agent-write-better-code-3c0g#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

              &lt;span class="hidden s:inline"&gt;Add&amp;nbsp;Comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            4 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


</description>
    </item>
    <item>
      <title>I Built a Free Toolkit That Makes Any AI Coding Agent Write Better Code</title>
      <dc:creator>subhansh</dc:creator>
      <pubDate>Wed, 08 Jul 2026 17:46:45 +0000</pubDate>
      <link>https://dev.to/subhansh/i-built-a-free-toolkit-that-makes-any-ai-coding-agent-write-better-code-3c0g</link>
      <guid>https://dev.to/subhansh/i-built-a-free-toolkit-that-makes-any-ai-coding-agent-write-better-code-3c0g</guid>
      <description>&lt;h1&gt;
  
  
  I Extracted 95+ Skills From Claude Fable 5, GPT-5.5, and Gemini CLI Into One Free Repo
&lt;/h1&gt;

&lt;p&gt;Your AI coding agent is powerful but generic. It writes code with purple gradients, opens responses with "Great question!", and ships skeletons instead of working code.&lt;/p&gt;

&lt;p&gt;I fixed that.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/subhansh-dev/agent-maxxing" rel="noopener noreferrer"&gt;Agent Maxxing&lt;/a&gt;&lt;/strong&gt; is a free, open-source collection of 95+ production-ready skills, 19 UI components, and 7 system prompts — extracted from the leaked system prompts of the world's best AI agents.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem
&lt;/h2&gt;

&lt;p&gt;Every AI coding agent has the same personality:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Starts every response with praise ("Great question!", "Absolutely!")&lt;/li&gt;
&lt;li&gt;Writes code with no error handling ("Here's a skeleton, you fill it in")&lt;/li&gt;
&lt;li&gt;Uses purple-to-blue gradients everywhere&lt;/li&gt;
&lt;li&gt;Sounds like a corporate press release&lt;/li&gt;
&lt;li&gt;Asks permission for low-risk actions instead of just doing them&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The root cause? Their system prompts are generic. They don't know your design system, your coding standards, or how to sound like a human.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Solution
&lt;/h2&gt;

&lt;p&gt;I extracted the actual system prompts from:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Claude Fable 5&lt;/strong&gt; (3,826 lines) — personality, memory system, tone, refusal handling&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GPT-5.5 Codex&lt;/strong&gt; (11,104 lines) — engineering judgment, frontend rules, formatting&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Gemini CLI&lt;/strong&gt; (254 lines) — context efficiency, sub-agent orchestration&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Claude Code&lt;/strong&gt; (1,798 lines) — tool usage, code review methodology, agent delegation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then I organized everything into 9 skill categories with 95+ individual skill files.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's Inside
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Engineering (22 skills)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Deep Code Review&lt;/strong&gt; — 8-angle methodology from Claude Code bundled skills&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security Review&lt;/strong&gt; — Senior security engineer audit with false-positive filtering&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Execution Protocol&lt;/strong&gt; — "Solve it, don't ask about it" problem-solving chain&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Debugging Patterns&lt;/strong&gt; — Systematic methodology for finding and fixing bugs&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;API Design&lt;/strong&gt; — REST patterns, status codes, pagination&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Database Patterns&lt;/strong&gt; — Schema design, indexing, migrations&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Performance Patterns&lt;/strong&gt; — Lazy loading, caching, memoization&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Frontend Design (16 skills)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Anti-Patterns&lt;/strong&gt; — What makes AI output look AI-generated&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Artifact Design&lt;/strong&gt; — Deliberate design choices from Claude Code&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Motion Design&lt;/strong&gt; — Timing, easing, enter/exit patterns&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Typography&lt;/strong&gt; — Font pairing, scale, typographic systems&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Responsive Design&lt;/strong&gt; — Breakpoints, fluid layouts&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  UI Components (19 patterns)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Glass Card, Gradient Button, Modal Dialog, Tabs, Dropdown, Avatar, Progress Bar, Badge, Toggle Switch, Accordion, Tooltip, Navbar, Data Table, Loading Skeleton, Toast Notification, Breadcrumb, Pagination, Animated Input&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  System Prompts (7 modules)
&lt;/h3&gt;

&lt;p&gt;Extracted and intelligently curated from leaked prompts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Agent Core Personality&lt;/strong&gt; — From Claude Fable 5&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Coding Excellence&lt;/strong&gt; — From GPT-5.5 Codex&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reasoning &amp;amp; Planning&lt;/strong&gt; — From Codex Plan Mode&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Frontend Mastery&lt;/strong&gt; — From GPT-5.5 + Claude Design&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Agent Orchestration&lt;/strong&gt; — From Claude Code + Gemini CLI&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tone &amp;amp; Communication&lt;/strong&gt; — From Fable 5 + Codex + Cursor&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How It Works
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Installation
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Clone the repo&lt;/span&gt;
git clone https://github.com/subhansh-dev/agent-maxxing.git

&lt;span class="c"&gt;# Install for your agent&lt;/span&gt;
&lt;span class="nb"&gt;cp&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; agent-maxxing ~/.claude/skills/agent-maxxing  &lt;span class="c"&gt;# Claude Code&lt;/span&gt;
&lt;span class="nb"&gt;cp&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; agent-maxxing ~/.codex/skills/agent-maxxing   &lt;span class="c"&gt;# Codex CLI&lt;/span&gt;
&lt;span class="nb"&gt;cp&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; agent-maxxing .cursor/skills/agent-maxxing    &lt;span class="c"&gt;# Cursor&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The Lazy Prompt
&lt;/h3&gt;

&lt;p&gt;Paste this to your agent and it self-fine-tunes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Deep dive into the agent-maxxing folder. Read every .md file — every skill, every system prompt, every component, every workflow example. Understand what each file teaches. Then fine-tune yourself: adopt the patterns, internalize the anti-patterns, apply the engineering judgment, use the writing style. Integrate all 95+ skills so you can use them on any task. From now on, before responding to anything, check if a relevant skill exists and apply it.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  How Agent Self-Fine-Tuning Works
&lt;/h3&gt;

&lt;p&gt;It's not weight training — it's &lt;strong&gt;context injection&lt;/strong&gt;. When an agent reads a skill file:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The file content enters the agent's context window&lt;/li&gt;
&lt;li&gt;The agent internalizes the patterns for that session&lt;/li&gt;
&lt;li&gt;It applies those patterns to every subsequent response&lt;/li&gt;
&lt;li&gt;The behavior changes without retraining&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The more skills it reads, the better it gets. The &lt;code&gt;FINE-TUNE-AGENT.md&lt;/code&gt; walks the agent through every skill category in order.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Anti-Patterns (What Agents Stop Doing)
&lt;/h2&gt;

&lt;p&gt;After fine-tuning, your agent will:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Stop&lt;/strong&gt; opening with "Great question!" or "Absolutely!"&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stop&lt;/strong&gt; using purple-to-blue gradients in every design&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stop&lt;/strong&gt; shipping skeleton code ("Here's a basic implementation")&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stop&lt;/strong&gt; hedging with "It seems like..." or "It appears that..."&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stop&lt;/strong&gt; asking permission for low-risk actions&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Start&lt;/strong&gt; writing code with proper error handling&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Start&lt;/strong&gt; matching the existing codebase style&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Start&lt;/strong&gt; sounds like a human, not a press release&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Start&lt;/strong&gt; reviewing code with 8-angle methodology&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Start&lt;/strong&gt; shipping working code, not skeletons&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Golden Rules
&lt;/h2&gt;

&lt;p&gt;Every top agent in this collection follows these:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Search before answering&lt;/strong&gt; — Never guess when you can check&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Read the codebase first&lt;/strong&gt; — Don't assume, investigate&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Parallel tool calls&lt;/strong&gt; — Independent operations run simultaneously&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Match existing patterns&lt;/strong&gt; — Follow the repo's conventions&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Show, don't tell&lt;/strong&gt; — Demonstrate with examples&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Be concise&lt;/strong&gt; — Short paragraphs, flat lists, no filler&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Take ownership&lt;/strong&gt; — Fix mistakes, don't deflect&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Respect the user's time&lt;/strong&gt; — Don't ask what you can figure out&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ship working code&lt;/strong&gt; — Not skeletons, not "you'll need to add..."&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sound human&lt;/strong&gt; — Not like a press release or corporate blog&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Compatible With 60+ Agents
&lt;/h2&gt;

&lt;p&gt;Works with any agent supporting the &lt;a href="https://agentskills.io/specification" rel="noopener noreferrer"&gt;Agent Skills specification&lt;/a&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Claude Code&lt;/li&gt;
&lt;li&gt;Codex CLI&lt;/li&gt;
&lt;li&gt;OpenCode&lt;/li&gt;
&lt;li&gt;Cursor&lt;/li&gt;
&lt;li&gt;Continue&lt;/li&gt;
&lt;li&gt;Kilo Code&lt;/li&gt;
&lt;li&gt;OpenClaw&lt;/li&gt;
&lt;li&gt;Pi Agent&lt;/li&gt;
&lt;li&gt;Hermes&lt;/li&gt;
&lt;li&gt;Gemini CLI&lt;/li&gt;
&lt;li&gt;And 50+ more&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What Makes This Different
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Agent Maxxing&lt;/th&gt;
&lt;th&gt;Generic Skill Packs&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Source&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Extracted from Claude Fable 5, GPT-5.5, Gemini CLI&lt;/td&gt;
&lt;td&gt;Community-written prompts&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Depth&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;95+ skills covering engineering, design, writing, security&lt;/td&gt;
&lt;td&gt;5-10 surface-level tips&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Components&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;19 production-ready UI patterns with CSS&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;System Prompts&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;7 fine-tuned personality modules&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Anti-Slop&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Dedicated anti-patterns + writing style guide&lt;/td&gt;
&lt;td&gt;"Be helpful"&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Try It Now
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Clone the repo&lt;/li&gt;
&lt;li&gt;Install for your agent&lt;/li&gt;
&lt;li&gt;Paste the lazy prompt&lt;/li&gt;
&lt;li&gt;Watch your agent transform
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;github.com/subhansh-dev/agent-maxxing
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;MIT licensed. Zero dependencies. Just markdown.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Built by a 17-year-old who got tired of generic AI output.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>productivity</category>
      <category>opensource</category>
      <category>agentskills</category>
    </item>
    <item>
      <title>[Boost]</title>
      <dc:creator>subhansh</dc:creator>
      <pubDate>Sun, 05 Jul 2026 20:25:41 +0000</pubDate>
      <link>https://dev.to/subhansh/-5819</link>
      <guid>https://dev.to/subhansh/-5819</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/subhansh/i-pointed-my-ai-research-engine-at-goldbachs-conjecture-it-found-a-hidden-bias-2026-1phl" class="crayons-story__hidden-navigation-link"&gt;I Pointed My AI Research Engine at Goldbach's Conjecture — It Found a Hidden Bias (2026)&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/subhansh" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3932783%2Fec98af63-4dd3-4af0-85ce-d5c0b76ebf45.png" alt="subhansh profile" class="crayons-avatar__image" width="81" height="76"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/subhansh" class="crayons-story__secondary fw-medium m:hidden"&gt;
              subhansh
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                subhansh
                
              
              &lt;div id="story-author-preview-content-4062006" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/subhansh" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3932783%2Fec98af63-4dd3-4af0-85ce-d5c0b76ebf45.png" class="crayons-avatar__image" alt="" width="81" height="76"&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;subhansh&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/subhansh/i-pointed-my-ai-research-engine-at-goldbachs-conjecture-it-found-a-hidden-bias-2026-1phl" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Jul 3&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/subhansh/i-pointed-my-ai-research-engine-at-goldbachs-conjecture-it-found-a-hidden-bias-2026-1phl" id="article-link-4062006"&gt;
          I Pointed My AI Research Engine at Goldbach's Conjecture — It Found a Hidden Bias (2026)
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/math"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;math&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/primes"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;primes&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/ai"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;ai&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/goldbach"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;goldbach&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
            &lt;a href="https://dev.to/subhansh/i-pointed-my-ai-research-engine-at-goldbachs-conjecture-it-found-a-hidden-bias-2026-1phl#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

              &lt;span class="hidden s:inline"&gt;Add&amp;nbsp;Comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            2 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


</description>
    </item>
    <item>
      <title>I Pointed My AI Research Engine at Goldbach's Conjecture — It Found a Hidden Bias (2026)</title>
      <dc:creator>subhansh</dc:creator>
      <pubDate>Fri, 03 Jul 2026 17:07:06 +0000</pubDate>
      <link>https://dev.to/subhansh/i-pointed-my-ai-research-engine-at-goldbachs-conjecture-it-found-a-hidden-bias-2026-1phl</link>
      <guid>https://dev.to/subhansh/i-pointed-my-ai-research-engine-at-goldbachs-conjecture-it-found-a-hidden-bias-2026-1phl</guid>
      <description>&lt;p&gt;As a developer building AI for scientific discovery, I wanted to test if autonomous research actually works. So I built &lt;a href="https://github.com/subhansh-dev" rel="noopener noreferrer"&gt;Luka&lt;/a&gt; and pointed it at Goldbach's conjecture.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Background
&lt;/h2&gt;

&lt;p&gt;Goldbach's conjecture: every even integer &amp;gt; 2 is the sum of two primes. Verified up to 4 × 10¹⁸, but the distributional properties are poorly understood.&lt;/p&gt;

&lt;p&gt;The Hardy–Littlewood formula predicts the count of representations r(n):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;r(n) ≈ 2C₂ · ∏_{p|n} (p-1)/(p-2) · n/(ln n)²
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's symmetric — predicts the same count for n ≡ 1 (mod 3) and n ≡ 2 (mod 3). I built &lt;a href="https://github.com/subhansh-dev" rel="noopener noreferrer"&gt;Luka&lt;/a&gt; to check if that's actually true.&lt;/p&gt;

&lt;p&gt;It's not.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Luka Discovered
&lt;/h2&gt;

&lt;p&gt;Luka computed Goldbach partition counts for &lt;strong&gt;2,495,001 even integers&lt;/strong&gt; (10,000 to 5,000,000). Split by residue class mod 3:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Class&lt;/th&gt;
&lt;th&gt;Mean g(n)&lt;/th&gt;
&lt;th&gt;Count&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;n ≡ 0 (mod 3)&lt;/td&gt;
&lt;td&gt;19,607.1&lt;/td&gt;
&lt;td&gt;831,667&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;n ≡ 1 (mod 3)&lt;/td&gt;
&lt;td&gt;9,816.6&lt;/td&gt;
&lt;td&gt;831,667&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;n ≡ 2 (mod 3)&lt;/td&gt;
&lt;td&gt;9,791.0&lt;/td&gt;
&lt;td&gt;831,667&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;n ≡ 1 (mod 3) has 0.26% more Goldbach representations than n ≡ 2 (mod 3).&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The Hardy–Littlewood formula says they should be equal. It's wrong.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Statistics Are Insane
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Paired t-test (831,666 pairs): t = 9.02, &lt;strong&gt;p = 2.0 × 10⁻¹⁹&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Sign test: p = &lt;strong&gt;4.07 × 10⁻²⁰⁴&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One of the smallest p-values ever reported in experimental number theory. This isn't a fluke.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Mechanism
&lt;/h2&gt;

&lt;p&gt;The bias propagates through &lt;strong&gt;prime-pair channels&lt;/strong&gt;. Twin prime pairs (p, p+2) contribute ~15–20% of r(n). For n ≡ 1 (mod 3), this channel is systematically enhanced because:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Chebyshev bias favors primes ≡ 2 (mod 3)&lt;/li&gt;
&lt;li&gt;For n ≡ 1 (mod 3), the complementary prime q = n - p satisfies q ≡ 2 (mod 3)&lt;/li&gt;
&lt;li&gt;Twin primes preferentially contribute when n ≡ 1 (mod 3)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The Chebyshev bias in primes &lt;strong&gt;propagates&lt;/strong&gt; to Goldbach counts.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Correction
&lt;/h2&gt;

&lt;p&gt;Luka proposed a Dirichlet character correction:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;r(n) ≈ Hardy–Littlewood + A₃χ₃(n) · n¹ᐟ²/(ln n)²
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A₃ = 1.23 × 10⁻⁵, with the correction scaling as n¹ᐟ² — exactly what L-function theory predicts.&lt;/p&gt;

&lt;h2&gt;
  
  
  The RS Gap
&lt;/h2&gt;

&lt;p&gt;The Rubinstein–Sarnak heuristic &lt;strong&gt;underestimates&lt;/strong&gt; the Goldbach bias by 4–10×. Why? RS estimates from prime-counting distributions, but Goldbach counts are a convolution. The bilinear structure amplifies the bias by the singular series S(n).&lt;/p&gt;

&lt;h2&gt;
  
  
  The Takeaway
&lt;/h2&gt;

&lt;p&gt;I'm a developer, not a mathematician. I built an AI research engine to see if it could do real discovery. Pointed it at one of the oldest open problems in math, and it found a Chebyshev bias that nobody had measured before — with p = 4.07 × 10⁻²⁰⁴.&lt;/p&gt;

&lt;p&gt;The times are not far when AI systems will make serious mathematical discoveries autonomously. This is a proof of concept.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code &amp;amp; Data
&lt;/h2&gt;

&lt;p&gt;GitHub: &lt;a href="https://github.com/subhansh-dev/goldbach-chebyshev-bias" rel="noopener noreferrer"&gt;github.com/subhansh-dev/goldbach-chebyshev-bias&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Python, NumPy, SciPy, 2.5M Goldbach counts (6.3 MB). Built with &lt;a href="https://github.com/subhansh-dev" rel="noopener noreferrer"&gt;Luka&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>math</category>
      <category>primes</category>
      <category>ai</category>
      <category>goldbach</category>
    </item>
    <item>
      <title>I Built an AI Research Engine and It Found a Perfect Power Law in Twin Primes (2026)</title>
      <dc:creator>subhansh</dc:creator>
      <pubDate>Fri, 03 Jul 2026 17:07:05 +0000</pubDate>
      <link>https://dev.to/subhansh/i-built-an-ai-research-engine-and-it-found-a-perfect-power-law-in-twin-primes-2026-4g65</link>
      <guid>https://dev.to/subhansh/i-built-an-ai-research-engine-and-it-found-a-perfect-power-law-in-twin-primes-2026-4g65</guid>
      <description>&lt;p&gt;I'm a developer, not a number theorist. But I built &lt;a href="https://github.com/subhansh-dev" rel="noopener noreferrer"&gt;Luka&lt;/a&gt; — an autonomous AI research engine — and pointed it at one of math's oldest open problems. What it found blew my mind.&lt;/p&gt;

&lt;h2&gt;
  
  
  How It Started
&lt;/h2&gt;

&lt;p&gt;I'm a developer who builds AI frameworks. One day I had an idea: what if I could build an engine that autonomously investigates open problems in mathematics? Not just answer questions — actually &lt;em&gt;research&lt;/em&gt; them. Run computations, test hypotheses, falsify models, write papers.&lt;/p&gt;

&lt;p&gt;I called it &lt;a href="https://github.com/subhansh-dev" rel="noopener noreferrer"&gt;Luka&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The first thing I pointed it at was the twin prime conjecture — the idea that there are infinitely many pairs of primes differing by 2, like (3,5), (11,13), (17,19). Hardy and Littlewood gave us a formula for this back in 1923:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;π₂(x) ≈ 2C₂x / (log x)²
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's elegant. It's widely used. And Luka found that it's systematically wrong.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Luka Found
&lt;/h2&gt;

&lt;p&gt;Using verified twin prime counts from 10⁶ to 10¹⁴ (33 data points across 8 orders of magnitude), Luka discovered that the residual — the gap between prediction and reality — follows a &lt;strong&gt;perfect power law&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;R(x) ≈ 6.6 × 10⁻³ · x⁰·⁸⁶
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;R² = 0.9907.&lt;/strong&gt; But there's more. The exponent drifts, so the true model is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;R(x) ≈ C · xᵅ · (log x)^β     →    R² = 0.9997
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bootstrap resampling (10,000 iterations) confirms α = 0.8635 ± 0.015. This isn't any known mathematical constant — it's something new.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Critical Insight
&lt;/h2&gt;

&lt;p&gt;The residual isn't about twin primes at all. The simplified formula &lt;code&gt;2C₂x/(log x)²&lt;/code&gt; is an approximation to the full integral &lt;code&gt;2C₂∫dt/(log t)²&lt;/code&gt;. The difference is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;∆(x) = 2C₂(Li(x) - x/log x - x/(log x)²)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the &lt;strong&gt;second-order term&lt;/strong&gt; in the asymptotic expansion of Li(x). It follows a &lt;strong&gt;perfect power law with R² &amp;gt; 0.9999&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;∆(x) ≈ 2.2 × 10⁻³ · x⁰·⁹⁰
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The power law characterizes the systematic error in the simplified approximation, not the true twin prime residual.&lt;/p&gt;

&lt;h2&gt;
  
  
  Falsifying a Model
&lt;/h2&gt;

&lt;p&gt;A recent preprint proposed PRIT — an oscillatory model using Riemann zeta zeros. Luka tested it with 200 zeros computed to 25-digit precision.&lt;/p&gt;

&lt;p&gt;The predictions were off by &lt;strong&gt;factors of 100–700&lt;/strong&gt; with wrong signs. The model is falsified by two orders of magnitude.&lt;/p&gt;

&lt;h2&gt;
  
  
  Extrapolation
&lt;/h2&gt;

&lt;p&gt;Luka trained on just 4 data points (10⁶–10⁹) and predicted π₂(10¹⁰) with &lt;strong&gt;0.99% error&lt;/strong&gt;. Trained on 5 points, predicted π₂(10¹¹) with &lt;strong&gt;1.15% error&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Bigger Picture
&lt;/h2&gt;

&lt;p&gt;I built Luka to prove that AI can do real scientific discovery — not just pattern matching on existing knowledge, but finding new structures, falsifying models, and generating testable predictions.&lt;/p&gt;

&lt;p&gt;This paper is the first result. The power law in the twin prime residual doesn't appear in any standard reference. It was found autonomously by an AI system I built as a developer.&lt;/p&gt;

&lt;p&gt;The times are not far when AI systems like Luka will make serious discoveries in mathematics, physics, and beyond. We're not there yet — but we're closer than most people think.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code &amp;amp; Data
&lt;/h2&gt;

&lt;p&gt;GitHub: &lt;a href="https://github.com/subhansh-dev/twin-prime-power-law" rel="noopener noreferrer"&gt;github.com/subhansh-dev/twin-prime-power-law&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Python, NumPy, verified computations from Nicely's database. Built with &lt;a href="https://github.com/subhansh-dev" rel="noopener noreferrer"&gt;Luka&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>math</category>
      <category>primes</category>
      <category>ai</category>
      <category>research</category>
    </item>
    <item>
      <title>I Pointed My AI Research Engine at Goldbach's Conjecture — It Found a Hidden Bias</title>
      <dc:creator>subhansh</dc:creator>
      <pubDate>Fri, 03 Jul 2026 17:05:12 +0000</pubDate>
      <link>https://dev.to/subhansh/i-pointed-my-ai-research-engine-at-goldbachs-conjecture-it-found-a-hidden-bias-44pn</link>
      <guid>https://dev.to/subhansh/i-pointed-my-ai-research-engine-at-goldbachs-conjecture-it-found-a-hidden-bias-44pn</guid>
      <description>&lt;p&gt;As a developer building AI for scientific discovery, I wanted to test if autonomous research actually works. So I built &lt;a href="https://github.com/subhansh-dev" rel="noopener noreferrer"&gt;Luka&lt;/a&gt; and pointed it at Goldbach's conjecture.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Background
&lt;/h2&gt;

&lt;p&gt;Goldbach's conjecture: every even integer &amp;gt; 2 is the sum of two primes. Verified up to 4 × 10¹⁸, but the distributional properties are poorly understood.&lt;/p&gt;

&lt;p&gt;The Hardy–Littlewood formula predicts the count of representations r(n):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;r(n) ≈ 2C₂ · ∏_{p|n} (p-1)/(p-2) · n/(ln n)²
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's symmetric — predicts the same count for n ≡ 1 (mod 3) and n ≡ 2 (mod 3). I built &lt;a href="https://github.com/subhansh-dev" rel="noopener noreferrer"&gt;Luka&lt;/a&gt; to check if that's actually true.&lt;/p&gt;

&lt;p&gt;It's not.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Luka Discovered
&lt;/h2&gt;

&lt;p&gt;Luka computed Goldbach partition counts for &lt;strong&gt;2,495,001 even integers&lt;/strong&gt; (10,000 to 5,000,000). Split by residue class mod 3:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Class&lt;/th&gt;
&lt;th&gt;Mean g(n)&lt;/th&gt;
&lt;th&gt;Count&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;n ≡ 0 (mod 3)&lt;/td&gt;
&lt;td&gt;19,607.1&lt;/td&gt;
&lt;td&gt;831,667&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;n ≡ 1 (mod 3)&lt;/td&gt;
&lt;td&gt;9,816.6&lt;/td&gt;
&lt;td&gt;831,667&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;n ≡ 2 (mod 3)&lt;/td&gt;
&lt;td&gt;9,791.0&lt;/td&gt;
&lt;td&gt;831,667&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;n ≡ 1 (mod 3) has 0.26% more Goldbach representations than n ≡ 2 (mod 3).&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The Hardy–Littlewood formula says they should be equal. It's wrong.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Statistics Are Insane
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Paired t-test (831,666 pairs): t = 9.02, &lt;strong&gt;p = 2.0 × 10⁻¹⁹&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Sign test: p = &lt;strong&gt;4.07 × 10⁻²⁰⁴&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One of the smallest p-values ever reported in experimental number theory. This isn't a fluke.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Mechanism
&lt;/h2&gt;

&lt;p&gt;The bias propagates through &lt;strong&gt;prime-pair channels&lt;/strong&gt;. Twin prime pairs (p, p+2) contribute ~15–20% of r(n). For n ≡ 1 (mod 3), this channel is systematically enhanced because:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Chebyshev bias favors primes ≡ 2 (mod 3)&lt;/li&gt;
&lt;li&gt;For n ≡ 1 (mod 3), the complementary prime q = n - p satisfies q ≡ 2 (mod 3)&lt;/li&gt;
&lt;li&gt;Twin primes preferentially contribute when n ≡ 1 (mod 3)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The Chebyshev bias in primes &lt;strong&gt;propagates&lt;/strong&gt; to Goldbach counts.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Correction
&lt;/h2&gt;

&lt;p&gt;Luka proposed a Dirichlet character correction:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;r(n) ≈ Hardy–Littlewood + A₃χ₃(n) · n¹ᐟ²/(ln n)²
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A₃ = 1.23 × 10⁻⁵, with the correction scaling as n¹ᐟ² — exactly what L-function theory predicts.&lt;/p&gt;

&lt;h2&gt;
  
  
  The RS Gap
&lt;/h2&gt;

&lt;p&gt;The Rubinstein–Sarnak heuristic &lt;strong&gt;underestimates&lt;/strong&gt; the Goldbach bias by 4–10×. Why? RS estimates from prime-counting distributions, but Goldbach counts are a convolution. The bilinear structure amplifies the bias by the singular series S(n).&lt;/p&gt;

&lt;h2&gt;
  
  
  The Takeaway
&lt;/h2&gt;

&lt;p&gt;I'm a developer, not a mathematician. I built an AI research engine to see if it could do real discovery. Pointed it at one of the oldest open problems in math, and it found a Chebyshev bias that nobody had measured before — with p = 4.07 × 10⁻²⁰⁴.&lt;/p&gt;

&lt;p&gt;The times are not far when AI systems will make serious mathematical discoveries autonomously. This is a proof of concept.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code &amp;amp; Data
&lt;/h2&gt;

&lt;p&gt;GitHub: &lt;a href="https://github.com/subhansh-dev/goldbach-chebyshev-bias" rel="noopener noreferrer"&gt;github.com/subhansh-dev/goldbach-chebyshev-bias&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Python, NumPy, SciPy, 2.5M Goldbach counts (6.3 MB). Built with &lt;a href="https://github.com/subhansh-dev" rel="noopener noreferrer"&gt;Luka&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>math</category>
      <category>primes</category>
      <category>ai</category>
      <category>goldbach</category>
    </item>
    <item>
      <title>I Built an AI Research Engine and It Found a Perfect Power Law in Twin Primes</title>
      <dc:creator>subhansh</dc:creator>
      <pubDate>Fri, 03 Jul 2026 17:05:11 +0000</pubDate>
      <link>https://dev.to/subhansh/i-built-an-ai-research-engine-and-it-found-a-perfect-power-law-in-twin-primes-12ba</link>
      <guid>https://dev.to/subhansh/i-built-an-ai-research-engine-and-it-found-a-perfect-power-law-in-twin-primes-12ba</guid>
      <description>&lt;p&gt;I'm a developer, not a number theorist. But I built &lt;a href="https://github.com/subhansh-dev" rel="noopener noreferrer"&gt;Luka&lt;/a&gt; — an autonomous AI research engine — and pointed it at one of math's oldest open problems. What it found blew my mind.&lt;/p&gt;

&lt;h2&gt;
  
  
  How It Started
&lt;/h2&gt;

&lt;p&gt;I'm a developer who builds AI frameworks. One day I had an idea: what if I could build an engine that autonomously investigates open problems in mathematics? Not just answer questions — actually &lt;em&gt;research&lt;/em&gt; them. Run computations, test hypotheses, falsify models, write papers.&lt;/p&gt;

&lt;p&gt;I called it &lt;a href="https://github.com/subhansh-dev" rel="noopener noreferrer"&gt;Luka&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The first thing I pointed it at was the twin prime conjecture — the idea that there are infinitely many pairs of primes differing by 2, like (3,5), (11,13), (17,19). Hardy and Littlewood gave us a formula for this back in 1923:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;π₂(x) ≈ 2C₂x / (log x)²
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's elegant. It's widely used. And Luka found that it's systematically wrong.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Luka Found
&lt;/h2&gt;

&lt;p&gt;Using verified twin prime counts from 10⁶ to 10¹⁴ (33 data points across 8 orders of magnitude), Luka discovered that the residual — the gap between prediction and reality — follows a &lt;strong&gt;perfect power law&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;R(x) ≈ 6.6 × 10⁻³ · x⁰·⁸⁶
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;R² = 0.9907.&lt;/strong&gt; But there's more. The exponent drifts, so the true model is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;R(x) ≈ C · xᵅ · (log x)^β     →    R² = 0.9997
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bootstrap resampling (10,000 iterations) confirms α = 0.8635 ± 0.015. This isn't any known mathematical constant — it's something new.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Critical Insight
&lt;/h2&gt;

&lt;p&gt;The residual isn't about twin primes at all. The simplified formula &lt;code&gt;2C₂x/(log x)²&lt;/code&gt; is an approximation to the full integral &lt;code&gt;2C₂∫dt/(log t)²&lt;/code&gt;. The difference is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;∆(x) = 2C₂(Li(x) - x/log x - x/(log x)²)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the &lt;strong&gt;second-order term&lt;/strong&gt; in the asymptotic expansion of Li(x). It follows a &lt;strong&gt;perfect power law with R² &amp;gt; 0.9999&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;∆(x) ≈ 2.2 × 10⁻³ · x⁰·⁹⁰
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The power law characterizes the systematic error in the simplified approximation, not the true twin prime residual.&lt;/p&gt;

&lt;h2&gt;
  
  
  Falsifying a Model
&lt;/h2&gt;

&lt;p&gt;A recent preprint proposed PRIT — an oscillatory model using Riemann zeta zeros. Luka tested it with 200 zeros computed to 25-digit precision.&lt;/p&gt;

&lt;p&gt;The predictions were off by &lt;strong&gt;factors of 100–700&lt;/strong&gt; with wrong signs. The model is falsified by two orders of magnitude.&lt;/p&gt;

&lt;h2&gt;
  
  
  Extrapolation
&lt;/h2&gt;

&lt;p&gt;Luka trained on just 4 data points (10⁶–10⁹) and predicted π₂(10¹⁰) with &lt;strong&gt;0.99% error&lt;/strong&gt;. Trained on 5 points, predicted π₂(10¹¹) with &lt;strong&gt;1.15% error&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Bigger Picture
&lt;/h2&gt;

&lt;p&gt;I built Luka to prove that AI can do real scientific discovery — not just pattern matching on existing knowledge, but finding new structures, falsifying models, and generating testable predictions.&lt;/p&gt;

&lt;p&gt;This paper is the first result. The power law in the twin prime residual doesn't appear in any standard reference. It was found autonomously by an AI system I built as a developer.&lt;/p&gt;

&lt;p&gt;The times are not far when AI systems like Luka will make serious discoveries in mathematics, physics, and beyond. We're not there yet — but we're closer than most people think.&lt;/p&gt;

&lt;h2&gt;
  
  
  Code &amp;amp; Data
&lt;/h2&gt;

&lt;p&gt;GitHub: &lt;a href="https://github.com/subhansh-dev/twin-prime-power-law" rel="noopener noreferrer"&gt;github.com/subhansh-dev/twin-prime-power-law&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Python, NumPy, verified computations from Nicely's database. Built with &lt;a href="https://github.com/subhansh-dev" rel="noopener noreferrer"&gt;Luka&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>math</category>
      <category>primes</category>
      <category>ai</category>
      <category>research</category>
    </item>
  </channel>
</rss>
