Skip to content

fix(browser): refresh folder counts after file operations - #1937

Merged
l0gicgate merged 2 commits into
mainfrom
fix/1917-refresh-folder-item-counts
Oct 30, 2026
Merged

l0gicgate merged 2 commits into
mainfrom
fix/1917-refresh-folder-item-counts

Conversation

@JoeJoeflyn

@JoeJoeflyn JoeJoeflyn commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Refresh folder item counts after file operations in Columns, Icons, and List using the existing shared operation notifications and viewport metadata workers. Handle stale metadata/listing results, shifted rows, multiple windows, overlapping operations, and undo without reloading parent listings or recounting offscreen folders. Reuse the cached metadata index to resolve shifted targets.

Visual evidence

folder-count-demo.mp4

How to test

  1. In Icons view, drag-copy or move a document onto an empty folder without opening it.
  2. Drop another document into that folder, then undo both operations. Repeat in List and Columns, optionally with the parent open in another window.
  3. Create or remove a sibling folder that sorts before the target, then repeat a drop to check counts after rows shift.

Expected result: The folder count updates automatically from empty to one, then two, and back to empty after undo. Selection stays intact and no manual refresh is needed.

Related issue

Closes #1917

Reuse shared operation-ended notices and viewport metadata admission to update counts without reloading parent listings. Reject stale fills and listings, preserve unrelated work, and resolve shifted targets through the cached metadata index.

Cover successive copy/move drops, row insertion/removal, undo, multiple browsers, overlapping writers, and offscreen/unbound metadata lifecycle.

Fixes #1917
@github-actions github-actions Bot added the fix label Oct 29, 2026
@JoeJoeflyn

Copy link
Copy Markdown
Collaborator Author

Implemented in 354c38a9.

The fix reuses the shared operation-ended subscription, viewport admission/batching, and the existing cached location index. It updates source/destination counts across browsers without parent-list reloads, preserves unrelated fills, cancels obsolete-only batches, waits for overlapping writers, and handles stale results/listings and shifted rows. The existing drop scenario now covers move/Ctrl-copy, successive drops, insertion/removal before the target, and undo in all three views.

Validation scope and results

Shared activity notifications and viewport routing warranted an initial full Rust and full QA run. Failures were subsequently isolated rather than repeating unrelated suites.

  • Original count reproduction and the additional shifted-row reproduction both failed on the count assertion after the filesystem copy succeeded, then passed with the fixes.

  • Final affected Rust selection: 139 passed, including the real GTK subprocess cases:

    ./scripts/test-headless.py -- \
      app::navigation::tests:: \
      app::browser::tests::folder_ \
      app::browser::tests::metadata:: \
      app::browser::loading::metadata::tests:: \
      services::file_activity::tests:: \
      ui::thumbnail::viewport::tests:: \
      ui::window::tests::preferences::columns_size_visibility_loads_and_updates_across_windows_and_rebuilds \
      ui::window::tests::preferences::folder_item_counts_fill_visible_rows_in_each_view \
      ui::window::tests::preferences::show_thumbnails_saved_and_live_preferences_apply_across_windows_and_views
  • ./scripts/qa.sh drag-file-onto-folder --test-threads 3: 6 passed on the final behavior.

  • ./scripts/qa-mutation.sh drag-file-onto-folder: 6 baseline runs passed; all 6 mutated runs failed as intended.

  • ./scripts/trace-main-io.py drag-file-onto-folder/icons-copy: 0 violations on the final code.

  • Private ./scripts/qa-drive.sh session: copied into a previously counted folder after a preceding-row insertion; file arrived and the count updated without F5.

  • Final ./scripts/quality.sh fmt, ./scripts/quality.sh clippy, and git diff --check: passed.

Retained full-run results

  • ./scripts/quality.sh test aborted when a new regression fixture left an idle callback for another test thread. The exact reported folder-sort test passed alone; the bounded app::browser::tests::folder_ selection reproduced the leak. The fixture now dispatches through the real idle and cancels its owned work on teardown. The final 139-test selection includes the formerly failing consumers and passes. The full Rust run was not repeated; CI remains the authoritative full gate.
  • ./scripts/qa.sh: 633 passed, 2 failed (preview-find-navigates-content/columns-default, markdown-equations-keep-prose/columns). Both passed when selected exactly with --test-threads 1, and both passed again alongside the six drop runs in an eight-run scoped selection. Their source/tests were not changed. No full QA rerun was used to replace that result.

QA quality was re-rated 3/4/4/4 = 49, with costs calibrated from the measured full-run inventory and final scoped timings. Independent Haiku grading could not run: the configured provider returned HTTP 402 (account balance required); it is not reported as passed.

No owner-policy overrides, host QA runs, desktop display/session-bus use, image rebuilds, or baseline updates were needed. Logs and investigation-only artifacts remain ignored under target/issue-1917/.

@JoeJoeflyn

JoeJoeflyn commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator Author

Measured before/after folder-count workflow benchmark

Icons view, moving a small text file into an existing visible folder. 10 measured moves per build per fixture, after two automatic-update probes and one excluded warmup.

Initial parent entries Before: immediate F5 workaround, median After: automatic update, median Lower latency Main-thread CPU before → after
100 938 ms 537 ms 42.8% 520 → 230 ms (55.8% lower)
10,000 2,122 ms 760 ms 64.2% 1,885 → 620 ms (67.1% lower)

Measured work per operation:

  • Parent reloads: 1 → 0 in every measured trial.
  • Median parent entries re-enumerated: 91.5 → 0 in the 100-entry fixture and 9,991.5 → 0 in the 10,000-entry fixture. The parent shrinks as source files are moved.
  • Median metadata row-update applications: 26 → 4 (not unique files or filesystem calls).
  • Median metadata request batches: 2 → 2 for 100 entries; 2 → 1 for 10,000 entries. No claim that batching improves in every case.
  • Automatic-update probes: the baseline stayed stale in 4/4 one-second waits after file arrival; the fix updated in 4/4. All measured moves verified file contents and removal from the source.

Method and limitations

  • Before: unmodified 44bfeab305cfb68993bafcf4794fe0bbf7ff1433; after: 354c38a992232466e557ece80ec8ba1da08e53aa.
  • Both builds used the same pinned image ID, 7e4de6a7728868b9c5ddc9b67a6eafca1529b7f08d700f072cb1c616b42c40f8, debug build with qa,invariant-checks, private Xvfb and private D-Bus. No host QA, desktop access, image rebuild, dependency change, or application instrumentation.
  • AMD Ryzen 7 3750H, 8 logical CPUs; Linux 7.1.9-arch1-2. Warm process/filesystem/metadata caches; software rendering; fixtures in the runner's private /tmp tmpfs. Runs were sequential, before then after for each fixture size.
  • Latency starts at release of a prepared drag and ends when the real folder-count label passes its assertion. It includes QA IPC/polling overhead. Baseline additionally presses F5 immediately after file arrival; no artificial probe timeout or human reaction delay is included in the timed samples.
  • This compares the old F5 workaround with the fixed automatic workflow, not two working automatic implementations. The baseline never refreshed automatically in its probes.
  • Main-thread CPU uses the existing scripts/benchmark-scroll.py /proc helpers, measured through post-count quiescence. Kernel accounting has 10 ms tick resolution. Reloads, enumerated entries, request batches, and row updates come from existing debug logs.
  • This is a scoped workflow benchmark, not release-build FPS, isolated rendering latency, or storage throughput. Ten samples are a small local measurement, not a cross-machine guarantee.
  • An initial held-drag pilot accidentally triggered hover navigation and was excluded (excluded-held-hover/). The first large-fixture launch exceeded the environment-argument limit; the fixture is now populated before restarting the isolated app, outside measurement. Neither unsuccessful setup contributed samples.

Reproduction and records

On the task machine:

python3 target/issue-1917/benchmark/run.py --samples 10 --sizes 100,10000

The detached baseline worktree and reflinked build cache are retained at target/issue-1917/benchmark-before/; the task checkout remains unchanged.

Raw data: target/issue-1917/benchmark/results.json, the four before/after-icons-<size>.json reports, per-round application logs, command/reply transcripts, startup logs, image IDs, and binaries.sha256. Investigation-only files are ignored, not committed.

@JoeJoeflyn

Copy link
Copy Markdown
Collaborator Author

CI status update: quality build/lint and Rust shards 0, 1, and 3 passed. Shard 2 failed only i18n::catalog_tests::catalogs_cover_all_languages_and_preserve_interpolation: Hungarian catalogs are missing the administrator-access messages introduced before this branch. The complete data/locales tree is identical in baseline 44bfeab3 and fix 354c38a9 (tree af2f379f2518f59c80beed07c1fa10cb681cea6e). No full-suite green or merge is claimed; the required aggregate gate is still failing. The before/after benchmark and its raw records are in the preceding comment. Benchmarking changed no tracked files.

@l0gicgate

Copy link
Copy Markdown
Contributor

Review

Merged main at fc4d2bbe8 into the branch (merge commit 9972932ed, no conflicts). That merge also picks up the Hungarian administrator strings, so the shard-2 i18n::catalog_tests failure from the previous CI run no longer applies: i18n:: passes locally on the merged tree (12 tests).

Reviewed the full diff against the updated main. No merge-blocking issues found, so no code changes beyond the merge:

  • invalidate_folder_counts / invalidate_count_entries keep state borrows scoped before emit, cancel only fills whose remaining tokens are empty, and re-admission goes through the existing viewport refresh rather than reloading parent listings.
  • Directory targets now stay registered in the viewport map after a successful fill; the details flag is true for directories in Icons, List and Columns (with sizes shown), so icon_details_need_fill re-admits a folder once its count is reset to Unknown.
  • Notice::covers for Ended is equivalent to the previous starts_with check, just split per scope kind.
  • The LoadFinished follow-up invalidation is justified: local_files enumerations with include_metadata stamp child_count at listing time, so a listing in flight during an operation can publish pre-operation counts.
  • New tests are behavioral (multi-browser invalidation without reload, stale-result rejection with unrelated batches preserved, tree vs folder scope, listing finishing after an operation, live-visible-only admission after the last writer, shifted-row resolution). New comments are limited to rationale and were kept.

Local validation on the merged tree:

  • ./scripts/test-headless.py (full native Rust suite): 3671 passed, 1 failed, 11 ignored. The failure is ui::virtual_preview::tests::smooth_content_scrolling_keeps_thumb_and_hit_testing_in_document_order, which fails identically on the main checkout without this PR and passed in this PR's earlier CI shards; it is a host-environment issue unrelated to this change.
  • The PR's scoped selection (navigation, browser folder/metadata, file_activity, viewport, preferences): 139 passed.
  • ./scripts/qa.sh --test-threads 6 drag-file-onto-folder: 6 passed.
  • ./scripts/qa-mutation.sh drag-file-onto-folder: baseline passed, 1 of 1 mutation caught.
  • cargo fmt --all --check, cargo clippy --all-targets --all-features -- -D warnings, git diff --check: clean.

@l0gicgate
l0gicgate merged commit 7a095a9 into main Oct 30, 2026
11 checks passed
@l0gicgate
l0gicgate deleted the fix/1917-refresh-folder-item-counts branch October 30, 2026 03:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Folder item count doesn't update in Icons view until refresh

2 participants