Skip to content

fix: race condition when moving to exact line/col - #2856

Merged
bajrangCoder merged 3 commits into
mainfrom
fix/project-search-navigation
Sep 5, 2026
Merged

fix: race condition when moving to exact line/col#2856
bajrangCoder merged 3 commits into
mainfrom
fix/project-search-navigation

Conversation

@bajrangCoder

Copy link
Copy Markdown
Member

No description provided.

@greptile-apps

greptile-apps Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR makes project-search result navigation resilient to overlapping asynchronous file opens.

  • Cancels obsolete navigation requests without waiting for their filesystem work to settle.
  • Verifies the target file remains active and fully loaded before revealing the match.
  • Reference-counts the shared title loader so overlapping opens cannot hide one another’s progress.
  • Adds focused tests for cancellation, stale navigation, restored tabs, coordinate clamping, and concurrent loader ownership.

Confidence Score: 5/5

The PR appears safe to merge; the prior navigation-blocking issue is resolved, and the loader fix addresses the remaining overlapping-open feedback issue.

The previously resolved obsolete-request finding remains fixed because newer navigation starts immediately and stale work is prevented from activating or revealing a file. The outstanding loader finding is now fully fixed by reference-counting active loaders and making cancellation release idempotent, so an obsolete open cannot hide the latest operation’s indicator.

Important Files Changed

Filename Overview
src/lib/openFile.js Adds cancellation checkpoints and reference-counted title-loader ownership for concurrent file opens.
src/sidebarApps/searchInFiles/index.js Delegates search-result opening and exact-range navigation to the new race-safe helper.
src/sidebarApps/searchInFiles/navigateToResult.js Cancels obsolete requests and validates target identity and loading state before revealing a clamped range.
tests/unit/openFileCancellation.test.js Covers cancellation across asynchronous stages and shared-loader behavior under overlapping opens.
tests/unit/searchResultNavigation.test.js Covers latest-request behavior, restored tabs, stale targets, exact ranges, and recovery after failures.

Sequence Diagram

sequenceDiagram
    participant User
    participant Nav as navigateToResult
    participant Open as openFile
    participant Filesystem
    participant Editor

    User->>Nav: Select search result
    Nav->>Nav: Abort previous navigation
    Nav->>Open: Open target with AbortSignal
    Open->>Filesystem: Stat/read target
    User->>Nav: Select newer result
    Nav->>Nav: Abort obsolete signal
    Nav->>Open: Open newer target
    Open-->>Nav: Newer target activated
    Nav->>Editor: Load and verify active file
    Nav->>Editor: Reveal exact range
    Filesystem-->>Open: Obsolete operation settles
    Open-->>Nav: Discard obsolete result
Loading

Reviews (3): Last reviewed commit: "fix(search): preserve loader during conc..." | Re-trigger Greptile

Comment thread src/sidebarApps/searchInFiles/navigateToResult.js Outdated
@bajrangCoder

This comment was marked as outdated.

Comment thread src/sidebarApps/searchInFiles/navigateToResult.js
@bajrangCoder

This comment was marked as outdated.

@bajrangCoder
bajrangCoder added this pull request to the merge queue Sep 5, 2026
Merged via the queue into main with commit fedf1e1 Sep 5, 2026
11 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in The Code Board - Acode Sep 5, 2026
@bajrangCoder
bajrangCoder deleted the fix/project-search-navigation branch September 5, 2026 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant