Skip to content

fix: keep a package library that outlives its bar from crashing the test run - #481

Merged
M4n0x merged 1 commit into
mainfrom
fix/package-updates-after-store
Nov 8, 2026
Merged

M4n0x merged 1 commit into
mainfrom
fix/package-updates-after-store

Conversation

@M4n0x

@M4n0x M4n0x commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator

Problem

Fixes #480. swift test sometimes aborts with "Attempted to read an unowned reference but the object was already destroyed", which ends the whole Swift Testing run. It failed 7 CI runs since 2026-10-23, four of them pushes to main that then published no beta. A local crash report gave the stack: the package update check's task, in PackageLibrary.syncSources().

Changes

  • PackageLibrary holds its BarStore weakly instead of unowned. Its update check (after 15 seconds, then hourly) runs in a task that keeps the library alive while it waits for the package client, and PackagesView keeps a library in @State; either can outlive the store. A library whose bar is gone now leaves it alone: actions that edit the bar return without doing anything, and read-only helpers fall back to the defaults they already had ([.store], 0, nil, false).
  • PackageLibraryLifetimeTests reproduces the crash: it releases the store, then runs the work the update check runs.
  • Not changed: BarEditing, ConfigurationHistory and the pinned popups also hold an unowned BarStore, but no crash points at them. A later change that forbids unowned will convert them with their own tests.

Testing

  • The new test aborted with the CI error before the change and passes after it.
  • The package suites (PackagesViewTests, PackageStoreClientTests, PackageSourceLinkTests) pass, except one test named below.
  • Full local run: everything passes except three tests that fail the same way without this change on this Mac, under a load average above 40 from other builds. testCommandPackageReviewLoadsInAnUnorderedWindow and testCommandReviewLoadsInsidePopoverIncludingRequirementsAndSettings wait 300 ms for a review to load, and failed 3 of 3 runs on main's PackageLibrary too. pinnedPopupsStayOnScreenAndReturnUnderTheirWidget depends on the displays. CI doesn't report any of them.
  • The crash was intermittent on CI, so the evidence it's gone is the deterministic test.

Merging

One commit; any merge method works.

Claude Opus 5.5 via Claude Code

…est run

PackageLibrary held its BarStore unowned, but the update check's task, or a view's @State, can keep
the library alive after the store is gone. When the update check resumed after a test had released
its store, syncSources() read the destroyed store and aborted the whole Swift Testing run. The
library now holds the store weakly and leaves the bar alone once it's gone.

Fixes #480
@M4n0x
M4n0x requested a review from Seb-GRAF as a code owner November 8, 2026 10:46
@coderabbitai

coderabbitai Bot commented Nov 8, 2026

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

PackageLibrary now holds its BarStore weakly. Store-dependent operations return, use fallback values, or skip persistence when the store is unavailable. A test verifies that loading installed packages does not report an error after the store is released.

Changes: Package library lifetime

Layer / File(s) Summary
Weak store and update lifecycle
Sources/StableBar/PackageLibrary.swift, Tests/StableBarTests/PackageLibraryLifetimeTests.swift
PackageLibrary now uses a weak optional store reference. Update, configuration, and preview work handles an unavailable store. The lifetime test releases the store before loading installed packages and checks for a library error.
Package operations when the store is unavailable
Sources/StableBar/PackageLibrary.swift
Package selection, settings persistence, adding, deactivation, and uninstalling now return or skip persistence when the store is unavailable.
Package source access and updates
Sources/StableBar/PackageLibrary.swift
Source lookup uses a fallback when the store is unavailable. Editability checks and source add, update, and removal operations handle a missing store.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 88fa2

The library now tolerates a released store during installed-package loading. No merge-blocking risk was identified.

Security architecture risk: Minimal · up to 88fa2

The change removes an unsafe lifetime dependency without expanding package-installation authority or exposing a new production entrypoint. Store-dependent mutations stop when the owner is unavailable.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed authority boundary is local to the original library, its owning bar configuration and its existing package client. Losing the owner does not grant authority over another bar or substitute another package directory.

Trust Boundaries and Controls

  • observed — Adding, updating or removing a configured package source now requires the original store to be available before configuration edits or associated token-saving calls begin. Duplicate-source and source-editability checks remain in place.

Resilience and Maintainability Implications

  • inferred — The new owner checks precede guarded package mutations and their working-state changes. Existing cleanup defers, error handling and configuration/token sequencing are retained rather than replaced by a new transaction or recovery protocol. Previously scheduled source synchronization can still finish client work without writing through a released BarStore.
Pre-merge checks: Passed 3

Check name Status Explanation
Description check Passed The description follows the repository template closely. It has all four sections: Problem, Changes, Testing, and Merging. The Problem section states the failure and links issue #480 with "Fixes #480"…
Linked Issues check Passed Objective [#480]: a PackageLibrary that outlives its BarStore must skip store-dependent work without crashing. The diff changes private unowned let store: BarStore to `private weak var store: BarSto…
Out of Scope Changes check Passed All changed hunks lie in Sources/StableBar/PackageLibrary.swift and Tests/StableBarTests/PackageLibraryLifetimeTests.swift. Each hunk either changes the store reference to weak, adds a nil guard or fa…
Full details: Description check

Explanation

The description follows the repository template closely. It has all four sections: Problem, Changes, Testing, and Merging. The Problem section states the failure and links issue #480 with "Fixes #480". The Changes section explains the weak-reference switch and why each lifetime path can outlive the store, and it lists the deliberately unchanged unowned references with reasons. The Testing section reports the new test's before/after result, the suites that pass, the three local failures with their load and display context, and the limits of the evidence. The Merging section states that one commit is present and that any merge method works. The last line names the model and harness, which the template requires. The template asks for before/after screens for visible changes, but this change is not visible in the UI, so that omission is acceptable.

Full details: Linked Issues check

Explanation

Objective [#480]: a PackageLibrary that outlives its BarStore must skip store-dependent work without crashing. The diff changes private unowned let store: BarStore to private weak var store: BarStore? in Sources/StableBar/PackageLibrary.swift. Every store-dependent path now has a guard or fallback. The reproduction path in the issue (loadInstalled -> configurationChanged -> syncSources) now returns early when the store is gone, so it no longer reads a destroyed store. Read-only helpers use fallbacks: shownWidgets returns 0, currentSources returns [.store], isEditable returns false, definingFile returns nil, and preview uses a nil themes directory. Action methods such as update, applyUpdate, select, add, deactivate, uninstall, addSource, updateSource, removeSource, applySources and setSetting return without acting when the store is nil. The new test PackageLibraryLifetimeTests.packageLibraryThatOutlivesItsStoreSkipsItsUpdateWork follows the issue's reproduction steps: it releases the store, keeps packageLibrary, calls await library.loadInstalled(), and asserts no error. The issue has no non-coding requirements. The issue's related notes on BarEditing, ConfigurationHistory and pinned popups are context, not requirements, and the PR does not change them. Limit: I did not run the test suite. This verdict rests on source and test inspection. The test also assumes no other strong reference keeps the BarStore alive after release, which the test checks through #expect(released == nil).

Full details: Out of Scope Changes check

Explanation

All changed hunks lie in Sources/StableBar/PackageLibrary.swift and Tests/StableBarTests/PackageLibraryLifetimeTests.swift. Each hunk either changes the store reference to weak, adds a nil guard or fallback for a store-dependent member, or adds the lifetime test. The preview hunk passes an optional themes directory when the store is nil. This follows from the same weak-reference change and does not add unrelated behavior. No hunk changes BarEditing, ConfigurationHistory, the pinned popups, or any unrelated feature. The PR description's test-run claims concern test environment results and are not code changes, so they do not affect this assessment.

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Usage-based review receipt

  • Mode: Continue automatically
  • Reviewed files: 2
  • Waived: $0.50 (charged $0.00)
  • View usage details

Note

This review exceeded your plan’s limits and used usage-based reviews—free during trial, billed after paid activation unless disabled. Manage usage-based reviews.

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 940777d and 88fa212.

Files selected for processing: 2

  • Sources/StableBar/PackageLibrary.swift
  • Tests/StableBarTests/PackageLibraryLifetimeTests.swift

Limit details: You’ve used all 10 included reviews currently available.

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Before and after

main at 940777d → this pull request at 88fa212 · 50 screens drawn in one CI job · 0 changed

50 unchanged screens

docs/essentials-clock-settings-dark, docs/essentials-clock-settings-light, docs/essentials-dark, docs/essentials-light, docs/essentials-settings-dark, docs/essentials-settings-light, docs/hero-dark, docs/hero-light, docs/popups-dark, docs/popups-light, docs/settings-dark, docs/settings-light, docs/themes-dark, docs/themes-light, scenes/app-menu-popup-dark, scenes/app-menu-popup-light, scenes/apple-menu-settings-dark, scenes/apple-menu-settings-light, scenes/crowded-edit-bar-dark, scenes/crowded-edit-bar-light, scenes/dock-badges-bar-dark, scenes/dock-badges-bar-light, scenes/essentials-clock-popup-dark, scenes/essentials-clock-popup-light, scenes/gruvbox-bar-dark, scenes/gruvbox-bar-light, scenes/horizontal-list-popup-dark, scenes/horizontal-list-popup-light, scenes/settings-bar-dark, scenes/settings-bar-light, scenes/settings-bar-placement-dark, scenes/settings-bar-placement-light, scenes/settings-general-dark, scenes/settings-general-light, scenes/settings-general-spaces-dark, scenes/settings-general-spaces-light, scenes/settings-theme-dark, scenes/settings-theme-light, scenes/settings-uninstall-dark, scenes/settings-uninstall-failed-dark, scenes/settings-uninstall-failed-light, scenes/settings-uninstall-light, scenes/slider-end-stop-popup-dark, scenes/slider-end-stop-popup-light, scenes/starter-bar-dark, scenes/starter-bar-light, scenes/starter-edit-bar-dark, scenes/starter-edit-bar-light, scenes/update-popup-dark, scenes/update-popup-light

Visual review: 50 screens, none changed.

@M4n0x
M4n0x merged commit 5f4821d into main Nov 8, 2026
15 checks passed
@M4n0x
M4n0x deleted the fix/package-updates-after-store branch November 8, 2026 11:27
M4n0x added a commit that referenced this pull request Nov 8, 2026
#481 replaced PackageLibrary's unowned store with a weak one, so its allowance drops to 0 and a new
unowned reference there fails the test.
stablebar-releases Bot pushed a commit that referenced this pull request Nov 10, 2026
## [0.12.0](v0.11.0...v0.12.0) (2026-11-10)

### Features

* ask for the permissions your bar needs before setup uses them ([#442](#442)) ([9494cc7](9494cc7)), closes [#441](#441)
* let a group's top corners curve outward into the top of the screen ([265eb90](265eb90))
* paint the notch black so screen shares and screenshots match the display ([c40dda3](c40dda3))
* set widget, popup and tooltip backgrounds separately ([7eaf5af](7eaf5af))
* show Rift workspaces in workspace widgets ([d0f6d4d](d0f6d4d))
* turn on Open at login when setup replaces the menu bar ([#507](#507)) ([d24abe1](d24abe1))

### Bug Fixes

* ask before Skip setup throws away the choices made so far ([#470](#470)) ([66f47ea](66f47ea)), closes [#454](#454)
* ask where the bar goes first, and for permissions after the choices ([#492](#492)) ([1f45416](1f45416)), closes [#450](#450)
* drop a window that left every workspace when clicking it fails ([ec45fcc](ec45fcc)), closes [#520](#520)
* drop stray focus rings and show popup focus in the theme's hover look ([61ea306](61ea306))
* fall back to macOS Spaces when no window manager is running ([#436](#436)) ([5cc4ef2](5cc4ef2)), closes [#435](#435) [#435](#435)
* give a bar below the menu bar what the menu bar doesn't show ([#469](#469)) ([1181904](1181904)), closes [#452](#452)
* hold Edit Bar in Place until setup is done ([7582976](7582976)), closes [#462](#462)
* keep a bar below the menu bar clear of it on every display ([#468](#468)) ([ff1d0e9](ff1d0e9)), closes [#451](#451)
* keep a cancelled hover from showing a tooltip or closing its popup late ([#483](#483)) ([93c44a1](93c44a1)), closes [#482](#482)
* keep a package library that outlives its bar from crashing the test run ([#481](#481)) ([5f4821d](5f4821d)), closes [#480](#480)
* keep a popup's focus when clicking inside it ([f5ecaec](f5ecaec))
* keep setup's buttons above a Dock at the bottom of the screen ([#445](#445)) ([2784139](2784139)), closes [#444](#444)
* keep setup's pointer below the bar when the menu bar shows ([#509](#509)) ([ef22935](ef22935))
* keep setup's steps, reminders and hints readable on short screens ([#476](#476)) ([940777d](940777d)), closes [#455](#455)
* keep the app menus on the menu bar's app while a background agent is in front ([#446](#446)) ([a900ef5](a900ef5)), closes [#443](#443)
* keep the app menus that fit beside the notch and put the rest behind » ([#477](#477)) ([8b09465](8b09465)), closes [#453](#453)
* keep the focus ring while editing the bar ([80195ff](80195ff))
* keep widgets beside the notch against it when More widgets shows its button ([d74b925](d74b925))
* leave Battery out of setup's presets on a Mac without a battery ([3db935d](3db935d)), closes [#456](#456)
* let Skip setup restore the menu bar when a change is still in flight ([#498](#498)) ([9fdf1ce](9fdf1ce)), closes [#497](#497)
* look up private macOS calls at runtime, so a missing one only turns its feature off ([#490](#490)) ([5f312fd](5f312fd))
* move a bar an earlier setup put below the menu bar under it ([#475](#475)) ([9cada9a](9cada9a)), closes [#468](#468) [#474](#474)
* name the profile that sets belowMenuBar in setup's profile notice ([#473](#473)) ([55aea3c](55aea3c)), closes [#471](#471)
* offer the Notch preset only when the bar replaces the menu bar ([#438](#438)) ([dc5a611](dc5a611)), closes [#437](#437)
* reject a negative group flare ([eae8615](eae8615))
* show workspace managers as segments in Settings again ([60e21a5](60e21a5))
* start a new bar with a clock in the Mac's date order and 12- or 24-hour time ([#501](#501)) ([ed119f7](ed119f7))
* stop reopening setup at every launch after Skip setup ([#472](#472)) ([a15e07a](a15e07a)), closes [#449](#449)
@stablebar-releases

Copy link
Copy Markdown

🎉 This PR is included in version 0.12.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The test run crashes when a package library outlives its bar

1 participant