https://bugs.kde.org/show_bug.cgi?id=529115

            Bug ID: 529115
           Summary: KCoreDirLister cache refresh duplicates filenamesearch
                    results when distinct URLs share a basename
    Classification: Frameworks and Libraries
           Product: frameworks-kio
      Version First 6.13.0
       Reported In:
          Platform: Debian stable
                OS: Linux
            Status: REPORTED
          Severity: normal
          Priority: NOR
         Component: general
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
  Target Milestone: ---

Created attachment 198653
  --> https://bugs.kde.org/attachment.cgi?id=198653&action=edit
Minimal reproducer, synthetic controls, candidate patch and sanitized
notification evidence

SUMMARY
An unchanged filenamesearch listing is initially correct, but each cache update
re-adopts already-listed URLs as new whenever different directories contain
files with the same basename. This happens with KCoreDirLister alone, without
Dolphin or any downstream customization. Stock Dolphin accepts these repeated
items, inflating the visible model and making subsequent sorting expensive.

MINIMAL REPRODUCER
The attached report-reproducer directory contains CMakeLists.txt, main.cpp,
make-fixture.py and README.txt. Run from an ordinary Linux desktop D-Bus
session:

  cmake -S report-reproducer -B build
  cmake --build build
  fixture=$(python3 report-reproducer/make-fixture.py)
  ./build/kio-search-refresh-repro "$fixture"

The fixture has only two regular files:
  0/ff-0.txt
  1/ff-0.txt
No symlinks are involved. The program opens a filenamesearch URL for "ff",
waits for listingDirCompleted, then calls the public updateDirectory() once.
The files are not changed between listings. Automatic directory updates are
disabled, so the test exercises exactly one explicit update.

OBSERVED
  initial=2, after_update=3, unique_urls=2, unique_names=1,
  unexpected_additions=1, same_url_set=true, exit status 1
EXPECTED
  initial=2, after_update=2, unique_urls=2, unexpected_additions=0,
  same_url_set=true, exit status 0

CONTROLS
- 12 directories with the same 500 distinct ff*.txt basenames per directory:
  6000 initial rows -> 11500 rows after one unchanged update;
  6000 unique URLs, 500 unique basenames, 5500 erroneous additions.
- 12 directories with 500 DIFFERENT basenames in each directory:
  6000 initial rows -> 6000 after update; zero erroneous additions.
- Thus, for a clean listing of N distinct URLs and K distinct basenames,
  one unchanged update adds N-K extra entries.

STOCK DOLPHIN CONFIRMATION
Actual installed /usr/bin/dolphin, Qt offscreen, isolated profile, no
LD_PRELOAD,
no LD_LIBRARY_PATH override and no downstream plugins:
- Open the two-file fixture with the native filenamesearch URL and native
  English title "Query Results from 'ff'".
- Select icons, descending size sort and previews.
- Send the normal session D-Bus org.kde.KDirNotify.FilesAdded signal to the
  virtual search URL after completion. Wait for the update; send it again.
- The model contains 2 -> 3 -> 4 records. No file is added or changed.
The model count was read through /proc/PID/mem without modifying the process.

The exact URL must match Dolphin's current canonical search URL. Opening an
untitled search URL causes Dolphin to replace it with a titled URL; notifying
the stale untitled URL has no effect and is not a negative result for this bug.

A separate trace-assisted six-case comparison uses a 6000-file fixture,
icons, descending size sorting and previews. After one FilesAdded update:
  Application                         F11 closed       F11 open
  Stock Dolphin                       11500            11500
  Downstream pre-fix DolphinXplorer    11500            11500
  Downstream with model URL guard       6000             6000
Every case starts with 6000 rows and still represents exactly 6000 URLs.
The downstream guard does not fix the KIO cache; it rejects the repeated
itemsAdded records before insertion. The defect reproduces upstream without
F11 or any downstream customization. This matrix is supplementary evidence;
the attached core-only reproducer is the minimal upstream test.

UPDATE SOURCE NOW IDENTIFIED IN A LIVE CAPTURE
A session-bus capture identified a current real trigger chain: plasmashell
writing Klipper clipboard storage emitted FilesAdded, followed immediately by
24 search-update FilesAdded signals from kded6. A later local directory
notification from DolphinXplorer produced the same fanout. The 24 signals
were for six older closed QA fixture searches with repeated registrations.
Stock kio-extras FileNameSearchModule incorrectly tests the empty path of a
filenamesearch URL rather than its actual root query item, so unrelated local
notifications reach registered searches. Ordinary system KIO::copy reproduced
the trigger without the downstream copier. F11 toggling and selection actions
emitted no KDirNotify signals in four completed supplementary cases.
See notification-supplement.txt and notification-evidence.json for sender
identities, controls and limits, including an automatically started private
kded6 which prevents using this supplementary run as a precise
cross-application
notification-frequency comparison. The original incident's full historical
notification sequence remains unavailable. Notification-producer scoping and
registration issues are additional KIO-extras findings; the main core cache
bug remains independently reproducible below.

ROOT CAUSE
KCoreDirListerCache::slotUpdateResult in KIO 6.13.0 builds a hash keyed by
item.name(), not item.url():
  QHash<QString, KFileItem> FileItemHash
  fileItems.insert(item.name(), item)
  fileItems.find(item.name())
Only one existing item survives per basename. The first new-listing entry
with that name consumes the hash entry; the remaining distinct URLs with the
same basename fall into the new-item branch and are appended again to the
existing cache. deleteUnmarkedItems also identifies entries by name.
The worker's second raw listing still has the correct distinct URLs. The
incorrect classification is in the cache reconciliation above it.

ISOLATED ROOT-FIX EXPERIMENT
A candidate patch changes the refresh hash and deleteUnmarkedItems keys from
basename QString to full QUrl. Built against the original KIO 6.13.0 source
in an isolated build; no system library was installed or replaced.
The SAME public core-only executable was run with that library:
  two same-name files:              2 -> 2, zero erroneous additions
  6000 files / 500 basenames:    6000 -> 6000, zero erroneous additions
  6000 unique basenames:        6000 -> 6000, zero erroneous additions
All preserve the exact initial URL set and return 0. ldd confirms that only
this test process loads the isolated candidate KIOCore. This is a validated
root-cause experiment, not a fully regression-tested upstream-ready fix;
the full KIO test suite and other protocols were not exercised.

UPSTREAM SOURCE CHECK
Inspected src/core/kcoredirlister.cpp at commit
9ff466f81e724c47511062aff7ee4cda07189ad4:
 
https://raw.githubusercontent.com/KDE/kio/9ff466f81e724c47511062aff7ee4cda07189ad4/src/core/kcoredirlister.cpp
The name-keyed hash remains at lines 1824, 1830 and 1891; deletion uses names
at line 2021. Its additional seenKey/seenKeys logic deduplicates entries within
one incoming listing and uses UDS_URL when available. Distinct files with
different UDS_URL values survive that check, so it does not resolve the
name-keyed reconciliation described here. This is a source-based inference;
only the installed versions below were tested as binaries. Latest upstream
binaries have not been tested.

TEST ENVIRONMENT
Debian GNU/Linux 13 (trixie), amd64
Dolphin: 4:25.04.3-1+deb13u1
KIO Core: 6.13.0-6
kio-extras: 4:25.04.3-1
Qt Core: 6.8.2+dfsg-9+deb13u2
GUI checks: Qt offscreen using actual application binaries/native workers.
Core-only check: QCoreApplication, KCoreDirLister and normal filenamesearch.

IMPACT AND LIMITS
Repeated updates can grow the model without any growth of the underlying
result set. Size sorting then spends CPU sorting repeated records. In the
original local capture, 257517 model records represented 5797 URLs with 1737
basenames. The arithmetic 5797 + 62*(5797-1737) = 257517 matches exactly.
The historical notification sequence and sender were not recorded, so this is
consistent with 62 unchanged updates; it is not a captured event count and
does not prove which desktop activity generated those updates.

No private file names or home-directory capture is included in the public
reproducer bundle. A separate synthetic nested-event-loop emission defect was
also observed locally; it is not needed for this report or the count formula.

RELATED REPORTS REVIEWED
https://bugs.kde.org/show_bug.cgi?id=447119 concerns search with symlinks.
This fixture uses no symlinks and duplicates the same URL after refresh.
https://bugs.kde.org/show_bug.cgi?id=525786 concerns missing initial results
with identical names and is marked resolved. This case has correct initial
results and excessive results on refresh. These reports do not establish
that the refresh-cache defect is already tracked; the duplicate search was
not exhaustive.

https://bugs.kde.org/show_bug.cgi?id=528607 was a previous report about an
off-screen item's changed-role queue repeatedly scheduling size sorting.
It is now RESOLVED/DUPLICATE of https://bugs.kde.org/show_bug.cgi?id=509081.
The present minimal case uses neither thumbnails nor that Dolphin role
updater: KCoreDirLister alone grows an unchanged result set. The existing
high-CPU reports do not explain this independently reproduced cache defect.
The report relationships/statuses above were read from KDE Bugzilla REST
on 2026-11-19; no existing report was posted to or modified.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to