Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(swift-ios): skip validated stale detail replay #10762

Closedsaphid(GitHub profile, opens in a new tab)wants to merge 250+ commits intot3code/rebuild-mobile-app-swift fromrefs/pull/10762/headopened View on GitHub

Review this layer

GitHub shows this PR against t3code/rebuild-mobile-app-swift, so its diff includes every earlier PR in the chain. Review only this layer's change:

This layer's diff: +123 / −2 lines across 2 files; app code +12 / −2, the rest is tests and docs.

Replayed detail events needlessly reduce already-applied state. Validate the shared event envelope and owning thread before skipping stale sequences, preserving malformed/foreign-event handling. This avoids replay reduction; no measured phone speedup is claimed.

Verification: all current-head GitHub checks pass, including contract fixtures and native tests. Skipped checks are not claimed as executed proof.

The completion fixture repair is carried from #10759. Current-head native CI passes.

Delivery: stacked. This branch contains #10758, #10759, #10761; merge the chain in order (#10758 → #10759 → #10761 → #10762 → #10763 → #10764 → #10765 → #10766 → #14021 → #10767). Each PR's own change is its top commit(s).

Base: Theo’s t3code/rebuild-mobile-app-swift, 157476f1fb.

Verification scope: Both stale-detail regressions passed on this head: preserve newer messages/explicit markers, and skip reduction only after envelope validation. This proves replay handling; no measured phone speedup is claimed. The native CI job linked above contains the passing receipts. The tests exercise the protocol, state, or accessibility-value boundary changed here.

Independent cross-provider review was unavailable: claude auth status returned exit 1 with loggedIn: false. No Claude review or maintainer approval is claimed.

Refresh onto 157476f1fb (2026-09-27)

Rebased with the thread-sync chain onto the current t3code/rebuild-mobile-app-swift (157476f1fb). Head dca56985ba.

  • Focused tests at this layer, measured before the review fixes below (NativeMultiEnvironmentTests, NativeThreadCatchUpTests, NativeRetryIdentityTests, FeatureRootModelTests, iOS Simulator, per-test time limits): 87 XCTest + 100 Swift Testing passed.
  • Full T3CodeTests at the chain top (68d92c2752): 343 XCTest cases passed (1 skipped). Swift Testing ran 892 tests; the only 2 failures are UsageModelsTests currency formatting, which fail identically on unmodified 157476f1fb.
  • Independent review: devin -p --sandbox --permission-mode smart --model swe-2-max over the whole chain diff, exit 0. No blocker, high or medium findings. A dead-state finding was fixed. A report that Stop state outlives a vanished thread was not changed, because stopSurvivesCloseReopenAndMissingReconnectSeed requires that behaviour.

Follow-ups (minor, not blocking)

  • Upstream's refreshThread replaces the active page with its initial-page snapshot when its read lands after an older-page load. Detaching the send refresh (#10758) moves that window rather than creating it. Invalidating the refresh on a history-epoch change would close it.
  • Overlapping adoptEnvironment calls: an older one can cancel aggregate workers started by a newer one before returning at its bootstrap guard; the next adoption or aggregate refresh restarts them (Macroscope).

Model and harness: GPT-6 / Codex. Rebase onto 157476f1fb: Claude Opus 5.5 / Claude Code.

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This diff is a large Swift runtime refactor that changes foreground hydration, passive environment streaming, retry timing, background lifecycle, outbox presentation, and stale-response handling. The unresolved refresh-history and worker-cancellation concerns, together with changed product defaults, warrant human review.

      Not approved because:

      • 2 blocking correctness issues found at or above your repo's Minimum Blocking Severity
      Adjust the Minimum Blocking Severity for this repo — including turning it Off — in [Settings](https://app.macroscope.com/pingdotgg/settings#Repos). You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. Bugbot is paused — on-demand spend limit reached

      Bugbot uses usage-based billing for this team and has hit its on-demand spend limit.

      A team admin can raise the spend limit in the Cursor dashboard, or wait for the next billing cycle to continue.

    4. @t3dotgg Could you review this SwiftUI reliability/performance fix? It will skip validated stale detail replay before reduction. It does not change the visible interface. This is a dependent PR; prerequisites: #10759. Its diff includes those prerequisites and needs rebasing after they land.

    5. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium Root/FeatureRootModel.swift:1756

      A newly created task can lose its accepted initial prompt after createThreadAndSend succeeds: the optimistic queued detail records its message ID in serverMessageIDs, so completeQueuedSubmission treats it as already present on the server and does not retain a delivered copy. If the next older transcript omits that turn, store replaces the detail without the prompt. Record only non-queued message IDs in serverMessageIDs.

      No longer relevant as of 7a9d0dec6a3563513077c6bf9b61222ae4d1fc61

      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium Root/FeatureRootModel.swift:1538

      Accepted messages disappear after their thread detail is evicted if the server transcript has not caught up yet. removeDetail clears deliveredAwaitingDetail, so reopening the thread loads neither the queued nor delivered copy; keep delivered messages when evicting detail, while retaining explicit cleanup for removed threads.

      No longer relevant as of 7a9d0dec6a3563513077c6bf9b61222ae4d1fc61

    6. @@ -2280,0 +2498,21 @@
      2498+ private func scheduleAcceptedCommandRefresh(
      2499+ threadID: String, client: T3Client, generation: Int, refreshDetail: Bool = true
      2500+ ) {
      2501+ guard isKnownClient(client, environmentID: client.environment.id, generation: generation) else {
      2502+ return
      2503+ }
      2504+ if let current = acceptedCommandRefreshes[threadID],
      2505+ current.client === client, current.generation == generation {
      2506+ acceptedCommandRefreshes[threadID]?.pending = true
      2507+ acceptedCommandRefreshes[threadID]?.needsDetail = current.needsDetail || refreshDetail
      2508+ return
      2509+ }
      2510+ cancelAcceptedCommandRefreshes(threadID: threadID)
      2511+ let id = UUID()
      2512+ let task = Task { [weak self] in
      2513+ while self?.isCurrentAcceptedCommandRefresh(threadID: threadID, id: id) == true {
      2514+ let needsDetail = self?.acceptedCommandRefreshes[threadID]?.needsDetail == true
      2515+ self?.acceptedCommandRefreshes[threadID]?.needsDetail = false
      2516+ self?.acceptedCommandRefreshes[threadID]?.pending = false
      2517+ if needsDetail {
      2518+ try? await self?.refreshThread(id: threadID, client: client) { [weak self] in
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium App/NativeFeatureClient.swift:2518

      The detached refreshThread started at line 2518 can overwrite a page loaded by loadEarlierThreadTurns: its initial-page snapshot replaces activeRawThread and activeThreadPage, dropping the prepended older messages and pagination state after sendMessage has returned. Cancel or invalidate this refresh when threadHistoryEpoch changes, or merge its result without discarding paginated history.

      🤖 Copy this AI Prompt to have your agent fix this:
      In file @apps/swift-ios/App/NativeFeatureClient.swift around line 2518:
      
      The detached `refreshThread` started at line 2518 can overwrite a page loaded by `loadEarlierThreadTurns`: its initial-page snapshot replaces `activeRawThread` and `activeThreadPage`, dropping the prepended older messages and pagination state after `sendMessage` has returned. Cancel or invalidate this refresh when `threadHistoryEpoch` changes, or merge its result without discarding paginated history.

      Not changing in this PR. Upstream's refreshThread already replaces the active page with its initial-page snapshot when its read lands after an older-page load; detaching the send refresh moves that window rather than creating it, and the window is one thread read. Listed as a follow-up (invalidate on history epoch).

      Sorry, I'm unable to act on this request because you do not have permissions within this repository.

    7. Fixed in #10758 (fix(swift-ios): keep accepted messages across eviction and local details): LRU eviction keeps retained delivered messages (it now clears only the transcript ID cache). Test: evictedDetailKeepsItsDeliveredMessageOnReopen fails without the fix.

    8. Sorry, I'm unable to act on this request because you do not have permissions within this repository.

    9. Fixed in #10758 (fix(swift-ios): keep accepted messages across eviction and local details): only server transcripts record confirmed message IDs now; restored-outbox and pending-creation details are stored as local. Test: startedTaskKeepsItsPromptUntilTheServerIncludesIt fails without the fix.

    10. Sorry, I'm unable to act on this request because you do not have permissions within this repository.

    11. @@ -971,3 +1160,4 @@
      9711160 _ environment: Environment,
      9721161 client newClient: T3Client
      9731162 ) async {
      1163+ cancelAggregateRefresh()
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium App/NativeFeatureClient.swift:1163

      An older adoptEnvironment invocation can cancel aggregate refresh workers started by a newer invocation, then return at the bootstrapID guard, leaving passive environments without background shell/catalog refreshes. Move cancelAggregateRefresh() below that guard so a stale adoption cannot tear down the current workers.

      🤖 Copy this AI Prompt to have your agent fix this:
      In file @apps/swift-ios/App/NativeFeatureClient.swift around line 1163:
      
      An older `adoptEnvironment` invocation can cancel aggregate refresh workers started by a newer invocation, then return at the `bootstrapID` guard, leaving passive environments without background shell/catalog refreshes. Move `cancelAggregateRefresh()` below that guard so a stale adoption cannot tear down the current workers.

      Acknowledged as a narrow ordering between overlapping adoptEnvironment calls; the next adoption or aggregate refresh restarts the workers. Listed as a follow-up rather than changed in this stack.

      Sorry, I'm unable to act on this request because you do not have permissions within this repository.

    12. @t3dotgg this is ready for your review and merge.

      Merge order: stacked chain, merge in order: #10758 → #10759 → #10761 → #10762 → #10763 → #10764 → #10765 → #10766 → #10767. #12655 (composer focus freeze) is independent and can merge at any time.

      Evidence at head dca56985ba:

      • CI: all checks pass on this head.
      • Full T3CodeTests at the chain top (70258b6a6b, iOS Simulator): 343 XCTest cases passed (1 skipped). Swift Testing ran 892 tests; the only 2 failures are UsageModelsTests currency formatting, which fail identically on unmodified 157476f1fb.
      • Each review fix has a focused regression test that fails without the fix, except where the description says why not.
      • An earlier build of this chain (before the review rounds) fixed the stuck-send behaviour on a physical iPhone, as confirmed by the user. The current heads have not been re-verified on a device.

      Independent review: No layer-specific Astra review. Covered by the SWE-2 Max review of the whole chain (exit 0, no blocker/high/medium findings).

      Macroscope findings on the latest heads have been verified against the source: real ones are fixed, and the rest have a written reason and are listed under Follow-ups in the description.

    13. Note

      This comment is posted by Julius' dot

      The stale-replay fast path is focused, but the current comparison also contains the hydration and command-recovery stack. Which of those changes are required for this optimization? Please isolate it or explain the dependency under the one problem rule.

    14. Note

      🤖 GPT-6.1-Sol responding on behalf of Theo

      Applied the focused fix to t3code/rebuild-mobile-app-swift in e4eaa597ab. Closing this source PR after the port.

      The source branch includes old rewrite history that conflicts with the current target. Only the intended fix and its focused tests were carried over.

      The combined focused native checks passed: 241 tests, one existing skip, no failures.

Sign in to join this conversation.