vibeapp.win

What broke

limit() without ORDER BY locked out whole exchanges

Several sync jobs in the stock app used .limit(N) with no ORDER BY, so Postgres returned about the same rows on every run and Paris, Germany and part of Oslo never got fetched. At the same time the SEC insider job read HTML instead of XML and wrote zeros for every US stock while reporting success. Two questions from Henning exposed both bugs.

The short version

What went wrongSync jobs used .limit(N) with no ORDER BY, so the same rows were fetched every run and whole exchanges were skipped. The SEC insider job also wrote zeros for every US stock and reported success.

How we found itHenning's two questions about Norwegian-only insider signals and the French exchange led Claude to measure coverage across every exchange and input, which showed the skew and the 0/0/0 rows.

The rule nowNever use limit without ORDER BY or a rotation, search for a bug class everywhere once fixed, judge coverage by the weakest cell, and give every known zero an explanation with an expiry date.

This post documents something Claude got wrong. The claim rests on a commit or a file, not on memory. All of Claude's mistakes

The stock app collects signals from news, earnings calendars and insider trades across five exchanges: NYSE, NASDAQ, Oslo, XETRA and Paris. In early August 2026 we found that several of the jobs feeding those signals had never covered the whole universe. One of them wrote zeros for every American stock and reported success every time it ran.

Claude wrote all of this code. The commit messages describe the faults plainly, and one of them calls the latest finding the “third and fourth occurrence” of a bug that had already been fixed once.

The first occurrence, 2 August

Henning asked Claude to verify the verification document. While checking when new SEC fundamentals would arrive, Claude found that the insider sync job selected US instruments with limit(60) and no ORDER BY. Postgres doesn’t promise any order in that case, and in practice it returned about the same 60 rows every week. The commit measured 343 active US instruments, of which only 76 had fundamentals, and that number had stopped growing.

It was worse than that. Instruments without a CIK (the SEC’s company identifier), such as ETFs like SPY and foreign listings like ASML, sat at the top of the unsorted list. The loop skipped them, but only after they had taken one of the 60 slots. They blocked those slots permanently.

The fix removed instruments without a CIK before the limit was applied, sorted so that instruments never fetched came first, and raised the limit to 120. The fix was never carried over to the other jobs.

Henning’s two questions, 4 August

Two days later Henning asked two questions within an hour. The first was about the insider signal: was it only Norwegian stocks coming in? The second, roughly translated from Norwegian: “what about the French exchange? Go over the other signal sources and check that we’re not only getting Norwegian ones.”

The insider signal: HTML that looked like XML

The answer to the first question was yes, but not by design. All 78 American rows in the insider table had net value 0, buy count 0 and sell count 0, for companies like XOM, SLB and PSX, over a 90-day window. The job had reported success ten runs in a row. All 457 of 457 insider buying signals in the outcomes table came from Oslo.

The cause was in how the job picked the document to download. For Form 4 filings, the SEC’s primaryDocument field points to the XSL-rendered version. It ends in .xml, returns 200, is about 18 kB, and is HTML meant for people, without a single <transactionCode>. The raw XML sits in the same folder without the prefix. The parser found nothing, the summary of an empty list came out as valid zeros, and those zeros were written to the database as if they were a measurement.

The code already had a comment warning about an all-null summary overwriting good numbers, but it only covered an unexpected response shape. The commit puts it this way: here the response was well-formed, just the wrong document, “so the guard looked right past it.”

After the fix, Claude checked against the live SEC data: AAPL had 5 sales worth about 87 million USD, MSFT 2 sales, JPM 6 sales. Before the fix, every one of them was 0/0/0.

Turning the data on exposed a second risk right away. One Phillips 66 filing from 21 July listed a price per share of 2110482 where the filer meant 211.0482. That single transaction came to about −7.4 billion USD, against about 5 million for all the others combined. The insider signal fires above a net value of 100,000 USD, so the same typo on a purchase would have produced a false insider signal. The summary now checks each price against the latest close and drops anything more than ten times higher or lower. The job logs the number of dropped transactions as a warning.

The other sources: same bug, two more places

For the second question, Claude measured coverage across the whole matrix of exchanges and data inputs instead of checking one source at a time. Share of the universe: NYSE 46 %, NASDAQ 28 %, Oslo 10 %, XETRA 9 %, Paris 7.5 %.

The signals themselves weren’t Norwegian-only. Paris showed up in most sources, often above its share, such as 14 % in one momentum source. The input data was skewed, though:

Exchange Active With earnings date With news events With insider data
NYSE 215 69 58 44
NASDAQ 128 57 34 34
XETRA 40 39 3 0
Oslo 46 15 33 35
Paris 35 29 0 0

Paris had 31 news articles spread over 3 of 35 instruments, and none in the previous 14 days. Oslo had earnings dates for 15 of 46 instruments, against 39 of 40 for XETRA.

The news job and the earnings calendar job had the same cause: .limit(N) with no ORDER BY. The commit says it was exactly the same bug that was found and fixed in the insider job on 2 August, and that the fix was just never carried over.

The skew passed straight into the signals. The news event source had 0 % coverage on Paris and XETRA, which looked like something about those markets but was an artifact of the selection. Two sources that read the earnings calendar inherited the skew against Oslo.

The data had been available the whole time. A direct Yahoo search for TEP.PA, MC.PA, AIR.PA, SAP.DE and ADS.DE returned 10 news items each. In the commit’s words: “We never asked.”

Both jobs now sort by the longest time since the last fetch, with never-fetched instruments first. When checked, the news rotation put 120 never-fetched instruments at the front (12 Paris, 14 XETRA), and the earnings calendar put 200 instruments without a date first (25 Oslo, 5 Paris).

One occurrence left on purpose

Claude found one more .limit() without an order, in the return series loader for an exploratory theme scanner. That loader caps the list at 150 because the correlation step grows with the square of the input size. It stays as it is. That scanner can’t trigger a buy, and rotating its input would make the result unstable: a “new theme” would mean “150 new names” rather than anything about the market. The reasoning is written in the code, along with a requirement that this must be fixed before the scanner ever goes into the buying path.

Some gaps are real limits and not bugs. There is no free insider source for continental Europe, so XETRA and Paris have no insider data, and the short interest source covers only the US. The commit records them so they stay known.

How we check that it worked

Henning’s questions caught all of this, and the commit for the zero check calls that “the most expensive way to find something.” Two checks came out of it.

The first is a milestone due 18 August that asks whether news and earnings coverage has reached every exchange. It measures the weakest exchange, not the average, because an average would hide the one exchange sitting at zero. The bar is 50 %. At the time of the commit it read “9 % news coverage · 32 % earnings date.” That material doesn’t include the result from 18 August.

The second is a silent-zero check. It sweeps 15 tables that feed decisions and flags numeric columns that are all null, all zero or never vary. On its first run it found 10, the same ten a manual review had found, and all of them already explained. Some zeros are correct. A window that is always 90 days never varies, and a 90-day return can’t exist before the oldest signal is 90 days old. So every known zero gets an expectation with an expiry date. For example, the 90-day return column is expected to be null until 21 September 2026. The SEC zeros were allowed to stay until 11 August, which left room for one failed run after the fix. When the date passes, the row becomes a finding again without anyone touching code. Anything not in the register gets flagged by default.

The rule

  • Never use limit without ORDER BY or a rotation. Without an order, “the first N” means “the same N forever”.
  • When a bug class is fixed in one place, search the other places for it the same day.
  • Measure coverage across the whole matrix, every exchange against every input, and judge it by the weakest cell.
  • Zeros need an explanation, and every explanation has an expiry date.