Skip to content

Add conversation key fetch and send-problem recovery - #108

Merged
santiagomed merged 55 commits into
mainfrom
cursor/conversation-keys-1d8a
Dec 6, 2026
Merged

santiagomed merged 55 commits into
mainfrom
cursor/conversation-keys-1d8a

Conversation

@santiagomed

@santiagomed santiagomed commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Lets an app that sends without loading message history get the conversation key from GET /2/chat/conversations/:id/keys, and recover when a send fails because that key is out of date or a recipient's key changed. This is in Rust, JS/WASM (browser and server), Python, Go, JVM, .NET, and Ruby.

What the app does

  • Registers a hook with set_resolve_conversation_keys (createChat({ resolveConversationKeys }) in JS, ResolveConversationKeys in .NET). The SDK calls it with a REST conversation id (100-200 for 1:1, g… for groups) and the key versions it needs ([] means latest).
  • Or passes the API response to add_conversation_keys. The SDK checks each signed encoded_event before it caches the key.
  • On a cold cache, send and decrypt_events use that hook to fetch the missing key. In JS and .NET this is the async send path, for example encryptMessageAsync.
  • Calls recover_send after a send problem:
    • conversation_key_out_of_date: loads a newer conversation key and returns reencrypt, so the app re-encrypts and retries.
    • recipient_key_changed: refreshes participant public keys, prepares a rotated key change, and returns rotate_key with key_change to publish before retrying.

Example (JavaScript)

const chat = await createChat({
  resolveConversationKeys: async (conversationId, keyVersions) => {
    const qs = keyVersions.length ? `?key_versions=${keyVersions.join(",")}` : "";
    const resp = await api.get(`/2/chat/conversations/${conversationId}/keys${qs}`);
    return resp.data ?? [];
  },
});

// Cold cache: the hook fetches the latest conversation key.
const payload = await chat.encryptMessageAsync({ conversationId: "100:200", text: "hello" });

// Send failed because the conversation key is out of date.
const recovery = await chat.recoverSendAsync({
  conversationId: "100:200",
  problem: "conversationKeyOutOfDate",
});
if (recovery.action === "rotateKey") {
  // POST recovery.keyChange to /2/chat/conversations/{id}/keys first.
}
const retried = await chat.encryptMessageAsync({ conversationId: "100:200", text: "hello" });
Open in Web Open in Cursor 

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ santiagomed
❌ github-actions[bot]
You have signed the CLA already but the status is still pending? Let us recheck it.

@cursor cursor Bot changed the title Add conversation key fetch and send-problem recovery across all bindings Add conversation key fetch and send-problem recovery Dec 4, 2026
@tcaldwell-x
tcaldwell-x self-requested a review December 5, 2026 01:39
santiagomed and others added 28 commits December 5, 2026 02:51
Accept historical pre-v6 conversation key changes in add_conversation_keys
for decrypt-only backfill (matching x-android and inline decrypt_events),
while keeping v6+ strict for sending and recover_send:

- Track send_eligible per cached key entry so decrypt-only pre-v6 keys
  are never selected for sends, needs_conversation_key, or high-water
  advancement.
- Verify pre-v6 1:1 key changes against stored signing keys and reject
  tampered/untrusted signatures; keep pre-v6 group key changes decrypt-only.
- Track per-conversation earliest verified sequence_id per v6+
  signature_version (populated from both inline decrypt_events and
  add_conversation_keys / recover_send) to reject newer-sequence
  signature-version downgrades across batches while allowing older
  backfill.
- Add regression tests for pre-v6 group and 1:1 backfill, send/recovery
  exclusion, and downgrade floor enforcement.
- Remove stale, lineage, banner, and narrating comments across core, FFI,
  Go, Python, and WASM bindings and tests.
- Add symmetric JSDoc comments across async send/file/group helpers in
  crates/wasm/js/chat.js and document intentional fallback suppression in
  crates/pyo3/python/chat_xdk/__init__.py.
@santiagomed
santiagomed merged commit 35df9ab into main Dec 6, 2026
36 of 37 checks 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.

4 participants