<?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: Wojciech Wentland</title>
    <description>The latest articles on DEV Community by Wojciech Wentland (@desty2k).</description>
    <link>https://dev.to/desty2k</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%2F3866520%2F3ad33efb-4ece-434a-97e5-e9cecc7cc9fd.png</url>
      <title>DEV Community: Wojciech Wentland</title>
      <link>https://dev.to/desty2k</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/desty2k"/>
    <language>en</language>
    <item>
      <title>Simplifying modular monolith composition in .NET</title>
      <dc:creator>Wojciech Wentland</dc:creator>
      <pubDate>Mon, 23 Nov 2026 16:15:00 +0000</pubDate>
      <link>https://dev.to/desty2k/simplifying-modular-monolith-composition-in-net-21op</link>
      <guid>https://dev.to/desty2k/simplifying-modular-monolith-composition-in-net-21op</guid>
      <description>&lt;p&gt;A layered .NET application splits code by technical role: endpoints in one project, handlers in another, the domain model and data access in their own. Adding a field to an order touches all four. Vertical slices split the same code by feature. Everything orders needs, from the endpoint to the query, sits together, and the change stays in one place.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fibkarj8dqz42yt4jct16.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fibkarj8dqz42yt4jct16.png" alt="Layers and vertical slices. The same code drawn twice. Rows are layers (endpoints, handlers, domain, data), columns are features (orders, billing, reporting). Cut into layers, a change to orders touches four projects; cut into slices, it stays inside one." width="799" height="279"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A modular monolith groups slices into modules and puts boundaries between them that a build can check. Orders may call billing through billing's public contract, but not read its tables or use its internal classes, and an architecture test fails if it tries. It still ships from one codebase, as one application or a handful of processes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8odjpb9unqkybqtwfoh0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8odjpb9unqkybqtwfoh0.png" alt="Modules and the host. Four modules in a row: orders, billing, reporting, identity. Neighbouring modules talk only through public contracts, which architecture tests check. Above them, the host project references every module and nothing checks it." width="800" height="257"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Those tests cover the modules and exempt the host. The host references every module, because something has to register them, and it decides which ones each process runs. In every setup I've built, that decision was a side effect of something else: which projects a host referenced, what a mediator found in an assembly, what a shared &lt;code&gt;AddX()&lt;/code&gt; helper pulled in, which &lt;code&gt;if&lt;/code&gt; branches matched a flag. None of them gave me a list I could read, or one a test could build.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Every process should be able to list what it runs and who registered each piece.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Fifteen hosts
&lt;/h2&gt;

&lt;p&gt;The first version was in an earlier project. I wanted each vertical slice to run as its own process so it could scale on its own, which meant a host project per slice. There were fifteen of them in the end, each with a &lt;code&gt;Program.cs&lt;/code&gt; that composed what its slice needed.&lt;/p&gt;

&lt;p&gt;To avoid fifteen copies of the same registrations, I moved them into extension methods on &lt;code&gt;IServiceCollection&lt;/code&gt;, and each host called the ones it needed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Orders.Host/Program.cs&lt;/span&gt;
&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddOrders&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Reporting.Host/Program.cs&lt;/span&gt;
&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddReporting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddOrders&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// reports read orders&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;IServiceCollection&lt;/span&gt; &lt;span class="nc"&gt;AddOrders&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="nc"&gt;IServiceCollection&lt;/span&gt; &lt;span class="n"&gt;services&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddScoped&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;OrderReader&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddScoped&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;OrderService&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddHostedService&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;OrderExpiryWorker&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   &lt;span class="c1"&gt;// now also runs in Reporting&lt;/span&gt;
    &lt;span class="n"&gt;services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddMessaging&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                          &lt;span class="c1"&gt;// and so do its consumers&lt;/span&gt;
    &lt;span class="n"&gt;services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddOptions&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;PaymentOptions&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BindConfiguration&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Payments"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ValidateDataAnnotations&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ValidateOnStart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;services&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The helpers grew to fit the host that needed the most. The reporting host wanted &lt;code&gt;OrderReader&lt;/code&gt; and got the expiry worker, the message consumers and a payments section it had to configure. Nothing failed in the build. Each process started more than it used, and reading a host's &lt;code&gt;Program.cs&lt;/code&gt; didn't tell me what it would end up running.&lt;/p&gt;

&lt;p&gt;Deployment was worse. Each host had its own Dockerfile, and each one copied the project files it needed before &lt;code&gt;dotnet restore&lt;/code&gt;. A new project meant a new &lt;code&gt;COPY&lt;/code&gt; line in every Dockerfile whose host referenced it, directly or through another project. When I missed one, restore failed in CI. The images were built in one job, so one missing line failed all of them, and the fix meant rebuilding every image instead of one. I missed it more than once, and so did coding agents: they added the project, the reference and the registration, and the build passed locally, where nothing copies project files one by one.&lt;/p&gt;

&lt;p&gt;Some problems got past CI. An image built, and the host failed when it started in the deployed environment, because a helper it called now needed a section or a service that host had never been given.&lt;/p&gt;

&lt;h2&gt;
  
  
  The mediator that wanted every handler
&lt;/h2&gt;

&lt;p&gt;The same project used &lt;a href="https://github.com/mayuanyang/Mediator.Net" rel="noopener noreferrer"&gt;Mediator.Net&lt;/a&gt; for in-process requests. Its recommended setup scans an assembly and registers every handler it finds. The handlers of several slices lived in assemblies each host referenced anyway, so every host got all of them, each registered as a container service. The mediator only creates a handler when a message arrives, but in the Development environment ASP.NET Core validates every registered service when the host is built (&lt;code&gt;ValidateOnBuild&lt;/code&gt;). On my machine, a host that served one slice didn't start until it registered the dependencies of handlers it would never call.&lt;/p&gt;

&lt;p&gt;Mediator.Net can also take an explicit list of handlers. I tried it. It works, and it gives you a hand-written list per host, which is the fifteen-hosts problem in a different file. At that point the mediator wasn't giving me anything I needed, so I removed it.&lt;/p&gt;

&lt;p&gt;Choosing which assemblies to scan doesn't help either. The unit I deploy is a process, and a process runs parts of several assemblies.&lt;/p&gt;

&lt;h2&gt;
  
  
  One executable with role flags
&lt;/h2&gt;

&lt;p&gt;My current project went the other way: one executable, one image, and a flag that says which roles a process runs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// dotnet App.dll serve --roles api,worker&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;roles&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;RoleSet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddOrders&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;roles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Role&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Api&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddPublicApi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;roles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Role&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Worker&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddHostedService&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;OrderExpiryWorker&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;roles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Role&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Api&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddApiClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// call the API process instead&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That fixed the images. The one Dockerfile still lists every project file before restore, but a new project is one edit instead of one per Dockerfile that needed it, CI builds one image, and the number of processes stopped being a build problem.&lt;/p&gt;

&lt;p&gt;The problem moved into composition. The branches spread from &lt;code&gt;Program.cs&lt;/code&gt; into the helpers, and the helpers started taking the role set as a parameter. Eleven roles as free flags allow 2,047 combinations. Tests covered a handful of them. Which combinations I supported wasn't written down anywhere, and the reason a service was registered in a process was whichever branch had added it.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;if (role)&lt;/code&gt; around extension methods is a reasonable design at a few branches, and I'd still use it there. It stops working when nobody can say, without reading every branch, who registered a service and which processes need it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Declaring what a process runs
&lt;/h2&gt;

&lt;p&gt;What I wanted was the list from the top of this post, built from declarations that sit next to the code they register:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;component&lt;/strong&gt; declares the services it registers, the components it requires, the configuration sections it reads, and what it adds to builders someone else owns, such as a message bus's list of handlers.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;role&lt;/strong&gt; is a workload: the components it requires.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;profile&lt;/strong&gt; is the exact set of roles one process runs.&lt;/li&gt;
&lt;li&gt;The host composes the profile it was started with, records which component registered each service, and refuses to start when a required component or configuration section is missing.&lt;/li&gt;
&lt;li&gt;A test builds every declared profile.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8d0x2s9abd1aytbpczu2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8d0x2s9abd1aytbpczu2.png" alt="The profile combined runs the roles orders and notifications; their components OrdersConsumer and NotificationsConsumer both require MessageProcessing, which is composed once" width="798" height="160"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;None of the pieces is new. Mark Seemann's &lt;a href="https://blog.ploeh.dk/2011/07/28/CompositionRoot/" rel="noopener noreferrer"&gt;Composition Root&lt;/a&gt; puts composition in one place near the entry point, and says only applications should have one. I keep the first part: the list of profiles is in one place. I break the second on purpose. Module projects reference the composition library, so their registrations sit with the code they register instead of in a host that references everything. &lt;a href="https://abp.io/docs/latest/framework/architecture/modularity/basics" rel="noopener noreferrer"&gt;ABP's modules&lt;/a&gt; are the same unit of registration, with dependencies between modules. Grafana Loki was one inspiration, among several systems that ship one binary able to run as any of its components; Loki picks them with &lt;code&gt;-target&lt;/code&gt;. Spring Modulith does the module-verification side for Java, and Google's Service Weaver split one Go binary into processes until it was archived in 2025.&lt;/p&gt;

&lt;p&gt;What I wanted beyond ABP's module graph was an owner for every registration and a test that builds every profile. I built that as &lt;a href="https://blog.wentland.io/projects/corfedo-troupe/" rel="noopener noreferrer"&gt;Corfedo Troupe&lt;/a&gt;, an open-source .NET library, still in alpha. A component from its &lt;a href="https://github.com/corfedo/corfedo-troupe/blob/v0.3.0/examples/Messaging/MessagingComposition.cs" rel="noopener noreferrer"&gt;Messaging example&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;sealed&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;OrdersConsumer&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;IComponent&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nc"&gt;Compose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;IComponentBuilder&lt;/span&gt; &lt;span class="n"&gt;component&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;component&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Requires&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;MessageProcessing&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;component&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Services&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;services&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddSingleton&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;OrderFormatter&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;component&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Contribute&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;WolverineOptions&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;options&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Discovery&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;IncludeType&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;PlaceOrderHandler&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;PublishMessage&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;PlaceOrder&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToLocalQueue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"orders"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;MessageProcessing&lt;/code&gt; is composed once, however many components require it. The handler goes into Wolverine's discovery from the component that owns it, and the application turns conventional discovery off (one line in its Wolverine setup). A process that doesn't compose &lt;code&gt;OrdersConsumer&lt;/code&gt; doesn't register &lt;code&gt;PlaceOrderHandler&lt;/code&gt;. The mediator built its handler list from what an assembly contained; here the list comes from what the process composes.&lt;/p&gt;

&lt;p&gt;Profiles name the processes. One executable runs as &lt;code&gt;--profile combined&lt;/code&gt; on a laptop and as &lt;code&gt;--profile orders&lt;/code&gt; and &lt;code&gt;--profile notifications&lt;/code&gt; in separate deployments:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;definition&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Profile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"orders"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Role&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;OrdersRole&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Profile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"notifications"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Role&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;NotificationsRole&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Profile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"combined"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Role&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;OrdersRole&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Role&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;NotificationsRole&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A test calls &lt;code&gt;CompositionVerifier.VerifyProfilesAsync&lt;/code&gt;, which builds every profile without starting it. In my current project, a profile missing a service now fails there, in CI, instead of after the image is running. The test catches what the components declare and what the container's own validation catches (&lt;code&gt;ValidateOnBuild&lt;/code&gt;, &lt;code&gt;ValidateScopes&lt;/code&gt;). A dependency resolved through a factory at runtime still gets past it. So does configuration: the test builds with its own settings, so a section missing in the deployed environment still stops the process, but before it listens and with the section named.&lt;/p&gt;

&lt;p&gt;For the person running it, adding a slice is a component and maybe a role, and the test lists the profiles that no longer build before anyone deploys.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding the library didn't remove the problem
&lt;/h2&gt;

&lt;p&gt;Moving registrations into components is mechanical work, and the over-registration moved with them. The shared helpers came along. One registered token validation the first time it was called and skipped every later call. Two components called it, so whichever ran first became the owner by accident. Another put an external API client into every process, because the component that called it was required by every role, including roles that never made that call.&lt;/p&gt;

&lt;p&gt;Each process can now list what it composes and which component registered each service, and that list is where I found both. It showed token validation owned by whichever component happened to run first; the guard had hidden the second caller from the duplicate check. A service registered by two owners is listed as an advisory unless it is declared exclusive, and duplicate hosted services or options bindings stop startup. Before, the same facts were spread across branches.&lt;/p&gt;

&lt;p&gt;Fixing them was the same work as without the library: decide which module owns token validation, split the helper that did three things, move the client into a component that only the processes using it require.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I still write myself
&lt;/h2&gt;

&lt;p&gt;Running as separate processes still takes code the library doesn't write. When the orders role needs the catalog and the catalog runs in another process, something has to make that call over HTTP, gRPC or a queue, carry the caller's identity and know the address. Troupe answers one question for that code: is the owner composed here? "Remote" only means "not here." The &lt;a href="https://github.com/corfedo/corfedo-troupe/tree/v0.3.0/examples/Operations" rel="noopener noreferrer"&gt;Operations example&lt;/a&gt; has HTTP/2 clients with mutual TLS between processes, and all of that code lives in the example.&lt;/p&gt;

&lt;p&gt;Splitting also breaks things that worked combined: an in-memory cache two roles shared, a timer that should fire in one process, keys that must be the same everywhere. That needs its own post.&lt;/p&gt;

&lt;p&gt;Boundaries are still projects and architecture tests. A component can register anything, and nothing in the composition stops the orders module from reaching into billing's internals.&lt;/p&gt;

&lt;p&gt;One image has a cost. Every process ships the code of every slice, and they all come from one build. With one codebase and one release schedule that's fine. I'd expect it to hurt with two teams on different schedules.&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>csharp</category>
      <category>architecture</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Rewriting the firmware of my Zigbee light switches</title>
      <dc:creator>Wojciech Wentland</dc:creator>
      <pubDate>Wed, 18 Nov 2026 16:15:00 +0000</pubDate>
      <link>https://dev.to/desty2k/rewriting-the-firmware-of-my-zigbee-light-switches-459g</link>
      <guid>https://dev.to/desty2k/rewriting-the-firmware-of-my-zigbee-light-switches-459g</guid>
      <description>&lt;p&gt;I wanted one thing from the light switches in my flat: a double click that triggers a Home Assistant automation every time. What I have now is a &lt;a href="https://github.com/desty2k/tuya-zigbee-switch-bseed" rel="noopener noreferrer"&gt;firmware fork&lt;/a&gt; that meters power, drives shutters, finds the pinout of a device it can't see inside, locks its buttons when my alarm is armed, and builds for 204 boards.&lt;/p&gt;

&lt;p&gt;The double click was fixed early. Everything after that was me saying yes to the next idea, because saying yes cost me one message to an agent.&lt;/p&gt;

&lt;h2&gt;
  
  
  The thing I needed
&lt;/h2&gt;

&lt;p&gt;The switches are BSEED wall switches, cheap Zigbee devices built on a Tuya design. Their stock firmware has a bug I couldn't live with: press two buttons at once and only one relay toggles. There's an open-source replacement, &lt;a href="https://github.com/romasku/tuya-zigbee-switch" rel="noopener noreferrer"&gt;romasku/tuya-zigbee-switch&lt;/a&gt;, that fixes it and installs over the air, straight from the stock firmware. I installed it and it was fine.&lt;/p&gt;

&lt;p&gt;Except the double click. Sometimes it fired, sometimes it didn't.&lt;/p&gt;

&lt;p&gt;The firmware reported a button as a state (not pressed, pressed, long press) and Home Assistant had to guess a double click from how that state changed. Two quick changes can arrive at the hub as one. On top of that, the light switched on the first press, before anyone knew whether a second press was coming. With the button driving the relay, a double click meant for an automation also toggled the light.&lt;/p&gt;

&lt;p&gt;Fixing that meant waiting until the gesture is known before doing anything, and sending every click as its own event instead of a state that can be overwritten. That's a different shape of code: something between the button and the relay that collects presses and turns them into single clicks, double clicks and holds. Once it existed, the double click fired every time.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fm7kvnqp0kmfnkjzhc70d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fm7kvnqp0kmfnkjzhc70d.png" alt="Relay mode setting of one switch button in Zigbee2MQTT. In deferred_single mode the relay waits until the press is known to be a single click" width="770" height="117"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I wrote none of it, and none of the other C in the project. I worked with Codex (Astra 6) and Claude Code (Opus 5.5), and the routine settled quickly: I'd discuss the architecture with an agent until I agreed with it, then let it implement on its own while I did something else. Some evenings I went shopping while an agent flashed the switches around my flat and ran the checks. I don't write C day to day and I didn't read the code line by line. My review was the switch on the wall.&lt;/p&gt;

&lt;p&gt;That could have been the end. Instead I decided the firmware should run on every Zigbee device in my flat, and not all of them were light switches.&lt;/p&gt;

&lt;h2&gt;
  
  
  The outlet
&lt;/h2&gt;

&lt;p&gt;First came a BSEED outlet with a power meter, built on the same chip. One button, one relay and a meter chip. I expected a small step. The meter reports power as thousands of pulses a second, which would drown the button code, so it needed its own path. And the chip's flash couldn't hold every feature for every device anymore, so features had to be compiled per board.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe766j7c95zg26ov9vdj9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe766j7c95zg26ov9vdj9.png" alt="Power, voltage, current and energy readings from the outlet in Zigbee2MQTT" width="770" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The fun problem was that I didn't know which pin did what, and I couldn't open the outlet without breaking it. So the agent and I built a probe image: firmware that joins the network and lets you read any pin or send it a short pulse over Zigbee. The agent sent pulses pin by pin and I watched for the light to flash. That's how the board got its pinout.&lt;/p&gt;

&lt;p&gt;It was the part I enjoyed most, and the most nervous I've been in the whole project. Driving an unknown pin high or low could break something, and the only way to find out which pin was which was to try. A computer was switching things in my home, and I had to stare at the lamp to catch a flash of a few tens of milliseconds.&lt;/p&gt;

&lt;h2&gt;
  
  
  The shutters
&lt;/h2&gt;

&lt;p&gt;A shutter switch drives a motor through two relays, one per direction. They must never be on at the same time, and between one switching off and the other switching on there has to be a pause so the motor stops.&lt;/p&gt;

&lt;p&gt;In the original firmware several parts of the code could switch a relay directly: the button handling, the Zigbee code, the startup logic. Adding that rule would have meant a check in each of them, and hoping nobody added another caller later. So relays got a single owner. Every request goes to one place, which enforces the pause and then switches the pin. An auto-off timer, the kind a garage door opener needs, came along almost for free once that existed.&lt;/p&gt;

&lt;p&gt;The shutter also has to know where it is, and it only knows by time. The stock firmware had one travel time for both directions, and the only way to set it was to start the shutter and stop it at the right moment. Up and down can take different times. The open-source firmware already took separate open and close times as numbers, and ran the motor three seconds past each end so the shutter really got there. I made that overrun a setting.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbsebhcuhll7oxupbfgjf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbsebhcuhll7oxupbfgjf.png" alt="Shutter timing settings in Zigbee2MQTT: open time, close time, deadzones at each end and the overrun" width="799" height="655"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then I flashed the shutter switch and it started buzzing loudly, both motor relays chattering.&lt;/p&gt;

&lt;p&gt;The cause, as far as the agent and I worked out: the stock firmware holds the pins it doesn't use low. Mine left them floating, and a floating pin next to mains wiring picks up enough noise to rattle a relay. Nothing broke, but it scared me, and now every pin the firmware doesn't use is held low.&lt;/p&gt;

&lt;p&gt;By the time the shutters worked, I had rewritten everything above the hardware layer.&lt;/p&gt;

&lt;h2&gt;
  
  
  The alarm
&lt;/h2&gt;

&lt;p&gt;When the alarm in my flat is armed, every switch now ignores its buttons while Home Assistant can still control the lights. The firmware calls it a child lock.&lt;/p&gt;

&lt;p&gt;It was small to build, because by then every button press already went through one place and the lock is one check there. In the original code it would have been a change in every handler. I liked this part of the rabbit hole: every structural change so far had come from a feature that needed it, and each one made the next feature cheaper.&lt;/p&gt;

&lt;h2&gt;
  
  
  What each feature brought with it
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;I asked for&lt;/th&gt;
&lt;th&gt;It needed&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Double click&lt;/td&gt;
&lt;td&gt;Waiting for the gesture, clicks sent as events&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Outlet with a meter&lt;/td&gt;
&lt;td&gt;A separate path for meter pulses, features compiled per board, a probe image&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Shutters&lt;/td&gt;
&lt;td&gt;One owner per relay, a pause between directions, held-low pins&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Alarm block&lt;/td&gt;
&lt;td&gt;One entry point for every button press&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;(because I could)&lt;/td&gt;
&lt;td&gt;A safe mode for broken configs, diagnostic counters, and every inherited board moved to the new code&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;By the last row I wasn't fixing my flat anymore. It had turned into an experiment: how much can I fit into a $15 switch whose stock firmware has very few options? The original project already covered a long list of boards and generated its Home Assistant and Zigbee2MQTT integrations from one device list. I could have kept the BSEED boards and dropped the rest. Instead the agents moved every board to the new code and regenerated the integrations, and the fork now builds images for 204 devices.&lt;/p&gt;

&lt;h2&gt;
  
  
  What only the hardware caught
&lt;/h2&gt;

&lt;p&gt;The project has 387 tests that run the whole firmware on my laptop, with a fake clock and a fake radio. They're good tests. The agents wrote most of them and ran them all the time. Two bugs got past them anyway.&lt;/p&gt;

&lt;p&gt;The first release candidate rebooted the switch on almost any button press. Nobody else had installed it, so the only home it broke was mine, and I fixed it there. The cause was the compiler for the switch's chip, tc32-gcc 4.5.1. At &lt;code&gt;-Os&lt;/code&gt;, the setting that makes the image small enough to fit, it stored some &lt;code&gt;switch&lt;/code&gt; statements as tables of one-byte offsets and then read them as four-byte addresses, so the code jumped to random places. My laptop uses a different compiler, so the tests never saw it. The fix was to build without jump tables, plus a check after linking that deletes the image if one ever comes back.&lt;/p&gt;

&lt;p&gt;Later a switch dropped off the network, and the devices that reached the network through it went offline too. Its radio stack had hit a fault and kept running in that state: still joined, no longer passing anything on for its neighbors. The fix was to reboot on such a fault, as the chip vendor's own sample code does. The fake radio in the tests never faults.&lt;/p&gt;

&lt;p&gt;Both bugs lived in the two things the laptop version replaces, the compiler and the radio. Only hardware sees those, and hardware is my flat.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where it stands
&lt;/h2&gt;

&lt;p&gt;Eleven devices run it on real walls: three outlets, four switches and four shutter controllers. The 4-gang switch, an outlet and a shutter controller ran the previous release candidate for two to three weeks, and a 3-gang has run the current one for a few days. The rest of the 204 build and are published as release candidates in &lt;a href="https://github.com/desty2k/tuya-zigbee-switch-bseed" rel="noopener noreferrer"&gt;the fork on GitHub&lt;/a&gt;, waiting for someone with the hardware. The builds for Silicon Labs, the second chip family the project supports, have never run on a device, and no board has been through a series of power cuts yet. Anyone coming from the original firmware starts with fresh settings.&lt;/p&gt;

&lt;p&gt;As far as I know, nobody outside my flat has installed it. The latest release candidate alone added seventeen entries to the changelog.&lt;/p&gt;

</description>
      <category>iot</category>
      <category>hardware</category>
      <category>ai</category>
      <category>c</category>
    </item>
    <item>
      <title>Restricting MCP connectors to read-only access</title>
      <dc:creator>Wojciech Wentland</dc:creator>
      <pubDate>Fri, 13 Nov 2026 16:15:00 +0000</pubDate>
      <link>https://dev.to/desty2k/restricting-mcp-connectors-to-read-only-access-57pf</link>
      <guid>https://dev.to/desty2k/restricting-mcp-connectors-to-read-only-access-57pf</guid>
      <description>&lt;p&gt;Say you're building a platform where agents read Jira. You could write a Jira client and a set of tools for it. I'd rather not, and most setups I've seen don't: you connect the existing MCP connector, Atlassian's hosted one or a community server, turn on whatever read-only settings it has, and allow only the tools that read.&lt;/p&gt;

&lt;p&gt;That doesn't always make the integration read-only. The allowlist decides which tools the agent can call. The grant you approved decides what a call can do. And in two of the 19 servers I checked, a tool labeled read-only can write. Grafana's ran an &lt;code&gt;INSERT&lt;/code&gt; for me with both of the server's read-only flags on, given an Editor token and a database user that could write.&lt;/p&gt;

&lt;p&gt;I build &lt;a href="https://blog.wentland.io/blog/why-read-only-mcp/" rel="noopener noreferrer"&gt;read-only MCP servers&lt;/a&gt;, so I have a stake in this. On a platform, nobody watches the agent's tool calls or clicks "allow" before one runs. The allowlist, the server's read-only mode and the grant are the whole defense against a write through the connector, so I checked what each of them holds.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I checked
&lt;/h2&gt;

&lt;p&gt;19 maintained MCP servers, vendor and community, local and hosted, between 2026-11-03 and 2026-11-12. For each one I listed the tools in its default configuration and with its read-only mode on, using dummy credentials. Five hosted servers (Notion, Linear, Slack, Stripe, Atlassian) I connected through their consent pages on test accounts. Then I tried writes: one each under a read-only grant on Stripe and Atlassian, and a set against local stacks for Grafana, MongoDB, ClickHouse, Octopus Deploy, TeamCity and Supabase. The full table, with versions, is further down.&lt;/p&gt;

&lt;h2&gt;
  
  
  Allowing only the read tools
&lt;/h2&gt;

&lt;p&gt;The usual way to restrict a connector is an allowlist: the OpenAI Agents SDK, for one, takes a static filter with the tool names you allow. Some platforms filter on the tool's own label instead: MCP lets a server mark a tool &lt;code&gt;readOnlyHint: true&lt;/code&gt;, and Cursor's unattended agents, per Cursor staff, use only tools marked that way.&lt;/p&gt;

&lt;p&gt;Either way you're trusting the server to have put the right tools under the right names and labels. In most of the servers I checked, it has; in the ones below, a name or a label lets a write through.&lt;/p&gt;

&lt;h3&gt;
  
  
  A Grafana image tool that runs queries
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;get_panel_image&lt;/code&gt; renders a dashboard panel or an Explore view as an image, and it's labeled read-only. In Explore mode it takes a datasource and a raw query, and Grafana runs that query to draw the result. I ran mcp-grafana v2.2.0 with both of its restricting flags, &lt;code&gt;--disable-write&lt;/code&gt; and &lt;code&gt;--disable-query&lt;/code&gt;, against Grafana OSS 13.3.1 with the image renderer and a Postgres datasource whose database user was allowed to insert. The two flags removed the SQL query tools. &lt;code&gt;get_panel_image&lt;/code&gt; stayed. I called it with an Editor service-account token and this query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="nf"&gt;probe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;VALUES&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'e2-panel-image-Editor'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;RETURNING&lt;/span&gt; &lt;span class="n"&gt;label&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The row is in the table. This is the image the tool returned to the agent, and it looks exactly like a successful read:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fy1vxz2l7odid9ym4wdxh.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fy1vxz2l7odid9ym4wdxh.webp" alt="The image get_panel_image returned to the agent: Grafana Explore with the INSERT query and the label Postgres returned" width="800" height="532"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  MongoDB's aggregate
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;aggregate&lt;/code&gt; and &lt;code&gt;aggregate-db&lt;/code&gt; are labeled read-only, and most pipelines only read. A &lt;code&gt;$out&lt;/code&gt; stage replaces a whole collection; &lt;code&gt;$merge&lt;/code&gt; modifies one. I ran mongodb-mcp-server 3.2.1 in its default configuration against a local MongoDB 8.0, connected as a user that could write, and called &lt;code&gt;aggregate&lt;/code&gt; with a &lt;code&gt;$out&lt;/code&gt; into a collection that held two documents. The tool answered "The aggregation pipeline executed successfully." Both documents were gone, replaced by the pipeline's output. &lt;code&gt;$merge&lt;/code&gt; overwrote an existing document the same way, and &lt;code&gt;aggregate-db&lt;/code&gt; did both.&lt;/p&gt;

&lt;p&gt;The server has a guard for this. If the client supports elicitation, it asks first: "This aggregation contains a &lt;code&gt;$out&lt;/code&gt; stage that will replace the entire contents of &lt;code&gt;e2.target&lt;/code&gt; [...] Proceed?" The MCP Inspector's command-line client doesn't support elicitation, so it never saw the question. Neither did a Python client (MCP SDK 2.3.0, over stdio) that does support it but connected with the newer 2026-07-28 protocol, the SDK's default: no prompt, and the collection was replaced. Over the older handshake the same client got the prompt, and declining stopped the write. Read-only mode refused both stages before they reached MongoDB, and so did a database user with only the &lt;code&gt;read&lt;/code&gt; role.&lt;/p&gt;

&lt;p&gt;Grafana and MongoDB have the same cause. A label belongs to the tool, and what these tools do depends on their arguments.&lt;/p&gt;

&lt;h3&gt;
  
  
  One tool for reads and writes
&lt;/h3&gt;

&lt;p&gt;Sentry's MCP server sends most operations, creates and deletes included, through &lt;code&gt;execute_sentry_tool&lt;/code&gt;. Octopus Deploy's &lt;code&gt;execute&lt;/code&gt; takes the HTTP method as an argument, GET through DELETE. Cloudflare's API server has an &lt;code&gt;execute&lt;/code&gt; that runs agent-written code against roughly 2,500 endpoints. All three are labeled destructive, correctly, and an allowlist can't take their reads without their writes. Stripe and Atlassian split the two into separate read and write gateways.&lt;/p&gt;

&lt;h3&gt;
  
  
  Filters checked only when listing
&lt;/h3&gt;

&lt;p&gt;In July, Manifold Security &lt;a href="https://www.manifold.security/blog/mcp-atlassian-access-control-bypass" rel="noopener noreferrer"&gt;reported&lt;/a&gt; that the community mcp-atlassian server applied its &lt;code&gt;ENABLED_TOOLS&lt;/code&gt; allowlist when listing tools but not when calling them: "Call tools/call with a restricted tool's name and it executes anyway." Fixed in 0.22.0. It matters when the allowlist lives in the server rather than in your client.&lt;/p&gt;

&lt;p&gt;There's a vocabulary problem too. Atlassian's &lt;code&gt;executeWrite&lt;/code&gt; describes itself as "creates or updates data, non-destructive", and &lt;code&gt;editJiraIssue&lt;/code&gt; ("Every field is set, not appended") carries the same &lt;code&gt;destructiveHint: false&lt;/code&gt;. To the vendor, destructive means delete. The MCP spec says non-destructive means the tool "performs only additive updates". An allowlist of read tools never admits these two, since they're plainly writes. A client that skips prompts for non-destructive tools does. Codex's auto mode, for instance, runs a tool marked non-destructive and closed-world without asking, and both of these are marked that way.&lt;/p&gt;

&lt;h2&gt;
  
  
  Connecting with a read-only grant
&lt;/h2&gt;

&lt;p&gt;Hosted connectors start with a consent page, and that page is the first real answer to "is this read-only?" The five I connected each answered it differently:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Connector&lt;/th&gt;
&lt;th&gt;What the consent page offers&lt;/th&gt;
&lt;th&gt;Tools listed, full grant → read grant&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Notion&lt;/td&gt;
&lt;td&gt;a workspace to pick; no read-only option&lt;/td&gt;
&lt;td&gt;71, of which 34 write&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Linear&lt;/td&gt;
&lt;td&gt;a separate read-only endpoint, or a &lt;code&gt;read&lt;/code&gt; scope&lt;/td&gt;
&lt;td&gt;70 → 38&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Slack&lt;/td&gt;
&lt;td&gt;whatever scopes the app requests; accept or cancel&lt;/td&gt;
&lt;td&gt;27 → 14&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Atlassian&lt;/td&gt;
&lt;td&gt;Read, Write and Search groups, Write preselected&lt;/td&gt;
&lt;td&gt;26 → 19, &lt;code&gt;executeWrite&lt;/code&gt; still listed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Stripe&lt;/td&gt;
&lt;td&gt;Read and Write presets, Write preselected&lt;/td&gt;
&lt;td&gt;11 → 11 (2026-11-12)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Two of the five preselect Write. Notion has no read-only connection at all; the assistant can change any page you can, unless you block its write tools.&lt;/p&gt;

&lt;p&gt;Slack surprised me. Its grants add up per app: a request for read scopes returned a token that still carried the write scopes from an earlier install, until I revoked the app's tokens.&lt;/p&gt;

&lt;p&gt;Going by Stripe's row, the Read preset changes nothing. The call says otherwise. I connected with the Read preset and asked &lt;code&gt;stripe_api_write&lt;/code&gt; to create a customer in the sandbox. Stripe answered with HTTP 403 &lt;code&gt;insufficient_scope&lt;/code&gt;: "Your API key does not have the required permissions for 'PostCustomers'." Atlassian, with Write unticked, refused a &lt;code&gt;createJiraIssue&lt;/code&gt; sent through &lt;code&gt;executeWrite&lt;/code&gt; the same way: "Additional permissions required: write:jira:agent-interface." Nothing was created on either account. That's one write per server: the grant held where I tested it, while the tool list still showed the write tool.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fh3tfej5l44xisd8rpio1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fh3tfej5l44xisd8rpio1.png" alt="Sequence: the agent lists tools, the list includes the write tool, the call gets 403 insufficient_scope, and the agent is sent to a second consent page" width="800" height="493"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A 403 with &lt;code&gt;insufficient_scope&lt;/code&gt; is how the spec asks for more access, and the MCP Python SDK in my test script answered it by opening a second consent page on its own. Atlassian's challenge names the missing write scope, so clicking through grants write. Stripe's asks for &lt;code&gt;mcp&lt;/code&gt;, the scope the grant already had, because its permissions sit behind the grant rather than in OAuth scopes; the second page looked like the first, and choosing Read again failed again.&lt;/p&gt;

&lt;p&gt;A real client behaved differently. Claude Code, connected to Atlassian with Write unticked and asked to create an issue, never tried. Atlassian's operation search returned only reads, and Claude told me the connection was read-only and how to re-authorize it with write access. Either way, a read-only connection sits one consent page away from read-write. On a platform, someone has to decide who may approve that page.&lt;/p&gt;

&lt;h2&gt;
  
  
  Read-only mode in the server
&lt;/h2&gt;

&lt;p&gt;12 of the 19 servers have a read-only mode of some kind. It's off by default in all but two. ClickHouse's server sends each query with the database setting &lt;code&gt;readonly=1&lt;/code&gt; unless you enable writes, and ClickHouse refused every write I sent, including queries that tried to switch the setting off. JetBrains' built-in TeamCity server starts in a safe mode where the only write is queuing a personal build. Most modes remove the write tools from the list (&lt;code&gt;--read-only&lt;/code&gt; in GitHub and Supabase, &lt;code&gt;READ_ONLY_MODE&lt;/code&gt; in mcp-atlassian). A few keep the tool and refuse the call: under &lt;code&gt;--read-only&lt;/code&gt;, Octopus Deploy's &lt;code&gt;execute&lt;/code&gt; stays listed, and the server refused every POST, PUT, PATCH and DELETE before it reached Octopus. Some lean on a database user. On Supabase's local stack, read-only mode ran &lt;code&gt;execute_sql&lt;/code&gt; as &lt;code&gt;supabase_read_only_user&lt;/code&gt;, and an &lt;code&gt;INSERT&lt;/code&gt; failed even after the query switched its transaction to read-write.&lt;/p&gt;

&lt;p&gt;Grafana's flags removed every tool that was obviously a query and kept the one that draws pictures of queries.&lt;/p&gt;

&lt;p&gt;If a person or a client is in the loop, labels matter in a second way. I ran a stub server with five no-op tools that differed only in their labels through VS Code 1.145.2, Codex 0.167.0 and Claude Code 2.1.321. All three ran the tool marked read-only without asking (Claude Code in plan mode). Codex also ran the one marked non-destructive and closed-world. With full access and approval set to "never", which is how you'd run Codex with nobody watching, all five ran.&lt;/p&gt;

&lt;h2&gt;
  
  
  Read-only support in 19 MCP servers
&lt;/h2&gt;

&lt;p&gt;Checked 2026-11-03 to 2026-11-12 with dummy credentials (local servers) or test accounts (hosted). Tool counts are for the default configuration and change between releases. "(tested)" in the credential column means a write under that credential was refused; the other cells are what the vendor documents. Left out: a community TeamCity server (I maintain a competing one), the archived Postgres reference server, two deprecated Cloudflare servers, Notion's unmaintained local server, and Octopus Deploy's hosted server, which needs an instance. Not tested: ChatGPT, Claude custom connectors, Cursor, paid plans.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Server&lt;/th&gt;
&lt;th&gt;Version&lt;/th&gt;
&lt;th&gt;Write tools by default&lt;/th&gt;
&lt;th&gt;Read-only mode&lt;/th&gt;
&lt;th&gt;Read-only grant or credential&lt;/th&gt;
&lt;th&gt;Tool list follows the grant&lt;/th&gt;
&lt;th&gt;Labeled read-only, can write&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;GitHub (official)&lt;/td&gt;
&lt;td&gt;2.1.0&lt;/td&gt;
&lt;td&gt;19 of 46&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;--read-only&lt;/code&gt; (46 → 27)&lt;/td&gt;
&lt;td&gt;fine-grained token, read permissions&lt;/td&gt;
&lt;td&gt;classic token and OAuth only&lt;/td&gt;
&lt;td&gt;none found&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Grafana (official)&lt;/td&gt;
&lt;td&gt;2.2.0&lt;/td&gt;
&lt;td&gt;20 of 80&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;--disable-write&lt;/code&gt; (80 → 63)&lt;/td&gt;
&lt;td&gt;Viewer service account (tested)&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;get_panel_image&lt;/code&gt; (tested)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;MongoDB (official)&lt;/td&gt;
&lt;td&gt;3.2.1&lt;/td&gt;
&lt;td&gt;11 of 27&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;--readOnly&lt;/code&gt; (27 → 18)&lt;/td&gt;
&lt;td&gt;database user with &lt;code&gt;read&lt;/code&gt; role (tested)&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;aggregate&lt;/code&gt;, &lt;code&gt;aggregate-db&lt;/code&gt; (tested)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ClickHouse (official)&lt;/td&gt;
&lt;td&gt;0.7.0&lt;/td&gt;
&lt;td&gt;none, writes off unless enabled&lt;/td&gt;
&lt;td&gt;database &lt;code&gt;readonly=1&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;SELECT-only user (tested)&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;td&gt;none found, no labels&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Kubernetes (containers)&lt;/td&gt;
&lt;td&gt;0.1.1&lt;/td&gt;
&lt;td&gt;6 of 20&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;read_only&lt;/code&gt; config key (20 → 14)&lt;/td&gt;
&lt;td&gt;RBAC &lt;code&gt;view&lt;/code&gt; role&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;td&gt;none found&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Slack (korotovsky)&lt;/td&gt;
&lt;td&gt;1.3.0&lt;/td&gt;
&lt;td&gt;9 of 18&lt;/td&gt;
&lt;td&gt;none&lt;/td&gt;
&lt;td&gt;read-only Slack scopes&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;td&gt;none found&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Slack (official, hosted)&lt;/td&gt;
&lt;td&gt;1.0.0&lt;/td&gt;
&lt;td&gt;13 of 27&lt;/td&gt;
&lt;td&gt;none&lt;/td&gt;
&lt;td&gt;the app's user-token scopes&lt;/td&gt;
&lt;td&gt;yes (27 → 14)&lt;/td&gt;
&lt;td&gt;none found&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Notion (hosted)&lt;/td&gt;
&lt;td&gt;1.2.0&lt;/td&gt;
&lt;td&gt;34 of 71&lt;/td&gt;
&lt;td&gt;none&lt;/td&gt;
&lt;td&gt;none&lt;/td&gt;
&lt;td&gt;one documented case&lt;/td&gt;
&lt;td&gt;none found&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Linear (hosted)&lt;/td&gt;
&lt;td&gt;1.0.2&lt;/td&gt;
&lt;td&gt;31 of 70&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;/mcp/readonly&lt;/code&gt; endpoint (70 → 38)&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;read&lt;/code&gt; scope&lt;/td&gt;
&lt;td&gt;yes (70 → 38)&lt;/td&gt;
&lt;td&gt;none found&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sentry (official)&lt;/td&gt;
&lt;td&gt;0.42.0&lt;/td&gt;
&lt;td&gt;3 of 9&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;--skills=inspect&lt;/code&gt; (9 → 7)&lt;/td&gt;
&lt;td&gt;read scopes&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;td&gt;none found&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Stripe (hosted)&lt;/td&gt;
&lt;td&gt;1.0.0&lt;/td&gt;
&lt;td&gt;3 of 11&lt;/td&gt;
&lt;td&gt;none&lt;/td&gt;
&lt;td&gt;Read preset (tested)&lt;/td&gt;
&lt;td&gt;no (11 → 11)&lt;/td&gt;
&lt;td&gt;none found&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Atlassian Rovo (hosted)&lt;/td&gt;
&lt;td&gt;1.0.0&lt;/td&gt;
&lt;td&gt;9 of 26&lt;/td&gt;
&lt;td&gt;none in the server; an org admin can turn writes off&lt;/td&gt;
&lt;td&gt;Write unticked on the consent page (tested)&lt;/td&gt;
&lt;td&gt;partly (26 → 19)&lt;/td&gt;
&lt;td&gt;none found&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;mcp-atlassian (community)&lt;/td&gt;
&lt;td&gt;0.23.1&lt;/td&gt;
&lt;td&gt;40 of 98&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;READ_ONLY_MODE&lt;/code&gt; (98 → 58)&lt;/td&gt;
&lt;td&gt;read-only token or OAuth scopes&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;td&gt;none found&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Supabase (official)&lt;/td&gt;
&lt;td&gt;0.15.0&lt;/td&gt;
&lt;td&gt;13 of 31&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;--read-only&lt;/code&gt; (31 → 19)&lt;/td&gt;
&lt;td&gt;project-scoped token&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;td&gt;none found&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cloudflare API (official)&lt;/td&gt;
&lt;td&gt;main, 2026-11&lt;/td&gt;
&lt;td&gt;1 of 4&lt;/td&gt;
&lt;td&gt;none&lt;/td&gt;
&lt;td&gt;read-only API token&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;td&gt;none found&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Octopus Deploy (npm)&lt;/td&gt;
&lt;td&gt;2.3.2&lt;/td&gt;
&lt;td&gt;5 of 30&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;--read-only&lt;/code&gt; (30 → 26)&lt;/td&gt;
&lt;td&gt;API key with a read-only role (tested)&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;td&gt;none found&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Filesystem (reference)&lt;/td&gt;
&lt;td&gt;2.1.0&lt;/td&gt;
&lt;td&gt;4 of 14&lt;/td&gt;
&lt;td&gt;none, directory allow-list&lt;/td&gt;
&lt;td&gt;OS permissions, read-only mounts&lt;/td&gt;
&lt;td&gt;n/a&lt;/td&gt;
&lt;td&gt;none found&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Postgres (crystaldba)&lt;/td&gt;
&lt;td&gt;0.3.0&lt;/td&gt;
&lt;td&gt;2 of 9&lt;/td&gt;
&lt;td&gt;&lt;code&gt;--access-mode=restricted&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;SELECT-only role&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;td&gt;none found, no labels&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;TeamCity (JetBrains, built-in)&lt;/td&gt;
&lt;td&gt;2026.2.2&lt;/td&gt;
&lt;td&gt;one limited write in safe mode&lt;/td&gt;
&lt;td&gt;safe mode is the default&lt;/td&gt;
&lt;td&gt;Read-only token preset (tested)&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;td&gt;none found, no labels&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;My two servers, for &lt;a href="https://blog.wentland.io/blog/read-only-mcp-server-teamcity/" rel="noopener noreferrer"&gt;TeamCity&lt;/a&gt; and &lt;a href="https://blog.wentland.io/blog/read-only-mcp-server-akamai/" rel="noopener noreferrer"&gt;Akamai&lt;/a&gt;, have no write code, and every tool is labeled read-only (TeamCity 1.0.1, Akamai 0.2.1). That label is my claim about my own code; nothing in MCP checks it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I check before connecting an MCP connector
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Question&lt;/th&gt;
&lt;th&gt;Where to look&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;What can the account I'm connecting change?&lt;/td&gt;
&lt;td&gt;The consent page or token settings. Untick Write, pick the read endpoint, or use a key with read permissions. If the connector has no read-only grant (Notion), the allowlist is all you have.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Who can approve more access later?&lt;/td&gt;
&lt;td&gt;The platform's connector settings. A refused write turns into a request for more scope.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Which tools do I allow?&lt;/td&gt;
&lt;td&gt;List them by name, not by label. Look hard at tools that render, export, query or "execute" anything.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Does the server have a read-only mode, and what does it leave?&lt;/td&gt;
&lt;td&gt;Its README and its tool list with the mode on.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Of these, only the credential is enforced by the system that holds the data. And read-only stops writes through those tools; anything the agent can read, it can still pass on.&lt;/p&gt;

&lt;p&gt;The Grafana test had a second half. I made the same call with a Viewer token. Nothing ran: Grafana sends a Viewer away from Explore, so the query never reached Postgres. The tool still reported success, and returned a picture of Grafana's home page. Nothing in the response said the query never ran.&lt;/p&gt;

</description>
      <category>mcp</category>
      <category>ai</category>
      <category>security</category>
      <category>llm</category>
    </item>
    <item>
      <title>A read-only MCP server for TeamCity</title>
      <dc:creator>Wojciech Wentland</dc:creator>
      <pubDate>Mon, 09 Nov 2026 18:00:00 +0000</pubDate>
      <link>https://dev.to/desty2k/a-read-only-mcp-server-for-teamcity-pke</link>
      <guid>https://dev.to/desty2k/a-read-only-mcp-server-for-teamcity-pke</guid>
      <description>&lt;p&gt;Most build questions arrive the same way: someone sends a link to a red build and asks what broke. Answering it by hand means opening the build, scrolling a log that can run to tens of thousands of lines, checking which tests failed and whether they were already muted, and looking at what changed since the last green run.&lt;/p&gt;

&lt;p&gt;With the &lt;a href="https://github.com/desty2k/readonly-mcp-teamcity" rel="noopener noreferrer"&gt;read-only MCP server for TeamCity&lt;/a&gt;, released as 1.0.0 on November 2, I paste the user's message, link included, into the agent and get a root-cause analysis back. It's built from the real log lines, failed tests and commits, so I can check every claim in it against the build. Nobody downloads a log.&lt;/p&gt;

&lt;p&gt;The server has 29 tools across projects, build configurations, builds, logs, tests, agents and the queue. None of them can trigger, cancel, pin or tag anything. It's the second server in this series after &lt;a href="https://blog.wentland.io/blog/read-only-mcp-server-akamai/" rel="noopener noreferrer"&gt;Akamai&lt;/a&gt;; &lt;a href="https://blog.wentland.io/blog/why-read-only-mcp/" rel="noopener noreferrer"&gt;why I only build read-only ones&lt;/a&gt; is a separate post.&lt;/p&gt;

&lt;h2&gt;
  
  
  From a link to a root cause
&lt;/h2&gt;

&lt;p&gt;The slow part of a failed build is rarely the fix. It's finding the line that explains it. The error can sit thousands of lines into the log, while the end of the log shows artifact publishing and cleanup. Then you still have to check whether the failing test was already broken last week, and which commit went in.&lt;/p&gt;

&lt;p&gt;With the server, the agent does that legwork. You paste the link as the user sent it, and the answer comes back with the error lines from the log, the tests that failed (new failures first, already-muted ones marked), and the commits that went into the build.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Find the build from the link.&lt;/li&gt;
&lt;li&gt;Read its error lines, failed tests and build problems.&lt;/li&gt;
&lt;li&gt;List the commits in the build.&lt;/li&gt;
&lt;li&gt;Write the root cause, quoting log lines, tests and commits.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Links to builds, pipelines, projects and commits all work, whether they come from the browser, a chat message or an old bookmark. The first step is one call that pulls everything TeamCity knows about the failure, and it's small enough to leave room for the conversation. If the agent needs more, it can read the log around a specific line or check who is already investigating a test.&lt;/p&gt;

&lt;p&gt;For the person who sent the link, the answer arrives with the failing line, the test and the commit that probably caused it, and every one of them can be checked in TeamCity.&lt;/p&gt;

&lt;h2&gt;
  
  
  "Where's the pipeline for X?"
&lt;/h2&gt;

&lt;p&gt;Not every question comes with a link. Someone asks where the production deploy for the payments service is, or which pipeline builds the docs site. They don't know the configuration's name, let alone its ID, and TeamCity's search wants one or the other.&lt;/p&gt;

&lt;p&gt;The agent can work from that description. It finds configurations by approximate names and project paths, so "prod deploy for payments" lands on the right pipeline. When two candidates fit about equally well, say the production and staging deploys, it shows both and asks which one was meant instead of picking one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Giving an agent access to CI
&lt;/h2&gt;

&lt;p&gt;A CI server can deploy to production, so handing an agent a token to it is a fair thing to worry about. This server only reads: it can't trigger, cancel, pin or tag builds, and a test fails if its HTTP client ever gets a method other than GET.&lt;/p&gt;

&lt;p&gt;Keep the token read-only as well. In TeamCity, create it with &lt;strong&gt;Limit per project&lt;/strong&gt; and the &lt;strong&gt;Read-only&lt;/strong&gt; preset. That preset covers everything the tools read and nothing that changes a build.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the agent can answer
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;"Why did this build fail?" with a pasted link&lt;/li&gt;
&lt;li&gt;"Find the deploy pipeline for the auth service."&lt;/li&gt;
&lt;li&gt;"Show me the last 10 builds of the API build and which ones failed."&lt;/li&gt;
&lt;li&gt;"Which agents are offline right now?"&lt;/li&gt;
&lt;li&gt;"What's in the build queue and why is it waiting?"&lt;/li&gt;
&lt;li&gt;"Who is investigating the failures in the Payments project?"&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Setup
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;claude mcp add teamcity &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nv"&gt;TEAMCITY_BASE_URL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;https://teamcity.example.com &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nv"&gt;TEAMCITY_TOKEN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;your-token &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--&lt;/span&gt; uvx readonly-mcp-teamcity
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Python 3.11 or newer, or the container from GHCR. Source, the full tool list and a comparison with JetBrains' own MCP server and the community ones: &lt;a href="https://github.com/desty2k/readonly-mcp-teamcity" rel="noopener noreferrer"&gt;readonly-mcp-teamcity on GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;One question it still doesn't answer well is "when did this start?" That means going through the logs of many past builds, and I haven't built that part yet.&lt;/p&gt;

</description>
      <category>mcp</category>
      <category>ai</category>
      <category>devops</category>
      <category>python</category>
    </item>
    <item>
      <title>How fast is PostgreSQL LISTEN/NOTIFY? I ran some benchmarks to find out.</title>
      <dc:creator>Wojciech Wentland</dc:creator>
      <pubDate>Fri, 06 Nov 2026 18:00:00 +0000</pubDate>
      <link>https://dev.to/desty2k/how-fast-is-postgresql-listennotify-i-ran-some-benchmarks-to-find-out-5bod</link>
      <guid>https://dev.to/desty2k/how-fast-is-postgresql-listennotify-i-ran-some-benchmarks-to-find-out-5bod</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/desty2k/listennotify-performance-in-postgresql-3a82" class="crayons-story__hidden-navigation-link"&gt;LISTEN/NOTIFY performance in PostgreSQL&lt;/a&gt;


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

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

          &lt;/div&gt;
          &lt;a href="https://dev.to/desty2k/listennotify-performance-in-postgresql-3a82" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Nov 5&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/desty2k/listennotify-performance-in-postgresql-3a82" id="article-link-4983182"&gt;
          LISTEN/NOTIFY performance in PostgreSQL
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/postgres"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;postgres&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/dotnet"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;dotnet&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/performance"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;performance&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/database"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;database&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
            &lt;a href="https://dev.to/desty2k/listennotify-performance-in-postgresql-3a82#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

              &lt;span class="hidden s:inline"&gt;Add&amp;nbsp;Comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            9 min read
          &lt;/small&gt;
          
          &lt;div class="only-sidebar-menu-item trusted-visible-block print-hidden align-center"&gt;
                
                    
                
          &lt;/div&gt;

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

&lt;/div&gt;


</description>
      <category>backend</category>
      <category>database</category>
      <category>performance</category>
    </item>
    <item>
      <title>LISTEN/NOTIFY performance in PostgreSQL</title>
      <dc:creator>Wojciech Wentland</dc:creator>
      <pubDate>Thu, 05 Nov 2026 16:15:00 +0000</pubDate>
      <link>https://dev.to/desty2k/listennotify-performance-in-postgresql-3a82</link>
      <guid>https://dev.to/desty2k/listennotify-performance-in-postgresql-3a82</guid>
      <description>&lt;p&gt;I'm building &lt;a href="https://blog.wentland.io/projects/corfedo-work/" rel="noopener noreferrer"&gt;Corfedo Work&lt;/a&gt;, a .NET library for background jobs that keeps its state in the application's own PostgreSQL database. Its workers need to know when something changed: a job became due, or a job somebody is waiting for has ended. The PostgreSQL answer is &lt;code&gt;NOTIFY&lt;/code&gt; in the transaction that made the change. I designed the library's signals around it.&lt;/p&gt;

&lt;p&gt;Then I measured it. Single-row transactions with a &lt;code&gt;NOTIFY&lt;/code&gt; committed about 3,900 times per second with 8 clients, and about 3,900 with 64. Without the &lt;code&gt;NOTIFY&lt;/code&gt;, the same transactions reached 16,700 and 56,700.&lt;/p&gt;

&lt;h2&gt;
  
  
  Signals that ride the transaction
&lt;/h2&gt;

&lt;p&gt;A signal in Work says "something you wait for may have changed, read again". It's a topic and a key, with no data. The application sends it in the same transaction as the change:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="n"&gt;SignalTopic&lt;/span&gt; &lt;span class="n"&gt;Pending&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"orders.pending"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;var&lt;/span&gt; &lt;span class="n"&gt;tx&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;BeginTransactionAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ct&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;SaveChangesAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ct&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;signals&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;SendAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WorkTransaction&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;Pending&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;TenantId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ct&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;tx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CommitAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ct&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The worker on the other side treats a signal as a reason to look, never as the change itself:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Subscribed with signals.Subscribe(Pending, worker).&lt;/span&gt;
&lt;span class="k"&gt;sealed&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;OrderWorker&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ISignalSubscriber&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// A tenant's orders may be pending: read again.&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Received&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;Wake&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="c1"&gt;// After every (re)connection signals may have been missed: read everything.&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Resync&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;Wake&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Its loop reads the pending orders, then sleeps until the next wake or a 30-second fallback poll, whichever comes first.&lt;/p&gt;

&lt;p&gt;What made &lt;code&gt;NOTIFY&lt;/code&gt; attractive is when the message goes out. PostgreSQL delivers it after the transaction commits, and never if the transaction rolls back. A worker woken by it reads the committed row, not an older version, and nobody wakes for a change that was undone. I didn't have to write any of that.&lt;/p&gt;

&lt;p&gt;I wasn't the first to hit the ceiling. Recall.ai &lt;a href="https://www.recall.ai/blog/postgres-listen-notify-does-not-scale" rel="noopener noreferrer"&gt;traced three outages in four days&lt;/a&gt; in March 2025 to a &lt;code&gt;NOTIFY&lt;/code&gt; on a busy write path and moved the logic out of the database. In July 2026, DBOS published the opposite headline, &lt;a href="https://www.dbos.dev/blog/postgres-listen-notify-scalability" rel="noopener noreferrer"&gt;"Postgres LISTEN/NOTIFY can actually scale"&lt;/a&gt;: their stream writes went from 2,900 to 60,000 per second once they buffered notifications and sent them in batches. Recall.ai's post now says a PostgreSQL commit removed the bottleneck. DBOS says the same change, which ships in PostgreSQL 19, doesn't. Before choosing a side for a job library I wanted to see where the limit comes from.&lt;/p&gt;

&lt;h2&gt;
  
  
  The ceiling
&lt;/h2&gt;

&lt;p&gt;Setup: Ryzen 7 7700X with an NVMe drive, PostgreSQL 18.6 and 19 RC1 in Docker with &lt;code&gt;fsync&lt;/code&gt; on, a .NET 10 client on the same machine. Each transaction inserts one row; two sessions listen. Wake-up is the time from a commit to the first listener receiving its message. Medians of three 8-second runs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvw6rh26j7bbpo0aevufu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvw6rh26j7bbpo0aevufu.png" alt="Commits per second by client count: no NOTIFY and batched rise to about 50,000-57,000, NOTIFY in the transaction stays near 3,900" width="799" height="384"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Single-row transactions, two listening sessions. PostgreSQL 18.6; 19 RC1 is within 3% at every point.&lt;/em&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Clients&lt;/th&gt;
&lt;th&gt;No NOTIFY&lt;/th&gt;
&lt;th&gt;NOTIFY in the transaction&lt;/th&gt;
&lt;th&gt;Median wake-up&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;2,711&lt;/td&gt;
&lt;td&gt;2,456&lt;/td&gt;
&lt;td&gt;0.37 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;16,663&lt;/td&gt;
&lt;td&gt;3,960&lt;/td&gt;
&lt;td&gt;2.0 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;32&lt;/td&gt;
&lt;td&gt;42,179&lt;/td&gt;
&lt;td&gt;3,923&lt;/td&gt;
&lt;td&gt;8.0 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;64&lt;/td&gt;
&lt;td&gt;56,700&lt;/td&gt;
&lt;td&gt;3,925&lt;/td&gt;
&lt;td&gt;16.1 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The flat line is the finding. More clients don't add commits; they add waiting, which is why the wake-up time grows from 2 ms to 16 ms. The notifications arrive later because the transactions sending them queue up.&lt;/p&gt;
&lt;h2&gt;
  
  
  What PostgreSQL does at commit
&lt;/h2&gt;

&lt;p&gt;Notifications go into one queue shared by every database in the cluster, in commit order. To keep that order, a transaction that has notifications takes a lock before it commits. It shows up in the logs as &lt;code&gt;AccessExclusiveLock on object 0 of class 1262 of database 0&lt;/code&gt;, the line Recall.ai found. The transaction holds it until it ends, which is after its commit record has been flushed to disk. So two notifying transactions never commit at the same time.&lt;/p&gt;

&lt;p&gt;That alone would be a queue. What makes it expensive is group commit. Normally, sessions that commit at the same moment share one WAL flush: in my runs one flush covered 4 commits at 8 clients and 19 at 64. With &lt;code&gt;NOTIFY&lt;/code&gt; it covered exactly one, at any client count.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3u7qf6lpul24t94i68ut.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3u7qf6lpul24t94i68ut.png" alt="Four sessions committing: without NOTIFY one WAL flush covers all four commits; with NOTIFY each commit holds the lock through its own flush" width="800" height="422"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Schematic, not to scale.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The database statistics at 64 clients:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;No NOTIFY&lt;/th&gt;
&lt;th&gt;NOTIFY in the transaction&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Commits per second&lt;/td&gt;
&lt;td&gt;56,700&lt;/td&gt;
&lt;td&gt;3,925&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Database CPU&lt;/td&gt;
&lt;td&gt;4.35 cores&lt;/td&gt;
&lt;td&gt;0.73 cores&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Commits per WAL flush&lt;/td&gt;
&lt;td&gt;19.1&lt;/td&gt;
&lt;td&gt;1.0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Most common wait of active sessions&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;LWLock:WALWrite&lt;/code&gt; 72%&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;Lock:object&lt;/code&gt; 98%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;At the ceiling the database is nearly idle. Almost every active session waits on that one lock, and a faster CPU wouldn't move the number. My reading is that the ceiling follows how long one WAL flush takes: here about 3,550 flushes per second for 3,925 commits. I haven't run it on another disk.&lt;/p&gt;

&lt;p&gt;Listeners pay too. Each notification wakes every listening session, and each one runs a short transaction to read the queue. At 8 clients the database ran 10,900 transactions per second to commit 3,960 of mine.&lt;/p&gt;
&lt;h2&gt;
  
  
  PostgreSQL 19
&lt;/h2&gt;

&lt;p&gt;The commit Recall.ai links, &lt;a href="https://github.com/postgres/postgres/commit/282b1cde9dedf456ecf02eb27caf086023a7bb71" rel="noopener noreferrer"&gt;&lt;code&gt;282b1cd&lt;/code&gt;&lt;/a&gt;, adds a shared map of which session listens on which channel. A session that doesn't listen on the notified channel is no longer woken. Its message says nothing about the commit lock.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fleofmvxs4hze4qd7g7ih.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fleofmvxs4hze4qd7g7ih.png" alt="Commits per second at 64 clients on PostgreSQL 18.6 and 19 RC1: nearly equal in every mode" width="800" height="363"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Median of three runs, 64 clients, two listening sessions on one channel.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;On one channel with two listeners, 19 RC1 matches 18.6 within 3% in every mode: 3,912 commits per second with &lt;code&gt;NOTIFY&lt;/code&gt; in the transaction at 64 clients, &lt;code&gt;Lock:object&lt;/code&gt; at 98% of waits, one commit per WAL flush.&lt;/p&gt;

&lt;p&gt;That isn't the case the patch is for, so I ran the one it is for: 50 listening sessions, each on its own channel, and every transaction notifying one of them. At 64 clients:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;18.6&lt;/th&gt;
&lt;th&gt;19 RC1&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Commits per second&lt;/td&gt;
&lt;td&gt;3,963–3,982&lt;/td&gt;
&lt;td&gt;3,975–3,987&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Database transactions per second&lt;/td&gt;
&lt;td&gt;183,246&lt;/td&gt;
&lt;td&gt;7,265&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Database CPU&lt;/td&gt;
&lt;td&gt;2.68 cores&lt;/td&gt;
&lt;td&gt;0.75 cores&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Active sessions waiting on &lt;code&gt;Lock:object&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;97%&lt;/td&gt;
&lt;td&gt;98%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;On 18.6, all 50 listeners woke for every notification and read the queue, although 49 of them had nothing to read. On 19 they stay asleep, and the database does a 25th of the work. The commit rate doesn't move.&lt;/p&gt;

&lt;p&gt;PostgreSQL 19 removes a real cost, the one that grows with the number of listening sessions. The waits in Recall.ai's logs were on the commit lock, though, and in my runs that lock behaves the same in 19 RC1 as in 18.6. If your notifying transactions queue on commit today, 19 won't let more of them commit per second.&lt;/p&gt;
&lt;h2&gt;
  
  
  Sending after commit
&lt;/h2&gt;

&lt;p&gt;If the lock is taken by transactions that notify, the fix is to have fewer of them. DBOS buffers notifications in memory and sends them in batches, so only the batch takes the lock. I did the same, except that Work, as a library, doesn't own the transaction. The application begins it, maybe through Entity Framework, and commits it whenever it likes. There's no commit callback I can rely on.&lt;/p&gt;

&lt;p&gt;What a library can get is the transaction's ID. The sending statement returns it, at no extra round trip:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;job_ends&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;job_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;VALUES&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;RETURNING&lt;/span&gt; &lt;span class="n"&gt;pg_current_xact_id&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The process keeps the ID and the message in memory. One background sender per process then asks PostgreSQL which of those transactions committed and notifies only those, in one statement:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="n"&gt;batch&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;MATERIALIZED&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;xid&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pg_xact_status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;xid&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;
    &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="k"&gt;unnest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;xid8&lt;/span&gt;&lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nb"&gt;text&lt;/span&gt;&lt;span class="p"&gt;[])&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;xid&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;sent&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;MATERIALIZED&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;count&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pg_notify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'work'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;
    &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;DISTINCT&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;batch&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'committed'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;xid&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;batch&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'in progress'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
       &lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;batch&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'in progress'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sent&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Committed transactions get their messages sent, duplicates collapse into one, rolled-back ones are dropped, and the ones still running come back to be checked again later.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flpodiog0v6tysxvn69x3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flpodiog0v6tysxvn69x3.png" alt="The app records the transaction ID and commits without the lock; 2 ms later the sender notifies committed transactions and gets back those still running" width="799" height="658"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first version had a bug that cost me about 30 signals per run. It read the statuses in two statements: one sent the committed messages, the next returned the ones still running. A transaction that committed between those two statements was in neither list, and its message was gone. Reading each status once per batch, in one materialized CTE, fixed it.&lt;/p&gt;

&lt;p&gt;The other setting is how often to send. A sender that flushes whenever anything is waiting turns into a notifying transaction itself, up to 2,900 times a second here, and queues for the same lock. A minimum gap between batches trades a little wake-up time for throughput:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Clients&lt;/th&gt;
&lt;th&gt;Flush when anything waits&lt;/th&gt;
&lt;th&gt;At least 2 ms apart&lt;/th&gt;
&lt;th&gt;At least 5 ms apart&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;2,645 · 1.2 ms&lt;/td&gt;
&lt;td&gt;2,699 · 2.1 ms&lt;/td&gt;
&lt;td&gt;2,667 · 3.6 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;16,280 · 0.6 ms&lt;/td&gt;
&lt;td&gt;16,763 · 1.9 ms&lt;/td&gt;
&lt;td&gt;16,791 · 2.9 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;32&lt;/td&gt;
&lt;td&gt;37,566 · 0.9 ms&lt;/td&gt;
&lt;td&gt;39,279 · 2.3 ms&lt;/td&gt;
&lt;td&gt;39,521 · 4.2 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;64&lt;/td&gt;
&lt;td&gt;47,144 · 1.4 ms&lt;/td&gt;
&lt;td&gt;49,800 · 2.7 ms&lt;/td&gt;
&lt;td&gt;50,194 · 4.5 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Commits per second · median wake-up, PostgreSQL 18.6.&lt;/p&gt;

&lt;p&gt;The difference is smaller than I expected, 3–5%. I kept 2 ms. With it, 64 clients commit about 50,000 times per second, 88% of the rate without notifications, and the median wake-up is 2.7 ms instead of 16.&lt;/p&gt;

&lt;p&gt;This is how Work sends signals now, in place of &lt;code&gt;NOTIFY&lt;/code&gt; in the transaction. Through the library's API, 64 clients that each insert a row and send a signal went from 3,972 to 40,204 commits per second. Batching costs 2–4% of that against the same statement without a signal; the bigger cost is the statement itself, since an application's send is a round trip of its own. Work's internal statements return the transaction ID with the rows they change and skip it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it costs
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A process that crashes after the commit and before the batch loses those signals. Readers need the fallback poll. Work already had one; with batching it stops being optional.&lt;/li&gt;
&lt;li&gt;A transaction ID can't tell a rollback to a savepoint apart. A message recorded after a savepoint that was later rolled back still goes out if the transaction commits. The reader wakes, finds nothing and goes back to waiting. I changed Work's signal contract to allow this.&lt;/li&gt;
&lt;li&gt;Wake-ups are later at low load. With one client, &lt;code&gt;NOTIFY&lt;/code&gt; in the transaction woke the listener in 0.37 ms and the batch in 2.1 ms, at the same throughput.&lt;/li&gt;
&lt;li&gt;A transaction that sends gets a transaction ID even if it wrote nothing else.&lt;/li&gt;
&lt;li&gt;There's a background sender per process to write, test and shut down cleanly.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  When I'd keep NOTIFY in the transaction
&lt;/h2&gt;

&lt;p&gt;If the application commits a few hundred notifying transactions per second, far below the ceiling, I'd keep it. It's less code, it wakes faster, and the transaction guarantees are exact. The ceiling I measured is per cluster, though, not per application: every notifying transaction on the server shares it.&lt;/p&gt;

&lt;p&gt;Whatever the approach, notify only on changes somebody waits for. Work signals a job's end only when a caller is waiting for that job; signalling every row change would put every commit in the queue for the lock.&lt;/p&gt;

&lt;p&gt;To see whether you're already there, look at the waits:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;count&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;pg_stat_activity&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;wait_event_type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Lock'&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;wait_event&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'object'&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="k"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'active'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A steady count during write bursts, together with low CPU, is the signature I saw in every run with &lt;code&gt;NOTIFY&lt;/code&gt; in the transaction.&lt;/p&gt;

&lt;p&gt;I haven't run this on a cloud volume, where a WAL flush takes longer than on a local NVMe drive. If the ceiling follows flush time, as the numbers here suggest, it would sit lower there.&lt;/p&gt;

&lt;p&gt;The other run I want is one without &lt;code&gt;NOTIFY&lt;/code&gt; at all. A transactional message written with &lt;code&gt;pg_logical_emit_message&lt;/code&gt; reaches a logical decoding consumer only if its transaction commits. It should also vanish with a rolled-back savepoint, the guarantee batching gave up, but I haven't tested that yet. Nor whether one consumer keeps up with 50,000 commits a second.&lt;/p&gt;

</description>
      <category>postgres</category>
      <category>dotnet</category>
      <category>performance</category>
      <category>database</category>
    </item>
    <item>
      <title>Designing tools that AI can actually use</title>
      <dc:creator>Wojciech Wentland</dc:creator>
      <pubDate>Wed, 01 Jul 2026 07:31:00 +0000</pubDate>
      <link>https://dev.to/desty2k/designing-tools-that-ai-can-actually-use-24pp</link>
      <guid>https://dev.to/desty2k/designing-tools-that-ai-can-actually-use-24pp</guid>
      <description>&lt;p&gt;Here's a tool definition I see all the time:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nd"&gt;@tool&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get_data&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Gets data.&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The model has no way to know when to call this. "Gets data" could match almost any request. And when an agent is choosing among thirty tools, the description does most of the routing. To the model, that two-word docstring is the interface; the code underneath barely enters the decision.&lt;/p&gt;

&lt;p&gt;Most of the agent bugs I chase turn out to be tool-selection bugs. The model picks the wrong tool, or picks nothing when it should have acted. Sometimes it calls the right tool with the wrong arguments. The fix is almost always in the description, not the code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Descriptions are prompts, not docstrings
&lt;/h2&gt;

&lt;p&gt;A description has to answer two questions for the model: when should I call this, and what do I get back. Here's the same tool written for a human reader:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nd"&gt;@tool&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;search_entities&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Search for entities.&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And written for the model that has to route to it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nd"&gt;@tool&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;search_entities&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Annotated&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Search term, matches name and domain. Use exact terms, NO wildcards&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Find entities by name or domain.

    Use this when the user refers to an entity but you don&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;t
    have its exact ID. Partial and approximate names work.
    Returns a ranked list of matches with IDs, names, and types.

    If you can&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;t find an entity by name, try its domain
    (e.g., &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;example.com&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;).

    Example questions:
        - &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Find the entity for Acme Corp&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;
        - &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Search for the vendor with domain example.com&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;
    &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second one says when to reach for it, what comes back, and what to do when the obvious approach fails. The &lt;code&gt;Example questions&lt;/code&gt; block is pulling more weight than it looks: it anchors the kinds of user requests that should route here, which is the exact decision the model is making.&lt;/p&gt;

&lt;p&gt;Notice what's missing. My first draft said "find entities by name using fuzzy matching." The model doesn't care that the matching is fuzzy; that's an implementation detail. It cares that it can type something approximate and get results. So I describe the behavior the model can act on, and how the matching works underneath never makes it into the text.&lt;/p&gt;

&lt;p&gt;One caution on those example questions: keep them varied. If they all look alike, the model decides the tool is narrower than it is and skips it when a question doesn't match the shape. I lean on examples mostly for parameters with non-obvious formats, and I keep the ones I do use deliberately different from each other.&lt;/p&gt;

&lt;h2&gt;
  
  
  Literal is the highest-value annotation you can add
&lt;/h2&gt;

&lt;p&gt;A parameter called &lt;code&gt;country&lt;/code&gt; could be a country name, a two-letter code, a three-letter code, or a UN numeric code. The model will guess, and it'll guess wrong often enough to matter.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;typing&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Annotated&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Literal&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pydantic&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Field&lt;/span&gt;

&lt;span class="n"&gt;Status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Literal&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;active&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;inactive&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;undetermined&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="nd"&gt;@tool&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;search_records&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="c1"&gt;# Inline description, fine for simple params
&lt;/span&gt;    &lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Annotated&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Search term. Use exact names, NO wildcards&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;

    &lt;span class="c1"&gt;# Literal pins the value to a known set
&lt;/span&gt;    &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Annotated&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Status&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Filter by status&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="c1"&gt;# Field adds examples and validation
&lt;/span&gt;    &lt;span class="n"&gt;country_code&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Annotated&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="nb"&gt;str&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nc"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Two-letter ISO 3166-1 alpha-2 country code&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;examples&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;DE&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;US&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;PL&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]),&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="c1"&gt;# ge=1 stops the model sending page 0 or a negative
&lt;/span&gt;    &lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Annotated&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Page number, 1-indexed&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ge&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="bp"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the model sees &lt;code&gt;Literal["active", "inactive", "undetermined"]&lt;/code&gt;, it knows the exact set of valid values. No guessing, no sending &lt;code&gt;"Active"&lt;/code&gt; with a capital A. For open-ended parameters you can't enumerate, the &lt;code&gt;examples&lt;/code&gt; field gives the model a sense of the format without pinning it down, and the &lt;code&gt;ge=1&lt;/code&gt; constraint on &lt;code&gt;page&lt;/code&gt; is a guardrail you get for free.&lt;/p&gt;

&lt;p&gt;The country code taught me where guidance actually belongs. The parameter said "two-letter code," and the model still passed "Germany" when the user said Germany. Tightening the parameter description didn't help. What helped was a line in the &lt;em&gt;tool&lt;/em&gt; description: "If the user gives a country name, convert it to the ISO alpha-2 code before calling." The parameter description sets the format, but the model only reads it once it's already decided to send a country, and by then the user's "Germany" is sitting in the slot. The instruction to convert had to live where the model looks earlier, in the tool description.&lt;/p&gt;

&lt;h2&gt;
  
  
  Empty does not mean zero
&lt;/h2&gt;

&lt;p&gt;A model queries something, gets back an empty list, and decides the tool failed. So it retries with different parameters, switches tools, or tells the user nothing's wrong when the real answer was "zero results matched." It took me a while to even see this one, because the tool was returning exactly what it should the whole time.&lt;/p&gt;

&lt;p&gt;The reinforcement has to land in more than one place:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In the tool description: "Returns an empty list when nothing matches. An empty result is a valid answer, not an error."&lt;/li&gt;
&lt;li&gt;In the system prompt or server instructions: "Empty results from these tools mean the query ran and found no matching data."&lt;/li&gt;
&lt;li&gt;In the response itself. Instead of &lt;code&gt;[]&lt;/code&gt;, return &lt;code&gt;{"results": [], "count": 0, "message": "No records matched"}&lt;/code&gt;. The structure carries enough context that the model reports the result instead of assuming the call broke.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After that, the "let me try another approach" false retries mostly stopped.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where guidance lives
&lt;/h2&gt;

&lt;p&gt;The model picks up tool behavior from four levels, and they do different jobs.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Level&lt;/th&gt;
&lt;th&gt;Scope&lt;/th&gt;
&lt;th&gt;What it's for&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Tool description&lt;/td&gt;
&lt;td&gt;one tool&lt;/td&gt;
&lt;td&gt;when to call it and what comes back; this is where routing happens&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Parameter description&lt;/td&gt;
&lt;td&gt;one field&lt;/td&gt;
&lt;td&gt;format, valid values, defaults&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;System prompt&lt;/td&gt;
&lt;td&gt;the conversation&lt;/td&gt;
&lt;td&gt;cross-tool behavior: date formats, empty-result semantics, rate-limit awareness&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Server instructions&lt;/td&gt;
&lt;td&gt;one MCP server&lt;/td&gt;
&lt;td&gt;the same behavioral guidance, delivered over the protocol&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The top two are specific to a single tool or field. The bottom two carry behavior that spans every tool from one source, and they get filled in last, if at all.&lt;/p&gt;

&lt;p&gt;The system prompt is where I put cross-tool rules. You can inject them as structured context:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;plugins&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;plugin&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"analytics"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    This plugin provides tools for querying the analytics warehouse.
    All dates in this system are UTC.
    Empty results mean the query found nothing, not that it failed.
    Report them as "no data found" rather than retrying with different parameters.
  &lt;span class="nt"&gt;&amp;lt;/plugin&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/plugins&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keep that block behavioral, not referential: date formats, empty-result semantics, rate-limit awareness. It's the right home for the kind of guidance that would bloat every individual tool description if you repeated it.&lt;/p&gt;

&lt;p&gt;MCP server instructions carry the same kind of guidance, but they ship as protocol metadata alongside the tool list rather than in your prompt. Clients surface them inconsistently and some ignore them entirely, so I treat the &lt;code&gt;instructions&lt;/code&gt; field (FastMCP puts it on the server) as a supplement to the system prompt, not a replacement.&lt;/p&gt;

&lt;p&gt;I've seen setups where everything gets crammed into the tool descriptions. That holds up until you have fifteen tools on one server and each description runs two hundred words.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fastest way to break tool selection
&lt;/h2&gt;

&lt;p&gt;Mention another tool by name. The moment a description says "for full history use &lt;code&gt;get_entity_details&lt;/code&gt;," you've created a dependency on that name. Filter the tool out or rename it and the model still tries to call it. I've watched models hallucinate calls to tools they only saw referenced in another tool's description. Even the soft version, "call the tool that returns full history," is fragile. So each description only talks about its own tool now; the moment one starts referencing another, I treat it as a bug.&lt;/p&gt;

&lt;p&gt;Two smaller ones. Vague parameter names like &lt;code&gt;q&lt;/code&gt; or &lt;code&gt;data&lt;/code&gt; give the model nothing to reason from; the name itself is a signal, so &lt;code&gt;search_query&lt;/code&gt; and &lt;code&gt;date_range_start&lt;/code&gt; earn their length. And implementation details ("calls &lt;code&gt;/api/v2/entities&lt;/code&gt; with pagination") are for whoever's reading the source, not the model deciding whether to call.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sometimes the fix is one fewer tool
&lt;/h2&gt;

&lt;p&gt;I had a tool that exposed a big reference dataset, millions of rows of geographic data. It worked. But its description was broad enough to match all sorts of questions it wasn't meant for, so the model kept reaching for it. Removing it, and routing those questions through a narrower tool, raised accuracy across the whole neighborhood of related queries.&lt;/p&gt;

&lt;p&gt;That lines up with what Anthropic's &lt;a href="https://platform.claude.com/docs/en/agents-and-tools/tool-use/define-tools" rel="noopener noreferrer"&gt;tool use docs&lt;/a&gt; recommend: detailed descriptions, and fewer capable tools over many overlapping ones. Their &lt;a href="https://platform.claude.com/docs/en/agents-and-tools/tool-use/tool-search-tool" rel="noopener noreferrer"&gt;tool search&lt;/a&gt; takes it further, deferring a tool's full schema until the model actually selects it, which is how Claude Code holds selection accuracy across a large tool count. I can't always defer like that, so the lever I'm left with is blunt: if a tool causes more confusion than it earns, it comes out.&lt;/p&gt;

&lt;p&gt;The descriptions that work don't read like docstrings. They read like a handoff note to whoever's covering your shift: when you'd actually reach for this, and the input that always trips people up. How long that note can run before the model starts skimming it, I don't know. Somewhere past a couple hundred words, but I've never actually measured where.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://blog.wentland.io/blog/designing-tools-for-ai/" rel="noopener noreferrer"&gt;blog.wentland.io&lt;/a&gt;. Related: &lt;a href="https://blog.wentland.io/blog/why-read-only-mcp/" rel="noopener noreferrer"&gt;Why I only build read-only MCP servers&lt;/a&gt; and &lt;a href="https://blog.wentland.io/blog/mcp-servers-are-not-api-adapters/" rel="noopener noreferrer"&gt;Your MCP server is not an API adapter&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>mcp</category>
      <category>ai</category>
      <category>programming</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Ship Python code without leaving source on disk. Encrypted bundles arrive at runtime, load from memory. Works with numpy, pydantic, boto3.</title>
      <dc:creator>Wojciech Wentland</dc:creator>
      <pubDate>Tue, 19 May 2026 10:22:18 +0000</pubDate>
      <link>https://dev.to/desty2k/ship-python-code-without-leaving-source-on-disk-encrypted-bundles-arrive-at-runtime-load-from-12ke</link>
      <guid>https://dev.to/desty2k/ship-python-code-without-leaving-source-on-disk-encrypted-bundles-arrive-at-runtime-load-from-12ke</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/desty2k/paker-load-encrypted-python-packages-from-memory-eaj" class="crayons-story__hidden-navigation-link"&gt;paker: load encrypted Python packages from memory&lt;/a&gt;


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

          &lt;a href="/desty2k" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3866520%2F3ad33efb-4ece-434a-97e5-e9cecc7cc9fd.png" alt="desty2k profile" class="crayons-avatar__image" width="420" height="420"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/desty2k" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Wojciech Wentland
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Wojciech Wentland
                
              
              &lt;div id="story-author-preview-content-3617232" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/desty2k" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3866520%2F3ad33efb-4ece-434a-97e5-e9cecc7cc9fd.png" class="crayons-avatar__image" alt="" width="420" height="420"&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Wojciech Wentland&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/desty2k/paker-load-encrypted-python-packages-from-memory-eaj" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;May 6&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/desty2k/paker-load-encrypted-python-packages-from-memory-eaj" id="article-link-3617232"&gt;
          paker: load encrypted Python packages from memory
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/python"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;python&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/security"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;security&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/opensource"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;opensource&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/programming"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;programming&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
            &lt;a href="https://dev.to/desty2k/paker-load-encrypted-python-packages-from-memory-eaj#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

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

              &lt;/span&gt;
              &lt;span class="bm-success"&gt;
                

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

&lt;/div&gt;


</description>
      <category>python</category>
      <category>security</category>
      <category>showdev</category>
      <category>tooling</category>
    </item>
    <item>
      <title>[Boost]</title>
      <dc:creator>Wojciech Wentland</dc:creator>
      <pubDate>Tue, 12 May 2026 13:12:35 +0000</pubDate>
      <link>https://dev.to/desty2k/-173c</link>
      <guid>https://dev.to/desty2k/-173c</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/desty2k/loading-code-without-the-disk-what-each-os-lets-you-get-away-with-1d5g" class="crayons-story__hidden-navigation-link"&gt;Loading code without the disk: what each OS lets you get away with&lt;/a&gt;


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

          &lt;a href="/desty2k" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3866520%2F3ad33efb-4ece-434a-97e5-e9cecc7cc9fd.png" alt="desty2k profile" class="crayons-avatar__image" width="420" height="420"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/desty2k" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Wojciech Wentland
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Wojciech Wentland
                
              
              &lt;div id="story-author-preview-content-3649574" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/desty2k" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3866520%2F3ad33efb-4ece-434a-97e5-e9cecc7cc9fd.png" class="crayons-avatar__image" alt="" width="420" height="420"&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Wojciech Wentland&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/desty2k/loading-code-without-the-disk-what-each-os-lets-you-get-away-with-1d5g" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;May 12&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/desty2k/loading-code-without-the-disk-what-each-os-lets-you-get-away-with-1d5g" id="article-link-3649574"&gt;
          Loading code without the disk: what each OS lets you get away with
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/python"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;python&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/linux"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;linux&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/security"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;security&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/opensource"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;opensource&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
            &lt;a href="https://dev.to/desty2k/loading-code-without-the-disk-what-each-os-lets-you-get-away-with-1d5g#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

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

              &lt;/span&gt;
              &lt;span class="bm-success"&gt;
                

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

&lt;/div&gt;


</description>
    </item>
    <item>
      <title>Loading code without the disk: what each OS lets you get away with</title>
      <dc:creator>Wojciech Wentland</dc:creator>
      <pubDate>Tue, 12 May 2026 07:00:00 +0000</pubDate>
      <link>https://dev.to/desty2k/loading-code-without-the-disk-what-each-os-lets-you-get-away-with-1d5g</link>
      <guid>https://dev.to/desty2k/loading-code-without-the-disk-what-each-os-lets-you-get-away-with-1d5g</guid>
      <description>&lt;p&gt;memfd, PE loaders, unlink-after-dlopen. Three operating systems, three different definitions of 'in memory'.&lt;/p&gt;




&lt;p&gt;"Load the module from memory" sounds like one thing. It is not one thing. Each operating system gives you different primitives, hides different walls, and has a different definition of what counts as "never touched disk." I've been working on &lt;a href="https://github.com/desty2k/paker" rel="noopener noreferrer"&gt;paker&lt;/a&gt;, a Python library that ships encrypted packages over the network and imports them without writing bytes to the filesystem, and the platform-by-platform reality turned out to be messier than the pitch. &lt;a href="https://blog.wentland.io/blog/paker-encrypted-in-memory-python-loader/" rel="noopener noreferrer"&gt;Post one in this series&lt;/a&gt; covered what paker is and what it's for; this one is about the plumbing underneath.&lt;/p&gt;

&lt;p&gt;The patterns below apply whether you're building a plugin system, shipping a proprietary SDK, or doing anything where the word "executable" appears without a corresponding path on disk. paker is the concrete example I'll point at, but the primitives are the OS's, not mine.&lt;/p&gt;

&lt;h2&gt;
  
  
  Linux: &lt;code&gt;memfd_create&lt;/code&gt; is the clean case
&lt;/h2&gt;

&lt;p&gt;Linux gives you the primitive you want. &lt;a href="https://man7.org/linux/man-pages/man2/memfd_create.2.html" rel="noopener noreferrer"&gt;&lt;code&gt;memfd_create(2)&lt;/code&gt;&lt;/a&gt; was added in kernel 3.17 and creates an anonymous file descriptor backed entirely by RAM. You write bytes to the fd, then &lt;code&gt;dlopen("/proc/self/fd/N")&lt;/code&gt;, and the loader maps the code into executable memory. The kernel never creates a filesystem entry.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ctypes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;importlib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;util&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;importlib.machinery&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ExtensionFileLoader&lt;/span&gt;

&lt;span class="n"&gt;libc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ctypes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CDLL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;use_errno&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;fd&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;libc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;memfd_create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;b&lt;/span&gt;&lt;span class="sh"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mh"&gt;0x0001&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# MFD_CLOEXEC
&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fd&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;so_bytes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;loader&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ExtensionFileLoader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;module_name&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/proc/self/fd/&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;fd&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;spec&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;importlib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;util&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;spec_from_loader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;module_name&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;loader&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;mod&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;importlib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;util&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;module_from_spec&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;spec&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;spec&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;loader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exec_module&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mod&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Outside the process, &lt;code&gt;ls -l /proc/&amp;lt;pid&amp;gt;/fd/&lt;/code&gt; shows &lt;code&gt;memfd:&lt;/code&gt; as the link target. Another process can reach the bytes through &lt;code&gt;/proc/&amp;lt;pid&amp;gt;/fd/&amp;lt;fd&amp;gt;&lt;/code&gt; (the memfd man page documents exactly this pattern for shared mappings), but it has to pass normal &lt;code&gt;/proc&lt;/code&gt; access checks: matching UID, no container isolation, &lt;code&gt;ptrace_scope&lt;/code&gt; friendly. There's no stable filesystem path, only a procfs entry whose accessibility depends on process-access rules.&lt;/p&gt;

&lt;p&gt;If you pass an empty tag instead of the module name, the anonymous mapping doesn't publish what it is.&lt;/p&gt;

&lt;p&gt;So far so clean. Then the real gotcha.&lt;/p&gt;

&lt;h3&gt;
  
  
  glibc can treat a reused &lt;code&gt;/proc/self/fd/N&lt;/code&gt; path as the same library
&lt;/h3&gt;

&lt;p&gt;glibc's dynamic linker reference-counts loaded objects and returns the same handle when the same library is opened again, as &lt;a href="https://man7.org/linux/man-pages/man3/dlopen.3.html" rel="noopener noreferrer"&gt;&lt;code&gt;dlopen(3)&lt;/code&gt;&lt;/a&gt; describes. Fine for normal libraries whose on-disk paths are stable. With memfd, the "path" looks like &lt;code&gt;/proc/self/fd/3&lt;/code&gt;, and &lt;code&gt;3&lt;/code&gt; is just whatever file descriptor number the kernel handed you. Close that fd after loading, the next &lt;code&gt;memfd_create&lt;/code&gt; will get fd 3 back, and in my glibc tests &lt;code&gt;dlopen("/proc/self/fd/3")&lt;/code&gt; returned the cached handle for the &lt;em&gt;previous&lt;/em&gt; library.&lt;/p&gt;

&lt;p&gt;I verified this empirically in Docker on glibc: close fd 3, open a new memfd for a different module, dlopen returns the wrong shared object. No error, no warning. The code just calls into the wrong library.&lt;/p&gt;

&lt;p&gt;So the fix is to keep the memfd fd open for the lifetime of the process. The &lt;code&gt;mmap&lt;/code&gt;'d pages survive an fd close on their own as long as the mapping exists, so the lifetime question isn't about keeping the code mapped. It's that closing the fd lets the kernel reuse the same fd number for a different memfd. Once &lt;code&gt;/proc/self/fd/3&lt;/code&gt; can mean a different shared object later, glibc's loaded-object cache can hand you the wrong handle. Cleaning up the fd is how you reintroduce a collision bug that will fire on the first process loading more than a handful of extensions.&lt;/p&gt;

&lt;p&gt;Every primitive has a papercut. This one was mine.&lt;/p&gt;

&lt;h2&gt;
  
  
  macOS: "zero disk" is a lie on Apple Silicon
&lt;/h2&gt;

&lt;p&gt;Apple Silicon and mandatory code signing killed in-memory loading as a general technique. There is no macOS equivalent of &lt;code&gt;memfd_create&lt;/code&gt;. The closest public API is &lt;code&gt;NSCreateObjectFileImageFromMemory&lt;/code&gt;, and &lt;a href="https://rtx.meta.security/post-exploitation/2022/12/19/In-Memory-Execution-in-macOS.html" rel="noopener noreferrer"&gt;Meta's Red Team X documented the behavior change&lt;/a&gt;: starting with dyld3, &lt;code&gt;NSLinkModule&lt;/code&gt; stopped doing in-memory loading and instead writes a temporary file with a &lt;code&gt;NSCreateObjectFileImageFromMemory-XXXXXXXX&lt;/code&gt; fingerprint in &lt;code&gt;$TMPDIR&lt;/code&gt;. The API still exists. It just doesn't do what the name says, and the temp artifact has a predictable fingerprint that monitoring tools can see.&lt;/p&gt;

&lt;p&gt;The practical ceiling on modern macOS is "milliseconds on disk." You &lt;code&gt;mkstemp&lt;/code&gt; a file with a random name, write the bytes, &lt;code&gt;dlopen&lt;/code&gt; it, and &lt;code&gt;os.unlink&lt;/code&gt; immediately. The directory entry disappears but the kernel keeps the &lt;code&gt;mmap&lt;/code&gt;'d pages alive for the loaded module.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tempfile&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ctypes&lt;/span&gt;

&lt;span class="n"&gt;fd&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tempfile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mkstemp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prefix&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;suffix&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fd&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;so_bytes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fd&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Depending on how the host binary is signed, you may need to disable
# library validation or otherwise satisfy macOS code-signing rules.
&lt;/span&gt;&lt;span class="n"&gt;handle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ctypes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CDLL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;ctypes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;RTLD_NOW&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;unlink&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# directory entry gone, mmap pages still valid
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Signing is its own rabbit hole. &lt;a href="https://developer.apple.com/forums/thread/736350" rel="noopener noreferrer"&gt;Apple's forums&lt;/a&gt; distinguish between library validation (who signed the dylib), unsigned executable memory (JIT-style entitlements), and the deprecated reflective-loading APIs. Different problems, different entitlements. Which one you need depends on your host binary's signature and whether the bundle you're loading is ad-hoc signed, team-signed, or unsigned.&lt;/p&gt;

&lt;p&gt;If your threat model assumes an attacker with root and a filesystem watcher, the milliseconds-on-disk window is still a window. If your threat model is "no plaintext bytes should survive this process," macOS lets you get close but never all the way there.&lt;/p&gt;

&lt;h2&gt;
  
  
  Windows: a full PE loader, until Static TLS stops you
&lt;/h2&gt;

&lt;p&gt;Windows is surprisingly good if you're willing to bring your own loader. The &lt;code&gt;_memimporter&lt;/code&gt; code from py2exe (itself derived from Joachim Bauch's MemoryModule, MPL-2.0) implements a PE loader in C: &lt;code&gt;VirtualAlloc&lt;/code&gt; a region, copy the section headers, walk the relocation table, resolve the import address table by calling &lt;code&gt;GetProcAddress&lt;/code&gt; against &lt;code&gt;LoadLibrary&lt;/code&gt;'d dependencies, mark pages executable, call &lt;code&gt;PyInit_&amp;lt;modname&amp;gt;&lt;/code&gt;. No filesystem syscalls anywhere in the path.&lt;/p&gt;

&lt;p&gt;It works. I've shipped numpy, Pillow, and a dozen other packages through it on both x64 and ARM64. The ARM64 work surfaced two real bugs that had been dormant because nobody had tried:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;HOST_MACHINE&lt;/code&gt; was hardcoded to &lt;code&gt;IMAGE_FILE_MACHINE_AMD64&lt;/code&gt;. On ARM64 the PE header says &lt;code&gt;0xAA64&lt;/code&gt;, and the check was rejecting every valid library.&lt;/li&gt;
&lt;li&gt;After relocations and section copies, ARM64 needs an explicit &lt;code&gt;FlushInstructionCache&lt;/code&gt; before executing the new pages. x64 gets away without it because of cache coherency; ARM64 has split I-cache and D-cache and will happily execute the old bytes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Fixing both of those was a Saturday. Static TLS is not a Saturday.&lt;/p&gt;

&lt;h3&gt;
  
  
  Static TLS is where my in-memory Windows path stops
&lt;/h3&gt;

&lt;p&gt;Any extension that uses static TLS (&lt;code&gt;__declspec(thread)&lt;/code&gt; or &lt;code&gt;thread_local&lt;/code&gt; with static initialization) cannot be loaded safely and generally by a normal user-mode PE loader. I hit this first with Rust-based Python extensions, but the reliable test isn't the language. It's the PE header: if &lt;code&gt;IMAGE_DIRECTORY_ENTRY_TLS&lt;/code&gt; is present and non-empty, the module needs the Windows loader's TLS machinery.&lt;/p&gt;

&lt;p&gt;The reason is where the TLS data lives. &lt;code&gt;TlsAlloc&lt;/code&gt; gives you dynamic indices and writes to &lt;code&gt;TEB-&amp;gt;TlsSlots&lt;/code&gt;. That one's fine. But the compiler doesn't emit &lt;code&gt;TlsAlloc&lt;/code&gt; code for static TLS. It emits direct indexing into &lt;code&gt;TEB-&amp;gt;ThreadLocalStoragePointer&lt;/code&gt;, which is a separate array. That array is managed by &lt;code&gt;LdrpHandleTlsData&lt;/code&gt; in &lt;code&gt;ntdll&lt;/code&gt;, an undocumented internal function responsible for resizing the array when a new DLL with TLS is loaded. When &lt;code&gt;LdrpHandleTlsData&lt;/code&gt; never runs, your extension's thread-local indexes point into memory that was never allocated for it.&lt;/p&gt;

&lt;p&gt;Projects that have tried to work around this all make trade-offs I wasn't willing to ship:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Blackbone&lt;/strong&gt; reimplements &lt;code&gt;LdrpHandleTlsData&lt;/code&gt; via pattern-scanning &lt;code&gt;ntdll&lt;/code&gt;. It maintains thirteen-plus byte patterns across Windows versions; every Windows update is a potential break.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/Fatmike-GH/PELoader" rel="noopener noreferrer"&gt;&lt;strong&gt;Fatmike's PELoader&lt;/strong&gt;&lt;/a&gt; does handle static TLS for a single loaded module. The author is explicit that simply iterating TLS callbacks isn't enough for Rust and that custom per-thread TLS-data initialization is required, with a &lt;code&gt;TlsCallbackProxy&lt;/code&gt; shim to forward thread events. The project describes itself as experimental on this surface and loads one target at a time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Manual slot management with &lt;code&gt;TlsAlloc&lt;/code&gt;&lt;/strong&gt; addresses the wrong array entirely. The one your compiler never touches.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is why Python freezing tools often keep a real file path in the loop for native extensions. py2exe made that trade-off explicit for Python 3.12+, where &lt;a href="https://github.com/py2exe/py2exe/issues/215" rel="noopener noreferrer"&gt;&lt;code&gt;bundle_files &amp;lt; 3&lt;/code&gt; is no longer supported&lt;/a&gt;. The maintainer closed the issue with "I did not see a viable implementation." At some point delegating to the OS loader is the boring solution that works.&lt;/p&gt;

&lt;p&gt;Accepting that took longer than fixing it. The TEB structure has been stable for decades. There is no user-mode path around it that's both general and stable, and a library that quietly breaks on the next Windows update is worse than a tempfile.&lt;/p&gt;

&lt;p&gt;So for static TLS, paker detects it, writes the extension to a tempfile, and lets &lt;code&gt;LoadLibrary&lt;/code&gt; do its job. For the majority of extensions without static TLS, the PE loader runs and nothing touches disk.&lt;/p&gt;

&lt;h2&gt;
  
  
  What you actually get, by platform
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Linux&lt;/th&gt;
&lt;th&gt;macOS (arm64)&lt;/th&gt;
&lt;th&gt;Windows (no TLS)&lt;/th&gt;
&lt;th&gt;Windows (static TLS)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Bytes on disk&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;td&gt;Milliseconds&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;td&gt;Lifetime of load&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Visible filesystem path&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Briefly&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Plaintext artifact after crash&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;td&gt;Possible before unlink&lt;/td&gt;
&lt;td&gt;None&lt;/td&gt;
&lt;td&gt;Temp file may remain&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Extra constraints&lt;/td&gt;
&lt;td&gt;Keep fd open&lt;/td&gt;
&lt;td&gt;Signing / entitlements&lt;/td&gt;
&lt;td&gt;PE loader quirks&lt;/td&gt;
&lt;td&gt;None, it's a file&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;"Loaded from memory" is not a binary property. Linux gives you a real zero-disk path with one behavioral gotcha. macOS gives you a brief window, not a guarantee, and the gap isn't closing. Windows gives you zero-disk for most of your bindings and a hard wall for the rest.&lt;/p&gt;

&lt;p&gt;If you're choosing techniques, the question I'd ask isn't "can I load without touching disk" but "what's the worst-case footprint when the happy path doesn't apply." The packages that break the pattern are usually the ones you most want to ship.&lt;/p&gt;

&lt;p&gt;paker hides most of this. &lt;code&gt;pip install paker&lt;/code&gt;, &lt;code&gt;paker.dumps(...)&lt;/code&gt; on one end, &lt;code&gt;paker.loads(...)&lt;/code&gt; on the other, and you get the correct primitive per platform with the gotchas already handled: memfd fds held open on Linux, ephemeral tempfile on macOS, PE loader on Windows with a static-TLS fallback. Source, docs, and a remote-agent example live at &lt;a href="https://github.com/desty2k/paker" rel="noopener noreferrer"&gt;github.com/desty2k/paker&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;span&gt;&lt;br&gt;
Footnote on memory hygiene: if you're decrypting bytes before loading, the buffer lifetime matters too. &lt;code&gt;mmap&lt;/code&gt; + &lt;code&gt;mlock&lt;/code&gt; keeps the plaintext out of swap, &lt;code&gt;MADV_DONTDUMP&lt;/code&gt; keeps it out of core dumps, and zeroing via a volatile pointer loop after use prevents the compiler from eliminating the scrub. None of this is OS-specific and all of it is secondary to the loading primitive itself.&lt;br&gt;
&lt;/span&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>linux</category>
      <category>security</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Ship Python code without leaving source on disk. Encrypted bundles arrive at runtime, load from memory. Works with numpy, pydantic, boto3.</title>
      <dc:creator>Wojciech Wentland</dc:creator>
      <pubDate>Wed, 06 May 2026 08:12:28 +0000</pubDate>
      <link>https://dev.to/desty2k/ship-python-code-without-leaving-source-on-disk-encrypted-bundles-arrive-at-runtime-load-from-3gjm</link>
      <guid>https://dev.to/desty2k/ship-python-code-without-leaving-source-on-disk-encrypted-bundles-arrive-at-runtime-load-from-3gjm</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/desty2k/paker-load-encrypted-python-packages-from-memory-eaj" class="crayons-story__hidden-navigation-link"&gt;paker: load encrypted Python packages from memory&lt;/a&gt;


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

          &lt;a href="/desty2k" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3866520%2F3ad33efb-4ece-434a-97e5-e9cecc7cc9fd.png" alt="desty2k profile" class="crayons-avatar__image" width="420" height="420"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/desty2k" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Wojciech Wentland
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Wojciech Wentland
                
              
              &lt;div id="story-author-preview-content-3617232" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/desty2k" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3866520%2F3ad33efb-4ece-434a-97e5-e9cecc7cc9fd.png" class="crayons-avatar__image" alt="" width="420" height="420"&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Wojciech Wentland&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/desty2k/paker-load-encrypted-python-packages-from-memory-eaj" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;May 6&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/desty2k/paker-load-encrypted-python-packages-from-memory-eaj" id="article-link-3617232"&gt;
          paker: load encrypted Python packages from memory
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/python"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;python&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/security"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;security&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/opensource"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;opensource&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/programming"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;programming&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
            &lt;a href="https://dev.to/desty2k/paker-load-encrypted-python-packages-from-memory-eaj#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

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

              &lt;/span&gt;
              &lt;span class="bm-success"&gt;
                

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

&lt;/div&gt;


</description>
      <category>python</category>
      <category>security</category>
      <category>showdev</category>
      <category>tooling</category>
    </item>
    <item>
      <title>paker: load encrypted Python packages from memory</title>
      <dc:creator>Wojciech Wentland</dc:creator>
      <pubDate>Wed, 06 May 2026 06:15:00 +0000</pubDate>
      <link>https://dev.to/desty2k/paker-load-encrypted-python-packages-from-memory-eaj</link>
      <guid>https://dev.to/desty2k/paker-load-encrypted-python-packages-from-memory-eaj</guid>
      <description>&lt;p&gt;Ship Python code without leaving source on disk. Encrypted bundles arrive at runtime, load from memory. Works with numpy, pydantic, boto3.&lt;/p&gt;




&lt;p&gt;PyInstaller bundles Python code into a standalone binary. Run &lt;code&gt;pyinstxtractor&lt;/code&gt; on that binary and you get every &lt;code&gt;.pyc&lt;/code&gt; back in about ten seconds. &lt;code&gt;uncompyle6&lt;/code&gt; turns those into readable source. The "compiled" binary is a zip file with extra steps.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/desty2k/paker" rel="noopener noreferrer"&gt;paker&lt;/a&gt; takes a different approach. The binary ships without the proprietary code. At runtime, encrypted modules arrive from the network and load directly into memory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;paker&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;

&lt;span class="c1"&gt;# Key arrives from your license server. paker doesn't manage keys.
&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;https://license.example.com/key&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;license&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;LICENSE_ID&lt;/span&gt;&lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;

&lt;span class="c1"&gt;# loads() accepts dict, str, bytes, or bytearray.
&lt;/span&gt;&lt;span class="n"&gt;bundle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;https://cdn.example.com/sdk.paker&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;paker&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bundle&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;proprietary_sdk&lt;/span&gt;
    &lt;span class="n"&gt;proprietary_sdk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No pip install on the client. Python modules get compiled from memory. Native extensions load through platform-specific loaders. numpy, pydantic, boto3, Pillow, anthropic, and a dozen more packages all work, including ones with compiled C code.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it loads
&lt;/h2&gt;

&lt;p&gt;paker implements zero-disk loading natively on Windows and Linux. macOS requires an ephemeral temp file (written, loaded, immediately deleted) because of mandatory code signing, and the host binary needs the &lt;code&gt;disable-library-validation&lt;/code&gt; entitlement. I'll go into the platform-specific details in a separate post.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it doesn't protect against
&lt;/h2&gt;

&lt;p&gt;Once loaded, modules live in &lt;code&gt;sys.modules&lt;/code&gt; as normal Python objects. Someone with access to the running process can inspect bytecode through &lt;code&gt;marshal.dumps(func.__code__)&lt;/code&gt; or walk the heap with &lt;code&gt;gc.get_objects()&lt;/code&gt;. Compiled code objects stay resident in the process. &lt;code&gt;mlock&lt;/code&gt; and &lt;code&gt;MADV_DONTDUMP&lt;/code&gt; keep them out of core dumps, not out of the address space.&lt;/p&gt;

&lt;p&gt;A determined attacker with the key and a debugger gets through. This is defense in depth against casual reverse engineering. If someone with a valid license wants to spend a week extracting bytecode, the real protection is legal, not technical.&lt;/p&gt;

&lt;p&gt;What paker does protect: the bundle at rest. Without the key, the encrypted payloads are AES-256-CTR + HMAC-SHA256 ciphertext. The key and the bundle always travel separately, through whatever key management you already have (license server, HSM, environment variable). paker handles encryption and loading. Key distribution is your problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  Transform hooks
&lt;/h2&gt;

&lt;p&gt;paker ships hooks instead of a built-in obfuscator. Pass any callable as &lt;code&gt;ast_transform&lt;/code&gt; or &lt;code&gt;code_transform&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ast&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;paker&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;strip_docstrings&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tree&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ast&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AST&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;module_name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;ast&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AST&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;ast&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;walk&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tree&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nf"&gt;isinstance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ast&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;FunctionDef&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ast&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AsyncFunctionDef&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                             &lt;span class="n"&gt;ast&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ClassDef&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ast&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Module&lt;/span&gt;&lt;span class="p"&gt;)):&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;ast&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_docstring&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
                &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;tree&lt;/span&gt;

&lt;span class="n"&gt;bundle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;paker&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;myapp&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ast_transform&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;strip_docstrings&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There's also a &lt;code&gt;code_transform&lt;/code&gt; hook for bytecode-level passes. I spent days building a built-in obfuscator before I understood my own threat model well enough to realize I didn't need one. Separate post coming on that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;paker
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Source, docs, examples (including a remote agent that ships the anthropic SDK over TCP to a zero-install client): &lt;a href="https://github.com/desty2k/paker" rel="noopener noreferrer"&gt;github.com/desty2k/paker&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>python</category>
      <category>security</category>
      <category>opensource</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
