oficina / base Public

Native: the event stream's loop in a method, so the release build compiles

Summary

Swift 6.4.2 crashes in its release optimiser (CopyPropagation) on AskModel.listen's task closure, which rebound a weak self with guard let self inside an awaiting loop. The loop body is now streamRound(epoch:failures:), called with a strong reference held only for one round, so behaviour is unchanged. swift build -c release --product BaseMac completes; check-native.sh 107 tests pass.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev ffd4fd5708b78c1d467927eb8175aea96ff3a71e parent 3bcec1e
1 file changed, +36 −25
  • native/apple/Sources/BaseKit/Ask/AskModel.swift +36 −25

CI passed — run details

CI log
=== build ===
CGO_ENABLED=0 go build ./...
=== vet ===
go vet ./...
=== fmt-check ===
=== staticcheck ===
go run honnef.co/go/tools/cmd/staticcheck@v0.7.0 ./...
=== govulncheck ===
go run golang.org/x/vuln/cmd/govulncheck@v1.8.0 ./...
No vulnerabilities found.
=== gitleaks ===
9:50PM INF Unknown SCM platform. Use --platform to include links in findings. host=amadan.net
9:50PM INF 1 commits scanned.
9:50PM INF scanned ~2380772 bytes (2.38 MB) in 336ms
9:50PM INF no leaks found
=== budget ===
go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget size
budget size: 22 directories within budget
=== script-test ===
scripts/prepare-apps_test.sh
ok   releases lookup failure stops before ship
ok   app owned elsewhere stops the script
ok   apps listing failure stops before create
ok   ambiguous release dir is refused
ok   explicit version resolves the ambiguity
ok   releases match is exact, not substring
ok   shipped version is only promoted, existing app not created
ok   fresh account creates, ships, promotes to edge, enables
ok   failing promote stops the script
ok   ship is retried while uploads are rate limited
all passed
hack/fonts_test.sh
fonts_test: ok
=== test ===
go run amadan.net/rastrillo/rastrillo/cmd/rastrillo budget test -count=1 ./...

receipt: test step 7.606s against a 60s target (the gate's other steps are not in this figure)
receipt: 16 packages ran, 0 cached, 6 without tests, 0 failed
receipt: slow package 6.535s amadan.net/oficina/base/internal/webtest
receipt: slow package 1.07s amadan.net/oficina/base/internal/issuer
receipt: slow package 583ms amadan.net/oficina/base/internal/operations
receipt: slow package 200ms amadan.net/oficina/base/internal/consumer
receipt: slow package 163ms amadan.net/oficina/base/internal/web
receipt: slow test 1.51s amadan.net/oficina/base/internal/webtest TestHomeDoesNotWaitOnAStalledSnapshot
receipt: slow test 1.1s amadan.net/oficina/base/internal/webtest TestAskZoneIsToldOnce
receipt: slow test 810ms amadan.net/oficina/base/internal/issuer TestAuthorizeSignsForInstalledApp
receipt: slow test 520ms amadan.net/oficina/base/internal/operations TestOperationsRefusals
receipt: slow test 230ms amadan.net/oficina/base/internal/issuer TestAuthorizeRefusals
=== native ===
strings: copy review's strings.json is not here (git-ignored); its comparison skipped
strings: 119 in the catalog, 116 used
worktree-lib_test: ok
diff --git a/native/apple/Sources/BaseKit/Ask/AskModel.swift b/native/apple/Sources/BaseKit/Ask/AskModel.swift
index ef3f312..e676daa 100644
--- a/native/apple/Sources/BaseKit/Ask/AskModel.swift
+++ b/native/apple/Sources/BaseKit/Ask/AskModel.swift
@@ -229,32 +229,43 @@ import SwiftUI
let epoch = generation
stream = Task { [weak self] in
var failures = 0
+ // Each round holds the model only while it runs; between rounds
+ // the task keeps no strong reference. (A helper method rather than
+ // `guard let self` in this loop: Swift 6.4.2's release optimiser
+ // crashes on the latter, in CopyPropagation.)
while !Task.isCancelled {
- guard let self, self.generation == epoch else { return }
- let client = self.client
- do {
- try await client.events(after: self.cursor, onRetry: { [weak self] ms in await self?.retryAfter(ms) }) { [weak self] event, id in
- await self?.receive(event, id: id, epoch: epoch)
- }
- failures = 0
- guard self.generation == epoch, self.phase.chatting else { return }
- try? await Task.sleep(for: .milliseconds(max(500, self.retryMilliseconds)))
- } catch {
- guard self.generation == epoch, !Task.isCancelled else { return }
- switch error as? BaseAPIError ?? .badResponse {
- case .unauthenticated:
- return
- case .offline:
- failures = min(failures + 1, 6)
- try? await Task.sleep(for: .seconds(2 * failures))
- guard self.generation == epoch, !Task.isCancelled else { return }
- self.reload()
- return
- default:
- self.reload()
- return
- }
- }
+ guard let model = self else { return }
+ guard await model.streamRound(epoch: epoch, failures: &failures) else { return }
+ }
+ }
+ }
+
+ /// One connection to the event stream. Returns whether to keep going.
+ private func streamRound(epoch: Int, failures: inout Int) async -> Bool {
+ guard generation == epoch else { return false }
+ let client = self.client
+ do {
+ try await client.events(after: cursor, onRetry: { [weak self] ms in await self?.retryAfter(ms) }) { [weak self] event, id in
+ await self?.receive(event, id: id, epoch: epoch)
+ }
+ failures = 0
+ guard generation == epoch, phase.chatting else { return false }
+ try? await Task.sleep(for: .milliseconds(max(500, retryMilliseconds)))
+ return true
+ } catch {
+ guard generation == epoch, !Task.isCancelled else { return false }
+ switch error as? BaseAPIError ?? .badResponse {
+ case .unauthenticated:
+ return false
+ case .offline:
+ failures = min(failures + 1, 6)
+ try? await Task.sleep(for: .seconds(2 * failures))
+ guard generation == epoch, !Task.isCancelled else { return false }
+ reload()
+ return false
+ default:
+ reload()
+ return false
}
}
}