Skip to content

fix(mesh-store): persist agent identity to disk to survive restarts#15

Open
YrFnS wants to merge 1 commit into
ExaDev:mainfrom
YrFnS:fix/identity-persistence-across-restarts
Open

fix(mesh-store): persist agent identity to disk to survive restarts#15
YrFnS wants to merge 1 commit into
ExaDev:mainfrom
YrFnS:fix/identity-persistence-across-restarts

Conversation

@YrFnS

@YrFnS YrFnS commented Jun 8, 2026

Copy link
Copy Markdown

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:

  1. readIdentity() — added disk fallback: reads the persisted agent ID from ~/.agent-comms/{harness}--{cwd}.json when the in-memory cache is empty

  2. writeIdentity() — added disk persistence: writes the agent ID to ~/.agent-comms/{harness}--{cwd}.json alongside the in-memory cache

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

  • src/core/mesh-store.ts — identity persistence + agent re-creation

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:

  • The same agent ID is reused
  • onDelivery fires for messages from other peers
  • Room membership is preserved

Related Issues

Closes #14
Related to #13

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

Pi bridge: onDelivery never fires after first session (ephemeral TLS identity diverges from persisted agentId

1 participant