The Draft That Overwrote the Publish — Python Bug Hunt
Inspired by the sync-conflict horror stories of every note-taking and CMS product: an old offline draft comes back online and steamrolls the article someone…
- Language: Python
- Layer: Backend
- Difficulty: Easy
- Concepts: Sync, Timestamps
- Modelled on: Sync engines
- Visible tests: an older incoming record loses; a newer incoming record wins
- Reward: 50 XP for a complete fix
Incident
- Severity: SEV-2 (priority: High (lost content))
- Ticket: BUG-LWW
- Reported by: editors
- Time to fix: 10 minutes, the target for an easy incident
Failing checks on the shipped build
- an older incoming record loses — expected "published" but got "stale draft"
How to work this incident
- Read the report: write down the expected behaviour and the actual one in a sentence each.
- Reproduce it: run the visible tests and find the failing check that matches the report.
- Read the logs and the failing checks for the first value that is wrong — the earliest wrong value is nearer the cause than the loudest error.
- Follow the request through the handler, the validation and the service it calls; find the first step whose output disagrees with the report.
- Fix the cause rather than the symptom, run the visible tests again, and submit against the hidden ones — then write the root cause down.
Briefing
Inspired by the sync-conflict horror stories of every note-taking and CMS product: an old offline draft comes back online and steamrolls the article someone published an hour ago. Last-write-wins needs to compare timestamps, not arrival order.
sync.py merges an incoming record with the stored one.
Bug report
BUG-LWW · Priority: High (lost content) · Reported by: editors
merge(saved, incoming) — both have updated_at:
- keep whichever has the NEWER updated_at
- ties keep the SAVED (server) copy
Observed: incoming always wins — a laptop that was offline all week just replaced today's homepage with last Tuesday's.
Logs
[sync] doc 41: incoming updated_at=1699000000 overwrote saved 1699600000The code as shipped
src/sync/sync.py (editable)
# Last-write-wins merge of a stored and incoming record.
def merge(saved, incoming):
return incoming
Open the hunt to start the incident clock, edit the files, run the visible tests and submit against the hidden ones, then write the root cause down. More Python bug hunts.