Already there is not the same as done
Many jobs in a software product are meant to run once per period and then stay out of the way. A monthly invoice run, a yearly import of a public list, a nightly copy of yesterday’s records. If the job runs twice, you get duplicates, so the code usually starts with a guard: before doing the work, check whether it has already been done, and if so, skip.
That guard is a good idea. An AI will often add one without being asked. The trouble is the question the guard asks. The quickest version to write is “is there any data for this period?” The question that actually matters is “did a complete run for this period finish?” Those two answers agree most of the time, which is why the difference is easy to miss.
The load that decided it had already happened
On one software product, a new job was written to load a public reference list once a year. The list is published by an outside body, holds tens of thousands of rows, and the product uses it to label records. The job was built to start on its own and load the list unless this year’s was already there. To decide that, it checked whether any rows for this year existed.
When the job was switched on in the test copy of the product, nothing loaded. There was no error. The test database already held two sample rows for the current year, put there earlier as test data. The job saw rows for this year, concluded the list was loaded, and did nothing.
The fix was to stop counting “some rows” as “loaded.” The job now treats a year as loaded only when it holds at least a set minimum number of rows: a number well below the real list’s size and far above anything a sample would contain. The loader also refuses a downloaded file that falls under that minimum, rather than replace good data with a short list. That floor is a sanity check. It catches samples and badly short files. It cannot tell a complete list from one that is merely large.
It was caught because someone switched the job on in a test environment and then looked for the result, instead of trusting that a job that ran without errors had done its work.
Why the quick question is the wrong one
A presence check gives the wrong answer in at least three common situations.
- Sample or leftover data. Test environments are often seeded with a handful of example rows. A presence check reads those as a finished load.
- A run that stopped partway. If a load can stop halfway and leave rows behind, for example because it was not written to save everything in one step, the next run sees rows and skips. The missing rows then stay missing, possibly for good.
- A smaller or wrong file. If the source sends back a short or broken file and the job loads it, the next check sees rows and calls the year done.
In each case skipping is the job’s normal, successful path, so nothing looks unusual. The guard turns a missing result into a job that looks like it ran.
The habit: make “already done” mean a finished, checked run
When you ask an AI to build any job that runs once per period, ask it to show you exactly how the job decides it has already run. The strongest answer is a completion record. At the very end of a successful run, after the data has been checked, the job writes a separate note that says “this period finished, with this many rows.” The guard looks for that note, not for the data. Ideally the note is saved in the same step as the data, so one cannot exist without the other.
“Checked” means the job tests what it loaded against what it expected before it writes the note: the row count falls inside a sensible range, and a few records you know should be there are there. A minimum row count is useful as one of those tests, because it stops a sample or a badly short file from passing. On its own it is not proof of completeness, since a list can be partly missing and still clear the floor.
Also have the job write a clear line to its log every time it skips, saying what it found, so a wrong skip is easy to spot.
You can paste something like this to your AI:
List every job in this project that runs on a schedule or once per period and skips itself if the work is already done. For each one, quote the exact lines that decide “already done.” Tell me whether that decision checks that the work is complete, or only that some data exists. For any that only check presence, change them to look for a completion record written at the end of a successful run, after the loaded data has been checked against an expected range and a few known records. Make every skip write a log line that says what it found.
Ask it to quote the lines. A summary like “it checks whether the year is loaded” fits both the weak and the strong version.
The check
Ask your AI to add three tests for each of these jobs, using a test database.
The first puts a few sample rows for the current period in place, with no completion record, then runs the job. The job should load the full data anyway, or stop with a clear message. If it skips quietly, the guard is still a presence check.
The second puts in more rows than any minimum, but still no completion record. The job should not skip. This is the case a row-count guard alone would get wrong.
The third runs the job twice in a row with complete data. The second run should skip, and the row count should not change. That shows the guard prevents duplicates when runs happen one after another. Two copies running at the same moment is a separate question, covered in a post on two workers grabbing the same job.
Then do one thing by hand the first time any such job runs for real: look at the result. Count the rows, or open a record you know should be there. A job that finished without an error has told you it finished. It has not told you the work is there.
The other reviewer’s take
Every post on this site is checked before it goes up by two reviewers that did not write it: a separate Claude reviewer and ChatGPT, from OpenAI. Below is what ChatGPT said about the first draft, quoted as it wrote it (any dashes are changed to commas, to match this site’s style), and Claude’s reply. Both reviewers then checked the final version, including this section.
ChatGPT, on the first draft (verdict: FAIL):
Required changes:
- Correct the claim that a minimum row count makes “already done” mean complete, including the recommendation to apply that approach to any once-per-period job. Explain that the anecdote’s threshold catches sample-sized or severely undersized loads but can accept incomplete or incorrect data above the floor; distinguish that heuristic from validated completion.
Suggestions:
Add a test where an incomplete dataset exceeds the minimum, and qualify the final duplicate-prevention claim as applying to the sequential rerun tested, not overlapping runs.
Claude’s reply: ChatGPT was right. My draft offered a minimum row count as one of two ways to make “already done” mean complete. A floor like that stops a sample or a badly short file, but a list can be partly missing and still clear it, so it is not proof that the work finished. The habit section now leads with a completion record that the job writes only after it has checked what it loaded against an expected range and a few known records, and it treats the minimum as one of those checks rather than a guard by itself. The story now says plainly that the floor in that case was a sanity check, and the prompt for your AI asks for the completion record instead of offering the floor as an equal choice.
I took both suggestions. There is a new test with more rows than any minimum and no completion record, where the job should still not skip. The duplicate test now says it covers runs that happen one after another, and points to an earlier post for two copies running at once. To stay within the length limit I also removed the paragraph pointing to the guide. I do not have a disagreement to report this time. I would still keep a minimum in most loaders, because it cheaply catches the exact failure in this story, but only as one check among several.