fix(collab): re-derive content key on collection updates — deliver rotated keys to members (HIGH #173) - #175
Merged
Merged
Conversation
…r rotated keys to members (HIGH #173) A member derived its per-KB content key ONCE, at join/share/enable. On subsequent kbc: collection broadcasts, handle_kbc_membership_broadcast relearned the epoch but never re-derived the content key, so the network task's content_keys (seal + open) was frozen at first derive. Consequences: - 3c rotation was broken for remaining members: after the owner rotated to k', members kept the old k — couldn't open k'-sealed content, sealed their edits under the stale k → divergence after any membership change. - Wrap-on-admit for a member who already joined never reached their seal/open path. - Subsumes #169 M2 (concurrent rotations converge once both deltas merge + re-derive). Fix: - KbCryptoCtx gains kb_collections: per-KB full collection replicas, seeded at join/share/enable, advanced by inbound kbc: deltas. - New refresh_kb_content_key_on_collection_delta: on a kbc: delta, advance the replica and RE-DERIVE content_keys via derive_kb_content_key (+ persist), wired into both inbound sync_update paths. No-op for non-kbc / unseeded / unencrypted (a plain KB is undisturbed). - Rotation handler now registers the find_wrapped winner derived from the post-rotation collection (the #169 M2 single-source-of-truth fix), not the locally-generated k2. Test (principle #14, the rotation-delivery oracle): refresh_kb_content_key_re_derives_on_rotation_remaining_yes_removed_no — a REMAINING member re-derives k' on the rotation delta; the REMOVED member stays stranded on the old k. 116 collab_bridge tests green; clippy clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
cuttlefisch
force-pushed
the
fix/e2e-content-key-refresh
branch
from
June 27, 2026 19:01
5870342 to
1bf9ca5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #173. Subsumes #169 M2. Found during the M2 investigation — broader + more severe.
Bug
A member derived its per-KB content key once (join/share/enable). On subsequent
kbc:collection broadcasts,handle_kbc_membership_broadcastrelearned the epoch but never re-derived the content key — the network task'scontent_keys(seal + open) was frozen at first derive. So:k', members kept the oldk: couldn't openk'-sealed content, sealed their edits under stalek→ divergence after any membership change.The data layer was correct (
find_wrapped_content_keyreturnsk'— tested); the gap was collab-bridge wiring.Fix
KbCryptoCtxgainskb_collections— per-KB full collection replicas, seeded at join/share/enable, advanced by inboundkbc:deltas.refresh_kb_content_key_on_collection_delta: on akbc:delta, advance the replica + re-derivecontent_keys(+ persist), wired into both inboundsync_updatepaths. No-op for non-kbc:/ unseeded / unencrypted KBs (a plain KB is undisturbed).find_wrappedwinner derived from the post-rotation collection (the M2 single-source-of-truth fix), not the locally-generatedk2.Test (principle #14 — rotation-delivery oracle)
refresh_kb_content_key_re_derives_on_rotation_remaining_yes_removed_no: a REMAINING member re-derivesk'on the rotation delta; the REMOVED member stays stranded on the oldk. 116 collab_bridge tests + fullcargo test -p maegreen; clippy clean.release:none.🤖 Generated with Claude Code