fix(mesh-store): persist agent identity to disk to survive restarts#15
Open
YrFnS wants to merge 1 commit into
Open
fix(mesh-store): persist agent identity to disk to survive restarts#15YrFnS wants to merge 1 commit into
YrFnS wants to merge 1 commit into
Conversation
The readIdentity/writeIdentity functions previously stored agent identity
only in an in-memory Map, which is lost on every pi restart. This caused
registerAgent() to create a new agent with the new TLS fingerprint as ID,
breaking message delivery from other peers that still target the old ID.
Changes:
- readIdentity(): added disk fallback reading from ~/.agent-comms/{harness}--{cwd}.json
- writeIdentity(): added disk persistence writing to ~/.agent-comms/{harness}--{cwd}.json
- registerAgent(): added re-creation path when identity exists on disk but
agent not in local store (e.g., after restart)
Fixes ExaDev#14
Related to ExaDev#13
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.
Problem
After restarting pi (or any harness), the agent-comms mesh agent gets a new TLS identity and therefore a new agent ID. Other peers that were targeting the old agent ID can no longer deliver messages to it. This breaks the mesh communication entirely — onDelivery never fires, rooms appear to have only 1 member, etc.
Root cause: readIdentity() and writeIdentity() in src/core/mesh-store.ts store the agent identity only in an in-memory Map (identityCache). On restart the cache is empty, so registerAgent() creates a fresh agent.
Fix
Three changes to src/core/mesh-store.ts:
readIdentity() — added disk fallback: reads the persisted agent ID from ~/.agent-comms/{harness}--{cwd}.json when the in-memory cache is empty
writeIdentity() — added disk persistence: writes the agent ID to ~/.agent-comms/{harness}--{cwd}.json alongside the in-memory cache
registerAgent() — added re-creation path: when the identity exists on disk (from a previous session) but the agent record is not in the local store (fresh process), the agent is re-created with the old persisted ID instead of throwing AGENT_NOT_FOUND
Files Changed
Testing
Applied the equivalent patch to the compiled dist/core/mesh-store.js in the installed agent-comms@1.24.0 package. Verified that after a pi restart:
Related Issues
Closes #14
Related to #13