Repository navigation
fix(ios): scan library folders off the main actor - #684
libravault-pipeline-bot[bot] wants to merge 2 commits into
Conversation
loadLibrary() called FileManager.enumerator synchronously on AppState's own MainActor. For a folder backed by a file-provider extension (iCloud Drive being the common case) that enumeration can mean the OS fetching remote metadata for every not-yet-downloaded placeholder, which is slow enough to trip the main-thread hang watchdog. Since loadLibrary() runs on every launch, this made the app look like it crashed on startup every single time a slow folder was added (#683).
Regression guard for #683 — verifies loadLibrary()'s scan hook fires off the main thread via AppState.onFolderScanForTesting, rather than relying on timing to observe main-actor blocking.
QA verification — PR #684 vs #683Environment note up front: this runner has no Xcode/macOS toolchain, and the PR's own Issue #683 checklist (bug report → repro steps + regression test)
Regression check
AGENTS.md conventions
Verdict rationaleThe mechanism is well-reasoned, matches an established in-repo pattern, the diff is minimal and self-contained, and the new test genuinely exercises the fix's real behavior rather than a mock. The only real gap is that no actual XCTest/simulator run has happened for this PR in any environment yet (this sandbox can't produce one, and CI's macOS job hasn't produced one either) — that should be treated as outstanding until a real iOS CI run lands, but isn't a defect in the PR's own logic or tests as reviewed. QA verdict: PASS |
There was a problem hiding this comment.
Principal review — verdict: human-merge
Code review
Read the full diff (AppState.swift, AppStateFolderTests.swift) plus the surrounding types it touches (Folder, FolderPersistence, BookData, LibraryFileScanner). The fix is sound on inspection:
scanFoldersOffMainActor()captures onlyfolders/folderPersistenceas locallets before enteringTask.detached, and both are plain structs (Folder,FolderPersistence— confirmed inFolder.swift) with no reference-type members other thanUserDefaults, which is Sendable.BookData(the type crossing back out) is likewise a plain struct. Nothing unsound is crossing the actor boundary.- This is the same
Task.detached+ value-capture shapeenrichCoverArtalready uses one function below it, so the PR is reusing an established pattern rather than introducing a new one, as claimed. - The new test (
testLoadLibraryScansFoldersOffTheMainActor) observes the actual mechanism (which thread the scan hook fires on) via a lock-protected recorder, not a mock — a legitimate regression guard. Verified pre-fix code (git show 8a25b9b^) calledscanFolders()synchronously inline onAppState's own@MainActor, so an equivalent hook there would have recordedtrueand failed this exact assertion. swiftc -parseon the changed file passes with no errors (this sandbox has a Linux Swift 6.3.3 toolchain — not a type-check, same limitation QA's comment already noted).- No sensitive path (
.github/agent-policy.yml) touched, no new networking call,AGENTS.md's test-with-every-fix rule followed, conventional commit messages. risk:lowis current and correctly computed:classify_pr_risk.py origin/dev HEAD→89 changed lines, touches no sensitive path→risk:low, and no commits landed after the label was applied (label at 01:29:52Z, last commit 01:29:13Z).
Why this is routing to a human anyway
QA's own comment on this PR already flags that no real Xcode build/test run exists for it, and I independently confirmed the gap is total, not partial. Checked via the Actions API directly:
- Both actual
iOS App Build & Testworkflow runs for this branch (33030206589,33030247122) hadbuild-ios-simulator/build-android-app/report-statusallskipped— correctly, since both were triggered bysynchronizeevents that landed before the PR left draft (ready_for_reviewfired at 01:29:29Z, 8s after the second commit's run started). - No workflow run of any kind exists for the
ready_for_reviewevent itself —gh api repos/LibraVault/reader/actions/workflows/318109220/runsshows exactly the same two runs and nothing after 01:29:21Z for this branch, despiteios-app-build.ymlexplicitly listingready_for_reviewin its trigger types for exactly this reason.
This is the same root cause already tracked in #433 (open): dev-agent's gh pr ready call uses the default GITHUB_TOKEN, and GitHub Actions doesn't create new workflow runs for events produced by that token — so marking a PR ready never actually triggers the CI it's supposed to. #684 is exactly the shape of PR #433 calls out as most likely to hit this silently: two commits, both pushed before ready_for_review, nothing pushed after — so there's no synchronize event to paper over the gap either. Not filing a new issue since #433 already covers this precisely; left a short comment there noting this as another live occurrence.
Net effect: this specific change — Swift concurrency/actor-isolation code, exactly the category where "I read it carefully and it looks right" is least trustworthy without a real compiler — has never actually been built by Xcode on any commit in this PR. My own reasoning and QA's both check out, but per review policy an unconfirmable "did CI actually run" is treated the same as a CONFIRMED finding rather than resolved in favor of auto-merge.
Suggested next step for whoever picks this up: push a trivial commit (or otherwise force a new synchronize event) to get one real Build & Test iOS (Simulator) run before merging — there isn't one yet for either commit in this PR.
|
Human-merge sweep: closing as superseded. This PR and merged #685 both fix the same underlying issue (#683, "Crash on startup using icloud vault") with the identical mechanism — moving |
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Summary
TestFlight report (#683): "tried to set my vault to an icloud folder and now it crashes on startup immediately." No crash log or device/iOS version was included in the report, so this fix targets the most plausible mechanism given the symptom, and is explained below — CI's real build/test run is the actual verification signal for this platform (this workflow runs on a Linux runner, no Xcode).
AppStateis@MainActor.loadLibrary()— which runs on every launch viainit's ownTask— calledscanFolders()synchronously, which walks every added folder withFileManager.enumerator, real synchronous filesystem I/O. For a plain local folder this is fast, but for a folder backed by a file-provider extension (iCloud Drive being the most common case reported to the app already — see #185), the OS can need to fetch remote metadata for every not-yet-downloaded placeholder as the enumerator walks it. Doing this inline on the main actor is slow enough, for a large enough iCloud folder, to trip iOS's main-thread hang watchdog — which kills the app and reads to the user (and to TestFlight/App Store Connect) exactly like a crash. SinceloadLibrary()re-scans every configured folder on every launch, once a slow folder was added the "crash" reproduced on every subsequent startup, matching the report.Fix: move the actual scanning work into a
Task.detached, capturing only the plain value types the scan needs ([Folder],FolderPersistence) rather thanself, so nothing about the main actor is touched until the scan's results come back.enrichCoverArtright next to this already uses the sameTask.detachedpattern for the same reason (see its own doc comment), so this brings folder scanning in line with it rather than introducing a new pattern.Risk / uncertainty
try?/optionals. The watchdog-timeout mechanism is the only concrete way I found for "iCloud folder" + "crashes on startup, every time" to fit together, but if CI or QA can't reproduce, we may need the reporter's actual crash log to confirm or find a different cause.Closes #683