Skip to content

Conversation

@lmarceau
Copy link
Contributor

@lmarceau lmarceau commented Oct 3, 2025

📜 Tickets

Jira ticket
Github issue

💡 Description

Second attempt at this, first one was here.

Now we do get the compiler errors. This is under tab peek (if I remove the ensureMainThread which was added a week ago or so):

Screenshot 2025-10-02 at 8 48 15 PM

And this is another error we didn't catch as well last time around:

Screenshot 2025-10-02 at 8 16 39 PM

cc: @Cramsden @ih-codes

📝 Checklist

  • I filled in the ticket numbers and a description of my work
  • I updated the PR name to follow our PR naming guidelines
  • I ensured unit tests pass and wrote tests for new code
  • If working on UI, I checked and implemented accessibility (Dynamic Text and VoiceOver)
  • If adding telemetry, I read the data stewardship requirements and will request a data review
  • If adding or modifying strings, I read the guidelines and will request a string review from l10n
  • If needed, I updated documentation and added comments to complex code

@lmarceau lmarceau requested a review from ih-codes October 3, 2025 00:54
@lmarceau lmarceau requested a review from a team as a code owner October 3, 2025 00:54
@mobiletest-ci-bot
Copy link

mobiletest-ci-bot commented Oct 3, 2025

Messages
📖 Project coverage: 38.42%

🧹 Tidy commit

Just 1 file(s) touched. Thanks for keeping it clean and review-friendly!

💬 Description craftsman

Great PR description! Reviewers salute you 🫡

❌ Per-file test coverage gate

The following changed file(s) are below 35.0% coverage:

File Coverage Required
firefox-ios/Client/Frontend/Browser/Tabs/Middleware/TabManagerMiddleware.swift 25.6% 35.0%

Client.app: Coverage: 37.2

File Coverage
TabManagerMiddleware.swift 25.6% ⚠️

Generated by 🚫 Danger Swift against 52db608

Copy link
Collaborator

@ih-codes ih-codes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cleanup, and thank goodness for finally seeing the correct compiler errors! 👏

@lmarceau lmarceau force-pushed the lm/TabManagerMiddleware branch from 57ea2c1 to b80d510 Compare October 3, 2025 17:45
@lmarceau lmarceau requested review from a team and issammani as code owners October 3, 2025 17:45
@lmarceau lmarceau requested review from clarmso and removed request for a team October 3, 2025 17:45
@lmarceau lmarceau force-pushed the lm/TabManagerMiddleware branch 2 times, most recently from 84f7941 to a2c6dc6 Compare October 6, 2025 14:50
@lmarceau
Copy link
Contributor Author

lmarceau commented Oct 6, 2025

Those same two tests fails every time, but they pass locally. I am not sure what's up there

Screenshot 2025-10-06 at 11 26 31 AM

Copy link
Collaborator

@clarmso clarmso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReadingListsTests fail on my end as well. The tests are known to be passing consistently.

@lmarceau lmarceau force-pushed the lm/TabManagerMiddleware branch from a2c6dc6 to 5b10e38 Compare October 8, 2025 14:25
@lmarceau lmarceau requested review from clarmso and ih-codes October 8, 2025 16:06
Copy link
Collaborator

@ih-codes ih-codes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pulled down to test the crash and it's pretty crazy to me the compiler gives zero warnings on this. I want to test a bit in a brand new Swift 6.2 project and/or playground just to replicate the issue to see if I get anything there.

What do you think changing the group.notify to dispatch to the main thread? That seems the real issue here (the mix of GCD and Concurrency). Then we could put an assert instead of ensureMainThread in the fetchProfileTabInfo completion... because if concurrency was working correctly for us here we shouldn't have to do that. 😭

private func fetchProfileTabInfo(...) {
   ...
   group.notify(queue: dataQueue) // <- main queue instead?

/// - isPrivate: if the tab should be created in private mode or not
private func addNewTab(with urlRequest: URLRequest?, isPrivate: Bool, showOverlay: Bool, for uuid: WindowUUID) {
assert(Thread.isMainThread)
MainActor.assertIsolated("Expected to be called only on main actor.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to double check that this gets removed at prod compile time, it sounds like it does!

Copy link
Collaborator

@clarmso clarmso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 Woohoo the issue in tests has been resolved.

Copy link
Collaborator

@ih-codes ih-codes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wanted to update here for visibility. After some testing, it seems the only scenario we do NOT get the appropriate build warnings in Xcode is due to the GCD DispatchGroup.notify call. For whatever reason, this call does not require the closure to be marked @Sendable, which in turn would have let us know that the closure might not execute on the main thread (which is what caused the crash @lmarceau saw in the UI tests). If we used instead DispatchQueue.global().async we get the expected warnings to at least tip us off to a runtime crash problem.

I've opened a discussion on the Apple Developer Forums about this last week... haven't heard anything yet.

Anyway, for now I think I'd like to see the dataLoadingCompletion closure marked @Sendable in the fetchProfileTabInfo function definition, and for the notify to dispatch deliberately to the main thread (instead of the background queue). It's a little weird to thread hop for that like we're doing anyway.

Maybe we can also put a main thread assertion in the fetchProfileTabInfo callback implementation and add a comment referring back to this PR for the discussion points. (Also still good to continue to use the ensureMainThread as well as backup 👌 ).

@lmarceau lmarceau force-pushed the lm/TabManagerMiddleware branch from 5b10e38 to 52db608 Compare October 14, 2025 19:47
@lmarceau lmarceau requested a review from ih-codes October 14, 2025 19:47
Copy link
Collaborator

@ih-codes ih-codes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @lmarceau for your iterations on this one! 🚀

@lmarceau lmarceau merged commit 9aebabd into epic-branch/swift-6-redux-migration Oct 14, 2025
9 checks passed
@lmarceau lmarceau deleted the lm/TabManagerMiddleware branch October 14, 2025 21:09
@lmarceau
Copy link
Contributor Author

Created the task for follow up investigation on notify here

lmarceau added a commit that referenced this pull request Oct 16, 2025
…re (#29768)

* Tab manager middleware

* fetchProfileTabInfo completion needs to be called on the main thread

* Update following comment
lmarceau added a commit that referenced this pull request Oct 16, 2025
…re (#29768)

* Tab manager middleware

* fetchProfileTabInfo completion needs to be called on the main thread

* Update following comment
lmarceau added a commit that referenced this pull request Oct 17, 2025
…re (#29768)

* Tab manager middleware

* fetchProfileTabInfo completion needs to be called on the main thread

* Update following comment
lmarceau added a commit that referenced this pull request Oct 20, 2025
…re (#29768)

* Tab manager middleware

* fetchProfileTabInfo completion needs to be called on the main thread

* Update following comment
ih-codes pushed a commit that referenced this pull request Oct 28, 2025
…re (#29768)

* Tab manager middleware

* fetchProfileTabInfo completion needs to be called on the main thread

* Update following comment
ih-codes added a commit that referenced this pull request Oct 28, 2025
…Actor` isolation (#30208)

* Refactor FXIOS-12831 [Swift 6 Migration] MainActor TabManagerMiddleware (#29768)

* Tab manager middleware

* fetchProfileTabInfo completion needs to be called on the main thread

* Update following comment

* Refactor FXIOS-12831 [Swift 6 Migration] MainActor ToolbarMiddleware (#30014)

Toolbar middleware

Missing microsurvey to be tested

* Ih/fxios 12831 search engine selection middleware 2 (#30026)

* Isolate the SearchEngineSelectionMiddleware to the main actor.

* Update unit tests.

* Tweak mocks so the SearchEnginesManagerTests unit tests pass under the same threading assumptions.

* Refactor FXIOS-12831 [Swift 6 Migration] MainActor TopSitesMiddleware & HomepageMiddleware (#30039)

Migration for those two middlewares

* Refactor FXIOS-12831 [Swift 6 Migration] MainActor SummarizerMiddleware (#30042)

Migration

* Refactor FXIOS-12831 [Swift 6 Migration] MainActor MainMenuMiddleware (#30013)

main menu middleware is now main actor

* Refactor FXIOS-12831 [Swift 6 Migration] MainActor TermsOfUseMiddleware & StartAtHomeMiddleware (#30061)

Migration

* Refactor FXIOS-12831 [Swift 6 Migration] @mainactor MessageCardMiddleware & ShortcutsLibraryMiddleware (#30064)

Migration

* Refactor FXIOS-12831 [Swift 6 Migration] MainActor MicrosurveyMiddleware & MicrosurveyPromptMiddleware (#30041)

* MIgration

* Adjust test

* Refactor FXIOS-12831 [Swift 6 Migration] MainActor ThemeMiddleware & FakeReduxMiddleware (#30040)

Migration

* Refactor FXIOS-12831 [Swift 6 Migration] FeltPrivacyMiddleware & BookmarksMiddleware (#30083)

Migration

* Refactor FXIOS-12831 [Swift 6 Migration] NativeErrorPageMiddleware & TrackingProtectionMiddleware (#30088)

* Migration

* Native error page VC migration

* Fix VC/coordinator not getting deinit

* Revert dispatch legacy changes

* Refactor FXIOS-12912 [Swift 6] Make Redux States sendable and Reducers @mainactor isolated (#30081)

* Make Redux State Sendable and Reducers MainActor isolated

* disambiguate passthrough state and default state

* Fix tests

* PR feedback

* Refactor FXIOS-12831 [Swift 6 Migration] RemoteTabsPanelMiddleware & WallpaperMiddleware MainActor (#30117)

Migration

* Refactor FXIOS-12831 [Swift 6 Migration] PasswordGeneratorMiddleware actor isolation (#30085)

* Isolate PasswordGeneratorMiddleware to the main actor.

* Add @mainactor annotations to our WebKit JS evaluation wrappers.

* Refactor FXIOS-12831 [Swift 6 Migration] MerinoMiddleware actor isolation (#30084)

Isolate MerinoMiddleware to the main actor.

---------

Co-authored-by: lmarceau <[email protected]>
Co-authored-by: Carson Ramsden <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants