Skip to content

Fix watch-folder startup race on Python 3.13#21

Merged
brianmeyer merged 1 commit intomasterfrom
codex/rec-178-watch-start-race
Mar 22, 2026
Merged

Fix watch-folder startup race on Python 3.13#21
brianmeyer merged 1 commit intomasterfrom
codex/rec-178-watch-start-race

Conversation

@brianmeyer
Copy link
Copy Markdown
Owner

Summary

  • capture the initial watch snapshot synchronously in start_watch before returning
  • start the scanner thread from that baseline so immediate post-start file creates are not missed
  • preserve existing logical-path indexing and child-cleanup behavior

Testing

  • pytest -q tests/test_watch_folder.py -k "document_uses_logical_path_and_child_cleanup or image_uses_logical_path"
  • for i in 1 2 3 4 5; do pytest -q tests/test_watch_folder.py -k document_uses_logical_path_and_child_cleanup >/tmp/recallforge-watch-$i.log || { cat /tmp/recallforge-watch-$i.log; exit 1; }; done
  • pytest -q tests/test_watch_folder.py
  • pytest -x -m "not live" --tb=short

Refs REC-178

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d4bda8e6a0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

evt = self.running[watch_id]

prev = self._build_snapshot(config)
prev = dict(initial_snapshot or self._build_snapshot(config))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve empty initial snapshot when starting scanner

When the watched folder is empty at startup, initial_snapshot is {} (falsy), so initial_snapshot or self._build_snapshot(config) performs a second snapshot in the scanner thread. Any file created between start_watch() taking the first snapshot and this second snapshot is treated as already present in prev, so no created event is emitted for it. This reintroduces the startup race for the common empty-directory case the change is trying to fix.

Useful? React with 👍 / 👎.

@brianmeyer brianmeyer merged commit 1c655eb into master Mar 22, 2026
4 checks passed
@brianmeyer brianmeyer deleted the codex/rec-178-watch-start-race branch March 22, 2026 19:19
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.

1 participant