Skip to content

Fix: discard notifications for deleted files instead of logging warnings repeatedly - #389

Open
R0Wi wants to merge 1 commit into
masterfrom
claude/workflow-ocr-notification-warning-nb9k4y
Open

Fix: discard notifications for deleted files instead of logging warnings repeatedly#389
R0Wi wants to merge 1 commit into
masterfrom
claude/workflow-ocr-notification-warning-nb9k4y

Conversation

@R0Wi

@R0Wi R0Wi commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #382. When a user deletes a file after workflow_ocr has created a success or error notification for it, the notification's row in oc_notifications persists. Because the notifications app re-renders every stored notification on each poll of /ocs/v2.php/apps/notifications/api/v2/notifications, the notifier would log a warning every time—multiple times per minute—cluttering the Nextcloud logs indefinitely.

Changes

  • tryGetRichParamForFile(): Now throws AlreadyProcessedException when the file cannot be found for the given user, instead of logging a warning and returning false. This signals Nextcloud to delete the notification row from the database, stopping the recurring logs.
  • Log level: Lowered from warning to debug for the missing-file case, since users deleting files (or moving them to trashbin) after OCR completes is a normal situation, not an error worth warning about.
  • API switch: Replaced getById() + array_shift() with getFirstNodeById() for cleaner code.
  • Test updates: Replaced the "fallback when file array was empty" test with testThrowsAlreadyProcessedExceptionIfFileCannotBeFoundAnymore, which verifies the notification is discarded and only debug is logged.

Unexpected errors while resolving the file still produce an error log and fall back to the generic subject without a file link.

Testing

Unit tests pass (9/9 with 70 assertions) against a local harness. composer cs:check is clean. The test suite will run in CI.


Generated by Claude Code

The notifications app re-renders every stored notification on each poll of
/ocs/v2.php/apps/notifications/api/v2/notifications. If the file a
workflow_ocr notification belongs to no longer exists for the user, the
notifier logged a warning and fell back to a generic subject, leaving the
row in oc_notifications. The warning was therefore emitted again on every
single poll and never went away by itself.

Throw AlreadyProcessedException instead so Nextcloud removes the obsolete
notification, and log the missing file at debug level: a user deleting a
file (or moving it to the trashbin, which is outside of /<user>/files and
hence not resolvable via the user folder either) after OCR has run is a
normal situation, not something worth a warning.

Unexpected errors while resolving the file still get logged as an error and
keep the previous fallback to the generic subject without a file link.

Also switches from getById()/array_shift() to getFirstNodeById().

Fixes #382

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M3aC9zhcgYNxtr2n4pZUaE
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.

Why workflow_ocr cares about a deleted file?

2 participants