Skip to content

Nextcloud File Locking gets out of sync #1940

Open

Description

@schemil053

Sometimes the nextcloud android app break and fails to sync a note. Only opening the file in the browser and closing it again resolves it

Steps to reproduce

This issue is not 100% reproducible every time, but I found it using that way:

  1. Use Android app to edit notes
  2. Edit the file with the website again (after closing the android app)
  3. Use the Android app again to edit again

Expected behaviour

The app syncs fine

Actual behaviour

The Server logs an error (attached below)

And the notes app shows an error that is not able to sync. Only if you go to the website, open and close the note, the sync works again

Server

  • Notes app version: 6.0.1
  • Nextcloud version: 34.0.1
  • OS: Debian/LXC
  • Web server: apache2 2.4.68-1~deb13u1
  • PHP version: 8.4.23
  • Database: mariadb

Nextcloud is ran behind an apache proxy server

Client

  • Browser (incl. version): Firefox ESR 140.12.0
    • OS: Debian Trixie with Wayland

The other Client is Android 16 using the latest available version of the notes android app

Log files

{
  "reqId": "REDACTED",
  "level": 3,
  "time": "2026-07-17T04:12:11+00:00",
  "remoteAddr": "REDACTED",
  "user": "REDACTED",
  "app": "notes",
  "method": "PUT",
  "url": "/index.php/apps/notes/api/v1/notes/23228?",
  "scriptName": "/index.php",
  "message": "Controller failed with OCP\\Lock\\ManuallyLockedException",
  "userAgent": "Mozilla/5.0 (Android) Nextcloud-android/34.0.1",
  "version": "34.0.1.2",
  "exception": {
    "Exception": "OCP\\Lock\\ManuallyLockedException",
    "Message": "\"files/Notizen/Privat/Todo.md\" is locked, existing lock on file: files_lock/1ed743bc-1034-40ef-9711-3a5ab33e994c",
    "Code": 0,
    "Trace": [
      {
        "file": "/var/www/nextcloud/apps/files_lock/lib/Storage/LockWrapper.php",
        "line": 213,
        "function": "checkPermissions",
        "class": "OCA\\FilesLock\\Storage\\LockWrapper",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/Files/Storage/Wrapper/Wrapper.php",
        "line": 150,
        "function": "file_put_contents",
        "class": "OCA\\FilesLock\\Storage\\LockWrapper",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/Files/View.php",
        "line": 1235,
        "function": "file_put_contents",
        "class": "OC\\Files\\Storage\\Wrapper\\Wrapper",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/Files/View.php",
        "line": 680,
        "function": "basicOperation",
        "class": "OC\\Files\\View",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/Files/Node/File.php",
        "line": 56,
        "function": "file_put_contents",
        "class": "OC\\Files\\View",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/apps/notes/lib/Service/Note.php",
        "line": 174,
        "function": "putContent",
        "class": "OC\\Files\\Node\\File",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/apps/notes/lib/Controller/NotesApiController.php",
        "line": 174,
        "function": "setContent",
        "class": "OCA\\Notes\\Service\\Note",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/apps/notes/lib/Service/Util.php",
        "line": 25,
        "function": "{closure:OCA\\Notes\\Controller\\NotesApiController::update():164}",
        "class": "OCA\\Notes\\Controller\\NotesApiController",
        "type": "->",
        "args": [
          "*** sensitive parameters replaced ***"
        ]
      },
      {
        "file": "/var/www/nextcloud/apps/notes/lib/Controller/Helper.php",
        "line": 135,
        "function": "retryIfLocked",
        "class": "OCA\\Notes\\Service\\Util",
        "type": "::"
      },
      {
        "file": "/var/www/nextcloud/apps/notes/lib/Controller/NotesApiController.php",
        "line": 164,
        "function": "handleErrorResponse",
        "class": "OCA\\Notes\\Controller\\Helper",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php",
        "line": 165,
        "function": "update",
        "class": "OCA\\Notes\\Controller\\NotesApiController",
        "type": "->",
        "args": [
          "*** sensitive parameters replaced ***"
        ]
      },
      {
        "file": "/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php",
        "line": 78,
        "function": "executeController",
        "class": "OC\\AppFramework\\Http\\Dispatcher",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/AppFramework/App.php",
        "line": 137,
        "function": "dispatch",
        "class": "OC\\AppFramework\\Http\\Dispatcher",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/lib/private/Route/Router.php",
        "line": 324,
        "function": "main",
        "class": "OC\\AppFramework\\App",
        "type": "::"
      },
      {
        "file": "/var/www/nextcloud/lib/base.php",
        "line": 1159,
        "function": "match",
        "class": "OC\\Route\\Router",
        "type": "->"
      },
      {
        "file": "/var/www/nextcloud/index.php",
        "line": 25,
        "function": "handleRequest",
        "class": "OC",
        "type": "::"
      }
    ],
    "File": "/var/www/nextcloud/apps/files_lock/lib/Storage/LockWrapper.php",
    "Line": 82,
    "message": "Controller failed with OCP\\Lock\\ManuallyLockedException",
    "exception": "{\"class\":\"OCP\\Lock\\ManuallyLockedException\",\"message\":\"\\\"files/Notizen/Privat/Todo.md\\\" is locked, existing lock on file: files_lock/1ed743bc-1034-40ef-9711-3a5ab33e994c\",\"code\":0,\"file\":\"/var/www/nextcloud/apps/files_lock/lib/Storage/LockWrapper.php:82\",\"trace\":\"#0 /var/www/nextcloud/apps/files_lock/lib/Storage/LockWrapper.php(213): OCA\\FilesLock\\Storage\\LockWrapper->checkPermissions()\\n#1 /var/www/nextcloud/lib/private/Files/Storage/Wrapper/Wrapper.php(150): OCA\\FilesLock\\Storage\\LockWrapper->file_put_contents()\\n#2 /var/www/nextcloud/lib/private/Files/View.php(1235): OC\\Files\\Storage\\Wrapper\\Wrapper->file_put_contents()\\n#3 /var/www/nextcloud/lib/private/Files/View.php(680): OC\\Files\\View->basicOperation()\\n#4 /var/www/nextcloud/lib/private/Files/Node/File.php(56): OC\\Files\\View->file_put_contents()\\n#5 /var/www/nextcloud/apps/notes/lib/Service/Note.php(174): OC\\Files\\Node\\File->putContent()\\n#6 /var/www/nextcloud/apps/notes/lib/Controller/NotesApiController.php(174): OCA\\Notes\\Service\\Note->setContent()\\n#7 /var/www/nextcloud/apps/notes/lib/Service/Util.php(25): OCA\\Notes\\Controller\\NotesApiController->{closure:OCA\\Notes\\Controller\\NotesApiController::update():164}()\\n#8 /var/www/nextcloud/apps/notes/lib/Controller/Helper.php(135): OCA\\Notes\\Service\\Util::retryIfLocked()\\n#9 /var/www/nextcloud/apps/notes/lib/Controller/NotesApiController.php(164): OCA\\Notes\\Controller\\Helper->handleErrorResponse()\\n#10 /var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php(165): OCA\\Notes\\Controller\\NotesApiController->update()\\n#11 /var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php(78): OC\\AppFramework\\Http\\Dispatcher->executeController()\\n#12 /var/www/nextcloud/lib/private/AppFramework/App.php(137): OC\\AppFramework\\Http\\Dispatcher->dispatch()\\n#13 /var/www/nextcloud/lib/private/Route/Router.php(324): OC\\AppFramework\\App::main()\\n#14 /var/www/nextcloud/lib/base.php(1159): OC\\Route\\Router->match()\\n#15 /var/www/nextcloud/index.php(25): OC::handleRequest()\\n#16 {main}\"}",
    "CustomMessage": "Controller failed with OCP\\Lock\\ManuallyLockedException"
  },
  "id": "REDACTED"
}

Activity

  1. schemil053 commented on Jul 18, 2026

    @schemil053
    Author
  2. spintike commented on Jul 20, 2026

    @spintike

    Same issue here with nearly the same parameters (versions etc.) and checking the server log.

  3. thmsaurel commented on Jul 23, 2026

    @thmsaurel

    I have the same issue using mostly a text editor with local synchronization.
    The issue seems related to the web editior.

  4. heapifyman commented on Jul 23, 2026

    @heapifyman

    I noticed that the notes file (.md) is marked as locked in the Nextcloud Files App

    Image

    after it was edited in the Nextcloud Notes App (web app).

    Afterwards the Nextcloud Notes App (Android) was not able to sync the note anymore with the exception mentioned above.

    This seems to happen only if the Notes App (web) is set to use "Rich Text".

    Image

    The file does not get locked when selecting "Plain text" or "Preview"

  5. robsteady commented on Jul 25, 2026

    @robsteady

    Thank you, @heapifyman ! This has been driving me insane. I even set up a Joplin server and started using that because I could not find a fix. I switched the Notes app to Plain text and now everything works as expected again.

  6. MegaV0lt commented on Jul 26, 2026

    @MegaV0lt

    I get also sync error in app

    App Version: 34.0.0
    App Version Code: 340000090
    App Flavor: fdroid
    
    Files App Version Code: 340000190 (PROD)
    
    ---
    
    OS Version: 6.1.138-android14-11-g6ab8c9a86a33-ab14396278(OS3.0.302.0.WNNEUXM)
    OS API Level: 36
    Device: rothko
    Manufacturer: Xiaomi
    Model (and Product): 2407FPN8EG (rothko_eea)
    
    ---
    
    java.lang.Exception: {"errorType":"OCP\\Lock\\ManuallyLockedException"}
    [com.nextcloud.android.sso.InputStreamBinder.processRequestV2(InputStreamBinder.java:440), com.nextcloud.android.sso.InputStreamBinder.performNextcloudRequestAndBodyStreamV2(InputStreamBinder.java:113), com.nextcloud.android.sso.InputStreamBinder.performNextcloudRequestV2(InputStreamBinder.java:96), com.nextcloud.android.sso.aidl.IInputStreamService$Stub.onTransact(IInputStreamService.java:112), android.os.Binder.execTransactInternal(Binder.java:1428), android.os.Binder.execTransact(Binder.java:1372)]
    	at it.niedermann.owncloud.notes.persistence.NotesServerSyncTask.pushLocalChanges(NotesServerSyncTask.java:150)
    	at it.niedermann.owncloud.notes.persistence.NotesServerSyncTask.run(NotesServerSyncTask.java:99)
    	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:520)
    	at java.util.concurrent.FutureTask.run(FutureTask.java:328)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1100)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    	at java.lang.Thread.run(Thread.java:1572)
    
    
    java.lang.Exception: {"errorType":"OCP\\Lock\\ManuallyLockedException"}
    [com.nextcloud.android.sso.InputStreamBinder.processRequestV2(InputStreamBinder.java:440), com.nextcloud.android.sso.InputStreamBinder.performNextcloudRequestAndBodyStreamV2(InputStreamBinder.java:113), com.nextcloud.android.sso.InputStreamBinder.performNextcloudRequestV2(InputStreamBinder.java:96), com.nextcloud.android.sso.aidl.IInputStreamService$Stub.onTransact(IInputStreamService.java:112), android.os.Binder.execTransactInternal(Binder.java:1428), android.os.Binder.execTransact(Binder.java:1372)]
    	at it.niedermann.owncloud.notes.persistence.NotesServerSyncTask.pushLocalChanges(NotesServerSyncTask.java:150)
    	at it.niedermann.owncloud.notes.persistence.NotesServerSyncTask.run(NotesServerSyncTask.java:99)
    	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:520)
    	at java.util.concurrent.FutureTask.run(FutureTask.java:328)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1100)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    	at java.lang.Thread.run(Thread.java:1572)
    
    
  7. larwood commented on Aug 20, 2026

    @larwood

    This is still an issue in Notes 6.0.2

  8. eziocangialosi commented on Aug 27, 2026

    @eziocangialosi

    I got the exactly same issue

    App Version: 34.0.1
    App Version Code: 340000190
    App Flavor: fdroid
    
    Files App Version Code: 340010090 (PROD)
    
    ---
    
    OS Version: 6.1.129-android14-11-gbb141a09b4e0-ab13735664(1786759659)
    OS API Level: 36
    Device: FP6
    Manufacturer: Fairphone
    Model (and Product): Fairphone 6 (lineage_FP6)
    
    ---
    
    java.lang.Exception: {"errorType":"Exception"}
    [com.nextcloud.android.sso.InputStreamBinder.processRequestV2(InputStreamBinder.java:440), com.nextcloud.android.sso.InputStreamBinder.performNextcloudRequestAndBodyStreamV2(InputStreamBinder.java:113), com.nextcloud.android.sso.InputStreamBinder.performNextcloudRequestV2(InputStreamBinder.java:96), com.nextcloud.android.sso.aidl.IInputStreamService$Stub.onTransact(IInputStreamService.java:112), android.os.Binder.execTransactInternal(Binder.java:1421), android.os.Binder.execTransact(Binder.java:1365)]
    	at it.niedermann.owncloud.notes.persistence.NotesServerSyncTask.pushLocalChanges(NotesServerSyncTask.java:150)
    	at it.niedermann.owncloud.notes.persistence.NotesServerSyncTask.run(NotesServerSyncTask.java:99)
    	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:524)
    	at java.util.concurrent.FutureTask.run(FutureTask.java:317)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1156)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:651)
    	at java.lang.Thread.run(Thread.java:1119)
    
    

    The issue disappear when I switch the Display mode from "Rich text" to "Plain text" in the webapp as saying @heapifyman just upward.

    As everyone here i got the "file lock" error in the server logs (Nextcloud Hub 26 Spring 34.0.2 with Notes 6.0.2)

  9. eziocangialosi commented on Aug 28, 2026

    @eziocangialosi

    A workaround appears possible: undo the change made in the Android app (to revert to a version matching the one in the web app). Deselect the note in the web app, then re-apply the change in the Android app; synchronization should then be possible.

    Note that the note file appears to be locked as long as the note is selected in the web app (even if the changes have already been applied).
    If a change is made in the Android app while the note is selected (and thus locked) in the web app, a ManuallyLockedException will be thrown until the Android app matches the version existing on the server.

  10. larwood commented on Sep 15, 2026

    @larwood

    This is still an issue in Notes 6.1.0

  11. cheywood commented on Sep 16, 2026

    @cheywood
    Contributor

    Behaviour seen with Notes 6.1.0:

    1. Open note in web Notes rich text editor using Firefox-based browser (Zen)
    2. Close tab in browser
    3. Make change to note in API consumer (Iotas)
    4. See attempt to push that note's changes via API fail due to note being locked (423 status code)
  12. JL710 commented on Sep 27, 2026

    @JL710

    I updated my nextcloud aio yesterday to 34.0.4 and notice this issue since then with the latest app version 35.0.0.

    A workaround that somewhat works for me is the one from @eziocangialosi. As long as there is no open browser tab with the note open, the sync works (again). As soon as that is not the case, the note seems unable to push.

  13. sallyhaj commented on Oct 1, 2026

    @sallyhaj

    I have similar issue:

    • Versions: Nextcloud server 35.0.0.10, files_lock 35.0.0, Notes Android 35.0.0.
    • Steps: edit a note in the web editor, close the tab, then sync an Android device that has its own
      unsent edit to the same note.
    • Result: PUT /apps/notes/api/v1/notes/<id> returns 423 with OCP\Lock\ManuallyLockedException, and the
      app only shows {"errorType":"Exception"}.
    • Workarounds: occ text:reset <fileId> clears it at once. Setting files_lock lock_timeout to 30 makes
      the lock expire by itself, but the device still fails for up to 30 minutes.
  14. staticdev commented on Oct 5, 2026

    @staticdev

    I have same issue after upgrading to NC 35.0.1, notes 6.1.0 and I use as well the android app on version 35.0.0.

    A short workaround I found for those suffering with this: nextcloud-occ files:lock --unlock <NOTE_ID> <YOUR_NEXTCLOUD_USERNAME>

  15. melo0187 commented on Oct 14, 2026

    @melo0187

    16. I have same issue after upgrading to NC 35.0.1, notes 6.1.0 and I use as well the android app on version 35.0.0.
    A short workaround I found for those suffering with this: nextcloud-occ files:lock --unlock <NOTE_ID> <YOUR_NEXTCLOUD_USERNAME>

    I even went this far: occ app:disable files_lock
    Funny enough things work better now in my humble opinion. If the web UI encounters a conflict it makes it very clear and easily resolvable.

  16. sallyhaj commented on Oct 15, 2026

    @sallyhaj

    Note: This comment with the help of AI:
    Some more findings since my last comment (Notes 6.1.0, Text 9.0.0, files_lock 35.0.0, Notes Android 35.0.0):

    • The root cause is in Text: nextcloud/text#9042. The web rich editor takes a files_lock lock (owner Text) when it opens the note. The lock leaks when the editor goes away without calling /close.
      files_lock lock_timeout defaults to -1, so the leaked lock never expires.
    • Reproduced again today from the access log: web Notes opened the note (PUT /apps/text/session/<id>/create), synced for about a minute, then stopped without ever sending /close.
      The lock stayed.
    • The same phone can edit the note but not sync it. Android Notes in rich mode joins the existing Text session (directEditing), and its edits save fine through Text. Meanwhile the same app's sync, PUT /apps/notes/api/v1/notes/<id>, gets 423 ManuallyLockedException on every retry.
    • nextcloud/text#9355 (merged 2026-10-13) is not the fix. It only refreshes the lock icon in the Files list after close. It doesn't release the lock.
    • A safer workaround than files:lock --unlock or disabling files_lock: occ text:reset <fileId> without --force. It refuses if the editor still holds unsaved changes. The <id> in the failing PUT is the file id.
    • Suggestion for Notes: even after Text is fixed, a note that's really open in the web editor will still return 423. Could the API return a clear "note is open in the editor" error that Android can show, instead of {"errorType":"Exception"}?
  17. klangme1ster commented on Oct 27, 2026

    @klangme1ster

    Same symptom here: NC 35.0.2.2, files_lock 35.0.1, notes 6.1.0, text 9.0.1, Android Notes 35.0.0 via SSO. The server log shows
    ManuallyLockedException from NotesApiController::update on PUT /notes/ (HTTP 423).

    What I found

    • When I checked oc_files_lock, nearly all locks were app locks owned by "Text" (type=1), with no user or WebDAV locks. The rest
      was a single Collabora lock. None of them expired, because lock_timeout defaults to -1.
    • Notes PUT runs outside Text's lock scope, so any Text app lock blocks it. Unlocking manually only helps until the note is
      opened again.
    • In the access log, the Android app opens a note via directEditing/open, then sync/push return 200. POST
      /apps/text/session//close returns 403 (2 of 2). In the browser, close returned 200 all 74 times, and the lock was
      released.
    • SessionController::close() throws InvalidSessionException (→ 403) when userSession->getUser() is null. That's my reading of
      the code, not confirmed. close is the only place that unlocks, so the lock stays forever.

    What helped: I had set the default view in the Android Notes app to the read-only preview. Switching it back to "simple editor"
    fixed the sync. My guess is that the preview mode goes through Text/direct editing and the editor doesn't.

    Workaround: use the simple editor as default, and set occ config:app:set files_lock lock_timeout --value=120 so new locks
    expire.

  18. KodoGit commented on Nov 2, 2026

    @KodoGit

    The only working way to use nc notes on android is to sync them with common nextcloud app and open with some 3rd party file browser.
    Native apps try to sync on open, lock, hang. Horrible.

  19. ffuuuuu commented on Nov 7, 2026

    @ffuuuuu

    It should be visible in the Notes app that a note is currently locked. Even better the locking shouldn't happen at all, or if it happens there should be an option to unlock in the Notes app. It took me a while to even figure out what the error was and how to fix it. It just gave me a random sync error message.

  20. mwinkens commented on Nov 14, 2026

    @mwinkens

    I am constantly able to reproduce this with a shared note, and I let AI analyse it, please take this with a grain of salt, I didn't proof this, but it looks and reads sound:

    AI written analysis
    Understood — and that detail is strong evidence. It isolates the bug to exactly one code path: the Text rich editor session, because that's the only thing in Notes that ever takes a lock.
    Why the workaround confirms the diagnosis
    Notes mode	Write path	Lock taken?
    rich (NoteRich.vue)	Text editor session → ApiService::create() takes an APP lock (owner text, files_lock/<uuid>)	yes
    edit / preview (NotePlain.vue)	PUT /apps/notes/api/.../notes/<id> → Note::setContent()	no lock at all
    Plain mode never creates a files_lock entry, so the Notes API write is never rejected. Rich mode leaks the lock when the browser tab goes away (Text only sends POST /apps/text/session/{id}/close on in-page teardown; a tab close only fires a saveBeforeUnload beacon). With files_lock lock_timeout = -1 (the NC 34+ default) the Unlock cron is a no-op, so the orphan lock is permanent — and every Notes API write dies in LockWrapper->checkPermissions() with ManuallyLockedException → 423 {"errorType":"Exception"}. Re-opening + closing the note in the web UI only "fixes" it because that runs ApiService::close() again.
    
    Reproduction
    
    A. Manual, ~60 s, faithful (needs Text + files_lock, both default-enabled on NC 34/35)
    
    1. Notes settings → editor mode Rich workspace annotation; create a note.
    2. Open the note in the web UI (rich editor mounts → session + APP lock created). Verify: occ files:lock <fileId> --status shows owner text.
    3. Close the browser tab (do not navigate away inside Notes, do not press back). This is the leak.
    4. occ files:lock <fileId> --status → lock still there (this assertion is the bug).
    5. From another client: curl -u test:test -X PUT -H 'Content-Type: application/json' -d '{"content":"hello"}' http://localhost:8080/index.php/apps/notes/api/v1/notes/<id> → 423 with {"errorType":"Exception"}.
    6. Sanity check of the workaround: switch mode to plain, repeat step 5 in the web UI → still 423 for the API, but plain-mode web editing works (it uses the internal controller — see the asymmetry below).
    
    B. Deterministic automated test (recommended for CI — no Text, no browser, ~seconds)
    
    occ files:lock <fileId> text creates exactly the same APP/TYPE_APP lock Text would, with no dependency on Text's flaky session lifecycle. Playwright already gives us everything needed: runOcc() from @nextcloud/e2e-test-server/docker, plus the basic-auth API pattern from playwright/e2e/attachment-api.spec.ts.
    New playwright/e2e/note-lock.spec.ts:
    - createNote() via POST /api/v1/notes, read its fileId (via WebDAV PROPFIND {DAV}getfileid, as attachment-api.spec.ts already does for paths).
    - runOcc('files:lock ' . $fileId . ' text').
    - PUT /api/v1/notes/<id> → assert the current behaviour as a documented expectation, then after the fix assert 200.
    - finally: runOcc('files:lock --unlock ' . $fileId . ' text') so the container stays clean (single worker, shared server).
    
    C. Faithful e2e (optional, keep local / tag it) — same as A but scripted: configureNextcloud(['notes', 'text']) in playwright/start-nextcloud-server.mjs, set noteMode=rich, login(), open a note, page.close(), then assert the lock persists and the API write fails. Worth having once to prove the fix closes the real leak, but cloning + composer-installing Text makes it slow, so I'd not gate CI on it.
    
    Fix plan (four layers, separate PRs)
    
    PR 1 — stop lying to clients (small, uncontroversial)
    
    - lib/Controller/Helper.php: catch \OCP\Lock\ManuallyLockedException before the generic LockedException branch and return 423 with an actionable body, e.g. {"errorType":"ManuallyLockedException","locked":true,"lock":{"type":"app","owner":"text"}}, using ILockManager::getLocks($note->getId()) (guarded by isLockProviderAvailable()). Never expose tokens.
    - lib/Service/Util.php: retryIfLocked() must not sleep 5×1s for manual/app locks — they never clear on that timescale. Re-throw immediately for ManuallyLockedException (and any lock whose getTimeout() is infinite). Today every blocked write burns 5 s and logs 5 times.
    - Document 423 in docs/api/README.md + docs/api/v1.md (the README already requires clients to tolerate unknown codes, so this is additive, no new API version needed) and add the FAQ entry for admins: occ config:app:set files_lock lock_timeout --value=30, occ text:reset <fileId>.
    - Tests: PHPUnit unit tests for the new error mapping (tests/unit/Controller/HelperTest.php, mocked ILockManager), plus a PHP API test asserting the 423 shape (tests/api/).
    
    PR 2 — the actual self-healing write path (needs maintainer sign-off, worth a ticket)
    
    Remove the asymmetry: NotesController already bypasses Text locks for rename/category via inLockScope() (lib/Controller/NotesController.php:390) while NotesController::update() and the whole public NotesApiController::update() have no lock scope — so web rename works and Android content push 423s. Proposal: in Helper, wrap note mutations in a lock scope for ILock::TYPE_APP locks only (leave TYPE_USER and WebDAV TYPE_TOKEN locks strictly enforced), keeping the If-Match/412 conflict flow as the data-safety net. Two variants to agree on:
    - 2a (consistent with existing code): always run content writes in an app-lock scope. Simple, no heuristics; risk is a genuine concurrent write while a live Text session is open — mitigated only if clients send If-Match (worth checking what Android/desktop actually send).
    - 2b (conservative): only bypass when the blocking app lock looks stale — getCreatedAt() older than a configurable threshold (opt-in app config, default off/disabled). Notes then compensates for lock_timeout = -1 without silently overriding an editor someone is using right now.
      I lean 2b as the default with 2a behind the same setting, because it cannot lose data on an actively open editor.
    
    PR 3 — reduce Notes' own lock exposure (frontend, cheap)
    
    - src/components/NoteRich.vue: call the editor's destroy() on pagehide (not just unmounted()), so a closing tab gives Text a chance to release the session; today onClose() on route change only resets a local unsaved flag.
    - Consider opening the rich editor readOnly until the user actually edits, so merely browsing notes doesn't leave locks behind. Needs a check whether Text's readOnly session still locks — if it does, this becomes an upstream ask instead.
    
    PR 4 — upstream (the real root cause, not ours to fix here)
    
    The leak belongs to Text (ApiService::create/close, no close-on-tab-unload, orphan sessions blocking clean closes for 5 min) and to files_lock's infinite default timeout. PR #9355 only refreshes the Files icon. Tracking in text#9042 / text#8858 / server#66479 — our PR 1/2 should reference these and say explicitly that Notes is compensating, not fixing.
    What I'd like to agree on before writing code
    1. Scope of the first PR: I'd start with PR 1 alone — it's a strict improvement, unblocks a good client-side message ("this note is open in the web editor"), and its Playwright test (repro B) is the "reliable reproduction" the need to reproduce label asks for. Agree?
    2. 2a vs 2b for the write path — this is the contentious one and probably needs a ticket for discussion since it touches the public API's stability contract and the data-safety story.
    3. Where the automated repro lives: Playwright (has runOcc) is the only suite that can create the lock, so PR 1's regression test goes there; tests/api/ can only assert the response shape once a lock exists out-of-band.
    One caveat on the AGENTS.md rules: none of these steps need me to open issues/PRs — I'd hand you branches and text you review and submit yourself, and each commit would carry the Assisted-by: trailer (no Signed-off-by).
  21. larwood commented on Nov 15, 2026

    @larwood

    This is still an issue in Notes 6.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneed to reproduceIssue that has not been reproduced

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions