Same here. Starting with iOS 17.4, my app waking in the background would crash when accessing an invalid modelContext environment variable.
Even moving the app into the background with recent SwiftData changes (especially changes to Relationships) caused the same crash. My guess is that an autoSave is triggered? Easier to reproduce on iPad.
My workaround, based on the helpful discussion above....
Create a globally accessible modelContext and modelContainer. In my case I created a singleton "DataCenter" object created in the first line of the app's init.
Remove ALL @Environment(.modelContext) private var modelContext from your project
Add the modelContainer modifier to the WindowGroup, in my case WindowGroup{...}.modelContainer(DataCenter.shared.container)
Use that global context directly when needed, such as DataCenter.shared.context.insert(...)
Half measures didn't work for me, such as just removing the modelContext environment variable from the root view. Had to nuke it entirely in the project.