fix(file): require fully-loaded content for File:is_valid#197
Merged
Conversation
`is_valid()` returned true as soon as `bufnr` was set, but `create_buffer` allocates the bufnr before awaiting `produce_data` -- so a concurrent caller could short-circuit on an empty placeholder. Add a `loaded` flag (set after content population) required by `is_valid()`, and a `Signal` so concurrent `create_buffer` callers on the same File wait for the in-flight load.
There was a problem hiding this comment.
Pull request overview
This PR fixes a race in vcs.File:create_buffer() where File:is_valid() could return true after bufnr allocation but before buffer content was populated, allowing concurrent callers to observe an empty placeholder buffer.
Changes:
- Adds a
loadedflag required byFile:is_valid()to distinguish fully-populated buffers from mid-load placeholders. - Introduces per-
Filein-flight load coordination via aSignalso concurrentcreate_buffer()callers wait for the first load to finish and share its outcome. - Expands functional test coverage for the new
loadedsemantics and concurrent loading behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| lua/diffview/vcs/file.lua | Adds loaded validity gating, in-flight load signaling, and buffer reuse/wipe guards to prevent half-built diffview:// buffers from escaping. |
| lua/diffview/tests/functional/window_spec.lua | Updates window tests to mark injected buffers as loaded so file:is_valid() behaves as intended. |
| lua/diffview/tests/functional/file_spec.lua | Adds functional coverage for loaded semantics, same-instance concurrency waiting, cancellation/error propagation, and buffer wipe behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
is_valid()returned true as soon asbufnrwas set, butcreate_bufferallocates the bufnr before awaitingproduce_data-- so a concurrent caller could short-circuit on an empty placeholder.Add a
loadedflag (set after content population) required byis_valid(), and aSignalso concurrentcreate_buffercallers on the same File wait for the in-flight load.