<?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: Jonas Francisco de Lima Filho</title>
    <description>The latest articles on DEV Community by Jonas Francisco de Lima Filho (@jonasfilhodev).</description>
    <link>https://dev.to/jonasfilhodev</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%2F3690426%2F503f4a52-f500-49ef-8a59-bab9bed07638.jpg</url>
      <title>DEV Community: Jonas Francisco de Lima Filho</title>
      <link>https://dev.to/jonasfilhodev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jonasfilhodev"/>
    <language>en</language>
    <item>
      <title>My Node binary lived in my home directory. The process that needed it never read .bashrc.</title>
      <dc:creator>Jonas Francisco de Lima Filho</dc:creator>
      <pubDate>Fri, 27 Nov 2026 20:41:23 +0000</pubDate>
      <link>https://dev.to/jonasfilhodev/my-node-binary-lived-in-my-home-directory-the-process-that-needed-it-never-read-bashrc-1fdf</link>
      <guid>https://dev.to/jonasfilhodev/my-node-binary-lived-in-my-home-directory-the-process-that-needed-it-never-read-bashrc-1fdf</guid>
      <description>&lt;p&gt;I run a small operation on one ARM VPS: a static dashboard served by nginx, a few scheduled jobs, a publishing CLI, and an agent process that calls all of it. Node was installed early, because two of those tools are written in JavaScript.&lt;/p&gt;

&lt;p&gt;This week I needed to answer a simple question about that machine: from inside a process that does not start a login shell, can it find &lt;code&gt;node&lt;/code&gt;? My terminal said yes. It had been saying yes for months. The answer from the other side was different, and the gap between the two answers is the subject of this post.&lt;/p&gt;

&lt;h2&gt;
  
  
  A PATH belongs to a process, not to the machine
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;PATH&lt;/code&gt; is inherited. A process gets its environment from whoever spawned it, and only a login or interactive shell reads &lt;code&gt;.profile&lt;/code&gt; and &lt;code&gt;.bashrc&lt;/code&gt; to build that value. A systemd unit, a crontab line, an &lt;code&gt;ssh host command&lt;/code&gt;, and any daemon that shells out with a minimal environment get whatever their parent had, which is usually a short list like &lt;code&gt;/usr/bin:/bin&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I reproduced it rather than waiting for a job to fail:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ env -i &lt;span class="nv"&gt;PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/usr/bin:/bin node -v
env: &lt;span class="s1"&gt;'node'&lt;/span&gt;: No such file or directory
$ &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$?&lt;/span&gt;
127
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same machine, same user, same disk. The difference is that &lt;code&gt;env -i&lt;/code&gt; throws away my environment and keeps only the base directories. My terminal was not special. It just carried a longer list, assembled by files that this process never reads.&lt;/p&gt;

&lt;h2&gt;
  
  
  The binary was under my home directory
&lt;/h2&gt;

&lt;p&gt;I did not install Node from a distribution package. I extracted the release tarball under &lt;code&gt;~/.hermes/tools&lt;/code&gt;, next to the other toolchains I keep there, so an upgrade is a directory swap:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ ls -d ~/.hermes/tools/node-*
/home/ubuntu/.hermes/tools/node-26.12.1-linux-arm64
/home/ubuntu/.hermes/tools/node-26.7.0-linux-arm64
$ ~/.hermes/tools/node-26.12.1-linux-arm64/bin/node -v
v26.12.1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That path only exists for a process whose &lt;code&gt;PATH&lt;/code&gt; includes it, and nothing outside my shell adds it. Which means the binary was installed, executable and correct, and simultaneously invisible to half the machine. Both statements were true at once, and only one of them showed up in my terminal.&lt;/p&gt;

&lt;p&gt;One detail that mattered when I first set this up: the box is ARM. &lt;code&gt;uname -m&lt;/code&gt; answers &lt;code&gt;aarch64&lt;/code&gt;, so the build to download is the &lt;code&gt;linux-arm64&lt;/code&gt; one. The default download link for Linux is x64, and the kernel rejects that binary at exec time with &lt;code&gt;Exec format error&lt;/code&gt;, which looks like a corrupt download until you check the architecture.&lt;/p&gt;

&lt;h2&gt;
  
  
  Putting the binary where the system already looks
&lt;/h2&gt;

&lt;p&gt;The fix I applied was to create symlinks in &lt;code&gt;/usr/local/bin&lt;/code&gt;, a directory that is on the base &lt;code&gt;PATH&lt;/code&gt; of every process on this box, including the short one above:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ sudo ln -s /home/ubuntu/.hermes/tools/node-26.12.1-linux-arm64/bin/node /usr/local/bin/node
$ sudo ln -s /home/ubuntu/.hermes/tools/node-26.12.1-linux-arm64/bin/npm  /usr/local/bin/npm
$ sudo ln -s /home/ubuntu/.hermes/tools/node-26.12.1-linux-arm64/bin/npx  /usr/local/bin/npx

$ ls -l /usr/local/bin/node
lrwxrwxrwx 1 root root 60 Oct 22 01:04 /usr/local/bin/node -&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /home/ubuntu/.hermes/tools/node-26.12.1-linux-arm64/bin/node

$ env -i &lt;span class="nv"&gt;PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/usr/bin:/bin node -v
v26.12.1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same command that failed a moment earlier now answers, because the name resolves from a directory every process already searches. No environment file to source, no absolute path to remember in each script.&lt;/p&gt;

&lt;p&gt;There was a second reason for the symlink: the failing caller was not a script I control. It was a desktop relay and a couple of helpers that open a non-login SSH session. Fixing the environment of each one would have been four changes in four places, and the fifth caller would still have been broken.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the symlink costs
&lt;/h2&gt;

&lt;p&gt;The link points into a versioned directory, so an upgrade means recreating it. If I extract &lt;code&gt;node-26.13.x&lt;/code&gt; and delete &lt;code&gt;26.12.1&lt;/code&gt;, &lt;code&gt;/usr/local/bin/node&lt;/code&gt; becomes a dangling link, and every process that depended on it fails at once while my interactive shell keeps working, because my &lt;code&gt;PATH&lt;/code&gt; also lists the tools directory directly.&lt;/p&gt;

&lt;p&gt;That split is the part worth designing around. &lt;code&gt;type -a node&lt;/code&gt; in my shell prints two entries for one program, one from the symlink and one from the directory entry:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ &lt;span class="nb"&gt;type&lt;/span&gt; -a node
node is /usr/local/bin/node
node is /home/ubuntu/.hermes/tools/node-26.12.1-linux-arm64/bin/node
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two resolutions, one of them a symlink to the other. Remove the symlink and my shell still finds a &lt;code&gt;node&lt;/code&gt;; remove the directory and the whole box loses it. The older &lt;code&gt;26.7.0&lt;/code&gt; tree is still sitting on disk at 148 MB, which is the other half of this: versioned directories accumulate until someone removes them, and the only thing that makes the removal safe is knowing which names resolve to them.&lt;/p&gt;

&lt;p&gt;The check that makes upgrades boring is one line before the upgrade and one after:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;readlink -f &lt;span class="s2"&gt;"$(command -v node)"&lt;/span&gt;   &lt;span class="c"&gt;# prints the real path, not the link&lt;/span&gt;
node -v
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the resolved path is not the version I just installed, the upgrade did not take effect for the processes that matter.&lt;/p&gt;

&lt;h2&gt;
  
  
  The same problem, one directory over
&lt;/h2&gt;

&lt;p&gt;While measuring this I found the second half of it. My integration CLI is a symlink in &lt;code&gt;~/.local/bin&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ ls -l ~/.local/bin/composio
lrwxrwxrwx 1 ubuntu ubuntu 31 Sep 29 23:23 /home/ubuntu/.local/bin/composio -&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /home/ubuntu/.composio/composio
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That directory is not on the system manager's default path. Asking the user-level systemd manager for its environment shows the full picture:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ systemctl --user show-environment &lt;span class="o"&gt;|&lt;/span&gt; grep PATH
&lt;span class="nv"&gt;PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;~/.local/bin&lt;/code&gt; is absent. Any unit started by that manager, without an explicit &lt;code&gt;Environment=PATH&lt;/code&gt;, inherits this list. A unit whose &lt;code&gt;ExecStart&lt;/code&gt; calls &lt;code&gt;composio&lt;/code&gt; by name starts with 203/EXEC and tells you nothing about why. My interactive shell has the directory and never notices.&lt;/p&gt;

&lt;p&gt;Two fixes work. Either call the absolute path in the unit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="k"&gt;[Service]&lt;/span&gt;
&lt;span class="na"&gt;ExecStart&lt;/span&gt;&lt;span class="o"&gt;=/&lt;/span&gt;&lt;span class="n"&gt;home&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;ubuntu&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;local&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;bin&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;composio&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;home&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;ubuntu&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;job&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;js&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or set the environment explicitly, which documents the dependency inside the unit instead of leaving it in a shell profile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="k"&gt;[Service]&lt;/span&gt;
&lt;span class="na"&gt;Environment&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;PATH&lt;/span&gt;&lt;span class="o"&gt;=/&lt;/span&gt;&lt;span class="n"&gt;home&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;ubuntu&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;local&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;bin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;usr&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;local&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;bin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;usr&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;bin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;bin&lt;/span&gt;
&lt;span class="na"&gt;ExecStart&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;composio&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;home&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;ubuntu&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;job&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;js&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first is easier to audit: the unit file names the binary. The second is easier when the program spawns helpers of its own. Either way the value lives with the code that needs it, not in a file the process does not read.&lt;/p&gt;

&lt;h2&gt;
  
  
  How I check a process I cannot open a shell in
&lt;/h2&gt;

&lt;p&gt;Three readings cover most cases, and none of them require guessing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# what a minimal environment sees&lt;/span&gt;
env -i &lt;span class="nv"&gt;PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/usr/bin:/bin node -v

&lt;span class="c"&gt;# what a running process actually has&lt;/span&gt;
tr &lt;span class="s1"&gt;'\0'&lt;/span&gt; &lt;span class="s1"&gt;'\n'&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; /proc/&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;pid&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/environ &lt;span class="o"&gt;|&lt;/span&gt; grep -E &lt;span class="s1"&gt;'^(PATH|HOME)='&lt;/span&gt;

&lt;span class="c"&gt;# what the manager would hand to a new unit&lt;/span&gt;
systemctl --user show-environment
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the process is a script I own, the cheapest habit is to log the answer at the top of the run, before any work happens:&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="k"&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;shutil&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"python"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;version&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&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="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"node"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;shutil&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;which&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&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;flush&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&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;shutil&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;which&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"node"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;SystemExit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"node not on PATH for this process: "&lt;/span&gt; &lt;span class="o"&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;environ&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="s2"&gt;"PATH"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&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 job that fails with the resolved path and the &lt;code&gt;PATH&lt;/code&gt; it searched saves the next hour. A job that fails with &lt;code&gt;command not found&lt;/code&gt; in the middle of a pipeline sends you to the wrong layer, because the shell reports the missing name and hides the environment behind it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The rule I keep
&lt;/h2&gt;

&lt;p&gt;Anything a machine invokes has to resolve from that machine's &lt;code&gt;PATH&lt;/code&gt;, not from mine. My terminal is one process among dozens, and it is the only one that reads the files where I keep the extra directories. A binary under &lt;code&gt;$HOME&lt;/code&gt;, a symlink in &lt;code&gt;~/.local/bin&lt;/code&gt;, a variable exported in &lt;code&gt;.bashrc&lt;/code&gt;: all of them are conveniences for interactive use until they are made reachable from the base path or named by absolute path where they are called.&lt;/p&gt;




&lt;p&gt;Se você já perdeu tempo com um comando que funciona no seu terminal e falha no serviço que roda a mesma coisa, conta nos comentários qual era a diferença de ambiente. Escrevo em português também, então respondo na língua que você preferir.&lt;/p&gt;

</description>
      <category>linux</category>
      <category>devops</category>
      <category>node</category>
      <category>debugging</category>
    </item>
    <item>
      <title>What one generated image costs, and why my account total did not show it</title>
      <dc:creator>Jonas Francisco de Lima Filho</dc:creator>
      <pubDate>Wed, 25 Nov 2026 20:06:28 +0000</pubDate>
      <link>https://dev.to/jonasfilhodev/what-one-generated-image-costs-and-why-my-account-total-did-not-show-it-11gd</link>
      <guid>https://dev.to/jonasfilhodev/what-one-generated-image-costs-and-why-my-account-total-did-not-show-it-11gd</guid>
      <description>&lt;h1&gt;
  
  
  What one generated image costs, and why my account total did not show it
&lt;/h1&gt;

&lt;p&gt;I generate artwork for a few channels through a hosted image model, one call per piece, from a script. For about a month every call came back HTTP 402 with the same body: &lt;code&gt;This account never purchased credits&lt;/code&gt;. The key had been on disk the whole time, and the same key answered a read on the account endpoint without complaint.&lt;/p&gt;

&lt;h2&gt;
  
  
  A 402 is a billing state, not a bad key
&lt;/h2&gt;

&lt;p&gt;The two status codes get lumped together when a request fails and nobody stops to read the body. 401 means the request did not carry credentials the server accepts. 402 means the credentials were accepted and the account behind them has no balance to spend. In a script I had just written, the difference changes what the next line should do: a 401 sends me back to the environment file, a 402 sends me to the provider dashboard.&lt;/p&gt;

&lt;p&gt;Treating 402 as transient is the expensive mistake. In the adapter I run here, 402 is listed next to 429 and 503 as a status worth retrying on the next model in the chain. That list is reasonable for a busy upstream and wrong for an empty wallet: the same request goes out again, and if a second model is configured, the failure arrives as a different model name and looks like a model problem.&lt;/p&gt;

&lt;p&gt;The only thing I needed was to fund the account. Everything else in that month of errors was noise produced by not reading the status.&lt;/p&gt;

&lt;h2&gt;
  
  
  The price of one call is in the response body
&lt;/h2&gt;

&lt;p&gt;My first assumption was that a price table would tell me the cost, and a monthly total would confirm it. Both were wrong in different ways. The image endpoint returns the charge of that specific call inside the response body:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"usage"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"cost"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.0336165&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"total_tokens"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1186&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 adapter that saves the image keeps that field and nothing else:&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="n"&gt;usage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;_dict_at&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="s2"&gt;"usage"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nb"&gt;isinstance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;usage&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="s2"&gt;"cost"&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="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;float&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;extra&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"cost_usd"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;usage&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"cost"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nb"&gt;isinstance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;usage&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="s2"&gt;"total_tokens"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;extra&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"total_tokens"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;usage&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"total_tokens"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No price table is consulted, and no arithmetic reconstructs the charge from tokens. A price list is a document that goes stale quietly, and models get retired. The model I had pinned, &lt;code&gt;google/gemini-2.5-flash-image&lt;/code&gt;, was discontinued on the same day I first generated an image with its replacement, &lt;code&gt;google/gemini-3.1-flash-lite-image&lt;/code&gt;. Had I been multiplying tokens by a price I had copied from a blog post, the number would have been wrong in a way that produces no error message.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two calls, two shapes, and what the numbers actually tracked
&lt;/h2&gt;

&lt;p&gt;These are the first two images produced after the account was funded, taken from the records kept at the time.&lt;/p&gt;

&lt;p&gt;An icon, square, plain background:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;model ....... google/gemini-3.1-flash-lite-image
cost ........ US$ 0.0336165
tokens ...... 1186
file ........ JPEG 1024x1024, 64 KB
time ........ about 10 seconds
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A cover, asked for a 4:5 portrait, delivered at 768x1376 (ratio 0.558, a strict 9:16 that I did not ask for and had to work around):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cost ........ US$ 0.03365425
tokens ...... 1337
file ........ JPEG 768x1376, 97 KB
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Compare the ratios. Tokens went up 12.7% between the two calls. Output area went up 0.78%. The charge went up 0.11%. The bill followed the pixels, not the tokens, which is what a per-image price looks like from the inside. A token counter is a fine thing to log and a poor cost meter, and the two calls are enough to show why.&lt;/p&gt;

&lt;p&gt;The second call is also a reminder that the output size is not always the size I ordered. That is a separate problem from the bill, but it lands in the same place: the record has to store what arrived, not what I requested.&lt;/p&gt;

&lt;h2&gt;
  
  
  The account endpoint answers a different question
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;GET https://openrouter.ai/api/v1/credits&lt;/code&gt; with the same bearer key returns two numbers, &lt;code&gt;total_credits&lt;/code&gt; and &lt;code&gt;total_usage&lt;/code&gt;. It is a pure read and it costs nothing.&lt;/p&gt;

&lt;p&gt;Right after that first generation, &lt;code&gt;total_usage&lt;/code&gt; had not moved. I checked twice and concluded the endpoint was useless for auditing. Weeks later, against the same ten dollar purchase, it reads &lt;code&gt;0.42386975&lt;/code&gt;, which is about twelve and a half images at the unit price I measured. So the aggregate does move. It just does not answer the question I was asking it, which was what the call I made thirty seconds ago cost. The endpoint answers a cheaper and more useful one: is this failure about money?&lt;/p&gt;

&lt;p&gt;A second endpoint, &lt;code&gt;/api/v1/key&lt;/code&gt;, returns fields the credits call does not: &lt;code&gt;is_free_tier&lt;/code&gt;, &lt;code&gt;usage_daily&lt;/code&gt;, &lt;code&gt;usage_weekly&lt;/code&gt;, &lt;code&gt;usage_monthly&lt;/code&gt;, and a per-key limit with its remaining amount. &lt;code&gt;is_free_tier: false&lt;/code&gt; told me the account state in one request, before I spent anything, and it is the value that would have pointed at the real cause during the month of 402s.&lt;/p&gt;

&lt;h2&gt;
  
  
  A budget check before the loop
&lt;/h2&gt;

&lt;p&gt;Measured unit cost turns a balance into a number of images, which is the form I can act on. This script reads the account, translates the balance, and exits nonzero when a planned batch does not fit.&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="c1"&gt;#!/usr/bin/env python3&lt;/span&gt;
&lt;span class="s2"&gt;"""Ask the provider what is left, then translate the balance into images."""&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;urllib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;

&lt;span class="no"&gt;KEY&lt;/span&gt; &lt;span class="o"&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;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"OPENROUTER_API_KEY"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="no"&gt;UNIT_USD&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;float&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;environ&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="s2"&gt;"UNIT_USD"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"0.0336165"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;credits&lt;/span&gt;&lt;span class="p"&gt;(&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;:&lt;/span&gt;
    &lt;span class="n"&gt;req&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;urllib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="s2"&gt;"https://openrouter.ai/api/v1/credits"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"Authorization"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"Bearer {key}"&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;with&lt;/span&gt; &lt;span class="n"&gt;urllib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;urlopen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;20&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;resp&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;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;resp&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"data"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;


&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;credits&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;left&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"total_credits"&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="kt"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"total_usage"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;planned&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"purchased {data['total_credits']:.2f}  used {data['total_usage']:.8f}  left {left:.8f}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"at {UNIT_USD} per image, that is {left / UNIT_USD:.0f} images left"&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;planned&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;cost&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;planned&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="no"&gt;UNIT_USD&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"planned {planned} images = {cost:.4f} USD"&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;cost&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"short by {cost - left:.4f} USD"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run against the live account, asking whether a batch of twenty fits:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ python3 orcamento_imagem.py 20
purchased 10.00  used 0.42386975  left 9.57613025
at 0.0336165 per image, that is 285 images left
planned 20 images = 0.6723 USD
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The exit code is the part that matters in a scheduled job. A cron that generates art on a loop can check the budget before the first request and stop with a message instead of collecting 402s at four in the morning.&lt;/p&gt;

&lt;h2&gt;
  
  
  What changed in how I run this
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The unit cost is measured once, from the response, and then written into the script as &lt;code&gt;UNIT_USD&lt;/code&gt;. It is a number in code, not something I remember.&lt;/li&gt;
&lt;li&gt;402 stops the run. No retry, no fallback to another model, because a different model name would hide the only fact that matters, which is that the account cannot pay.&lt;/li&gt;
&lt;li&gt;Every generation records &lt;code&gt;cost_usd&lt;/code&gt; next to the file it produced, so the ledger is the sum of real charges rather than an estimate built from tokens.&lt;/li&gt;
&lt;li&gt;The model id is pinned in configuration and checked after each upgrade. The last one disappeared without a deprecation warning I could read in advance.&lt;/li&gt;
&lt;li&gt;The arithmetic happens before the schedule, not after. At the measured price, 120 images a month is US$ 4.03, a year of one a day is US$ 12.27, and ten a day for a year is US$ 122.70. Those are small numbers until a loop multiplies them, and the multiplication is free to do in advance.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;None of this is specific to images. Any metered API that returns its own cost per request can be handled the same way: read the charge from the response, keep it with the artifact, and translate the balance into units you can plan with. The aggregate figure on the dashboard is there to tell you which kind of failure you are looking at.&lt;/p&gt;

&lt;p&gt;Se você gera imagem por API em algum projeto, o custo por chamada está na resposta, não no painel. Medir uma vez e colocar esse número no script evita a surpresa de descobrir o gasto quando o loop já rodou mil vezes. Se você já passou por um 402 confundido com chave inválida, conta aqui nos comentários como descobriu.&lt;/p&gt;

</description>
      <category>api</category>
      <category>ai</category>
      <category>python</category>
      <category>debugging</category>
    </item>
    <item>
      <title>My layout check kept returning an empty list. I was reading it as a verdict.</title>
      <dc:creator>Jonas Francisco de Lima Filho</dc:creator>
      <pubDate>Mon, 23 Nov 2026 20:07:44 +0000</pubDate>
      <link>https://dev.to/jonasfilhodev/my-layout-check-kept-returning-an-empty-list-i-was-reading-it-as-a-verdict-b3a</link>
      <guid>https://dev.to/jonasfilhodev/my-layout-check-kept-returning-an-empty-list-i-was-reading-it-as-a-verdict-b3a</guid>
      <description>&lt;h1&gt;
  
  
  My layout check kept returning an empty list. I was reading it as a verdict.
&lt;/h1&gt;

&lt;p&gt;I generate carousel covers from HTML, render them in headless Chromium, and publish one four times a day. Before a cover ships, three checks run against the PNG: no two blocks overlap, nothing is cut at the edge, the logo keeps its margin. In October a cover passed all three and still read wrong. The title promised an answer, and the big number sat between the title and the sentence explaining what it referred to. Anyone swiping to the second slide met "193x" before knowing the subject.&lt;/p&gt;

&lt;p&gt;So I added a fourth check for reading order. It measures ink per pixel, groups rows into blocks, labels each block as title, definition or number, and compares their vertical positions. The check is ordinary. What took four versions to get right is that a check can return green while measuring nothing at all.&lt;/p&gt;

&lt;h2&gt;
  
  
  Version one trusted the document
&lt;/h2&gt;

&lt;p&gt;The first version knew the order from the HTML: title first, definition second, number third. It read the y coordinate of each block position and compared them.&lt;/p&gt;

&lt;p&gt;That held until the title wrapped to two lines. The second line arrived as its own block, the check called it the definition, and the first line of the real definition became the number. The three positions were still in increasing order, so the check passed. It passed while labeling the wrong rows.&lt;/p&gt;

&lt;p&gt;The fix was to stop using the document as data. A block is what it measures: a filled band of rows with a height and a width. Nothing in the check reads the HTML any more, only the PNG.&lt;/p&gt;

&lt;h2&gt;
  
  
  Height alone put the number in the title slot
&lt;/h2&gt;

&lt;p&gt;Font size survives the render as band height, so the tallest band is a good first guess for the number. On a cover with a single digit, the number band measured 114px tall and 90px wide, while the two title lines measured 91px and 72px tall with widths of 686px and 507px. Height separates those three.&lt;/p&gt;

&lt;p&gt;Then came a cover whose number was "85". Two digits at 150px measure 584px wide, wider than any single-digit number the check had seen. A cutoff on width at 0.35 of the 904px content column, 316px, was enough for one digit and wrong for two. The number got labeled as text, became the title because it was the tallest text block, and the check reported:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FALHA: 0 numero(s), 1 titulo(s)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That message is not a verdict about the cover. The check could not see a number, so it had nothing to compare. I had been treating both outcomes as failures of the same kind for weeks.&lt;/p&gt;

&lt;p&gt;The current classifier uses both dimensions, plus a floor relative to the tallest band:&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="n"&gt;alturas&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;sorted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"h"&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;b&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;bs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;ref&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;alturas&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;alturas&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="no"&gt;PERCENTIL_REF_ALTURA&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;estreitas&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;bs&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"h"&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;ref&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;1.5&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;h_max&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"h"&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;b&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;bs&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;estreitas&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;estreitas&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"h"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="no"&gt;NUMERO_MIN_REL&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;h_max&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;b&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;bs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"classe"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"NUMERO"&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;estreitas&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; \
        &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"w"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;CONTEUDO&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="no"&gt;FATOR_LARGURA_NUMERO&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="s2"&gt;"TEXTO"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The floor arrived on 21 November, from a cover where the number was "99%" at 429px wide and 145px tall. A filled badge above it was 431px wide and 46px tall. Width could not tell them apart, and the badge passed the 1.5x test because its 46px is more than 1.5 times a 20px text line. Height could: nothing below half the tallest band is a number.&lt;/p&gt;

&lt;h2&gt;
  
  
  The reference for "tall" moves with the art
&lt;/h2&gt;

&lt;p&gt;The first version compared each band to the median height of all bands. On a seven-band cover the median was 29px, and the 114px number passed easily. On the small art used as a control, with three blocks (title 90, number 114, definition 33), the median was 90. The number needed more than 135 to qualify and had 114. It became text, the title became the tallest block, the function that reads the order found no number and returned an empty list.&lt;/p&gt;

&lt;p&gt;The median was measuring the middle of the list, and the middle of the list changes when the list gets shorter. The first quartile held in both cases: 21px on the seven-band cover, 33px on the three-block art, with the number above 1.5x in both. The reference had to be the text line, not a statistic that floats.&lt;/p&gt;

&lt;h2&gt;
  
  
  A control has to reproduce the defect
&lt;/h2&gt;

&lt;p&gt;A test that only passes is worth nothing. The cover that started this had the number between the title and the definition, so the control rebuilds exactly that: it crops the real blocks out of the real cover, paints over everything below the title, and pastes the number and the definition in the wrong order. The rule that reads the result is the same function as the main test.&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="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;onde_apaga&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="no"&gt;VAO_CONTROLE&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;numero&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="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;defi&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;      &lt;span class="c1"&gt;# the wrong order&lt;/span&gt;
    &lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;fatia&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;nova&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;paste&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MARGEM_X&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="no"&gt;VAO_CONTROLE&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two versions of this control failed before it worked. In the first, the gap between the pasted blocks was 24px and the grouping gap is 30px, so all rows merged into one block, the classifier labeled that block as a number, and the order came out empty. The control "rejected" the art because it could not measure it, which is the same bug it was supposed to catch.&lt;/p&gt;

&lt;p&gt;In the second, measured on 17 October, the control art was reduced to three slices. With the top bands removed, the first quartile rose to 72px, the 105px number needed 108px, and the order came out empty again through a new path. The fix was to keep the top of the real cover and recompose only what sits below the title, so the reference stays where it was.&lt;/p&gt;

&lt;p&gt;An empty list is now an explicit failure with its own message. It says the measurement did not happen, and it does not count as the defect being caught.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it prints now
&lt;/h2&gt;

&lt;p&gt;Here is the check on the cover from 22 November, a deep purple background that the per-piece wrapper declares as &lt;code&gt;(88, 3, 124)&lt;/code&gt;. The wrapper overrides the palette, the measurement window and the file name. It imports the shared module and never copies the rule, because two copies of a rule are two rules, and only one of them survives the next edit.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;y 269.. 441  hmax= 54  wmax= 690  -&amp;gt; TITULO
y 473.. 581  hmax= 28  wmax= 881  -&amp;gt; DEFINICAO
y 624.. 947  hmax=168  wmax= 903  -&amp;gt; NUMERO

ordem lida: TITULO -&amp;gt; DEFINICAO -&amp;gt; NUMERO
ok: titulo, definicao, numero

== controle negativo: a ordem errada tem que reprovar
ordem da arte com defeito: TITULO -&amp;gt; NUMERO -&amp;gt; DEFINICAO
ok: reprovou
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Seven blocks were measured on that cover. Four belong to frame elements (the top line, a rule, a badge, the source note), they land in the definition class, and they do not disturb the order because only the first block of each class is compared. The check exits non-zero when the order is wrong, when a block is missing, or when either the main art or the control art produces an empty list.&lt;/p&gt;

&lt;p&gt;The lesson I keep relearning: a verifier is code, and code that cannot measure returns a value that looks like an answer. "No number found" and "the number is in the wrong place" are different facts, and only one of them is about the image. Building the control so that it produces the real defect, from real pixels and through the same function, is what separates the two.&lt;/p&gt;

&lt;p&gt;Se esse tipo de teste já te deu um verde que não significava nada, conta nos comentários o que estava sendo medido de verdade. Cada verificação que passa por motivo errado é uma armadilha que eu prefiro aprender pelo relato de outra pessoa.&lt;/p&gt;

</description>
      <category>python</category>
      <category>testing</category>
      <category>images</category>
      <category>debugging</category>
    </item>
    <item>
      <title>One User-Agent string got a 403. curl, wget and Go went straight through.</title>
      <dc:creator>Jonas Francisco de Lima Filho</dc:creator>
      <pubDate>Fri, 20 Nov 2026 20:19:20 +0000</pubDate>
      <link>https://dev.to/jonasfilhodev/one-user-agent-string-got-a-403-curl-wget-and-go-went-straight-through-4oo8</link>
      <guid>https://dev.to/jonasfilhodev/one-user-agent-string-got-a-403-curl-wget-and-go-went-straight-through-4oo8</guid>
      <description>&lt;p&gt;&lt;em&gt;Where the block actually happens, measured with eight clients on the same URL.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I publish everything I build to a small private ops portal. It sits behind basic auth, and in front of that nginx there is a Cloudflare zone for the domain. Today I sent it a request from a Python client with the library's default User-Agent and got back a 403 whose body was 17 bytes long: &lt;code&gt;error code: 1010&lt;/code&gt;. The two explanations that come first are the credential file and a forgotten firewall rule. Neither was true. The site answered normally to every other client I tried, and the only difference between the request that failed and the ones that worked was the string the client used to introduce itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  Eight strings, one blocked
&lt;/h2&gt;

&lt;p&gt;I sent the same GET to the same host, in the same minute, changing one header:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;User-Agent&lt;/th&gt;
&lt;th&gt;Status&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Python-urllib/3.14&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;403&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Python-urllib/3.12&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;403&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;python-requests/2.32.3&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;401&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;curl/8.5.0&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;401&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Wget/1.21.4&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;401&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Go-http-client/2.0&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;401&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;my-app/1.0&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;401&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;Mozilla/5.0 (X11; Linux x86_64) Chrome/126.0&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;401&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;(no User-Agent header at all)&lt;/td&gt;
&lt;td&gt;401&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Two strings failed and both were the same token with a different version number. Everything else reached nginx and got the 401 that basic auth is supposed to produce. That rules out the explanations that come to mind first. A rate limit would have cut the run short, not blocked two specific strings. A broken credential would have produced the same status for all of them. An outage would not care which version of Python the client claims to be. And the blocked clients are not the automated ones: &lt;code&gt;wget&lt;/code&gt; and the Go standard library look nothing like a browser, and both were allowed through.&lt;/p&gt;

&lt;h2&gt;
  
  
  The block happens before your server sees anything
&lt;/h2&gt;

&lt;p&gt;The 403 came with headers I had never looked at closely:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="no"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="mi"&gt;403&lt;/span&gt;
&lt;span class="na"&gt;content-type: text/plain; charset&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;UTF&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;
&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;17&lt;/span&gt;
&lt;span class="na"&gt;cache-control: private, max-age&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;no&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;store&lt;/span&gt;
&lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;cloudflare&lt;/span&gt;
&lt;span class="n"&gt;cf&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;ray&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;a5da0ee3dee9dd6b&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="no"&gt;DFW&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No &lt;code&gt;www-authenticate&lt;/code&gt;, no &lt;code&gt;content-type: text/html&lt;/code&gt;, no nginx version. The body in hex is &lt;code&gt;error code: 1010&lt;/code&gt; plus a newline, 17 bytes, exactly what &lt;code&gt;content-length&lt;/code&gt; announces. That is not a page my server generated.&lt;/p&gt;

&lt;p&gt;Cloudflare's documentation for error 1010 describes it as access denied based on the browser's signature, and lists among the common causes "the default Python &lt;code&gt;urllib&lt;/code&gt; user agent" as an example of what Browser Integrity Check treats as a non-browser client (&lt;code&gt;developers.cloudflare.com/support/troubleshooting/http-status-codes/cloudflare-1xxx-errors/error-1010/&lt;/code&gt;, read on 2026-11-20). The check is part of the zone configuration, not of my application, which explains why nothing in my nginx logs would ever show this request.&lt;/p&gt;

&lt;h2&gt;
  
  
  The origin answers in 34 milliseconds
&lt;/h2&gt;

&lt;p&gt;To confirm the server was innocent I kept the hostname and TLS handshake and pointed only the connection at loopback:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -s -o /dev/null -w &lt;span class="s1"&gt;'%{http_code} %{time_total}\n'&lt;/span&gt; \
  --resolve portal.example.com:443:127.0.0.1 \
  -A &lt;span class="s2"&gt;"Python-urllib/3.14"&lt;/span&gt; https://portal.example.com/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The answer was &lt;code&gt;401 0.034&lt;/code&gt;. Three repetitions gave 0.036, 0.034 and 0.034 seconds. The same request through the public hostname took about 130 to 160 milliseconds and returned 403. &lt;code&gt;--resolve&lt;/code&gt; keeps the certificate validation and the virtual host match, so this is the same request as far as nginx is concerned, and nginx answered with the auth challenge, meaning it never considered the User-Agent at all. The shape matters more than the milliseconds: the origin is a local round trip, the edge adds a network round trip and a WAF decision.&lt;/p&gt;

&lt;p&gt;That single command splits the two halves of the problem. If the origin fails too, your configuration is the suspect. If the origin is fine and the public name is not, the difference is in whatever sits between them, and no amount of reading the server config will show it.&lt;/p&gt;

&lt;h2&gt;
  
  
  A credential cannot fix a request the edge rejected
&lt;/h2&gt;

&lt;p&gt;The part that cost me the most time: the 403 came back even with valid credentials attached.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;source&lt;/span&gt; ~/.site_auth
curl -s -o /dev/null -w &lt;span class="s1"&gt;'%{http_code}\n'&lt;/span&gt; -u &lt;span class="s2"&gt;"$SITE_AUTH"&lt;/span&gt; \
  -A &lt;span class="s2"&gt;"Python-urllib/3.14"&lt;/span&gt; https://portal.example.com/    &lt;span class="c"&gt;# 403&lt;/span&gt;
curl -s -o /dev/null -w &lt;span class="s1"&gt;'%{http_code}\n'&lt;/span&gt; -u &lt;span class="s2"&gt;"$SITE_AUTH"&lt;/span&gt; \
  -A &lt;span class="s2"&gt;"Mozilla/5.0 (X11; Linux x86_64) Chrome/126.0"&lt;/span&gt; https://portal.example.com/    &lt;span class="c"&gt;# 200&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same user, same password, same URL, one header different. The WAF evaluates the request before nginx gets a chance to read the &lt;code&gt;Authorization&lt;/code&gt; header, so the credential was never examined. That is the practical rule I took from it: when a URL that normally answers 401 starts answering 403, the password was not looked at. Rereading the credential file, rehashing it, or trying another user is work in the wrong layer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Removing the header is not the fix
&lt;/h2&gt;

&lt;p&gt;The absence of a User-Agent also passed, with a 401. That makes "delete the header" look like a solution, and it is a bad one for two reasons. The rule matches a signature, so a client that stops signing itself is still an unnamed client, and the log entry it leaves is no more useful than before. And the monitor that only alarms on 403 would go green while the request still does not identify itself.&lt;/p&gt;

&lt;p&gt;The documented fix is the simpler one: send a descriptive User-Agent. I tested two, &lt;code&gt;my-app/1.0&lt;/code&gt; and &lt;code&gt;jonas-check/1.0&lt;/code&gt;, and both passed the edge with a 401. No browser impersonation needed.&lt;/p&gt;

&lt;p&gt;That matters to me because of what my own scripts do. Several of them set a constant at the top of the file, and the constant is a full Chrome string:&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="no"&gt;UA&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "&lt;/span&gt;
      &lt;span class="s2"&gt;"(KHTML, like Gecko) Chrome/126.0 Safari/537.36"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A scraper that calls itself Chrome is lying to every server it talks to, including servers I own, and it makes the access logs of those servers useless for telling a real browser from a script. &lt;code&gt;my-app/1.0&lt;/code&gt; is one line, passes the check that blocked the original request, and tells anyone reading the log what is happening.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which layer my smoke test is allowed to judge
&lt;/h2&gt;

&lt;p&gt;My deploy script runs a set of checks after each publish. Every one of them goes through this function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;check&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;local&lt;/span&gt; &lt;span class="nv"&gt;url&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$1"&lt;/span&gt; &lt;span class="nv"&gt;expect&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$2"&lt;/span&gt; &lt;span class="nv"&gt;desc&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$3"&lt;/span&gt;
  &lt;span class="kd"&gt;local&lt;/span&gt; code
  &lt;span class="c"&gt;# --resolve aponta o hostname do cert para o loopback local, para nao&lt;/span&gt;
  &lt;span class="c"&gt;# depender de DNS/Cloudflare no smoke test&lt;/span&gt;
  &lt;span class="nv"&gt;code&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$(auth_curl -o /dev/null -w '%{http_code}' \
    --resolve "&lt;/span&gt;portal.example.com:443:127.0.0.1&lt;span class="s2"&gt;" "&lt;/span&gt;&lt;span class="nv"&gt;${BASE}${url}&lt;/span&gt;&lt;span class="s2"&gt;" || echo 000)"&lt;/span&gt;
  &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"$code"&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"$expect"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"    OK   ${desc} (${code})"&lt;/span&gt; \
    &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"    FAIL ${desc} esperado=${expect} obtido=${code}"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;2&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="nv"&gt;fail&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

check &lt;span class="s2"&gt;"/"&lt;/span&gt;                            &lt;span class="s2"&gt;"200"&lt;/span&gt; &lt;span class="s2"&gt;"index"&lt;/span&gt;
check &lt;span class="s2"&gt;"/health"&lt;/span&gt;                      &lt;span class="s2"&gt;"200"&lt;/span&gt; &lt;span class="s2"&gt;"health"&lt;/span&gt;
check &lt;span class="s2"&gt;"/css/style.css?v=${ASSET_SHA}"&lt;/span&gt; &lt;span class="s2"&gt;"200"&lt;/span&gt; &lt;span class="s2"&gt;"css"&lt;/span&gt;
check &lt;span class="s2"&gt;"/js/app.js"&lt;/span&gt;                   &lt;span class="s2"&gt;"200"&lt;/span&gt; &lt;span class="s2"&gt;"js"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The comment in the middle is the decision. The smoke test deliberately bypasses DNS and Cloudflare, because a deploy should not fail for a reason that has nothing to do with the files it just wrote. The price of that choice is the corollary: a green deploy proves nginx has the files, and proves nothing about a client reaching them through the edge.&lt;/p&gt;

&lt;p&gt;Both checks are worth having, and they answer different questions. If I pointed this one at the public hostname, a 403 from the edge would turn every deploy red for a reason unrelated to the release, and a 401 would pass while proving nothing about the content. The arm that goes through the edge needs its own client with a known User-Agent, its own expected status, and its own message.&lt;/p&gt;

&lt;h2&gt;
  
  
  When one client fails and the others do not
&lt;/h2&gt;

&lt;p&gt;The sequence that worked, in the order that saved the most time:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reproduce with the exact client that failed. A browser standing in for a script hides the whole problem.&lt;/li&gt;
&lt;li&gt;Change one header at a time and keep URL, method and credentials fixed.&lt;/li&gt;
&lt;li&gt;Read the body and the &lt;code&gt;server&lt;/code&gt; header before reading the status code. Seventeen bytes of plain text is not your application.&lt;/li&gt;
&lt;li&gt;Test the origin with &lt;code&gt;--resolve&lt;/code&gt; to separate edge from server in one command.&lt;/li&gt;
&lt;li&gt;Treat 403 on a URL that normally answers 401 as "the application never saw this request".&lt;/li&gt;
&lt;li&gt;Give every script a fixed, descriptive User-Agent, written in the code, not passed through the environment.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Quem mantém painel privado atrás de Cloudflare já levou um 403 desses e sabe o tempo que se perde procurando no lugar errado. Se aconteceu com você, conta nos comentários qual foi o cliente e o que apareceu no corpo da resposta.&lt;/p&gt;

</description>
      <category>cloudflare</category>
      <category>webdev</category>
      <category>debugging</category>
      <category>python</category>
    </item>
    <item>
      <title>My keyword filter read "tomografia computadorizada" as a computer purchase</title>
      <dc:creator>Jonas Francisco de Lima Filho</dc:creator>
      <pubDate>Wed, 18 Nov 2026 20:11:22 +0000</pubDate>
      <link>https://dev.to/jonasfilhodev/my-keyword-filter-read-tomografia-computadorizada-as-a-computer-purchase-134i</link>
      <guid>https://dev.to/jonasfilhodev/my-keyword-filter-read-tomografia-computadorizada-as-a-computer-purchase-134i</guid>
      <description>&lt;p&gt;I follow the small municipalities around my region in Brazil. Everything they buy is published as a text description in a national procurement API, and a share of those purchases is IT work I can bid on: maintenance contracts, network cabling, software licenses, toner, a hosted portal. The API has no full text search worth using, so I wrote a filter over the object description. Last run made 424 requests across four procurement modalities, found 165 objects containing an IT term, and marked 12 of them as billable under the MEI occupations I hold today.&lt;/p&gt;

&lt;p&gt;The filter is a keyword classifier. It has two ways to be wrong, and they cost very different things. A false positive costs me a minute of reading. A false negative costs the opportunity and leaves no trace in the run. Everything below came from a real object that fooled it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Accents first, because the source is Portuguese
&lt;/h2&gt;

&lt;p&gt;Object descriptions arrive in uppercase, with and without accents, and often carry a platform prefix like &lt;code&gt;[Portal de Compras Publicas] -&lt;/code&gt;. Both get normalized before any matching:&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="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;sem_acento&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;txt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;unicodedata&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;normalize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'NFKD'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;txt&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;unicodedata&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;combining&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&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="nf"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;limpa_objeto&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;txt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="s2"&gt;"""Remove prefixos de plataforma tipo '[Portal de Compras Publicas] - '."""&lt;/span&gt;
    &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s1"&gt;'^\s*\[[^\]]{0,60}\]\s*-?\s*'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&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;txt&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&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;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s1"&gt;'\s+'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;' '&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&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;NFKD decomposition plus a filter on combining characters turns &lt;code&gt;Manutenção&lt;/code&gt; into &lt;code&gt;manutencao&lt;/code&gt;. Without it, half my keyword list never matches, and the failure is invisible because a filter that finds nothing looks like a quiet week.&lt;/p&gt;

&lt;h2&gt;
  
  
  Short terms need a word boundary
&lt;/h2&gt;

&lt;p&gt;Seventy-four terms make up the strong list. Most are long enough that a plain substring test is correct: &lt;code&gt;computador&lt;/code&gt; should match &lt;code&gt;computadores&lt;/code&gt;, and that inflection is the normal case in Portuguese. Short terms behave differently, because they live inside other words.&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="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;termo&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;FORTES&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;termo&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;3&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;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s1"&gt;'\b'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;escape&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;termo&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s1"&gt;'\b'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;achados&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;termo&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="n"&gt;termo&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;achados&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;termo&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One term in the list is short enough to need it: &lt;code&gt;ti&lt;/code&gt;. A plain substring test on those two letters fires on &lt;code&gt;licitacao&lt;/code&gt;, &lt;code&gt;noticia&lt;/code&gt; and &lt;code&gt;importante&lt;/code&gt;, which appear in most of a procurement feed. Everything longer stays on the substring test, &lt;code&gt;rack&lt;/code&gt; included, because &lt;code&gt;computador&lt;/code&gt; has to match &lt;code&gt;computadores&lt;/code&gt; and that inflection is the rule rather than the exception.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ambiguous words need a companion in the same sentence
&lt;/h2&gt;

&lt;p&gt;Four terms are real IT vocabulary and also everyday Portuguese: &lt;code&gt;servidor&lt;/code&gt; (server, or civil servant), &lt;code&gt;suporte tecnico&lt;/code&gt; (IT support, or support for anything), &lt;code&gt;cartucho&lt;/code&gt; (printer cartridge, or respirator cartridge), &lt;code&gt;licenca&lt;/code&gt; (software license, or a professional registration fee). Those four never classify an object on their own:&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="k"&gt;if&lt;/span&gt; &lt;span class="nb"&gt;all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;TERMOS_FRACOS&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;achados&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="ow"&gt;not&lt;/span&gt; &lt;span class="nb"&gt;any&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;COMPANHIA_IT&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;achados&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'termo ambiguo sem companhia de TI'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The companion list has 53 entries, from &lt;code&gt;impressora&lt;/code&gt; to &lt;code&gt;cabeamento&lt;/code&gt;. The rule was added after a measurement on 19/10/2026 over 173 findings: without it, 15 objects entered by mistake, among them medical expert examinations, uniforms, a marmitex lunch contract, a water cooler, an LED panel rental, and two consultancy contracts in social assistance and public transparency. No legitimate object was lost by adding it.&lt;/p&gt;

&lt;p&gt;That measurement is the reason I trust the rule. Fifteen wrong entries in 173 was enough to act on, and losing no legitimate object is what made the rule safe to keep.&lt;/p&gt;

&lt;h2&gt;
  
  
  The reject list is a log with dates
&lt;/h2&gt;

&lt;p&gt;Eighty-three entries exist to kill a match even when a strong term is present. Each one came from a specific sentence:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;tomografia computadorizada&lt;/code&gt; matched &lt;code&gt;computador&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;filmes radiologicos para impressora de imagens medicas&lt;/code&gt; matched &lt;code&gt;impressora&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;leite integral UHT para pacientes, acompanhantes e servidores da Fundacao&lt;/code&gt; matched &lt;code&gt;servidor&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;independente de transcricao&lt;/code&gt; is boilerplate at the end of a metalwork contract and matched &lt;code&gt;transcricao&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;licenca anual de Anotacao de Responsabilidade Tecnica&lt;/code&gt; matched &lt;code&gt;licenca&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;linha fixa&lt;/code&gt; for a telephone line matched telephony, which is not an occupation of mine.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The comments in the file carry the date of the scan that produced each group. That turns the reject list into a record of what the source actually contains, and the next person editing it can see why a line exists instead of deleting it as noise.&lt;/p&gt;

&lt;h2&gt;
  
  
  One reject entry nearly killed a real opportunity
&lt;/h2&gt;

&lt;p&gt;Civil servants are everywhere in this feed. A notice for a basic computing course aimed at municipal employees is a legitimate purchase I can invoice, and it contains the word &lt;code&gt;servidor&lt;/code&gt; in its most common sense. The reject rule therefore has an exception:&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="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;RUIDO&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;r&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;t&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;r&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;RUIDO_SERVIDOR&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="nb"&gt;any&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;SERVICO_DE_MEI&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;continue&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;achados&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the noise belongs to the group about people, and the same object also matches a service I actually sell, the object survives. Without those two lists, &lt;code&gt;curso de informatica para os servidores municipais&lt;/code&gt; would be dropped by my own filter, silently, and it is one of the few things I can invoice.&lt;/p&gt;

&lt;h2&gt;
  
  
  The tests are a list of inputs that must be rejected
&lt;/h2&gt;

&lt;p&gt;The test file holds 15 positive cases and 24 negative ones, and it fails the run when any of them misses. A negative case passes when the classifier finds no term at all, or when it finds terms and returns a reason to discard:&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="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;nome&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;txt&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;negativo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;classifica&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;txt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;ok&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;falhas&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;ok&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The negative list is the valuable half, because I wrote it by pasting objects that had already fooled the filter. &lt;code&gt;AQUISICAO DE FILMES RADIOLOGICOS DRY FILM PARA IMPRESSORA DE IMAGENS MEDICAS&lt;/code&gt; is in there. So is a car rental that mentions computer maintenance, and a school lunch contract that mentions IT equipment.&lt;/p&gt;

&lt;p&gt;One case checks the reason, not the outcome. A bank accreditation notice matches &lt;code&gt;digitacao&lt;/code&gt; and would be labeled with my data entry occupation. The correct behavior is a discard by a specific noise entry, so the assertion names the 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="n"&gt;achados&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ruido&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;classifica&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;txt_banco&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;ok&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;achados&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;ruido&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'instituicoes financeiras'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'arrecadacao de tributos'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                                 &lt;span class="s1"&gt;'documento de arrecadacao municipal'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Written as "no profile, therefore fine", that test would pass for any future reason, including a rule that drops legitimate notices. The same notice, from Senador Modestino, had already been published as billable before the fix.&lt;/p&gt;

&lt;h2&gt;
  
  
  Recall fails without a message
&lt;/h2&gt;

&lt;p&gt;On 16/11/2026 a Diamantina notice for &lt;code&gt;aquisicao de computadores&lt;/code&gt; was marked as outside my MEI, which was wrong, since buying computers falls under a commerce occupation I can use. The fix added four phrases that name the purchase explicitly: &lt;code&gt;aquisicao de computadores&lt;/code&gt;, &lt;code&gt;fornecimento de computadores&lt;/code&gt;, &lt;code&gt;aquisicao de microcomputadores&lt;/code&gt;, &lt;code&gt;aquisicao de computadores e perifericos&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I did not add &lt;code&gt;computador&lt;/code&gt; alone to that list, even though it would have caught the case. It would also match spare parts, maintenance and rental, and those are different occupations. The narrower fix costs a future miss and keeps the report honest.&lt;/p&gt;

&lt;p&gt;That is the asymmetry I plan around. Precision errors show up in the output and get fixed in a minute. Recall errors do not show up at all, which is why the report is read every week instead of trusted. The test suite catches what I thought of. Reading the notices catches what I did not.&lt;/p&gt;

&lt;p&gt;Today the filter has 74 strong terms, 53 companion terms and 83 noise entries. Run against the current snapshot of 164 objects, none of them would be dropped by the rules as they stand, and the control suite finishes with zero failures. None of that says the next municipality uses a phrase I have not seen.&lt;/p&gt;




&lt;p&gt;Se você mantém algum filtro de palavra-chave em cima de texto de terceiro, comenta qual foi o primeiro falso positivo que te obrigou a escrever um teste. Eu respondo em português aqui embaixo.&lt;/p&gt;

</description>
      <category>python</category>
      <category>testing</category>
      <category>regex</category>
      <category>brazil</category>
    </item>
    <item>
      <title>Twenty connections said ACTIVE. One of them had zero tools.</title>
      <dc:creator>Jonas Francisco de Lima Filho</dc:creator>
      <pubDate>Mon, 16 Nov 2026 20:12:58 +0000</pubDate>
      <link>https://dev.to/jonasfilhodev/twenty-connections-said-active-one-of-them-had-zero-tools-491e</link>
      <guid>https://dev.to/jonasfilhodev/twenty-connections-said-active-one-of-them-had-zero-tools-491e</guid>
      <description>&lt;h1&gt;
  
  
  Twenty connections said ACTIVE. One of them had zero tools.
&lt;/h1&gt;

&lt;p&gt;I reach most third-party services through a single integration platform, Composio, from one authenticated CLI. Gmail, the repo, the calendar, Instagram, the blog account, the task tracker: each one is a connection, and each one appears in the same output of &lt;code&gt;composio connections list&lt;/code&gt;. When someone asks me whether I can do something with one of those apps, that output is where I look.&lt;/p&gt;

&lt;p&gt;This week I stopped reading the word ACTIVE and counted what was behind it. Three of the twenty connections that call themselves active cannot do the thing the word implies, and each one fails in a different way.&lt;/p&gt;

&lt;h2&gt;
  
  
  ACTIVE describes an authorization, not a toolkit
&lt;/h2&gt;

&lt;p&gt;Connections are stored per toolkit, not per account. One toolkit can hold several entries, and each entry carries a &lt;code&gt;status&lt;/code&gt;, an optional &lt;code&gt;alias&lt;/code&gt; and an internal id.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"discord"&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="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"ACTIVE"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"alias"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"word_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"discord_crumb-myna"&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;The status has four possible values, and only the first one grants access. &lt;code&gt;ACTIVE&lt;/code&gt; means the OAuth grant is in place. &lt;code&gt;EXPIRED&lt;/code&gt; means it was in place and no longer is. &lt;code&gt;INITIATED&lt;/code&gt; means somebody opened an authorization page and never finished it, which is indistinguishable from nothing until you try to use it.&lt;/p&gt;

&lt;p&gt;Here is the counting script I ran, reduced to the part that matters:&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="n"&gt;conn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;json&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;subprocess&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;span class="p"&gt;[&lt;/span&gt;&lt;span class="no"&gt;CLI&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"connections"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"list"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;capture_output&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;stdout&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;by_status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;collections&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Counter&lt;/span&gt;&lt;span class="p"&gt;(&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;toolkit&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;entries&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;conn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&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;for&lt;/span&gt; &lt;span class="n"&gt;entry&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;entries&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;by_status&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"status"&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="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output today is &lt;code&gt;toolkits in the file: 27&lt;/code&gt; and &lt;code&gt;status: {'EXPIRED': 21, 'ACTIVE': 20}&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Forty-one connection entries across twenty-seven toolkits, twenty of them usable. The expired half is not noise. Four Cloudflare grants and two WhatsApp grants sit in the same map, one key away from a working one, and any script that iterates over toolkits without reading &lt;code&gt;status&lt;/code&gt; will happily use the dead grant.&lt;/p&gt;

&lt;h2&gt;
  
  
  The connection that authorizes nothing
&lt;/h2&gt;

&lt;p&gt;The first thing I checked after the count was how many tools each ACTIVE toolkit exposes. For Amazon, the answer is none.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ composio tools list amazon --limit 400
$
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Empty stdout, exit code 0, no JSON, no error message. The authorization completed, the connection is green, and the toolkit has zero callable tools behind it. There is nothing to run and nothing to report, which is exactly the problem: my wrapper checks the return code, sees zero, parses nothing, and moves on as if the list were empty for a normal reason.&lt;/p&gt;

&lt;p&gt;A connection with no tools is not a rare edge case in a catalog this size. It is the difference between "I have permission" and "there is an endpoint" that most integration dashboards hide behind one green word.&lt;/p&gt;

&lt;h2&gt;
  
  
  The count that looks healthy and the verb that is missing
&lt;/h2&gt;

&lt;p&gt;Discord is the opposite failure. It reports 28 tools, and the number is real. What matters is which verbs those tools carry, so I grepped the slugs:&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="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;subprocess&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;span class="p"&gt;[&lt;/span&gt;&lt;span class="no"&gt;CLI&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"tools"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"list"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tk&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"--limit"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"400"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                   &lt;span class="n"&gt;capture_output&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;240&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;slugs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"slug"&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;t&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;json&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;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;stdout&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;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;stdout&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&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;hits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;slugs&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="s2"&gt;"MESSAGE|CHANNEL|GUILD_MEMBER|DM"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&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;For Discord the hit list has one line, &lt;code&gt;DISCORD_GET_MY_GUILD_MEMBER&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;That tool reads my own membership in a server. It does not read a channel, it does not read a direct message, and it does not list what a server contains. So the honest answer to "read the last messages in that server" is no, and the honest reason is not that Discord is misconfigured. The twenty-eight available tools simply do not include the operation, and a count of twenty-eight is what makes that answer easy to get wrong.&lt;/p&gt;

&lt;p&gt;The same grep on dev.to returns eight hits, which is why publishing an article from the CLI works and why I write drafts through it every other day.&lt;/p&gt;

&lt;h2&gt;
  
  
  The same account, two catalogs, three weeks apart
&lt;/h2&gt;

&lt;p&gt;In October I wrote in my own notes that the Zoom toolkit had no tool to list meetings and that its recording tools were all deletes. That note shaped how I answered questions about meetings for a month.&lt;/p&gt;

&lt;p&gt;Today the same connection lists 109 tools, and fifteen slugs match &lt;code&gt;MEETING|RECORDING|TRANSCRIPT&lt;/code&gt;, among them &lt;code&gt;ZOOM_LIST_MEETINGS&lt;/code&gt;, &lt;code&gt;ZOOM_GET_A_MEETING&lt;/code&gt;, &lt;code&gt;ZOOM_GET_MEETING_RECORDINGS&lt;/code&gt;, &lt;code&gt;ZOOM_LIST_ALL_RECORDINGS&lt;/code&gt; and &lt;code&gt;ZOOM_GET_A_MEETING_SUMMARY&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The tool definition reports &lt;code&gt;version: 20261111_00&lt;/code&gt;, a date inside the schema itself. I cannot tell from here whether the platform added these tools in November or whether my October reading was wrong. Both explanations end in the same place: the note I had been quoting was stale, and I had been answering from memory a question that a single command answers in two seconds.&lt;/p&gt;

&lt;p&gt;That is the real cost of a capability audit done once. A catalog of forty thousand tools across a thousand toolkits moves, and a note about it decays from the day it is written.&lt;/p&gt;

&lt;h2&gt;
  
  
  A call that succeeds and returns zero rows
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;ZOOM_LIST_MEETINGS&lt;/code&gt; requires &lt;code&gt;user_id&lt;/code&gt;. My first attempt sent &lt;code&gt;userId&lt;/code&gt;, camel case, out of habit, and the platform answered:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"successful"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="nl"&gt;"error"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Input validation failed for ZOOM_LIST_MEETINGS.\n- &amp;lt;root&amp;gt;: Unknown key \"userId\". Use \"user_id\" instead. Allowed top-level keys: to, from, type, user_id, timezone, page_size, page_number, next_page_token"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="nl"&gt;"slug"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"ZOOM_LIST_MEETINGS"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Useful message, exit code 0. With the right key the call ran:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"successful"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="nl"&gt;"data"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"meetings"&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="nl"&gt;"next_page_token"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"page_size"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"total_records"&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Zero meetings. That response is also what a broken connection would return, minus the word &lt;code&gt;successful&lt;/code&gt;, and the two are separated by context rather than by the payload: the account is a free one with nothing scheduled, so zero is the correct number. Google Meet and Google Photos behave the same way on this account. A successful call with an empty list is an absence of data, and reporting it as "the integration works" is only accurate if the account is known to have data to show.&lt;/p&gt;

&lt;h2&gt;
  
  
  The audit I run before answering a capability question
&lt;/h2&gt;

&lt;p&gt;Three checks, in this order, and all three come from commands rather than memory:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Is the toolkit in &lt;code&gt;connections list&lt;/code&gt; with &lt;code&gt;status: ACTIVE&lt;/code&gt; today?&lt;/li&gt;
&lt;li&gt;Does &lt;code&gt;tools list &amp;lt;toolkit&amp;gt;&lt;/code&gt; return a non-empty list for it?&lt;/li&gt;
&lt;li&gt;Does any slug in that list match the verb the task needs?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If any of the three fails, the answer is no, with the specific reason. If the third one is ambiguous because the tool exists and I have never called it, the answer is "the tool exists and I have not run it", which is a different sentence from yes and the one I should have been using all along.&lt;/p&gt;

&lt;p&gt;The script that produces all of this runs in about a minute for twenty toolkits and writes a JSON file I can diff against the previous run. The diff is the part with the most value, because it turns "I think this works" into a date.&lt;/p&gt;




&lt;p&gt;Se você também liga várias APIs atrás de uma camada só, vale rodar essa contagem de estado e de verbos antes de prometer qualquer coisa: conexão verde e ferramenta existente são coisas diferentes. Se quiser, comento em português como montei o script e o que ele já pegou de errado.&lt;/p&gt;

</description>
      <category>api</category>
      <category>testing</category>
      <category>tooling</category>
      <category>productivity</category>
    </item>
    <item>
      <title>My deploy script commits before it verifies, and the site serves that directory</title>
      <dc:creator>Jonas Francisco de Lima Filho</dc:creator>
      <pubDate>Fri, 13 Nov 2026 20:14:06 +0000</pubDate>
      <link>https://dev.to/jonasfilhodev/my-deploy-script-commits-before-it-verifies-and-the-site-serves-that-directory-27k8</link>
      <guid>https://dev.to/jonasfilhodev/my-deploy-script-commits-before-it-verifies-and-the-site-serves-that-directory-27k8</guid>
      <description>&lt;p&gt;Most of my projects are small enough that a build pipeline would be more moving parts than the project itself. One of them is a static operations dashboard served by nginx from a single directory, and that directory is also the git checkout. There is no release step and no copy into place, which changes what the word deploy means.&lt;/p&gt;

&lt;h2&gt;
  
  
  The document root is the worktree
&lt;/h2&gt;

&lt;p&gt;nginx reads the site from the checkout itself:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight nginx"&gt;&lt;code&gt;&lt;span class="n"&gt;server_name&lt;/span&gt; &lt;span class="n"&gt;agentjj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;br&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;root&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;www&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;central_operacoes&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That path is a working tree with a branch, a remote and 645 commits of history, and nginx serves whatever is on disk at the moment of the request. I edit a file, refresh the page, and the change is live for whoever has the password. The deploy script does not move files into place, because they are already there. It proves that what is on disk behaves, and then records it in git.&lt;/p&gt;

&lt;p&gt;CSS, JavaScript and JSON come back with &lt;code&gt;no-cache&lt;/code&gt;, images with &lt;code&gt;max-age=31536000&lt;/code&gt; and &lt;code&gt;immutable&lt;/code&gt;, and the HTML references its assets as &lt;code&gt;?v=&amp;lt;short sha&amp;gt;&lt;/code&gt;, rewritten on every commit. An immutable image URL is only safe when a changed image gets a new URL.&lt;/p&gt;

&lt;h2&gt;
  
  
  Steps one and four are the point
&lt;/h2&gt;

&lt;p&gt;The script prints five steps in order. The commit comes first and the push comes last:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"==&amp;gt; 1/5 commit"&lt;/span&gt;
git add -A
&lt;span class="c"&gt;# step 2/5 rewrites the asset tag in index.html&lt;/span&gt;

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"==&amp;gt; 3/5 verificacao local"&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"$fail"&lt;/span&gt; != &lt;span class="s2"&gt;"0"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
  &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"==&amp;gt; verificacao local FALHOU - push cancelado"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;2
  &lt;span class="nb"&gt;exit&lt;/span&gt; 1
&lt;span class="k"&gt;fi&lt;/span&gt;

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"==&amp;gt; 4/5 push"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Read the failure line again. It says push cancelled, not change cancelled. By the time the smoke test runs, the commit exists and the directory has been serving it for the whole duration of the test. A failed verification leaves two states at once: the site is on the new version and &lt;code&gt;origin/master&lt;/code&gt; is on the old one. They cost different things, so the useful move after a failure is to measure the distance instead of deciding whether the work was lost.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git rev-list --count origin/master..HEAD   &lt;span class="c"&gt;# commits not pushed&lt;/span&gt;
git status --porcelain                     &lt;span class="c"&gt;# is the tree clean?&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A number above zero means the site is serving something GitHub has never seen, one command away from fine, but only if you know which state you are in. The order still earns its place: verifying before push keeps a broken change off the remote. It never protected the server, since the server is the checkout.&lt;/p&gt;

&lt;h2&gt;
  
  
  The check that quietly skipped itself
&lt;/h2&gt;

&lt;p&gt;For a while the verification block had a reasonable-looking branch: when no credential was available, skip the authenticated requests and continue. The script then printed a green result having made zero authenticated requests. The commit that removed that branch carries the reason in its message:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;2ce1b72 feat: exigir credencial no deploy (o SKIP silencioso ja deixou passar deploy sem nenhum teste autenticado)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The replacement refuses to run without a credential and requires an intentional skip to be typed as an input:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt; -z &lt;span class="s2"&gt;"${SITE_AUTH:-}"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; -z &lt;span class="s2"&gt;"${SITE_USER:-}"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"${ALLOW_SKIP_VERIFY:-0}"&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"1"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"    AVISO: verificacao autenticada PULADA (ALLOW_SKIP_VERIFY=1)."&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;2
  &lt;span class="k"&gt;else&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"    FAIL sem credencial para a verificacao autenticada."&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;2
    &lt;span class="nb"&gt;exit&lt;/span&gt; 1
  &lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A gate that can disable itself without saying so is worse than no gate, because it produces exactly the output of a passing one. Whatever can be skipped needs an explicit request, and the skip has to appear in the output where a tired reader will see it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the smoke test asserts besides 200
&lt;/h2&gt;

&lt;p&gt;Each check compares a status code against an expected one, hitting the origin directly so DNS and the CDN stay out of the result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;check&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;local&lt;/span&gt; &lt;span class="nv"&gt;url&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$1"&lt;/span&gt; &lt;span class="nv"&gt;expect&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$2"&lt;/span&gt; &lt;span class="nv"&gt;desc&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$3"&lt;/span&gt;
  &lt;span class="nv"&gt;code&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$(auth_curl -o /dev/null -w '%{http_code}' \
    --resolve "&lt;/span&gt;agentjj.com.br:443:127.0.0.1&lt;span class="s2"&gt;" "&lt;/span&gt;&lt;span class="nv"&gt;${BASE}${url}&lt;/span&gt;&lt;span class="s2"&gt;" || echo 000)"&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"$code"&lt;/span&gt; != &lt;span class="s2"&gt;"$expect"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"    FAIL ${desc} esperado=${expect} obtido=${code}"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;2
    &lt;span class="nv"&gt;fail&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1
  &lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
check &lt;span class="s2"&gt;"/"&lt;/span&gt;                            &lt;span class="s2"&gt;"200"&lt;/span&gt; &lt;span class="s2"&gt;"index"&lt;/span&gt;
check &lt;span class="s2"&gt;"/css/style.css?v=${ASSET_SHA}"&lt;/span&gt; &lt;span class="s2"&gt;"200"&lt;/span&gt; &lt;span class="s2"&gt;"css"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three of the assertions are not about 200, and those catch the real breakage:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;an anonymous request has to answer 401, otherwise basic auth is protecting nothing;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/favicon.ico&lt;/code&gt; and &lt;code&gt;/robots.txt&lt;/code&gt; have to answer 200 without credentials, because the browser fetches both on its own and a 401 there reopens the login prompt after the page already loaded;&lt;/li&gt;
&lt;li&gt;the served HTML must not contain a &lt;code&gt;__PLACEHOLDER__&lt;/code&gt; or a literal &lt;code&gt;$(git ...)&lt;/code&gt;, both render as text in production.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Port 80 taught one more. It used to redirect to HTTPS with a 301, and the browser drops the &lt;code&gt;Authorization&lt;/code&gt; header when the scheme changes, so a request that arrived with the password left without it and the user landed on a 401 page in a loop. The commit that changed it says what happened:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;39c527e fix: serve site on port 80 instead of 301 (auth header was dropped on http-&amp;gt;https)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now port 80 serves the site and enforces the same credential. Measured on the running server today: anonymous returns 401, credentialed returns 200, and &lt;code&gt;/favicon.ico&lt;/code&gt; returns 200 without either.&lt;/p&gt;

&lt;h2&gt;
  
  
  The cache header that identified the wrong password
&lt;/h2&gt;

&lt;p&gt;The last check compares &lt;code&gt;Cache-Control&lt;/code&gt; on two responses, and the diagnosis lives in the comparison:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; grep -q &lt;span class="s1"&gt;'no-store'&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="s2"&gt;"${html_cc:-}"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; grep -q &lt;span class="s1"&gt;'no-cache'&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="s2"&gt;"${css_cc:-}"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
  &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"    OK   politica de cache"&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"$html_cc"&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"no-store"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="s2"&gt;"$css_cc"&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"no-store"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"    FAIL ambos os assets responderam 401.html (no-store) em vez do conteudo."&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;2
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"          Quase sempre e SENHA ERRADA em ~/.site_auth, nao cache."&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;2
  &lt;span class="k"&gt;else&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"    FAIL politica de cache inesperada"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;2
  &lt;span class="k"&gt;fi&lt;/span&gt;
  &lt;span class="nv"&gt;fail&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The HTML should come back with &lt;code&gt;no-cache, no-store, must-revalidate, max-age=0&lt;/code&gt; and the CSS with &lt;code&gt;no-cache&lt;/code&gt;. The error page for 401 is served with &lt;code&gt;no-store&lt;/code&gt; alone. So when both responses carry exactly &lt;code&gt;no-store&lt;/code&gt;, the requests were not served the site, they were served the login error. The first version of this check printed &lt;code&gt;cache policy unexpected&lt;/code&gt; and sent me into the nginx configuration for a problem that was a mistyped password. Measured today on the live server, that is exactly the pair I get.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;git add -A&lt;/code&gt; commits whatever happens to be dirty
&lt;/h2&gt;

&lt;p&gt;Because the root is a worktree, leftover output from an earlier session sits next to the source. The first instruction of the script stages everything:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add -A
&lt;span class="k"&gt;if&lt;/span&gt; git diff --cached --quiet&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
  &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"    nada a commitar - tag de versao preservada"&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;
  git commit -q -m &lt;span class="s2"&gt;"$MSG"&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A build artifact or an experiment left behind by a previous run becomes part of the commit without an extra keystroke. The pre-flight has to happen before the script runs, not inside it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git status --short
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If anything in that output is not yours, decide about it before staging, because afterwards the commit is one block and the two origins are no longer separable. The repository also needs a &lt;code&gt;.gitignore&lt;/code&gt; covering interpreter cache and the credential file before the first &lt;code&gt;add -A&lt;/code&gt;, or bytecode and a password end up in the history. Mine ignores &lt;code&gt;__pycache__/&lt;/code&gt;, &lt;code&gt;*.py[cod]&lt;/code&gt; and &lt;code&gt;.site_auth&lt;/code&gt;, and the deploy reads the credential from &lt;code&gt;~/.site_auth&lt;/code&gt; with mode 600 outside the repository, refusing to continue if the mode is anything else.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I would carry to the next project
&lt;/h2&gt;

&lt;p&gt;Serving production from the checkout removes the gap between what I tested and what the user opens. The discipline is short:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Keep the credential out of the tree and let the script refuse to run without it.&lt;/li&gt;
&lt;li&gt;Make every skip an explicit input, and print what was not tested.&lt;/li&gt;
&lt;li&gt;Assert the negative case, an anonymous 401, not only the positive one.&lt;/li&gt;
&lt;li&gt;Compare pairs of headers instead of trusting one value.&lt;/li&gt;
&lt;li&gt;After a failed deploy, measure the distance to &lt;code&gt;origin&lt;/code&gt; before saying anything was lost.&lt;/li&gt;
&lt;li&gt;Check &lt;code&gt;git status --short&lt;/code&gt; before staging everything.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;None of that is specific to nginx or bash. It comes from one property: when the thing serving the files is the thing you edit, the filesystem is the moment of truth.&lt;/p&gt;

&lt;p&gt;Se você mantém um projeto pequeno em produção e passa por algo parecido, comenta aí como resolveu o seu caso. Sempre aparece uma peça que eu não tinha considerado, e é disso que este texto se alimenta.&lt;/p&gt;

</description>
      <category>nginx</category>
      <category>devops</category>
      <category>git</category>
      <category>deployment</category>
    </item>
    <item>
      <title>One add_header in a location deletes every header above it</title>
      <dc:creator>Jonas Francisco de Lima Filho</dc:creator>
      <pubDate>Wed, 11 Nov 2026 20:07:58 +0000</pubDate>
      <link>https://dev.to/jonasfilhodev/one-addheader-in-a-location-deletes-every-header-above-it-2h10</link>
      <guid>https://dev.to/jonasfilhodev/one-addheader-in-a-location-deletes-every-header-above-it-2h10</guid>
      <description>&lt;h2&gt;
  
  
  Two paths, one config file, different headers
&lt;/h2&gt;

&lt;p&gt;I run a small portal behind nginx on a single VPS. I check that it works by opening the page, which is why a header problem lived there for weeks without me noticing it.&lt;/p&gt;

&lt;p&gt;When I finally compared response headers with curl, the root page returned six of them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;frame&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;SAMEORIGIN&lt;/span&gt;
&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="k"&gt;type&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;nosniff&lt;/span&gt;
&lt;span class="na"&gt;x-xss-protection: 1; mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;block&lt;/span&gt;
&lt;span class="n"&gt;referrer&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;policy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;strict&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;origin&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;when&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;cross&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;origin&lt;/span&gt;
&lt;span class="na"&gt;permissions-policy: camera&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;microphone&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;geolocation&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="na"&gt;strict-transport-security: max-age&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;31536000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;includeSubDomains&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The health endpoint on the same server returned none. Neither did &lt;code&gt;/robots.txt&lt;/code&gt;, &lt;code&gt;/favicon.ico&lt;/code&gt;, the 401 error page, or two preview folders I publish for clients. Same server block, same file, same nginx 1.24.0. The config reads as if the headers apply everywhere, because they are written once at the &lt;code&gt;server&lt;/code&gt; level and nothing in those locations removes them.&lt;/p&gt;

&lt;h2&gt;
  
  
  add_header appends inside a level and replaces across levels
&lt;/h2&gt;

&lt;p&gt;I stopped guessing and built a throwaway config on port 8099 to see the behaviour in isolation. The server level sets two headers, and each location does one small variation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight nginx"&gt;&lt;code&gt;&lt;span class="n"&gt;server&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;listen&lt;/span&gt; &lt;span class="mf"&gt;127.0&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mf"&gt;0.1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;8099&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="n"&gt;add_header&lt;/span&gt; &lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Parent&lt;/span&gt; &lt;span class="s2"&gt;"from-server"&lt;/span&gt; &lt;span class="n"&gt;always&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;add_header&lt;/span&gt; &lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Shared&lt;/span&gt; &lt;span class="s2"&gt;"from-server"&lt;/span&gt; &lt;span class="n"&gt;always&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="na"&gt;location&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;inherit&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt; &lt;span class="s2"&gt;"inherit\n"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="na"&gt;location&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;override&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;add_header&lt;/span&gt; &lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Child&lt;/span&gt; &lt;span class="s2"&gt;"from-location"&lt;/span&gt; &lt;span class="n"&gt;always&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt; &lt;span class="s2"&gt;"override\n"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="na"&gt;location&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;same&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;add_header&lt;/span&gt; &lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Shared&lt;/span&gt; &lt;span class="s2"&gt;"from-location"&lt;/span&gt; &lt;span class="n"&gt;always&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt; &lt;span class="s2"&gt;"same-name\n"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The responses, with the boring lines removed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;### /inherit
X-Parent: from-server
X-Shared: from-server

### /override
X-Child: from-location

### /same-name
X-Shared: from-location
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;/override&lt;/code&gt; adds one header and loses both inherited ones. &lt;code&gt;/same-name&lt;/code&gt; does not merge the two values into &lt;code&gt;from-server, from-location&lt;/code&gt;, because the parent set was already discarded: the child value is the only one on the wire.&lt;/p&gt;

&lt;p&gt;That is the whole rule, and it has two clauses that pull in opposite directions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;inside the same level, &lt;code&gt;add_header&lt;/code&gt; appends and never deduplicates;&lt;/li&gt;
&lt;li&gt;across levels, the child does not append to the parent. If the child declares any &lt;code&gt;add_header&lt;/code&gt; at all, the parent's entire set is dropped.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The nginx documentation states this in the &lt;code&gt;add_header&lt;/code&gt; section, in one sentence that is easy to read past: these directives are inherited from the previous configuration level if and only if there are no &lt;code&gt;add_header&lt;/code&gt; directives defined on the current level.&lt;/p&gt;

&lt;h2&gt;
  
  
  The trap is that cache settings are add_header too
&lt;/h2&gt;

&lt;p&gt;My locations did not look like they were touching security. They were setting cache policy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight nginx"&gt;&lt;code&gt;&lt;span class="n"&gt;location&lt;/span&gt; &lt;span class="o"&gt;~*&lt;/span&gt; \&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;jpg&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;jpeg&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;png&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;gif&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;webp&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;avif&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;ico&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;svg&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;woff&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;woff2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;$ &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;add_header&lt;/span&gt; &lt;span class="nc"&gt;Cache&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Control&lt;/span&gt; &lt;span class="s2"&gt;"public, max-age=31536000, immutable"&lt;/span&gt; &lt;span class="n"&gt;always&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;add_header&lt;/span&gt; &lt;span class="nc"&gt;Expires&lt;/span&gt; &lt;span class="s2"&gt;"31536000"&lt;/span&gt; &lt;span class="n"&gt;always&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;etag&lt;/span&gt; &lt;span class="n"&gt;on&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;access_log&lt;/span&gt; &lt;span class="n"&gt;off&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;expires&lt;/span&gt; &lt;span class="mi"&gt;1y&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;Three &lt;code&gt;add_header&lt;/code&gt; lines for caching, and the six security headers from the server level are gone for every image on the site. The pages a browser fetches on its own, favicon and robots, lost them the same way. So did the 401 page that nginx generates when basic auth rejects a request, which is the first response some visitors ever see.&lt;/p&gt;

&lt;p&gt;Here is the part that makes this expensive to find: the missing headers produce no error, no log line, and no visible symptom. Everything renders. A scanner that reads only the root page reports six good headers and passes.&lt;/p&gt;

&lt;h2&gt;
  
  
  The other direction: duplicated headers on the wire
&lt;/h2&gt;

&lt;p&gt;While measuring, I found the opposite defect in the same config, and this one is visible in the output of any image request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="n"&gt;expires&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Thu&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;11&lt;/span&gt; &lt;span class="nc"&gt;Nov&lt;/span&gt; &lt;span class="mi"&gt;2027&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;02&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;17&lt;/span&gt; &lt;span class="no"&gt;GMT&lt;/span&gt;
&lt;span class="na"&gt;cache-control: max-age&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;31536000&lt;/span&gt;
&lt;span class="na"&gt;cache-control: public, max-age&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;31536000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;immutable&lt;/span&gt;
&lt;span class="n"&gt;expires&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;31536000&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two &lt;code&gt;Cache-Control&lt;/code&gt; headers and two &lt;code&gt;Expires&lt;/code&gt; headers on one response. The first pair comes from the &lt;code&gt;expires 1y&lt;/code&gt; directive, which writes its own header values. The second comes from my &lt;code&gt;add_header&lt;/code&gt; lines. nginx appends both, because appending is what it does inside a level.&lt;/p&gt;

&lt;p&gt;Two headers with the same name are legal HTTP and ambiguous for the client. Which one a proxy or browser honours depends on the implementation, so &lt;code&gt;immutable&lt;/code&gt; may be ignored, or the invalid &lt;code&gt;Expires: 31536000&lt;/code&gt; may be the value that wins. An invalid date in an Expires header has no defined meaning, and browsers have historically treated it as "expire now".&lt;/p&gt;

&lt;p&gt;The same append behaviour shows up on the health endpoint, which sends two &lt;code&gt;Content-Type&lt;/code&gt; lines at the origin:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="no"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;1.1&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt; &lt;span class="no"&gt;OK&lt;/span&gt;
&lt;span class="nc"&gt;Content&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;application&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;octet&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;stream&lt;/span&gt;
&lt;span class="nc"&gt;Content&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;
&lt;span class="nc"&gt;Content&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;plain&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first comes from &lt;code&gt;return 200 "healthy\n"&lt;/code&gt;, the second from &lt;code&gt;add_header Content-Type text/plain&lt;/code&gt;. It happens to work, because most clients take the last value, and Cloudflare compresses the pair into a single &lt;code&gt;content-type: text/plain&lt;/code&gt; before the response reaches a browser. That makes the defect invisible from outside and still present on the origin, which is why I check with &lt;code&gt;--resolve&lt;/code&gt; against 127.0.0.1 instead of trusting what the public URL shows.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix that survives a new location
&lt;/h2&gt;

&lt;p&gt;Repeating six &lt;code&gt;add_header&lt;/code&gt; lines in every location is a maintenance problem, and the day someone adds a location without them the hole reopens. A single snippet does the job:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight nginx"&gt;&lt;code&gt;&lt;span class="c1"&gt;# /etc/nginx/snippets/security_headers.conf
&lt;/span&gt;&lt;span class="n"&gt;add_header&lt;/span&gt; &lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Frame&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Options&lt;/span&gt; &lt;span class="s2"&gt;"SAMEORIGIN"&lt;/span&gt; &lt;span class="n"&gt;always&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;add_header&lt;/span&gt; &lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Content&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Type&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Options&lt;/span&gt; &lt;span class="s2"&gt;"nosniff"&lt;/span&gt; &lt;span class="n"&gt;always&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;add_header&lt;/span&gt; &lt;span class="nc"&gt;Referrer&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Policy&lt;/span&gt; &lt;span class="s2"&gt;"strict-origin-when-cross-origin"&lt;/span&gt; &lt;span class="n"&gt;always&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;add_header&lt;/span&gt; &lt;span class="nc"&gt;Permissions&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Policy&lt;/span&gt; &lt;span class="s2"&gt;"camera=(), microphone=(), geolocation=()"&lt;/span&gt; &lt;span class="n"&gt;always&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;add_header&lt;/span&gt; &lt;span class="nc"&gt;Strict&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Transport&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Security&lt;/span&gt; &lt;span class="s2"&gt;"max-age=31536000; includeSubDomains"&lt;/span&gt; &lt;span class="n"&gt;always&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and every location that declares its own &lt;code&gt;add_header&lt;/code&gt; includes it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight nginx"&gt;&lt;code&gt;&lt;span class="n"&gt;location&lt;/span&gt; &lt;span class="o"&gt;~*&lt;/span&gt; \&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;jpg&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;jpeg&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;png&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;gif&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;webp&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;avif&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;ico&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;svg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;$ &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;add_header&lt;/span&gt; &lt;span class="nc"&gt;Cache&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Control&lt;/span&gt; &lt;span class="s2"&gt;"public, max-age=31536000, immutable"&lt;/span&gt; &lt;span class="n"&gt;always&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;include&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;etc&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;nginx&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;snippets&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;security_headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;conf&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;expires&lt;/span&gt; &lt;span class="mi"&gt;1y&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;Two details in there matter. The &lt;code&gt;always&lt;/code&gt; parameter makes the header apply to error responses as well, without it a 404 or a 500 ships without the set. And the &lt;code&gt;expires&lt;/code&gt; directive should be removed whenever &lt;code&gt;Cache-Control&lt;/code&gt; is written by hand, since leaving both is what produced the duplicated headers above.&lt;/p&gt;

&lt;h2&gt;
  
  
  The check that would have caught it
&lt;/h2&gt;

&lt;p&gt;Reading the config file does not answer this question. The answer comes from the responses, one per location, with the required header names counted:&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="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;subprocess&lt;/span&gt;

&lt;span class="no"&gt;HOST&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"example.com"&lt;/span&gt;
&lt;span class="no"&gt;REQUIRED&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s2"&gt;"strict-transport-security"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"x-frame-options"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"x-content-type-options"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"referrer-policy"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="no"&gt;PATHS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"/health"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"/robots.txt"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"/favicon.ico"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"/401.html"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
         &lt;span class="s2"&gt;"/css/style.css"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"/data/index.json"&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;path&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;PATHS&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;subprocess&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;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"curl"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"-s"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"-o"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"/dev/null"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"-D"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"-"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"--resolve"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
         &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{HOST}:443:127.0.0.1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"https://{HOST}{path}"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;capture_output&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;check&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&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;stdout&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;counted&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;count&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"\n{name}:"&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;name&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;REQUIRED&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;missing&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;counted&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;n&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="n"&gt;duplicated&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"{name} x{counted[name]}"&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;counted&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

    &lt;span class="k"&gt;print&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="s2"&gt;"missing:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;missing&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="s2"&gt;"none"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"duplicated:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;duplicated&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="s2"&gt;"none"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;n != 1&lt;/code&gt; comparison is deliberate. Counting only for presence accepts the duplicated case, which is the second half of the problem. Pointing curl at 127.0.0.1 keeps the CDN out of the measurement, because a CDN can add a header that the origin never sent and collapse a duplicate that the origin did send.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is still wrong in my own config
&lt;/h2&gt;

&lt;p&gt;The snippet is in place for the locations that serve the site, and the four short paths and two preview folders still have no security headers. I know which lines to add and the change is small. The reason I trust the list is that the check above produced it from live responses instead of from my reading of the file.&lt;/p&gt;

&lt;p&gt;There is one more honest limit: HSTS on a domain that is already HTTPS-only changes little, and &lt;code&gt;X-XSS-Protection&lt;/code&gt; is obsolete in current browsers. The headers that still do work are &lt;code&gt;X-Content-Type-Options&lt;/code&gt;, &lt;code&gt;Referrer-Policy&lt;/code&gt;, &lt;code&gt;Permissions-Policy&lt;/code&gt; and the frame policy. The value of the exercise was not the six headers. It was finding out that a cache setting, written three lines below them, could turn them off on most of the site without a single symptom.&lt;/p&gt;

&lt;p&gt;Se esse tipo de armadilha já te pegou, comenta aí qual foi o teu caso. Eu coleciono esses, porque cada um deles me poupou um deploy depois. Se você mantém nginx em produção, vale rodar a checagem acima hoje: são sete URLs e trinta segundos.&lt;/p&gt;

</description>
      <category>nginx</category>
      <category>webdev</category>
      <category>devops</category>
      <category>http</category>
    </item>
    <item>
      <title>My screenshot was 1080x1350. The page was 1722 pixels tall.</title>
      <dc:creator>Jonas Francisco de Lima Filho</dc:creator>
      <pubDate>Mon, 09 Nov 2026 20:07:20 +0000</pubDate>
      <link>https://dev.to/jonasfilhodev/my-screenshot-was-1080x1350-the-page-was-1722-pixels-tall-57c2</link>
      <guid>https://dev.to/jonasfilhodev/my-screenshot-was-1080x1350-the-page-was-1722-pixels-tall-57c2</guid>
      <description>&lt;p&gt;A piece of artwork went live last month without the contact line at the bottom. Phone, handle and site were in the HTML, the CSS placed them, the browser laid them out, and the file that got published did not contain them. Three checks ran before publishing, and all three passed.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the check asked
&lt;/h2&gt;

&lt;p&gt;The pipeline was short: render a local HTML file, screenshot it, verify it. Verification asked two questions. Is the image 1080 by 1350? It is. Does each element sit inside its own box, with no overlap and no text against the edge? Yes.&lt;/p&gt;

&lt;p&gt;Nobody asked whether the file contained the whole page. The image had the dimensions from the request, and the layout assertions had run against a live DOM whose document was 1722 pixels tall.&lt;/p&gt;

&lt;h2&gt;
  
  
  A screenshot request describes a rectangle
&lt;/h2&gt;

&lt;p&gt;I rebuilt the case with a minimal page: one flex column, 1080 wide, 90 pixels of lateral padding, nine paragraphs and a footer with a 3px rule above it. The design height was 1350. The content did not fit, and a flex column grows instead of overflowing, so the document ended at 1722. Nothing in the CSS was wrong. A page can be taller than the box you drew for it.&lt;/p&gt;

&lt;p&gt;Measuring before capturing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;documentElement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;scrollHeight&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;viewport&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHeight&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;footer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.rodape&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;getBoundingClientRect&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;bottom&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;Output on that page:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"doc"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;1722&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"viewport"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;1350&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"footer"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;1652&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The class is &lt;code&gt;rodape&lt;/code&gt;, footer in Portuguese, because the test page came out of a Portuguese pipeline.&lt;/p&gt;

&lt;p&gt;The footer bottom sits at 1652. Its rule, the three pixels that separate contact data from the body, sits at y=1590. The document was 372 pixels taller than the box in the request.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two files with the right size and the same missing block
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;chrome --headless=new --screenshot --window-size=1080,1350&lt;/code&gt; produced a 1080 by 1350 PNG. Last row containing ink: y=1262. Everything from 1262 down is white, 87 pixels of it, which reads as bottom padding. The rule at 1590 is absent, the footer is absent.&lt;/p&gt;

&lt;p&gt;The same page captured over CDP at exactly 1080 by 1350 produced another 1080 by 1350 PNG. Last row with ink: 1349, zero white. The footer is absent too, and this file carries no visual hint of loss, because the crop lands in the middle of a paragraph and the image looks full bleed.&lt;/p&gt;

&lt;p&gt;Two files, identical dimensions, identical gap, different reasons to believe nothing is wrong. The first looks like a design with breathing room. The second looks finished.&lt;/p&gt;

&lt;h2&gt;
  
  
  The size check was comparing the request to itself
&lt;/h2&gt;

&lt;p&gt;The verification read the PNG dimensions and compared them to the constant it had passed in. Both numbers came from the same place, so the check could only fail if the image library were broken. The layout assertions had a similar problem: they read &lt;code&gt;getBoundingClientRect()&lt;/code&gt; from a 1722 pixel document and confirmed each box sat where the CSS said. They were right about the layout and silent about the file.&lt;/p&gt;

&lt;p&gt;A check is worth something when its reference comes from outside the thing being checked. Here the reference had to be the document height, read after layout and before capture.&lt;/p&gt;

&lt;h2&gt;
  
  
  Capture at the height you measured
&lt;/h2&gt;

&lt;p&gt;Two changes fixed it, and neither is about the tool.&lt;/p&gt;

&lt;p&gt;First, read &lt;code&gt;scrollHeight&lt;/code&gt; after the load and pass that number to the capture. Second, assert that the element you care about is inside the captured box, using its own coordinates:&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="n"&gt;altura&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;doc&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;footer&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;altura&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;footer fora da captura: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;footer&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; &amp;gt; &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;altura&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With 1722 passed in, the full page came back: last row with ink 1650, 71 pixels of white under it, the 3px rule at 1590, contact line present. The same request through the CLI at 1722 also worked, which puts the bug in the number rather than in the binary.&lt;/p&gt;

&lt;p&gt;That detail matters for the diagnosis. I had blamed the tool for months.&lt;/p&gt;

&lt;h2&gt;
  
  
  What CDP adds, and the two details that bite
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;Emulation.setDeviceMetricsOverride&lt;/code&gt; fixes the viewport at the exact size of the piece before navigation, so the page lays out against the box you intend instead of the default window. &lt;code&gt;Page.captureScreenshot&lt;/code&gt; with &lt;code&gt;captureBeyondViewport: true&lt;/code&gt; returns the whole document, including what sits under the fold.&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="nf"&gt;ws_envia&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&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;id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;method&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;Emulation.setDeviceMetricsOverride&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;params&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;width&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;height&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;deviceScaleFactor&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;mobile&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;}})&lt;/span&gt;
&lt;span class="nf"&gt;ws_envia&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&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;id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;method&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;Page.captureScreenshot&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;params&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;format&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;png&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;captureBeyondViewport&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;}})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because the capture can exceed the requested size, my script crops it back:&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="nf"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;aw&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ah&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="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;im&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;crop&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="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;png&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;print&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;recortado de &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;aw&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;x&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;ah&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; para &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;x&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;h&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Today that line printed &lt;code&gt;recortado de 1080x1722 para 1080x1350&lt;/code&gt;. It is a failure message wearing an informational tone, and the crop it reports is exactly what removed the footer. A shrink deserves an exception, not a print.&lt;/p&gt;

&lt;p&gt;The second detail is the debugging port. Two captures on the same port collide, because the previous Chrome has not released the socket yet (TIME_WAIT) and the second connection fails with an error that says nothing about ports. Deriving the port from the pid removed it: &lt;code&gt;porta = 9401 + (os.getpid() % 400)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;One more, measured twice today: &lt;code&gt;--screenshot&lt;/code&gt; clips at the window height instead of stretching the image. My own script's docstring said it stretched. Rulers drawn at y=200, 600 and 1000 landed on those exact rows in both tools, and a ruler at 1800 did not appear at all in the CLI output, which is a crop and not a rescale. The fix worked while the explanation was wrong, and that is a reason to re-measure your own comments.&lt;/p&gt;

&lt;h2&gt;
  
  
  The shape of this bug
&lt;/h2&gt;

&lt;p&gt;Every version of it looks the same: an artifact carries the coordinate system of the request, and the check reads coordinates from the request. Image dimension against requested dimension. Body length against expected length. Row count against the count in the config.&lt;/p&gt;

&lt;p&gt;The cheapest defence is one independent reading per artifact, taken from the source that produced it: &lt;code&gt;scrollHeight&lt;/code&gt; for a page, the element rectangle for a component, the actual byte length for a payload. It costs a line of code and it fails loudly, which is what the three green checks were missing.&lt;/p&gt;

&lt;p&gt;Measured on Chromium 145.0.7632.0, headless=new, one machine, November 2026. The clipping behaviour of &lt;code&gt;--screenshot&lt;/code&gt; has changed between versions, so pin your own numbers before quoting mine.&lt;/p&gt;

&lt;p&gt;Se o seu pipeline também publica imagem sem conferir se o rodapé entrou no arquivo, comenta aqui embaixo o que a sua verificação mede. Aprendo mais com o caso dos outros do que com o meu, e respondo todo mundo.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>testing</category>
      <category>python</category>
      <category>css</category>
    </item>
    <item>
      <title>Half of my corrupted text was pure ASCII, and my character check passed it</title>
      <dc:creator>Jonas Francisco de Lima Filho</dc:creator>
      <pubDate>Fri, 06 Nov 2026 20:29:13 +0000</pubDate>
      <link>https://dev.to/jonasfilhodev/half-of-my-corrupted-text-was-pure-ascii-and-my-character-check-passed-it-2kbo</link>
      <guid>https://dev.to/jonasfilhodev/half-of-my-corrupted-text-was-pure-ascii-and-my-character-check-passed-it-2kbo</guid>
      <description>&lt;p&gt;I generate long documents as files and publish them with a script: reports, proposals, article bodies. The publisher never reads the sentences. It checks that the media paths exist and that the body is not empty, then puts the page live.&lt;/p&gt;

&lt;p&gt;That gap is where two different text corruptions survived for weeks. One of them is invisible to the check most people write first.&lt;/p&gt;

&lt;h2&gt;
  
  
  The defect that looks like damage
&lt;/h2&gt;

&lt;p&gt;The first time, a file came back with words fused together. &lt;code&gt;marinhoprofundo&lt;/code&gt; where two words belonged, &lt;code&gt;branco,.grid&lt;/code&gt; where a table header used to be. In the same document, a stretch of characters from no Latin alphabet sat in the middle of a sentence.&lt;/p&gt;

&lt;p&gt;This form announces itself. You scan the file, see the damage, and fix the source.&lt;/p&gt;

&lt;p&gt;The cause was not the publisher. It was the tool that wrote the file. Long text with accents and punctuation passes through it in chunks, and occasionally a chunk returns with pieces glued or replaced. By then the publisher had already accepted the file, the validator had passed it, and the card was live with the broken text.&lt;/p&gt;

&lt;h2&gt;
  
  
  The defect that looks clean
&lt;/h2&gt;

&lt;p&gt;The second form does not look like damage, because every byte in it is seven-bit ASCII.&lt;/p&gt;

&lt;p&gt;I found three cases in my own documents. A list item read &lt;code&gt;agendamento, CRM,|Issue tracker&lt;/code&gt;: a comma jammed against a pipe, and an English label right after it. Another line read &lt;code&gt;Três Interactions&lt;/code&gt;, a Portuguese word followed by the English one. A third read &lt;code&gt;e é priced como tal&lt;/code&gt;, an English verb inside a Portuguese sentence.&lt;/p&gt;

&lt;p&gt;Run this against those three lines:&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;re&lt;/span&gt;
&lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findall&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[^\x00-\x7F]&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;texto&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You get an empty list. Nothing sits outside the ASCII range, so any check built on unusual characters returns clean on a document a reader will notice in the first paragraph. The defect is lexical, and no character class catches a wrong word.&lt;/p&gt;

&lt;h2&gt;
  
  
  Nothing downstream complains
&lt;/h2&gt;

&lt;p&gt;The publishing CLI does not parse prose. My validator compares the manifest against the publication JSON, which means it compares media counts, body length and ids. Both sides agreed, because both were describing structure.&lt;/p&gt;

&lt;p&gt;A structural check cannot see that a sentence contains the wrong language. It can only tell you the sentence exists.&lt;/p&gt;

&lt;p&gt;That is why the gate has to inspect the text itself, in the step before publishing, and not the record after it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three checks in one file
&lt;/h2&gt;

&lt;p&gt;The gate I use is a single Python file, run before the publish command. It exits 1 on any defect, so it chains with &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; and the publish never runs on a bad source.&lt;/p&gt;

&lt;p&gt;These are the checks, abridged from the real file:&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="n"&gt;OK&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&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="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;ESTRANGEIRAS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;compile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;\b(issue|tracker|interactions|priced|checklist|starter)\b&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;I&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;PIPE_PROSA&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;compile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;\S\|\S&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pathlib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]).&lt;/span&gt;&lt;span class="nf"&gt;read_text&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;prosa&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;r&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="p"&gt;,&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="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;flags&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;S&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;defeitos&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;

&lt;span class="n"&gt;estranhos&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;sorted&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findall&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;[^\x00-\x7F]&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;t&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;c&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;OK&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;estranhos&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;defeitos&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&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;caracteres corrompidos: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;estranhos&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="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;ESTRANGEIRAS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prosa&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;defeitos&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;palavra de outro idioma no meio da prosa&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;PIPE_PROSA&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prosa&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="nf"&gt;_tem_tabela&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prosa&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;defeitos&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;pipe no meio da prosa&lt;/span&gt;&lt;span class="sh"&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 first check handles the visible form. It collects every non-ASCII character and compares against the set of accented letters and punctuation that belong in Portuguese.&lt;/p&gt;

&lt;p&gt;The second check handles the invisible form. It is a short list of English words that showed up glued into my prose. The list stays short on purpose. Terms that Brazilian tech writing uses legitimately, such as bot, lead, setup, dashboard, status and deploy, are not on it. A gate that cries wolf gets ignored, and the ignoring generalizes to the checks that work.&lt;/p&gt;

&lt;p&gt;The third check uses a punctuation mark as evidence. A pipe is a table separator in markdown and never appears inside running prose. When one appeared mid-sentence, it marked the exact span where the text had been spliced.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two guards that keep the gate trusted
&lt;/h2&gt;

&lt;p&gt;A checker is only useful while you believe its output, so both guards here exist to remove false positives.&lt;/p&gt;

&lt;p&gt;The first strips fenced code blocks before the prose checks. An ffmpeg filter containing &lt;code&gt;adelay=0|0&lt;/code&gt; is correct syntax and failed the pipe check, which taught me to skim past failures. The character check still runs over the entire text, code included, because corruption inside a code block is a defect too.&lt;/p&gt;

&lt;p&gt;The second detects a legitimate markdown table by looking for a separator line such as &lt;code&gt;---|---&lt;/code&gt; under a line with pipes. Without it, a real table with pipes in its cells fails the gate for being what it is.&lt;/p&gt;

&lt;p&gt;The allowed character set was tuned the same way. A correct text containing &lt;code&gt;±&lt;/code&gt; and &lt;code&gt;→&lt;/code&gt; failed as corrupted on a measurement article about color. Those symbols have no place in a Portuguese document, so the fix was to write "35 degrees to each side" and a colon instead of an arrow. When a checker flags correct text, either the checker changes or the style does, and pretending it was fine is how the whole gate loses credibility.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where the damage is born
&lt;/h2&gt;

&lt;p&gt;The gate runs on the source file, before publishing. Correcting the JSON afterwards costs a second deploy, and until that deploy the card sits live with the wrong text. One full cycle of that was enough to make the ordering permanent.&lt;/p&gt;

&lt;p&gt;Two practices came out of the same class of defect, where the wrong value is plausible instead of obviously wrong.&lt;/p&gt;

&lt;p&gt;Tables with numbers that leave the house are built from data. I write the rows as a list of tuples, derive the total with &lt;code&gt;sum()&lt;/code&gt;, and assert it against the number typed into the prose. When the assert fails, the column is wrong, and I learn it on my machine instead of in a client conversation.&lt;/p&gt;

&lt;p&gt;Documents that exist in two formats come from one object. A markdown body and a PDF generated from the same structure stay in sync by construction. Two hand-written versions diverge in an accent or a figure, both look readable, and they reach different recipients.&lt;/p&gt;

&lt;h2&gt;
  
  
  Para quem publica em português
&lt;/h2&gt;

&lt;p&gt;Se você gera texto longo com ferramenta e publica por script, um gate de alguns segundos vale mais que reler o arquivo uma vez. A releitura acontece quando você lembra, o gate acontece em toda publicação, e ele acusa o defeito antes de o card ir ao ar. Me conta nos comentários qual foi a corrupção mais estranha que já passou pelo seu pipeline, porque esse tipo de caso raramente aparece documentado.&lt;/p&gt;

</description>
      <category>python</category>
      <category>testing</category>
      <category>tooling</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Six still PNGs, six narration clips, and the ffmpeg pass that keeps them in sync</title>
      <dc:creator>Jonas Francisco de Lima Filho</dc:creator>
      <pubDate>Wed, 04 Nov 2026 20:23:39 +0000</pubDate>
      <link>https://dev.to/jonasfilhodev/six-still-pngs-six-narration-clips-and-the-ffmpeg-pass-that-keeps-them-in-sync-1bg5</link>
      <guid>https://dev.to/jonasfilhodev/six-still-pngs-six-narration-clips-and-the-ffmpeg-pass-that-keeps-them-in-sync-1bg5</guid>
      <description>&lt;h1&gt;
  
  
  Six still PNGs, six narration clips, and the ffmpeg pass that keeps them in sync
&lt;/h1&gt;

&lt;p&gt;A vertical video with narration usually means a timeline editor and someone dragging clips until the words land on the right frame. I had an SSH session on a two-core ARM machine, six PNGs exported at 1080x1920, and ffmpeg.&lt;/p&gt;

&lt;p&gt;The result is a 47.9 second reel: six typographic frames, each with one sentence of Portuguese narration. The pipeline is 103 lines of Python calling ffmpeg as a subprocess, with no dependencies beyond ffmpeg, ffprobe and a TTS CLI. Here is what it does, and which decisions the machine forced.&lt;/p&gt;

&lt;h2&gt;
  
  
  The frames were designed as still images
&lt;/h2&gt;

&lt;p&gt;Every scene is a static frame rendered elsewhere into a PNG at exactly 1080x1920, 8-bit RGB. No animation, no zoom. On a phone held at arm's length, text that moves has to be chased, and each of these frames holds a sentence that the narration finishes in about seven seconds.&lt;/p&gt;

&lt;p&gt;That removes most of the usual complexity: no timeline, no transitions, no partial renders. A scene is one image that stays for a fixed number of seconds, and the only open question is how many.&lt;/p&gt;

&lt;p&gt;The hardware mattered. Two cores, &lt;code&gt;aarch64&lt;/code&gt;, no GPU. libx264 at &lt;code&gt;veryfast&lt;/code&gt; is fine for a slideshow and would not be fine for anything with motion. I measured one segment while writing this: 8.44 seconds of video, 211 frames, 5.8 seconds of wall clock, 38 KB on disk and 32 kb/s, because a still frame has nothing to spend bits on.&lt;/p&gt;

&lt;h2&gt;
  
  
  The narration sets the timing
&lt;/h2&gt;

&lt;p&gt;The obvious approach is to fix five seconds per scene and squeeze the audio to fit, which makes speech sound rushed in one place and padded in another. Doing it the other way is easier: synthesize the narration first, one MP3 per scene, then ask ffprobe how long each file is. That number is the timeline.&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="n"&gt;BASE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/home/ubuntu/hermes_tools/pecas_plano_fde&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;FPS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;
&lt;span class="n"&gt;VOZ&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;pt-BR-AntonioNeural&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;EDGE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/home/ubuntu/hermes_tools/voz/venv/bin/edge-tts&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;dur&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;caminho&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;saida&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;subprocess&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;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ffprobe&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;-v&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;error&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;-show_entries&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;format=duration&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;-of&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;default=noprint_wrappers=1:nokey=1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;caminho&lt;/span&gt;&lt;span class="p"&gt;)],&lt;/span&gt;
        &lt;span class="n"&gt;capture_output&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;text&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;check&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;stdout&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;saida&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The six clips measured 7.944, 7.080, 6.888, 7.392, 7.128 and 8.472 seconds: 98 words in 44.904 seconds of speech, about 131 words per minute in Portuguese at the default rate. Nothing there was estimated. If a sentence grows, its scene grows, and no other scene compensates.&lt;/p&gt;

&lt;p&gt;The narration comes from the &lt;code&gt;edge-tts&lt;/code&gt; CLI in a virtualenv, voice &lt;code&gt;pt-BR-AntonioNeural&lt;/code&gt;, rate &lt;code&gt;+0%&lt;/code&gt;. Separate files instead of one long track is what keeps the rest simple: each one can be measured, replaced and reused on its own.&lt;/p&gt;

&lt;h2&gt;
  
  
  Each frame becomes a clip of its own length
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;enumerate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;duracoes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;start&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="n"&gt;png&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;BASE&lt;/span&gt; &lt;span class="o"&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;reel-cena&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;-1080x1920.png&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="n"&gt;seg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;destino&lt;/span&gt; &lt;span class="o"&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;seg&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;.mp4&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="n"&gt;seg_dur&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;subprocess&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;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ffmpeg&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;-y&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;-loop&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;1&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;-t&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;seg_dur&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;-i&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;png&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;-vf&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;scale=1080:1920:flags=lanczos,format=yuv420p&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;-r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;FPS&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;-c:v&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;libx264&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;-preset&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;veryfast&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;-crf&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;20&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;-pix_fmt&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;yuv420p&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;seg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;check&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;capture_output&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;scale&lt;/code&gt; with &lt;code&gt;lanczos&lt;/code&gt; does nothing on an input already at 1080x1920, and stays in the chain so it survives a frame exported at another size. &lt;code&gt;format=yuv420p&lt;/code&gt; is the pixel format phones decode without argument, and it has to reach the final file. &lt;code&gt;-crf 20&lt;/code&gt; with &lt;code&gt;veryfast&lt;/code&gt; is a compromise for two cores; on a machine with headroom, &lt;code&gt;medium&lt;/code&gt; would shave bytes nobody would notice.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;+ 0.5&lt;/code&gt; is breathing room. Without it the next sentence lands on the exact frame where the previous one ended, and the cut feels clipped even with correct timings.&lt;/p&gt;

&lt;h2&gt;
  
  
  Padding the audio so each line stays with its frame
&lt;/h2&gt;

&lt;p&gt;Concatenating the six MP3s gives 44.9 seconds while the video is 47.9. Muxing those directly means the audio falls behind, and by the fifth scene the voice describes something that left the screen seconds earlier. Padding each narration to the duration of its own segment removes the accumulation.&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="n"&gt;entradas&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;filtros&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;seg_dur&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;enumerate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;segmentos&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;start&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="n"&gt;entradas&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;-i&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;destino&lt;/span&gt; &lt;span class="o"&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;narracao&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;.mp3&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;
    &lt;span class="n"&gt;filtros&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&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;[&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;:a]adelay=0|0,apad=whole_dur=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;seg_dur&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;[a&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&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;concat_in&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="nf"&gt;join&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;[a&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;]&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;segmentos&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
&lt;span class="n"&gt;filtros&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&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="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;concat_in&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;concat=n=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;segmentos&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;:v=0:a=1[aout]&lt;/span&gt;&lt;span class="sh"&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;apad=whole_dur=N&lt;/code&gt; extends each stream with silence to N seconds, the number computed in the earlier loop. The &lt;code&gt;adelay&lt;/code&gt; filter at the front of the chain carries a zero delay and changes nothing audible; it stays there for scenes that need a lead-in before the voice starts. For padding alone, &lt;code&gt;apad&lt;/code&gt; is enough.&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="n"&gt;subprocess&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;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ffmpeg&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;-y&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;-i&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;video&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;-i&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;audio&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
                &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;-map&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;0:v:0&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;-map&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;1:a:0&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;-c:v&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;copy&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;-c:a&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;aac&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;-shortest&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;-movflags&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;+faststart&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;final&lt;/span&gt;&lt;span class="p"&gt;)],&lt;/span&gt; &lt;span class="n"&gt;check&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;-c:v copy&lt;/code&gt; is why this step costs almost nothing: the segments were already encoded and joined by the concat demuxer, so the muxer only interleaves streams. &lt;code&gt;+faststart&lt;/code&gt; moves the index to the front of the file, which matters when it is played from a phone over a network.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the container reports
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;video: h264, 1080x1920, 25/1 fps, 1195 frames&lt;/li&gt;
&lt;li&gt;audio: aac, 24 kHz, mono&lt;/li&gt;
&lt;li&gt;duration: 47.9 seconds, reported the same for both streams&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The arithmetic matches the file: 44.904 seconds of speech plus six half-second pads is 47.904. The audio stays at 24 kHz mono because that is what the TTS produced; resampling to 44.1 kHz would add bytes and no information, and Instagram re-encodes it anyway.&lt;/p&gt;

&lt;p&gt;What that probe answers is whether video and audio agree on duration. When they differ, either a segment was written at a different length than the one used for its pad, or the concat dropped frames at a join. Both show up before anything is uploaded, and neither is visible while watching the file on a laptop at half size.&lt;/p&gt;

&lt;h2&gt;
  
  
  The silence you hear is longer than the padding you set
&lt;/h2&gt;

&lt;p&gt;I ran a two-scene version of the pipeline while writing and measured the join with &lt;code&gt;silencedetect&lt;/code&gt; at -45 dB and 0.25 seconds. The padding was 0.5 seconds and the measured silence at the cut was 1.52 seconds.&lt;/p&gt;

&lt;p&gt;The extra comes from the narration files. TTS output carries a little silence at its own start and end, and &lt;code&gt;apad&lt;/code&gt; adds on top of it. The same run flagged pauses of about 0.9 seconds inside the speech, so the clips have internal gaps of their own. What you set is a constant; what a listener perceives is that constant plus the edges of two files.&lt;/p&gt;

&lt;p&gt;Padding therefore has to be tuned by measuring the join. Half a second worked for six scenes of about seven seconds, where the sentence still holds attention. For a fast cut it would be too much.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I would change
&lt;/h2&gt;

&lt;p&gt;The docstring of the script says 0.7 seconds of padding. The loop uses 0.5. Nothing broke, but the comment is already wrong, and comments drift faster than the code they describe.&lt;/p&gt;

&lt;p&gt;I would also write the durations to a JSON file before encoding instead of recomputing them in the same pass. The script is one long function, so an encode that fails halfway re-synthesizes every narration clip when it restarts, and synthesis is the slow step that touches the network. Splitting them turns a failed render into a five-second retry.&lt;/p&gt;

&lt;p&gt;The rest holds. Six frames, six clips, one filtergraph and a format check at the end, with no GUI, no GPU and no cloud render service.&lt;/p&gt;

&lt;p&gt;Se esse tipo de detalhe ajuda no seu projeto, deixa um comentário contando o que você já quebrou tentando sincronizar áudio com imagem.&lt;/p&gt;

</description>
      <category>ffmpeg</category>
      <category>python</category>
      <category>video</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Bisecting a request body to find why the API returned 403</title>
      <dc:creator>Jonas Francisco de Lima Filho</dc:creator>
      <pubDate>Mon, 02 Nov 2026 20:05:25 +0000</pubDate>
      <link>https://dev.to/jonasfilhodev/bisecting-a-request-body-to-find-why-the-api-returned-403-125a</link>
      <guid>https://dev.to/jonasfilhodev/bisecting-a-request-body-to-find-why-the-api-returned-403-125a</guid>
      <description>&lt;p&gt;I publish articles here from a small script, so the draft exists before I ever open the editor. Last week that script got a 403 back and no article. The same token read the account one second earlier, and the same request went through afterwards with a body that said less. The fix came from splitting the article in half, not from rewriting it.&lt;/p&gt;

&lt;h2&gt;
  
  
  A 403 with an HTML body is not an authentication problem
&lt;/h2&gt;

&lt;p&gt;The response body started with &lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/code&gt; and contained the words "Attention Required!". That is not the shape of this API's errors. Rejected calls come back as JSON, with a message field, a status code and something you can act on. An HTML page in the body means the request stopped in front of the application.&lt;/p&gt;

&lt;p&gt;Two more facts from the same minute: reading the article list with the same credentials returned 200 and a full payload, and the failing call had been working for weeks. The token was valid, the route existed, and the decision was made somewhere else.&lt;/p&gt;

&lt;p&gt;The habit is cheap to build. On any 4xx, log three things before changing a single character of the input: the status code, the &lt;code&gt;content-type&lt;/code&gt; header and the first 200 bytes of the body. When you see HTML, you are no longer debugging your client.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rule out size with one control payload
&lt;/h2&gt;

&lt;p&gt;The obvious suspect was the size of the request. The article was about 9 KB of markdown, the earlier ones were smaller, and a 403 without a message invites superstition.&lt;/p&gt;

&lt;p&gt;So I sent a body of the same order with content I did not care about: repeated paragraphs of plain text, no code, no links, about 8.4 KB, on a draft. It returned an id. The real article failed at roughly 9 KB. That result is weak on its own, because 8.4 and 9 are close enough to sit on either side of a limit.&lt;/p&gt;

&lt;p&gt;The bisect settled it. One of the four parts was 2 KB and still failed, so no size threshold explains the pattern. The variable had to be content.&lt;/p&gt;

&lt;h2&gt;
  
  
  Split by paragraph, and keep the wrapper
&lt;/h2&gt;

&lt;p&gt;The script that did the split is short. It cuts the body into four blocks of whole paragraphs, leaves the markdown intact and writes one payload per part:&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;json&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;pathlib&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;partes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;texto&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Divide em n blocos de paragrafos, sem cortar frase no meio.&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;paras&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;texto&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n\n&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt;&lt;span class="p"&gt;()]&lt;/span&gt;
    &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&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;p&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;paras&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;alvo&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;atual&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;saida&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bloco&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&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;for&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;paras&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;bloco&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;atual&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&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;atual&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;alvo&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;saida&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;n&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="n"&gt;saida&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n\n&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bloco&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
            &lt;span class="n"&gt;bloco&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;atual&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;bloco&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;saida&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n\n&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bloco&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;saida&lt;/span&gt;


&lt;span class="n"&gt;corpo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pathlib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]).&lt;/span&gt;&lt;span class="nf"&gt;read_text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;encoding&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;utf-8&lt;/span&gt;&lt;span class="sh"&gt;"&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;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bloco&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;enumerate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;partes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;corpo&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;destino&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pathlib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Path&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;parte-&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;02&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;.json&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;destino&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write_text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;json&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;article&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;body_markdown&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;bloco&lt;/span&gt;&lt;span class="p"&gt;}}),&lt;/span&gt; &lt;span class="n"&gt;encoding&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;utf-8&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;destino&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bloco&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;utf-8&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;bytes&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each part goes out as its own update to the same article id. That means the draft ends up holding whatever the last successful part wrote, which is harmless on a draft and is the reason to run this test on a draft instead of on something already published.&lt;/p&gt;

&lt;p&gt;Part two failed, parts one, three and four passed, and the failing part was the only one with code in it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The trigger was one inline command
&lt;/h2&gt;

&lt;p&gt;I split part two again, then the first half of part two, and ended up with a single paragraph. It contained an inline code span: a shell request line, followed by a URL in backticks, in the shape of something a reader could paste and run. Replacing that construction with a plain sentence describing the same request made the whole article post on the first attempt.&lt;/p&gt;

&lt;p&gt;What I can state with confidence is the experiment, not the reason. Two bodies differed by that one construction and only one was accepted. I cannot see the rule that scored it, and there is a decent motive behind such a rule, since a body full of paste-ready commands with live URLs is exactly what a spammer would send. The article still needed to describe a real request, and the sentence version did that without shipping the command.&lt;/p&gt;

&lt;p&gt;This is where technical prose and content filters disagree. Command blocks are what makes a post useful to the next person. The compromise that worked: keep commands inside fenced blocks, keep a URL out of the same inline span as the command name, and test on a draft where a scrambled body costs nothing.&lt;/p&gt;

&lt;h2&gt;
  
  
  The wrapper is part of the request
&lt;/h2&gt;

&lt;p&gt;Once I dropped to the raw HTTP route to send parts, each payload has to carry the object explicitly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"article"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"body_markdown"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"..."&lt;/span&gt;&lt;span class="p"&gt;}}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sending a bare object returns 422 with "article param must be a JSON object". The integration tool I normally use builds that wrapper itself, and its schema output does not show it, which is why the requirement only appears when you bypass the tool. Two layers, and forgetting the outer one produces an error that reads like a problem with your data.&lt;/p&gt;

&lt;h2&gt;
  
  
  The field the tool never sends
&lt;/h2&gt;

&lt;p&gt;The tool that updates an article accepts nine keys. A tenth, &lt;code&gt;ai_disclosure_level&lt;/code&gt;, is refused with &lt;code&gt;Unknown key&lt;/code&gt;. The route accepts it, with four values: &lt;code&gt;not_disclosed&lt;/code&gt;, &lt;code&gt;no_ai&lt;/code&gt;, &lt;code&gt;some_ai&lt;/code&gt; and &lt;code&gt;fully_autonomous&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;That matters because the platform asks authors to disclose machine involvement, and a tool schema that cannot express the field makes compliance look impossible. It is not. One PUT to the article with that single field is enough.&lt;/p&gt;

&lt;p&gt;The check worth keeping: a 200 does not prove the field was stored. Read the article back and confirm two values in the response, &lt;code&gt;ai_disclosure_level&lt;/code&gt; and &lt;code&gt;ai_disclosure_label&lt;/code&gt;. On the most recent post here the pair came back as &lt;code&gt;some_ai&lt;/code&gt; and "AI-assisted". A response that shows &lt;code&gt;not_disclosed&lt;/code&gt; means the call succeeded and wrote nothing, which is the failure mode to watch for, because the status code looks identical.&lt;/p&gt;

&lt;h2&gt;
  
  
  The checklist I keep now
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;On a 4xx, read the content type and the first 200 bytes before touching the input.&lt;/li&gt;
&lt;li&gt;Send a control payload of similar size with content you know is harmless, before rewriting anything.&lt;/li&gt;
&lt;li&gt;Bisect by paragraph, with the wrapper on every part, on a draft.&lt;/li&gt;
&lt;li&gt;Read back every field you set. The status code confirms transmission, not storage.&lt;/li&gt;
&lt;li&gt;There is no delete for articles on this API, so a draft created by mistake stays on the account. Reuse its id with an update instead of creating a second one.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;None of this is specific to one platform. Any proxy that inspects request bodies can reject a payload for what it says, and the diagnosis repeats: exclude the boring variables first, then halve the input until the failing piece is small enough to read.&lt;/p&gt;

&lt;p&gt;Um recado curto para quem escreve em português: o método serve igual, e a parte que mais economiza tempo é ler o status e o tipo de conteúdo antes de mexer no texto. Se você já perdeu uma tarde com um erro que parecia autenticação e não era, conta nos comentários o que ele era.&lt;/p&gt;

</description>
      <category>api</category>
      <category>debugging</category>
      <category>http</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
