Docs native: read the catch-up cursor before the request suspends
#147 re-review finding 2. `let since = sequence` ran after the fetch's await. settleParking takes since == 0 to mean the reply holds the server's whole state. So a concurrent refresh that set the cursor to 0 mid-fetch could make a partial catch-up settle and accept parking. The cursor is now captured once, before the request, and used for both the URL and settling.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+4
−2
native/apple/Sources/DocsKit/DocsModel.swift+4 −2
diff --git a/native/apple/Sources/DocsKit/DocsModel.swift b/native/apple/Sources/DocsKit/DocsModel.swift| index 80e1e74..1aa523a 100644 |
| --- a/native/apple/Sources/DocsKit/DocsModel.swift |
| +++ b/native/apple/Sources/DocsKit/DocsModel.swift |
| @@ -534,10 +534,12 @@ import RastrilloNative |
| return |
| } |
| do { |
| - let reply = try await client().responseDetails("/d/\(sqid)/updates?since=\(sequence)", maxBytes: 8 * 1024 * 1024) |
| + // The cursor this request fetches from, read before it suspends: |
| + // settleParking takes 0 to mean the reply is the whole state. |
| + let since = sequence |
| + let reply = try await client().responseDetails("/d/\(sqid)/updates?since=\(since)", maxBytes: 8 * 1024 * 1024) |
| guard reply.status == 200, let seq = Int64(reply.header("Docs-Seq") ?? "") else { throw CRDTReplica.Failure.rejected } |
| guard self.detail?.sqid == sqid, self.replica === replica else { return } |
| - let since = sequence |
| do { _ = try await replica.apply(reply.data) } |
| catch { |
| guard self.detail?.sqid == sqid, self.replica === replica else { return } |