Skip to content

fix(file): require fully-loaded content for File:is_valid#197

Merged
dlyongemallo merged 1 commit into
mainfrom
fix_tab_not_first_diff
May 22, 2026
Merged

fix(file): require fully-loaded content for File:is_valid#197
dlyongemallo merged 1 commit into
mainfrom
fix_tab_not_first_diff

Conversation

@dlyongemallo
Copy link
Copy Markdown
Owner

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.

`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.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 loaded flag required by File:is_valid() to distinguish fully-populated buffers from mid-load placeholders.
  • Introduces per-File in-flight load coordination via a Signal so concurrent create_buffer() callers wait for the first load to finish and share its outcome.
  • Expands functional test coverage for the new loaded semantics 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.

Comment thread lua/diffview/vcs/file.lua
@dlyongemallo dlyongemallo merged commit 5e9de1d into main May 22, 2026
11 checks passed
@dlyongemallo dlyongemallo deleted the fix_tab_not_first_diff branch May 22, 2026 05:30
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