Skip to content

Preserve iOS Bot navigation and live permission ownership - #233

Merged
sambitcreate merged 4 commits into
feature/mobile-stream-recoveryfrom
feature/ios-bot-response-ownership
Sep 26, 2026
Merged

sambitcreate merged 4 commits into
feature/mobile-stream-recoveryfrom
feature/ios-bot-response-ownership

Conversation

@sambitcreate

@sambitcreate sambitcreate commented Sep 22, 2026 •

Copy link
Copy Markdown
Owner

Bot navigation can start duplicate chat loads through open and restoration. A delayed response or permission result could replace a newer transcript, publish an error after navigation, or restore mutation access after a policy downgrade.

Reserve cache authority before loading and tie continuations to the current navigation attempt. Keep the admitted cache winner in memory through disk failure and reject stale fallback after removal/purge. Permission completion preserves the current transcript and rechecks live write grants and notice policy; policy changes refresh permissions on the existing destination. Path changes invalidate ownership synchronously.

Stacked on PR217 ff777f5. This slice covers Bot navigation/permission responses; workspace rename/list response ownership remains assigned separately.

Validation: four XCTest methods cover held production GET ordering with disk failure/removal/purge, real navigation-store away/back ownership, held write/notice-policy downgrades, and a held create receipt that remains read-only pending live permission resolution. Generic iOS app/XCTest compilation passes;177 Android JVM tests, lint and instrumentation compilation pass; iOS policy31 Node tests plus20 Ruby tests/42 assertions pass. Both independent GPT-5.6 Sol medium final reviews are clear. Physical XCTest execution remains pending the unlocked, coordinated device slot; compiled regressions are not claimed as executed baseline reproductions.

Evidence: .memory/ios-bot-response-ownership.md. No merge, release or deployment.

Final exact-head acceptance

Head 0f94027e0666312b9724d08ea595104ae52779a8: hosted verify and Deterministic Electron E2E passed; Android hosted check skipped by changed-area detection. No unresolved review threads. Local generic iOS app/XCTest compilation, 177 Android JVM tests/lint/instrumentation compilation, and iOS policy checks passed; both independent GPT-5.6 Sol medium reviews clear. Combined integration c74195ccb also passed iOS compilation and157 host tests with both reviews clear (unchanged213 Android evidence retained). Physical XCTest/device acceptance remains unexecuted because the shared iPhone is locked. This is scoped Bot-response acceptance; workspace rename/Home response work remains assigned separately.

@pullfrog

pullfrog Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Run failed. View the logs →

Pullfrog  | Rerun failed job ➔ | View workflow run | via Pullfrog | Using GPT Luna | 𝕏

@very-hermes-bot very-hermes-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Inline review — 2 finding(s) anchored to the diff. See the pinned summary comment for the overview.


let cached = aidenAdmittedCachedBotChat(
await AidenChatCache.shared.loadChat(
let existing = chatsByScope[scope]?[chatID]?.chat

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P1 · logic] hydrateRestoredPath prematurely resets mutation access to false for existing presentations
Confidence: 0.92

When hydrateRestoredPath runs for an existing in-memory conversation, it unconditionally overwrites chatsByScope with allowsMutations: false before checking permissions; if offline or during a transient network error, mutations are left permanently disabled.

Repair: Only apply allowsMutations: false when existing == nil, preserving the existing presentation's mutation authorization during permission revalidation.

Comment on lines 1076 to 1078
var capturedContext: AidenRemoteRequestContext?
let attempt = presentationOwner.begin(instanceID: scope.instanceID, deviceID: scope.deviceID, chatID: chatID, fullAccessAllowed: fullAccessActionsAllowed())
do {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P1 · logic] hydrateRestoredPath disowns openConversation and triggers duplicate loads on user navigation
Confidence: 0.9

Tapping a conversation invokes openConversation which begins an attempt and sets path, triggering .task(id: restorationID) to run hydrateRestoredPath; hydrateRestoredPath unconditionally calls presentationOwner.begin, replacing current with a new attempt and invalidating openConversation midway through execution.

Repair: In hydrateRestoredPath, check if presentationOwner already has an active attempt matching the scope, chatID, and policy before calling begin, returning early if a load is already in flight.

@very-hermes-bot

very-hermes-bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

Hermes Review Bot

Confidence: 5

Engine: agy/gemini-3.8-flash-high
Review mode: full
Head: 51346457fda235781a53b91f5a9976a07c552e17
Generated: 2026-09-26T05:57:41+00:00
Reviews: 1

Summary

Guarantees response ownership and prevents stale concurrency races across iOS Bot navigation, live permission publication, workspace chat lists, rename patches, and home summary caching. Navigation attempts and continuations are owned through AidenBotPresentationOwner, which adopts in-flight opens under matching policies, invalidates stale callbacks synchronously on navigation changes, and preserves current transcripts while rechecking write grants and notice policy. Cache admission establishes in-memory winners ahead of disk IO, fences cleanup-era and post-purge disk fallbacks, and isolates temporary rename title overlays from canonical wire/cache encodings. Maintainers should double-check that Attempt instances created by user-initiated Bot opens remain adoptable only until their asynchronous execution scope exits (via defer { presentationOwner.finish(attempt) }), ensuring subsequent policy shifts or network reconnects correctly revalidate permissions on the active destination.

Confidence Score: 5/5

All changed Swift files, concurrency and actor isolation boundaries, cache clock synchronizers, view models, and 26 comprehensive regression tests were thoroughly traced end-to-end across lifecycle, navigation, and storage failure boundaries.

📁 Important Files Changed
  • ios/AidenOnTheGo/Features/Remote/AidenProductShellView.swift: Introduces AidenBotPresentationOwner to manage navigation attempt lifecycles, coordinate restoration adoption of in-flight opens, invalidate stale owners synchronously on path mutations, and enforce fail-closed permission revalidation across write and notice policy updates.
  • ios/AidenOnTheGo/Persistence/AidenChatCache.swift: Hardens cache admission with in-memory winners surviving disk IO failures, introduces summary write authority gating, separates pending rename title overlays (RenameTitle) from canonical chat records, and fences post-purge/post-deletion disk fallbacks.
  • ios/AidenOnTheGo/Features/Remote/AidenChatFeature.swift: Passes reserved write tokens into chat fetches and reconciliations, switches UI and Live Activities to displayTitle, requires coherent canonical reads prior to revisioned rename/remove, and admits workspace lists against newer detail owners.
  • ios/AidenOnTheGo/Features/Remote/AidenWorkspaceShellView.swift: Enforces token and row-level authority gating for home summary loads and continuations, preserves unacknowledged local edits across pagination, and verifies cursor consistency before merging continuation pages.
  • ios/AidenOnTheGo/Models/AidenChat.swift: Adds the presentation-only localTitleOverride and displayTitle properties excluded from Codable CodingKeys to prevent wire and canonical cache corruption.
  • ios/AidenOnTheGoTests/AidenChatTests.swift: Adds 26 unit and integration test methods covering held HTTP requests, out-of-order responses, away/back navigation, policy downgrades, simulated disk IO failures, and deletion/purge boundaries.
  • .memory/*.md: Records design context, review history, and verification evidence for Bot, Home, Workspace, and Rename response ownership slices.

Findings

No findings.

Sequence Diagram

sequenceDiagram
    autonumber
    actor User
    participant Shell as AidenBotShellView
    participant Owner as AidenBotPresentationOwner
    participant Server as Aiden Remote API
    participant Cache as AidenChatCache

    User->>Shell: Tap Bot conversation (openConversation)
    Shell->>Owner: begin(chatID, canWrite, fullAccessAllowed, adoptable: true)
    Shell->>Shell: path = [chatID] (updates navigation store & triggers restorationID)
    Shell-->>Shell: hydrateRestoredPath() runs (.task)
    Shell->>Owner: adoptsRestoration(chatID, canWrite, fullAccessAllowed)
    Owner-->>Shell: true (in-flight open adopted; duplicate load suppressed)
    Shell->>Server: GET /chats/{id}
    Server-->>Shell: Chat payload
    Shell->>Cache: saveChat(chat, writeToken)
    Shell->>Cache: admittedChat(id)
    Cache-->>Shell: Admitted winner
    Shell->>Server: GET /bots/{id} (check permissions)
    Server-->>Shell: Bot details & access mode
    Shell->>Owner: ownsPermission(attempt, currentCanWrite, fullAccessActionsAllowed())
    Owner-->>Shell: true (same policy preserved)
    Shell->>Shell: Publish Presentation.resolved (mutations enabled)
    Shell->>Owner: finish(attempt) (adoptable = false)
Loading
[]

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

…toration

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
@pullfrog

pullfrog Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Run failed. View the logs →

Pullfrog  | Rerun failed job ➔ | View workflow run | via Pullfrog | Using GPT Luna | 𝕏

4 similar comments
@pullfrog

pullfrog Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Run failed. View the logs →

Pullfrog  | Rerun failed job ➔ | View workflow run | via Pullfrog | Using GPT Luna | 𝕏

@pullfrog

pullfrog Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Run failed. View the logs →

Pullfrog  | Rerun failed job ➔ | View workflow run | via Pullfrog | Using GPT Luna | 𝕏

@pullfrog

pullfrog Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Run failed. View the logs →

Pullfrog  | Rerun failed job ➔ | View workflow run | via Pullfrog | Using GPT Luna | 𝕏

@pullfrog

pullfrog Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Run failed. View the logs →

Pullfrog  | Rerun failed job ➔ | View workflow run | via Pullfrog | Using GPT Luna | 𝕏

sambitcreate and others added 2 commits September 26, 2026 01:48
…#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)
…nership

Keep the base's absent-cache cursor retention alongside this branch's
row-scoped admission and disk-failure safeguards in saveChatSummaries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GAkZRgQzUoKWGpgupF3a4D
@sambitcreate
sambitcreate merged commit ccb6415 into feature/mobile-stream-recovery Sep 26, 2026
4 checks passed
sambitcreate added a commit that referenced this pull request Sep 26, 2026
* Fence Android chat reads and Home summary admission (#225)

* 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)

* Preserve iOS Bot navigation and live permission ownership (#233)

* 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

* test(mobile): cover #217 x #218 run controls on iOS and Android

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

* fix(ios): resolve the 9 failing AidenChatTests on #217

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

* fix(ios): superseded create/send read the admitted chat winner

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)

* fix(ios): keep a superseded or failed create's row in the durable list

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

* docs(memory): record the #217 follow-up carry onto main

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>
@sambitcreate
sambitcreate deleted the feature/ios-bot-response-ownership branch September 26, 2026 17:52
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