oficina / base Public

Read Ask's state afresh outside the stream it replaces

The load-generation fix (finding 3) made a refused stream's reload a
no-op: the stream's own task ran load(), which stops the stream and so
cancelled the task it ran in, and the load then saw itself cancelled.
The stream now starts the reload as a task of its own.
EventsTests.testReconnectsFromTheLastIDAndReloadsOnRefusal caught it;
fd23da0 was pushed with that test failing.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 31833506512867d27aa4cc4854cb495fcc2e76f1 parent fd23da0
1 file changed, +6 −2
  • native/apple/Sources/BaseKit/Ask/AskModel.swift +6 −2
diff --git a/native/apple/Sources/BaseKit/Ask/AskModel.swift b/native/apple/Sources/BaseKit/Ask/AskModel.swift
index 05b2034..7000eb5 100644
--- a/native/apple/Sources/BaseKit/Ask/AskModel.swift
+++ b/native/apple/Sources/BaseKit/Ask/AskModel.swift
@@ -202,10 +202,10 @@ import Observation
failures = min(failures + 1, 6)
try? await Task.sleep(for: .seconds(2 * failures))
guard self.generation == epoch, !Task.isCancelled else { return }
- await self.load()
+ self.reload()
return
default:
- await self.load()
+ self.reload()
return
}
}
@@ -217,6 +217,10 @@ import Observation
private var retryMilliseconds = 3000
private func retryAfter(_ ms: Int) { retryMilliseconds = ms }
+ /// Reads the state afresh from outside the stream's own task, which
+ /// the load cancels as it stops the stream.
+ private func reload() { Task { await self.load() } }
+
private func receive(_ event: AskEvent, id: Int64?, epoch: Int) {
guard generation == epoch else { return }
if let id { cursor = id }