Skip to content

fix(realtime): a failed attempt no longer leaves a dedup record that suppresses the next write - #508

Merged
HananKavitzAmat merged 1 commit into
chunkhound:mainfrom
fstrasz:fix/realtime-end-active-change-upstream
Nov 11, 2026
Merged

HananKavitzAmat merged 1 commit into
chunkhound:mainfrom
fstrasz:fix/realtime-end-active-change-upstream

Conversation

@fstrasz

@fstrasz fstrasz commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Problem

After a failed processing attempt, the next write to that file can be dropped and never indexed.

  • _consume_events (chunkhound/services/realtime/pipeline.py, "Layer 3") suppresses an event whose type and path match the last recorded event for that path within _EVENT_DEDUP_WINDOW_SECONDS (2.0 s). Since fix(realtime): never drop a duplicate event while the path's change is being processed #507 a created/modified duplicate still gets through while the path's change is active, because add_file then reserves a follow-up.
  • The record is cleared (self._recent_file_events.pop(str(file_path), None)) only after process_file succeeds.
  • When process_file raises (any non-cancellation error, including the compaction-busy error that schedules a retry), the finally block releases the active path, but the record stays.
  • A same-type write inside the window then arrives for a path that is no longer active, so it is suppressed, and nothing queues work for it. The index keeps the old content (or nothing, if the first attempt never indexed the file) until the file changes again.

This only happens on the error path, so it is rare.

Fix

The pop moves from the success path into the processing finally block, beside the release of the active path, so the record is cleared whether or not processing succeeded.

Cost: after a failed attempt, the next same-type write inside the window is processed instead of suppressed, which is what already happens after a successful attempt. A failed attempt's own reads produce no event, so this cannot loop.

This change does not depend on any other open PR. It applies to main on its own.

Evidence

Not reproduced end to end. Triggering it needs process_file to fail on a real file and a second write to land within 2 s, which takes fault injection. No end-to-end run was attempted against a real chunkhound mcp.

Test

tests/test_realtime_functional.py::test_write_after_failed_processing_inside_dedup_window_is_indexed. Both events go through the real event_queue, _consume_events and _process_loop, as the watcher's do. The first process_file raises. Once the loop's error handler has run (the path is no longer active), the file is rewritten and its event queued. The test asserts that the new content is processed. It widens _EVENT_DEDUP_WINDOW_SECONDS to 60 s on the service, so the second event is inside the window whatever the machine's speed.

  • On main: fails. It times out waiting for the second processing; the event was suppressed.
  • With this change: passes.
  • With the pop removed from the finally block: fails.

Run on Windows, Python 3.13, serially (-n 0): tests/realtime, tests/test_realtime_functional.py, tests/test_realtime_failures.py, tests/test_debounce.py.

passed failed skipped
main (with the new test) 133 1 (the new test) 34
this branch 134 0 34

32 of the 34 skips need a native Watchman runtime this source install does not have; one is Windows-only and one is Linux-only.

🤖 Generated with Claude Code

…suppresses the next write

The duplicate-event record (_recent_file_events) was popped only after a
successful process_file. When process_file raised, the path stopped being
active in the finally block but its record stayed, so a same-type write
within the 2 s dedup window was suppressed in _consume_events (the active-
path exception no longer applies) and nothing queued work for it. The
newer content stayed unindexed until the file changed again.

The pop moves into the processing finally block, beside the active-path
release, so it runs whether or not processing succeeded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@HananKavitzAmat

Copy link
Copy Markdown
Collaborator

looks good

@HananKavitzAmat
HananKavitzAmat added this pull request to the merge queue Nov 11, 2026
Merged via the queue into chunkhound:main with commit d211589 Nov 11, 2026
25 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