Skip to content

fix: reconcile conversations with server authority - #8344

Merged
Git-on-my-level merged 5 commits into
BasedHardware:mainfrom
Git-on-my-level:fix/issue-8197-conversation-reconciliation
Jun 25, 2026
Merged

Git-on-my-level merged 5 commits into
BasedHardware:mainfrom
Git-on-my-level:fix/issue-8197-conversation-reconciliation

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Jun 25, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Adds a pure desktop ConversationReconciliationPolicy for cache-first/server-refresh list merging.
  • Makes server list responses authoritative for non-pending fields so stale SQLite cache rows cannot permanently mask backend-updated status, summary, title, folder, or starred state.
  • Tracks short-lived successful local title/star/folder mutations as explicit pending overlays until the server list catches up.
  • Preserves only true local in-progress rows that have not appeared in the backend yet.

Oracle

Test plan

  • git diff --check
  • xcrun swiftc -parse desktop/macos/Desktop/Sources/ConversationReconciliationPolicy.swift desktop/macos/Desktop/Sources/AppState.swift desktop/macos/Desktop/Tests/ConversationReconciliationPolicyTests.swift
  • xcrun swift test --package-path desktop/macos/Desktop --filter ConversationReconciliationPolicyTests — 6 tests passed

Refs #8197

Review in cubic

@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: 73cf5f1dce

ℹ️ 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".

@Git-on-my-level

Copy link
Copy Markdown
Member Author

Addressed the review comment.

Fix:

  • Pending conversation mutation overlays now carry recordedAt and expire after a bounded TTL (default 120s).
  • Once expired, the server value wins and the pending overlay is removed, so a cross-device newer title/star/folder value cannot be masked forever if this client never observes its own optimistic value.
  • New regression test covers the superseded-value case.

Verification:

git diff --check
xcrun swiftc -parse desktop/macos/Desktop/Sources/ConversationReconciliationPolicy.swift desktop/macos/Desktop/Sources/AppState.swift desktop/macos/Desktop/Tests/ConversationReconciliationPolicyTests.swift
xcrun swift test --package-path desktop/macos/Desktop --filter ConversationReconciliationPolicyTests
# 7 tests passed

@cubic-dev-ai cubic-dev-ai 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.

1 issue found across 3 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

@Git-on-my-level

Copy link
Copy Markdown
Member Author

Addressed the new cubic review comment.

Fix:

  • Pending mutation TTL cleanup now runs across the entire pending-mutation map before list reconciliation, not only for IDs present in the latest server list.
  • This drops expired overlays for conversations missing from the response, preventing unbounded stale pending state.
  • Added regression coverage for an expired pending mutation whose conversation is absent from the server response.

Verification:

git diff --check
xcrun swiftc -parse desktop/macos/Desktop/Sources/ConversationReconciliationPolicy.swift desktop/macos/Desktop/Tests/ConversationReconciliationPolicyTests.swift
xcrun swift test --package-path desktop/macos/Desktop --filter ConversationReconciliationPolicyTests
# 8 tests passed

@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: 191319afbb

ℹ️ 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".

Git-on-my-level added a commit to Git-on-my-level/omi that referenced this pull request Jun 25, 2026
Previously a single  timestamp governed the entire pending
mutation struct.  A later star or folder mutation refreshed that shared
timestamp, keeping an older title overlay alive past its intended TTL
and masking fresher server values.

Replace the single  with per-field timestamps
(, , ) and add
 that evaluates each overlay independently.
Callers use typed setters (setTitle/setStarred/setFolderId) that stamp
only their own timestamp.

Adds two tests that verify:
- A later star change does NOT refresh an older title overlay's TTL.
- When all fields are expired the mutation entry is fully removed.

Addresses PR BasedHardware#8344 review thread PRRT_kwDOLkKqys6MIJ26.
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Per-field TTL for pending conversation overlays

The review correctly identified that a single recordedAt timestamp on ConversationPendingMutation caused later star/folder mutations to refresh the TTL of an older title overlay (and vice-versa).

Fix: Replaced the shared recordedAt with per-field timestamps (titleRecordedAt, starredRecordedAt, folderIdRecordedAt). Each field now has its own TTL clock started by a typed setter (setTitle, setStarred, setFolderId). The mergeList expiration loop calls expireFields(now:ttl:) which independently evaluates each overlay field.

Verification:

  • git diff --check — clean
  • swiftc -parse — clean
  • xcrun swift test --filter ConversationReconciliationPolicyTests — 10/10 passed (8 existing + 2 new)
  • New testLaterStarMutationDoesNotRefreshOlderTitleOverlayTTL directly exercises the reported scenario

@Git-on-my-level

Copy link
Copy Markdown
Member Author

@cursor resolve merge conflicts for me and do another round of review/fix

Previously a single  timestamp governed the entire pending
mutation struct.  A later star or folder mutation refreshed that shared
timestamp, keeping an older title overlay alive past its intended TTL
and masking fresher server values.

Replace the single  with per-field timestamps
(, , ) and add
 that evaluates each overlay independently.
Callers use typed setters (setTitle/setStarred/setFolderId) that stamp
only their own timestamp.

Adds two tests that verify:
- A later star change does NOT refresh an older title overlay's TTL.
- When all fields are expired the mutation entry is fully removed.

Addresses PR BasedHardware#8344 review thread PRRT_kwDOLkKqys6MIJ26.
@Git-on-my-level
Git-on-my-level force-pushed the fix/issue-8197-conversation-reconciliation branch from c20d758 to 534d0ff Compare June 25, 2026 19:08
@Git-on-my-level

Copy link
Copy Markdown
Member Author

Rebased this PR onto current upstream main and resolved the AppState conversation-count/reconciliation conflict.

Follow-up fix from verification:

  • Preserved transcriptSegmentsIncluded when rebuilding ServerConversation during reconciliation, matching the current upstream initializer.

Verification:

  • git diff --check → passed
  • xcrun swift test --package-path desktop/macos/Desktop --filter ConversationReconciliationPolicyTests → 10 tests passed

@Git-on-my-level
Git-on-my-level merged commit fe5b5fb into BasedHardware:main Jun 25, 2026
1 check passed
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.

1 participant