trackslash
VAULT-137 P2 For an agent

Mac app can crash the first time a counter-based code's row is drawn during a synchronous layout

0
All issues

Description

Found while building the Mac screenshot mode (VAULT-135).

VaultMacRoot.hotpPreviewRepository is a lazy static. Its initializer appends the repository to vaultDataModel.itemCaches, which is observable. The static can first be touched while a counter-based (HOTP) code's row is evaluated for the first time. If that happens during a synchronous layout, such as a window resize, the append invalidates a view straight away. The view's body is re-evaluated, reads hotpPreviewRepository again while its initializer is still running, and the app crashes with a recursive dispatch_once.

It was reproduced in screenshot mode by resizing the window while a list with counter-based codes was showing. The workaround there was to resize while locked. Nothing in screenshot mode makes this more likely, so a real resize that first draws a counter-based row probably crashes too. That still needs confirming in a normal debug build.

totpPreviewRepository uses the same pattern. It's probably first touched earlier, through vaultItemCopyHandler, but check it too.

Fix idea: create both preview repositories, and register them in itemCaches, eagerly at app start, outside any view's body. Or register them without mutating observable state from inside a static initializer. Add a test that draws a feed whose first counter-based row appears during a resize, or one that pins the eager setup.

Sub-issues

0

Linked issues

0

GitHub

0

No branches or pull requests linked.

Comments

2
Bradley

Merged as #768 (195bdab7) on 2026-11-14, after a full green make validate with the Mac unlocked, Mac UI tests included. It ships with the next release, and the CHANGELOG has it under Unreleased.

Bradley

PR: https://github.com/badbundle/vault-app/pull/768

Cause. The append that registers a repository can't invalidate the body it's made in: Observation installs that body's observer only after it finishes. What crashes is a second registration. The view whose body registered the first repository goes on observing itemCaches. Registering the next one, from a counter-based row during a synchronous layout, invalidates that view at once, and its body reads the second static again while it's still being made.

Fix.

  • VaultDataModel.itemCaches is @ObservationIgnored, which covers iOS's identical pattern too.
  • VaultMacRoot.setup() makes both repositories at launch.
  • A VaultDataModelTests test pins it. It fails without the change.

I didn't reproduce the crash itself: a SwiftUI test host with the same pattern deferred the re-evaluation and didn't crash.