workflowengine: File entity reuses the node of the first "Tag assigned" event for all later events in the same process
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 62/100
Rechercherichtung
Beginne in der Klasse OCA\WorkflowEngine\Entity\File, in der getNode() den aufgelösten Knoten in $this->node zwischenspeichert und prepareRuleMatcher() das neue Ereignis setzt, ohne diesen Cache zu leeren. Führe das schreibgeschützte Reproduktionsskript aus dem Issue mit ausgeschaltetem und eingeschaltetem Reset-Flag aus, um zu bestätigen, dass zwei "Tag assigned"-Ereignisse in einem Prozess denselben Knoten auswerten. Fertig ist, wenn jedes Ereignis seine eigene Datei auflöst und ein Test zwei Zuweisungsereignisse in einem Prozess abdeckt; der Cache von FileSystemTags ist ein eigenständiges, nicht überprüftes Anliegen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
⚠️ This issue respects the following points: ⚠️
- This is not a troubleshooting question, general support matter, or webserver/proxy problem, but likely a bug.
- This issue is not already reported on Github OR solved at the Community Help Forum (I've searched!).
- I'm using a maintained major version of Nextcloud Server and tested against the latest patch level. (Reproduced on 34.0.3; the affected files are byte-identical in 34.0.6 and unchanged apart from formatting in 35.0.3 and master.)
- I agree to follow Nextcloud's Code of Conduct.
- I've tried my best to provide clear reproduction steps that someone unfamiliar with this bug could use to reproduce it.
Bug description
OCA\WorkflowEngine\Entity\File is resolved from the DI container and is therefore a per-process singleton. For MapperEvent::EVENT_ASSIGN ("Tag assigned"), File::getNode() stores the resolved node in $this->node:
protected function getNode(): Node {
if ($this->node) {
return $this->node;
}
...
case MapperEvent::EVENT_ASSIGN:
...
$this->node = $this->root->getFirstNodeById((int)$this->event->getObjectId());
prepareRuleMatcher() sets the new $event/$eventName, but it never resets $this->node. Every later "Tag assigned" event in the same PHP process is therefore matched against the file from the first event: setEntitySubject() and setFileInfo() both use the stale node.
Web requests usually handle only one tag assignment, so the problem stays hidden there. Long-running processes such as cron.php handle many assignments in a row (CronService runs jobs for up to 14 minutes), and there it does real damage. A common setup is affected directly:
files_automatedtaggingassigns tags in a background job (AssignTagsJob).- A second flow reacts to "Tag assigned" with a "File has tag" check.
Depending on which file comes first in a cron run, the second flow then either does not run for any later file in that run, or runs for files it should not match.
On our instance, a bulk upload of about 7,600 PDFs led to the following:
- 2,461 files received the tag from
files_automatedtagging, but the OCR flow (workflow_ocr, triggered by "Tag assigned") never created a job for them. - 695 files were processed two to four times.
Steps to reproduce
- Flow A (
files_automatedtagging): "File updated", MIME type PDF and not tagX→ assign tagX. The tag is assigned byAssignTagsJobin cron. - Flow B: any operation on "Tag assigned" with "MIME type PDF and file has tag
X". We useworkflow_ocr. When it finishes, it removesXand adds tagY. - Upload many PDFs, so that several
AssignTagsJobs and flow B jobs end up in the samecron.phprun. - Some files keep tag
Xwithout flow B ever having run for them; others are processed by flow B several times.
Read-only reproduction that does not change tags or queue jobs. Run it as the web server user with php inside the Nextcloud container, with REPRO_ARGS="<reset 0|1> <fileid> <fileid>". Use one file that has tag X and one that does not.
<?php
require_once '/var/www/html/lib/base.php';
\OC_App::loadApps();
use OCP\SystemTag\MapperEvent;
$args = explode(' ', getenv('REPRO_ARGS'));
$reset = $args[0] === '1';
$ev = MapperEvent::EVENT_ASSIGN;
$manager = \OCP\Server::get(\OCA\WorkflowEngine\Manager::class);
$entity = \OCP\Server::get(\OCA\WorkflowEngine\Entity\File::class);
$op = \OCP\Server::get(\OCA\WorkflowOcr\Operation::class); // class of any operation configured for "Tag assigned"
$prop = new ReflectionProperty($entity, 'node');
foreach (array_slice($args, 1) as $fid) {
if ($reset) { $prop->setValue($entity, null); }
$event = new MapperEvent($ev, 'files', $fid, [4]);
$rm = $manager->getRuleMatcher();
$rm->setEventName($ev); $rm->setEntity($entity); $rm->setOperation($op);
$entity->prepareRuleMatcher($rm, $ev, $event);
$match = $rm->getFlows(true);
echo "event_file=$fid evaluated_node=" . $prop->getValue($entity)->getId() . ' match=' . ($match ? 'yes' : 'no') . "\n";
}
Output with the rule "PDF and has tag X". File 94069 has only tag Y; file 4365 has only tag X.
reset=0 order=94069 4365
event_file=94069 evaluated_node=94069 match=no
event_file=4365 evaluated_node=94069 match=no <- wrong, 4365 has tag X
reset=1 order=94069 4365
event_file=94069 evaluated_node=94069 match=no
event_file=4365 evaluated_node=4365 match=yes
reset=0 order=4365 94069
event_file=4365 evaluated_node=4365 match=yes
event_file=94069 evaluated_node=4365 match=yes <- wrong, 94069 does not have tag X
reset=1 order=4365 94069
event_file=4365 evaluated_node=4365 match=yes
event_file=94069 evaluated_node=94069 match=no
Expected behavior
Each "Tag assigned" event is evaluated against the file in that event, regardless of what was evaluated earlier in the same process.
A possible fix is to reset the cached node whenever a new event is prepared, e.g. at the start of File::prepareRuleMatcher():
$this->node = null;
The reproduction above (reset=1) shows that resetting the node fixes both directions.
Nextcloud Server version
34
Operating system
Other
PHP engine version
PHP 8.3
Web server
Other
Database engine version
PostgreSQL
Is this bug present after an update or on a fresh install?
None
Are you using the Nextcloud Server Encryption module?
Encryption is Disabled
What user-backends are you using?
- Default user-backend (database)
Configuration report
Not relevant for this bug: Nextcloud All-in-One 34.0.3 on Ubuntu 26.04.1 LTS, PHP 8.3.33, PostgreSQL 18.4, AIO web server container, background jobs via cron.
List of activated Apps
Relevant apps: workflowengine 2.16.0, systemtags 1.24.0, files_automatedtagging 5.0.0, workflow_ocr 1.34.1, app_api 34.0.0.
Nextcloud Signing status
No response
Nextcloud Logs
Nothing is logged: the rule simply does not match, or matches wrongly.
Additional info
Possibly related, found by reading the code and not tested: Check\FileSystemTags is also a singleton. It caches tag IDs per file ID ($fileSystemTags) and does not invalidate them when tags change. In a long-running process, a file whose tags changed after an earlier check can therefore still be evaluated with outdated tags.
As a workaround we re-assign the tag per file with occ tag:files:delete/tag:files:add, so each assignment runs in a fresh process.
Disclosure: I used an AI assistant (Claude) to analyse the code, write the read-only reproduction and draft this report. I reviewed and verified the results on my instance.
- Vorherrschende Sprache
- PHP
- Sterne
- 37.5k
- Forks
- 5.4k
- Ø Merge
- 1 T. 14 Std.
- Gemergte PRs (30 T.)
- 648
Entwicklungsumgebung
Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus nextcloud/server
-
0. Needs triage 35-feedback bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 66/100
Maintainer antworten meist innerhalb von 1 Tag
-
Contacts import aborts with TypeError when vCards have no UID (TextImporter structure)Evtl. vergeben @SebastianKrupinski hat das vor 4 Tagen übernommen. Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
nextcloud/server#66486 · 2 Kommentare · 2 Reaktionen · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
-
Unified search: screen reader hears "No matching results" on mobile even when there are resultsEvtl. vergeben @lazerg hat das vor 8 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
34-feedback needs info
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 77/100
nextcloud/server#66249 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
[Bug]: DAV Forbidden/InvalidPath responses break on "&" in the message (DOMDocument::createElementNS(): unterminated entity reference)Evtl. vergeben @th-joerger hat das vor 12 Tagen übernommen. Offen0. Needs triage 35-feedback bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in nextcloud/server
Ähnliche Issues
-
Old /download.php attachment links: redirect drops the subfolder, nginx.example.conf returns 404OffenBug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 Unter einer Stunde Anfängerfreundlichkeit 82/100
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 72/100
wpgenius/stackfolio#22 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
Automattic/static-site-importer#3024 ·
Maintainer antworten meist innerhalb von 1 Tag
-
[6.0]: Uncaught TypeError: can't access property "value", event.chart.scales.x.ticks[4] is undefinedOffenBug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
phpmyadmin/phpmyadmin#20626 ·
Maintainer antworten meist innerhalb von 1 Tag