Conversation
Contributor
🤖 Pull request artifacts
|
capcom6
force-pushed
the
messages/unified-message-state-service
branch
3 times, most recently
from
August 19, 2026 07:55
ee18a96 to
e87837a
Compare
capcom6
force-pushed
the
messages/unified-message-state-service
branch
from
August 20, 2026 00:49
e87837a to
0253ec7
Compare
capcom6
force-pushed
the
messages/unified-message-state-service
branch
from
August 21, 2026 03:52
0253ec7 to
51430e4
Compare
capcom6
force-pushed
the
messages/unified-message-state-service
branch
from
August 21, 2026 11:50
78114a1 to
c9307f8
Compare
capcom6
force-pushed
the
messages/unified-message-state-service
branch
from
August 25, 2026 01:58
c9307f8 to
e0c178c
Compare
capcom6
force-pushed
the
messages/unified-message-state-service
branch
from
August 27, 2026 00:30
e0c178c to
d987662
Compare
capcom6
force-pushed
the
messages/unified-message-state-service
branch
from
August 29, 2026 23:31
fe75b52 to
eb8889f
Compare
capcom6
force-pushed
the
messages/unified-message-state-service
branch
from
August 31, 2026 02:57
18f55b6 to
aee1110
Compare
capcom6
force-pushed
the
messages/unified-message-state-service
branch
from
August 31, 2026 07:28
aee1110 to
d28a4ae
Compare
capcom6
force-pushed
the
messages/unified-message-state-service
branch
5 times, most recently
from
September 8, 2026 01:16
c03d0f3 to
3918c51
Compare
Contributor
|
This PR is stale because it has been open for 7 days with no activity. |
capcom6
force-pushed
the
messages/unified-message-state-service
branch
from
September 25, 2026 01:44
3918c51 to
487b8e3
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
"## Purpose\n\nExtract message and recipient state transitions from
MessagesServiceinto a dedicatedMessageStateService-- the single point of control for all message state operations. Centralizes transition validation, persistence, and event emission, and fixes a cancellation race condition where a concurrent send worker could dispatch an SMS after recipients were already marked Cancelled.\n\n## Key Changes\n\n### New files\n-MessageStateService.kt-- Single owner of state-transition logic. Every transition: acquires per-message lock, loads current row, validates againstMessageStateTransitions, applies the DAO write, syncs stored state from derived recipient state, and emitsMessageStateChangedEventonly on successful writes.\n-MessageStateTransitions.kt-- Pure state-machine table. Cancelled is not terminal (late SMS outcomes supersede cancel). Failed is the only terminal state.\n-PerMessageLock.kt-- Per-key mutex with atomic reference-counted entry lifecycle. Same-key blocks serialize; different keys run in parallel.\n\n### Modified files\n-MessagesDao.kt-- AddedupdateRecipientsAndMessageState: a single DB transaction that atomically updates recipient and message state, eliminating the two-transaction race window.\n-MessagesService.kt-- Removed ~86 lines of inline state logic; delegates toMessageStateService.\n-GatewayApi.kt-- AddedCancellingto wire-levelMessageState, explicitly separated from localProcessingState.\n-GatewayService.kt-- Resolves cloudCancellingvia the extracted local cancellation path (handleCloudCancel).\n-EventsReceiver.kt-- HandlesMessageCancelledEventby delegating toMessagesService.cancelMessage.\n\n### New tests\n-MessageStateServiceTest.kt-- State-machine validation, cancellation strict-reject, and event emission.\n-MessageStateTransitionsTest.kt-- Transition table correctness.\n-PerMessageLockTest.kt-- Concurrency serialization and entry lifecycle.\n-CancelEntryPointsParityTest.kt-- Parity across all cancellation entry points.\n-GatewayWireStateTest.kt-- Cancelling wire state resolution.\n\n## Cancellation Race Condition Fix\n\nPreviously, cancellation committed recipient and message state in separate transactions. A concurrent send worker could observePendingbetween commits and dispatch the SMS. The fix:updateRecipientsAndMessageStateatomically updates both in one transaction, andPerMessageLockserializes the full read-validate-write-sync-emit cycle per message.\n\n## Known Limitations\n\n- The send worker's pre-send state check insendMessageremains outside the lock. AtomicupdateRecipientsAndMessageStateeliminates the race; the unlocked check is defense-in-depth.\n- DAO mutation methods remain public; visibility cleanup is deferred.\n"The PR appears safe to merge.
Summary
The PR centralizes message and recipient state transitions behind a per-message lock and separates the gateway’s wire-level cancellation state from local processing states.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart TD A[State transition request] --> B[Acquire per-message lock] B --> C[Load message and recipients] C --> D{Transition valid?} D -- No --> E[Reject or no-op] D -- Yes --> F[Atomically persist recipient and message state] F --> G[Reload persisted state] G --> H[Emit MessageStateChangedEvent] H --> I[Release lock]Reviews (26) · Last reviewed commit: "[messages] introduce message state servi..."