Skip to content

Conversation

@j0KZ
Copy link

@j0KZ j0KZ commented Feb 5, 2026

Summary

  • Marks BitchatMessage class with @MainActor to ensure thread-safe access to mutable state
  • Prevents potential data races when deliveryStatus is updated from background threads while being read from the UI

Changes

  • Add @MainActor attribute to BitchatMessage class
  • Mark CodingKeys enum as nonisolated for Codable conformance
  • Update documentation to note MainActor isolation

Context

The deliveryStatus property and cached formatted text dictionary are mutable state that can be accessed from multiple threads. By isolating the entire class to MainActor, we ensure all access is serialized on the main thread where SwiftUI updates occur.

Test plan

  • Verify app compiles without actor isolation warnings
  • Verify message delivery status updates correctly in UI
  • Verify cached formatted text works correctly
  • Test with Thread Sanitizer enabled to verify no data races

🤖 Generated with Claude Code

Marks BitchatMessage class with @mainactor to ensure thread-safe access
to mutable state (deliveryStatus, cached formatted text).

Changes:
- Add @mainactor attribute to BitchatMessage class
- Mark CodingKeys enum as nonisolated for Codable conformance
- Mark init as nonisolated to allow creation from BLE callbacks
- Mark toBinaryPayload() and init?(_ data:) as nonisolated for serialization
- Update documentation to note MainActor isolation and nonisolated methods

The nonisolated init allows BitchatMessage to be created from any context
(e.g., CoreBluetooth callbacks on background threads) while mutable state
access (deliveryStatus, cached text) remains MainActor-isolated for safety.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@j0KZ j0KZ force-pushed the feature/thread-safe-delivery-status branch from 5dc9f82 to 4ebc43e Compare February 5, 2026 02:40
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5dc9f82da3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +16 to 17
@MainActor
final class BitchatMessage: Codable {

Choose a reason for hiding this comment

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

P1 Badge Avoid main-actor isolating the entire message model

Marking the whole BitchatMessage type as @MainActor makes its initializers and property reads main-actor isolated. Several call sites construct messages on background queues (for example, CoreBluetooth callbacks in BLEService build BitchatMessage instances before notifyUI hops to the main actor). With this change, those paths either fail to compile under strict concurrency or will synchronously hop to the main actor, which can block BLE processing and cause UI jank. Consider isolating only the mutable cached state (or moving it into a separate @MainActor wrapper) so message creation/parsing can remain off the main thread.

Useful? React with 👍 / 👎.

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.

1 participant