Skip to content

fix(sources): serialize first source keypair generation - #85

Closed
DivyamTalwar wants to merge 1 commit into
hanzoai:mainfrom
DivyamTalwar:fix/source-device-keypair-crossprocess-lock
Closed

DivyamTalwar wants to merge 1 commit into
hanzoai:mainfrom
DivyamTalwar:fix/source-device-keypair-crossprocess-lock

Conversation

@DivyamTalwar

Copy link
Copy Markdown

Problem

Two concurrent first-time hanzo sources link processes can both find no device key, generate different Ed25519 keypairs and truncate/write the same source-key.ed25519 path. The later write replaces the first process's key, so a source registered with the earlier public key can no longer sign valid heartbeats after restart.

Fix

Acquire the repository's existing cross-process file lock before checking for and creating the keypair. The lock resides at a separate .lock path, including when the device key does not yet exist. Calls that race during first setup now all read the single persisted key.

Verified

  • Added a 12-worker simultaneous first-link regression. It checks that every returned public key equals the final on-disk key, and that repeated reads return the same identity.
  • rustfmt parsed the updated source and git diff --check passed.
  • Full Cargo test execution was unavailable in this checkout due an uncached workspace Git dependency and critically low Mac startup-disk space; the test needs CI/maintainer validation.

No new dependencies, no change to key format, and no network calls under the lock.

@zeekay

zeekay commented Nov 25, 2026

Copy link
Copy Markdown
Member

Audited, verified with cargo test --locked commands::sources:: (including the 12-worker concurrent keypair test) + clippy, and merged via #95 at commit 2821a9b05c2b00c4c3a12ba2796bbedccac0055d (with full Co-authored-by attribution to @DivyamTalwar). Thank you!

@zeekay zeekay closed this Nov 25, 2026
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