<?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: marcelo lang</title>
    <description>The latest articles on DEV Community by marcelo lang (@marcelo_lang_4be7da2e0bee).</description>
    <link>https://dev.to/marcelo_lang_4be7da2e0bee</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4047237%2F857d0f5b-17f6-4126-9184-fbf17057cf2e.jpg</url>
      <title>DEV Community: marcelo lang</title>
      <link>https://dev.to/marcelo_lang_4be7da2e0bee</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/marcelo_lang_4be7da2e0bee"/>
    <language>en</language>
    <item>
      <title>Why your n8n workflow can lose items and still show a green checkmark</title>
      <dc:creator>marcelo lang</dc:creator>
      <pubDate>Sat, 25 Jul 2026 22:31:16 +0000</pubDate>
      <link>https://dev.to/marcelo_lang_4be7da2e0bee/why-your-n8n-workflow-can-lose-items-and-still-show-a-green-checkmark-1adh</link>
      <guid>https://dev.to/marcelo_lang_4be7da2e0bee/why-your-n8n-workflow-can-lose-items-and-still-show-a-green-checkmark-1adh</guid>
      <description>&lt;p&gt;I spent a while chasing a bug where a scheduled n8n workflow was dropping items — not crashing, not erroring in a way I noticed, just… quietly not processing some of them. The execution list looked healthy. Re-running did nothing. Here's what was actually happening, because I think a lot of people have this bug and don't know it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The setup
&lt;/h2&gt;

&lt;p&gt;A really common pattern: you keep a list of "already processed" ids in workflow static data so you don't re-send things. So the flow is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mark id as done  →  do the work (send message / call API / write row)  →  done
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Intuitive. Also wrong, and here's the specific reason.&lt;/p&gt;

&lt;h2&gt;
  
  
  The cause
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;n8n persists static data on the &lt;code&gt;workflowExecuteAfter&lt;/code&gt; hook, and that hook fires whether the run succeeded &lt;em&gt;or&lt;/em&gt; failed.&lt;/strong&gt; I went and read it in the source to be sure, then reproduced it: a workflow that marks an id done and &lt;em&gt;then&lt;/em&gt; throws still has the "done" write persisted.&lt;/p&gt;

&lt;p&gt;So when the work step fails:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the id is marked done ✅&lt;/li&gt;
&lt;li&gt;the work never happened ❌&lt;/li&gt;
&lt;li&gt;the run shows as failed, so you think you'll just retry it&lt;/li&gt;
&lt;li&gt;but on retry, the id is already "done" → it's skipped forever&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The item is gone. Nothing tells you. The counter of "processed" even looks right.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix is ordering, not code
&lt;/h2&gt;

&lt;p&gt;Commit &lt;em&gt;after&lt;/em&gt; the side effect succeeds, per item:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;check if done  →  do the work ✅  →  only now mark it done
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Concretely, in a Code node it's just moving the write to the end:&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="c1"&gt;// runs only AFTER the side effect succeeded, once per item&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;$getWorkflowStaticData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;global&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;done&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;done&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;$json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&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="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;done&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;done&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;$input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two details that matter in practice:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Per item, not per batch.&lt;/strong&gt; If you process 10 items and mark the whole batch done at the end, one failure in the batch re-does the other 9 on the next run (and re-sends 9 messages). Commit each item right after its own side effect.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It's at-least-once, not exactly-once.&lt;/strong&gt; If the process dies &lt;em&gt;between&lt;/em&gt; the side effect and the commit, that one item repeats. That's the right trade for most work — a visible duplicate beats a silent loss — but know that you're choosing it.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Why this one is worth your attention
&lt;/h2&gt;

&lt;p&gt;The thing I keep coming back to: this isn't an exotic edge case. It's the &lt;em&gt;default&lt;/em&gt; way most people wire dedup/idempotency in n8n, and it fails in exactly the situation you built the dedup for (something downstream breaks). The green checkmark is the trap.&lt;/p&gt;

&lt;p&gt;If you have a scheduled workflow with a dedup list right now, go look at the order of those two steps. It takes thirty seconds and it's either fine or it's been quietly eating your data.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;I write these up as I hit them while building production n8n workflows. This one, plus five other error-handling patterns (smart retry, cooldowns, dead-letter, circuit breaker, graceful degradation) — each with the experiment and the number behind it — ended up in a kit I put together: &lt;a href="https://marcelang.gumroad.com/l/stsdsi" rel="noopener noreferrer"&gt;Error-Handling Starter Kit for n8n&lt;/a&gt;. There's also an &lt;a href="https://marcelang.gumroad.com/l/zzunu" rel="noopener noreferrer"&gt;invoice-processing template&lt;/a&gt; built on the same idea: validate the output, don't trust it.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>n8n</category>
      <category>automation</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
