Nobody has started this yet — be first.
Business impact
GET /events/stats and the Prometheus /metrics endpoint are the only way an on-call engineer can tell "is ingestion actually landing rows, or just accepting requests and quietly losing them downstream?" during an incident. Both ultimately depend on AsyncpgInserter.insert_batch() correctly reporting how many rows a batch actually persisted. If that number is wrong, every capacity dashboard is wrong, every "are we dropping data" alert is either permanently silent or permanently screaming, and the load test's own headline claim ("zero data loss, verified") in the project README is unverifiable — it would be reading a broken instrument.
Problem
Postgres reports the outcome of an INSERT as a command tag string like "INSERT 0 1834" — three space-separated fields: the literal word INSERT, an OID field that's always 0 for a modern multi-row insert, and the actual number of rows affected. _rows_from_command_tag parses this tag but reads the wrong field.
Current behavior
_rows_from_command_tag("INSERT 0 1834") returns 0 instead of 1834 — the function is reading parts[1] (the always-zero OID placeholder field) instead of parts[2] (the actual affected-row count).
Expected behavior
_rows_from_command_tag("INSERT 0 1834") should return 1834. More generally, for any Postgres INSERT command tag, the function should return the third field (the real affected-row count), not the second.
Steps to reproduce
cd fastapi/ingest_service && .venv/bin/python -c "from app.db import _rows_from_command_tag; print(_rows_from_command_tag('INSERT 0 1834'))"0 — should print 1834.Why this matters
This is the single most common way to misparse a Postgres command tag — skimming the string as "the second token is the count" instead of checking the docs, because for SELECT/UPDATE/DELETE tags there often is no OID field and the count genuinely is the second token. The tag format isn't uniform across statement types, which is exactly what makes this an easy copy-paste mistake between codebases.
Suggested approach
Look at INSERT_SQL and _rows_from_command_tag in app/db.py together with a real example tag ("INSERT 0 1834"). Count the fields and check which index actually holds the row count.
Acceptance criteria
Verification
pytest practice_tickets/tests/test_ticket_01_persisted_count.py -v
Hints (0/2)
Try it without hints first — the reading is the exercise.
Working on this ticket
Work on a branch named for the ticket — that's what you'll submit.
Branch off your fork
Sign in to create it automatically, or do it yourself:
$git checkout -b fix/persisted-count-off-by-oneFix it and commit
Meet every acceptance criterion, and add a test that would have caught this.
Push the branch
$git push -u origin fix/persisted-count-off-by-oneSubmit it below
Paste your fork URL and the branch name, with a short write-up of the root cause.
Questions
Ask about anything unclear in the ticket — the maintainer and anyone who has solved it can answer. Please don't post full solutions.
Sign in to ask a question or reply.
Sign inhttp://localhost:8000localhost:5432curl localhost:8000/healthzcurl localhost:8000/readyzWork the tickets in practice_tickets/tickets/ (ordered easy → hard); each names one dedicated test in practice_tickets/tests/:
pytest practice_tickets/tests/test_ticket_01_persisted_count.py -v # a single ticket
./practice_tickets/run_tickets.sh # all 20, clean pass/fail summary
TICKET-17 needs a real Postgres to run at all (it checks which column a value lands in, which no fake/in-memory DB backend can meaningfully verify) — set TEST_DATABASE_URL=postgresql://<you>@localhost/ingest_test before running it or the full suite; without it, that one test is skipped, not failed.
Level 1
Fix a bug
Read existing behaviour, correct it.