Skip to content

refactor: hold the bar weakly in edit mode, the Undo history and pinned popups - #493

Merged
M4n0x merged 1 commit into
mainfrom
refactor/weak-store-owners
Nov 8, 2026
Merged

M4n0x merged 1 commit into
mainfrom
refactor/weak-store-owners

Conversation

@M4n0x

@M4n0x M4n0x commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator

Problem

An unowned reference to BarStore crashes the whole test run when something outlives the store. A view or a task keeps the helper alive, and its next read of the store aborts with "Attempted to read an unowned reference but the object was already destroyed". #481 fixed that for the package library, which caused the crashes seen on CI. Edit mode (BarEditing), the Undo history (ConfigurationHistory) and pinned popups (PinnedPopup in WidgetPopup.swift) still held the store unowned. The rule in AGENTS.md is that a helper pointing back at its owner holds it weak.

Changes

  • BarEditing, ConfigurationHistory and PinnedPopup hold the store weak. While the store is there, nothing changes. Once it's gone, they have nothing left to change:
    • reads return empty or false;
    • edits return without doing anything;
    • a pinned popup is dismissed, like one whose widget left the bar.
  • A queued edit still keeps the store until it finishes, as before.
  • ArchitectureRulesTests now allows no unowned reference at all: noUnownedReferences replaces the per-file allowance.
  • StoreLifetimeTests uses edit mode and the Undo history after their store is released.

Testing

  • Before the change, editModeAndUndoHistoryThatOutliveTheirStoreDoNothing aborted the test run with the unowned-reference crash. After it, the test passes.
  • The suites that use edit mode, the history or popups pass.
  • Full local run: everything passes except the three tests that also fail on main on this Mac (pinnedPopupsStayOnScreenAndReturnUnderTheirWidget and the two package review tests). The pinned popup test fails at the same five lines with main's WidgetPopup.swift, so it's CI that checks the changed unpin path.
  • No visible change.

Merging

One commit; any merge method works.

Claude Opus 5.5 via Claude Code

…ed popups

A view or a queued task can keep edit mode, the Undo history or a pinned popup alive after
its bar is gone, and reading an unowned bar then crashes the test run, as the package library
did before #481. They now hold the bar weakly and have nothing left to change once it's gone.
ArchitectureRulesTests now allows no unowned reference at all.
@M4n0x
M4n0x requested a review from Seb-GRAF as a code owner November 8, 2026 13:33
@coderabbitai

coderabbitai Bot commented Nov 8, 2026

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

BarEditing, ConfigurationHistory, and PinnedPopup now hold BarStore weakly and handle its absence during store-dependent operations. The changes also add a store-lifetime test and tighten the architecture test to reject unowned references in Swift sources.

Changes: BarStore lifetime handling

Layer / File(s) Summary
Guard editing operations
Sources/StableBar/BarEditing.swift
BarEditing uses a weak store reference. Queries return fallback values, and editing operations skip store-dependent work when the store is unavailable.
Guard configuration history
Sources/StableBar/ConfigurationHistory.swift, Tests/StableBarTests/StoreLifetimeTests.swift
ConfigurationHistory uses a weak store reference and guards history operations when the store is unavailable. The new test exercises retained editing and history objects after store deallocation.
Guard popup restoration and enforce weak references
Sources/StableBar/WidgetPopup.swift, Tests/StableBarTests/ArchitectureRulesTests.swift
PinnedPopup dismisses its windows if its anchor or store is unavailable. The architecture test rejects unowned references in Swift sources.

Possibly related issues

Possibly related PRs

  • Seb-GRAF/StableBar#481: That PR changes PackageLibrary.store to a weak optional reference; this PR applies the same pattern to BarEditing, ConfigurationHistory, and pinned popups.
Merge Risk: Minimal · up to 54fd3

No actionable regression attributable to this change remains identified. The change is mergeable after normal checks.

Security architecture risk: Low · up to 54fd3

The reviewed changes replace crash-prone lifetime assumptions with guarded behavior. Queued edits retain their owner, and existing configuration-write checks remain in place. No new privilege or exposure was identified, but some lifetime edge cases remain incompletely covered.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The reviewed effects are bounded to application editing state, popup windows, and configuration files already reachable through the existing store. Existing every-bar edits can affect multiple bar configuration files, but this PR does not add that capability or expand its targets.

Trust Boundaries and Controls

  • observed — Unpin removes the pinned entry before either dismissing it or restoring it with a locally retained store. Its inspected UI caller itself holds a strong store reference, which limits reachability of the new missing-store branch through that caller.

Resilience and Maintainability Implications

  • observed — Ending editing clears pending visual state and prevents queued actions that have not started from running. It does not cancel an action already suspended in asynchronous preparation. That behavior predates this PR; the weak-reference change preserves it rather than introducing a new cancellation guarantee.
Pre-merge checks: Passed 3

Check name Status Explanation
Description check Passed The description follows the template's Problem, Changes, Testing, and Merging sections and ends with the required agent attribution line. It states the cause (an unowned reference to BarStore that abo…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description follows the template's Problem, Changes, Testing, and Merging sections and ends with the required agent attribution line. It states the cause (an unowned reference to BarStore that aborts when the store is destroyed), lists the changed files and behavior when the store is gone, and gives concrete test results. The Problem section does not link an issue number, and the Changes section does not explain how the template's visible-change screenshot requirement applies. The author reports no visible change, so that gap is minor. Overall the description is mostly complete.

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: 5
  • Waived: $1.25 (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 e630e3e and 54fd3f7.

Files selected for processing: 5

  • Sources/StableBar/BarEditing.swift
  • Sources/StableBar/ConfigurationHistory.swift
  • Sources/StableBar/WidgetPopup.swift
  • Tests/StableBarTests/ArchitectureRulesTests.swift
  • Tests/StableBarTests/StoreLifetimeTests.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 e630e3e → this pull request at 54fd3f7 · 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 632d061 into main Nov 8, 2026
15 checks passed
@M4n0x
M4n0x deleted the refactor/weak-store-owners branch November 8, 2026 13:54
M4n0x added a commit that referenced this pull request Nov 8, 2026
#493 bans unowned references outright and #490 keeps private macOS API in PrivateAPI.swift,
so only the BarStore cap is a number that goes down.
@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.

1 participant