<?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</title>
    <description>The most recent home feed on DEV Community.</description>
    <link>https://dev.to</link>
    <atom:link rel="self" type="application/rss+xml" href="https://medialegacy1.dev.to/feed"/>
    <language>en</language>
    <item>
      <title>Ranking Hashtags by Reach with Asyncio</title>
      <dc:creator>Jinyoung Byun</dc:creator>
      <pubDate>Tue, 17 Nov 2026 06:44:21 +0000</pubDate>
      <link>https://dev.to/jinyoung_byun_afc6ea20f1c/ranking-hashtags-by-reach-with-asyncio-4of5</link>
      <guid>https://dev.to/jinyoung_byun_afc6ea20f1c/ranking-hashtags-by-reach-with-asyncio-4of5</guid>
      <description>&lt;h1&gt;
  
  
  Ranking Hashtags by Reach with Asyncio
&lt;/h1&gt;

&lt;p&gt;I maintain a ranked table of the hashtags in my niche, sorted by the median play count of their recent posts, with a post-count column next to it so I can tell a real signal from three lucky videos. I regenerate it on demand in about the time of the slowest handful of HTTP requests, not the sum of all of them.&lt;/p&gt;

&lt;p&gt;The ranking is the useful part. A hashtag with 4M posts and a median in the hundreds is a landfill. A hashtag with 60k posts and a median in the tens of thousands is where my content should go. You cannot eyeball this from the Instagram app, and you cannot get it from one request.&lt;/p&gt;

&lt;p&gt;Here is how the script works.&lt;/p&gt;

&lt;h2&gt;
  
  
  The one call everything is built on
&lt;/h2&gt;

&lt;p&gt;The whole thing started as this, against HikerAPI's REST endpoints:&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;requests&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;"x-access-key"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"YOUR_KEY"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"https://api.hikerapi.com/v2/hashtag/medias/recent?name=food"&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="n"&gt;headers&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;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="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;One hashtag, one round trip, a few hundred milliseconds of waiting during which my CPU does nothing. With 150 candidate hashtags in a sequential loop, that is 150 sequential round trips. The work is entirely I/O-bound, which is the easy case: I just need many requests in flight at once.&lt;/p&gt;

&lt;p&gt;Two things to fix before scaling it. The key goes in an environment variable, and the hashtag goes in &lt;code&gt;params&lt;/code&gt; rather than string-concatenated into the URL, so anything with a non-ASCII character survives.&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="no"&gt;BASE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"https://api.hikerapi.com/v2/hashtag/medias/recent"&lt;/span&gt;
&lt;span class="no"&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;"x-access-key"&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="s2"&gt;"HIKER_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;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;BASE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"food"&lt;/span&gt;&lt;span class="p"&gt;}&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="no"&gt;HEADERS&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;30&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;raise_for_status&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;h2&gt;
  
  
  Threads first, because it is four lines
&lt;/h2&gt;

&lt;p&gt;If you have a few dozen hashtags, &lt;code&gt;ThreadPoolExecutor&lt;/code&gt; wrapped around the call you already have is the entire upgrade. One caveat: &lt;code&gt;requests.Session&lt;/code&gt; is not documented as thread-safe, so I give each worker thread its own via &lt;code&gt;threading.local()&lt;/code&gt; rather than sharing one across the pool.&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="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;threading&lt;/span&gt;
&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;concurrent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;futures&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;ThreadPoolExecutor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;as_completed&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;

&lt;span class="no"&gt;BASE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"https://api.hikerapi.com/v2/hashtag/medias/recent"&lt;/span&gt;
&lt;span class="no"&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;"x-access-key"&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="s2"&gt;"HIKER_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;_local&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;threading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;local&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;session&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="nb"&gt;hasattr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_local&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="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;_local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Session&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;_local&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;def&lt;/span&gt; &lt;span class="nf"&gt;fetch_hashtag&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="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;session&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;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;BASE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"name"&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="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="no"&gt;HEADERS&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;30&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;raise_for_status&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;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;fetch_all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;names&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;workers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;results&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;with&lt;/span&gt; &lt;span class="nc"&gt;ThreadPoolExecutor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max_workers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;workers&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;pool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;futures&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;pool&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;submit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fetch_hashtag&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&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="k"&gt;for&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;names&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;future&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;as_completed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;futures&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;futures&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;future&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
            &lt;span class="k"&gt;try&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;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;future&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;result&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;exc&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;"{name}: {exc}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="k"&gt;continue&lt;/span&gt;
            &lt;span class="n"&gt;results&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="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;max_workers&lt;/code&gt; is your concurrency limit. It is not a dial to turn up until things go fast; it is the thing that decides whether you get rate limited. More on that below.&lt;/p&gt;

&lt;p&gt;This is fine and I used it for weeks. It stops being fine when the list grows, because every in-flight request costs you an OS thread.&lt;/p&gt;

&lt;h2&gt;
  
  
  Asyncio when the list gets long
&lt;/h2&gt;

&lt;p&gt;Once I was fanning out across hundreds of hashtags, plus a second pass over the top performers, I moved to &lt;code&gt;httpx.AsyncClient&lt;/code&gt;. Same mental model, no thread per request, and a &lt;code&gt;Semaphore&lt;/code&gt; gives me an explicit knob for concurrency that is independent of the connection pool.&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;asyncio&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;random&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;httpx&lt;/span&gt;

&lt;span class="no"&gt;BASE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"https://api.hikerapi.com/v2/hashtag/medias/recent"&lt;/span&gt;
&lt;span class="no"&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;"x-access-key"&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="s2"&gt;"HIKER_KEY"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="no"&gt;MAX_CONCURRENCY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;
&lt;span class="no"&gt;MAX_RETRIES&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;backoff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;attempt&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="nb"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="n"&gt;attempt&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="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&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;retry_delay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;header&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;headers&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;"Retry-After"&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;header&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&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;header&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;pass&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;backoff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;attempt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;fetch_hashtag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sem&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="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;sem&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;attempt&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MAX_RETRIES&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;client&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="no"&gt;BASE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"name"&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="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="no"&gt;HEADERS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="n"&gt;httpx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TransportError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;backoff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;attempt&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;if&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status_code&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;429&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;retry_delay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;attempt&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;if&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status_code&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;600&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;backoff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;attempt&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="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;raise_for_status&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;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;RuntimeError&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;"gave up on {name}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;fetch_all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;names&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;concurrency&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;MAX_CONCURRENCY&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;sem&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Semaphore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;concurrency&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;limits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;httpx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Limits&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max_connections&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;concurrency&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_keepalive_connections&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;concurrency&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;httpx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AsyncClient&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;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;limits&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;limits&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;client&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;tasks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;fetch_hashtag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sem&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&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;n&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;names&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="n"&gt;settled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;asyncio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;gather&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;tasks&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;return_exceptions&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;results&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;item&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;settled&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;item&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt;&lt;span class="p"&gt;)&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;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;continue&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;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;
        &lt;span class="n"&gt;results&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="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;results&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three details that matter more than they look:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;return_exceptions=True&lt;/code&gt; means one dead hashtag does not cancel the other 149. Without it, &lt;code&gt;gather&lt;/code&gt; propagates the first exception and you lose the whole batch.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;Semaphore&lt;/code&gt; and &lt;code&gt;httpx.Limits&lt;/code&gt; are set to the same number on purpose. The semaphore caps requests in flight; the limits cap TCP connections. If the limits are lower, requests queue inside httpx where your retry logic cannot see them, and your timeouts start firing for the wrong reason.&lt;/p&gt;

&lt;p&gt;Retries are inside the semaphore. A task that is sleeping off a 429 is still holding its slot, so the backoff actually reduces pressure on the API instead of letting another task take the slot immediately.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rate limits are a concurrency problem, not a retry problem
&lt;/h2&gt;

&lt;p&gt;Retries are the bandage. The fix is picking the right &lt;code&gt;MAX_CONCURRENCY&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Your allowed rate depends on your plan, so read the limits for yours rather than guessing from mine. The method I use is boring and works: start at 4, run the full batch, count how many 429s showed up. Zero 429s means step up. Any 429s at all means step back down. You want a concurrency level where the retry path almost never runs, because retries are requests, and requests cost money.&lt;/p&gt;

&lt;p&gt;Jitter in &lt;code&gt;backoff()&lt;/code&gt; is not decoration. Without it, every task that hit a 429 in the same window wakes up at the same instant and hits the API simultaneously, which produces another wave of 429s. The &lt;code&gt;random.random()&lt;/code&gt; smears them out.&lt;/p&gt;

&lt;p&gt;I also respect &lt;code&gt;Retry-After&lt;/code&gt; when it is present rather than overriding it with my own exponential curve. If the server tells you how long to wait, arguing with it just burns quota.&lt;/p&gt;

&lt;p&gt;The last piece is caching. At per-request pricing, the expensive mistake is not concurrency, it is re-fetching data you already have because your script crashed on row 140. I write every raw payload to a JSON file keyed by hashtag and timestamp, and the fetch layer checks for a fresh-enough file before making a call. Parsing bugs then cost nothing to fix, because iterating on the parser never touches the network.&lt;/p&gt;

&lt;p&gt;HikerAPI starts at $0.001 per request with 100 free to begin with, which is enough to tune your concurrency and confirm your parser against real payloads before you point it at a long list: &lt;a href="https://hikerapi.com/instagram-scraper-api?utm_source=devto&amp;amp;utm_medium=rewards" rel="noopener noreferrer"&gt;HikerAPI Instagram scraper API&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting numbers out of the payloads
&lt;/h2&gt;

&lt;p&gt;Response shapes nest differently across endpoints, and I did not want my ranking logic to care. So I walk each payload once and pull out anything that looks like a media object, identified by the engagement keys rather than by position in the tree.&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;MEDIA_KEYS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"play_count"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"view_count"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"like_count"&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;walk_medias&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="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;node&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;dict&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="no"&gt;MEDIA_KEYS&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;keys&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;yield&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;values&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;yield&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="nf"&gt;walk_medias&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;elif&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;node&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;list&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;value&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="nf"&gt;walk_medias&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is deliberately forgiving. When a payload comes back wrapped one level deeper than last month, nothing breaks.&lt;/p&gt;

&lt;p&gt;Then the ranking. Median, not mean, because one viral post in a sample of twenty will drag a mean somewhere useless and tell me a dead hashtag is alive.&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;from&lt;/span&gt; &lt;span class="n"&gt;statistics&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;median&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;rank&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;rows&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;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;results&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="n"&gt;plays&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;m&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;walk_medias&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;m&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;"play_count"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;m&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;"view_count"&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;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;plays&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;value&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;plays&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;5&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;continue&lt;/span&gt;

        &lt;span class="n"&gt;rows&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="p"&gt;{&lt;/span&gt;
            &lt;span class="s2"&gt;"hashtag"&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="s2"&gt;"sampled"&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;plays&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;"median_plays"&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="nf"&gt;median&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;plays&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;return&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;rows&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"median_plays"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;reverse&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;def&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;names&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;asyncio&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="nf"&gt;fetch_all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;names&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;row&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;rank&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;)&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;"{row['hashtag']:&amp;lt;28} {row['median_plays']:&amp;gt;10,}  (n={row['sampled']})"&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;len(plays) &amp;lt; 5&lt;/code&gt; guard drops hashtags where I got too thin a sample to say anything. Ranking on two posts is noise with a confident-looking number attached.&lt;/p&gt;

&lt;p&gt;If an endpoint hands back a pagination cursor, I do not chase it on the first pass. I fan out wide and shallow across every candidate hashtag, rank them, then paginate only the ones near the top. Depth is expensive and most of the list does not deserve it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which one to use
&lt;/h2&gt;

&lt;p&gt;Threads if your fan-out is in the dozens and you already have working &lt;code&gt;requests&lt;/code&gt; code. The migration is a &lt;code&gt;ThreadPoolExecutor&lt;/code&gt; and a thread-local session, and you keep every library you know.&lt;/p&gt;

&lt;p&gt;Asyncio if you are in the hundreds or thousands, if you want one explicit place to express "no more than N requests in flight", or if this fetch is one stage in a pipeline that already has an event loop in it.&lt;/p&gt;

&lt;p&gt;Both get you the same win, which is that total time collapses toward the latency of your slowest request instead of the sum of all of them. The part that actually took me iterations was not the concurrency. It was learning that &lt;code&gt;max_workers&lt;/code&gt; is a budget decision, not a performance one.&lt;/p&gt;




&lt;p&gt;Tags: &lt;code&gt;#python&lt;/code&gt; &lt;code&gt;#api&lt;/code&gt; &lt;code&gt;#async&lt;/code&gt;&lt;/p&gt;

</description>
      <category>automation</category>
      <category>python</category>
      <category>webscraping</category>
    </item>
    <item>
      <title>Hybrid AI setups seem to be most practical setup right now compared to fully local (for certain workflows)</title>
      <dc:creator>Aaron Vaz</dc:creator>
      <pubDate>Tue, 17 Nov 2026 06:44:11 +0000</pubDate>
      <link>https://dev.to/myne06/hybrid-ai-setups-seem-to-be-most-practical-setup-right-now-compared-to-fully-local-for-certain-3lfl</link>
      <guid>https://dev.to/myne06/hybrid-ai-setups-seem-to-be-most-practical-setup-right-now-compared-to-fully-local-for-certain-3lfl</guid>
      <description>&lt;p&gt;I got tired of burning through cloud api quotas every time an agent writes boilerplate code.&lt;/p&gt;

&lt;p&gt;So i tested a tri-tier setup: &lt;strong&gt;Gemini 3.8 Flash&lt;/strong&gt; as the high-level architect, and a local &lt;strong&gt;Ternary Bonsai 2 9B MTP&lt;/strong&gt; model as the actual coder.&lt;/p&gt;

&lt;p&gt;Turns out it slashed cloud token usage by &lt;strong&gt;92.7%&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkt0wh1u8snbqbbe4d9vj.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkt0wh1u8snbqbbe4d9vj.jpg" alt="architecture" width="800" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  how it works
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Gemini 3.8 Flash (planner):&lt;/strong&gt; breaks down the task, sets up data structures, CSS tokens, and atomic function signatures (~290 tokens total).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ConvAI Laya (gatekeeper):&lt;/strong&gt; fast local router that decides if a step is safe to delegate.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bonsai 2 9B MTP (coder):&lt;/strong&gt; runs locally via prism llama-server on CPU with MTP speculative decoding. it takes the signatures and outputs 100% of the raw code with thinking turned off.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Task]
   │
   ▼
[Gemini Flash] ──(Interfaces &amp;amp; Constants)──┐
                                           │
                                           ▼
                                [Local Bonsai 2 9B]
                                           │
                                           ▼
                                [Clean Production Code]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  the test: building MONSOON
&lt;/h2&gt;

&lt;p&gt;to test this, i had it build a complete website from scratch for a pop-up shop selling Indian coffee and single-estate cacao:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;index.html&lt;/code&gt;: semantic markup, hero with steam particles, terroir origin cards, off-canvas drawer.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;styles.css&lt;/code&gt;: warm earth luxury palette, glassmorphism, responsive grid, keyframe animations.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;app.js&lt;/code&gt;: tasting flight builder state machine, live INR pricing calculator, and a countdown clock to the Bangalore pop-up.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  token breakdown
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;file&lt;/th&gt;
&lt;th&gt;cloud tokens (planning)&lt;/th&gt;
&lt;th&gt;local bonsai tokens (code)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;styles.css&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;~95&lt;/td&gt;
&lt;td&gt;1,400&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;app.js&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;~85&lt;/td&gt;
&lt;td&gt;1,200&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;index.html&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;~110&lt;/td&gt;
&lt;td&gt;1,103&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;total&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;~290&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;3,703&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;cloud tokens spent:&lt;/strong&gt; ~290&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;tokens offloaded locally:&lt;/strong&gt; 3,703&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;net savings:&lt;/strong&gt; ~92.7%&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;local bonsai clocked ~6 tok/s on CPU with near 100% draft acceptance via MTP.&lt;/p&gt;

&lt;p&gt;repo with all the code &amp;amp; prompt wrappers:&lt;br&gt;
&lt;a href="https://github.com/MVYNE06/tri-tier-bonsai-orchestrator" rel="noopener noreferrer"&gt;https://github.com/MVYNE06/tri-tier-bonsai-orchestrator&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>webdev</category>
      <category>localai</category>
      <category>llm</category>
    </item>
    <item>
      <title>Why a stock score should be boring: rule-based beats black-box</title>
      <dc:creator>Ram Chandra</dc:creator>
      <pubDate>Tue, 17 Nov 2026 06:43:38 +0000</pubDate>
      <link>https://dev.to/scripwise/why-a-stock-score-should-be-boring-rule-based-beats-black-box-7oj</link>
      <guid>https://dev.to/scripwise/why-a-stock-score-should-be-boring-rule-based-beats-black-box-7oj</guid>
      <description>&lt;p&gt;I am an indie hacker from Bengaluru building Scripwise, a free research and screening tool for Indian stocks. One design decision shaped the product more than any other: the score every company gets is plain rules, with no model behind it. Here is the reasoning, in case it helps anyone building a scoring feature of their own.&lt;/p&gt;

&lt;h2&gt;
  
  
  The feature
&lt;/h2&gt;

&lt;p&gt;Scripwise covers 5,000+ companies listed on NSE and BSE. Each one gets a Scripwise Score from 0 to 100, built from five areas: valuation, profitability, growth, balance-sheet strength and shareholding.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three properties I wanted
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Deterministic.&lt;/strong&gt; The same inputs always give the same score. There is no external AI in the loop, so there is no drift between runs and nothing to re-explain when a number changes. If a score moves, a reported figure moved.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Traceable.&lt;/strong&gt; Every point maps back to a reported number. A user who disagrees with a score can see which input caused it and check that input against the company's statements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Honest about freshness.&lt;/strong&gt; Closing prices load after each trading day. During market hours, indices and the largest companies refresh about every 15 minutes. It is a research tool, not a trading terminal, and the product says so.&lt;/p&gt;

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

&lt;p&gt;Rules are blunt. A debt level that is normal for a utility looks alarming for a software company, and a rule does not know the difference unless you teach it. A rule-based score also describes the past, because reported figures do. I think that trade is worth it in finance, where a user who cannot check a number should not trust it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The same idea in the screener
&lt;/h2&gt;

&lt;p&gt;The filters follow the same principle. The &lt;a href="https://www.scripwise.co.in/screener" rel="noopener noreferrer"&gt;Scripwise screener&lt;/a&gt; exposes 47 fundamental and valuation metrics, and the presets are just visible thresholds. "High Quality Compounders" is ROE above 20% and debt-to-equity below 0.5. "Debt-Free Companies" is debt-to-equity below 0.05. Nothing is hidden behind a label.&lt;/p&gt;

&lt;h2&gt;
  
  
  Takeaway
&lt;/h2&gt;

&lt;p&gt;If your users will make decisions with your number, make the number reproducible and show your working. It is less impressive in a demo and more useful every day after.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Scripwise is not a SEBI-registered investment adviser. This post is for information and education only and is not investment advice.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>fintech</category>
      <category>webdev</category>
    </item>
    <item>
      <title>io_uring registered resources keep authority after the request ends</title>
      <dc:creator>facilishz</dc:creator>
      <pubDate>Tue, 17 Nov 2026 06:43:36 +0000</pubDate>
      <link>https://dev.to/facilishz/iouring-registered-resources-keep-authority-after-the-request-ends-1797</link>
      <guid>https://dev.to/facilishz/iouring-registered-resources-keep-authority-after-the-request-ends-1797</guid>
      <description>&lt;h1&gt;
  
  
  io_uring registered resources keep authority after the request ends
&lt;/h1&gt;

&lt;p&gt;An I/O request usually carries its authority through ordinary process state: the caller has a file descriptor, a buffer, and a set of credentials. Linux &lt;code&gt;io_uring&lt;/code&gt; changes that model by creating a submission queue that can prepare work for later execution. It also allows applications to register files, buffers, and credentials as reusable resources. Those registrations are useful, but each one creates authority that may outlive the call that created it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://man7.org/linux/man-pages/man2/io_uring_register.2.html" rel="noopener noreferrer"&gt;io_uring_register(2)&lt;/a&gt; documents &lt;code&gt;IORING_REGISTER_FILES&lt;/code&gt;, which registers a file set that operations can reference by fixed-file index. It also documents &lt;code&gt;IORING_REGISTER_PERSONALITY&lt;/code&gt;, which registers the running application's credentials and returns an identifier. That identifier can be placed in the &lt;code&gt;personality&lt;/code&gt; field of a submission queue entry. The manual page explicitly describes rings shared between separate users or processes as a use case.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which identity runs the work
&lt;/h2&gt;

&lt;p&gt;The kernel needs a rule for the credentials used by synchronous and asynchronous execution. &lt;a href="https://man7.org/linux/man-pages/man2/io_uring_setup.2.html" rel="noopener noreferrer"&gt;io_uring_setup(2)&lt;/a&gt; describes &lt;code&gt;IORING_FEAT_CUR_PERSONALITY&lt;/code&gt;. With that feature, both paths use the credentials of the task that called &lt;code&gt;io_uring_enter(2)&lt;/code&gt; to queue the request. Without the feature, operations use the credentials of the task that originally registered the ring. A registered personality can override that choice for individual requests.&lt;/p&gt;

&lt;p&gt;This is more than an implementation detail. If a privileged process creates a ring and passes its file descriptor to a less privileged component, the new component may be able to submit work against registered files and personalities that the original process prepared. A shared ring therefore behaves like a capability set. Treat access to the ring descriptor, shared memory mappings, fixed-file indexes, and personality identifiers as security-sensitive configuration.&lt;/p&gt;

&lt;h2&gt;
  
  
  Review the sharing model
&lt;/h2&gt;

&lt;p&gt;Applications that do not need shared rings should keep them private to one trust domain. A supervisor that exposes a ring to another process should validate the queue entries it accepts and restrict which personalities and fixed files are available to that client. Do not assume the peer is allowed to use every object already registered with the ring.&lt;/p&gt;

&lt;p&gt;Seccomp profiles and service sandboxes should list &lt;code&gt;io_uring_setup&lt;/code&gt;, &lt;code&gt;io_uring_enter&lt;/code&gt;, and &lt;code&gt;io_uring_register&lt;/code&gt; deliberately. If the workload does not need the API, the kernel's &lt;code&gt;io_uring_disabled&lt;/code&gt; control can remove the surface at a host or namespace boundary. If it does need the API, log ring creation, sharing, personality registration, and file registration in the controlling service rather than relying only on individual I/O requests.&lt;/p&gt;

&lt;p&gt;Lifecycle tests should close or revoke a ring before handing its files or memory to an untrusted component, verify that closed fixed files cannot be reused, and check whether a shared ring can select a stale personality after a role change. Include worker-thread behavior in the test, because credential timing can differ between submission and completion.&lt;/p&gt;

&lt;p&gt;Registered resources make &lt;code&gt;io_uring&lt;/code&gt; efficient and make its authority persistent. The design review should name who can submit to the ring, which credentials each request may use, and which files remain reachable after the original request returns.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://man7.org/linux/man-pages/man2/io_uring_register.2.html" rel="noopener noreferrer"&gt;Linux manual: io_uring_register(2)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://man7.org/linux/man-pages/man2/io_uring_setup.2.html" rel="noopener noreferrer"&gt;Linux manual: io_uring_setup(2)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://man7.org/linux/man-pages/man2/io_uring_enter.2.html" rel="noopener noreferrer"&gt;Linux manual: io_uring_enter(2)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>linux</category>
      <category>sandboxing</category>
      <category>accesscontrol</category>
    </item>
    <item>
      <title>Build a Tiny LLM Output Evaluation Harness in Python (No Framework Required)</title>
      <dc:creator>Tamer Kalla</dc:creator>
      <pubDate>Tue, 17 Nov 2026 06:42:50 +0000</pubDate>
      <link>https://dev.to/tamer_kalla/build-a-tiny-llm-output-evaluation-harness-in-python-no-framework-required-14e9</link>
      <guid>https://dev.to/tamer_kalla/build-a-tiny-llm-output-evaluation-harness-in-python-no-framework-required-14e9</guid>
      <description>&lt;h2&gt;
  
  
  The problem
&lt;/h2&gt;

&lt;p&gt;Every team I have seen wire an LLM into a production service eventually ships the same bug: somebody improves a prompt, the demo looks great, and a downstream consumer quietly breaks. The summarizer stops including the one field the ticket parser needs. The classifier starts answering "The sentiment is positive" instead of "positive", and the exact-match routing downstream falls over. The extraction step returns JSON wrapped in markdown fences, and &lt;code&gt;json.loads&lt;/code&gt; throws at 2 a.m.&lt;/p&gt;

&lt;p&gt;None of these are model-quality problems. They are contract problems. The model team changed the shape of the output, and nothing in the pipeline checked the shape.&lt;/p&gt;

&lt;p&gt;The usual responses are both wrong-sized. Eyeballing a spreadsheet of outputs does not survive the second prompt change. Adopting a full evaluation platform, with its own config format, storage, and opinions, is a week of work for a service that has five prompts. What most services actually need sits in between: a small suite of deterministic checks, written in the same language as the service, that runs in CI and fails the build when an output contract breaks. This article builds one in about 150 lines of dependency-free Python.&lt;/p&gt;

&lt;h2&gt;
  
  
  The approach
&lt;/h2&gt;

&lt;p&gt;Three design decisions keep the harness small and honest.&lt;/p&gt;

&lt;p&gt;First, a check is just a function. It takes the model's response text and returns &lt;code&gt;(passed, detail)&lt;/code&gt;: a boolean and a human-readable explanation. No classes to subclass, no plugin registry. If you can write an &lt;code&gt;assert&lt;/code&gt;, you can write a check.&lt;/p&gt;

&lt;p&gt;Second, checks never raise. A malformed response is a failed check with a useful message, not a crashed test run. This matters more than it sounds like, and the gotchas section comes back to it.&lt;/p&gt;

&lt;p&gt;Third, the harness knows nothing about model providers. It takes a callable, &lt;code&gt;prompt -&amp;gt; response_text&lt;/code&gt;, and runs cases against it. In production that callable wraps your API client. In tests it is a stub with canned responses, which is how the example in this article runs with no API key and no network.&lt;/p&gt;

&lt;p&gt;What this harness deliberately does not do is judge whether an answer is &lt;em&gt;good&lt;/em&gt;. Deterministic checks verify contracts: required content, forbidden content, format, length, parseability. Semantic quality needs a different tool (human review, or a model-graded rubric with all its own caveats). Conflating the two is how eval suites turn into noise nobody reads.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: The check signature and the two simplest checks
&lt;/h2&gt;

&lt;p&gt;Most production failures I have debugged were content failures: something required went missing, or something forbidden showed up. Two checks cover a surprising amount of ground.&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="nc"&gt;CheckFn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Callable&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;tuple&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;str&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;contains_all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;needles&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;CheckFn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="s2"&gt;"""Pass when every needle appears in the response (case-insensitive)."""&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;tuple&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;lowered&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;text&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;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;n&lt;/span&gt; &lt;span class="k"&gt;for&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;needles&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;n&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="ow"&gt;not&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;lowered&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;missing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;False&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;"missing: {missing}"&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"all present"&lt;/span&gt;

    &lt;span class="n"&gt;check&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;label&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"contains_all{list(needles)}"&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;check&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;not_contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;needles&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;CheckFn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="s2"&gt;"""Pass when none of the needles appear (case-insensitive)."""&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;tuple&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;lowered&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;text&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;found&lt;/span&gt; &lt;span class="o"&gt;=&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;for&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;needles&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;n&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;in&lt;/span&gt; &lt;span class="n"&gt;lowered&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;found&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;False&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;"found forbidden: {found}"&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"none present"&lt;/span&gt;

    &lt;span class="n"&gt;check&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;label&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"not_contains{list(needles)}"&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;check&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each factory returns a closure with a &lt;code&gt;label&lt;/code&gt; attribute, so failure reports can name the check that failed instead of printing a memory address. Matching is case-insensitive by default because models are inconsistent about capitalization and your contract usually is not.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Format checks, where the real failures live
&lt;/h2&gt;

&lt;p&gt;Format drift is the highest-value thing to catch, because format consumers are code, and code is unforgiving. Two checks cover the common cases: a full-match regex for label-style outputs, and a JSON check for extraction outputs.&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;matches_regex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pattern&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;CheckFn&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;check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;tuple&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;str&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;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fullmatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pattern&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&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;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="no"&gt;DOTALL&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="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"full match"&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;False&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;"no full match for {pattern!r}: {text.strip()[:60]!r}"&lt;/span&gt;

    &lt;span class="n"&gt;check&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;label&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"matches_regex({pattern!r})"&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;check&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;valid_json_with_keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;CheckFn&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;check&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;tuple&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;try&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="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="nf"&gt;_strip_code_fences&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;except&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="nc"&gt;JSONDecodeError&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;ValueError&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;exc&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;False&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;"invalid JSON: {exc}"&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;isinstance&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="kt"&gt;dict&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="kc"&gt;False&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;"expected JSON object, got {type(data).__name__}"&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;k&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;keys&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;data&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;missing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;False&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;"missing keys: {missing}"&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"valid JSON with all keys"&lt;/span&gt;

    &lt;span class="n"&gt;check&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;label&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"valid_json_with_keys{list(keys)}"&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;check&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two details here are load-bearing. &lt;code&gt;matches_regex&lt;/code&gt; uses &lt;code&gt;fullmatch&lt;/code&gt;, not &lt;code&gt;search&lt;/code&gt;: for a classifier, "positive" buried in a sentence is a failure, not a pass. And the JSON check strips markdown code fences before parsing, via a small &lt;code&gt;_strip_code_fences&lt;/code&gt; helper. Whether you should strip fences depends on your consumer (more in the gotchas), but the harness should make that policy explicit rather than accidental. A &lt;code&gt;max_words&lt;/code&gt; check, same shape, rounds out the set for length budgets.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Cases and the runner
&lt;/h2&gt;

&lt;p&gt;A case is a name, a prompt, and a list of checks. The runner calls the model once per case and collects failures instead of stopping at the first one, because in CI you want the full damage report from a prompt change, not a single red 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="nd"&gt;@dataclass&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Case&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="kt"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;checks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;CheckFn&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;default_factory&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kt"&gt;list&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;run_eval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model_fn&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cases&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;results&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="k"&gt;case&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;cases&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;model_fn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;case&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;failures&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;check_fn&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="k"&gt;case&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;checks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;passed&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;detail&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;check_fn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&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="n"&gt;passed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;failures&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;f&lt;/span&gt;&lt;span class="s2"&gt;"{getattr(check_fn, 'label', 'check')}: {detail}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;results&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="nc"&gt;CaseResult&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;case&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;passed&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;failures&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;failures&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;failures&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;results&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 4: A suite, a stub model, and a CI-friendly exit code
&lt;/h2&gt;

&lt;p&gt;The suite below tests a small support-automation service: a summarizer, an extractor, a sentiment classifier, a factual answerer, and an explainer with a length budget. The stub model returns canned responses, three of which contain the exact failure modes this suite exists to catch. In a real deployment you would replace &lt;code&gt;stub_model&lt;/code&gt; with a thin wrapper around your provider's client and keep everything 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="no"&gt;CASES&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="nc"&gt;Case&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"summary_keeps_key_facts"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Summarize this incident report in under 60 words: ..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;checks&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;contains_all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"database"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"rollback"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;max_words&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;Case&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"extraction_is_valid_json"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Extract the contact from this signature block as JSON: ..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;checks&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;valid_json_with_keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"email"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;Case&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"sentiment_is_bare_label"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Classify the sentiment of this review as one word: ..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;checks&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;matches_regex&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;"positive|negative|neutral"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;Case&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"facts_have_no_invented_links"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"When was the Eiffel Tower completed?"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;checks&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;not_contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"http"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;Case&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"explanation_respects_length_cap"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Explain idempotency in at most 25 words."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;checks&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;max_words&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;main()&lt;/code&gt; function prints one line per case plus the failure details, then returns exit code 1 if anything failed. That exit code is the entire CI integration: run the suite on any pull request that touches a prompt, a model version, or decoding parameters, and let the build go red.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Run it
&lt;/h2&gt;

&lt;p&gt;Here is the actual output of the suite above (full code in &lt;code&gt;eval_harness.py&lt;/code&gt; and &lt;code&gt;run_evals.py&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[PASS] summary_keeps_key_facts
[PASS] extraction_is_valid_json
[FAIL] sentiment_is_bare_label
       matches_regex('positive|negative|neutral'): no full match for 'positive|negative|neutral': 'The sentiment is positive.'
[FAIL] facts_have_no_invented_links
       not_contains['http']: found forbidden: ['http']
[FAIL] explanation_respects_length_cap
       max_words(25): 51 words &amp;gt; 25

2/5 cases passed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Read the three failures the way you would in a real regression. The classifier drifted from a bare label to a sentence; every exact-match consumer of that label is now broken. The factual answerer invented a citation URL on a domain that does not exist; if your UI renders links, you are now sending users to a hallucinated site. The explainer blew its length budget by 2x, which is how a tidy UI card becomes a wall of text. Each failure names the check and shows the evidence, so the fix conversation starts from facts instead of vibes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Real gotchas
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Fenced JSON will flood you with false alarms if you let it.&lt;/strong&gt; Models wrap JSON in code fences constantly, even when the prompt says not to, and even at temperature zero. If your consumer strips fences before parsing, your check should too; if your consumer does a bare &lt;code&gt;json.loads&lt;/code&gt;, then the fenced output is a genuine failure and the check should be strict. The mistake is a harness whose policy differs from the production parser's. Mirror the consumer, exactly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A crashed harness is worse than a red one.&lt;/strong&gt; Early versions of suites like this tend to die on the first truly malformed output, a JSONDecodeError escaping out of a check, an index error on an empty response. In CI that reads as an infrastructure failure, and infrastructure failures get retried and ignored. Wrap every parse, treat empty responses as ordinary failures, and make the harness's own exit path boring. A suite people route around is worse than no suite.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Deterministic checks pass wrong answers happily.&lt;/strong&gt; &lt;code&gt;contains_all("1889")&lt;/code&gt; passes whether the sentence around it is right, wrong, or incoherent. For factual cases where the answer space is small, prefer exact-match or golden-answer checks. For open-ended cases, accept the limit: this harness guards contracts, and correctness sampling (a human reading twenty random outputs a week) is a separate, necessary habit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;One run proves little about a stochastic model.&lt;/strong&gt; At nonzero temperature, a case that passes today is a coin you flipped once. For the checks that guard expensive failures, run each case three to five times and report a pass rate, failing the build below a threshold you choose. Keep the repetition count small and the case list shorter; a suite that takes twenty minutes will be the first thing deleted under deadline pressure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Keep responses cached during development.&lt;/strong&gt; When you are iterating on the checks themselves, you do not want to pay for fresh completions on every run. Cache responses keyed by model name, prompt, and decoding parameters, and add a flag to bust the cache when the point of the run is fresh model behavior.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap-up
&lt;/h2&gt;

&lt;p&gt;You now have a harness that catches the failures that actually page people: missing facts, forbidden content, format drift, invalid JSON, and blown length budgets, in about 150 lines with no dependencies. Graduate to a heavier evaluation platform when you need semantic scoring at scale, dataset versioning across teams, or statistical comparisons between model versions. Until then, the highest-leverage habit is procedural, not technical: every prompt change runs the suite, and a red suite blocks the merge. Contracts first, quality second, in that order, because the contract failures are the ones your users notice before you do.&lt;/p&gt;

</description>
      <category>python</category>
      <category>ai</category>
      <category>llm</category>
      <category>testing</category>
    </item>
    <item>
      <title>Fail CI when Lighthouse budgets slip: GitHub Actions + a hosted audit</title>
      <dc:creator>Jerry Lin</dc:creator>
      <pubDate>Tue, 17 Nov 2026 06:42:48 +0000</pubDate>
      <link>https://dev.to/jerrylin1102/fail-ci-when-lighthouse-budgets-slip-github-actions-a-hosted-audit-1557</link>
      <guid>https://dev.to/jerrylin1102/fail-ci-when-lighthouse-budgets-slip-github-actions-a-hosted-audit-1557</guid>
      <description>&lt;p&gt;Lighthouse is a lab test. Run it twice on the same URL and the performance score often moves a few points. That is normal: CPU contention, network jitter, and third-party scripts all wobble the result.&lt;/p&gt;

&lt;p&gt;If you only glance at PageSpeed Insights before a launch, a regression can ship between glances. A more useful habit is to set a &lt;strong&gt;performance budget&lt;/strong&gt; and let CI fail the deploy when the budget misses.&lt;/p&gt;

&lt;p&gt;This post walks through a complete GitHub Actions job that:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Runs real Google Lighthouse on a public URL (mobile and desktop).&lt;/li&gt;
&lt;li&gt;Repeats the audit up to three times and reports the median run, so one noisy measurement does not fail the build.&lt;/li&gt;
&lt;li&gt;Fails the workflow when the score or Core Web Vitals miss limits you chose.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I will use an Apify Actor I built for the hosted run, and I will say so clearly at the end. The same budget idea works with &lt;a href="https://github.com/GoogleChrome/lighthouse-ci" rel="noopener noreferrer"&gt;Lighthouse CI&lt;/a&gt; if you prefer to run Chrome yourself on the runner.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to budget
&lt;/h2&gt;

&lt;p&gt;Google's "good" lab-style thresholds are a reasonable default:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;LCP&lt;/strong&gt; (Largest Contentful Paint) ≤ 2500 ms&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CLS&lt;/strong&gt; (Cumulative Layout Shift) ≤ 0.1&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Performance score&lt;/strong&gt; is a 0–100 weighted blend; a floor such as 90 is stricter than "not poor," so only set it if you can actually hold it&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Total Blocking Time (TBT) is the lab stand-in for INP. INP itself needs real user interactions, so do not expect a Lighthouse run to report INP.&lt;/p&gt;

&lt;p&gt;Lab data is not Chrome User Experience Report (CrUX) field data. Hardware and network location also differ from PageSpeed Insights, so treat the CI number as a trend on the same setup, not a promise that PSI will show the same score.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why run Lighthouse off the GitHub runner?
&lt;/h2&gt;

&lt;p&gt;Official Lighthouse CI is the usual path: install Chrome, build the app, run &lt;code&gt;lhci autorun&lt;/code&gt;. That is the right default when you can audit &lt;code&gt;localhost&lt;/code&gt; or a preview URL the runner can reach.&lt;/p&gt;

&lt;p&gt;Sometimes the page you care about is already on a public staging or production URL, and you would rather not install Chrome in the workflow. In that case you can call a hosted Lighthouse run over an API, then fail the job on the run status.&lt;/p&gt;

&lt;p&gt;The Actor I use is &lt;a href="https://apify.com/rationalistic_tail/lighthouse-budget-auditor" rel="noopener noreferrer"&gt;Lighthouse Audit &amp;amp; Performance Budgets&lt;/a&gt;. It runs Lighthouse in Chrome on Apify (no Google API key, no PageSpeed Insights quota), can audit mobile and desktop in the same run, and has a &lt;code&gt;failRunIfBudgetFails&lt;/code&gt; flag that marks the Actor run as &lt;code&gt;FAILED&lt;/code&gt; when any row misses a budget. Results are still saved. Pages blocked by &lt;code&gt;robots.txt&lt;/code&gt;, non-HTML URLs, and failed audits are not charged.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cost, so there are no surprises
&lt;/h2&gt;

&lt;p&gt;Pricing is pay-per-event (from the public listing):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;$0.025&lt;/strong&gt; per successful Lighthouse run (one URL × one device × one run)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;$0.001&lt;/strong&gt; Actor start fee per GB of memory. The default is &lt;strong&gt;4 GB&lt;/strong&gt;, so the start fee is &lt;strong&gt;$0.004&lt;/strong&gt;. Keep the default: on Apify, CPU scales with memory, and less CPU can make mobile scores look worse than they are.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Worked example: 1 URL, mobile + desktop, &lt;code&gt;runsPerUrl: 3&lt;/code&gt; → 6 successful audits → &lt;strong&gt;$0.15 + $0.004 = $0.154&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If you only need a cheap smoke check, set &lt;code&gt;runsPerUrl: 1&lt;/code&gt; (2 audits → about $0.054). Use 3 when you want a stabler median. Cap the bill with &lt;code&gt;maxTotalChargeUsd&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Create an Apify token
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Sign in at &lt;a href="https://console.apify.com/" rel="noopener noreferrer"&gt;Apify Console&lt;/a&gt; and open &lt;strong&gt;Settings → Integrations&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Create an API token with enough rights to start a run and read the default dataset.&lt;/li&gt;
&lt;li&gt;In the GitHub repo, add a secret named &lt;code&gt;APIFY_TOKEN&lt;/code&gt;. Never put the token in the workflow file.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  2. Add a small script the workflow can run
&lt;/h2&gt;

&lt;p&gt;This uses the official &lt;a href="https://docs.apify.com/api/client/js/docs" rel="noopener noreferrer"&gt;&lt;code&gt;apify-client&lt;/code&gt;&lt;/a&gt; package. &lt;code&gt;actor.call()&lt;/code&gt; starts the run and waits until it finishes. &lt;code&gt;waitForFinish&lt;/code&gt; on the raw HTTP API only waits up to 60 seconds, which is too short for three mobile + desktop audits, so the client (which polls) is the better fit.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;scripts/lighthouse-budget.mjs&lt;/code&gt;:&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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;ApifyClient&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"apify-client"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;APIFY_TOKEN&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;siteUrl&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;SITE_URL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;token&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"APIFY_TOKEN is missing. Add it as a GitHub Actions secret."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nb"&gt;process&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="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="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;siteUrl&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"SITE_URL is missing."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nb"&gt;process&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="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="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ApifyClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;token&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;input&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;urls&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;siteUrl&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;devices&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"mobile"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"desktop"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;runsPerUrl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;minPerformance&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;maxLcpMs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2500&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;maxCls&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"0.1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;failRunIfBudgetFails&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="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Optional: cap the run so a misconfigured input cannot overspend.&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;actor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"rationalistic_tail/lighthouse-budget-auditor"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;maxTotalChargeUsd&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="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dataset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;run&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;defaultDatasetId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listItems&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="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;label&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sb"&gt;`${row.device} ${row.url}`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="s2"&gt;"ok"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`${label}: ${row.status}`&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="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="sb"&gt;`${label}: perf=${row.performance} LCP=${row.lcpMs}ms CLS=${row.cls} budgetPassed=${row.budgetPassed}`&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;budgetFailures&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"  failures:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;budgetFailures&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="s2"&gt;"; "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;opportunities&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="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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;top&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;opportunities&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="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`  top fix: ${top.title} (est. ${top.savingsMs}ms)`&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="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;run&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="s2"&gt;"SUCCEEDED"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`Actor run ended with status ${run.status}.`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nb"&gt;process&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="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="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;missed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;row&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;row&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;budgetPassed&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;missed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Belt and braces: should already be a FAILED run when failRunIfBudgetFails is true.&lt;/span&gt;
  &lt;span class="nb"&gt;process&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="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="p"&gt;}&lt;/span&gt;

&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"All budgets passed."&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 passing row looks like the public example on the Actor page (numbers will differ on your site):&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;"url"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"https://example.com/"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"device"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"mobile"&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;"ok"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"performance"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;86&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"lcpMs"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2890&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"cls"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.03&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"budgetPassed"&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;"budgetFailures"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"performance 86 &amp;lt; 90"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"LCP 2890ms &amp;gt; 2500ms"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"opportunities"&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;"title"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Eliminate render-blocking resources"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"savingsMs"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;450&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;"runs"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"performanceRange"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;84&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;89&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;In that example the run should fail CI: LCP is over 2500 ms and the performance score is under 90, even though CLS is fine.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Wire it to GitHub Actions
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;.github/workflows/lighthouse-budget.yml&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Lighthouse budget&lt;/span&gt;

&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;workflow_dispatch&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="c1"&gt;# After your own deploy job, or on a schedule against staging:
&lt;/span&gt;  &lt;span class="c1"&gt;# schedule:
&lt;/span&gt;  &lt;span class="c1"&gt;#   - cron: "0 6 * * 1"
&lt;/span&gt;
&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;lighthouse&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;timeout-minutes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v4&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/setup-node@v4&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;node-version&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"22"&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Install apify-client&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;npm install apify-client&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Run Lighthouse budgets&lt;/span&gt;
        &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;APIFY_TOKEN&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.APIFY_TOKEN }}&lt;/span&gt;
          &lt;span class="c1"&gt;# Public staging or production URL. Must be reachable without login.
&lt;/span&gt;          &lt;span class="na"&gt;SITE_URL&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ vars.SITE_URL }}&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;node scripts/lighthouse-budget.mjs&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Store &lt;code&gt;SITE_URL&lt;/code&gt; as a repository variable (Settings → Secrets and variables → Actions → Variables), or hard-code a public staging URL in the workflow if that is simpler.&lt;/p&gt;

&lt;p&gt;Run this &lt;strong&gt;after&lt;/strong&gt; the deploy that makes the URL live. Auditing the previous release is how budgets go stale.&lt;/p&gt;

&lt;h2&gt;
  
  
  Things the audit will not do
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;It honors &lt;code&gt;robots.txt&lt;/code&gt;. A disallowed URL is skipped and not charged.&lt;/li&gt;
&lt;li&gt;It only loads public pages. There is no login, cookie injection, or CAPTCHA solving.&lt;/li&gt;
&lt;li&gt;It measures lab data in Chrome. Use RUM or CrUX if you need real-user numbers.&lt;/li&gt;
&lt;li&gt;Lighthouse is pinned on the Actor (currently 12.8.x) and reported on each row as &lt;code&gt;lighthouseVersion&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you want a first-party, same-commit check against a preview build, use &lt;a href="https://github.com/GoogleChrome/lighthouse-ci" rel="noopener noreferrer"&gt;Lighthouse CI&lt;/a&gt; instead of, or as well as, a hosted audit of the public URL.&lt;/p&gt;

&lt;h2&gt;
  
  
  Disclosure
&lt;/h2&gt;

&lt;p&gt;I built the &lt;a href="https://apify.com/rationalistic_tail/lighthouse-budget-auditor" rel="noopener noreferrer"&gt;Lighthouse Audit &amp;amp; Performance Budgets&lt;/a&gt; Actor that this workflow calls. It is pay-per-event on Apify, as priced above. I also maintain a few related developer tools on the same profile, including a &lt;a href="https://apify.com/rationalistic_tail/broken-link-anchor-checker" rel="noopener noreferrer"&gt;broken-link and &lt;code&gt;#anchor&lt;/code&gt; checker&lt;/a&gt; and a &lt;a href="https://apify.com/rationalistic_tail/sitemap-validator-generator" rel="noopener noreferrer"&gt;sitemap extractor / validator / generator&lt;/a&gt;. You can call the Lighthouse Actor from an AI agent through &lt;a href="https://mcp.apify.com?tools=rationalistic_tail/lighthouse-budget-auditor" rel="noopener noreferrer"&gt;Apify's official MCP server&lt;/a&gt; if you want the same audit outside CI.&lt;/p&gt;

&lt;p&gt;If you already run Lighthouse CI in the repo, you do not need this. If you want a budget gate on a public URL without installing Chrome on the runner, the workflow above is the whole setup.&lt;/p&gt;

</description>
      <category>webperf</category>
      <category>lighthouse</category>
      <category>github</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Day 24/90 — Should AI Agents Be Allowed to Take Actions Without Human Approval?</title>
      <dc:creator>Rimsha Kanwal</dc:creator>
      <pubDate>Tue, 17 Nov 2026 06:42:41 +0000</pubDate>
      <link>https://dev.to/rimsha_kanwal/day-2490-should-ai-agents-be-allowed-to-take-actions-without-human-approval-27ck</link>
      <guid>https://dev.to/rimsha_kanwal/day-2490-should-ai-agents-be-allowed-to-take-actions-without-human-approval-27ck</guid>
      <description>&lt;p&gt;&lt;em&gt;Why Human-in-the-Loop (HITL) is becoming one of the most important engineering patterns for building reliable AI agents.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We are getting surprisingly good at building AI agents.&lt;/p&gt;

&lt;p&gt;Not long ago, most AI applications were limited to answering questions, summarizing documents, or generating text. Today, we are building systems that can reason through problems, interact with external APIs, query databases, execute tools, and complete multi-step workflows with relatively little human involvement.&lt;/p&gt;

&lt;p&gt;An AI agent can now handle customer support requests, update records, generate reports, schedule meetings, and even initiate financial operations.&lt;/p&gt;

&lt;p&gt;From an engineering perspective, that is impressive.&lt;/p&gt;

&lt;p&gt;But the more autonomy we give these systems, the more important another question becomes:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Just because an AI agent can perform an action, how do we know it should?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is where the conversation around AI agents needs to evolve.&lt;/p&gt;

&lt;p&gt;We spend a lot of time discussing reasoning capabilities, tool calling, orchestration frameworks, and how to make agents more autonomous.&lt;/p&gt;

&lt;p&gt;But in real-world applications, making an agent capable of executing an action is only half the problem.&lt;/p&gt;

&lt;p&gt;The other half is making sure that action is appropriate, authorized, and safe.&lt;/p&gt;

&lt;p&gt;And sometimes, that means the agent needs to stop and ask a human.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem With Fully Autonomous AI Agents
&lt;/h2&gt;

&lt;p&gt;Let's imagine a simple customer support application.&lt;/p&gt;

&lt;p&gt;A customer contacts an AI-powered support agent and says:&lt;/p&gt;

&lt;p&gt;"I received the wrong product. I want a refund."&lt;/p&gt;

&lt;p&gt;The agent analyzes the message, identifies the customer's intent, retrieves their order details, checks the refund policy, and prepares the next action.&lt;/p&gt;

&lt;p&gt;So far, everything seems to be working.&lt;/p&gt;

&lt;p&gt;Now imagine the agent has access to tools such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;get_order_status()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;check_refund_policy()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;create_support_ticket()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;process_refund()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The agent decides that the customer qualifies for a refund and proceeds to execute &lt;code&gt;process_refund()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The workflow completes successfully.&lt;/p&gt;

&lt;p&gt;The API returns a success response. The transaction is recorded. The customer receives a confirmation.&lt;/p&gt;

&lt;p&gt;Technically, everything worked.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;But what if the agent made the wrong decision?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;What if the order was outside the refund period?&lt;/p&gt;

&lt;p&gt;What if the customer had already received a refund?&lt;/p&gt;

&lt;p&gt;What if the agent misunderstood the customer's request and initiated a refund when the customer only wanted to open a support ticket?&lt;/p&gt;

&lt;p&gt;Or what if the refund amount was incorrect?&lt;/p&gt;

&lt;p&gt;These aren't necessarily failures in tool execution.&lt;/p&gt;

&lt;p&gt;The tools might be working perfectly.&lt;/p&gt;

&lt;p&gt;The problem is that the agent was allowed to make and execute a decision without sufficient verification.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A technically successful action can still be a business failure.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And that is an important distinction when designing agentic systems.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding Human-in-the-Loop (HITL)
&lt;/h2&gt;

&lt;p&gt;Human-in-the-Loop, commonly called HITL, is an approach where human judgment is incorporated into an automated system at specific decision points.&lt;/p&gt;

&lt;p&gt;Instead of allowing an AI agent to execute every action independently, we introduce checkpoints where a human can review what the agent intends to do.&lt;/p&gt;

&lt;p&gt;The human may approve the action, reject it, or modify the proposed details.&lt;/p&gt;

&lt;p&gt;The goal isn't to remove automation.&lt;/p&gt;

&lt;p&gt;It's to ensure that automation operates within appropriate boundaries.&lt;/p&gt;

&lt;p&gt;For example, a customer support agent might be allowed to independently retrieve order information, explain refund policies, and prepare support tickets.&lt;/p&gt;

&lt;p&gt;However, when the workflow involves issuing a refund, changing sensitive account information, or performing an irreversible operation, the system can require human approval.&lt;/p&gt;

&lt;p&gt;This creates a clear separation between two responsibilities:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AI handles preparation and recommendation. Humans retain authority over selected high-impact decisions.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That separation becomes particularly valuable as agents interact with more tools and systems.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why This Matters Beyond Customer Support
&lt;/h2&gt;

&lt;p&gt;The same problem appears across many industries.&lt;/p&gt;

&lt;p&gt;Consider an AI agent responsible for managing cloud infrastructure.&lt;/p&gt;

&lt;p&gt;It detects unusually high resource usage and recommends terminating an instance to reduce costs.&lt;/p&gt;

&lt;p&gt;That recommendation might be reasonable.&lt;/p&gt;

&lt;p&gt;But what if the instance is running a production database?&lt;/p&gt;

&lt;p&gt;A similar problem can occur with an AI coding agent that decides to modify database schemas, an HR assistant that updates employee records, or a financial agent that prepares transactions.&lt;/p&gt;

&lt;p&gt;In all these situations, the challenge is not simply whether the AI understands the task.&lt;/p&gt;

&lt;p&gt;The challenge is whether the system has appropriate controls over what happens next.&lt;/p&gt;

&lt;p&gt;This concern is also reflected in established AI risk and security guidance.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;NIST AI Risk Management Framework&lt;/strong&gt; emphasizes governance, accountability, clearly defined responsibilities, and human oversight as part of managing AI risks.&lt;/p&gt;

&lt;p&gt;Similarly, the &lt;strong&gt;OWASP Top 10 for LLM Applications&lt;/strong&gt; identifies &lt;em&gt;Excessive Agency&lt;/em&gt; as a security risk, where AI-powered systems are given more functionality, permissions, or autonomy than necessary.&lt;/p&gt;

&lt;p&gt;The underlying engineering principle is straightforward:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;An agent should have the minimum authority required to complete its responsibilities, and high-impact decisions should receive appropriate oversight.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Human approval is one way of implementing that principle, alongside authorization controls, validation, and restricted tool permissions.&lt;/p&gt;

&lt;h2&gt;
  
  
  How LangGraph Makes Human-in-the-Loop Possible
&lt;/h2&gt;

&lt;p&gt;One framework that provides useful primitives for implementing these workflows is LangGraph.&lt;/p&gt;

&lt;p&gt;LangGraph is designed for building stateful, multi-step agent workflows. Instead of treating an AI interaction as a single model request, it allows developers to organize execution into nodes, transitions, and persistent state.&lt;/p&gt;

&lt;p&gt;One particularly useful feature is &lt;code&gt;interrupt()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The purpose of &lt;code&gt;interrupt()&lt;/code&gt; is to pause execution at a specific point in the workflow and request external input before continuing.&lt;/p&gt;

&lt;p&gt;For example, imagine that an agent has prepared a refund request.&lt;/p&gt;

&lt;p&gt;It has identified:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Customer order: ORD-1042&lt;/li&gt;
&lt;li&gt;Requested refund amount: $125&lt;/li&gt;
&lt;li&gt;Reason: Incorrect product delivered&lt;/li&gt;
&lt;li&gt;Recommended action: Issue refund&lt;/li&gt;
&lt;li&gt;Approval status: Pending&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Rather than immediately issuing the refund, the workflow reaches a human review node.&lt;/p&gt;

&lt;p&gt;At that point, LangGraph can call &lt;code&gt;interrupt()&lt;/code&gt; and expose the proposed action for review.&lt;/p&gt;

&lt;p&gt;Conceptually, the flow looks like this:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Customer Request → AI Analysis → Policy Validation → Human Review → Approved Execution → Customer Response&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The agent has already completed the preliminary reasoning and information gathering.&lt;/p&gt;

&lt;p&gt;But the actual refund remains pending.&lt;/p&gt;

&lt;p&gt;A reviewer can inspect the request and decide what happens next.&lt;/p&gt;

&lt;p&gt;If the reviewer approves it, execution continues.&lt;/p&gt;

&lt;p&gt;If the reviewer rejects it, the system can stop the refund and communicate the appropriate outcome.&lt;/p&gt;

&lt;p&gt;If the reviewer edits the request, the workflow can use the revised information after validating it.&lt;/p&gt;

&lt;p&gt;This pattern provides a practical way to introduce human control without rebuilding the entire application around manual intervention.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Simple Implementation Using LangGraph
&lt;/h2&gt;

&lt;p&gt;The core mechanism is relatively straightforward.&lt;/p&gt;

&lt;p&gt;Consider a simplified review node:&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;from&lt;/span&gt; &lt;span class="n"&gt;langgraph&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;types&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;interrupt&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;human_review&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;decision&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;interrupt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;"action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"process_refund"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"order_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"order_id"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"amount"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"amount"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Review this refund request."&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="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"review_decision"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;decision&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When execution reaches &lt;code&gt;interrupt()&lt;/code&gt;, the workflow pauses and exposes the approval request to the application.&lt;/p&gt;

&lt;p&gt;The application can then display the details to a human reviewer.&lt;/p&gt;

&lt;p&gt;Once the reviewer makes a decision, the application resumes the workflow using &lt;code&gt;Command(resume=...)&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;langgraph&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;types&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;Command&lt;/span&gt;

&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;graph&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;invoke&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nc"&gt;Command&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;resume&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"approved"&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="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;"configurable"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="s2"&gt;"thread_id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"refund-1042"&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;This is intentionally a simplified example. In a real application, subsequent nodes must validate the review decision, verify authorization, and only execute the refund if all required conditions are satisfied.&lt;/p&gt;

&lt;p&gt;The important part is that the agent does not have to restart the entire workflow after human review.&lt;/p&gt;

&lt;p&gt;LangGraph's persistence mechanism allows execution state to be checkpointed and retrieved using the associated thread identifier.&lt;/p&gt;

&lt;p&gt;That makes it possible to support approval workflows where a human might respond several minutes or even hours after the agent initially requested approval.&lt;/p&gt;

&lt;h2&gt;
  
  
  Persistence Is What Makes This Useful in Real Applications
&lt;/h2&gt;

&lt;p&gt;Pausing an agent is one thing.&lt;/p&gt;

&lt;p&gt;Resuming it reliably is another.&lt;/p&gt;

&lt;p&gt;Think about how traditional request-response applications usually work.&lt;/p&gt;

&lt;p&gt;A user sends a request, the backend processes it, and a response is returned.&lt;/p&gt;

&lt;p&gt;But human approval workflows do not always fit into that model.&lt;/p&gt;

&lt;p&gt;A reviewer might be unavailable.&lt;/p&gt;

&lt;p&gt;A sensitive request might require investigation.&lt;/p&gt;

&lt;p&gt;An approval could remain pending overnight.&lt;/p&gt;

&lt;p&gt;Keeping a normal HTTP request open throughout this process would be a poor architectural choice.&lt;/p&gt;

&lt;p&gt;Instead, the application needs durable workflow state.&lt;/p&gt;

&lt;p&gt;LangGraph supports this through checkpointing.&lt;/p&gt;

&lt;p&gt;With an appropriate persistent checkpointer, the workflow can preserve its state while waiting for a decision.&lt;/p&gt;

&lt;p&gt;When the human responds, execution can continue using the saved context.&lt;/p&gt;

&lt;p&gt;This enables a more realistic architecture:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The agent prepares an action.&lt;/li&gt;
&lt;li&gt;The workflow pauses for approval.&lt;/li&gt;
&lt;li&gt;The application stores and displays the pending request.&lt;/li&gt;
&lt;li&gt;An authorized human reviews the action.&lt;/li&gt;
&lt;li&gt;The workflow resumes using the reviewer's decision.&lt;/li&gt;
&lt;li&gt;The system executes the approved operation and records the result.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For production environments, this also means thinking carefully about database-backed persistence, access control, checkpoint retention, and recovery after failures.&lt;/p&gt;

&lt;p&gt;A checkpoint is not just a convenience feature.&lt;/p&gt;

&lt;p&gt;For long-running agent workflows, it is part of the reliability architecture.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Engineering Detail That Is Easy to Miss
&lt;/h2&gt;

&lt;p&gt;Here is one of the most important things developers need to understand when working with LangGraph interrupts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Resuming an interrupted node can execute code from the beginning of that node again.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It does not necessarily continue from the exact Python statement immediately following the interrupt.&lt;/p&gt;

&lt;p&gt;That distinction matters.&lt;/p&gt;

&lt;p&gt;Imagine a node performs the following operations:&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;refund_node&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;create_refund_record&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;decision&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;interrupt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Approve refund?"&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="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"decision"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;decision&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At first glance, this may seem reasonable.&lt;/p&gt;

&lt;p&gt;The node creates a refund record and then requests approval.&lt;/p&gt;

&lt;p&gt;But there's a problem.&lt;/p&gt;

&lt;p&gt;When the node resumes, the logic before &lt;code&gt;interrupt()&lt;/code&gt; can run again.&lt;/p&gt;

&lt;p&gt;This means &lt;code&gt;create_refund_record()&lt;/code&gt; might execute a second time.&lt;/p&gt;

&lt;p&gt;Depending on the implementation, that could create duplicate database entries or trigger other unintended side effects.&lt;/p&gt;

&lt;p&gt;A safer approach is to pause before performing the side effect:&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;refund_review&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;decision&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;interrupt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s2"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Approve refund?"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s2"&gt;"amount"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"amount"&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="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"decision"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;decision&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The approved action can then be handled separately, with explicit validation and controlled execution.&lt;/p&gt;

&lt;p&gt;Even this separation is not sufficient on its own.&lt;/p&gt;

&lt;p&gt;External API calls can fail after completing an operation but before returning confirmation. Retries can then create duplicate effects.&lt;/p&gt;

&lt;p&gt;For that reason, production systems should also use mechanisms such as idempotency keys, database constraints, transactional checks, and read-before-write validation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reliable agent workflows must be designed for retries, interruptions, and partial failures—not just successful execution.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is one of those details that separates an interesting AI prototype from a dependable production system.&lt;/p&gt;

&lt;h2&gt;
  
  
  Human Approval Should Be Risk-Based
&lt;/h2&gt;

&lt;p&gt;One mistake developers can make is requiring human approval for every action.&lt;/p&gt;

&lt;p&gt;That might sound safe, but it creates another problem.&lt;/p&gt;

&lt;p&gt;If every small operation requires manual confirmation, the system becomes slow, inefficient, and frustrating.&lt;/p&gt;

&lt;p&gt;Imagine an AI support agent that needs permission every time it retrieves an order status or reads a knowledge-base article.&lt;/p&gt;

&lt;p&gt;There would be very little benefit to using an autonomous agent.&lt;/p&gt;

&lt;p&gt;A better approach is to classify actions based on risk.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Risk Level&lt;/th&gt;
&lt;th&gt;Example Action&lt;/th&gt;
&lt;th&gt;Suggested Control&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Low&lt;/td&gt;
&lt;td&gt;Retrieve order status&lt;/td&gt;
&lt;td&gt;Automated execution&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Low&lt;/td&gt;
&lt;td&gt;Search documentation&lt;/td&gt;
&lt;td&gt;Automated execution&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Medium&lt;/td&gt;
&lt;td&gt;Create an internal support ticket&lt;/td&gt;
&lt;td&gt;Validate inputs; review when necessary&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;High&lt;/td&gt;
&lt;td&gt;Issue a refund&lt;/td&gt;
&lt;td&gt;Human approval according to policy&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;High&lt;/td&gt;
&lt;td&gt;Modify sensitive customer information&lt;/td&gt;
&lt;td&gt;Authorization and human review&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Critical&lt;/td&gt;
&lt;td&gt;Delete records or transfer significant funds&lt;/td&gt;
&lt;td&gt;Strict authorization and potentially multiple approvals&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;These categories are illustrative. Actual thresholds should be defined according to organizational policies, regulatory requirements, and the potential consequences of each action.&lt;/p&gt;

&lt;p&gt;The purpose is to preserve automation where the risk is manageable and introduce oversight where the potential impact justifies it.&lt;/p&gt;

&lt;h2&gt;
  
  
  HITL Is Not a Replacement for Security
&lt;/h2&gt;

&lt;p&gt;There is another important consideration.&lt;/p&gt;

&lt;p&gt;Adding a human approval step does not automatically make an AI agent secure.&lt;/p&gt;

&lt;p&gt;What happens if the person approving the request is not authorized?&lt;/p&gt;

&lt;p&gt;What happens if the approval payload is modified?&lt;/p&gt;

&lt;p&gt;What happens if a previously approved action is executed twice?&lt;/p&gt;

&lt;p&gt;What happens if the underlying customer information changes while the workflow is waiting?&lt;/p&gt;

&lt;p&gt;These are application security and distributed-systems problems, not just AI problems.&lt;/p&gt;

&lt;p&gt;A production-ready HITL workflow should therefore include several safeguards.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Authorization:&lt;/strong&gt; Only designated reviewers should be allowed to approve particular actions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Validation:&lt;/strong&gt; The system should validate human-edited inputs rather than assuming that manually entered values are always correct.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Auditability:&lt;/strong&gt; Approval decisions should record relevant metadata, including who approved an action, when it was approved, and what was actually executed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Idempotency:&lt;/strong&gt; The same approval or execution request should not unintentionally cause repeated side effects.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;State verification:&lt;/strong&gt; Before executing a sensitive action, the application should confirm that important business conditions have not changed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Failure handling:&lt;/strong&gt; The workflow should define what happens when an approval expires, a reviewer becomes unavailable, or an external service fails.&lt;/p&gt;

&lt;p&gt;This aligns with broader security guidance from OWASP, which recommends least-privilege tool access, human oversight for high-risk actions, and independent validation of sensitive operations.&lt;/p&gt;

&lt;p&gt;In other words, HITL is one layer of a reliable system.&lt;/p&gt;

&lt;p&gt;It should work together with security policies, application-level authorization, and robust backend engineering.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Next Challenge: Designing Better Human Oversight
&lt;/h2&gt;

&lt;p&gt;As AI agents become more capable, I think one of the most interesting engineering challenges will be determining when an agent should act autonomously and when it should request assistance.&lt;/p&gt;

&lt;p&gt;We shouldn't assume that increasing autonomy always means increasing reliability.&lt;/p&gt;

&lt;p&gt;In some situations, additional autonomy reduces operational overhead.&lt;/p&gt;

&lt;p&gt;In others, it increases the consequences of mistakes.&lt;/p&gt;

&lt;p&gt;The challenge is to establish clear decision boundaries.&lt;/p&gt;

&lt;p&gt;A well-designed agent should understand its task and operate within the permissions assigned to it.&lt;/p&gt;

&lt;p&gt;A well-designed application should enforce those permissions independently of the agent's reasoning.&lt;/p&gt;

&lt;p&gt;And a well-designed HITL workflow should provide enough context for a human to make an informed decision without needing to reconstruct the agent's entire conversation.&lt;/p&gt;

&lt;p&gt;That final point matters more than it might initially appear.&lt;/p&gt;

&lt;p&gt;If a reviewer receives hundreds of requests that simply say "Approve this action?", the review process is unlikely to be very effective.&lt;/p&gt;

&lt;p&gt;A useful approval interface should explain what the agent intends to do, why it proposed the action, what information supports the recommendation, and what the consequences may be.&lt;/p&gt;

&lt;p&gt;Human oversight should be meaningful, not just another button in the workflow.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Building AI agents is becoming easier.&lt;/p&gt;

&lt;p&gt;Frameworks like LangGraph provide powerful primitives for managing state, orchestrating tools, and coordinating complex workflows.&lt;/p&gt;

&lt;p&gt;But building agents that people can actually trust requires more than connecting an LLM to a collection of tools.&lt;/p&gt;

&lt;p&gt;It requires thinking about permissions, failure recovery, accountability, persistence, and human decision-making.&lt;/p&gt;

&lt;p&gt;The most interesting part of agent engineering is no longer just getting an AI system to perform an action.&lt;/p&gt;

&lt;p&gt;It's designing the surrounding system so the right action happens under the right conditions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Autonomy is a capability. Reliability is an engineering responsibility.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Sometimes, the smartest thing an AI agent can do is execute a task independently.&lt;/p&gt;

&lt;p&gt;And sometimes, the smartest thing it can do is recognize that a human decision is required.&lt;/p&gt;

&lt;p&gt;Knowing the difference is what makes an AI agent useful in the real world.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>agents</category>
      <category>llm</category>
      <category>challenge</category>
    </item>
    <item>
      <title>Why "deny or allow" is the wrong model for MCP tool permissions: a verdict table with reason codes</title>
      <dc:creator>Correctover</dc:creator>
      <pubDate>Tue, 17 Nov 2026 06:42:35 +0000</pubDate>
      <link>https://dev.to/dshcorrectover/why-deny-or-allow-is-the-wrong-model-for-mcp-tool-permissions-a-verdict-table-with-reason-codes-29lk</link>
      <guid>https://dev.to/dshcorrectover/why-deny-or-allow-is-the-wrong-model-for-mcp-tool-permissions-a-verdict-table-with-reason-codes-29lk</guid>
      <description>&lt;p&gt;If you build agents on MCP, you have met this loop: a tool call should not run, the framework raises a permission error, the operator retries, and nobody can later explain what the system believed at the moment of decision.&lt;/p&gt;

&lt;p&gt;We spent the last months turning that loop into a deterministic decision table — published, replayable, and deliberately free of an LLM in the gatekeeping path. Three design choices surprised even us:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. ESCALATE is a verdict, not a failure.&lt;/strong&gt;&lt;br&gt;
Irreversible actions route to a human gate. That is not a denial with extra steps — folding it into a permission error is exactly how approval fatigue starts. The operator starts rubber-stamping because the system cannot say why it paused.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Attempt level, not action level.&lt;/strong&gt;&lt;br&gt;
Two attempts can share one logical action id (hello, lost-response retry). The decision table keys verdicts at the attempt level; the action id aggregates them for audit display, never for the decision itself. This matches the shape the crewAI community converged on in issue #6221 independently.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. unknown never folds.&lt;/strong&gt;&lt;br&gt;
If the evidence is partial, the verdict is unknown, with its own code. It does not round to PASS and it does not round to DENY. Audit consumers deserve the honest column.&lt;/p&gt;

&lt;p&gt;The table anchors 576 parameter-risk decisions across mutating and read-only axes, and every verdict ships with the reason code so a downstream system can distinguish:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;TOOL_DENIED_BY_POLICY — policy said no&lt;/li&gt;
&lt;li&gt;VERDICT_ESCALATE — parked for a human gate&lt;/li&gt;
&lt;li&gt;INTEGRITY_TAMPERED_EVIDENCE — the record itself failed integrity; trust nothing downstream of it&lt;/li&gt;
&lt;li&gt;SIDE_EFFECT_REPLAY_RISK — retried mutating call, judged at its own attempt&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It also runs as a GitHub App (Correctover Admission Verifier) so verdicts land in Checks with the same codes.&lt;/p&gt;

&lt;p&gt;The full dataset is CC0, the code is Apache-2.0, no CLA, no telemetry:&lt;br&gt;
&lt;a href="https://github.com/DSHCorrectover/correctover-recovery-admission" rel="noopener noreferrer"&gt;https://github.com/DSHCorrectover/correctover-recovery-admission&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If your framework or platform needs an independent look at its admission semantics — we do bounded review engagements, fixed price, every finding ships with a replay pack. &lt;a href="mailto:wangguigui@correctover.com"&gt;wangguigui@correctover.com&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>mcp</category>
      <category>security</category>
      <category>aiagents</category>
      <category>devops</category>
    </item>
    <item>
      <title>Companion apps for connected devices under the CRA</title>
      <dc:creator>Catalin Shipmark</dc:creator>
      <pubDate>Tue, 17 Nov 2026 06:42:29 +0000</pubDate>
      <link>https://dev.to/shipmark/companion-apps-for-connected-devices-under-the-cra-290l</link>
      <guid>https://dev.to/shipmark/companion-apps-for-connected-devices-under-the-cra-290l</guid>
      <description>&lt;p&gt;&lt;strong&gt;Short answer: the companion app is covered, and so is the manufacturer's cloud behind it.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  An app installed on the user's phone is software supplied to the user, so it is a product with digital elements when it is made available in the EU in the course of a commercial activity.&lt;/li&gt;
&lt;li&gt;  A product with digital elements includes its "remote data processing solutions" (Article 3(1)). The cloud service that lets the app control the device is one when it passes a three-part test.&lt;/li&gt;
&lt;li&gt;  The manufacturer is whoever markets the product under its own name or trademark (Article 3(13)), not whoever wrote the code.&lt;/li&gt;
&lt;li&gt;  That company carries the obligations for the app and the backend together: risk assessment, third-party component due diligence, vulnerability handling and reporting.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The setup this guide is about
&lt;/h2&gt;

&lt;p&gt;A company sells a connected device, such as a thermostat, a smart lock, a wearable or a toy. Users control it from an app, and the app talks to a cloud service that the company built or had built. Three things can be in scope: the device and its firmware, the app, and the backend. Teams often treat them as three separate projects with three separate owners. The CRA does not.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. The app is a product with digital elements
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://eur-lex.europa.eu/eli/reg/2024/2847/oj" rel="noopener noreferrer"&gt;Cyber Resilience Act&lt;/a&gt; (Regulation (EU) 2024/2847) applies to products with digital elements made available on the market whose intended purpose or reasonably foreseeable use includes a direct or indirect logical or physical data connection to a device or network (Article 2(1)). A companion app exists to connect to a device and a service, so that condition is met almost by definition.&lt;/p&gt;

&lt;p&gt;Article 3(1) defines a product with digital elements as "a software or hardware product and its remote data processing solutions", including software or hardware components placed on the market separately. According to the Commission guidance, software that is provided to and run on the user's side, such as an app downloaded from a store, is a product with digital elements, while a service used only through a browser is not on that basis alone. For the wider picture see &lt;a href="https://shipmark.eu/guides/cra-mobile-apps/" rel="noopener noreferrer"&gt;does the CRA apply to mobile apps?&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;"Made available" means supplied for distribution or use in the course of a commercial activity, "whether in return for payment or free of charge" (Article 3(22)). A companion app is usually free to download, but it supports a product that is sold, so the commercial context is normally obvious.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. The cloud behind the app: the three-part test
&lt;/h2&gt;

&lt;p&gt;Article 3(2) defines remote data processing as data processing at a distance for which the software is designed and developed by the manufacturer, or under the responsibility of the manufacturer, and the absence of which would prevent the product from performing one of its functions. The Commission guidance turns this into three cumulative questions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Does the processing happen at a distance?&lt;/li&gt;
&lt;li&gt; Would the product be unable to perform one of its functions without it?&lt;/li&gt;
&lt;li&gt; Was the software designed and developed by the manufacturer, or under its responsibility?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Recitals 11 and 12 give the two cases that matter here. If a mobile app needs an API or database from a service built by the manufacturer, that service is a remote data processing solution (recital 11). Cloud-enabled features from the manufacturer that let users control a device remotely, such as smart home devices, are within scope because they are part of how the product works (recital 12).&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Situation&lt;/th&gt;
&lt;th&gt;Position under the guidance&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;The manufacturer's own cloud service for onboarding and configuration of the device&lt;/td&gt;
&lt;td&gt;Likely part of the product&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The manufacturer's over-the-air update service&lt;/td&gt;
&lt;td&gt;Same reasoning: likely part of the product&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The manufacturer's own application running on rented infrastructure (IaaS or PaaS)&lt;/td&gt;
&lt;td&gt;Can still be remote data processing: who operates the servers is not the deciding factor&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Generic third-party storage or SaaS the manufacturer did not develop&lt;/td&gt;
&lt;td&gt;Normally not remote data processing, but a dependency to assess&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The Wi-Fi or cellular link itself&lt;/td&gt;
&lt;td&gt;A communication channel, not automatically remote data processing&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Back-end systems that do not interact with the product (CRM, HR tools)&lt;/td&gt;
&lt;td&gt;Not remote data processing&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;A manual alternative to a remote function (a physical switch)&lt;/td&gt;
&lt;td&gt;Does not automatically take the remote function out of the analysis&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;These rows summarise the guidance as reported by law firms and independent guides, and the examples in it are fictional archetypes. Check the text of the guidance for your own case. Note also that commentators describe the guidance as approved but dependent on formal adoption in all languages, so confirm its current status on the &lt;a href="https://digital-strategy.ec.europa.eu/en/library/commission-publishes-new-guidance-support-timely-cyber-resilience-act-implementation" rel="noopener noreferrer"&gt;Commission's page&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Who is the manufacturer?
&lt;/h2&gt;

&lt;p&gt;Article 3(13) defines the manufacturer as a person who develops or manufactures products with digital elements, or has them designed, developed or manufactured, and markets them under its own name or trademark, whether for payment, monetisation or free of charge. A device brand that commissions an agency to build the app, and publishes it under the brand's name in the stores, is the manufacturer of that app. The agency is a supplier, unless it also markets the app under its own name. The longer version of this question is in &lt;a href="https://shipmark.eu/guides/cra-manufacturer-agency-or-client/" rel="noopener noreferrer"&gt;agency or client: who is the manufacturer?&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The same applies to the backend. If the brand had it built by a contractor, it was developed "under the responsibility of the manufacturer", and the second and third conditions of the test above are met.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. One product or two?
&lt;/h2&gt;

&lt;p&gt;The sources I read do not say whether a device and its companion app are one product or two for conformity purposes. What the text does establish is narrower: Article 3(1) says software or hardware components placed on the market separately are products with digital elements, and the guidance says modules with their own functionality that can be bought or subscribed to separately are standalone products. An app that is distributed through an app store separately from the device may therefore need its own analysis. Treat this as an open point: decide it deliberately for each product line, write the reasoning into the technical documentation, and revisit it when the guidance is formally adopted or updated.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. What this means for the app team
&lt;/h2&gt;

&lt;p&gt;Because the manufacturer's obligations attach to the product and its remote data processing solutions together, an app team should not scope its CRA work at the app alone.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Obligation&lt;/th&gt;
&lt;th&gt;What to include for a companion app&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Risk assessment (Article 13(2))&lt;/td&gt;
&lt;td&gt;The app, the backend functions it depends on, the device link and the data flows between them. See &lt;a href="https://shipmark.eu/guides/cra-cybersecurity-risk-assessment/" rel="noopener noreferrer"&gt;the risk assessment template&lt;/a&gt;.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Third-party components (Article 13(5), 13(6))&lt;/td&gt;
&lt;td&gt;Due diligence on SDKs and libraries in the app and on third-party services the backend uses. A vulnerability found in a component must be reported to whoever maintains it.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Vulnerability handling (Article 13(8))&lt;/td&gt;
&lt;td&gt;Vulnerabilities of the product, including its components, must be handled effectively for the support period. A backend flaw is a product flaw.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Reporting (Article 14)&lt;/td&gt;
&lt;td&gt;Actively exploited vulnerabilities in the product must be notified within 24 hours (early warning), 72 hours (notification) and 14 days after a fix is available (final report). In our reading, an exploited flaw in the manufacturer's own cloud is within that duty, because the backend is part of the product. See &lt;a href="https://shipmark.eu/guides/cra-vulnerability-reporting/" rel="noopener noreferrer"&gt;the reporting guide&lt;/a&gt;.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Support period&lt;/td&gt;
&lt;td&gt;One period per product version, covering the app and the services it needs. See &lt;a href="https://shipmark.eu/guides/cra-support-period/" rel="noopener noreferrer"&gt;the support period guide&lt;/a&gt;.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A practical way to start is the one-page map per remote function that SCHUTZWERK recommends: what the device does without it, who is responsible for the software, which data flows through it, which dependencies it has, and where its documentation is kept. A short list of the app's remote functions (pairing, firmware update, remote control, history sync) gets you most of the way.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Try it on your own app:&lt;/strong&gt; the &lt;a href="https://shipmark.eu/scan/" rel="noopener noreferrer"&gt;free Shipmark scanner&lt;/a&gt; builds a CycloneDX SBOM from a lockfile in the browser and checks it against OSV.dev. Not sure the CRA applies? Use the &lt;a href="https://shipmark.eu/tools/cra-checker/" rel="noopener noreferrer"&gt;six-question CRA check&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Questions teams ask
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Is a companion app covered if it is free?&lt;/strong&gt; A price is not required. Article 3(22) covers supply "in the course of a commercial activity, whether in return for payment or free of charge", and the app supports a product that is sold.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Is our cloud API covered if it runs on a hyperscaler?&lt;/strong&gt; It can be. The guidance says the operator of the servers is not the deciding factor. The test is whether you designed and developed the software, or had it developed under your responsibility, and whether a product function depends on it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Is the third-party service we use for push notifications or storage covered?&lt;/strong&gt; Generic third-party services you did not develop are normally not your remote data processing solution. They remain dependencies that your risk assessment and Article 13(5) due diligence must cover.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://eur-lex.europa.eu/eli/reg/2024/2847/oj" rel="noopener noreferrer"&gt;Regulation (EU) 2024/2847 (Cyber Resilience Act), EUR-Lex&lt;/a&gt;: Articles 2, 3, 13, 14 and recitals 11 and 12, read via the &lt;a href="https://www.springlex.eu/en/packages/cra/cra-regulation/article-3/" rel="noopener noreferrer"&gt;Springlex consolidated text&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://digital-strategy.ec.europa.eu/en/library/commission-publishes-new-guidance-support-timely-cyber-resilience-act-implementation" rel="noopener noreferrer"&gt;European Commission: guidance to support the implementation of the CRA&lt;/a&gt;, C(2026) 5252, 27 July 2026.&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.schutzwerk.com/en/blog/cra-guidance-2026/" rel="noopener noreferrer"&gt;SCHUTZWERK: the new CRA guidance in practice&lt;/a&gt;, on remote data processing and the per-function map.&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://atb.law/en/blog-post/cyber-resilience-act-guidance-update-2026/" rel="noopener noreferrer"&gt;ATB Law: Cyber Resilience Act, the final EU guidance 2026&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.cyberresilienceact.eu/commission-guidance.html" rel="noopener noreferrer"&gt;cyberresilienceact.eu: Commission guidance overview&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This guide summarises EU law and non-binding Commission guidance for practical use. It is not legal advice. Related: &lt;a href="https://shipmark.eu/guides/cra-mobile-apps/" rel="noopener noreferrer"&gt;Does the CRA apply to mobile apps?&lt;/a&gt; · &lt;a href="https://shipmark.eu/guides/cra-manufacturer-agency-or-client/" rel="noopener noreferrer"&gt;Who is the manufacturer?&lt;/a&gt; · &lt;a href="https://shipmark.eu/guides/cra-cybersecurity-risk-assessment/" rel="noopener noreferrer"&gt;CRA risk assessment template&lt;/a&gt; · &lt;a href="https://shipmark.eu/guides/cra-vulnerability-reporting/" rel="noopener noreferrer"&gt;CRA vulnerability reporting&lt;/a&gt; · &lt;a href="https://shipmark.eu/guides/cra-support-period/" rel="noopener noreferrer"&gt;The CRA support period&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://shipmark.eu/guides/cra-companion-apps/" rel="noopener noreferrer"&gt;shipmark.eu&lt;/a&gt;, where the guide is kept up to date. More guides for app teams: &lt;a href="https://shipmark.eu/guides/" rel="noopener noreferrer"&gt;shipmark.eu/guides&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>security</category>
      <category>mobile</category>
      <category>android</category>
      <category>ios</category>
    </item>
    <item>
      <title>Phương Thức equals() và hashCode() trong Java</title>
      <dc:creator>Tiểu Share</dc:creator>
      <pubDate>Tue, 17 Nov 2026 06:41:50 +0000</pubDate>
      <link>https://dev.to/tieushare/phuong-thuc-equals-va-hashcode-trong-java-36na</link>
      <guid>https://dev.to/tieushare/phuong-thuc-equals-va-hashcode-trong-java-36na</guid>
      <description>&lt;p&gt;&lt;span id="docs-internal-guid-85d314e8-7fff-ab86-7ef6-7d3f7a7ba47a"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;"Trong Java, equals() và hashCode() là hai phương thức quan trọng được sử dụng để so sánh các đối tượng và tạo mã băm tương ứng. Sự phối hợp giữa chúng đảm bảo tính nhất quán trong các cấu trúc dữ liệu như HashMap, HashSet, và HashTable. Dưới đây là những điều cơ bản bạn cần biết về &lt;b&gt;&lt;a href="https://www.tieushare.com/2026/10/phuong-thuc-equals-hashcode-trong-java.html" rel="noopener noreferrer"&gt;equals() và hashCode() trong Java&lt;/a&gt;&lt;/b&gt;:"&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;&lt;br&gt;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;&lt;a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgC2URK1o_oCnoIOrLXAsWxG0Qy8Lg1GDNSS6b3_CdPaD-8JwcqQf31MIA7cnUR2T7oUJiYpJxd-2Qn9wMT7KmKEpEgeX7wVPo2HjrBbj6m6fH4wliknozffy-5xc1lF2SiN6C5VKelKZ_-954Ct_eJuOM0AKT1fBaDhTSTyrNAqrtKDh4hNSprSQBD_UQ/s1600/image.png" rel="noopener noreferrer"&gt;&lt;img alt="Phương Thức equals() và hashCode() trong Java" height="360" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblogger.googleusercontent.com%2Fimg%2Fb%2FR29vZ2xl%2FAVvXsEgC2URK1o_oCnoIOrLXAsWxG0Qy8Lg1GDNSS6b3_CdPaD-8JwcqQf31MIA7cnUR2T7oUJiYpJxd-2Qn9wMT7KmKEpEgeX7wVPo2HjrBbj6m6fH4wliknozffy-5xc1lF2SiN6C5VKelKZ_-954Ct_eJuOM0AKT1fBaDhTSTyrNAqrtKDh4hNSprSQBD_UQ%2Fw640-h360%2Fimage.png" title="Phương Thức equals() và hashCode() trong Java" width="640"&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Phương Thức equals() và hashCode() trong Java&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;
&lt;span&gt;&lt;br&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;

&lt;h1&gt;&lt;span&gt;&lt;span&gt;Ⅰ. Lớp java.lang.Object: Cốt lõi của mọi đối tượng trong Java&lt;/span&gt;&lt;/span&gt;&lt;/h1&gt;
&lt;p&gt;&lt;span&gt;&lt;a href="https://www.tieushare.com/2026/10/phuong-thuc-equals-hashcode-trong-java.html" rel="noopener noreferrer"&gt;&lt;b&gt;Lớp java.lang.Object&lt;/b&gt;&lt;/a&gt; là lớp gốc của tất cả các lớp trong Java. Điều này có nghĩa là mọi lớp mà bạn tạo ra, dù trực tiếp hay gián tiếp, đều kế thừa từ lớp Object. Vì thế, mọi đối tượng trong Java đều có sẵn các phương thức được định nghĩa trong lớp Object.&lt;/span&gt;&lt;/p&gt;
&lt;h2&gt;&lt;span&gt;&lt;span&gt;Tại sao lớp Object lại quan trọng?&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;&lt;span&gt;↳ Cốt lõi của hệ thống: &lt;/span&gt;&lt;span&gt;Object là nền tảng để xây dựng các lớp khác. Nó cung cấp các phương thức cơ bản nhất mà mọi đối tượng cần có.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ Đa hình: &lt;/span&gt;&lt;span&gt;Nhờ cơ chế kế thừa, các lớp con có thể ghi đè (override) các phương thức của lớp cha, tạo ra tính đa hình. Điều này cho phép chúng ta viết code linh hoạt và mở rộng.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ Garbage Collection: &lt;/span&gt;&lt;span&gt;Lớp Object cũng đóng một vai trò quan trọng trong cơ chế thu gom rác của Java. Khi một đối tượng không còn được tham chiếu đến, nó sẽ được bộ thu gom rác tự động xóa khỏi bộ nhớ.&lt;/span&gt;&lt;/p&gt;
&lt;h2&gt;&lt;span&gt;&lt;span&gt;Các phương thức của lớp Objects&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;&lt;span&gt;↳ static &amp;lt;T&amp;gt; int compare(T a, T b, Comparator&amp;lt;? super T&amp;gt; c): &lt;/span&gt;&lt;span&gt;So sánh hai đối tượng a và b bằng cách sử dụng bộ so sánh c. Nếu hai đối tượng giống nhau, trả về 0; nếu không, trả về kết quả so sánh.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ static boolean deepEquals(Object a, Object b): &lt;/span&gt;&lt;span&gt;Kiểm tra xem hai đối tượng có bằng nhau khi so sánh sâu (so sánh tất cả các phần tử của các đối tượng lồng ghép không). Nếu có, trả về true; nếu không, trả về false.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ static boolean equals(Object a, Object b): &lt;/span&gt;&lt;span&gt;So sánh hai đối tượng a và b để xem chúng có bằng nhau không. Nếu có, trả về true; nếu không, trả về false.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ static int hash(Object... values): &lt;/span&gt;&lt;span&gt;Sinh mã băm cho một tập hợp các giá trị đầu vào. Ví dụ: nếu bạn có nhiều giá trị và muốn tạo mã băm cho tất cả, bạn có thể dùng phương thức này.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ static int hashCode(Object o): &lt;/span&gt;&lt;span&gt;Trả về mã băm của đối tượng o. Nếu o không phải là null, trả về mã băm của nó; nếu o là null, trả về 0.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ static boolean isNull(Object obj): &lt;/span&gt;&lt;span&gt;Kiểm tra xem đối tượng obj có phải là null không. Nếu có, trả về true; nếu không, trả về false.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ static boolean nonNull(Object obj): &lt;/span&gt;&lt;span&gt;Kiểm tra xem đối tượng obj có phải là khác null không. Nếu không phải là null, trả về true; nếu là null, trả về false.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ static &amp;lt;T&amp;gt; requireNonNull(T obj): &lt;/span&gt;&lt;span&gt;Đảm bảo rằng đối tượng obj không phải là null. Nếu là null, ném ra ngoại lệ NullPointerException.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ static &amp;lt;T&amp;gt; requireNonNull(T obj, String message): &lt;/span&gt;&lt;span&gt;Đảm bảo rằng đối tượng obj không phải là null. Nếu là null, ném ra ngoại lệ NullPointerException với thông báo lỗi được chỉ định.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ static &amp;lt;T&amp;gt; requireNonNull(T obj, Supplier&amp;lt;String&amp;gt; messageSupplier): &lt;/span&gt;&lt;span&gt;Đảm bảo rằng đối tượng obj không phải là null. Nếu là null, ném ra ngoại lệ NullPointerException với thông báo lỗi do messageSupplier cung cấp.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ static String toString(Object o): &lt;/span&gt;&lt;span&gt;Chuyển đổi đối tượng o thành chuỗi. Nếu o không phải là null, gọi phương thức toString của nó; nếu o là null, trả về chuỗi "null".&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ static String toString(Object o, String nullDefault): &lt;/span&gt;&lt;span&gt;Chuyển đổi đối tượng o thành chuỗi. Nếu o không phải là null, gọi phương thức toString của nó; nếu o là null, trả về chuỗi nullDefault.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Phương thức equals() và hashCode() là hai phương thức quan trọng được cung cấp bởi lớp Object để so sánh các đối tượng. Vì lớp Object là lớp cha của tất cả các đối tượng Java, nên tất cả các đối tượng đều kế thừa triển khai mặc định của hai phương thức này. Trong phần này, chúng ta sẽ xem xét chi tiết về các phương thức equals() và hashCode(), mối liên hệ giữa chúng và cách chúng ta có thể triển khai hai phương thức này trong Java.&lt;/span&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span&gt;&lt;span&gt;Ⅱ. Phương thức equals()&lt;/span&gt;&lt;/span&gt;&lt;/h1&gt;
&lt;p&gt;&lt;span&gt;&lt;b&gt;&lt;a href="https://www.tieushare.com/2026/10/phuong-thuc-equals-hashcode-trong-java.html" rel="noopener noreferrer"&gt;Phương thức equals() trong Java&lt;/a&gt;&lt;/b&gt; được sử dụng để kiểm tra xem hai đối tượng có "bằng nhau" hay không.&lt;/span&gt;&lt;/p&gt;
&lt;h2&gt;&lt;span&gt;&lt;span&gt;Hành vi mặc định của phương thức equals()&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;&lt;span&gt;↳ So sánh tham chiếu: &lt;/span&gt;&lt;span&gt;Theo mặc định, phương thức equals() chỉ kiểm tra xem hai đối tượng có cùng địa chỉ bộ nhớ hay không. Nói cách khác, nó kiểm tra xem hai biến đang trỏ đến cùng một đối tượng hay không.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ Không so sánh nội dung: &lt;/span&gt;&lt;span&gt;Phương thức mặc định không so sánh nội dung của hai đối tượng.&lt;/span&gt;&lt;/p&gt;
&lt;h2&gt;&lt;span&gt;&lt;span&gt;Các đặc tính của phương thức equals()&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;&lt;span&gt;Để đảm bảo tính nhất quán, phương thức equals() phải tuân theo các quy tắc tham chiếu đối tượng không null sau:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ Phản xạ (Reflexive): &lt;/span&gt;&lt;span&gt;Đối với bất kỳ giá trị tham chiếu không null x, x.equals(x) phải trả về true.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ Đối xứng (Symmetric): &lt;/span&gt;&lt;span&gt;Đối với bất kỳ giá trị tham chiếu không null x và y, x.equals(y) phải trả về true nếu và chỉ nếu y.equals(x) trả về true.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ Bắc cầu (Transitive): &lt;/span&gt;&lt;span&gt;Đối với bất kỳ giá trị tham chiếu không null x, y và z, nếu x.equals(y) trả về true và y.equals(z) trả về true, thì x.equals(z) phải trả về true.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ Nhất quán (Consistent): &lt;/span&gt;&lt;span&gt;Đối với bất kỳ giá trị tham chiếu không null x và y, nhiều lần gọi x.equals(y) nhất quán trả về true hoặc nhất quán trả về false, với điều kiện không có thông tin nào được sử dụng trong so sánh equals trên các đối tượng bị sửa đổi.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ Không so sánh với null (Non-nullity): &lt;/span&gt;&lt;span&gt;Đối với bất kỳ giá trị tham chiếu không null x, x.equals(null) phải trả về false.&lt;/span&gt;&lt;/p&gt;
&lt;h2&gt;&lt;span&gt;&lt;span&gt;Cú pháp của phương thức equals():&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;br&gt;
&lt;b&gt;Cú Pháp&lt;/b&gt;

&lt;pre&gt;&lt;code&gt;public boolean equals(Object obj)&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;span&gt;&lt;b&gt;Giải thích từng phần:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ Tham số obj: &lt;/span&gt;&lt;span&gt;Đối tượng tham chiếu cần được so sánh.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ Trả về: &lt;/span&gt;&lt;span&gt;true nếu hai đối tượng giống nhau, ngược lại trả về false&lt;/span&gt;&lt;/p&gt;
&lt;h3&gt;&lt;span&gt;Dưới đây là một ví dụ minh họa về phương thức equals() trong Java. Phương thức equals() thường được sử dụng để so sánh hai đối tượng xem chúng có bằng nhau không, dựa trên các tiêu chí bạn định nghĩa.&lt;/span&gt;&lt;/h3&gt;
&lt;b&gt;Person.java&lt;/b&gt;
&lt;pre&gt;&lt;code&gt;import java.util.Objects;

class Person {
  private String name;
  private int age;

  // Constructor
  public Person(String name, int age) {
      this.name = name;
      this.age = age;
  }

  // Ghi đè phương thức equals()
  @Override
  public boolean equals(Object obj) {
      // Nếu so sánh chính đối tượng hiện tại
      if (this == obj) {
          return true;
      }
      // Nếu obj là null hoặc không cùng kiểu với Person
      if (obj == null || getClass() != obj.getClass()) {
          return false;
      }
      // Ép kiểu obj về kiểu Person để so sánh
      Person person = (Person) obj;
      // So sánh tên và tuổi
      return age == person.age &amp;amp;&amp;amp; name.equals(person.name);
  }

  // Phương thức hashCode() cũng nên được ghi đè khi ghi đè equals()
  @Override
  public int hashCode() {
      return Objects.hash(name, age);
  }
}

public class Main {
  public static void main(String[] args) {
      Person person1 = new Person("Dương", 25);
      Person person2 = new Person("Dương", 25);
      Person person3 = new Person("Trường", 30);

      // So sánh person1 và person2
      System.out.println("person1 và person2 bằng nhau: " + person1.equals(person2)); // Kết quả: true

      // So sánh person1 và person3
      System.out.println("person1 và person3 bằng nhau: " + person1.equals(person3)); // Kết quả: false
  }
}&lt;/code&gt;&lt;/pre&gt;
      
&lt;p&gt;&lt;span&gt;&lt;span id="docs-internal-guid-6312f6eb-7fff-1a50-b17f-c1dc6278b43f"&gt;&lt;span&gt;&lt;b&gt;Kết quả của chương trình là: &lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;person1 và person2 bằng nhau: true
person1 và person3 bằng nhau: false&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;span&gt;Hy vọng ví dụ này giúp bạn hiểu rõ hơn về cách sử dụng phương thức equals() trong Java!&lt;/span&gt;&lt;/p&gt;
&lt;h3&gt;&lt;span&gt;Dưới đây là ví dụ về cách so sánh chuỗi trong Java để thấy sự khác nhau giữa phương thức equals() và toán tử ==.&lt;/span&gt;&lt;/h3&gt;
&lt;b&gt;Main.java&lt;/b&gt;
&lt;pre&gt;&lt;code&gt;public class Main {
    public static void main(String[] args) {
        // Tạo hai chuỗi bằng cách sử dụng ký tự chuỗi
        String str1 = "Hello";
        String str2 = "Hello";

        // Tạo hai chuỗi bằng cách sử dụng từ khóa new
        String str3 = new String("Hello");
        String str4 = new String("Hello");

        // So sánh chuỗi bằng toán tử ==
        System.out.println("So sánh str1 và str2 bằng toán tử ==: " + (str1 == str2)); // Kết quả: true
        System.out.println("So sánh str1 và str3 bằng toán tử ==: " + (str1 == str3)); // Kết quả: false
        System.out.println("So sánh str3 và str4 bằng toán tử ==: " + (str3 == str4)); // Kết quả: false

        // So sánh chuỗi bằng phương thức equals()
        System.out.println("So sánh str1 và str2 bằng phương thức equals(): " + str1.equals(str2)); // Kết quả: true
        System.out.println("So sánh str1 và str3 bằng phương thức equals(): " + str1.equals(str3)); // Kết quả: true
        System.out.println("So sánh str3 và str4 bằng phương thức equals(): " + str3.equals(str4)); // Kết quả: true
    }
} &lt;/code&gt;&lt;/pre&gt;
      
&lt;p&gt;&lt;span&gt;&lt;span id="docs-internal-guid-6312f6eb-7fff-1a50-b17f-c1dc6278b43f"&gt;&lt;span&gt;&lt;b&gt;Kết quả của chương trình là: &lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;So sánh str1 và str2 bằng toán tử ==: true
So sánh str1 và str3 bằng toán tử ==: false
So sánh str3 và str4 bằng toán tử ==: false
So sánh str1 và str2 bằng phương thức equals(): true
So sánh str1 và str3 bằng phương thức equals(): true
So sánh str3 và str4 bằng phương thức equals(): true&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;&lt;span&gt;Giải thích đoạn mã trên:&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;&lt;span&gt;&lt;b&gt;Tạo chuỗi:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;str1 và str2 được tạo ra bằng cách sử dụng ký tự chuỗi. Java tối ưu hóa bộ nhớ bằng cách lưu trữ các chuỗi giống nhau trong một vùng nhớ chung gọi là "string pool". Do đó, str1 và str2 sẽ trỏ đến cùng một đối tượng chuỗi trong bộ nhớ.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ &lt;/span&gt;&lt;span&gt;str3 và str4 được tạo ra bằng từ khóa new, nghĩa là mỗi lần sẽ tạo ra một đối tượng chuỗi mới trong bộ nhớ heap.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;b&gt;So sánh chuỗi bằng Toán Tử ==:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ &lt;/span&gt;&lt;span&gt;Toán tử == so sánh tham chiếu của hai đối tượng, tức là so sánh xem hai đối tượng có cùng trỏ đến một vùng nhớ hay không.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ &lt;/span&gt;&lt;span&gt;str1 == str2 sẽ trả về true vì cả hai đều trỏ đến cùng một đối tượng trong ""string pool".&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ &lt;/span&gt;&lt;span&gt;str1 == str3 và str3 == str4 sẽ trả về false vì chúng trỏ đến các đối tượng khác nhau trong bộ nhớ heap.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;b&gt;So sánh chuỗi bằng phương thức equals():&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ &lt;/span&gt;&lt;span&gt;Phương thức equals() so sánh nội dung của hai đối tượng chuỗi.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ &lt;/span&gt;&lt;span&gt;str1.equals(str2), str1.equals(str3) và str3.equals(str4) đều trả về true vì nội dung của các chuỗi đều giống nhau.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;b&gt;Kết luận:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ &lt;/span&gt;&lt;span&gt;Toán tử == so sánh tham chiếu của các đối tượng.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ &lt;/span&gt;&lt;span&gt;Phương thức equals() so sánh nội dung của các đối tượng.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Hy vọng ví dụ này giúp bạn hiểu rõ sự khác nhau giữa toán tử == và phương thức equals() trong Java khi so sánh chuỗi!&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Phương thức contains(Object) của interface List trong Java sử dụng phương thức equals() để kiểm tra xem một đối tượng cụ thể có tồn tại trong danh sách hay không. Khi bạn gọi contains(Object) trên một danh sách, nó sẽ duyệt qua tất cả các phần tử trong danh sách và sử dụng phương thức equals() của đối tượng để so sánh từng phần tử với đối tượng bạn muốn kiểm tra.&lt;/span&gt;&lt;/p&gt;
&lt;h3&gt;&lt;span&gt;Dưới đây là ví dụ về cách sử dụng phương thức contains(Object) với một danh sách các đối tượng Person, trong đó phương thức equals() của lớp Person đã được ghi đè:&lt;/span&gt;&lt;/h3&gt;

&lt;p&gt;&lt;b&gt;Person.java&lt;/b&gt;

&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;import java.util.ArrayList;
import java.util.List;

class Person {
    private String name;
    private int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    // Ghi đè phương thức equals() để so sánh dựa trên thuộc tính name và age
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        Person person = (Person) obj;
        return age == person.age &amp;amp;&amp;amp; name.equals(person.name);
    }

    // Ghi đè phương thức hashCode() để hỗ trợ việc so sánh trong các collection
    @Override
    public int hashCode() {
        int result = name.hashCode();
        result = 31 * result + age;
        return result;
    }

    @Override
    public String toString() {
        return "Person{name='" + name + "', age=" + age + '}';
    }
}

public class Main {
    public static void main(String[] args) {
        List personList = new ArrayList&amp;lt;&amp;gt;();

        Person person1 = new Person("Dương", 30);
        Person person2 = new Person("Trường", 25);
        Person person3 = new Person("Dương", 30); // Có cùng thuộc tính với person1

        personList.add(person1);
        personList.add(person2);

        // Kiểm tra xem person3 có tồn tại trong danh sách hay không
        boolean containsPerson3 = personList.contains(person3); // Kết quả: true
        System.out.println("Danh sách có chứa person3: " + containsPerson3);

        // Thêm person3 vào danh sách
        personList.add(person3);

        // In ra các phần tử trong danh sách
        System.out.println("Các phần tử trong danh sách:");
        for (Person person : personList) {
            System.out.println(person);
        }
    }
}&lt;/code&gt;&lt;/pre&gt;
      
&lt;p&gt;&lt;span&gt;&lt;span id="docs-internal-guid-6312f6eb-7fff-1a50-b17f-c1dc6278b43f"&gt;&lt;span&gt;&lt;b&gt;Kết quả của chương trình là: &lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Danh sách có chứa person3: true
Các phần tử trong danh sách:
Person{name='Dương', age=30}
Person{name='Trường', age=25}
Person{name='Dương', age=30}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;span&gt;Phương thức contains(Object) của List trong Java sử dụng phương thức equals() của đối tượng để kiểm tra sự tồn tại của đối tượng trong danh sách. Khi equals() được ghi đè đúng cách, contains(Object) sẽ hoạt động chính xác, giúp bạn kiểm tra sự tồn tại của các đối tượng trong danh sách dựa trên các tiêu chí so sánh đã định nghĩa trong equals().&lt;/span&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span&gt;&lt;span&gt;Ⅲ. Phương thức hashCode()&lt;/span&gt;&lt;/span&gt;&lt;/h1&gt;
&lt;p&gt;&lt;span&gt;&lt;b&gt;&lt;a href="https://www.tieushare.com/2026/10/phuong-thuc-equals-hashcode-trong-java.html" rel="noopener noreferrer"&gt;Phương thức hashCode() trong Java&lt;/a&gt;&lt;/b&gt; trả về một giá trị số nguyên (hash code) cho một đối tượng. Giá trị này được sử dụng để hỗ trợ các cấu trúc dữ liệu như bảng băm (hash table) như HashMap.&lt;/span&gt;&lt;/p&gt;
&lt;h2&gt;&lt;span&gt;&lt;span&gt;Các đặc tính của phương thức hashCode()&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;&lt;span&gt;Để đảm bảo tính nhất quán, phương thức hashCode() tuân theo các quy tắc sau:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ Nhất quán (Consistent): &lt;/span&gt;&lt;span&gt;Khi gọi phương thức hashCode() trên cùng một đối tượng nhiều lần trong cùng một chương trình, kết quả trả về phải là cùng một số nguyên, trừ khi thông tin được sử dụng để so sánh bằng phương thức equals() thay đổi.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ Quan hệ với equals(): &lt;/span&gt;&lt;span&gt;Nếu hai đối tượng bằng nhau theo phương thức equals(), thì chúng phải có cùng một giá trị hash code.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ Không yêu cầu khác biệt (Non-required uniqueness): &lt;/span&gt;&lt;span&gt;Nếu hai đối tượng khác nhau theo phương thức equals(), thì không bắt buộc chúng phải có giá trị hash code khác nhau. Tuy nhiên, việc tạo ra các giá trị hash code khác nhau cho các đối tượng khác nhau sẽ giúp cải thiện hiệu suất của bảng băm.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ Giá trị mặc định: &lt;/span&gt;&lt;span&gt;Phương thức hashCode() mặc định của lớp Object thường trả về một giá trị dựa trên địa chỉ bộ nhớ của đối tượng, nhưng điều này không bắt buộc.&lt;/span&gt;&lt;/p&gt;
&lt;h2&gt;&lt;span&gt;&lt;span&gt;Cú pháp của phương thức hashCode()&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;b&gt;Cú Pháp&lt;/b&gt;&lt;pre&gt;&lt;code&gt;public int hashCode()&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;&lt;span&gt;↳ Trả về: &lt;/span&gt;&lt;span&gt;Trả về giá trị mã băm cho các đối tượng đã cho.&lt;/span&gt;&lt;/p&gt;
&lt;h3&gt;&lt;span&gt;Dưới đây là một ví dụ về cách triển khai phương thức hashCode() và equals() trong một lớp Java. Chúng ta sẽ tạo một lớp Person với các thuộc tính name và age, và triển khai cả hai phương thức hashCode() và equals() để đảm bảo rằng hai đối tượng Person có cùng name và age được coi là bằng nhau.&lt;/span&gt;&lt;/h3&gt;
&lt;b&gt;Example.java&lt;/b&gt;

&lt;pre&gt;&lt;code&gt;public class Example {
  public static void main(String[] args) {
      // Tạo các đối tượng SinhVien
      SinhVien sv1 = new SinhVien("Nguyễn Văn A", 20, "K62");
      SinhVien sv2 = new SinhVien("Trần Thị B", 19, "K62");

      // In thông tin sinh viên
      sv1.inThongTin();
      System.out.println();
      sv2.inThongTin();
  }
}&lt;/code&gt;&lt;/pre&gt;
      
       
      &lt;p&gt;&lt;span&gt;&lt;span id="docs-internal-guid-6312f6eb-7fff-1a50-b17f-c1dc6278b43f"&gt;&lt;span&gt;&lt;b&gt;Kết quả của chương trình là: &lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;person1 equals person2: true
person1 hashCode: 2058250920
person2 hashCode: 2058250920
person1 equals person3: false
person1 hashCode: 2058250920
person3 hashCode: 97582&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;span&gt;Khi bạn chạy chương trình, bạn sẽ thấy rằng person1 và person2 có cùng giá trị mã băm và được coi là bằng nhau bởi phương thức equals(). Tuy nhiên, person1 và person3 có các giá trị mã băm khác nhau và không bằng nhau theo phương thức equals().&lt;/span&gt;&lt;/p&gt;
&lt;h1&gt;&lt;span&gt;&lt;span&gt;Ⅳ. Mối quan hệ giữa hashCode() và equals() trong Java&lt;/span&gt;&lt;/span&gt;&lt;/h1&gt;
&lt;p&gt;&lt;span&gt;hashCode() và equals() là hai phương thức cơ bản trong Java, được sử dụng để so sánh và xác định tính duy nhất của các đối tượng. Mặc dù chúng có chức năng khác nhau nhưng lại có mối liên hệ chặt chẽ với nhau để đảm bảo tính nhất quán và hiệu quả của các cấu trúc dữ liệu trong Java.&lt;/span&gt;&lt;/p&gt;
&lt;h2&gt;&lt;span&gt;&lt;span&gt;Mối quan hệ giữa hai phương thức:&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;&lt;span&gt;↳ Nguyên tắc: &lt;/span&gt;&lt;span&gt;Nếu hai đối tượng bằng nhau theo equals(), thì chúng phải có cùng một giá trị hash. Điều này đảm bảo rằng các đối tượng bằng nhau sẽ luôn được nhóm lại cùng nhau trong bảng băm.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ Không bắt buộc: &lt;/span&gt;&lt;span&gt;Nếu hai đối tượng không bằng nhau theo equals(), thì chúng không nhất thiết phải có giá trị hash khác nhau. Tuy nhiên, để tăng hiệu suất của bảng băm, các đối tượng khác nhau nên có giá trị hash khác nhau càng nhiều càng tốt.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Lưu ý: &lt;/span&gt;&lt;span&gt;Theo tài liệu của Java, cả hai phương thức equals() và hashCode() cần được ghi đè để có được cơ chế so sánh đầy đủ; chỉ sử dụng equals() là không đủ. Điều này có nghĩa là, nếu bạn ghi đè phương thức equals(), bạn cũng phải ghi đè phương thức hashCode().&lt;/span&gt;&lt;/p&gt;
&lt;h3&gt;&lt;span&gt;Tại sao cần ghi đè cả hai phương thức?&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;&lt;span&gt;↳ Đảm bảo tính nhất quán: &lt;/span&gt;&lt;span&gt;Khi ghi đè equals(), việc ghi đè hashCode() là cần thiết để đảm bảo rằng hai đối tượng bằng nhau theo equals() sẽ luôn có cùng một giá trị hash.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ Tăng hiệu suất: &lt;/span&gt;&lt;span&gt;Một hàm hashCode() được thiết kế tốt có thể giúp giảm thiểu các cuộc gọi đến equals(), đặc biệt là trong các cấu trúc dữ liệu lớn.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Nếu bạn ghi đè equals() mà không ghi đè hashCode() hoặc ngược lại, bạn sẽ gặp phải các vấn đề về tính nhất quán và hiệu suất trong các cấu trúc dữ liệu dựa trên băm (như HashMap, HashSet). Dưới đây là những điều có thể xảy ra trong từng trường hợp:&lt;/span&gt;&lt;/p&gt;
&lt;h2&gt;&lt;span&gt;&lt;span&gt;Ví dụ minh họa ghi đè cả hai phương thức equals() và hashCode():&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;b&gt;Example.java&lt;/b&gt;
&lt;pre&gt;&lt;code&gt;import java.util.HashSet;
import java.util.Objects;

class Person {
    private String name;
    private int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return age == person.age &amp;amp;&amp;amp; Objects.equals(name, person.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }
}

public class Example {
    public static void main(String[] args) {
        HashSet set = new HashSet&amp;lt;&amp;gt;();
        Person person1 = new Person("Alice", 30);
        Person person2 = new Person("Alice", 30);

        set.add(person1);
        set.add(person2);

        System.out.println("Kích thước của set: " + set.size());
    }
}&lt;/code&gt;&lt;/pre&gt;
      
&lt;p&gt;&lt;span&gt;&lt;span id="docs-internal-guid-6312f6eb-7fff-1a50-b17f-c1dc6278b43f"&gt;&lt;span&gt;&lt;b&gt;Kết quả của chương trình là: &lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Kích thước của set: 1&lt;/code&gt;&lt;/pre&gt;


&lt;h2&gt;&lt;span&gt;&lt;span&gt;Ghi đè equals() mà không ghi đè hashCode()&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;&lt;span&gt;Nếu bạn chỉ ghi đè phương thức equals() mà không ghi đè phương thức hashCode(), hai đối tượng có thể được coi là bằng nhau theo equals(), nhưng vẫn có thể có các mã băm khác nhau. Điều này vi phạm hợp đồng của phương thức hashCode(), và dẫn đến các vấn đề sau:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ HashSet: &lt;/span&gt;&lt;span&gt;Khi bạn thêm các đối tượng vào HashSet, hai đối tượng bằng nhau (theo equals()) có thể không được coi là cùng một đối tượng. Điều này có thể dẫn đến việc HashSet chứa các bản sao không mong muốn của cùng một đối tượng.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ HashMap: &lt;/span&gt;&lt;span&gt;Khi bạn sử dụng đối tượng làm khóa trong HashMap, hai khóa bằng nhau có thể được lưu trữ như hai mục nhập riêng biệt nếu chúng có các mã băm khác nhau. Điều này có thể gây ra các vấn đề khi tìm kiếm, cập nhật hoặc xóa các mục nhập trong bản đồ.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Ví dụ minh họa ghi đè equals() mà không ghi đè hashCode()&lt;/span&gt;&lt;/p&gt;
&lt;br&gt;
&lt;b&gt;Example.java&lt;/b&gt;

&lt;pre&gt;&lt;code&gt;import java.util.HashSet;
import java.util.Objects;

class Person {
    private String name;
    private int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return age == person.age &amp;amp;&amp;amp; Objects.equals(name, person.name);
    }

    // Không ghi đè hashCode()
}

public class Example {
    public static void main(String[] args) {
        HashSet set = new HashSet&amp;lt;&amp;gt;();
        Person person1 = new Person("Alice", 30);
        Person person2 = new Person("Alice", 30);

        set.add(person1);
        set.add(person2);

        System.out.println("Kích thước của set: " + set.size()); // Có thể là 2 thay vì 1
    }
} &lt;/code&gt;&lt;/pre&gt;
      

&lt;p&gt;&lt;span&gt;&lt;span id="docs-internal-guid-6312f6eb-7fff-1a50-b17f-c1dc6278b43f"&gt;&lt;span&gt;&lt;b&gt;Kết quả của chương trình là: &lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Kích thước của set: 2&lt;/code&gt;&lt;/pre&gt;


&lt;h2&gt;&lt;span&gt;&lt;span&gt;Ghi đè hashCode() mà không ghi đè equals()&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;&lt;span&gt;Nếu bạn chỉ ghi đè phương thức hashCode() mà không ghi đè phương thức equals(), bạn có thể gặp phải các vấn đề về tính nhất quán sau:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ HashSet: &lt;/span&gt;&lt;span&gt;Nếu hai đối tượng có cùng mã băm nhưng không được coi là bằng nhau theo equals(), HashSet sẽ coi chúng là hai đối tượng khác nhau. Điều này có thể dẫn đến việc HashSet chứa các bản sao không mong muốn của cùng một đối tượng.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;↳ HashMap: &lt;/span&gt;&lt;span&gt;Khi sử dụng đối tượng làm khóa trong HashMap, hai đối tượng có cùng mã băm nhưng không bằng nhau (theo equals()) có thể ghi đè lẫn nhau. Điều này dẫn đến việc mất dữ liệu không mong muốn.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Ví dụ ghi đè hashCode() mà không ghi đè equals()&lt;/span&gt;&lt;/p&gt;
&lt;br&gt;
&lt;b&gt;Example.java&lt;/b&gt;

&lt;pre&gt;&lt;code&gt;import java.util.HashSet;
import java.util.Objects;

class Person {
    private String name;
    private int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    // Không ghi đè equals()
}

public class Example {
    public static void main(String[] args) {
        HashSet set = new HashSet&amp;lt;&amp;gt;();
        Person person1 = new Person("Alice", 30);
        Person person2 = new Person("Alice", 30);

        set.add(person1);
        set.add(person2);

        System.out.println("Kích thước của set: " + set.size()); // Có thể là 2 thay vì 1
    }
}&lt;/code&gt;&lt;/pre&gt;
      

&lt;p&gt;&lt;span&gt;&lt;span id="docs-internal-guid-6312f6eb-7fff-1a50-b17f-c1dc6278b43f"&gt;&lt;span&gt;&lt;b&gt;Kết quả của chương trình là: &lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Kích thước của set: 2&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;&lt;span&gt;Để đảm bảo tính nhất quán và hiệu suất của các cấu trúc dữ liệu dựa trên băm, bạn cần ghi đè cả hai phương thức equals() và hashCode() khi bạn triển khai một trong hai phương thức này. Điều này đảm bảo rằng các đối tượng được coi là bằng nhau bởi equals() cũng sẽ có cùng mã băm, và các cấu trúc dữ liệu dựa trên băm sẽ hoạt động đúng đắn.&lt;/span&gt;&lt;/p&gt;
&lt;br&gt;

</description>
      <category>equalstrongjava</category>
      <category>ghiđèequalsvàhashcode</category>
      <category>hashcodetrongjava</category>
      <category>tieushare</category>
    </item>
    <item>
      <title>Setting up bulk app install and launch across a group of cloud phones before a release check</title>
      <dc:creator>Growth Marketing</dc:creator>
      <pubDate>Tue, 17 Nov 2026 06:41:39 +0000</pubDate>
      <link>https://dev.to/growthmktg/setting-up-bulk-app-install-and-launch-across-a-group-of-cloud-phones-before-a-release-check-542i</link>
      <guid>https://dev.to/growthmktg/setting-up-bulk-app-install-and-launch-across-a-group-of-cloud-phones-before-a-release-check-542i</guid>
      <description>&lt;p&gt;I work with DuoPlus, and the thing I get asked about most by small QA teams isn't some fancy feature. It's this: "How do I get the same build onto a dozen phones without doing it twelve times?"&lt;/p&gt;

&lt;p&gt;So here's the routine I use before a release check. Most of the value is in doing the boring parts in the same order every time.&lt;/p&gt;

&lt;p&gt;One note before starting: I'll describe the steps generically. Menus and labels change, so I'll say "in the DuoPlus console" rather than pretend to quote exact button names. If something looks a bit different on your screen, the idea still holds.&lt;/p&gt;

&lt;h2&gt;
  
  
  What you need first
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A set of cloud phones you're going to test on. For a typical check I want a spread of Android 10, 11, 12 and 15.&lt;/li&gt;
&lt;li&gt;Your build file (APK) and, if you have them, any companion apps the test depends on.&lt;/li&gt;
&lt;li&gt;A short test script. Even five lines in a doc is fine. "Open app, log in with test account, go to checkout, back out." Something everyone runs the same way.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you're testing your own app's sign-up flow, a cloud number that receives verification SMS can be useful here too. Keep that strictly to your own app.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Make a group just for this release
&lt;/h2&gt;

&lt;p&gt;Don't install onto "all phones." That's how a client's long-running device ends up with a test build on it, which you'll then have to explain.&lt;/p&gt;

&lt;p&gt;In the DuoPlus console, put the phones you want into a group and give it a name that says what it is. I use something like &lt;code&gt;release-2026-11-qa&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I keep client devices and test devices completely separate. Client phones are long-term, fixed device environments; they don't get pulled into release groups. Test phones are the ones I'm happy to wipe.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Check each phone's basics before anything goes on
&lt;/h2&gt;

&lt;p&gt;This is the step people skip, and it's the step that saves the most time later.&lt;/p&gt;

&lt;p&gt;Open each phone in the group (or at least skim through them) and check:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Android version is what you think it is.&lt;/li&gt;
&lt;li&gt;Region and proxy settings are set per device the way your test needs. If you're checking a German storefront, that phone should actually be set up for Germany.&lt;/li&gt;
&lt;li&gt;No leftover version of your app from the last check. If there is, remove it now, not halfway through testing.&lt;/li&gt;
&lt;li&gt;Storage isn't nearly full.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A few minutes here beats finding out on phone nine that it's on the wrong region.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Bulk uninstall old builds
&lt;/h2&gt;

&lt;p&gt;If several phones still have last week's build, select the group in the console and use the bulk uninstall option to clear the old version from all of them at once.&lt;/p&gt;

&lt;p&gt;I do this as its own step rather than relying on "install over the top," because occasionally an upgrade path hides a bug that a fresh install would show, and vice versa. Decide which one you're testing. For a normal release check, I want fresh instalss.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Upload the build and bulk install
&lt;/h2&gt;

&lt;p&gt;Upload your APK through the console, then pick the group and run a bulk install.&lt;/p&gt;

&lt;p&gt;A few things I've learned the hard way:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Name your file with the version in it.&lt;/strong&gt; &lt;code&gt;myapp-3.4.1-rc2.apk&lt;/code&gt;, not &lt;code&gt;app-release.apk&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Install companion apps in the same pass&lt;/strong&gt; if your test needs them, so every phone ends up in the same state.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Wait for it to finish on every phone&lt;/strong&gt; before moving on. If one fails, deal with that phone on its own rather than re-running the whole group.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 5: Bulk launch and eyeball the first screen
&lt;/h2&gt;

&lt;p&gt;Now launch the app across the group in one go. Then go phone by phone and just look at the first screen.&lt;/p&gt;

&lt;p&gt;You're not testing yet. You're checking that it opened, it didn't crash on start, and the first screen looks sane on each Android version. This catches the obvious stuff (missing permission prompt on one version, a layout that's clearly broken on another) before anyone starts working through the script.&lt;/p&gt;

&lt;p&gt;If you're using root for debugging logs, this is a good moment to grab startup logs from any phone that looked off.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6: Hand phones out to testers
&lt;/h2&gt;

&lt;p&gt;If more than one person is running the check, share phones to teammates from the console. One-click sharing means they open the device already in the state you left it, app installed and launched, no re-logging in.&lt;/p&gt;

&lt;p&gt;I split it by Android version: one person takes 10 and 11, another takes 12 and 15. Clear ownership, no two people tapping on the same phone at the same time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 7: Run the script, write things down
&lt;/h2&gt;

&lt;p&gt;Everyone runs the same short script on their phones. Notes go into one shared doc, with the phone name and Android version on every line. "Checkout button cut off — release-qa-03, Android 12" is useful. "Button looks weird" is not.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 8: Clean up when you're done
&lt;/h2&gt;

&lt;p&gt;After the check:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Take back shared access from testers.&lt;/li&gt;
&lt;li&gt;Decide whether to keep the build on the phones for a follow-up check or bulk uninstall it now.&lt;/li&gt;
&lt;li&gt;If you won't need the test phones for a while, remember billing is per minute, so there's no point leaving phones running for nothing.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Optional: do it with the API
&lt;/h2&gt;

&lt;p&gt;Once you've run this by hand a few times and the steps stop changing, it's worth scripting. DuoPlus has an API, so install, launch and uninstall can be wired into whatever you already use for builds. I wouldn't start there, though. Do it manually until you trust the routine, then automate the routine you trust.&lt;/p&gt;

&lt;h2&gt;
  
  
  A short hypothetical
&lt;/h2&gt;

&lt;p&gt;Made-up example, to show the timing: a two-person team has a release candidate on Thursday morning. They group eight test phones across four Android versions, clear old builds, bulk install, bulk launch, and spot that the app opens to a blank screen on one version. They catch it before lunch instead of after a client emails about it. That's really the whole point.&lt;/p&gt;

&lt;p&gt;If you want to try it on a small group first, the console is at &lt;a href="https://www.duoplus.net" rel="noopener noreferrer"&gt;https://www.duoplus.net&lt;/a&gt;. Start with four phones, one per Android version, and run the eight steps once. You'll find your own shortcuts quickly.&lt;/p&gt;

</description>
      <category>android</category>
      <category>testing</category>
      <category>qa</category>
      <category>devops</category>
    </item>
    <item>
      <title>What Information Should You Prepare Before Ordering Solar Street Lights for a Project?</title>
      <dc:creator>Yantai Edobo</dc:creator>
      <pubDate>Tue, 17 Nov 2026 06:41:35 +0000</pubDate>
      <link>https://dev.to/jiren-edobo/what-information-should-you-prepare-before-ordering-solar-street-lights-for-a-project-4mea</link>
      <guid>https://dev.to/jiren-edobo/what-information-should-you-prepare-before-ordering-solar-street-lights-for-a-project-4mea</guid>
      <description>&lt;p&gt;When planning a solar street lighting project, it is tempting to start by comparing wattage, prices, or product specifications. However, these figures are difficult to evaluate without understanding the actual installation conditions.&lt;/p&gt;

&lt;p&gt;A solar street light is not just a lamp with a solar panel and a battery. Its performance depends on how these components are matched to the site, the lighting requirements, and the expected operating conditions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9d4t4p0yq04eyyevt66k.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9d4t4p0yq04eyyevt66k.jpg" alt=" " width="799" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here are several practical considerations worth clarifying before requesting quotations or selecting equipment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Start With the Installation Environment&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The project location affects more than the choice of lamp housing. It also influences solar panel positioning, battery capacity, mounting structure, and long-term maintenance.&lt;/p&gt;

&lt;p&gt;For example, a road surrounded by trees or buildings may receive less direct sunlight than an open rural road. Coastal locations may require additional attention to corrosion protection, while areas with strong winds need appropriate pole and foundation designs.&lt;/p&gt;

&lt;p&gt;Useful information includes:&lt;/p&gt;

&lt;p&gt;Project location and local climate&lt;/p&gt;

&lt;p&gt;Available sunlight and possible shading&lt;/p&gt;

&lt;p&gt;Coastal, humid, dusty, or high-wind conditions&lt;/p&gt;

&lt;p&gt;Road width and surrounding obstacles&lt;/p&gt;

&lt;p&gt;These details help determine whether a proposed configuration is suitable for the actual site rather than just looking good on a specification sheet.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Define the Lighting Objective&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The required lighting level depends on the application. A residential access road, a public road, a parking area, and an industrial site may have very different lighting requirements.&lt;/p&gt;

&lt;p&gt;Before choosing a fixture, clarify the road layout, installation height, pole spacing, and the area that needs to be illuminated.&lt;/p&gt;

&lt;p&gt;It is also important to consider the lighting distribution, not just the LED wattage. Two fixtures with the same rated power may produce different lighting results because of differences in optical design and installation conditions.&lt;/p&gt;

&lt;p&gt;For larger projects, a lighting layout or photometric calculation can help evaluate whether the proposed arrangement meets the project's requirements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Consider the Entire Operating Cycle&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Solar street lights need to collect energy during the day and use stored energy at night. Therefore, the system should be considered over its complete operating cycle.&lt;/p&gt;

&lt;p&gt;The expected nightly operating hours, local sunlight conditions, and required backup days all influence the relationship between the solar panel, battery, and LED load.&lt;/p&gt;

&lt;p&gt;For instance, a project that requires lighting throughout the night has different energy requirements from one that uses reduced brightness during low-traffic hours.&lt;/p&gt;

&lt;p&gt;If dimming or motion-sensing functions are required, these should be discussed before selecting the controller and lighting configuration. Not every model has the same control functions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Check the Pole and Installation Structure&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The pole is sometimes treated as a separate purchasing item, but it is an important part of the overall system.&lt;/p&gt;

&lt;p&gt;Its height, material, wall thickness, wind-load requirements, foundation, and mounting arrangement should be considered together with the lighting equipment.&lt;/p&gt;

&lt;p&gt;Surface protection also matters, especially for outdoor installations exposed to moisture and corrosive environments. Hot-dip galvanizing and additional powder coating may be considered depending on the project conditions.&lt;/p&gt;

&lt;p&gt;The installation layout should be clear as well. Single-side, opposite-side, staggered, and central arrangements can lead to different requirements for pole spacing and lighting distribution.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Make Technical Quotations Comparable&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One common problem during procurement is receiving quotations based on different assumptions.&lt;/p&gt;

&lt;p&gt;One supplier may quote a complete system with a particular battery capacity and pole configuration, while another may offer a lower price based on a different setup. Comparing only the unit price can therefore be misleading.&lt;/p&gt;

&lt;p&gt;A more useful quotation request should specify the same basic requirements for every supplier, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;LED power and lighting requirements&lt;/li&gt;
&lt;li&gt;Solar panel and battery configuration&lt;/li&gt;
&lt;li&gt;Pole height and structural specifications&lt;/li&gt;
&lt;li&gt;Control functions&lt;/li&gt;
&lt;li&gt;Operating hours and backup expectations&lt;/li&gt;
&lt;li&gt;Installation quantity and delivery location&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can then compare not only the price but also what is actually included in each proposed system.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Final Thoughts&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Good solar street lighting procurement starts with clear project information. The more accurately the site conditions and lighting requirements are defined, the easier it becomes to evaluate different configurations and avoid unnecessary changes later.&lt;/p&gt;

&lt;p&gt;Rather than choosing equipment based on wattage or price alone, treat the project as a complete system. This makes technical discussions with suppliers more productive and helps ensure that the selected equipment is appropriate for the intended application.&lt;/p&gt;

</description>
      <category>solarpower</category>
      <category>solarstreetlight</category>
      <category>renewableenergy</category>
      <category>infrastructure</category>
    </item>
  </channel>
</rss>
