Skip to content

fix: keep the comment reader reading after a bogus head comment ID - #103

Merged
Toldry merged 1 commit into
masterfrom
claude/project-thread-wz5dwe
Oct 17, 2026
Merged

Toldry merged 1 commit into
masterfrom
claude/project-thread-wz5dwe

Conversation

@Toldry

@Toldry Toldry commented Oct 17, 2026

Copy link
Copy Markdown
Owner

Before: since about 00:20 UTC on 2026-10-17 the bot scanned 0 comments. The heartbeat showed reads: 0 requests, a lag of about -6 × 10^18 IDs, and about 10^12 "IDs skipped" every 10 minutes. The r/all listing had returned one comment ID of about 6 × 10^18 (real IDs are about 8 × 10^10). The reader skipped ahead to it, never saw a higher head again, and stopped reading.

After: such an ID is ignored. If a bogus position ever gets in anyway, the reader resets itself within a minute. The heartbeat now warns when heads were found but nothing was read. Deploying this also recovers the stuck production reader, because a saved cursor ahead of the newest comment is ignored at startup.

How:

  • fetch_head drops listing IDs more than MAX_BACKLOG_IDS from the median (newest_consistent_id).
  • poll_head rejects a head further past the last accepted head (or the saved cursor) than MAX_BACKLOG_IDS + 2,000 IDs/s × elapsed. It logs this once per streak and counts it as rejected in the heartbeat.
  • After 6 polls in a row where the head is far below the reader's position, the reader restarts at the newest comment.
  • If heads were found but no reads were made, the heartbeat logs a WARNING saying the reader is stalled.

Tests:

  • Unit tests:
    • an outlier ID or a malformed ID in the listing
    • a rejected bogus jump
    • a real jump after time has passed
    • a replay of the incident with bogus heads mixed in
    • a head going slightly backwards
    • the self-reset
    • a restart with a bogus first head
    • a restart with a cursor ahead of the head
    • reader threads that keep reading while heads are bogus
    • the heartbeat stall warning and the rejected count
  • Live tests:
    • the head is a real comment written in the last hour
    • the real CommentReader runs for 45 s and must read at least 200 comments with a sane lag. This is the check that would have caught this outage before the deploy.

Locally: uv run pytest gives 1804 passed. The live tests run only on master in CI.


Generated by Claude Code

On 2026-10-17 the r/all listing returned a comment ID of about 6 * 10^18.
The reader skipped ahead to it, never saw a higher head again and scanned
nothing for hours. Outlier IDs in the listing and implausible head jumps
are now ignored, a position far ahead of every head resets itself, and the
heartbeat warns when heads were found but nothing was read. Adds unit and
live regression tests.

Co-Authored-By: Toldry <toldry@gmail.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019ddUNNyEKK7YQuAyfKfGwi
@Toldry Toldry self-assigned this Oct 17, 2026
@Toldry
Toldry merged commit 91ad4c3 into master Oct 17, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants