Skip to content

Refactor the JobRunner to use actors and be async/await#538

Merged
mpretty-cyro merged 27 commits intosession-foundation:devfrom
mpretty-cyro:feature/job-runner-refactor
Feb 2, 2026
Merged

Refactor the JobRunner to use actors and be async/await#538
mpretty-cyro merged 27 commits intosession-foundation:devfrom
mpretty-cyro:feature/job-runner-refactor

Conversation

@mpretty-cyro
Copy link
Copy Markdown
Collaborator

@mpretty-cyro mpretty-cyro commented Aug 29, 2025

  • Refactored the JobRunner to be an actor and use async/await
  • Refactored the JobQueue to be an actor and use async/await
  • Removed ThreadSafe logic from both
  • Removed the uniqueHashValue from Job
    • Add a migration to drop the column
    • Make the shouldBeUnique behaviour part of the DisplayPictureDownloadJob (since it's only used for that one job)
  • Refactor jobs to conform to the new JobExecuter structure (a number of these will need further refactoring to be fully async/await)
    • AttachmentDownloadJob
    • AttachmentUploadJob
    • CheckForAppUpdatesJob
    • ConfigMessageReceiveJob
    • ConfigurationSyncJob
    • DisappearingMessagesJob
    • DisplayPictureDownloadJob
    • ExpirationUpdateJob
    • FailedAttachmentDownloadsJob
    • FailedGroupInvitesAndPromotionsJob
    • FailedMessageSendsJob
    • GarbageCollectionJob
    • GetExpirationJob
    • GroupInviteMemberJob
    • GroupLeavingJob
    • GroupPromoteMemberJob
    • MessageReceiveJob
    • MessageSendJob
    • ProcessPendingGroupMemberRemovalsJob
    • RetrieveDefaultOpenGroupRoomsJob
    • SendReadReceiptsJob
    • SyncPushTokensJob
    • UpdateProfilePictureJob
  • Test that the jobs are actually still working with the above changes
  • Fix the unit tests

• Refactored the JobRunner
• Refactored the JobQueue
• Refactored the FailedAttachmentDownloadsJob to be async/await
• Refactored the FailedMessageSendsJob to be async/await
• Removed the `uniqueHashValue` from `Job` (make the `shouldBeUnique` behaviour part of the `DisplayPictureDownloadJob` instead)
@mpretty-cyro mpretty-cyro self-assigned this Aug 29, 2025
…efactor

# Conflicts:
#	Session.xcodeproj/project.pbxproj
#	Session/Settings/NukeDataModal.swift
#	SessionMessagingKit/Jobs/AttachmentDownloadJob.swift
#	SessionMessagingKit/Jobs/AttachmentUploadJob.swift
#	SessionMessagingKit/Jobs/CheckForAppUpdatesJob.swift
#	SessionMessagingKit/Jobs/ConfigurationSyncJob.swift
#	SessionMessagingKit/Jobs/DisplayPictureDownloadJob.swift
#	SessionMessagingKit/Jobs/ExpirationUpdateJob.swift
#	SessionMessagingKit/Jobs/GroupInviteMemberJob.swift
#	SessionMessagingKit/Jobs/MessageReceiveJob.swift
#	SessionMessagingKit/Jobs/SendReadReceiptsJob.swift
#	SessionMessagingKit/Jobs/UpdateProfilePictureJob.swift
#	SessionMessagingKit/Utilities/Profile+CurrentUser.swift
#	SessionUtilitiesKit/JobRunner/JobRunner.swift
#	SessionUtilitiesKit/Types/CurrentValueAsyncStream.swift
• Updated `waitUntilInitialised` to have fallback support for iOS 15
• Updated the JobExecutor to allow individual jobs to control their concurrent execution behaviour
• Fixed some race conditions in the JobRunner
• Fixed some issues with concurrent job running
• Fixed some issues where jobs would initialise a Noop version of libSession which could break the users state during this app run
• Updated the code to set the `JobPriorityContext` when entering/leaving a conversation
• Updated the MessageReceiveJob to split failed messages into a separate job (keeps the behaviours and logs more consistent)
• Updated the Onboarding code to use async/await instead of publishers
• Updated the BackgroundPoller to handle the async/await Poller changes
• Fixed a couple of issues with the file download sorting
• Fixed an issue when setting the file sort data retriever
• Fixed an issue where "initial job dependencies" provided when adding a job to the job runner weren't saved to the database
• Fixed a few issues where jobs could fail or behave strangely on startup because they were racing initial data loading
• Fixed an issue where the home and conversation screens would try to trigger layouts while the app was doing background fetches
• Added a timeout to the background message sending logic
• Updated the logic to allow starting specific job variants during the background period (so dependant jobs work)
• Updated the job filtering logic to allow OR based filters within a category (eg. select jobs where "RUNNING" AND ("messageSend" OR "attachmentUpload")
@mpretty-cyro mpretty-cyro changed the title [WIP] Refactor the JobRunner to use actors and be async/await Refactor the JobRunner to use actors and be async/await Jan 27, 2026
@mpretty-cyro mpretty-cyro added enhancement New feature or request Jira This ticket is being tracked in Jira labels Jan 27, 2026
@mpretty-cyro mpretty-cyro requested a review from RyanRory January 27, 2026 21:38
@mpretty-cyro mpretty-cyro marked this pull request as ready for review January 27, 2026 21:38
Comment thread Session/Notifications/SyncPushTokensJob.swift
Comment thread SessionMessagingKit/Database/Migrations/_002_SUK_SetupStandardJobs.swift Outdated
Comment thread SessionMessagingKit/Database/Migrations/_005_SNK_SetupStandardJobs.swift Outdated
Comment thread SessionMessagingKit/Database/Migrations/_007_SMK_SetupStandardJobs.swift Outdated
Comment thread SessionMessagingKit/Database/Migrations/_033_ScheduleAppUpdateCheckJob.swift Outdated
• Made some optimisations to the logging logic
• Updated a bunch of group update functions to be async/await
• Updated code to use `decodedMessage.sender` everywhere instead of `message.sender` (where available)
• Fixed an issue where we would pointlessly try to mutate the contacts config when updating the current users profile info
• Fixed an issue where onboarding could fail to save the user to the database due to a query trying to update a non-existent config
• Cleaned up some logic and updated some database actions to be bulk actions
• Fixed an issue where a long running blocking startup job could lockup the JobRunner preventing any calls to it from returning
• Fixed an issue where jobs being added with initial dependencies could incorrectly be started before the dependencies we added
• Fixed a painful race condition which could cause odd job running behaviours with dependencies due to async loop logic
• Fixed a race condition where a "ghost" dependency could be added to a job if it was removed while being read from the database
• Fixed an issue where the home and conversation screens wouldn't update if a system prompt was visible
• Fixed an issue where receiving a new conversation may not update the home screen under some circumstances
@mpretty-cyro mpretty-cyro merged commit 11125fd into session-foundation:dev Feb 2, 2026
1 check failed
@mpretty-cyro mpretty-cyro deleted the feature/job-runner-refactor branch February 2, 2026 22:16
@mpretty-cyro mpretty-cyro mentioned this pull request Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request Jira This ticket is being tracked in Jira

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants