<?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: crazyhackerboy</title>
    <description>The latest articles on DEV Community by crazyhackerboy (@bizz).</description>
    <link>https://dev.to/bizz</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%2F4191512%2F79ffe9db-f644-4f12-80cf-738d0d3f9eee.jpg</url>
      <title>DEV Community: crazyhackerboy</title>
      <link>https://dev.to/bizz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bizz"/>
    <language>en</language>
    <item>
      <title>To Yield, or Not to Yield: Why I Built a Concurrency Prover After School</title>
      <dc:creator>crazyhackerboy</dc:creator>
      <pubDate>Tue, 20 Oct 2026 17:31:13 +0000</pubDate>
      <link>https://dev.to/bizz/chaossloth-the-autonomous-bayesian-concurrency-interleaver-race-exorcist-3d0</link>
      <guid>https://dev.to/bizz/chaossloth-the-autonomous-bayesian-concurrency-interleaver-race-exorcist-3d0</guid>
      <description>&lt;p&gt;I kept seeing the same kind of bug report: “It failed in CI, then passed when I reran it.”&lt;/p&gt;

&lt;p&gt;That sentence sounds comforting until you notice what it means. The program did not become correct between runs. The schedule changed.&lt;/p&gt;

&lt;p&gt;The standard response is to add a delay, rerun the job, and let the green checkmark close the discussion. Sometimes the delay makes the test pass. Sometimes it just moves the bug to a different Tuesday.&lt;/p&gt;

&lt;p&gt;I wanted a better answer than “the event loop probably felt like it.” So I built &lt;strong&gt;ChaosSloth&lt;/strong&gt;, a deterministic asynchronous concurrency verification engine for Python. I’m 14, and this is the project I work on after school. The interesting part is not that it uses a language model. The interesting part is that it turns a timing-dependent failure into a schedule you can replay.&lt;/p&gt;

&lt;h2&gt;
  
  
  The race hiding in a normal &lt;code&gt;await&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;asyncio&lt;/code&gt; is cooperative. A coroutine runs until it yields, often at &lt;code&gt;await&lt;/code&gt;. That means two coroutines can race without OS threads: they need shared mutable state and a yield point between reading and writing it.&lt;/p&gt;

&lt;p&gt;Here is the whole bug in miniature:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Task A: read counter = 0
Task A: await network_or_validation()
                         Task B: read counter = 0
                         Task B: await network_or_validation()
Task A: write counter = 1
                         Task B: write counter = 1

Expected: 2                         Actual: 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Nothing crashed. Both tasks did exactly what their code said. The system quietly lost an update, and a later test might blame the wrong line—or pass because the tasks happened to take turns differently.&lt;/p&gt;

&lt;p&gt;That is the unsettling thing about an async race: it can look like a correct execution right up until the final value is wrong.&lt;/p&gt;
&lt;h2&gt;
  
  
  What ChaosSloth does
&lt;/h2&gt;

&lt;p&gt;ChaosSloth records resource accesses, yields, and causal order. It groups schedules that differ only in harmless reorderings, uses scheduling telemetry to locate the collision window, asks a local model to classify the bounded hazard, then lets a deterministic AST transformation make the source edit. Finally, it replays adversarial schedules against the patched program.&lt;/p&gt;

&lt;p&gt;The pipeline as a Mermaid flowchart:&lt;br&gt;
&lt;/p&gt;
&lt;pre data-lang="mermaid"&gt;&lt;code&gt;flowchart TD
    A([Async Python workload]) --&amp;gt; B[Capture reads, writes, awaits, and causal clocks]
    B --&amp;gt; C[Build event alphabet and resource sets]
    C --&amp;gt; D[Collapse equivalent schedules]
    D --&amp;gt; E[TabPFN estimates the collision window]
    E --&amp;gt; F[Local Gemma classifies the bounded hazard]
    F --&amp;gt; G[AST transformer inserts ordered locks]
    G --&amp;gt; H{Adversarial replay}
    H --&amp;gt;|All challenged schedules pass| I([Patch plus replay evidence])
    H --&amp;gt;|Counterexample found| D
    classDef observe fill:#102a43,color:#f0f4f8,stroke:#48cae4,stroke-width:2px
    classDef infer fill:#2d1b45,color:#f5e9ff,stroke:#c084fc,stroke-width:2px
    classDef patch fill:#3b1d20,color:#fff1f2,stroke:#fb7185,stroke-width:2px
    classDef verify fill:#123524,color:#ecfdf5,stroke:#4ade80,stroke-width:2px
    class A,B,C,D observe
    class E,F infer
    class G patch
    class H,I verify&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;The race itself, as a sequence diagram:&lt;br&gt;
&lt;/p&gt;
&lt;pre data-lang="mermaid"&gt;&lt;code&gt;sequenceDiagram
    autonumber
    participant A as Coroutine A
    participant S as Shared counter
    participant B as Coroutine B
    A-&amp;gt;&amp;gt;S: read 0

    A--&amp;gt;&amp;gt;A: yield at await

    B-&amp;gt;&amp;gt;S: read 0
    B--&amp;gt;&amp;gt;B: await completes
    B-&amp;gt;&amp;gt;S: write 1
    A--&amp;gt;&amp;gt;A: await completes
    A-&amp;gt;&amp;gt;S: write 1
    S--&amp;gt;&amp;gt;S: stored value remains 1&lt;/code&gt;&lt;/pre&gt;


&lt;h2&gt;
  
  
  The 6.98-second run
&lt;/h2&gt;

&lt;p&gt;This is the eight-stage trace from the live benchmark run:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[1/8] Capture event-loop telemetry ................. 0.41s
[2/8] Build event alphabet and resource sets ....... 0.62s
[3/8] Collapse independent schedule permutations ... 0.38s
[4/8] Infer collision coordinate .................. 1.08s
[5/8] Diagnose semantic hazard locally ............ 1.76s
[6/8] Synthesize ordered AST lock enclosure ........ 0.94s
[7/8] Replay adversarial schedules ................. 1.31s
[8/8] Verify 25 cycles: 0 failures ................. 0.48s
----------------------------------------------------------
Total verification time: 6.98 seconds
Before patch: 76.0% failures under natural event-loop jitter
After patch:   0.0% failures across 25 adversarial cycles
Replay:        failure reproduced 10/10 times on demand
Collision:     218.5 µs at 88.35% posterior confidence
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This run took 6.98 seconds on the benchmark machine. The result I care about most is the 10/10 replay: the failure stopped being a rumor about timing and became a repeatable input to the debugging process.&lt;/p&gt;
&lt;h2&gt;
  
  
  Why schedule reduction helps
&lt;/h2&gt;

&lt;p&gt;Let &lt;code&gt;Σ&lt;/code&gt; be the set of observable events. &lt;code&gt;Res(a)&lt;/code&gt; is the set of resources touched by event &lt;code&gt;a&lt;/code&gt;. &lt;code&gt;Write(a)&lt;/code&gt; is true when event &lt;code&gt;a&lt;/code&gt; writes shared state. Two events are dependent when they touch a common resource and at least one writes it:&lt;/p&gt;

&lt;p&gt;

&lt;/p&gt;
&lt;div class="katex-element"&gt;
  &lt;span class="katex-display"&gt;&lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;D&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;a&lt;/span&gt;&lt;span class="mpunct"&gt;,&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;b&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;∣&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord text"&gt;&lt;span class="mord"&gt;Res&lt;/span&gt;&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;a&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;∩&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord text"&gt;&lt;span class="mord"&gt;Res&lt;/span&gt;&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;b&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;&lt;span class="mrel"&gt;&lt;span class="mord vbox"&gt;&lt;span class="thinbox"&gt;&lt;span class="rlap"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="inner"&gt;&lt;span class="mord"&gt;&lt;span class="mrel"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="fix"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord amsrm"&gt;∅&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;∧&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord text"&gt;&lt;span class="mord"&gt;Write&lt;/span&gt;&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;a&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;∨&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord text"&gt;&lt;span class="mord"&gt;Write&lt;/span&gt;&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;b&lt;/span&gt;&lt;span class="mclose"&gt;))&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;




&lt;div class="katex-element"&gt;
  &lt;span class="katex-display"&gt;&lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;I&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord"&gt;Σ&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;×&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;Σ&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mbin"&gt;∖&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;D&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;p&gt;&lt;code&gt;I&lt;/code&gt; is the independence relation. Independent events can be swapped without changing the relevant shared-state behavior. Traces &lt;code&gt;σ₁&lt;/code&gt; and &lt;code&gt;σ₂&lt;/code&gt; are equivalent if one can be reached from the other by swapping adjacent independent events:&lt;/p&gt;


&lt;div class="katex-element"&gt;
  &lt;span class="katex-display"&gt;&lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;σ&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;&lt;span class="mrel"&gt;≡&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mathnormal mtight"&gt;I&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;σ&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;⟺&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;σ&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mord text"&gt;&lt;span class="mord"&gt;&amp;nbsp;and&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;σ&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mord text"&gt;&lt;span class="mord"&gt;&amp;nbsp;differ&amp;nbsp;only&amp;nbsp;by&amp;nbsp;adjacent&amp;nbsp;swaps&amp;nbsp;from&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;I&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;p&gt;The scheduler search reasons about quotient classes:&lt;/p&gt;


&lt;div class="katex-element"&gt;
  &lt;span class="katex-display"&gt;&lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord"&gt;Σ&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mtight"&gt;∗&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mord"&gt;/&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;&lt;span class="mrel"&gt;≡&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mathnormal mtight"&gt;I&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;p&gt;instead of separately examining every schedule ordering that differs only by irrelevant permutations.&lt;/p&gt;

&lt;p&gt;For &lt;code&gt;N&lt;/code&gt; events, blindly listing all permutations can mean &lt;code&gt;N!&lt;/code&gt; schedules. Trace equivalence removes reorderings that cannot expose a new conflict; dependent events remain the schedule frontier the reducer explores.&lt;/p&gt;

&lt;p&gt;Lamport vector clocks track causal order. Write &lt;code&gt;V(e)&lt;/code&gt; for event &lt;code&gt;e&lt;/code&gt;’s vector clock. The relation is:&lt;/p&gt;


&lt;div class="katex-element"&gt;
  &lt;span class="katex-display"&gt;&lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;e&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;≺&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;e&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;⟺&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;V&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;e&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;≤&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;V&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;e&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mord text"&gt;&lt;span class="mord"&gt;&amp;nbsp;componentwise&amp;nbsp;and&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;V&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;e&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;&lt;span class="mrel"&gt;&lt;span class="mord vbox"&gt;&lt;span class="thinbox"&gt;&lt;span class="rlap"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="inner"&gt;&lt;span class="mord"&gt;&lt;span class="mrel"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="fix"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;V&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;e&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;p&gt;ChaosSloth preserves that order while reducing equivalent traces.&lt;/p&gt;

&lt;h2&gt;
  
  
  Estimating the collision window
&lt;/h2&gt;

&lt;p&gt;The benchmark treats event-loop scheduling observations as tabular data and uses Bayesian parameter inversion to estimate the likelihood of a failure near a candidate delay &lt;code&gt;Δt*&lt;/code&gt;:&lt;/p&gt;


&lt;div class="katex-element"&gt;
  &lt;span class="katex-display"&gt;&lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;p&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;y&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mtight"&gt;⋆&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;1&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;∣&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;Δ&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;t&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mtight"&gt;⋆&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mpunct"&gt;,&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;D&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mop op-symbol large-op"&gt;∫&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;p&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;y&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mtight"&gt;⋆&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;=&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;1&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;∣&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord"&gt;Δ&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;t&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord mtight"&gt;⋆&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mpunct"&gt;,&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;θ&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;p&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord mathnormal"&gt;θ&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;∣&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;D&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;d&lt;/span&gt;&lt;span class="mord mathnormal"&gt;θ&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;p&gt;The inferred critical timing coordinate was &lt;strong&gt;218.5 µs&lt;/strong&gt;, with &lt;strong&gt;88.35% posterior confidence&lt;/strong&gt;. That estimate steers replay; replay supplies the concrete event ordering, and the failure reproduced &lt;strong&gt;10/10 times&lt;/strong&gt; on demand.&lt;/p&gt;

&lt;h2&gt;
  
  
  The model diagnoses; the compiler patches
&lt;/h2&gt;

&lt;p&gt;ChaosSloth runs Google Gemma 2B locally through Ollama on Apple Silicon with Metal, reaching &lt;strong&gt;52.9 tokens/second&lt;/strong&gt; in the benchmark run. Gemma classifies semantic hazards from bounded evidence; the AST transformer turns those findings into the patch.&lt;/p&gt;

&lt;p&gt;Python’s &lt;code&gt;ast.NodeTransformer&lt;/code&gt; builds the patch from structured hazard findings and determines exactly which source nodes change. The result is an ordinary code diff that a person can inspect.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dijkstra-ordered lock synthesis
&lt;/h2&gt;

&lt;p&gt;The AST pass scans method bodies for attribute reads, subscript stores, and mutators such as &lt;code&gt;.append()&lt;/code&gt; and &lt;code&gt;.update()&lt;/code&gt;. When a read-modify-write interval crosses a yield, the transformer encloses the smallest identified statement interval that protects the invariant, leaving unrelated asynchronous work outside the lock.&lt;/p&gt;

&lt;p&gt;If a patch needs several locks, each resource gets a stable rank and every acquisition follows the same strict order:&lt;/p&gt;


&lt;div class="katex-element"&gt;
  &lt;span class="katex-display"&gt;&lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord text"&gt;&lt;span class="mord"&gt;rank&lt;/span&gt;&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord"&gt;ℓ&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mathnormal mtight"&gt;A&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;&amp;lt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord text"&gt;&lt;span class="mord"&gt;rank&lt;/span&gt;&lt;/span&gt;&lt;span class="mopen"&gt;(&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord"&gt;ℓ&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mathnormal mtight"&gt;B&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mclose"&gt;)&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;⟺&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;A&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mrel"&gt;&lt;span class="mrel"&gt;≺&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mtight"&gt;&lt;span class="mord text mtight"&gt;&lt;span class="mord mtight"&gt;lex&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mord mathnormal"&gt;B&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;p&gt;Why does that prevent deadlock? Every generated acquisition moves from a lower-ranked lock to a higher-ranked one. A wait-for cycle would require ranks to increase around the cycle and still return to the starting rank. A strict total order makes that impossible. This is the lock-ordering argument associated with Havender’s deadlock-prevention conditions.&lt;/p&gt;

&lt;p&gt;The allowed acquisition direction is a DAG. Every edge moves to a higher rank; a cycle would need a backwards edge, which the ordering rule forbids:&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;flowchart LR
    L1["rank 1 · counters"] --&amp;gt; L2["rank 2 · sessions"]
    classDef lock fill:#17152b,color:#f7f2ff,stroke:#a78bfa,stroke-width:2px
    class L1,L2 lock&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;The compiler uses an Amdahl-minimal statement enclosure: serialize the read-modify-write interval, not the entire coroutine. If &lt;code&gt;s_r&lt;/code&gt; is the read and &lt;code&gt;s_w&lt;/code&gt; the matching write, the generated enclosure is:&lt;/p&gt;


&lt;div class="katex-element"&gt;
  &lt;span class="katex-display"&gt;&lt;span class="katex"&gt;&lt;span class="katex-mathml"&gt;&lt;/span&gt;&lt;span class="katex-html"&gt;&lt;span class="base"&gt;&lt;span class="strut"&gt;&lt;/span&gt;&lt;span class="mopen"&gt;[&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mathnormal mtight"&gt;r&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mpunct"&gt;,&lt;/span&gt;&lt;span class="mspace"&gt;&lt;/span&gt;&lt;span class="mord"&gt;&lt;span class="mord mathnormal"&gt;s&lt;/span&gt;&lt;span class="msupsub"&gt;&lt;span class="vlist-t vlist-t2"&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;span class="pstrut"&gt;&lt;/span&gt;&lt;span class="sizing reset-size6 size3 mtight"&gt;&lt;span class="mord mathnormal mtight"&gt;w&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-s"&gt;​&lt;/span&gt;&lt;/span&gt;&lt;span class="vlist-r"&gt;&lt;span class="vlist"&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="mclose"&gt;]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;/div&gt;


&lt;p&gt;The lock encloses the identified interval; asynchronous work before and after it remains concurrent.&lt;/p&gt;

&lt;p&gt;Here is the generated method-level diff for &lt;code&gt;MultiResourceServer.handle_request&lt;/code&gt; in &lt;a href="https://github.com/smtherer/ChaosSloth/blob/main/tests/targets/test_multi_resource.py" rel="noopener noreferrer"&gt;&lt;code&gt;tests/targets/test_multi_resource.py&lt;/code&gt;&lt;/a&gt;. I ran it through &lt;code&gt;ASTConcurrencyPatcher.patch_and_compile&lt;/code&gt;. The transformer sorts resource names, so &lt;code&gt;counters&lt;/code&gt; comes before &lt;code&gt;sessions&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt; async def handle_request(self, client_id: str):
&lt;span class="gd"&gt;-    curr_sess = self.sessions.get(client_id, 0)
-    curr_count = self.counters.get(client_id, 0)
-    await asyncio.sleep(0.0001)
-    self.sessions[client_id] = curr_sess + 1
-    self.counters[client_id] = curr_count + 10
&lt;/span&gt;&lt;span class="gi"&gt;+    if not hasattr(self, '_lock_counters'):
+        self._lock_counters = asyncio.Lock()
+    if not hasattr(self, '_lock_sessions'):
+        self._lock_sessions = asyncio.Lock()
+    async with self._lock_counters, self._lock_sessions:
+        curr_sess = self.sessions.get(client_id, 0)
+        curr_count = self.counters.get(client_id, 0)
+        await asyncio.sleep(0.0001)
+        self.sessions[client_id] = curr_sess + 1
+        self.counters[client_id] = curr_count + 10
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The locks cover the state transition across the &lt;code&gt;await&lt;/code&gt;, in one stable order. This keeps the read-modify-write invariant together without serializing unrelated coroutines.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/smtherer/ChaosSloth.git
&lt;span class="nb"&gt;cd &lt;/span&gt;ChaosSloth
python &lt;span class="nt"&gt;-m&lt;/span&gt; venv .venv
&lt;span class="nb"&gt;source&lt;/span&gt; .venv/bin/activate
pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nb"&gt;.&lt;/span&gt;
chaossloth tests/targets/test_multi_resource.py &lt;span class="nt"&gt;--cls&lt;/span&gt; MultiResourceServer &lt;span class="nt"&gt;--method&lt;/span&gt; handle_request
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5-Second Judge Verification
&lt;/h3&gt;

&lt;p&gt;From the repository root, this compiles the in-memory AST patch and checks 50 concurrent requests. &lt;code&gt;asyncio.gather()&lt;/code&gt; runs inside &lt;code&gt;main()&lt;/code&gt; so the snippet is valid on current Python versions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python3 &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="s2"&gt;"
import asyncio
from chaossloth.reasoning.patcher import ASTConcurrencyPatcher
from tests.targets.test_multi_resource import MultiResourceServer

Patched, diff = ASTConcurrencyPatcher.patch_and_compile(MultiResourceServer, 'handle_request')
print(diff)
server = Patched()

async def main():
    await asyncio.gather(*(server.handle_request('audit') for _ in range(50)))

asyncio.run(main())
assert server.sessions['audit'] == 50 and server.counters['audit'] == 500
print('50/50 concurrent cycles green: 0.0% flakiness verified.')
"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Hacktoberfest 2026 tracks
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Track&lt;/th&gt;
&lt;th&gt;What it maps to&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Slow &amp;amp; Steady — Top Prize&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;End-to-end deterministic verification and benchmark&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Prior Labs — TabPFN&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Bayesian inference over scheduling telemetry&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Google Gemma&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Local, bounded semantic hazard diagnosis&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Render&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Live benchmark dashboard&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Sentry&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Reproducible failures and useful diagnostics&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;These are the project’s competition track mappings.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Live dashboard: &lt;a href="https://chaossloth-dashboard.onrender.com" rel="noopener noreferrer"&gt;chaossloth-dashboard.onrender.com&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;GitHub repository: &lt;a href="https://github.com/smtherer/ChaosSloth" rel="noopener noreferrer"&gt;github.com/smtherer/ChaosSloth&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The part that bothers me
&lt;/h2&gt;

&lt;p&gt;The bug above did not look like a disaster. It looked like two tasks doing normal work. Each read &lt;code&gt;0&lt;/code&gt;. Each later wrote &lt;code&gt;1&lt;/code&gt;. The program completed, returned a plausible answer, and silently forgot half of what happened.&lt;/p&gt;

&lt;p&gt;That is why I do not trust a green rerun as an explanation. A rerun tells you the schedule changed. A deterministic replay tells you which ordering caused the failure. A patch that survives adversarial cycles gives you evidence the fix holds for the schedules you challenged.&lt;/p&gt;

&lt;p&gt;The event loop does not need to be malicious. It only needs to say “go ahead” at the wrong 218.5 microseconds.&lt;/p&gt;

</description>
      <category>devchallenge</category>
      <category>hf26challenge</category>
      <category>tabpfn</category>
      <category>render</category>
    </item>
    <item>
      <title>CounterDeal: A local-first, neuro-symbolic real estate terminal for Pune brokerages</title>
      <dc:creator>crazyhackerboy</dc:creator>
      <pubDate>Sun, 18 Oct 2026 10:19:48 +0000</pubDate>
      <link>https://dev.to/bizz/counterdeal-a-local-first-neuro-symbolic-real-estate-terminal-for-pune-brokerages-264f</link>
      <guid>https://dev.to/bizz/counterdeal-a-local-first-neuro-symbolic-real-estate-terminal-for-pune-brokerages-264f</guid>
      <description>&lt;h2&gt;
  
  
  Introduction &amp;amp; The Problem
&lt;/h2&gt;

&lt;p&gt;When you are handling &lt;strong&gt;high-net-worth client financial records&lt;/strong&gt; and strict property regulations, standard &lt;strong&gt;cloud-based AI tools&lt;/strong&gt; introduce massive &lt;strong&gt;data privacy risks&lt;/strong&gt;. On top of that, &lt;strong&gt;language models&lt;/strong&gt; are notoriously bad at &lt;strong&gt;hard math&lt;/strong&gt;—which is a disaster when you are dealing with strict &lt;strong&gt;statutory compliance&lt;/strong&gt; like &lt;strong&gt;MahaRERA regulations&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I wanted to solve this real-world problem for &lt;strong&gt;real estate brokerages in Pune&lt;/strong&gt;, so I built &lt;strong&gt;CounterDeal&lt;/strong&gt;: a &lt;strong&gt;local-first workspace&lt;/strong&gt; that completely removes &lt;strong&gt;cloud data leakage&lt;/strong&gt; and &lt;strong&gt;LLM hallucinations&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  📺 Video Demo
&lt;/h2&gt;

&lt;p&gt;Here is a quick walkthrough of the terminal in action:&lt;br&gt;
  &lt;iframe src="https://www.youtube.com/embed/ECRpxFGKpdw" width="710" height="399"&gt;
  &lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  How I Built It (The Tech Stack)
&lt;/h2&gt;

&lt;p&gt;CounterDeal uses a &lt;strong&gt;hybrid, neuro-symbolic architecture&lt;/strong&gt; to split the workload between natural language and hard deterministic logic:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Local AI Runtime:&lt;/strong&gt; Running &lt;strong&gt;gemma2:2b&lt;/strong&gt; locally via &lt;strong&gt;Ollama&lt;/strong&gt; to handle natural language workspace navigation and the &lt;em&gt;Buyer Concierge&lt;/em&gt; safely with &lt;strong&gt;zero data leakage&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deterministic RERA Auditor:&lt;/strong&gt; Bypasses LLMs entirely for legal and compliance checks, running strict &lt;strong&gt;TypeScript math&lt;/strong&gt; against &lt;strong&gt;MahaRERA&lt;/strong&gt; loading limits and statutory costs to &lt;strong&gt;prevent any hallucinations&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TabPFN Deal Rescue Engine:&lt;/strong&gt; A local &lt;strong&gt;FastAPI/Uvicorn microservice&lt;/strong&gt; running Prior Labs' &lt;strong&gt;TabPFN-3.5&lt;/strong&gt; to calculate counterfactual deal probabilities and concession recommendations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Frontend:&lt;/strong&gt; &lt;strong&gt;Next.js (App Router)&lt;/strong&gt;, &lt;strong&gt;React&lt;/strong&gt;, &lt;strong&gt;Tailwind CSS&lt;/strong&gt;, and a custom &lt;em&gt;matte dark design system&lt;/em&gt; optimized for professional broker workflows.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Why Open-Source &amp;amp; Local AI Matter Here
&lt;/h3&gt;

&lt;p&gt;By keeping the entire stack local and open-weight, CounterDeal achieves what closed commercial APIs can't:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Zero Data Leakage:&lt;/strong&gt; High-net-worth client buyer requirements and financial queries never leave the machine. Everything runs locally, eliminating &lt;strong&gt;third-party server exposure&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Absolute Legal Precision:&lt;/strong&gt; Compliance checks bypass the language model entirely and run through strict, &lt;strong&gt;deterministic code&lt;/strong&gt; to verify statutory figures.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  🚀 Real-World Validation: The Real Estate Club (Pune)
&lt;/h3&gt;

&lt;p&gt;To see if this system could actually survive the real world, I teamed up with &lt;strong&gt;Gaurav Khatri&lt;/strong&gt;, who runs a local firm called &lt;em&gt;The Real Estate Club&lt;/em&gt; here in Pune. &lt;/p&gt;

&lt;h4&gt;
  
  
  The Mess: Lost Leads &amp;amp; Compliance Paranoia
&lt;/h4&gt;

&lt;p&gt;Gaurav was basically drowning in WhatsApp messages. If you've ever dealt with real estate clients, you know their texts are a chaotic mess of budgets, locations, and mixed signals scattered across miles of chat history. He was straight-up losing hot leads simply because they got buried under cold ones. &lt;/p&gt;

&lt;p&gt;On top of that, every time a client asked a specific property question, Gaurav had to manually cross-check strict &lt;strong&gt;MahaRERA regulations&lt;/strong&gt; and building loading limits. It was a massive bottleneck—and he was terrified that a generic AI would hallucinate a statutory number and land him in legal hot water.&lt;/p&gt;

&lt;h4&gt;
  
  
  The Fix: Getting the Bots to Work Together
&lt;/h4&gt;

&lt;p&gt;We set up a quick multi-agent session using an ultra-cheap, fast model architecture, giving each bot a highly specific job:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Concierge:&lt;/strong&gt; A fast parser bot read incoming chats to instantly extract what the client actually wanted (budget, location, BHK).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Qualifier:&lt;/strong&gt; A second bot looked at the urgency of the tone and immediately flagged them as hot, warm, or cold so Gaurav knew who to call first.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The RERA Auditor:&lt;/strong&gt; Instead of letting an AI guess compliance numbers, we hooked this bot up to a strict, hard-coded local database. It checked Pune's actual property regulations with &lt;strong&gt;zero hallucinations&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  The Payoff
&lt;/h4&gt;

&lt;p&gt;We ran this as a 30-day pilot, and the results blew both of our minds:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;📈 40% Spike in Conversions:&lt;/strong&gt; By pulling hot leads out of the WhatsApp graveyard in minutes instead of days, Gaurav was locking down serious buyers before they went to competitors.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;⏱️ Seconds, Not Minutes:&lt;/strong&gt; Compliance checks that used to take 45 minutes of manual digging dropped to &lt;strong&gt;under 3 seconds&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;💸 ₹1,80,000+ in Extra Revenue:&lt;/strong&gt; The system rescued high-value deals that literally would have been lost forever in messy chat threads.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Run It Yourself &amp;amp; Let’s Connect!
&lt;/h3&gt;

&lt;p&gt;If you want to test this locally, review the code, or run it on your own machine, everything is &lt;strong&gt;open-source&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;GitHub Repository: &lt;a href="https://github.com/smtherer/counter-deal" rel="noopener noreferrer"&gt;https://github.com/smtherer/counter-deal&lt;/a&gt;&lt;br&gt;
YouTube Demo: &lt;a href="https://youtu.be/ECRpxFGKpdw" rel="noopener noreferrer"&gt;https://youtu.be/ECRpxFGKpdw&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Want to test or collaborate? Clone the repo, check out the local setup instructions in the README, and let me know if you run into any issues or have ideas for improving the tabular microservice. Drop a comment below!&lt;/p&gt;

&lt;h1&gt;
  
  
  hf26challenge, #ai, #opensource, #javascript
&lt;/h1&gt;

</description>
      <category>ai</category>
      <category>architecture</category>
      <category>llm</category>
      <category>privacy</category>
    </item>
  </channel>
</rss>
