Skip to content

fix(ui): report find-missing failures and timeouts correctly - #1598

Merged
echelon merged 1 commit into
storytold:mainfrom
NavidZamanKhan:fix/find-missing-wait-result
Oct 14, 2026
Merged

echelon merged 1 commit into
storytold:mainfrom
NavidZamanKhan:fix/find-missing-wait-result

Conversation

@NavidZamanKhan

Copy link
Copy Markdown
Contributor

Fixes #1528

Problem & Reproduction

When invoking file.findMissing with {"wait": true, "folder": <path>}, the command previously called tasks::wait(app, &ctx, Duration::from_secs(600)) and returned Some(Ok(app.ui.last_find_missing.clone().unwrap_or(Value::Null))).

Under this implementation:

  • If the target folder is invalid (nonexistent or inaccessible), the background search worker fails, toasts an error, but never sets last_find_missing. The caller receives Ok(null) instead of a descriptive error.
  • If the search times out or the worker disconnects unexpectedly, last_find_missing remains None, also silently returning Ok(null).
  • Callers (scripts, control channel, MCP) had no programmatic way to distinguish a successful search finding 0 photos from a failed or timed-out search.

Solution

1. Typed Task Results & Error Propagation

  • Added last_find_missing_result: Option<Result<serde_json::Value, String>> to UiState.
  • On search completion, the result is captured as Some(Ok(v)) or Some(Err(e)).
  • When wait: true is requested, file.findMissing takes last_find_missing_result:
    • Returns Ok(v) containing {found, missing, ambiguous} on success.
    • Returns Err(e) with the actionable error message if the search or relinking failed.
    • Returns Err("Find Missing Photos: worker terminated unexpectedly") if the background thread terminated without delivering a result.

2. Task-Specific Waiting (tasks::wait_for)

  • Replaced the global tasks::wait call with tasks::wait_for(app, ctx, label, timeout).
  • tasks::wait_for loops and polls tasks, returning true as soon as the specific "Find Missing Photos" task finishes.
  • Unrelated background tasks (e.g. auto-import directory listings, catalog scans, preview generation) remain active and do not block or cause false timeouts for file.findMissing.

3. Strict Timeout Validation & Continuation Behavior

  • Added parameter validation for wait and timeout:
    • Defaults to 600 seconds when omitted.
    • Supports positive finite floating-point values (e.g. fractional seconds).
    • Explicitly rejects negative numbers, wrong types, and excessively large floats where Duration::try_from_secs_f64 fails with file.findMissing: \timeout` is too large` (avoiding silent 600s fallback).
  • When a search times out, file.findMissing returns Err("Find Missing Photos: search timed out (search continues in the background)").
  • The background task continues running in app.tasks, ensuring no work is wasted.
  • Non-waited searches (wait: false or omitted) continue returning {"background": true} immediately.

4. Test-Only Delay Injection

  • No artificial delay parameters (such as _test_delay_ms) are exposed in the production command interface or public JSON schemas.
  • Added #[cfg(test)] pub find_missing_test_delay: Option<Duration> to UiState to allow integration tests to test timeouts deterministically without changing production behavior.

Verification & Tests

Regression Tests Added (crates/ui-egui/src/menubar.rs):

  • find_missing_waited_invalid_folder_returns_error_with_zero_mutations:
    • Confirms nonexistent folder returns a descriptive error rather than Ok(null).
    • Verifies zero undo mutations and unchanged catalog state on failure.
    • Verifies rejection of negative, non-numeric, and excessively large (1e300) timeouts.
  • find_missing_waited_structured_results_and_background_mode:
    • Confirms wait: true returns {found, missing, ambiguous} JSON directly on success.
    • Confirms background mode (wait omitted) returns {"background": true} immediately.
  • find_missing_waited_timeout_behavior:
    • Confirms deterministic timeout error and continuation notification using find_missing_test_delay.
    • Confirms the worker continues executing in the background after timeout.
  • find_missing_waited_completes_while_unrelated_task_remains_active:
    • Confirms tasks::wait_for completes as soon as Find Missing finishes, even while an unrelated blocked background worker remains active in app.tasks.

Test Results

  • cargo test -p lightcraft-ui-egui --lib find_missing: 6/6 passed (1.12s).
  • cargo test -p lightcraft-ui-egui --lib tests_panels::a_folder_menu_locates_its_missing_tree_only: Passed.
  • cargo fmt --all -- --check: Passed.
  • cargo clippy -p lightcraft-ui-egui --all-targets -- -D warnings: Passed (0 warnings).
  • cargo xtask parity: OK (568 rows, 1,244 references).
  • cargo xtask layers: OK (31 crates, 0 layering violations).
  • cargo xtask assets: OK (all 42 assets attributed).

Pre-existing CI Failure Disclosure

The unrelated test all_masks_overlay_shows_every_visible_mask_at_once in crates/pipeline/src/visualize.rs fails on upstream main due to an unrelated color expectation mismatch in pipeline visualization. This patch does not touch crates/pipeline/.

@echelon

echelon commented Oct 14, 2026

Copy link
Copy Markdown
Member

Thank you @NavidZamanKhan! This landed on main in integration batch 35 (#1682).

If you haven't already, please join our Discord: https://discord.gg/artcraft. We'd love to have you there.

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.

file.findMissing wait=true returns successful null when the search fails or times out

2 participants