Repository navigation
RAD-17385 iOS: a result from an earlier use of an id cannot change a later request with the same id - #86
Open
dmurphy5 wants to merge 3 commits into
Open
RAD-17385 iOS: a result from an earlier use of an id cannot change a later request with the same id#86dmurphy5 wants to merge 3 commits into
dmurphy5 wants to merge 3 commits into
Conversation
An app can use one request id again after its row is forgotten. The new entry starts again at generation 1 and attempt 1, so a late result, cancel callback, progress event or relaunch match from an earlier use could match it. A late 2xx then completed the new entry with the old response and cancelled its task, a late 4xx failed it, and a late 500 counted as a failed attempt and scheduled a retry. Each simple task now carries the entry's incarnation in its description and its task-map key. The incarnation is a random value minted when an entry is created or its body replaced, so every use of an id has its own. A task whose value differs from the entry's is dropped by the completion, the delayed begin, progress and the relaunch reconcile. Reconcile also prunes keys of earlier uses, so they no longer hold a relaunch wait. A task with no value comes from 11.3.0 or earlier. It still matches an entry that such a build created or saved, so a task in flight across the upgrade drives its entry and is not sent again. It does not match an entry created by this build (tasksCarryIncarnation), which is a later use. Also: a live task under a late-result key that is still the entry's current attempt (the re-issue after the wait was not saved) is adopted at relaunch instead of being cancelled and sent again. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The foreground replace and the late-result marking after the relaunch wait now check the task's use of the id, as the other readers do. A test shows that a retry this build makes for an entry from 11.3.0 begins and completes that entry. Docs: a request created before the upgrade keeps the old behavior until it settles. A launch also prunes a kept key when the id belongs to a newer request. Only the ack of a completed or cancelled outcome removes the row. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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.
iOS: a result from an earlier use of an id cannot change a later request with the same id
What was wrong
An app can use one request id again after its row is gone (the outcome was acknowledged, or the row was cancelled). Diana does this for every edit of one note. The new entry starts again at generation 1 and attempt 1. A simple task was matched to its entry only by id, generation and attempt, in its task description and its task-map key. So a task result that came late from the earlier use could match the new entry:
cancel(id)that landed anyway, a delayed task that began, a progress event before reconcile, and a live task at relaunch (it could be adopted in place of the new use's task).What changes
incarnationin its description and in its task-map key.incarnationalready exists on every entry: a random UUID made when the entry is created or its body is replaced, saved inentry.json. Chunked parts already carry it. So every use of an id has its own value, and it survives relaunches.Apple documents
taskDescriptionas an app string that the system does not interpret. Its page states no length limit and says nothing about whether the value survives a relaunch. So the value is in both places, as before: the description first, then the task-map key.Compatibility with tasks from older versions
A task started by 11.3.0 or earlier carries no value. The entry gets a new field,
tasksCarryIncarnation, set to true on every entry this build creates. An entry from an older build does not have it.Dropping every task with no value would be stricter, but then a task in flight during the upgrade would be cancelled or ignored and its request sent again. The rule above keeps that task and stops it from changing a later use.
Downgrade: 11.3.0 reads the new description (it ignores the new field), the new
entry.json(it ignorestasksCarryIncarnationand drops it at its next save), and the task map (no new field; 11.3.0 treats a key with no part index as a simple attempt). After a downgrade and upgrade, the entry has no flag, so tasks from 11.3.0 still match it.Tests
New file
ios/Tests/CoordinatorPerUseTests.swift:cancel(id)that lands later; a delayed begin; progress before reconcile; reconcile with both uses' tasks live; an old key and an old live task holding the relaunch wait; the failed re-issue save.Each part of the fix was broken on purpose. At least one test failed each time.
Android has the same class of problem through a different path (old journal records). It is not changed here.
An independent review was applied. Stacked on #83. Part of RAD-17385.
🤖 Generated with Claude Code