Skip to content

fix(sdk): accept 6+ digit event indices in EventLog filename regex - #3927

Merged
VascoSch92 merged 2 commits into
OpenHands:mainfrom
tomsen02:fix/event-log-index-width
Jun 30, 2026
Merged

VascoSch92 merged 2 commits into
OpenHands:mainfrom
tomsen02:fix/event-log-index-width

Conversation

@tomsen02

@tomsen02 tomsen02 commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

HUMAN:

The writer pads the event index with {idx:05d} (a 5-digit minimum, uncapped) while the reader regex matched exactly \d{5}. So any event log that grows past 99,999 events writes 6-digit filenames the reader can no longer recognise, and the tail of the history is silently dropped on the next cold reload. This widens the reader to \d{5,} and adds regression tests across the boundary.


AGENT:

Why

EVENT_FILE_PATTERN = "event-{idx:05d}-{event_id}.json" zero-pads the event index to a minimum of 5 digits and never caps it, so an append-only event log that grows past 99,999 events writes 6-digit filenames (event-100000-...). The reader EVENT_NAME_RE matched exactly 5 digits (\d{5}), so on a cold reload (process restart → resume/fork) every event with index ≥ 100000 was treated as "Unrecognized event file name" and excluded from the rebuilt index.

Consequences (silent, persistent, irreversible):

  • _scan_and_build_index() stops at the first missing contiguous index, so len(EventLog) is truncated to 100000 — the tail of the history is silently lost on reload.
  • The prefix-based _count_events_on_disk() still counts the 6-digit files, so it diverges from the scan; the next append() triggers _sync_from_disk and the length accounting becomes permanently inconsistent (idx 100000+ are on disk but unreadable holes).

Reported and analysed in #3926.

Summary

  • Relax the reader regex from \d{5} to \d{5,} so it accepts whatever width the {idx:05d} writer emits. One character; fully backward compatible (existing 5-digit names still match).
  • Add regression tests: a parametrized writer↔reader agreement check across the 5/6-digit boundary, and an end-to-end cold-reload test of a >100k-event log.

Issue Number

Closes #3926

How to Test

Run the new + existing EventLog tests:

uv run pytest tests/sdk/conversation/test_event_store.py -q
# 29 passed

Guard verification — the new tests fail on the pre-fix regex and pass after the fix. Temporarily reverting \d{5,} → \d{5}:

FAILED ...::test_event_filename_writer_reader_agree[100000]
FAILED ...::test_event_filename_writer_reader_agree[100001]
FAILED ...::test_event_filename_writer_reader_agree[999999]
FAILED ...::test_event_filename_writer_reader_agree[1000000]
FAILED ...::test_event_log_cold_reload_past_100k_events
WARNING event_store.py:237 Unrecognized event file name: event-100000-...json

End-to-end reproduction before the fix (a 100,002-event log cold-reloads as length 100000, and idx 100000/100001 raise IndexError: Event index out of range); after the fix the same log reloads as 100002 with all events readable.

lint/format: uv run ruff check and ruff format --check clean on both files.

EVENT_FILE_PATTERN zero-pads the event index to a minimum of 5 digits
({idx:05d}) but never caps it, so a conversation whose append-only event
log grows past 99999 events writes 6-digit filenames. The reader regex
EVENT_NAME_RE matched exactly 5 digits (\d{5}), so on a cold reload
(process restart -> resume/fork) every event with index >= 100000 was
treated as "Unrecognized", silently truncating the log and corrupting the
length accounting (the prefix-based _count_events_on_disk kept counting
them). Relax the reader to \d{5,} so it accepts whatever width the writer
emits. Backward compatible: existing 5-digit names still match.

Closes OpenHands#3926

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@VascoSch92 VascoSch92 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

If you can fix the couple of nits I pointed out, than we can merge. ;-)

- Trim the persistence_const comment to a single concise line.
- Drop the regression divider comment block in the test module.
- Hoist the per-test persistence_const imports to module top.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@tomsen02

Copy link
Copy Markdown
Contributor Author

Thanks for the review! Addressed all four nits in 455b86d:

  • Trimmed the persistence_const comment to a single concise line.
  • Removed the regression divider comment block.
  • Hoisted both per-test imports to the top of the module.

Tests still green (29 passed), ruff check/format clean. Ready when you are 🙂

@VascoSch92 VascoSch92 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@VascoSch92
VascoSch92 merged commit 1c230d9 into OpenHands:main Jun 30, 2026
29 of 30 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.

bug: EventLog silently drops events and corrupts the log once event index reaches 100000 (5-digit regex vs unbounded writer)

2 participants