Skip to content

Carry remaining #217 mobile stream-recovery work onto main - #255

Merged
sambitcreate merged 9 commits into
mainfrom
feature/mobile-stream-recovery-followups
Sep 26, 2026
Merged

sambitcreate merged 9 commits into
mainfrom
feature/mobile-stream-recovery-followups

Conversation

@sambitcreate

Copy link
Copy Markdown
Owner

Carries the rest of #217 (mobile stream recovery, 0.50.0) onto main. #242 (squash 7033118) already contains #217 through 62fa352 plus its own repairs. These #217 commits were not on main, so they are cherry-picked here onto a fresh branch from main. This is not a reconciliation merge. #217 can be closed as superseded once this lands.

Carried commits (in order)

#217 commit Here What
1a3cd3e 215cef7 #225: fence Android chat reads and Home summary admission
ccb6415 1b693a2 #233: iOS Bot navigation, live permission, workspace/rename/Home response ownership
d41ad06 aab1fce #217 x #218 run-control tests (iOS and Android)
37b5920 4ddbcbb The 9 AidenChatTests fixes
eb2dc82 ed05a88 Superseded create/send read admittedChat
1ad6af1 ec4f3bb Keep a superseded or failed create's row in the durable list (Pullfrog)

49f8d90 (papercuts only) did not apply cleanly, so I skipped it.

Resolved against #242

Where #242 already fixed something, I kept #242's version and left the #217 copy out. Everything #242 didn't have is kept.

Verification

  • iOS build-for-testing (iPhone 17 Pro simulator) succeeded after every cherry-pick and after the --no-ff merge of the latest main.
  • Android testDebugUnitTest: 207/207 passed. lint is clean.
  • npm run test:ci-policy: 45/45 passed.
  • Simulator XCTest run pending. The AidenChatTests suite has not been run on this branch yet. The Mac has an authorization prompt waiting that blocks simulator test launch. The full AidenChatTests run (simulator only) will follow once that prompt is cleared.

Refs #217, #242.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GAkZRgQzUoKWGpgupF3a4D

sambitcreate and others added 8 commits September 26, 2026 07:51
* fix(android): fence deferred home cache writes

* fix(android): reject superseded cross-owner chat reads

* fix(android): order Home summary requests and pagination commits

* Preserve Android turn receipts across response ownership changes (#227)

* Preserve Android accepted turn receipts across response ownership changes

* Keep receipt merges under request authority in both completion orders

(cherry picked from commit 1a3cd3e)
* Own iOS Bot navigation responses and live permission publication

* fix(ios): keep in-flight Bot opens and same-policy grants through restoration

Restoration re-ran on an open's own path change and superseded it, and it
reset an already-presented chat's live mutation grant to false before
revalidating, leaving it disabled after a transient failure. Restoration now
adopts an in-flight open under identical inputs, and keeps a prior live grant
only when the write and notice policy are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GAkZRgQzUoKWGpgupF3a4D

* fix(ios): preserve newer detail state across workspace list responses (#234)

* fix(ios): admit workspace lists against newer detail owners

* fix(ios): preserve accepted rename titles and coherent chat revisions (#236)

* fix(ios): preserve rename receipts without replacing newer chat state

* Preserve authoritative list titles across detail hydration

* Fence iOS Home responses and preserve admitted row ownership (#238)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

(cherry picked from commit ccb6415)

Conflict resolution against #242: saveChats keeps #242's committed-write
ordering (older lists are partial companions, rows come from successful
detail commits, and the list token is the max). #233's in-memory list,
rename-title and fetch authority stay. The durable list extends only the
last admitted rows, so a detail whose disk write failed stays a memory-only
winner on the read path and never becomes a durable row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GAkZRgQzUoKWGpgupF3a4D
Integration coverage for the merged stream-recovery and acknowledged
run-control state machines:

- iOS: removal while a stop, approval response or approval snapshot is
  held cannot report, restore a card or re-read; URLError(.cancelled) on
  stop/approval leaves the run live without optimistic cancel or card
  resurrection, and a second Stop may retry.
- Android: unpair during a held stop or approval snapshot, and a dropped
  stop write that is not retried. #217 fixtures now encode the Mac wire
  shape (absent optionals omitted) so main's reasoning validator accepts
  them.

(cherry picked from commit d41ad06)

Conflict resolution against #242: #242 already added the cancelledControls
mode, its URLProtocol failure path and the load()-based mismatched-approval
delivery, so those duplicates were dropped. The cancelled Stop test now
follows #242's silent-cancellation rule (no "Stop was not confirmed").

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GAkZRgQzUoKWGpgupF3a4D
Executed on the iPhone 17 Pro simulator for the first time, the stacked
ownership changes exposed real interaction bugs with #217:

- Workspace list merges pulled a removed chat's later detail-only
  re-admission into a list reserved before the removal.
- Chat removal minted a fresh summary reservation and cleanup-era Home
  writes needed the full floor, so unrelated pending-era rows were lost.
  Removal keeps its deletion token; partial writes are row updates.

Test-only corrections: whole-second dates for ISO 8601 round trips,
create the cache root before blocking its chats directory, and assert
that a fresh detail re-admission owns its Home row (#238 projection).

(cherry picked from commit 37b5920)

Conflict resolution against #242: #242 already moved the cached-stream
check ahead of draft I/O in load(), so that duplicate was dropped. Its
committed-write ordering also admits an older create list's own row when
the create's detail committed after the omitting list, so create() no
longer needs the `!saveChats` fallback. admitCreatedWorkspaceChat stays
for the superseded and failed-write create paths carried next.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GAkZRgQzUoKWGpgupF3a4D
A superseded saveChat fell back to cache.loadChat, which reads disk only.
saveChat admits the winner in memory before its file write, so a failed
winner write left no file (row removed, stream startup aborted) or an
older snapshot (rebase onto stale data). Both sites now use
cache.admittedChat. Adds failed-write regression tests for both paths.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GAkZRgQzUoKWGpgupF3a4D
(cherry picked from commit eb2dc82)
After adopting the admitted winner, the superseded create branch (and the
detail disk-failure branch) returned before any workspace-list write, so a
failed detail write with a writable list cache lost the created row on an
offline cold reopen. Both branches now call admitCreatedWorkspaceChat,
which also accepts a newer detail winner only while that winner is newer
than the list token, so later removal, purge and newer list omissions win.

(cherry picked from commit 1ad6af1)

Adjusted for #242: the helper extends the admitted list rows themselves,
not the merged memory view, so only the created chat (not other chats'
memory-only detail winners) becomes a durable row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GAkZRgQzUoKWGpgupF3a4D
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GAkZRgQzUoKWGpgupF3a4D

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

The Bot owner can cancel an unrelated selected chat, and rename completion can republish a row omitted by a newer list. Please resolve these races and close the documented iOS runtime-test gap before merging.

Reviewed changes I reviewed the 19-file diff at feb1726d, covering Android chat and Home cache admission, iOS Bot/Workspace/Home response ownership, rename reconciliation, and the integration regressions.

  • Android response admission Request-origin tokens and retained in-memory winners fence stale chat, summary, and turn-receipt writes across owners, removal, and purge.
  • iOS navigation and permissions Bot open/restoration ownership and live policy checks are integrated with the shared conversation presentation path.
  • Workspace persistence Rename receipts use a durable title overlay rather than replacing newer transcript state; create/send fallbacks retain the admitted winner.
  • Regression coverage New held network/cache schedules cover receipts, pagination, run controls, rename/list races, deletion, and write failures.

⚠️ iOS runtime coverage is pending on this integrated head

The PR description reports iOS build-for-testing but says AidenChatTests has not executed on this branch. Compile-only verification does not exercise the held actor/network schedules added by this integration; please run the simulator suite on this head before merging.

Technical details
# Verify integrated iOS schedules on simulator

## Affected sites
- `ios/AidenOnTheGoTests/AidenChatTests.swift` contains newly added held HTTP/cache regressions.
- The PR description reports `build-for-testing` passed but says simulator XCTest execution is pending.

## Required outcome
- Execute the iOS test suite on exact head `feb1726d` and report the result before merging.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using GPT Luna | 𝕏

let deviceID = deepLinkedDeviceID,
presentationScope == PresentationScope(instanceID: instanceID, deviceID: deviceID) else { return }
let scope = PresentationScope(instanceID: instanceID, deviceID: deviceID)
presentationOwner.invalidate()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] A permission result for the retained deep link can invalidate a different chat's in-flight load. Once the access notice is accepted, the deep-link Bot lookup can still be pending while this callback runs; it invalidates the shell-wide owner even when another chat is selected. That chat's continuation then exits, and restorationID does not change for this result, so the UI can remain on its skeleton or read-only state.

Technical details
# Preserve the selected Bot presentation

## Affected sites
- `ios/AidenOnTheGo/Features/Remote/AidenProductShellView.swift:896` invalidates the global presentation owner for every deep-link permission change.
- `ios/AidenOnTheGo/Features/Remote/AidenProductShellView.swift:998-1004` and `:1194-1200` publish only while the current attempt owns that owner.
- `ios/AidenOnTheGo/Features/Remote/AidenProductShellView.swift:902-903` keys restoration by `restorationID`, which does not include the deep-link permission result.

## Required outcome
- A permission update for a non-selected deep link must not cancel an unrelated selected chat; changes relevant to the selected chat must trigger validation against its current policy.

guard await cache.reconcileWorkspaceChat(admitted, instanceId: instanceId, authority: origin, cutoff: receiptCutoff) else { return }
let publicationGeneration = presentationGenerations[chat.id] ?? 0
guard let presentation = await cache.presentedWorkspaceChat(instanceId: instanceId, workspaceId: workspaceId, chatId: chat.id) else { return }
guard coordinator.isCurrent(context), publicationGeneration == (presentationGenerations[chat.id] ?? 0), cache.isChatWriteRetained(origin, instanceId: instanceId, chatId: chat.id) else { return }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] A newer authoritative list can omit this chat after the cache read but before this continuation publishes. load() updates chats without advancing this model's presentationGenerations, and isChatWriteRetained only fences removal/purge, so this guard can still pass and upsert can re-add the omitted row. Recheck current admitted workspace-list authority after the await before publishing, including the refresh path.

Technical details
# Do not republish a row omitted by a newer list

## Affected sites
- `ios/AidenOnTheGo/Features/Remote/AidenChatFeature.swift:813-814` guards and publishes the rename receipt presentation.
- `ios/AidenOnTheGo/Features/Remote/AidenChatFeature.swift:825-826` has the same gap after rename refresh.
- `ios/AidenOnTheGo/Features/Remote/AidenChatFeature.swift:724-735` admits and publishes a fetched authoritative list without advancing the per-chat presentation generation.

## Required outcome
- A rename continuation must not publish a chat when a later admitted authoritative list has omitted it.

let value = RenameTitle(instanceId: instanceId, chatId: receipt.id, title: newerListTitle ?? receipt.title)
renameTitles[instanceId, default: [:]][receipt.id] = PendingRename(value: value, origin: origin, cutoff: titleCutoff)
retiredRenameTitles[instanceId]?.remove(receipt.id)
try? save(value, to: fileURL(kind: "rename-titles", instanceId, receipt.id))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] A failed sidecar write can drop the only durable copy of a successful rename title. If a newer detail winner has already made this PATCH receipt ineligible to replace the canonical chat, try? hides failure to persist the title overlay; after relaunch, the old detail/list title is shown offline. Keep the receipt title durable through an admitted cache representation or surface and repair this persistence failure.

Technical details
# Retain a successful title when its canonical receipt is stale

## Affected sites
- `ios/AidenOnTheGo/Persistence/AidenChatCache.swift:599` ignores failure to write the `rename-titles` record.
- `ios/AidenOnTheGo/Persistence/AidenChatCache.swift:601-605` can retain a newer canonical detail winner instead of the PATCH receipt.
- `ios/AidenOnTheGo/Models/AidenChat.swift:973-975` keeps the presentation-only title out of canonical cache/wire encoding.

## Required outcome
- When the canonical chat is newer than the PATCH receipt, failure to persist its title overlay must not silently leave restart-time Workspace/detail presentation with the pre-rename title.

@very-hermes-bot

very-hermes-bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Collaborator

Hermes Review Bot

Confidence: 5

Engine: agy/gemini-3.8-flash-high
Review mode: full
Head: 759f278f36c817c4a1615096af118643f023d53d
Generated: 2026-09-26T15:48:56+00:00
Reviews: 1

Summary

Remaining stream-recovery capabilities from #217 are ported cleanly onto main, integrating the latest cache admission fencing, response ownership handoffs, and UI presentation overrides across both iOS and Android. The architecture establishes strict fencing around chat reads, turn receipt overlays, and purge operations, ensuring out-of-order network responses or local disk read failures cannot corrupt in-memory or durable chat state. Durable workspace list membership correctly extends only admitted workspace list rows rather than intermediate memory winners, maintaining the persistence invariants established in #242. Presentation-only overrides (such as local title edits) remain decoupled from Codable disk models while projecting consistently across workspace views, Home summaries, and Live Activities.

Confidence Score: 5/5

Full confidence: the complete diff and all modified Swift and Kotlin source files were traced end-to-end across UI, view models, actors/coroutines, cache write clocks, and serialization boundaries. Every core path aligns with the design memory contracts (.memory/mobile-stream-recovery.md, .memory/mobile-response-ownership.md), and behavioral invariants are reinforced with comprehensive unit test coverage on both native platforms.

📁 Important Files Changed
  • apps/ios/Aiden/Features/Chat/AidenChatCache.swift: Governs actor-isolated disk and memory caching for iOS chats, enforcing monotonic write clocks, memory winner promotion, and turn receipt overlay retirement upon authoritative server reconciliation.
  • apps/ios/Aiden/Features/Chat/AidenChatFeature.swift: Manages active chat lifecycle, navigation attempt ownership, live permission checking (noticeGate), and stream attachment recovery.
  • apps/ios/Aiden/Features/Chat/AidenChat.swift: Introduces presentation-only localTitleOverride (excluded from serialization keys) and surfaces unified displayTitle for UI and Live Activity projections.
  • apps/android/app/src/main/java/com/aiden/agent/AidenChatCache.kt: Thread-safe Android chat cache coordinating reservation tokens, turn overlay merges, stream marker persistence, and purge fencing.
  • apps/android/app/src/main/java/com/aiden/agent/AidenChatViewModel.kt: Implements Android turn-receipt reconciliation, response stream recovery, run cancellation safeguards, and navigation handoffs.
  • apps/android/app/src/main/java/com/aiden/agent/AidenWorkspaceHomeViewModel.kt: Fences workspace Home chat summaries against unadmitted reads, maintaining parity with iOS workspace chat models.

Findings

No findings.

📊 Sequence Diagram
sequenceDiagram
    autonumber
    actor User
    participant ViewModel as ChatViewModel / Feature
    participant Cache as ChatCache (Actor / Mutex)
    participant Disk as Local File Storage
    participant Server as Aiden Backend (SSE / HTTP)

    User->>ViewModel: Send Message / Prompt
    ViewModel->>Cache: reserveWriteToken(chatId)
    Cache-->>ViewModel: token #T1
    ViewModel->>Cache: mergeTurnReceiptOverlay(token #T1, pendingTurn)
    Cache->>Disk: Persist unconfirmed snapshot
    
    par Stream Execution
        ViewModel->>Server: POST /chat/stream
        Server-->>ViewModel: SSE Stream Events (turn #T1)
        ViewModel->>Cache: recordStreamMarker(chatId, sequence)
    and Authoritative Refresh
        ViewModel->>Server: GET /chat/{id}
        Server-->>ViewModel: Authoritative Chat Details
        ViewModel->>Cache: presentedChat(chatId, serverChat, throughToken: #T1)
        Note over Cache: Retires overlays <= #T1<br/>Preserves overlays > #T1<br/>Updates memory winner
        Cache->>Disk: Persist reconciled snapshot
    end

    Cache-->>ViewModel: Admitted Reconciled Chat
    ViewModel-->>User: Render updated UI & localTitleOverride
Loading

Machine-Readable Findings

[]

Last reviewed commit: 759f278f36c8
Reviews (1) · Comment /hermes review to trigger a new review · /hermes review full for full re-review

Android startTurn keeps #225's installation, client and receipt fences and
adopts main's selected-skill and pending-question resets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GAkZRgQzUoKWGpgupF3a4D

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No new issues found in this incremental change. Existing review threads remain open and are outside this delta.

Reviewed changes I re-reviewed the merge commit added after feb1726d, focusing on Android's accepted-turn flow.

  • Turn receipt admission Moved successful turn handling behind installation-retention checks, admitted the receipt through the shared cache, and started streaming only from the admitted stream.

Pullfrog  | Fix it ➔ | View workflow run | Using GPT Luna | 𝕏

@sambitcreate
sambitcreate merged commit 0e07bfe into main Sep 26, 2026
22 checks passed
@sambitcreate
sambitcreate deleted the feature/mobile-stream-recovery-followups branch September 26, 2026 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants