<?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:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0"><channel><title><![CDATA[Inalpha]]></title><description><![CDATA[I'm building Inalpha — quant agents that evolve under audit — and writing about it here. ADR walkthroughs, failure post-mortems, phase retros. ~1 post/month.]]></description><link>https://inalpha.substack.com</link><image><url>https://substackcdn.com/image/fetch/$s_!nBKZ!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73a66cfc-43c1-4eb6-a77e-4c42fa2f5110_1024x1024.png</url><title>Inalpha</title><link>https://inalpha.substack.com</link></image><generator>Substack</generator><lastBuildDate>Sat, 05 Dec 2026 02:43:09 GMT</lastBuildDate><atom:link href="https://inalpha.substack.com/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[Inalpha]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[inalpha@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[inalpha@substack.com]]></itunes:email><itunes:name><![CDATA[Inalpha]]></itunes:name></itunes:owner><itunes:author><![CDATA[Inalpha]]></itunes:author><googleplay:owner><![CDATA[inalpha@substack.com]]></googleplay:owner><googleplay:email><![CDATA[inalpha@substack.com]]></googleplay:email><googleplay:author><![CDATA[Inalpha]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[An AI writes my trading code. Three gates decide if it ever runs.]]></title><description><![CDATA[It tried to import os. The sandbox said no.]]></description><link>https://inalpha.substack.com/p/an-ai-writes-my-trading-code-three</link><guid isPermaLink="false">https://inalpha.substack.com/p/an-ai-writes-my-trading-code-three</guid><dc:creator><![CDATA[Inalpha]]></dc:creator><pubDate>Thu, 02 Jul 2026 02:47:55 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!Wn0-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3721be2f-0356-4933-8213-0df79a7d5ca3_1024x768.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Wn0-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3721be2f-0356-4933-8213-0df79a7d5ca3_1024x768.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Wn0-!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3721be2f-0356-4933-8213-0df79a7d5ca3_1024x768.png 424w, https://substackcdn.com/image/fetch/$s_!Wn0-!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3721be2f-0356-4933-8213-0df79a7d5ca3_1024x768.png 848w, https://substackcdn.com/image/fetch/$s_!Wn0-!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3721be2f-0356-4933-8213-0df79a7d5ca3_1024x768.png 1272w, https://substackcdn.com/image/fetch/$s_!Wn0-!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3721be2f-0356-4933-8213-0df79a7d5ca3_1024x768.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Wn0-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3721be2f-0356-4933-8213-0df79a7d5ca3_1024x768.png" width="1024" height="768" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3721be2f-0356-4933-8213-0df79a7d5ca3_1024x768.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:768,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1041959,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://inalpha.substack.com/i/204564329?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3721be2f-0356-4933-8213-0df79a7d5ca3_1024x768.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Wn0-!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3721be2f-0356-4933-8213-0df79a7d5ca3_1024x768.png 424w, https://substackcdn.com/image/fetch/$s_!Wn0-!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3721be2f-0356-4933-8213-0df79a7d5ca3_1024x768.png 848w, https://substackcdn.com/image/fetch/$s_!Wn0-!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3721be2f-0356-4933-8213-0df79a7d5ca3_1024x768.png 1272w, https://substackcdn.com/image/fetch/$s_!Wn0-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3721be2f-0356-4933-8213-0df79a7d5ca3_1024x768.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-nxj3kw" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-nxj3kw" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>A few months ago I built a system where an AI can write trading strategies &#8212; actual Python files &#8212; and then run them against real market data.</p><p>The first thing it wrote was a simple moving-average crossover. Clean, reasonable, made money in backtest. Cool.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://inalpha.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>The second thing it wrote tried to <code>import os</code>.</p><p>This post is about what happened next, and the three gates I built to make sure the answer is always &#8220;nice try, but no.&#8221;</p><h2>Why let an AI write code in the first place?</h2><p>In two earlier posts I talked about keeping an AI away from the order book &#8212; making sure it can&#8217;t place trades directly. Those were about controlling what the AI <em>wants</em> to do.</p><p>This is different. This is about letting the AI <em>write code</em>, and then actually running that code. Not picking from a menu. Not tuning a few parameters. Writing a complete trading strategy from scratch, 80 to 200 lines.</p><p>Why bother? Because the interesting strategies aren&#8217;t in the built-in library. A human quant might spend a week combining a Bollinger Band width filter with a volume-weighted entry and a time-decay exit. An AI can generate that in seconds. The creative possibilities are way beyond what you&#8217;d bother to hard-code.</p><p>But giving an AI the ability to write and run code introduces a new problem. The code might be dangerous &#8212; <code>import os</code>, read files, leak environment variables. Or it might be safe but worthless &#8212; an overfit noise machine that backtests beautifully on one slice of data and falls apart everywhere else.</p><p>Two independent problems. Two independent solutions. Sandbox catches the dangerous stuff. A fitness score catches the garbage.</p><h2>What I was actually afraid of</h2><p>Before writing any code, I sat down and listed every way an AI-written trading strategy could hurt me. Four categories:</p><p><strong>Escape.</strong> Python has a famous trick: <code>().__class__.__bases__[0].__subclasses__()</code> reaches into Python&#8217;s internals and gives you access to basically any class &#8212; file handles, network sockets, subprocesses. No <code>import</code> needed. Pure runtime trickery.</p><p><strong>Side-effect imports.</strong> Even a harmless-looking <code>import</code> runs that module&#8217;s initialization code. If the AI imports the wrong thing, damage happens before you can blink. So interception has to happen <em>before</em> the import, not after.</p><p><strong>Runtime hangs.</strong> A perfectly legal, perfectly clean function can still be an infinite loop or a memory bomb. The code looks fine to a static checker. It only misbehaves when you actually run it.</p><p><strong>Garbage that passes.</strong> The code is completely safe. No dangerous imports, no weird tricks. It&#8217;s also a hopelessly overfit mess &#8212; 300 trades on 500 bars, great numbers in-sample, zero predictive power out-of-sample. This isn&#8217;t a safety problem. But it fills your strategy library with noise.</p><p>The important thing I realized: these four problems happen at four <em>different moments</em>. After the AI writes the code. When the code imports things. When the code actually runs. After the backtest finishes. No single check catches them all. You need defenses spread across the whole timeline.</p><h2>Gate one: check the code before it runs</h2><p>The first gate is the simplest one, and it runs before a single line of the AI&#8217;s code executes.</p><p>I wrote a scanner that reads the AI&#8217;s Python file and checks it at the syntax level &#8212; no execution, no imports, just looking at the structure. Think of it like a security guard checking bags at the door.</p><p>It has three lists:</p><p><strong>Only these imports are allowed.</strong> <code>math</code>, <code>statistics</code>, <code>collections</code>, <code>dataclasses</code>, <code>typing</code>, <code>enum</code>, <code>json</code>. Seven modules, all pure computation, no filesystem, no network. Everything else the strategy needs &#8212; market data, order types, execution events &#8212; gets provided later by gate two. The AI doesn&#8217;t need to import any of it.</p><p><strong>These names are forbidden.</strong> <code>eval</code>, <code>exec</code>, <code>compile</code>, <code>open</code>, <code>input</code>, <code>getattr</code>, <code>setattr</code>, <code>globals</code>, <code>locals</code> &#8212; seventeen in total. They&#8217;re the dynamic execution, reflection, and file I/O functions that no trading strategy should ever need.</p><p><strong>No double-underscore attribute access.</strong> That <code>__class__.__bases__[0].__subclasses__()</code> escape trick? Blocked. Any attribute starting and ending with <code>__</code> is denied, with five harmless exceptions like <code>__init__</code>. One rule kills the entire escape path.</p><p>Here&#8217;s the part that actually matters in practice: when the scanner rejects something, it doesn&#8217;t just say &#8220;no.&#8221; It returns exactly which line, what the violation was, and a human-readable reason. The AI gets told <em>what</em> it did wrong and <em>where</em>, so it can fix it and try again. It&#8217;s a linter, not a brick wall.</p><h2>Gate two: give it only what it needs</h2><p>Code that passes the scanner moves to the second gate. Now we actually have to <em>load</em> it &#8212; compile the Python and make it runnable. But we do it in a carefully stripped-down environment.</p><p>Every time we load a new AI-written strategy, we build a fresh sandbox from scratch. The sandbox contains:</p><ul><li><p>A cut-down set of Python&#8217;s built-in functions. <code>abs</code>, <code>len</code>, <code>range</code>, <code>sum</code>, <code>sorted</code> &#8212; about 55 names total, down from Python&#8217;s usual 70-plus. No <code>open</code>, no <code>eval</code>, no <code>__import__</code>. The scanner already blocked these, but this is the second net in case it missed something.</p></li><li><p>All the trading system&#8217;s symbols injected directly: what a bar of market data looks like, how to place an order, what side (buy or sell), what the clock says. The AI doesn&#8217;t import these &#8212; they&#8217;re already there in the sandbox when its code wakes up.</p></li><li><p>One weird one: <code>__build_class__</code>. This is a hidden Python function that makes <code>class Whatever:</code> syntax work. If we don&#8217;t include it, the code crashes with a confusing error. Is it dangerous? No &#8212; its interface is implicit and an AI can&#8217;t realistically call it directly. Figuring out which &#8220;scary-looking&#8221; things are actually safe is most of the fun in sandbox design.</p></li></ul><p>This is defense in depth. The scanner is the first net. The stripped-down sandbox is the second. If something slips past the scanner, it still can&#8217;t reach anything dangerous at runtime.</p><h2>Gate three: make sure it actually looks like a strategy</h2><p>Code that passes gates one and two has been scanned and loaded safely. But is it actually a <em>trading strategy</em>? Or did the AI write a class that has nothing to do with what we need?</p><p>Three checks:</p><p><strong>Is there exactly one strategy class?</strong> Zero classes that inherit from <code>Strategy</code> &#8594; rejected. Multiple strategy classes in one file &#8594; also rejected. One file, one strategy. Keeps things simple.</p><p><strong>Does it actually respond to market data?</strong> A strategy needs a method called <code>on_bar</code> &#8212; the function that gets called every time a new bar of price data arrives. If the AI forgot to write it, the strategy is a paperweight that will never make a decision. Rejected.</p><p><strong>Can the engine actually create it?</strong> When the backtest system starts a strategy, it passes in a few things: a name, a clock, a message bus, the instrument being traded, the timeframe. The AI&#8217;s code needs to accept those. If its <code>__init__</code> has the wrong signature, the engine can&#8217;t create it. Rejected &#8212; but with a message saying exactly which parameters are missing.</p><p>The order of these three gates matters: scan the code (static) &#8594; load it in a sandbox &#8594; confirm it&#8217;s a real strategy (structural). Each failure sends a clear reason back to the AI so it can rewrite and retry.</p><h2>One more thing: run it in a cage</h2><p>The three gates catch a lot. They don&#8217;t catch a pure-compute infinite loop. The code is clean, uses only allowed symbols, looks like a valid strategy &#8212; and then runs forever, hanging the entire service.</p><p>So when we actually backtest the strategy, it runs in a separate process with CPU, memory, and time limits. If it blows up, it blows up the subprocess, not the main service. The rest of the system keeps running.</p><p>Also, every AI-written strategy gets tested side-by-side against &#8220;just buy and hold&#8221; &#8212; same market data, same starting cash, same fees. If the AI&#8217;s fancy strategy can&#8217;t beat the dumbest possible benchmark, it doesn&#8217;t deserve a second look.</p><p><strong>Honest part.</strong> There&#8217;s one path where this subprocess isolation isn&#8217;t in place yet: the live runner &#8212; the thing that trades on real-time bars while nobody&#8217;s watching. Currently it runs strategy code inline. It relies on two human approval steps (someone promoted the strategy, someone started the run) to keep things trusted. Subprocess isolation for the live runner is on the list, not done yet. If you&#8217;re deploying this yourself, you should know.</p><h2>The other problem: safe code can still be garbage</h2><p>A strategy can pass all three gates &#8212; perfectly safe, zero dangerous symbols &#8212; and still be worthless. 300 trades on 500 bars, a great-looking return number for the test period, falls apart the moment market conditions shift.</p><p>This is overfitting, and it&#8217;s not a safety problem. It&#8217;s a quality problem. The solution is a scoring function that doesn&#8217;t let any single number fool you.</p><p>The score is a combination of four things:</p><ul><li><p><strong>Sharpe ratio</strong> &#8212; return relative to volatility. The standard metric.</p></li><li><p><strong>Calmar ratio</strong> &#8212; return relative to the worst drawdown. This catches strategies that look good on average but occasionally fall off a cliff.</p></li><li><p><strong>Turnover penalty</strong> &#8212; subtract points for excessive trading. This stops the AI from gaming the score by churning through tiny trades.</p></li><li><p><strong>Drawdown veto</strong> &#8212; if the strategy ever lost more than 30% from its peak, automatic disqualification. One strike and you&#8217;re out.</p></li></ul><p>Why not just use Sharpe ratio alone? Because the AI figures that out. It discovers that high-frequency churn pumps the Sharpe number on paper, even though the strategy would get eaten alive by real trading costs. The turnover penalty says no. It also discovers strategies with great average returns that had one catastrophic month. The drawdown veto says no.</p><p>The coefficients &#8212; how much each factor weighs &#8212; are starting points, not gospel. They&#8217;ll get tuned as we collect more data from real evolution runs. But the principle is more important than the exact numbers: no single metric gets to decide.</p><h2>What the whole thing looks like</h2><p>AI writes source code &#8594; Gate 1: scanner checks for dangerous patterns. Caught something? Here&#8217;s what and where. Fix it and try again. &#8594; Gate 2: load the code in a stripped-down sandbox. &#8594; Gate 3: confirm it&#8217;s actually a trading strategy. &#8594; Run it in an isolated subprocess, parallel with buy-and-hold. &#8594; Score it across multiple dimensions. &#8594; If it beats the baseline, it goes in the candidate pool. &#8594; Human reviews &#8594; Human approves &#8594; It trades.</p><p>The AI gets to be creative &#8212; it writes whatever strategy it can think of. But every line passes through three gates that don&#8217;t care what it was <em>trying</em> to do. They care about structure. And at the end, a scoring function decides whether the result was worth running at all.</p><p>Not a single step in this chain says &#8220;trust the AI.&#8221;</p><h2>What I&#8217;d do differently</h2><ul><li><p><strong>The scanner is a lock, not a theorem.</strong> It blocks the things I know about. New escape tricks will show up, and the rules will need updates. This is not a mathematical proof of safety. It&#8217;s a practical defense that gets better over time.</p></li><li><p><strong>The live runner needs the same subprocess isolation as backtesting.</strong> Right now it relies on human gates. That&#8217;s the top hardening priority.</p></li><li><p><strong>The scoring weights are judgment calls.</strong> 30% drawdown veto, 0.3 Calmar multiplier, 0.10 turnover penalty &#8212; these numbers were reasonable starting points, not optimized values. Real evolution data will tell us if they&#8217;re right.</p></li><li><p><strong>A single score loses information.</strong> Compressing &#8220;safe, profitable, stable, low-turnover&#8221; into one number is always lossy. A future version will track these dimensions separately instead of boiling them down.</p></li></ul><p>I&#8217;d rather name the gaps now than pretend the whole chain is bulletproof. If you&#8217;re building something similar, I recommend the same: ship what&#8217;s load-bearing, name what isn&#8217;t, and don&#8217;t bluff.</p><div><hr></div><p>The AI writes the code. Three gates decide if it ever runs. One scoring function decides if it deserves to.</p><p>No prompt engineering. No &#8220;please don&#8217;t import os.&#8221; Just structural checks that don&#8217;t care about the AI&#8217;s intentions &#8212; only about what&#8217;s actually in the file.</p><p>If this resonated:</p><ul><li><p>&#128236; <strong><a href="https://inalpha.substack.com">Subscribe to Inalpha on Substack</a></strong> &#8212; one post a month on what I&#8217;m building</p></li><li><p>&#11088; <strong><a href="https://github.com/mirror29/inalpha">github.com/mirror29/inalpha</a></strong> &#8212; the three gates, scoring system, and full pipeline in <code>services/paper</code></p></li></ul><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://inalpha.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Same code, three clocks — letting a quant agent trade on its own without losing the audit trail]]></title><description><![CDATA[Same code across backtest and paper is the easy half. The hard half is: who approves the order when no human is watching?]]></description><link>https://inalpha.substack.com/p/same-code-three-clocks-letting-a</link><guid isPermaLink="false">https://inalpha.substack.com/p/same-code-three-clocks-letting-a</guid><dc:creator><![CDATA[Inalpha]]></dc:creator><pubDate>Fri, 05 Jun 2026 14:51:23 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!MCdO!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3a3a4c49-10e2-4d7c-b695-46282c31fac3_1456x816.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!MCdO!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3a3a4c49-10e2-4d7c-b695-46282c31fac3_1456x816.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!MCdO!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3a3a4c49-10e2-4d7c-b695-46282c31fac3_1456x816.png 424w, https://substackcdn.com/image/fetch/$s_!MCdO!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3a3a4c49-10e2-4d7c-b695-46282c31fac3_1456x816.png 848w, https://substackcdn.com/image/fetch/$s_!MCdO!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3a3a4c49-10e2-4d7c-b695-46282c31fac3_1456x816.png 1272w, https://substackcdn.com/image/fetch/$s_!MCdO!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3a3a4c49-10e2-4d7c-b695-46282c31fac3_1456x816.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!MCdO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3a3a4c49-10e2-4d7c-b695-46282c31fac3_1456x816.png" width="1456" height="816" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3a3a4c49-10e2-4d7c-b695-46282c31fac3_1456x816.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:816,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1493892,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://inalpha.substack.com/i/200771577?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3a3a4c49-10e2-4d7c-b695-46282c31fac3_1456x816.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!MCdO!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3a3a4c49-10e2-4d7c-b695-46282c31fac3_1456x816.png 424w, https://substackcdn.com/image/fetch/$s_!MCdO!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3a3a4c49-10e2-4d7c-b695-46282c31fac3_1456x816.png 848w, https://substackcdn.com/image/fetch/$s_!MCdO!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3a3a4c49-10e2-4d7c-b695-46282c31fac3_1456x816.png 1272w, https://substackcdn.com/image/fetch/$s_!MCdO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3a3a4c49-10e2-4d7c-b695-46282c31fac3_1456x816.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-tqxFUX" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-tqxFUX" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>In the last post I argued that an LLM should never hold the approval token on a trade. A human approves. The model only proposes. That works as long as a human is in the loop on every order.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://inalpha.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>Then a user does the obvious thing. They take a strategy the agent wrote, like the backtest, and say <em>&#8220;put it on the paper account.&#8221;</em></p><p>They expect it to <strong>trade</strong>: follow the market in, follow it out, update positions while they sleep.</p><p>The honest truth at that point: <code>status = 'promoted'</code> was a database flag. Nobody was ticking the strategy&#8217;s <code>on_bar</code>. The account didn&#8217;t move. That gap was the whole feature.</p><p>Closing it means the machine now places orders on live bars with <strong>no human clicking approve each time</strong>. Which sounds like exactly the thing the last post said not to do.</p><p>This post is how you close the gap without throwing away the audit trail. And the four places the trust boundary has to be redesigned the moment no human is in the chair.</p><h2>The easy half: same code, three clocks</h2><p>Inalpha holds one invariant tight: the Python file you backtest is the file you paper-trade. No fork for production. You swap two things underneath the strategy &#8212; the <strong>Clock</strong> and the <strong>Gateway</strong> &#8212; and the business logic doesn&#8217;t move.</p><p>The invariant itself isn&#8217;t rare. What&#8217;s rare is the thing standing on top of it here.</p><p><strong>The author of that file is an LLM.</strong> It was vetted by a human. And it&#8217;s now running itself on live bars.</p><p>Quant engines hold the invariant, but don&#8217;t assume an agent wrote the strategy. Agent frameworks assume the LLM, but have nowhere to put a trading harness. Inalpha sits in that seam. And the same-code invariant is exactly what makes the audit chain mean anything: there&#8217;s precisely one file to point a signature at.</p><p>How it runs &#8212; three deployment modes, two clocks, one file:</p><ul><li><p><strong>Backtest:</strong> a <code>TestClock</code> driven by historical bars; fills simulated against a reference price.</p></li><li><p><strong>Paper (live runner):</strong> a <code>LiveClock</code> on real wall-clock time, bars pulled fresh on the strategy&#8217;s timeframe, the same matching engine, the order routed out through the real plan/exec path &#8212; the only simulated part is that fills are matched locally instead of sent to a broker.</p></li><li><p><strong>Live (real capital):</strong> architecturally the same seam &#8212; <code>LiveClock</code>, same kernel, same plan/exec path, only the <strong>Gateway</strong> swapping to a real broker. But real-money trading is <strong>deliberately out of scope</strong> for this project; holding the invariant isn&#8217;t about chasing it. The payoff is narrower and real: backtest and paper are literally one code path, so the audit chain has exactly one file to point a signature at.</p></li></ul><p>So &#8220;three clocks&#8221; is shorthand: two clock implementations (<code>TestClock</code> / <code>LiveClock</code>), the third mode (real capital) a seam the architecture leaves open but the project doesn&#8217;t pursue &#8212; and the strategy file never notices which one it&#8217;s running under.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!NHVW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d79aa2b-419a-474f-bbcd-c287dc1714dc_3888x2144.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!NHVW!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d79aa2b-419a-474f-bbcd-c287dc1714dc_3888x2144.png 424w, https://substackcdn.com/image/fetch/$s_!NHVW!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d79aa2b-419a-474f-bbcd-c287dc1714dc_3888x2144.png 848w, https://substackcdn.com/image/fetch/$s_!NHVW!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d79aa2b-419a-474f-bbcd-c287dc1714dc_3888x2144.png 1272w, https://substackcdn.com/image/fetch/$s_!NHVW!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d79aa2b-419a-474f-bbcd-c287dc1714dc_3888x2144.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!NHVW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d79aa2b-419a-474f-bbcd-c287dc1714dc_3888x2144.png" width="1456" height="803" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7d79aa2b-419a-474f-bbcd-c287dc1714dc_3888x2144.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:803,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:593394,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://inalpha.substack.com/i/200771577?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d79aa2b-419a-474f-bbcd-c287dc1714dc_3888x2144.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!NHVW!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d79aa2b-419a-474f-bbcd-c287dc1714dc_3888x2144.png 424w, https://substackcdn.com/image/fetch/$s_!NHVW!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d79aa2b-419a-474f-bbcd-c287dc1714dc_3888x2144.png 848w, https://substackcdn.com/image/fetch/$s_!NHVW!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d79aa2b-419a-474f-bbcd-c287dc1714dc_3888x2144.png 1272w, https://substackcdn.com/image/fetch/$s_!NHVW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d79aa2b-419a-474f-bbcd-c287dc1714dc_3888x2144.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-tqxFUX" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-tqxFUX" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The live runner (<code>services/paper/.../live_runner.py</code>) is one long-lived task per running strategy. Each tick it does three things:</p><ol><li><p>pull the latest <strong>closed</strong> bar;</p></li><li><p>feed it to a session that reuses the exact backtest kernel, firing the strategy&#8217;s <code>on_bar</code>;</p></li><li><p>intercept the order the strategy emits and hand it to the guarded order path &#8212; it does not match locally.</p></li></ol><p>When the fill comes back, it&#8217;s replayed into the session. So the strategy&#8217;s view of its own position stays consistent with what actually filled.</p><p>Why this matters for <em>audit-grade</em>, not just convenience: if your backtest and live code are two different files, no signature chain will tell you which one ran when the $93k order happened. Same code, three clocks is the precondition. It&#8217;s also the boring half. Here&#8217;s the half that kept me up.</p><h2>The hard half: who approves the order?</h2><p>Last post&#8217;s thesis was a three-step state machine. The LLM drives step one. A human drives the approval:</p><pre><code><code>trade.create_plan       &#8594; plan: pending_approval
trade.approve_plan      &#8594; mints a single-use token
trade.execute_plan(tok) &#8594; places the order</code></code></pre><p>A runner that trades while you sleep can&#8217;t stop and wait for a click on every bar. So the naive fix is to delete the approval step for the automated path. That&#8217;s the fix that quietly turns &#8220;audit-grade&#8221; back into &#8220;trust me.&#8221;</p><p>We did the opposite. The automated path goes through the <strong>same</strong> plan/exec state machine. The approval is just stamped <code>approved_by = "system:live_runner"</code>.</p><p>Machine approval. The order still creates a plan. Still mints and consumes a single-use token. Still writes the same signed audit line. Nothing on the order path got a shortcut.</p><p>Machine approval is only honest if it&#8217;s earned. Ours rests on two human gates upstream, and the agent can&#8217;t route around either:</p><ol><li><p><strong>A human promotes the candidate.</strong> <code>promote</code> is a deliberate human action, with <code>permission: ask</code> on the agent side. The model can&#8217;t self-promote a strategy into the runnable set.</p></li><li><p><strong>A human starts the run.</strong> <code>paper.start_strategy</code> is an explicit call a person makes for a specific market and timeframe.</p></li></ol><p>So the chain reads: a person vetted this strategy, a person chose to run it here. Given those two signatures, having the machine approve each later order on live bars is the expected behavior, not a bypass. The audit line records <code>system:live_runner</code> as the approver for exactly this reason &#8212; a replay shows where the human gates were and where the machine took over.</p><p>Every order the runner places also writes a <strong>decision record</strong> (<code>strategy_run_decisions</code>): the bar context, the order intent, and the outcome (<code>filled</code>, <code>rejected</code>, or <code>risk_rejected</code>), cross-referenced to the plan and the trade.</p><p>The point of the autonomous path isn&#8217;t just that it trades. It&#8217;s that the next morning you can read, line by line, every bar where it <em>wanted</em> to act and what the harness did about it.</p><h2>The trust boundary moves when the human leaves the chair</h2><p>This isn&#8217;t a bug list. It&#8217;s four faces of one architectural question.</p><p>With a human in the loop, a lot of guarantees are propped up implicitly by &#8220;someone is at the screen.&#8221; Designing the unattended path means asking that again, on purpose: which of those props has to become something the <em>system</em> holds up on its own?</p><p>Four answers.</p><p><strong>1. Identity has to become explicit.</strong> When a human starts each run, ownership is implicit &#8212; whoever clicked owns it. Automate it, and ownership has to live in the data model, or there&#8217;s no boundary at all.</p><p>Concretely: the start path checked that a candidate was <code>promoted</code>, not that the caller owned it. So you could run someone else&#8217;s strategy on your own account.</p><p>The trap in fixing it was real. The candidate&#8217;s <code>author_id</code> is only set for UUID identities, while the account id falls back to <code>uuid5</code> for everyone else. A naive <code>author_id == account_id</code> would lock out every non-UUID user. The fix derives an <code>owner_account_id</code> through the <em>same</em> function as the account id (migration 0013), so ownership is comparable for everyone.</p><p><strong>2. Resource bounds are part of the trust boundary, not an ops detail.</strong> A human starting runs self-limits. An API doesn&#8217;t. Each run is a long-lived task polling the data service on a timer, and the only limit was one instance per candidate &#8212; but a user can promote arbitrarily many. So the boundary grows a per-account cap (default 10) that returns <code>429</code>, instead of letting one account quietly melt the event loop.</p><p><strong>3. With no human, the default has to invert.</strong> Fail-open is a default that <em>assumes</em> a backstop. Letting risk checks fail open in dev is fine when a human is at the screen.</p><p>The unattended runner is not at a screen. A risk engine that&#8217;s disabled or fails to load becomes an autonomous order loop with zero risk checks &#8212; the worst possible default. So on this path the default inverts: <strong>fail closed.</strong> No risk guard, no run, unless you explicitly opt out.</p><p><strong>4. Backtest/live parity has to reach down to data shape.</strong> A human wouldn&#8217;t trade a half-formed bar. The machine will, unless the architecture forbids it.</p><p>The latest bar each tick is often still forming &#8212; its close isn&#8217;t final. Acting on it silently diverges from the backtest, which only ever saw closed bars. So the runner decides only on <strong>closed</strong> bars, matching backtest semantics exactly.</p><p>(One implementation detail rides along. The loop treated every exception as retryable with backoff, so a determined-wrong error &#8212; a delisted symbol, a constraint violation &#8212; burned the whole retry budget before giving up. It now splits retryable from non-retryable and stops immediately on the latter. Plumbing, not architecture.)</p><p>Some of these I saw clearly only after an adversarial review of the shipped runner. But they aren&#8217;t scattered bugs. They&#8217;re four corollaries of one sentence: <strong>the trust boundary of an autonomous path is not the same boundary as one with a human in the loop.</strong></p><h2>What this still costs, and what we punted</h2><p>Honesty section, same as last time.</p><ul><li><p><strong>The runner runs candidate code in the main event loop.</strong> The backtest path isolates strategy code in a resource-limited subprocess. The live session compiles and runs it inline. The AST audit is a static gate, not a runtime one &#8212; it won&#8217;t stop a pure-compute infinite loop from hanging the service. We lean on the two human gates to keep the code trusted. Subprocess/watchdog hardening is filed, not done.</p></li><li><p><strong>A crash mid-fill can drift the in-memory position from the DB.</strong> The fill is committed to the DB first, then replayed into the session. If the process dies in between, a restart rebuilds the session from empty cash, not from the DB positions. &#8220;Resume a run from its real position&#8221; is the next robustness item, deliberately not faked in this release.</p></li><li><p><strong>Single-instance only.</strong> Startup reconciliation marks every stranded <code>running</code> row as <code>errored</code>. Correct for one process, wrong the moment you run two. Multi-instance leasing is a Phase-F item, flagged in the code where it bites.</p></li></ul><p>I&#8217;d rather ship the gates that are load-bearing now and name the ones that aren&#8217;t yet, than imply the autonomous path is hardened against things it isn&#8217;t.</p><h2>So what</h2><p>The cheap version of &#8220;let the agent trade for you&#8221; deletes the approval step and calls it autonomy.</p><p>The audit-grade version keeps the entire order path intact. It stamps the approver as the machine. It earns that stamp with two human gates the model can&#8217;t route around. Then it redesigns the trust boundary, so every guarantee the human used to backstop is one the system now holds on its own.</p><p>Autonomy isn&#8217;t the absence of the harness. It&#8217;s the harness running without you in the chair.</p><p>If this resonated:</p><ul><li><p>&#128236; <strong><a href="https://inalpha.substack.com">Subscribe to Inalpha on Substack</a></strong> &#8212; one long-form post a month, ADRs and post-mortems, no algorithm between us and you</p></li><li><p>&#11088; <strong><a href="https://github.com/mirror29/inalpha">github.com/mirror29/inalpha</a></strong> &#8212; the live runner, the plan/exec path, and the four boundary changes above are all in <code>services/paper</code></p></li><li><p>&#128073; <strong>Next post:</strong> <em>Sandboxed strategy evolution &#8212; three gates + multi-objective fitness.</em> What happens when you actually let the LLM mutate trading code, and what catches it when it shouldn&#8217;t have. (Yes, the one I promised last time &#8212; it&#8217;s next.)</p></li></ul><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://inalpha.substack.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Quant agents under audit — how we keep LLMs out of the trading path]]></title><description><![CDATA[Every order has a token. Every decision has a signature. The LLM writes the code; the harness signs it.]]></description><link>https://inalpha.substack.com/p/quant-agents-under-audit-how-we-keep</link><guid isPermaLink="false">https://inalpha.substack.com/p/quant-agents-under-audit-how-we-keep</guid><dc:creator><![CDATA[Inalpha]]></dc:creator><pubDate>Thu, 28 May 2026 10:03:00 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!OPqB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf2c7969-3a25-4c9e-95ed-8415cfa38744_1456x816.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>You wrote in the prompt: <em>&#8220;never place a single order above $10k.&#8221;</em> The next morning the agent placed a $93k order. Yes, this has happened to me.</p><p>The prompt didn&#8217;t fail because the LLM was dumb. It failed because the LLM should never have had that decision in the first place. Telling a language model to &#8220;be careful&#8221; with money is the same kind of category error as telling a 22-year-old contractor to be careful with <code>sudo rm -rf</code> &#8212; the protection has to live below the layer that types the command, not inside it.</p><p>This is what <em>audit-grade</em> means in practice: when that $93k order happens, you can replay &#8212; in 30 seconds, by signature &#8212; exactly how the LLM arrived at the decision, who approved it, when the token was consumed, and why every guardrail above the order path either fired or stayed silent. Not grep the logs. Not check Slack. Replay it, by <code>sha256</code>, end to end.</p><p>That&#8217;s the bar. The rest of this post is how we hit it.</p><h2>The LangChain / AutoGen shape doesn&#8217;t have a place to put this</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ly9B!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20b53e62-a961-49d3-936a-185a6877a6ef_1456x816.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ly9B!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20b53e62-a961-49d3-936a-185a6877a6ef_1456x816.png 424w, https://substackcdn.com/image/fetch/$s_!ly9B!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20b53e62-a961-49d3-936a-185a6877a6ef_1456x816.png 848w, https://substackcdn.com/image/fetch/$s_!ly9B!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20b53e62-a961-49d3-936a-185a6877a6ef_1456x816.png 1272w, https://substackcdn.com/image/fetch/$s_!ly9B!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20b53e62-a961-49d3-936a-185a6877a6ef_1456x816.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ly9B!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20b53e62-a961-49d3-936a-185a6877a6ef_1456x816.png" width="1456" height="816" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/20b53e62-a961-49d3-936a-185a6877a6ef_1456x816.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:816,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1125475,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://inalpha.substack.com/i/199578909?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20b53e62-a961-49d3-936a-185a6877a6ef_1456x816.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ly9B!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20b53e62-a961-49d3-936a-185a6877a6ef_1456x816.png 424w, https://substackcdn.com/image/fetch/$s_!ly9B!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20b53e62-a961-49d3-936a-185a6877a6ef_1456x816.png 848w, https://substackcdn.com/image/fetch/$s_!ly9B!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20b53e62-a961-49d3-936a-185a6877a6ef_1456x816.png 1272w, https://substackcdn.com/image/fetch/$s_!ly9B!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20b53e62-a961-49d3-936a-185a6877a6ef_1456x816.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-tqxFUX" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-tqxFUX" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>In the standard agent loop, the LLM is handed a list of tools, emits <code>tool_name + args</code>, and the runtime executes. That shape works beautifully for chatbots, research agents, and code assistants &#8212; most of the open-source agent ecosystem rests on it for good reason. But it has nowhere to put the things financial code paths need:</p><ul><li><p>A pre-execution interception layer that runs on every call, on every agent</p></li><li><p>A scoped permission table that says <code>deny: paper.submit_order</code> regardless of whose hook ran first</p></li><li><p>A two-phase commit between <em>intent</em> and <em>action</em>, where the LLM holds the intent and a separate state machine holds the action</p></li><li><p>An audit signature that survives the agent process dying mid-call</p></li></ul><p>The analogy I keep coming back to: <code>sudo</code> without a timestamp, without <code>syslog</code>, without caller verification, without an <code>/etc/sudoers</code> file. The command still runs. You just can&#8217;t prove anything about how it ran. For chat or content generation that&#8217;s a fine trade. For an agent that has <code>paper.submit_order</code> in its tool list, &#8220;we can&#8217;t prove anything&#8221; is the same as &#8220;this never happened.&#8221;</p><h2>What we borrowed from Claude Code</h2><p>Anthropic, in shipping Claude Code, faced a structurally identical problem: an LLM running inside an IDE has powerful capabilities (write files, run commands, push code) and prompt-level guardrails were not sufficient. Their answer was a small set of pieces wired together: <code>PreToolUse</code> / <code>PostToolUse</code> / <code>Stop</code> hooks, a declarative <code>permissions</code> config, and a plan-then-execute mode that separates <em>what the model proposes</em> from <em>what the runtime carries out</em>. The philosophy is one sentence: <strong>data-layer enforcement beats prompt-layer self-discipline</strong>. Hooks fire whether the LLM wanted them to or not. Permissions deny whether the LLM thought to ask.</p><p>Inalpha takes that shape and pushes it one step further: in our trading path, <strong>the LLM never holds the approval token</strong>. The token is minted by the plan store at <code>approve</code> time, consumed exactly once at <code>execute</code> time, and burned. The LLM sees <code>plan: pending</code> and <code>plan: approved</code> &#8212; it never sees the token&#8217;s lifecycle, because it isn&#8217;t a participant in it.</p><p>&#128214; <a href="https://code.claude.com/docs/en/hooks">Claude Code hooks documentation</a></p><h2>What we borrowed from NautilusTrader</h2><p>The other half of Inalpha&#8217;s DNA is <a href="https://github.com/nautechsystems/nautilus_trader">NautilusTrader</a>: <strong>the same Python file you backtest is the file you paper-trade is the file you go live with</strong>. You swap the <code>Clock</code> and the <code>Gateway</code>. The business logic doesn&#8217;t move. This discipline is the institutional-grade standard, and it&#8217;s the precondition for everything below &#8212; because if your backtest and your paper code are two different files, no amount of audit signing will tell you which file ran in production.</p><p>Inalpha inherits this directly. The event-driven kernel in <code>services/paper</code> runs backtest and paper-trade as the same code path; when the live runner ships, it will too. Behavioral differences come from physics &#8212; slippage, latency, data precision &#8212; not from a second branch of the codebase.</p><p>What Nautilus doesn&#8217;t assume is the LLM. It doesn&#8217;t have to: Nautilus is a quant engine, not an agent framework. Inalpha does assume the LLM, which is why everything above and below this paragraph exists &#8212; to keep the LLM productive <em>inside</em> the harness without letting it touch the harness&#8217;s signing keys.</p><h2>Four layers of defense</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!qDFl!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65d9a040-22fc-4b7e-8f91-e0710ee751a9_1456x816.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!qDFl!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65d9a040-22fc-4b7e-8f91-e0710ee751a9_1456x816.png 424w, https://substackcdn.com/image/fetch/$s_!qDFl!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65d9a040-22fc-4b7e-8f91-e0710ee751a9_1456x816.png 848w, https://substackcdn.com/image/fetch/$s_!qDFl!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65d9a040-22fc-4b7e-8f91-e0710ee751a9_1456x816.png 1272w, https://substackcdn.com/image/fetch/$s_!qDFl!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65d9a040-22fc-4b7e-8f91-e0710ee751a9_1456x816.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!qDFl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65d9a040-22fc-4b7e-8f91-e0710ee751a9_1456x816.png" width="1456" height="816" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/65d9a040-22fc-4b7e-8f91-e0710ee751a9_1456x816.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:816,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1088042,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://inalpha.substack.com/i/199578909?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65d9a040-22fc-4b7e-8f91-e0710ee751a9_1456x816.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!qDFl!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65d9a040-22fc-4b7e-8f91-e0710ee751a9_1456x816.png 424w, https://substackcdn.com/image/fetch/$s_!qDFl!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65d9a040-22fc-4b7e-8f91-e0710ee751a9_1456x816.png 848w, https://substackcdn.com/image/fetch/$s_!qDFl!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65d9a040-22fc-4b7e-8f91-e0710ee751a9_1456x816.png 1272w, https://substackcdn.com/image/fetch/$s_!qDFl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65d9a040-22fc-4b7e-8f91-e0710ee751a9_1456x816.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-tqxFUX" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-tqxFUX" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><h3>4.1 Tool bucketing &#8212; what the LLM can&#8217;t see, it can&#8217;t call</h3><p>The orchestrator agent&#8217;s tool list does not contain <code>paper.submit_order_intent</code>. It contains the things an orchestrator should be able to call &#8212; market data, backtest runs, factor queries, plan creation &#8212; and nothing that crosses the order boundary. That tool is exposed only to the <code>plan/exec</code> code path, which is not an LLM-driven path.</p><p>This is the cheapest layer, and the one most often skipped. The temptation in agent frameworks is to register every tool globally and rely on prompt discipline to keep the wrong ones from being called. Bucketing tool visibility at the <em>agent definition</em> level &#8212; <code>packages/orchestration/src/tools/index.ts</code> L43-90 with the orchestrator binding at <code>src/mastra/agents/orchestrator.ts</code> L99-112 &#8212; costs about twenty lines of TypeScript and removes an entire class of failure mode.</p><h3>4.2 Permissions deny-list &#8212; even if a tool leaks in, the engine catches it</h3><p>Layer two is a permission engine that runs on every tool call, regardless of which agent invoked it or which hook ran first. The rules live in TypeScript, not YAML &#8212; unit-testable, type-checked, merged through code review:</p><pre><code><code>// permissions/defaults.ts L75-84
{
  defaultMode: "allow",                          // dev-friendly; prod switches to "ask"
  allow: ["data.*", "paper.run_backtest", ...],
  deny:  ["paper.submit_order", "live.*", ...]   // not overridable by hooks
}</code></code></pre><p>Resolution order is <code>deny &gt; allow &gt; ask &gt; defaultMode</code>. The detail that matters most: <code>deny</code><strong> is not overridable by a hook</strong> (<code>with-hooks.ts</code> L188-210 contains the hard check). The reason is the obvious one &#8212; without that check, &#8220;write a quick hook to grant yourself an exception&#8221; becomes the in-house attack surface. The engine doesn&#8217;t trust its own middleware.</p><h3>4.3 Two-phase Plan/Exec with a single-use approval token</h3><p>The order path is a three-step state machine, and the LLM only drives the first step:</p><pre><code><code>trade.create_plan       &#8594; plan: pending_approval
trade.approve_plan      &#8594; mints UUID approval_token, 5-minute TTL, single-use
trade.execute_plan(token) &#8594; calls paper /orders/submit</code></code></pre><p>The token is a <code>crypto.randomUUID()</code> minted at approval time, stored in the plan store, and set to <code>null</code> the instant <code>execute_plan</code> consumes it. Replay attack is not a concern in theory because the token is one-shot; in practice the <code>null</code> happens before the order request leaves the function, so even a same-tick double-call resolves to &#8220;token already consumed.&#8221; </p><p>The design point worth stating explicitly: this is <strong>not multi-agent separation of powers</strong>. We tried that &#8212; a <code>trader</code> agent and a <code>risk</code> agent in Phase D-8a &#8212; and refactored to a single orchestrator agent in D-8a&#8217; because the middleware was already doing the work the second agent was nominally for. Even when the same orchestrator, in the same turn, calls <code>plan &#8594; approve &#8594; execute</code>, the token&#8217;s <code>null</code> after consumption, the required <code>rationale</code> field, and the <code>deny</code> on <code>paper.submit_order</code> mean the state machine itself is unbypassable. The concern &#8220;what if the LLM approves its own plan&#8221; doesn&#8217;t get solved by adding more LLMs. It gets solved by making <code>approve</code> mechanically distinct from <code>execute</code> in a way the LLM cannot route around.</p><h3>4.4 Audit signature &#8212; the layer that makes the first three provable</h3><p>Three layers of enforcement get you a system that&#8217;s safe. The fourth makes it <em>defensible</em>. A <code>PostToolUse</code> hook writes a signed JSON line to the audit sink on every tool call, with <code>apiKey</code> / <code>token</code> / <code>email</code> / <code>phone</code> / <code>wallet</code> automatically redacted to <code>[REDACTED]</code>:</p><pre><code><code>{"ts":"2026-05-27T14:32:11.482Z","agent":"orchestrator","tool":"trade.approve_plan",
 "args":{"plan_id":"p_8f3a","rationale":"BTC 30m breakout, vol &#8593;180%"},
 "result":{"approval_token":"[REDACTED]","ttl_sec":300},"latency_ms":47,
 "signature":"sha256:c4a9...","caller":"user:miro","session":"s_9b1"}</code></code></pre><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!OPqB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf2c7969-3a25-4c9e-95ed-8415cfa38744_1456x816.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!OPqB!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf2c7969-3a25-4c9e-95ed-8415cfa38744_1456x816.png 424w, https://substackcdn.com/image/fetch/$s_!OPqB!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf2c7969-3a25-4c9e-95ed-8415cfa38744_1456x816.png 848w, https://substackcdn.com/image/fetch/$s_!OPqB!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf2c7969-3a25-4c9e-95ed-8415cfa38744_1456x816.png 1272w, https://substackcdn.com/image/fetch/$s_!OPqB!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf2c7969-3a25-4c9e-95ed-8415cfa38744_1456x816.png 1456w" sizes="auto, 100vw"><img src="https://substackcdn.com/image/fetch/$s_!OPqB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf2c7969-3a25-4c9e-95ed-8415cfa38744_1456x816.png" width="1456" height="816" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/af2c7969-3a25-4c9e-95ed-8415cfa38744_1456x816.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:816,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1192042,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://inalpha.substack.com/i/199578909?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf2c7969-3a25-4c9e-95ed-8415cfa38744_1456x816.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!OPqB!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf2c7969-3a25-4c9e-95ed-8415cfa38744_1456x816.png 424w, https://substackcdn.com/image/fetch/$s_!OPqB!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf2c7969-3a25-4c9e-95ed-8415cfa38744_1456x816.png 848w, https://substackcdn.com/image/fetch/$s_!OPqB!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf2c7969-3a25-4c9e-95ed-8415cfa38744_1456x816.png 1272w, https://substackcdn.com/image/fetch/$s_!OPqB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Faf2c7969-3a25-4c9e-95ed-8415cfa38744_1456x816.png 1456w" sizes="auto, 100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button class="pencraft pc-reset pencraft icon-container restack-image buttonBase-tqxFUX" tabindex="0" type="button"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" class="icon-noB79L"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button class="pencraft pc-reset pencraft icon-container view-image buttonBase-tqxFUX" tabindex="0" type="button"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2 icon-noB79L"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>This is the layer that took me longest to convince myself was a <em>defense</em> layer, not a logging layer. The argument that flipped me: without the signature chain, every guarantee from the first three layers is &#8220;trust me, I didn&#8217;t bypass it.&#8221; A regulator, a post-incident investigator, a yourself-six-months-from-now &#8212; none of them want &#8220;trust me.&#8221; They want <code>grep signature: &amp;&amp; replay</code>. The first three layers stop bad actions. The fourth proves the stops happened.</p><h2>What this costs</h2><p>Honesty section.</p><ul><li><p><strong>More code.</strong> Compared to the <code>loop + tool list</code> shape, Inalpha adds hooks middleware, a permission engine, a plan store, an audit sink, plus the wiring between them. Roughly 2,700 lines of TypeScript across hooks, permissions, and plans.</p></li><li><p><strong>Cognitive overhead.</strong> A new contributor onboarding has to learn <code>deny &gt; allow &gt; ask &gt; defaultMode</code>, single-use token semantics, and why <code>deny</code> isn&#8217;t overridable. That&#8217;s a real ramp.</p></li><li><p><strong>Latency.</strong> Every tool call eats an extra hook + permission check + audit write. We measured under 5ms end-to-end. Negligible for the order path; you should still measure it before claiming &#8220;negligible.&#8221;</p></li><li><p><strong>Audit sink volume.</strong> Every tool call produces a JSON line. You need tiered storage &#8212; hot for 30 days of replay-ability, cold (S3 / OSS) for the long tail. This is operational cost, not engineering cost, but it exists.</p></li></ul><p>Is it worth it? For finance, medical, critical infrastructure &#8212; yes. For chatbots, content generation, code assistants &#8212; no. The middleware tax is proportional to the cost of a wrong action, and a <code>paper.submit_order</code> is in a different cost universe than a wrong sentence.</p><p>The bet underneath this whole architecture: the next wave of LLM-ops will be judged less on <em>how clever</em> the agent is and more on <em>how defensible</em> it is. Clever is competitive. Defensible is structural.</p><h2>A note on Anthropic&#8217;s Financial Services Agents</h2><p>In May 2026 Anthropic shipped Financial Services Agents &#8212; a managed offering with per-tool permissions, credential vaults, and full audit logs viewable in the Claude Console. If you&#8217;ve read this far, you&#8217;re probably wondering how Inalpha is different. Four honest answers:</p><ul><li><p><strong>Open-source vs managed SaaS.</strong> Every middleware in Inalpha is in <code>packages/orchestration/</code> &#8212; you can fork it, self-host it, and audit the audit code. The Anthropic offering is an enterprise black box, which is the right choice for many companies but a different choice.</p></li><li><p><strong>Quant-shaped vs general finance-ops.</strong> Inalpha assumes you&#8217;re building strategies, factors, and risk rules. The Anthropic agents assume you might be doing invoice review, compliance screening, or research summarization. The default tool shape is different.</p></li><li><p><strong>Strategy evolution.</strong> Inalpha&#8217;s E1+ phase lets the LLM mutate full Python strategy source, gated by three sandbox layers and a multi-objective fitness function. That capability line doesn&#8217;t exist in the Anthropic offering.</p></li><li><p><strong>Multi-market, same-code BT=Paper=Live.</strong> Inalpha routes across crypto, US equities, A-shares, HK, FRED macro, etc., with one codebase. The Anthropic offering is broker-agnostic but doesn&#8217;t presuppose cross-market strategy work.</p></li></ul><p>The framing I&#8217;d use: <strong>complementary, not substitutive.</strong> The Anthropic reference implementation will educate the market on what audit-grade agent infrastructure looks like. Inalpha is the open-source choice for teams who want the same shape but on their own metal, with strategy generation baked in.</p><h2>So what</h2><p>Hooks, scoped permissions, plan-then-execute with single-use tokens, and a signed audit chain are not over-engineering. For an agent that touches money, they are the minimum viable architecture &#8212; and they are what <em>audit-grade</em> literally means.</p><p>If this resonated:</p><ul><li><p>&#128236; <strong><a href="https://inalpha.substack.com">Subscribe to Inalpha on Substack</a></strong> &#8212; one long-form post a month, ADRs and post-mortems, no algorithm between us and you</p></li><li><p>&#11088; <strong><a href="https://github.com/mirror29/inalpha">github.com/mirror29/inalpha</a></strong> &#8212; the code that runs everything above</p></li><li><p>&#128073; <strong>Next post:</strong> <em>Sandboxed strategy evolution &#8212; three gates + multi-objective fitness</em>. What happens when you actually let the LLM mutate trading code, and what catches it when it shouldn&#8217;t have.</p></li></ul>]]></content:encoded></item></channel></rss>