Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(swift-ios): reconcile silent selected-thread streams #10763

Closedsaphid(GitHub profile, opens in a new tab)wants to merge 14 commits intot3code/rebuild-mobile-app-swift fromrefs/pull/10763/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: +1257 / −42 lines across 3 files; app code +192 / −27, the rest is tests and docs.

A healthy socket can stop delivering selected-thread events. Reconcile only the foreground selected transcript after 30 seconds without actual detail progress, defer to existing recovery owners, and validate selection and generation before applying results. Retain loaded messages, activities and checkpoints when a capped recovery page cannot cover them; use authoritative fallback rather than unioning stale cached history.

Verification: current-head CI passes, including contract fixtures and native tests. The final bootstrap/environment run passed 38 tests, covering environment switching, error visibility and archive hydration; separate focused checks cover passive-worker lifetime. Skipped checks are not claimed as executed proof.

Delivery: stacked. This branch contains #10758, #10759, #10761, #10762; 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: Native selected-reconciliation tests passed in CI before the repair and in the combined local verification, including the actual default deadline (30.080 seconds), progress postponement, cancellation in background, navigation rejection of held responses, and authoritative recovery of truncated history. The measured deadline is from the CI Simulator fixture, not a phone responsiveness benchmark. 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 8ef7e74c91.

  • Focused tests at this layer, measured before the review fixes below (NativeMultiEnvironmentTests, NativeThreadCatchUpTests, NativeRetryIdentityTests, FeatureRootModelTests, iOS Simulator, per-test time limits): 110 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.
  • Test fixtures now mark running threads through session.status, which upstream uses as the only source of the working state.

Follow-ups (minor, not blocking)

  • After a failed environment catalog read, a config event updates the cache but skips that publish; it reaches the UI on the next snapshot publish (Macroscope).
  • The missing-reply repair reloads the initial page, dropping older pages loaded before it (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 PR is a large synchronization and lifecycle refactor that changes active/passive environment hydration, WebSocket ownership, optimistic message handling, and selected-thread recovery across existing iOS paths. Its production blast radius and unresolved medium-severity findings require human review.

      Not approved because:

      • 3 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 reconcile selected-thread streams that silently stop progressing. It does not change the visible interface. This is a dependent PR; prerequisites: #10761, #10758, #10759. Its diff includes those prerequisites and needs rebasing after they land.

    5. @@ -4057,6 +4492,15 @@
      4057- continue
      4058- }
      4059- let passiveIDs = Set(passiveEnvironments.map(\.id))
      4060- failureBackoffs = failureBackoffs.reduce(into: [:]) { result, entry in
      4061- guard passiveIDs.contains(entry.key) else { return }
      4062- result[entry.key] = max(.zero, entry.value - elapsedInterval)
      4492+ guard owns(environment) else { return }
      4493+ state.isLive = false
      4494+ // A read begun before the stream lost completeness cannot
      4495+ // repair that gap, even if the socket identity is unchanged.
      4496+ state.authorityRevision &+= 1
      4497+ markStreamPaused(environment)
      4498+ state.requestRepair()
      4499+ do { try await streamRetrySleep(environment.id, failureInterval) } catch { return }
      4500+ }
      4501+ }
      4502+
      4503+ func markStreamPaused(_ environment: Environment) {
      4504+ guard let owner, owns(environment) else { return }
      4505+ owner.shellConnectionIDsByEnvironmentID[environment.id] = nil
      4506+ owner.environmentConnectionStates[environment.id] = .reconnecting
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium App/NativeFeatureClient.swift:4506

      markStreamPaused changes a passive environment from .needsPairing back to .reconnecting when the concurrent followShell subscription fails. After refreshShell marks rejected credentials with credentialRejected: true, this generic recovery path hides the pairing state in Settings and continues retrying the unusable credential. Preserve .needsPairing and stop the worker's recovery path instead of calling requestRepair for that environment.

      🤖 Copy this AI Prompt to have your agent fix this:
      In file @apps/swift-ios/App/NativeFeatureClient.swift around line 4506:
      
      `markStreamPaused` changes a passive environment from `.needsPairing` back to `.reconnecting` when the concurrent `followShell` subscription fails. After `refreshShell` marks rejected credentials with `credentialRejected: true`, this generic recovery path hides the pairing state in Settings and continues retrying the unusable credential. Preserve `.needsPairing` and stop the worker's recovery path instead of calling `requestRepair` for that environment.

      Fixed further up the stack in #10764 (fix(swift-ios): share a peer's credential rejection with its live stream): markStreamPaused keeps Needs pairing for a rejected peer and a new stream snapshot no longer wakes the HTTP loop (test livePeerRejectedCredentialStopsReconciling). The chain merges in order.

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

      @@ -3982,8 +4241,5 @@
      39824241 case .unrelated:
      39834242 continue
      39844243 }
      3985- if let shell = self.latestShell {
      3986- await self.emitSnapshot(
      3987- shell, client: activeClient, expectedGeneration: generation
      3988- )
      3989- }
      4244+ // A failed catalog read skips this publish; later events still apply.
      4245+ guard let environments = try? await self.runtime.environments() else { continue }
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium App/NativeFeatureClient.swift:4245

      A transient failure from runtime.environments() causes this configuration event to skip publish, so the updated providers or settings remain cached but no FeatureSnapshot reaches the UI. Unlike the previous emitSnapshot path, the continue leaves the configuration stream idle until an unrelated later event publishes a snapshot; retain a fallback publication path when the environment lookup fails.

      🤖 Copy this AI Prompt to have your agent fix this:
      In file @apps/swift-ios/App/NativeFeatureClient.swift around line 4245:
      
      A transient failure from `runtime.environments()` causes this configuration event to skip `publish`, so the updated providers or settings remain cached but no `FeatureSnapshot` reaches the UI. Unlike the previous `emitSnapshot` path, the `continue` leaves the configuration stream idle until an unrelated later event publishes a snapshot; retain a fallback publication path when the environment lookup fails.

      Intentional trade-off from the #10761 fix: previously a failed catalog read ended the whole configuration subscription. Now it skips one publish, and the cached config reaches the UI on the next snapshot publish. Listed as a follow-up (retry that publish).

      @@ -5290,0 +6089,21 @@
      6089+ rawThread.latestTurn?.completedAt == completed.completedAt,
      6090+ rawThread.messages.contains(where: {
      6091+ $0.role == "assistant" && $0.turnId == completed.turnId && !$0.streaming
      6092+ }),
      6093+ !rawThread.messages.contains(where: {
      6094+ $0.role == "assistant" && $0.turnId == completed.turnId && $0.streaming
      6095+ }) {
      6096+ flushDetailPublish(route)
      6097+ return
      6098+ }
      6099+
      6100+ // Equal-cursor completion may flush final content, but only a newer
      6101+ // shell can prove that detail is missing and require HTTP repair.
      6102+ guard sequence > (activeThreadSequence ?? .min) else { return }
      6103+
      6104+ // Keep rendered partial text while requiring a snapshot that includes
      6105+ // the shell's completion. Later detail events advance this same floor.
      6106+ flushDetailPublish(route)
      6107+ activeRawThread = nil
      6108+ activeThreadSequence = sequence
      6109+ scheduleDetailRefresh(threadID: threadID, client: route.client, force: true)
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium App/NativeFeatureClient.swift:6109

      When a shell completion exposes a missing detail event after the user loaded older pages, this recovery drops those pages and resets the pagination window. repairMissingCompletedTurn clears activeRawThread and calls the ordinary forced refreshThread path, which uses only initialThreadUserTurnLimit and replaces activeThreadPage; schedule this through the reconciliation path so the loaded history extent is retained.

      🤖 Copy this AI Prompt to have your agent fix this:
      In file @apps/swift-ios/App/NativeFeatureClient.swift around line 6109:
      
      When a shell completion exposes a missing detail event after the user loaded older pages, this recovery drops those pages and resets the pagination window. `repairMissingCompletedTurn` clears `activeRawThread` and calls the ordinary forced `refreshThread` path, which uses only `initialThreadUserTurnLimit` and replaces `activeThreadPage`; schedule this through the reconciliation path so the loaded history extent is retained.
      saphid(GitHub profile, opens in a new tab)commented

      Acknowledged: the missing-reply repair (#10759) reloads the initial page, so older pages loaded before it are dropped and can be loaded again. Listed as a follow-up.

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

    6. @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 8ef7e74c91:

      • 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.

    7. Note

      This comment is posted by Julius' dot

      The new 30-second HTTP reconciliation loop changes recovery ownership and how authoritative history replaces cached pages. This substantial recovery change has no linked maintainer-triaged issue or approved scope. Please establish that direction under the prior approval rule, then request reconsideration.

    8. juliusmarminge closed this

Sign in to join this conversation.