Fix flaky diff_pipeline_computes_added_lines_and_ghost_blocks TUI test#13683
Draft
warp-dev-github-integration[bot] wants to merge 1 commit into
Draft
Fix flaky diff_pipeline_computes_added_lines_and_ghost_blocks TUI test#13683warp-dev-github-integration[bot] wants to merge 1 commit into
warp-dev-github-integration[bot] wants to merge 1 commit into
Conversation
Two races made this test flaky: 1. The test's bounded ghost wait (100x yield_now) raced the async layout channel: spawn_stream_local polls the layout stream on the background executor before dispatching back to the foreground, so ghost-block delivery latency is unbounded while the yield loop spins out in microseconds. The waits are now event-driven (DiffUpdated / LayoutInvalidated) instead of bounded spinning. 2. DiffModel::compute_diff aborts a superseded computation only best-effort; a computation that already completed on the background thread still delivered its stale result, clobbering a newer diff and re-triggering refresh_diff_state with the stale status. The completion callback now drops results that are no longer the latest requested computation. Verified with 1100 runs of the test (800 under full CPU load): 0 failures, versus 20/300 failures for the original test under the same load. Co-Authored-By: Oz <oz-agent@warp.dev>
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.
Description
Fixes the flaky TUI test
diff_pipeline_computes_added_lines_and_ghost_blocksincrates/warp_tui/src/tui_file_edits_view_tests.rs(e.g. it flaked on a CI run for #13486, failingassert_eq!(ghosts.len(), 1)withleft: 0).Root cause
Two races combined to make the test flaky:
1. Bounded spinning raced the async layout channel (dominant race).
Ghost blocks travel through
RenderState's layout channel, andspawn_stream_localpolls that channel on the background executor before forwarding each item to a foreground dispatch task (crates/warpui_core/src/core/app.rs,spawn_stream_local). So afterexpand_diffs, ghost delivery makes a round trip through a background thread and its latency is unbounded under load. The test's wait —for _ in 0..100 { ... yield_now().await }— spins through the foreground executor in microseconds and gives up long before the background thread forwards theLayoutTemporaryBlockaction, leavingghostsempty. Instrumented traces confirmed failing runs whererefresh_diff_stateproduced the ghost block butset_temporary_blocksnever ran before the loop exhausted.2. Stale diff computations could clobber newer results.
reset_contentschedules its own diff computation (the buffer reset emitsContentChanged, recomputing against the just-set base), and the recompute triggered byapply_diffsonly best-effort aborts it:ctx.spawnstarts the future on the background executor immediately, andcompute_diff_internalyields per diff op, so the two in-flight computations interleave on the background worker and can complete in either order. A superseded computation that already completed still delivered its result, overwriting the newer diff status and emitting a misleadingDiffUpdated(which, with diff nav expanded, re-runsrefresh_diff_statewith the stale status and can clear the ghost blocks).Fix
DiffModel::compute_diff(app/src/code/editor/diff.rs): the completion callback now drops results that are no longer the latest requested computation (compared against the version stored alongside the abort handle), so stale results never clobber a newer diff. This also hardens the production diff pipeline, where last-write-wins by completion order was incorrect.crates/warp_tui/src/tui_file_edits_view_tests.rs): both waits are now event-driven instead of bounded spinning. It subscribes toDiffUpdated/LayoutInvalidatedon an unbounded channel, waits until the diff model actually contains the applied hunk before expanding, and then re-checks for ghosts after eachLayoutInvalidated(emitted right after the render state stores the temporary blocks) rather than spinning a fixed number of iterations.Linked Issue
N/A — flaky-test fix; no tracked issue.
Testing
ghosts.len():left: 0).cargo nextest run -p warp_tui --lib: 102/102 passed.cargo nextest run -p warp_editor: 458/458 passed.cargo nextest run -p warp code::editor: 95/95 passed (coversdiff_testsand editormodel_tests)../script/formatclean;cargo clippy -p warp -p warp_tui --all-targets --features tui -- -D warningsclean.This is a headless-test/infrastructure change with no user-visible behavior, so no manual
./script/runtesting or screenshots.Agent Mode
CHANGELOG-NONE
Conversation: https://staging.warp.dev/conversation/b96d06d2-7f01-4e47-acef-6039567955c8
Run: https://oz.staging.warp.dev/runs/019f5d59-095b-7b38-a79c-8cc11cf4b5c6
This PR was generated with Oz.