<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Arjun K Varkey on Medium]]></title>
        <description><![CDATA[Stories by Arjun K Varkey on Medium]]></description>
        <link>https://medium.com/@arjunkvarkey?source=rss-17f4d119992c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*CQ_dzRBW5Z4mk7BU.jpg</url>
            <title>Stories by Arjun K Varkey on Medium</title>
            <link>https://medium.com/@arjunkvarkey?source=rss-17f4d119992c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 18:43:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@arjunkvarkey/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[I Built a Tool to Watch Code Rot. Then I Pointed It at Flask.]]></title>
            <link>https://medium.com/@arjunkvarkey/i-built-a-tool-to-watch-code-rot-then-i-pointed-it-at-flask-535b9be43c26?source=rss-17f4d119992c------2</link>
            <guid isPermaLink="false">https://medium.com/p/535b9be43c26</guid>
            <dc:creator><![CDATA[Arjun K Varkey]]></dc:creator>
            <pubDate>Mon, 16 Nov 2026 15:06:10 GMT</pubDate>
            <atom:updated>2026-11-16T15:54:22.715Z</atom:updated>
            <content:encoded><![CDATA[<h3>Every commit looked fine</h3><p>If you’ve let an AI coding agent work on the same codebase for a few weeks, you might know the feeling. Each change passes review. Each diff is reasonable. Then one day you open a file and find a 200-line function that handles nine different cases, and you can’t remember agreeing to any of it.</p><p>Nothing broke. The code just got worse, a little at a time, in a way no single pull request shows.</p><p>I wanted to see that happen as a number on a chart instead of a vague feeling. So I built a small tool that measures it, ran it on 13 years of real Python history, and learned more from what my own tool got wrong than from what it got right.</p><p>One honest note up front: I built it with an AI pair programmer. A tool for catching AI code rot, written with an AI. I’ll come back to why that turned out to matter.</p><h3><strong>The paper that gave it a number</strong></h3><p>The starting point was <a href="https://arxiv.org/abs/2603.24755">SlopCodeBench</a>, a 2026 paper by Gabriel Orlanski and colleagues. They gave 15 coding agents a set of programming problems, then kept changing the requirements. Each agent had to extend its own earlier code, checkpoint after checkpoint, the way real projects grow.</p><p>Three results stuck with me:</p><ul><li>The code got worse almost every time. Their measure of structural decay rose in 77% of agent runs, and redundant code rose in 75.5%.</li><li>Agents were worse than people. Compared with 473 human-maintained Python projects, agent code was 2.3 times more verbose and twice as eroded.</li><li>Telling the agent to write clean code didn’t fix it. Quality instructions lowered the starting point by up to a third. The rate of decline stayed the same.</li></ul><p>That last one is the uncomfortable part. You can’t prompt your way out of it. If decay is gradual, you need something that watches the trend.</p><p>The paper defines its two measures with exact formulas. I wanted those formulas as a tool I could point at any repo, run in CI, and trust. So I built one.</p><h3>What I built: slopwatch</h3><p><a href="https://github.com/Arjun-K-Varkey/slopwatch">slopwatch</a> is a small Python command-line tool with no dependencies. It measures the paper’s two numbers.</p><p><strong>Structural erosion</strong> asks: how much of your code’s complexity is piled into a few overloaded functions? Every function gets a weight, its complexity times the square root of its length. Erosion is the share of the total weight held by functions with a complexity above 10. A codebase where complexity is spread out scores near 0%. One with a handful of monster functions scores high.</p><p><strong>Verbosity</strong> asks: how much of your code is redundant? It counts lines that match known wasteful patterns (things like if x == True or building a list with an append loop) plus lines that are copy-pasted elsewhere, even with the variable names changed. Then it divides by total lines of code.</p><p>The tool does three things with those numbers:</p><pre>slopwatch scan src/ # how does the code look today? slopwatch history . -n 100 --step 20 # how has it changed across commits? slopwatch check src/ --base origin/main # did this pull request make it worse?</pre><p>The last one is the point. check runs in CI as a GitHub Action and fails the pull request if erosion or verbosity rises past a threshold you set. That’s the guard the paper says prompting can’t give you.</p><h3>What 13 years of real Python looks like</h3><p>I wanted a baseline from code that humans have maintained for years, so I picked three well-known Python HTTP libraries: requests, flask and httpx. I counted library code only, leaving out tests, docs and examples.</p><p>Here’s where they stand today:</p><ul><li><strong>requests</strong>: 4,743 lines of code, 38.1% erosion, 3.5% verbosity. Most complex function: HTTPAdapter.send</li><li><strong>flask</strong>: 7,009 lines of code, 27.2% erosion, 8.9% verbosity. Most complex function: Blueprint.register</li><li><strong>httpx</strong>: 7,091 lines of code, 17.3% erosion, 16.6% verbosity. Most complex function: urlparse</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*77bhZBpxoBkm2Fh-.png" /></figure><p>Then I ran each project’s history, about 100 commits sampled evenly across 7 to 13 years.</p><p>The flat lines surprised me most. requests stayed between 34% and 43% erosion for 13 years. Across the sampled steps, its erosion fell 41 times and rose 38 times. flask fell 34 times and rose 45; httpx fell 49 times and rose 38. Somebody keeps paying the complexity back down.</p><p>httpx still ended higher than it started, and the chart shows why. It climbed from 0% to about 15% in its first year, while it grew from 620 to about 5,000 lines. Since 2021 it has stayed between 15% and 22%.</p><p>That’s the opposite of the paper’s agents, whose code eroded in 77% of runs. The comparison isn’t exact. One of my steps covers 9 to 19 commits, and the paper’s steps are agent checkpoints. But the difference is clear. Over years, maintainers pull erosion back down almost as often as it goes up. In the paper’s runs, the agents mostly added.</p><p>Two other things showed up:</p><ul><li>A small number of functions carry most of the weight. Only 1.6% to 4.9% of functions in these projects are highly complex, but they hold 17% to 38% of the complexity. That’s 7 to 13 functions per project. If you only have time to refactor a handful this year, the tool tells you which ones.</li><li>A high number needs context. Most of httpx’s copy-pasted lines (637 of 1,156) live in one file, which keeps separate Client and AsyncClient versions on purpose. The tool is right that the code is duplicated. Whether that’s a problem is a design decision, not something a metric can settle.</li></ul><h3>Real code embarrassed my tool three times</h3><p>The first version had a full test suite, and every test passed. Then I ran it on code I didn’t write, and later went through the code line by line. That’s where the real problems showed up.</p><p><strong>1. It flagged good code as waste.</strong> One rule marks an exception handler that only re-raises as pointless. On Python’s own asyncio library it fired 46 times, on lines like except KeyboardInterrupt: raise. Those aren’t pointless. They sit in front of a broader except on purpose, so that Ctrl-C still stops the program. The handler is only redundant when it’s the last one, so I changed the rule to check that.</p><p><strong>2. The charts fell off a cliff that wasn’t there.</strong> In flask’s early history, erosion would suddenly drop to 0%. The code hadn’t improved. Early flask was written in Python 2, and Python 3 can’t parse a line like print “hello”. The tool was quietly skipping those files and scoring whatever was left. Of 100 commits sampled across flask’s whole history, 61 were affected. The tool now warns you when it skips files, and the charts in this post start once each project was fully Python 3.</p><p><strong>3. The quality gate had a back door.</strong> When I reviewed the code later, I found the worst one. A pull request could add a huge, tangled function in a file with a syntax error. That file would be skipped, erosion wouldn’t move, and check would print PASS. The gate meant to catch hidden complexity could be beaten by hiding it in a file it couldn’t read. Version 0.2.1 fails the check when a change adds a file it can’t parse.</p><p>This is why the AI pair programmer matters to the story. It wrote working code quickly, and the tests passed. But none of these three problems showed up in the tests. They showed up when I ran the tool on real code and when I questioned its results. That’s the same lesson the paper teaches: code can pass every check and still be wrong in ways you only see by looking at it over time.</p><h3>What it can’t tell you</h3><p>A few honest limits, because a metric you trust too much is worse than none:</p><ul><li>It’s a simpler version of the paper’s setup. The paper uses 137 pattern rules for verbosity. slopwatch has 17, so its verbosity numbers run lower. Comparing a project with its own past is reliable. Comparing raw numbers with the paper is not.</li><li>It measures shape, not correctness. A function with a complexity of 46, like httpx’s urlparse, may be exactly as complex as URL parsing needs to be. The tool points at it. You decide.</li><li>It only reads Python. And only Python your interpreter can parse.</li></ul><p>If you’re using AI agents on a codebase you plan to keep, my advice is short. Watch the trend, not the snapshot. A single erosion number tells you little. A line that only goes up tells you a lot, and by the time you feel it in review, it’s months old.</p><h3>Try it on your own repo</h3><p>It takes a minute:</p><pre>pip install git+https://github.com/Arjun-K-Varkey/slopwatch slopwatch scan src/ slopwatch history . -n 50 --format html</pre><p>The code, the GitHub Action and the full results are on <a href="https://github.com/Arjun-K-Varkey/slopwatch">GitHub</a>. If you run it on a project you know well, I’d really like to hear what the chart shows, especially if an AI agent has been doing a lot of the writing. And if it flags something that isn’t actually a problem, tell me. Every real fix so far started with the tool being wrong about real code.</p><p><em>If you’d like the next one, I’m writing up what happens when I run slopwatch on a codebase built mostly by an agent. Subscribe and it’ll land in your inbox.</em></p><p><em>Originally published at </em><a href="https://arjunkvarkey.substack.com/p/i-built-a-tool-to-watch-code-rot"><em>https://arjunkvarkey.substack.com</em></a><em> on November 16, 2026.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=535b9be43c26" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>