Skip to content

Fix desktop conversation session and mutation races - #9371

Merged
Git-on-my-level merged 3 commits into
mainfrom
codex/conversation-session-hardening
Jul 10, 2026
Merged

Git-on-my-level merged 3 commits into
mainfrom
codex/conversation-session-hardening

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Jul 10, 2026 •

Copy link
Copy Markdown
Member

Summary

  • reject detail, mutation, delete, and cache work that belongs to a reset/account session
  • serialize remote edits and deletes per conversation while keeping title, star, and folder changes instantly optimistic
  • settle fields by operation UUID so sibling, duplicate, cyclic, refreshed, failed, and cancelled edits cannot erase newer intent
  • keep conversation cache admission session-aware without blocking the main actor on SQLite work
  • route the desktop star automation action through the repository exactly once

This preserves the high-value hardening that remained after #9354 landed, supersedes the now-closed #9365, and is a focused follow-up to #8197.

Failure cases covered

  • old-account detail/mutation/delete acknowledgements after reset
  • reset while a detail cache write is suspended before transaction admission
  • overlapping title + star success and partial failure
  • duplicate and A → B → A title operations, including a refresh reflecting the older A
  • two queued failures rolling back to the last confirmed value
  • delete racing an in-flight mutation
  • transport cancellation and cancellation while queued
  • older canonical revisions and active-filter removal
  • automation double-call/invalid async routing regression

Verification

  • xcrun swift test --package-path Desktop --filter 'ConversationRepositoryTests|ConversationReconciliationPolicyTests|DesktopAutomationSecondaryActionTests' — 57 passed
  • OMI_SWIFT_TEST_SUITE_WORKERS=4 ./scripts/swift-test-suites.sh — 184 suites passed in isolated processes
  • every desktop/macos/tests/test-*.sh launcher/shell test passed
  • strict desktop E2E flow coverage passed for all changed production Swift files
  • repository pre-push hook passed, including a clean desktop Swift compile
  • launched the ad-hoc-signed omi-conversation-races named bundle and exercised the real set_conversation_starred semantic action; the cold signed-out profile returned the expected safe no conversations available failure
  • independent subagent review iterated through concurrency, refresh, delete, storage, and cancellation findings and approved the final diff with no remaining findings

Risk

No API, schema, or migration changes. The behavioral change is limited to conversation cache/session admission and repository-owned mutation ordering. Optimistic UI remains immediate; only remote acknowledgement order is serialized per conversation.

Review in cubic

Avoid the duplicate direct API plus repository mutation path and keep the automation action on the same optimistic reconciliation path as the UI.\n\nVerified: xcrun swift test --package-path Desktop --filter 'DesktopAutomationSecondaryActionTests'
Fence cache writes by account session, serialize per-conversation mutations and deletes, and settle optimistic fields by operation identity so overlapping, duplicate, refreshed, failed, or cancelled edits preserve the latest user intent.\n\nVerified: 57 focused conversation/automation tests; 184 Swift XCTest suites via scripts/swift-test-suites.sh with 4 workers; all desktop tests/test-*.sh scripts; strict desktop E2E flow coverage; named omi-conversation-races bundle launch and semantic star action failure path. Independent subagent review approved with no remaining findings.
@Git-on-my-level

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 33021538d8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

try Task.checkCancellation()
try ensureCurrentSession(session)
let canonical = try await remotely()
try Task.checkCancellation()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Apply successful mutations despite later cancellation

For any caller that cancels a repository mutation task after the PATCH has already completed, this post-response check sends the code into the cancellation rollback path even though the server side effect succeeded. That leaves the UI/cache showing the old value until a later refresh while the server has committed the new title/star/folder state; cancellation should be checked before sending the mutation, not after receiving the canonical response.

Useful? React with 👍 / 👎.

}
}

try ensureCurrentSession(session)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Honor cancellation before queued deletes

When a delete is queued behind an active mutation, acquireMutationSlot can suspend; if the delete task is cancelled during that wait, this path still proceeds to remote.delete because it only checks the session generation. In that cancelled-while-queued case the app can delete a conversation after the caller abandoned the operation, so add a cancellation check after acquiring the slot and before issuing the remote delete.

Useful? React with 👍 / 👎.

@Git-on-my-level

Copy link
Copy Markdown
Member Author

@cursor resolve merge conflicts and address review comments

@cursor

cursor Bot commented Jul 10, 2026 •

Copy link
Copy Markdown

Merge conflicts are resolved and both Codex P2 review comments are addressed.

Merge conflicts resolved

  • DesktopAutomationBridge.swift — kept main's multi-line setStarred call (same behavior as our branch)
  • DesktopAutomationSecondaryActionTests.swift — kept main's test name and assertion messages

Review comments addressed

1. Apply successful mutations despite later cancellation (ConversationRepository.swift)

Removed the post-response Task.checkCancellation() after the remote PATCH returns. Cancellation is still checked before sending the mutation, so queued/in-flight abandonment still rolls back optimistic UI — but a successful server write is no longer undone by a late caller cancel.

2. Honor cancellation before queued deletes

Added try Task.checkCancellation() in delete() after acquiring the mutation slot and before remote.delete, so a delete cancelled while waiting behind an in-flight mutation does not hit the server.

Regression tests added

  • testSuccessfulMutationCommitsCanonicalStateDespiteCallerCancellationAfterRemote
  • testDeleteCancelledWhileQueuedDoesNotCallRemote

Pushed

Commit f3f6616ee is on codex/conversation-session-hardening. Swift tests could not run on this Linux VM; please verify on macOS with:

xcrun swift test --package-path Desktop --filter 'ConversationRepositoryTests|DesktopAutomationSecondaryActionTests'
Open in Web Open in Cursor 

Resolve automation bridge merge conflicts and fix conversation mutation
cancellation handling:

- apply successful remote mutations even if the caller cancels after the
  PATCH completes, instead of rolling back committed server state
- honor cancellation after a queued delete acquires the mutation slot and
  before issuing the remote delete

Add regression tests for both cases.

Co-authored-by: David Zhang <[email protected]>
@Git-on-my-level
Git-on-my-level merged commit 906e37b into main Jul 10, 2026
17 checks passed
@Git-on-my-level
Git-on-my-level deleted the codex/conversation-session-hardening branch July 10, 2026 02:54
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