AC-045 Scenario not caught

A stale read after a write

State, retries and concurrency

How to run this card's commands yourself

1. The problem

In one sentence

A client writes a change and reads the record straight back, and gets the old value.

A story

A user renames an item from Original to Updated. The PUT answers 200. The page reloads and reads the item with a GET. It still says Original. A cache in front of the read path had stored the old answer, and the write did not clear it. The user changes it again, thinks it did not work, and files a bug.

Why it hurts

The most common thing a client does after a write is to read it back. If the read does not show the write, the client concludes the write failed, or shows old data as current.

  • For developers: the data is saved, but a cache or a read replica still serves the old version. The write path and the read path disagree for a while, or for good if the cache is never cleared.
  • For managers: users see their own changes disappear and reappear. Trust in the product drops and support tickets rise, though nothing is actually lost.
  • For DevOps: caches, CDNs and read replicas each add their own delay. Decide which operations need “read your own writes” and test that path end to end.

Example

In a failure-catalog demo with a cache in front of the read:

GET /items/1                      ->  name: "Original"    (the cache is filled)
PUT /items/1 {"name":"Updated"}   ->  200
GET /items/1                      ->  name: "Original"    (stale: the write is not visible)

How to detect it without clrsig

  • Write with curl, then read straight away, and compare. Repeat a few times: a stale read that clears after a while points to a cache or a replica delay.
  • Bypass the cache (a request header or a different route) and compare.

How to fix it

There are two usual causes:

  1. The cache is not cleared on write (more likely). Clear or update the cached entry when the data changes, or give the entry a short life that matches how fresh the data must be.
  2. Eventual consistency is intended (a replica or a queue). Then the spec must say so, and clients must not assume an instant read. Offer a way to read the latest value, or return the new state in the write answer.

To tell which: ask whether the client needs to see its own write at once. If it does, make that path consistent.

AC-041 A write returns success but is not saved, AC-043 A stale update overwrites a newer one, AC-044 A write times out, yet it was done. See also the site’s Stale Cache and Cache-Invalidation Failures.

Words used on this page are explained once in the glossary.

2. How clrsig helps

Check

No built-in check, and the state is not caught: each answer is valid. A scenario that reads, writes and reads again, and asserts the new value, finds it.

Command

This demo is a runnable server in the failure catalog. The scenario sends a PUT to its own local toy server, so it writes data there:

Safety. Run this against a test server, never production. clrsig conform sends POST, PUT and DELETE requests built from the spec: start with --read-only, and take secrets from the environment (${NAME}), never from files in the repository.

cd failures/fm-017-01-stale-read
go run broken/main.go &
clrsig run scenarios/detect.yaml --env environments/local.yaml

Exit code: 0 all steps pass, 1 a step failed, 2 the scenario or the setup is broken. Here it is 1. Against fixed/main.go all three steps pass and the exit code is 0.

What you see

Output from clrsig v0.21.0, recorded on 2026-11-30:

Scenario: fm-017-01 — Stale Read After Write

  PASS  GET /items/1 — prime the cache on the broken server  200  12ms
         ✓ status eq 200
  PASS  PUT /items/1 to rename to Updated — must return 200  200  0ms
         ✓ status eq 200
  FAIL  GET /items/1 again — must reflect the write (broken server returns stale cached name)  200  0ms
         ✗ jsonpath $.name eq Updated: expected "Updated"; got "Original"

FAILED  2 passed, 1 failed, 0 skipped  (2/3 assertions passed)  13ms

How to read it: the first read fills the cache, the write passes, and the second read returns the old name. The first read is part of the test: it is what puts the stale value in the cache.

Where to look

  • Desktop app: open the scenario and run it; each step shows its assertion result.
  • Reports: --format json and junit on clrsig run.
  • GitHub Action: use command: run with the scenario and env inputs. The demo checks with its own assertions. To compare your own responses with your spec, name it with specFile in the scenario, or give the spec input, which replaces it; older releases of the Action ignored that input with run (setup and upgrading).

How clrsig helps you fix it

It shows the exact read that returned the old value, and what it should have been. It cannot say whether the cause is a cache, a replica or a queue.

Limits

  • The scenario reads once, right after the write. A delay that clears after a few seconds would need a wait, and the scenario does not add one by itself.
  • It tests only the path your scenario takes (through the same entry point as your clients).

More ways

Nothing yet.

3. Video brief for Google NotebookLM

VIDEO BRIEF — AC-045 · A stale read after a write
Length: 5 to 7 minutes. Language: English. Audience: developers, with a line each for managers and DevOps.
One idea: the most common thing a client does after a write is to read it back; if the read shows the old value, the client believes the write failed.
Open with this story: A user renames an item from Original to Updated. The write answers 200. The page reloads and reads the item. It still says Original. A cache in front of the read path had stored the old answer, and the write did not clear it. The user changes it again, thinks it did not work, and files a bug.
Say these facts, in this order:
1. The scenario has three steps: read the item, rename it with a PUT, read it again.
2. The first read fills the cache. The PUT answers 200. The second read returns Original instead of Updated.
3. The data may be saved; the read path shows the old version.
4. Two usual causes: the cache is not cleared on write (clear it, or give entries a short life), or eventual consistency is intended, in which case the spec must say so.
5. For managers: users see their own changes disappear; trust drops though nothing is lost.
6. For DevOps: caches, CDNs and read replicas each add delay; decide which operations need to read their own writes and test that path end to end.
Show on screen: the three example lines, the commands (go run broken/main.go and clrsig run scenarios/detect.yaml --env environments/local.yaml), and the output block, copied exactly from the card.
Name the check: none built in; found by a read, write and read-again scenario. Say the clrsig version: v0.21.0.
Explain these words once: cache (a stored copy of an answer, served to save time); stale (out of date); eventual consistency (a change becomes visible everywhere after a delay); exit code (0 clean, 1 a finding, 2 setup or spec broken).
Say what clrsig does not see here: it cannot tell whether the cause is a cache, a replica or a queue; the scenario reads once, so a short delay would need a wait; it tests only the path your scenario takes.
Safety line (if a write is shown): Run this against a test server, never production. clrsig conform sends POST, PUT and DELETE requests built from the spec: start with --read-only, and take secrets from the environment (${NAME}), never from files in the repository.
Finish with three recap questions:
1. Why does the first read matter in the scenario? (It fills the cache.)
2. Name two causes of a stale read. (A cache that is not cleared, or a delayed replica.)
3. What must the spec say if consistency is eventual? (That a read after a write may be old for a while.)
Tease the next video: AC-046 · An async job never finishes.
Do not: say "contract testing" alone; say clrsig "catches everything"; invent flags, IDs or numbers; read tables aloud; use any fact that is not in the card.