Skip to content

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
dylan/ios-late-result-winsfrom
dylan/ios-per-use-value
Open

dmurphy5 wants to merge 3 commits into
dylan/ios-late-result-winsfrom
dylan/ios-per-use-value

Conversation

@dmurphy5

@dmurphy5 dmurphy5 commented Nov 17, 2026 •

Copy link
Copy Markdown

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:

  • A late 2xx completed the new entry with the old response and cancelled its task. The new body was then never sent.
  • A late 4xx failed the new entry.
  • A late 500 counted as a failed attempt of the new entry and scheduled a retry while its real task still ran.
  • The same happened through a task cancelled by a late win or by 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).
  • A key of the earlier use stayed while the id was in use, and held the next relaunch wait for 10 s.
sequenceDiagram
  participant D as iOS daemon
  participant L as Library
  Note over L: Use 1: task T1 (id a, gen 1, att 1)
  L->>L: use 1 settles, ack, row forgotten
  L->>D: use 2: task T2 (id a, gen 1, att 1)
  D-->>L: late 2xx from T1
  Note over L: before: matches use 2, completes it, cancels T2
  Note over L: now: T1's incarnation differs, the result is dropped
Loading

What changes

  • Each simple task now carries the entry's incarnation in its description and in its task-map key. incarnation already exists on every entry: a random UUID made when the entry is created or its body is replaced, saved in entry.json. Chunked parts already carry it. So every use of an id has its own value, and it survives relaunches.
  • The completion, the delayed-begin hook, the progress hook, the relaunch reconcile and the foreground replace drop a task whose value differs from the entry's.
  • Reconcile removes the task-map keys of earlier uses. The relaunch wait counts only keys of the current use.
  • Also: when the relaunch wait gave up on a task and the next attempt could not be saved, the entry stayed on that attempt. If the task was still running at the next launch, it was cancelled and the request sent again. Now it is adopted, because it may have sent the body already.

Apple documents taskDescription as 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.

  • A request created before the upgrade keeps the old behavior until it settles. It accepts any task with no value that has its id, generation and attempt. So its own task in flight during the upgrade completes it, and the request is not sent again. A late result from an even earlier use of the id, also started by the old version, can still change it, as before. This change does not close that window.
  • Tasks this build makes for such a request carry the value and drive it as usual.
  • A task with no value does not match an entry this build created. Such a task can only come from an earlier use.

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 ignores tasksCarryIncarnation and 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:

  • 12 behavior tests. Each one failed before this change: a late 500, 2xx and 4xx from an earlier use; the same with the earlier use's key still there; a task cancelled by a late win or by 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.
  • 5 compatibility tests: an 11.3.0 task (literal description, no value in the key or the entry) that is live after the upgrade, one that finishes after the upgrade, one that fails and whose retry from this build begins and completes the entry, one that reports after the id is used again, and the 11.3.0 decoders reading what this build writes.

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

dmurphy5 and others added 3 commits November 17, 2026 17:57
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>
@dmurphy5
dmurphy5 added this pull request to stack #87 November 17, 2026 23:19
@dmurphy5 dmurphy5 changed the title dylan/ios per use value RAD-17385 iOS: a result from an earlier use of an id cannot change a later request with the same id Nov 17, 2026
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