Repository navigation
feat(chat): require an idempotency key on StartChat - #787
Merged
Merged
Conversation
flipcash2 0.8.0 adds a required idempotency_key field to StartChatRequest: a retry with the same key returns the original chat (result OK) instead of creating a duplicate, even if the group title/picture/rules differ on the retry. Thread a UUID through ChatService.startChat and FlipClient.startChat as a required parameter, encoded the same way clientMessageID already is for SendMessage. The caller must mint the key once, where the user's intent to create the chat originates, and reuse it across retries of that attempt. There is no call site yet to wire that reuse into, so this scaffolds the plumbing without inventing one. Built against the local flipcash2-client-protocol override (FLIPCASH_PROTO_LOCAL); no published release exists at this contract version yet.
StartChat needs the idempotency_key field that 0.8.0 adds. Blocked until that tag exists for SPM to resolve.
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.
Draft: blocked on code-payments/flipcash2-client-protocol#14. This branch pins
flipcash2-client-protocol0.8.0, and no such tag exists yet, so theexact:requirement has nothing for SPM to resolve. It goes green once that PR merges and publishes.What changed upstream
StartChatRequestgained a requiredidempotency_key(field 9), backed by a new 16-byteIdempotencyKeymessage. Nothing was removed and nothing was renumbered —StartChatResponse.Resultkeeps all six cases in order, soErrorStartChat's positionalrawValuemapping is unaffected. Confirmed by reading the mapping, not assumed.What this does
idempotencyKey: UUIDbecomes a required parameter — no default — on both layers that exist:ChatService.startChatand theFlipClient.startChatwrapper that threads it through.UUIDrather than rawDatabecause the existingUUID.dataextension is exactly the 16 bytes the proto'smin_len: 16/max_len: 16demands, and because it matches the precedent already in this codebase:sendMessage'sclientMessageID: UUID, whichConversationController.send/.retrymint once and reuse across retries of the same logical send.No default value is the point of the change. The server derives the chat's identity from caller plus key, so a key minted inside the call, fresh per attempt, would pass validation while producing exactly the duplicate chats the field prevents. Forcing the caller to supply it keeps minting where the user's intent originates. Both doc comments say so.
Ordering is preserved:
$0.auth = owner.authFor(message: $0)still runs last, so the signature covers the new field.Scope left open
There is no group-chat-creation screen on
main—startChathas no caller aboveFlipClient, so there is no retry path yet in which to reuse a key. (Every otherstartChat*match in the tree is the unrelatedstartChattingtip-DM fee concept.) AConversationController-level create/retry pair analogous tosend/retryis the natural home for that reuse, and belongs with the screen that needs it rather than here.Builds
xcodebuild build -scheme Flipcash -destination generic/platform=iOSviaScripts/build.sh, against the client repo throughFLIPCASH_PROTO_LOCAL/FLIPCASH_PROTO_LOCAL_PACKAGES=flipcash2rather than a published tag — succeeds.Package.resolvedis unchanged: the local override drops the overridden package's entry while it is on, and that was restored before committing.