Creating file bookmarks doesn't work anymore on macOS 15 Sequoia

Before updating to macOS 15 Sequoia, I used to be able to create file bookmarks with this code:

let openPanel = NSOpenPanel()
openPanel.runModal()
let url = openPanel.urls[0]
do {
    let _ = try url.bookmarkData(options: [.withSecurityScope])
} catch {
    print(error)
}

Now I get an error

Error Domain=NSCocoaErrorDomain Code=256 "Failed to retrieve app-scope key"

These are the entitlements:

com.apple.security.app-sandbox
com.apple.security.files.user-selected.read-write
com.apple.security.files.bookmarks.app-scope

Strangely, my own apps continued working, after updating to macOS 15 some days ago, until a few moments ago. Then it seems that all of a sudden my existing bookmarks couldn't be resolved anymore, and no new bookmarks could be created. What could be the problem?

Answered by DTS Engineer in 806097022

Yesterday I filed FB15258541.

Thank you, that was very helpful.

What you're hitting is bug in "ScopedBookmarksAgent" which can cause it hang if it happens to have been launched when the keychain was also locked (for example, late in the screen lock process). That bug is fixed as of macOS 15.1 beta 4.

If you're hitting it regularly during development, you can resolve the issue by killing ScopedBookmarksAgent (you may also need to kill and relaunch your app, depending on what state it ends up). On the user side, a log out (or reboot) should resolve the issue.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

Today, mysteriously, the sample code works again. How could this possibly happen? Yesterday all my App Store apps weren't able to resolve and create file bookmarks, and today they work again.

Today, mysteriously, the sample code works again. How could this possibly happen? Yesterday all my App Store apps weren't able to resolve and create file bookmarks, and today they work again.

It's hard to guess at an exact cause, but this particular error:

Error Domain=NSCocoaErrorDomain Code=256 "Failed to retrieve app-scope key"

...comes from one of the intermediate daemons involved in resolving security scoped bookmarks. If there was a problem in one of the lower level daemons it communicated with, then it's possible the problem would resolve itself if/when that daemon restarted.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

I have the same issue, did you find a solution?

I have the same issue, did you find a solution?

We're seeing the same thing in the wild. Security Scoped Bookmarks on macOS 15 don't resolve after a while.

Reports are that a device restart helps, but only for a little while. Trying to gather more data from some pretty angry users right now... Same app/binary works on lower macOS versions. App is a sandboxed.

Something is very broken resolving Security Scoped Bookmarks on Sequoia.

Edit to add: Same error is indicated (256).

Uh o. I have a sandbox app that uses security scoped bookmarks. Nobody's mentioned this to me so far.

Just to throw some spaghetti at the wall, is it possible this could be related to not balancing -startAccessingSecurityScopedResource calls with -stopAccessingSecurityScopedResource when you are done with the file?

If I remember from many years ago not doing this would eventually cause open/save panels etc. to no longer work in your app until after you reboot your Mac.

If you're having this kind of issue in your app, the first and most important step is to file bugs. If you've filed bugs, please post the bug numbers here.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

Just to throw some spaghetti at the wall, is it possible this could be related to not balancing -startAccessingSecurityScopedResource calls with -stopAccessingSecurityScopedResource when you are done with the file?

I don't think so. This happened both with my App Store published app and with a sample app I had just created to reproduce the issue. Even after restarting both apps they had the same issue. It only disappeared the day after.

If you've filed bugs, please post the bug numbers here.

Yesterday I filed FB15258541.

Yesterday I filed FB15258541.

Thank you, that was very helpful.

What you're hitting is bug in "ScopedBookmarksAgent" which can cause it hang if it happens to have been launched when the keychain was also locked (for example, late in the screen lock process). That bug is fixed as of macOS 15.1 beta 4.

If you're hitting it regularly during development, you can resolve the issue by killing ScopedBookmarksAgent (you may also need to kill and relaunch your app, depending on what state it ends up). On the user side, a log out (or reboot) should resolve the issue.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

That bug is fixed as of macOS 15.1 beta 4.

Thank you for the feedback. I'm looking forward to the fix.

Thanks for the quick fix. Also running into this and can't wait for 15.1 to come out!

Does anyone see the same problem on macOS 14.7.1?

I've received multiple reports from users that macOS 14.7.1 cannot create new bookmarks or resolve existing bookmarks. Same error message:

Error Domain=NSCocoaErrorDomain Code=256 "Failed to retrieve app-scope key" UserInfo={NSDebugDescription=Failed to retrieve app-scope key}
  • All users updated from macOS 13.* Ventura to macOS 14.7.1 Sonoma, which triggered the issue
  • Restarting Mac does not fix the issue
  • Clearing all app data does not resolve the issue

One user reported that using bookmarks on a new macOS user account works correctly. This leads me to believe that the macOS keychain for their user account is broken. See also https://developer.apple.com/forums/thread/46583

Does upgrading from macOS 13 to macOS 14.7.1 break the keychain?

Still seeing this issue on 15.1. Also on 14.5 and 14.6.

I haven't had the issue since updating to macOS 15.1 and haven't got any more reports from users either, but I will update you if I do.

Creating file bookmarks doesn't work anymore on macOS 15 Sequoia
 
 
Q