Skip to content

feat(sync): auto-register as replica with origin after successful mirror#56

Merged
kevincodex1 merged 1 commit into
mainfrom
auto-replica-registration
Jun 18, 2026
Merged

feat(sync): auto-register as replica with origin after successful mirror#56
kevincodex1 merged 1 commit into
mainfrom
auto-replica-registration

Conversation

@kevincodex1

@kevincodex1 kevincodex1 commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

The sync worker mirrored repos from peers but never told the origin, so replica_count (repo_replicas table, GET /api/v1/repos/:owner/:repo/replicas) stayed at 0 network-wide — the dashboard showed 0 replication even for repos that were actually mirrored.

After each successful clone/fetch the worker now sends a signed PUT /api/v1/repos/{owner}/{repo}/replicas to the origin with our public_url, using the same HTTP-Signature scheme as push notifies. Best-effort by design: skipped when public_url is unset, failures are logged without failing the sync, and the PUT is idempotent on the origin (201 first, 200 after) so re-registering every sync is self-healing.

Nodes need this build before their mirrors are counted: a new node's repos show replication once its peers upgrade.

Summary by CodeRabbit

  • New Features
    • Nodes now automatically register as replicas with sync origins after successfully mirroring repositories, enhancing distributed synchronization capabilities

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e8409af4-0f80-450e-afa7-0b4297795631

📥 Commits

Reviewing files that changed from the base of the PR and between 7a8b6c4 and eb2a939.

📒 Files selected for processing (2)
  • crates/gitlawb-node/src/main.rs
  • crates/gitlawb-node/src/sync.rs

📝 Walkthrough

Walkthrough

The sync worker gains post-mirror replica registration. node_keypair is threaded from main through sync::startrunprocess_batch. After each successful mirror and mark_sync_done, the worker calls a new best-effort helper that signs a PUT request to the origin's /replicas endpoint with the node's public URL.

Changes

Replica Registration After Sync

Layer / File(s) Summary
Keypair threading from main through sync worker
crates/gitlawb-node/src/main.rs, crates/gitlawb-node/src/sync.rs
sync::start gains an Arc<Keypair> parameter; main.rs passes Arc::clone(&state.node_keypair); run and process_batch are updated to forward the reference.
Replica registration helpers and call site
crates/gitlawb-node/src/sync.rs
After mark_sync_done, process_batch calls register_replica_with_origin (best-effort, result ignored). New helpers build the /replicas path, skip when public_url is absent or empty, sign the PUT with http_sig::sign_request, send digest and signature headers, and log outcomes. Module docs and unit tests cover the route format and the skip-on-no-URL cases.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 A key in my paw, I hop to the source,
Signing my PUTs with a confident force.
"I hold your replica!" I tell the origin node,
A best-effort whisper along the sync road.
No failure shall stop me, I log and move on —
The replica count grows from dusk until dawn! 🌿

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: automatic replica registration with the origin repository after successful synchronization. It directly aligns with the primary objective of the PR.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch auto-replica-registration

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 and usage tips.

The sync worker mirrored repos from peers but never told the origin, so
replica_count (repo_replicas table, GET /api/v1/repos/:owner/:repo/replicas)
stayed at 0 network-wide — the dashboard showed 0 replication even for
repos that were actually mirrored.

After each successful clone/fetch the worker now sends a signed
PUT /api/v1/repos/{owner}/{repo}/replicas to the origin with our
public_url, using the same HTTP-Signature scheme as push notifies.
Best-effort by design: skipped when public_url is unset, failures are
logged without failing the sync, and the PUT is idempotent on the origin
(201 first, 200 after) so re-registering every sync is self-healing.

Nodes need this build before their mirrors are counted: a new node's
repos show replication once its peers upgrade.

Co-Authored-By: OpenClaude <openclaude@gitlawb.com>
@kevincodex1 kevincodex1 force-pushed the auto-replica-registration branch from 93b36ce to eb2a939 Compare June 18, 2026 14:12
@kevincodex1 kevincodex1 merged commit c03c9af into main Jun 18, 2026
6 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.

1 participant