Skip to content

Shell: Rebuild Search Helper Launch Arguments When Folders Change (#199) - #199

Open
Ocean572 wants to merge 1 commit into
ARahim3:mainfrom
Ocean572:fix/folders-after-restart-170
Open

Ocean572 wants to merge 1 commit into
ARahim3:mainfrom
Ocean572:fix/folders-after-restart-170

Conversation

@Ocean572

@Ocean572 Ocean572 commented Nov 6, 2026 •

Copy link
Copy Markdown

Shell: Rebuild Search Helper Launch Arguments When Folders Change (#199)

Closes #170.

Problem

The shell originally built the search helper's launch arguments once during setup and reused them every time the helper started.

When a folder was added during an active session, the running helper received the update through the live folders request, so searches worked as expected. However, if the helper exited automatically (for example, due to inactivity) and the shell restarted it, the original launch arguments were reused.

This caused the newly added folder to disappear from the helper's configuration. As a result:

  • Files in the newly added folder were no longer included in search results.
  • The Settings interface continued to display the folder, but its indexing status became incorrect.
  • The X of Y indexed count no longer reflected the actual indexing state.

Changes

This PR changes the search helper's launch arguments from a static list into a factory function, search_arguments(), allowing them to be rebuilt using the current application state.

The current launch configuration is now maintained by SearchService through:

  • launch: Mutex<Launch> — protects the current launch configuration.
  • set_launch_args — updates the saved launch arguments.

Two operations now rebuild the saved arguments whenever the folder configuration changes:

  • apply_folders — updates the saved launch arguments whenever folders are added, removed, or modified, before sending the corresponding live request to the running helper.
  • turn_off_code — updates the saved arguments when code indexing is disabled, ensuring that a subsequently restarted helper does not reopen the code index.

This keeps the saved launch configuration synchronized with the current Settings state. Any subsequent helper restart now uses the latest folder configuration, including exclusions and code-index settings.

Concurrency and Process Startup

A related issue was identified during pre-push code review.

Previously, start() chained launch.lock().unwrap().clone() directly into .spawn(). Because a MutexGuard remains alive until the end of its statement, this meant the launch mutex was held throughout process creation.

On Windows, antivirus scanning can make process creation take hundreds of milliseconds. Holding the mutex during this operation could therefore block set_launch_args() while a new helper process was starting.

The implementation now takes a snapshot of the launch configuration into a separate let binding before spawning the process.

This provides two important guarantees:

  • The launch mutex is released before process creation begins, allowing configuration updates to proceed without waiting for fork/exec.
  • The configuration swap remains atomic. A newly spawned helper receives either the complete previous argument list or the complete updated argument list, never a partially updated configuration.

Testing and Verification

Measured on the development machine:

Hardware and environment: Apple M1, 8 GB RAM, macOS 26.5.1.

Rust Tests

  • cargo test: 15 tests passed.
  • Includes two new unit tests verifying that the rebuilt launch arguments:
    • Include the current folders and their exclusions.
    • Include configured code folders and the index flag.
    • Omit the index flag when no code folders are configured.

End-to-End Verification

Tested against the Swift search helper.

The test started with one indexed root and then expanded the folder configuration to three roots through op:folders.

Two restart scenarios were compared:

Scenario Indexing result
Restart using the original startup arguments Only root1 was indexed
Restart using rebuilt launch arguments All three roots were indexed

The rebuilt configuration successfully restored the expected indexing state:

root1:2, root2:1, root3:1

This reproduces the original issue and verifies that rebuilding the launch arguments resolves it.

Additional Test Suites

  • Swift test suite: 125 tests passed (no Swift changes in this PR).
  • Shell JavaScript tests: node --test — 17 tests passed.

Scope and Limitations

Windows GUI acceptance testing remains outstanding.

The development environment validates the shell's Rust unit tests but does not run the Tauri GUI application. Windows 11 GUI acceptance testing remains the responsibility of the reporter or maintainer.

Adjacent environment-variable behavior is unchanged and out of scope.

The saved launch environment currently carries DIGUP_MODELS but does not include DIGUP_DEVICE.

set_processor_only relies on this behavior for the index helper, which rebuilds its environment independently. The search helper had the same behavior before this PR, and this change does not modify it.

…ge, so a restarted helper keeps them

The Windows/Linux shell built the search helper's launch arguments once at setup and
replayed them every time the helper started. A folder added during the session reaches a
*running* helper through the live `folders` request, so it works — but when that helper
exits by itself (idle) and the shell starts a new one from the saved arguments, the added
folder is gone: the helper searches only the startup folders, so Settings rows stop
showing `X of Y indexed` for it and its files drop out of search results (issue ARahim3#170,
Windows 11, 0.7.0-beta.3; local folders added after startup show the same mechanism).

The arguments are now a factory, `search_arguments()`, and the running set is saved in the
`SearchService` (`launch: Mutex<Launch>`, `set_launch_args`). `apply_folders` — called on
every folder change — and `turn_off_code` — which must not let a restarted helper reopen
the code index the person just closed — both rebuild the saved list before sending the
live request, so the next helper starts with exactly what Settings shows.

A pre-push review folded in one detail: `start()` chained `launch.lock().unwrap().clone()`
straight onto `.spawn()`, and a MutexGuard in a statement lives to the statement's end —
the launch mutex stayed held across fork/exec (hundreds of ms under Windows AV scanning),
stalling `set_launch_args` exactly while a helper is being born. The snapshot is a `let`
now, and spawn runs without the lock; the swap stays atomic (a spawn sees all-old or
all-new arguments, never a half-written list). Redundant clones in the unit tests went
too. Known adjacent staleness, out of scope here: the saved launch env carries
`DIGUP_MODELS` only, never `DIGUP_DEVICE` — `set_processor_only` relies on it for the
index helper only, which rebuilds its env fresh; the search helper behaved identically
before this change.

Verified on this box: cargo test 15 green, including two new unit tests that check the
rebuilt argument list carries the current folders, their exclusions, the code folders, and
the index (and drops the index flag when there is none). End to end against the Swift
helper: after `op:folders` grows 1 root to 3, a restart with startup args shows the
reporter's symptom (summaries: root1 only), a restart with rebuilt args restores all
three (root1:2, root2:1, root3:1 indexed). Swift suite 125 green (no Swift changes),
shell JS tests 17 pass. GUI acceptance on Windows is the reporter/maintainer's call —
this box runs only the shell's Rust unit tests, not the Tauri app.
@Ocean572 Ocean572 changed the title Shell: rebuild the search helper's launch arguments when folders change Shell: Rebuild Search Helper Launch Arguments When Folders Change (#199) Nov 6, 2026

This branch has not been deployed

No deployments
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.

Search helper restart loses folders added after app startup: missing indexed counts and excluded search results

1 participant