Skip to content

fix(id): replicate signed ProseMirror save revisions to peers (#792) - #1830

Merged
dezren39 merged 2 commits into
mainfrom
queue/2655-792-id-sync-serve
Oct 29, 2026
Merged

dezren39 merged 2 commits into
mainfrom
queue/2655-792-id-sync-serve

Conversation

@dezren39

@dezren39 dezren39 commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Implementation for #792 from queue task 2655 (Lane A shift): save revisions are signed and stored locally; this change adds their replication to peers.

Process note: the lane shift timed out after committing and pushing (e86742f) but before opening this PR. Opened by the operator to complete the handoff; the task is parked on this PR for CI. Review and merge proceed through the normal lane shepherd flow.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

Serve opens the web layer's LocalEvents store once and shares the single
Arc<Mutex<LocalEvents>> between the web state and a new /id-sync/1
range-sync handler (event_sync::EventSyncProtocol), so ProseMirror save
revisions published into that store are in the sync set carried to
peers — and revisions arriving by sync are in the history the web UI
reads. A background loop offers a session to each discovered peer every
30s. Sessions run the existing event_store::sync::sync_over; arriving
events are decided by the store's own ingest, so tampered or unsigned
events are refused. The pull gate is PullPolicy::Open, the documented
default; serve reads no per-world policy yet.

Two-node tests in event_sync: a save published on node A is
discoverable in node B's history after one session, and a second
session between equal stores sends nothing.
@dezren39
dezren39 requested a review from a team as a code owner October 28, 2026 21:21
@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 18 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2c391f27-f75e-46e4-b67a-5031607dd0b6
Commits

Reviewing files that changed from the base of the PR and between 528886e and 83e35ff.

Files selected for processing: 6
  • pkgs/id/src/commands/serve.rs
  • pkgs/id/src/event_store/sync.rs
  • pkgs/id/src/event_sync.rs
  • pkgs/id/src/lib.rs
  • pkgs/id/src/local_events.rs
  • pkgs/id/src/web/mod.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T22:35:03.475983Z 83e35ff New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@dezren39

Copy link
Copy Markdown
Member Author

Status note (operator): the Lane A shift that produced this branch timed out mid-debugging. Its last checkpoint: the dialer side sends, but the accepting side's sync_session never applies the event within 60s - the acceptor path (EventSyncProtocol::accept / sync_over responder / EventStore::ingest rejection) was still under investigation, and its logs only surface at debug level. Treat this PR as work-in-progress: task 2655 is parked with that checkpoint, and the resuming lane picks up the acceptor-side debug from there. CI results on the current head are evidence about a partial implementation, not a finished fix.

@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: e86742ffe7

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

Comment thread pkgs/id/src/event_sync.rs
.sync_session(&conn, true, SESSION_DEADLINE, gate)
.await
};
conn.close(0_u32.into(), b"done");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Wait for remote receipt before closing the sync connection

When the initiator has new revisions and the accepting node has nothing to send, sync_session can return after buffering outgoing records and receiving the peer's zero count, before the peer has read those records. The underlying sender in event_store/sync.rs calls send.finish() without awaiting delivery or a completion acknowledgment. Closing the connection immediately can discard pending records, so a successful outcome can leave the peer without the saved revisions. Add a remote-completion handshake before closing; the existing lower-level loopback tests avoid this race by waiting for both sessions to finish.

Useful? React with 👍 / 👎.

Comment thread pkgs/id/src/event_sync.rs
Comment on lines +135 to +138
let mut events = events.lock().await;
events
.sync_session(&conn, true, SESSION_DEADLINE, gate)
.await

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Prevent competing sessions from locking both nodes

When two serve nodes dial each other concurrently, each outgoing session can acquire its local store mutex while the corresponding incoming handler waits for that same mutex. Both outgoing sessions then wait for remote handlers that cannot run until the 60-second session deadlines expire, also blocking web saves behind those locks. The new serve loop independently dials every discovered peer, so this can occur during normal operation. Elect one initiator per peer pair or restructure synchronization so competing sessions cannot hold the stores while waiting on each other.

Useful? React with 👍 / 👎.

Comment thread pkgs/id/src/event_sync.rs
Comment on lines +18 to +21
//! The pull gate is [`PullPolicy::Open`], the documented default for sync: `id serve`
//! does not read a per-world pull policy from config yet, and there is no world whose
//! membership this store belongs to. An open gate never consults membership, so the
//! [`WorldAccess`] it carries is a formality that is never read.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Add the required dated revision-sync design record

This adds a network-facing replication path and selects an open pull policy for the web event store, but no dated design document accompanies the change. Repository-wide documentation searches found historical local-save and range-sync designs, while the platform acceptance brief still describes revision replication as an open gap; none records this integration's shared-store architecture or open-access trade-off. The package's AGENTS.md explicitly requires documenting significant changes before implementation. Add the required dated design record rather than relying solely on source comments.

AGENTS.md reference: pkgs/id/AGENTS.md:L159-L168

Useful? React with 👍 / 👎.

…peer applied (#792)

The two-node event_sync tests failed intermittently: the dialer finished its session and closed the connection while its last events were still in flight, and the accepting side's session died with the connection before it applied them. sync_over now has a completion phase: each side writes a completion frame once it has applied what it received, and ends the session only after reading the peer's. The accepting handler also waits (bounded) for the dialer to close before returning, so the router cannot close the connection out from under the completion frame — the same pattern ArtifactPullProtocol uses. Receiving was factored into receive_data so the completion signal fires on error exits too.
@dezren39

Copy link
Copy Markdown
Member Author

🤖 Agent note · handed off (fix pushed, awaiting CI)

  • Agent: queue worker (repo-worker-code), lane C
  • Session / ID: queue task 2655 (resumed, attempt 2)
  • Found via: queue claim
  • Task: Root-caused and fixed the intermittent two-node failure on this PR. The dialer finished its session and closed the connection while its last events were still in flight; the accepting side's session died with the connection before applying them (flaky: on rerun, 1 of 2 tests passed; the acceptor's error was only debug-logged).
  • Fix (commit 83e35ff): sync_over gains a completion phase — each side writes a completion frame once it has applied what it received, and ends the session only after reading the peer's, so a returned session means the peer applied what it sent. The accepting handler additionally waits (bounded, 5s) for the dialer to close before returning, so the router cannot close the connection out from under that final frame (the ArtifactPullProtocol pattern). Receiving was factored into receive_data so the completion signal fires on error exits too, and the acceptor's outcome log now includes accepted/duplicates/waiting/refused.
  • Tests (laptop, this run): event_sync 2/2 pass ×4 consecutive runs (0.6–0.9s each; previously 60s timeouts/flaky) · event_store::sync 15/15 pass (2 ignored) · local_events 4/4 pass.
  • Expectation: task parked on this PR for CI on 83e35ff; merge proceeds through the normal lane flow once checks are green.

@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: 83e35ff465

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

Comment on lines +545 to +546
applied.notify_one();
let (count, tally) = received?;

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 Send the applied acknowledgment only after successful ingestion

If receive_data fails—for example, because the receiving store cannot commit a batch after running out of disk space—this notification still releases the sending half to write APPLIED_FRAME before the error is propagated. In a one-way transfer, the sender can consequently receive that acknowledgment and report a successful session even though the receiving node did not persist its revisions. Separate failure cancellation from successful completion so an ingestion error terminates the session without acknowledging application.

Useful? React with 👍 / 👎.

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