Contents Lesson 15 of 18

10 min read · practitioner

How old is this number, really?

By the end of this lesson you will have a data-age line that reports the oldest number on the page rather than the freshest, a test that pins it, and three ages measured at three moments on your own account.

Your tool shows prices. Underneath every one of them sits a question almost no dashboard answers honestly: as of when?

Three different things that all look like "the price"

What you called What it is Typical age
/real-time/{ticker} latest quote your plan permits minutes, or delayed by the exchange's rule
/eod/{ticker} the official close of a completed session yesterday, or older over a weekend
a cached copy whatever your server stored as old as the cache

They render identically. A number is a number on screen, and nothing about 310.34 tells you whether it is from thirty seconds ago or last Friday. That is the whole problem.

Read the age from the data, never from the plan name

Every quote carries its own timestamp. Use it:

const ageMinutes = Math.round((Date.now() - quote.timestamp * 1000) / 60_000);

Do not infer freshness from your subscription tier. The plan name is a claim about what you should be getting; the timestamp is evidence about what you got, and the two disagree more often than you would expect. The market may be closed. The feed may lag. A cache may have served you. Only one of those is visible in the response, and it is the timestamp.

Say what the age supports, not what it is

"12 minutes old" is data. What a person needs is what they can do with it:

  • Under a couple of minutes — effectively live. An alert built on this is honest.
  • A couple of minutes to about twenty-five — behind by exactly the minutes on screen, so say that number rather than "a delayed feed": fifteen minutes and two are different promises. Fine for watching, checking, reporting. An alert fires exactly that late, so do not build one that pretends otherwise.
  • Hours — a snapshot, not a quote. It answers "where did this close", never "where is it now".
  • More than a day — an end-of-day close wearing a quote's clothes. Useful for history, useless for anything measured in minutes.

Print the band next to the number. This is the panel that makes the wall in the next lesson honest rather than a sales message: when the limit bites, you will read it off your own screen instead of being told about it.

Prove it to yourself

On 2026-08-25, /eod/AAPL.US returned these completed sessions:

[{"date":"2026-08-20","close":311.3,"volume":40959200},
 {"date":"2026-08-21","close":309.35,"volume":46876800},
 {"date":"2026-08-24","close":310.34,"volume":34673600}]

And /real-time/AAPL.US at the same moment reported close: 310.34 with previousClose: 309.35.

Look carefully. The "live" close equals the 24 August end-of-day close, and previousClose equals the 21 August close. Nothing is broken: the session had not produced a newer print at that moment, so the freshest available number was the last close. A dashboard that labelled that "live" would be lying without a single wrong number in it.

This is why the label matters more than the value.

Caching is your quota strategy, and it must be visible

Serving a stored copy for a minute is a legitimate way to make a page cheap. It is also a way to show stale data silently, which is the exact sin this lesson is about. If you cache, the age you display must be the age of the data, not the age of the request that served it.

Try it now

The prompt

The starter already prints a data-age line with its band. Read how it decides first: ageMinutes() in src/lib/quotes.ts takes the newest row. With a list that mixes markets, one fresh row — a crypto pair at the weekend, a market still open — makes the whole page look live while another row is a day old. Mock mode on, plan mode on, and paste:

The data-age panel uses ageMinutes() in src/lib/quotes.ts, which
reports the newest row, so one fresh market can vouch for a stale one.
Change it to report the oldest row, make asOf in src/app/page.tsx take
the same row, and say "oldest number on this page" in the panel. Plan
first and name the files. Write tests/age.test.ts before the code, with
literal timestamps and a fixed now: rows one minute and two days old
give 2880, and a row stamped after now gives 0, never a negative age.
If an existing test assumed the newest row decides, change it to the
oldest and tell me which one. Show me the first test failing, then the
code. No request. Run
npm test, npm run typecheck and npm run check:leak.

A good answer changes src/lib/quotes.ts, src/app/page.tsx and the component that prints the panel text, adds the test, and shows the two-row test red on the newest-row code. If you did Pair With Your Agent, its hand-off test of ageMinutes() covers a single row and an empty list, so it stays green; any test you wrote that says the newest row decides is now wrong, and rewriting it to say the oldest is part of this change.

Check it yourself

  1. The two-row test failed first: the old code answered 1, not 2880.
  2. Green afterwards, and every earlier test still passes.
  3. In mock mode the panel says the oldest number on the page is days old, with the end-of-day band: the fixtures are stamped 30 October 2026.
  4. Live, check it at three moments (this needs your own key and the time of day to cooperate; if you cannot, the mock panel in step 3 is the part you can check today and the live table is the part you do when you can): during market hours, an hour after the close, and on a weekend, at one call per ticker each time. Write down the three ages. That table is the actual freshness of your tool, measured rather than assumed, and it is what the next lesson works from.

Break it on purpose

Make ageMinutes take the newest row again (in ours below, Math.max in place of Math.min; in your agent's version, whatever line picks the row) and run npm test: the two-row test goes red. That is the whole lesson in one line of code, the freshest number vouching for the rest. Put it back.

Compare with ours

Our ageMinutes
export function ageMinutes(rows: Quote[], now: number = Date.now()): number | null {
  if (rows.length === 0) return null;
  // The OLDEST row: one fresh market must not vouch for a stale one.
  const oldest = Math.min(...rows.map((r) => r.timestamp));
  if (!Number.isFinite(oldest)) return null;
  return Math.max(0, Math.round((now - oldest * 1000) / 60_000));
}

The full state at the end of this unit is on the starter's branch ref/build-your-first-tool/u4.

Checkpoint

npm test
git status   # only the files you expect, and no .env*
git add -A
git commit -m "Data age is the oldest row's, so one fresh market cannot vouch for a stale one"

Then answer this lesson's questions.