Repository navigation
[RunInference] Fix WatchFilePattern selecting the newest model - #40765
AmoghAtreya wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
📋 Review Summary
This PR fixes a bug in WatchFilePattern (#40638) where model files were keyed by their individual paths before stateful timestamp comparison, causing older models to be emitted and multiple files within a single poll to break AsSingleton side input consumption in RunInference. By keying all matched files with a shared global key, reducing each triggered pane via CombinePerKey(_LatestFileCombineFn()), and tracking the latest modification timestamp in _EmitLatestModel, the transform now reliably emits at most one newest model per pane.
🔍 General Feedback
- The pipeline topology change—applying
WindowIntowithRepeatedly(AfterProcessingTime(1))andDISCARDINGaccumulation mode beforeCombinePerKeyand the stateful_EmitLatestModelParDo—is clean and preserves windowing/triggering strategies downstream forAsSingletonside inputs. - Deterministic tie-breaking by file path in
_is_newerensuresCombineFncommutativity and associativity. - Unit test coverage in
utils_test.pythoroughly exercises combine order independence, tie-breaking, pre-start filtering, single-poll reduction, and multi-poll state progression viaTestStream.
💡 Tip: Comment /gemini review on this pull request to trigger a new Gemini code review.
|
Assigning reviewers: R: @tvalentyn for label python. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
WatchFilePatternkept its newest-timestamp state under each file path. Beam partitions that state by key, so each path was compared only with the pipeline start time. Any file newer than startup was treated as the latest model, and a poll that saw several of them emitted all of them.RunInferencereads this side input withAsSingleton, which rejects more than one value.Every watched file now shares one key, and the newest modification time seen so far is remembered. Each poll is reduced to the single newest file. A later file is emitted only when its modification time is newer than that. Files already present at pipeline construction stay on the model configured on the handler.
A model update still needs a new filename. The file watcher reports a path once, and
RunInferencereloads only when the path changes. A rollback has to be uploaded under a new name with a newer modification time.Fixes #40638.
Test plan
utils_test.py: several files in one poll, out of order, emit only the newest model, andAsSingletonaccepts that value.CHANGES.mdnotes the fix.