Skip to content

Move double ratchet storage operations to PrivateV1#82

Merged
kaichaosun merged 5 commits intomainfrom
private-store
Apr 10, 2026
Merged

Move double ratchet storage operations to PrivateV1#82
kaichaosun merged 5 commits intomainfrom
private-store

Conversation

@kaichaosun
Copy link
Copy Markdown
Contributor

Why this changes?

Based on the previous discussion, we want to put the store operations inside each module out of context, as each module has more knowledge on how to deal with storage.

What changes:

  • add store dependency in PrivateV1
  • load private v1 convo from store
  • persist private v1 vonvo
  • save ratchet state in handle message and handle frame
  • clear context

Copy link
Copy Markdown
Collaborator

@jazzz jazzz left a comment

Choose a reason for hiding this comment

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

Overall Love the direction here. Conversations becoming more autonomous.

Few comments around further clean up, and simplification.

Approved assuming the Justfile Pebble is cleaned up.

}

impl PrivateV1Convo {
impl<S: ConversationStore + RatchetStore> PrivateV1Convo<S> {
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.

[Dust] Creating an empty supertrait bound, would make the code easier to follow along, and easier to maintain.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have think about introduce a new trait to wrap the two traits here, but it would introduce too many traits since there will be other convo, and some of the traits is likely to be changed in near future.

Comment on lines +108 to +112
pub fn new_responder(
seed_key: SymmetricKey32,
dh_self: &PrivateKey,
store: Rc<RefCell<S>>,
) -> Self {
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.

[Sand] store should come before the other parameters.

Parameters should be ordered most-stable to least-stable. Such as:
self — the actor
context/deps — what the actor needs to function (an allocator, a fmt handle) — rarely changes between calls
the main data — the thing being transformed or inspected
options/flags — tweaks to the operation
output buffer — where to write results, if not returned directly

Comment on lines -97 to +96
let convo_id = self.persist_convo(&convo)?;
let convo_id = convo.persist()?;
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.

If conversations know how to persist themselves, whats the advantage to calling persist externally from the context? Seems like its separating storage responsibilities across two different layers.

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.

Specifically, this would call persist regardless of whether the state needs to be updated. Removing persist from Conversation Trait would mean that clients didn't manage internal state at all.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Looks like a good idea, will refactor it later to keep this RP small.
There is a lot of discussion spaces around here, like clean up state when error happens, and how to resume for error scenarios, etc. Such requirements will be much clear when MVPs start releasing.

Comment thread core/conversations/src/context.rs Outdated
/// Loads a conversation from DB by constructing it from metadata + ratchet state.
fn load_convo(&self, convo_id: ConversationId) -> Result<Conversation, ChatError> {
/// Loads a conversation from DB by constructing it from metadata.
fn load_convo(&self, convo_id: ConversationId) -> Result<Conversation<T>, ChatError> {
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.

[Dust] T implies that this Conversation has is an operand type. Better off choosing, S for Store or Store for Store, as there will be more Generic parameters.

Comment thread .gitignore Outdated
Comment on lines +34 to +35

justfile
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.

[Pebble] Can you exclude this instead. This project may have justfiles in the future which would cause a conflict.

Copy link
Copy Markdown
Contributor Author

@kaichaosun kaichaosun Apr 9, 2026

Choose a reason for hiding this comment

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

If the project include justfile in the future, remove it then.
I have been using justfile for this project heavily, not ignore it makes the git commit flow really bad.

Copy link
Copy Markdown
Collaborator

@jazzz jazzz Apr 9, 2026

Choose a reason for hiding this comment

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

not ignore it makes the git commit flow really bad.

I asked if you could use git exlcude instead.

@kaichaosun kaichaosun merged commit 9cc7362 into main Apr 10, 2026
4 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.

2 participants