The upgrade said it worked
After my workflow tool moved to a new major version, the step that remembered what had already been posted kept reporting success and saved nothing. How I found it, and why that state now lives in a database.
On July 26, a workflow of mine posted an article at 3 a.m. and posted it again at 7 a.m. On July 27 it happened again. Every run involved was marked successful, including the step whose only job is to remember what has already been posted.
That step had been running, reporting success and saving nothing for eight days. The cause was an upgrade I had not known I was making.
What the workflow does
This is the pipeline I wrote about two weeks ago. Every four hours it reads eleven news feeds, removes duplicates, has a model score the items, picks one, drafts a short post and publishes it. The last step records the article in a list of things already posted, and the next run checks new items against that list.
The order of the last two steps is deliberate. The record is written only after the post goes out. If publishing fails, nothing is recorded and the next run can try the same article again.
All green, nothing saved
The run history showed no failure. The record step had completed 40 times since July 19 and every one was green.
Then I looked at the stored list itself. It was empty. Forty successful writes had produced no entries at all.
The tool is n8n, and the list lived in a feature it calls workflow static data, a small store attached to the workflow that code steps can read and change. My record step was a few lines of code that added the article's address to that store.
On July 19 a fresh copy of the tool's container image had been pulled under the tag latest, and that tag had moved to version 2. The breaking changes page for version 2 lists a change to how code steps execute: "All Code node executions will run on task runners," which are separate processes. My configuration had task runners switched off. After the upgrade the code steps ran on them anyway.
In that arrangement, the changes my code made to static data never made it back to storage. The code ran without an error, passed its items to the next step and turned green. Nothing was saved.
I am not going to complain about the tool. Its documentation for static data says in plain words that it "is an experimental feature" and that it "may behave unreliably under high-frequency workflow executions." I had built the pipeline's only memory on a feature labeled experimental. And the breaking changes were published. I did not read them, because I did not know I was crossing a major version.
Why it only showed at night
The memory had been dead for a week before I saw a duplicate, and the reason is worth a paragraph because it applies to a lot of silent failures.
During the day, new articles arrive constantly. Four hours after a post, something newer usually outscores the article that won last time, so the pipeline picks a different one even with no memory at all. Overnight the feeds go quiet. At 7 a.m. the best available article is often the same one that was best at 3 a.m., and with nothing recorded, it gets posted again.
So the fault was present on every run and visible only on quiet nights. A failure like that can pass a daytime test every time.
- Image pulled under latestOn July 19 the tag had moved to version 2 of n8n.
- Code steps run on task runnersThis happened even though my configuration had them switched off.
- Static data changes are lostChanges my code made to static data never made it back to storage.
- Record step still turns greenIt completed 40 times since July 19 and the stored list was empty.
- Same article posted twiceOn a quiet night the best article at 7 a.m. was the one from 3 a.m.
n8n documents static data as an experimental feature and published the version 2 breaking changes.
The rebuild
On July 27 I moved the list into a Postgres table. A Postgres database was already running beside the tool for other work, so this added no new service.
Each run now does three things with it. After the in-run cleanup, a query loads everything posted in the last 21 days. A filter drops any new item that matches. After a post is published, an insert adds the article, written so that inserting the same article twice does nothing.
The order I cared about is preserved. The insert still comes after the publish step, so a failed post leaves no row.
Matching uses a normalized address (query string removed, trailing slash removed, lower case) and a key made from the first twelve words of the title. The same story often appears under different addresses when it is syndicated, and matching on the address alone lets those through. The normalization has to be identical in the filter and in the insert, or the two will disagree about what counts as the same article.
I seeded the table with 14 recent posts so the first run would not start from nothing. Then I tested the insert end to end with a throwaway workflow and deleted it afterward.
The gain is larger than durability. A database row is something I can count from outside the tool. "How many rows were added in the last day" and "how many posts went out in the last day" should be the same number, and a query can check it.
Two more things from the same week
The fix that was not running. I run two copies of this pipeline. I wrote two weeks ago that I had replaced a retired model ID in both. For one of them, that was true in the tool's database and false in the scheduler. I had updated that workflow through the tool's API. On my install, saving a workflow that way did not reload its already-registered schedule trigger, so the scheduler kept running the copy it had in memory. That copy went on calling the retired model for eight days after its stored definition had the new ID. Turning the workflow off and on again loads the new definition. After any change made through the API, do that and then check a run.
One dead feed stopped everything. Two scheduled runs were missed on those same days because a single feed failed to load and the workflow aborted. Each feed step is now set to continue on error, so one bad source costs one source.
What I should have had
A pinned version. The Docker documentation notes that when no tag is given, the engine "uses the :latest tag as a default," and that pulling by digest lets you pin an image and guarantee "that the image you're using is always the same." A tag of latest means the version is decided by whatever day the container happens to be recreated. Upgrades should happen because I chose a version and read its notes.
A check on the result. A green step tells you the code did not throw an error. Whether the thing the code was for has happened is a separate question, and for anything that stores state, the way to answer it is to read the state back.
A test for memory after any upgrade. "It starts and the workflows run" was my whole upgrade test, and it passed. Anything that persists between runs needs its own check: write a value, start a new run, read it.
One caveat. Moving state into a database gives the workflow a dependency it did not have before. If the database is down, the pipeline now stops. I prefer that. A pipeline that halts loudly because it cannot reach its memory is easier to live with than one that keeps going without it.
This was my problem at each step. The tool documented the feature as experimental and documented the breaking change. The tag that let the upgrade arrive unannounced was in my own configuration.
Sources
Views are my own.