Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix(instances): preserve user-set peer names on re-announce

Adam Eivy3eb8e86e5aee
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index d7db946df8..cc0f13fff8 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -6,6 +6,7 @@
## Fixed
+- Peer renames no longer revert when remote peer re-announces (handleAnnounce now preserves user-set names)
- CoS task evaluation now blocks tasks that exceeded max spawn limit before reaching spawn logic
- Metadata count fields (totalSpawnCount, failureCount, orphanRetryCount) use Number() coercion to prevent string comparison bugs
- jira-status-report task now runs in PortOS context (not the app's directory) and uses the correct PortOS API endpoint
diff --git a/server/services/instances.js b/server/services/instances.js
index 37a02a42c2..de4c314177 100644
--- a/server/services/instances.js
+++ b/server/services/instances.js
@@ -336,8 +336,11 @@ export async function handleAnnounce({ address, port, instanceId, name }) {
existing.status = 'online';
existing.instanceId = instanceId;
existing.port = port;
+ // Only auto-update name if still an IP address (preserve user-set names)
const sanitized = validName(name, null);
- if (sanitized) existing.name = sanitized;
+ if (sanitized && /^\d+\.\d+\.\d+\.\d+$/.test(existing.name)) {
+ existing.name = sanitized;
+ }
// Mark that this peer has announced to us (inbound connection)
existing.directions = existing.directions || [];
if (!existing.directions.includes('inbound')) existing.directions.push('inbound');
diff --git a/server/services/instances.test.js b/server/services/instances.test.js
index de69d44a1b..3d182b68e2 100644
--- a/server/services/instances.test.js
+++ b/server/services/instances.test.js
@@ -527,13 +527,13 @@ describe('instances.js', () => {
expect(instanceEvents.emit).toHaveBeenCalledWith('peers:updated', expect.any(Array));
});
- it('should update existing peer matched by instanceId', async () => {
+ it('should update existing peer matched by instanceId but preserve user-set name', async () => {
const existing = {
id: 'p1',
address: '10.0.0.5',
port: 5555,
instanceId: 'remote-instance',
- name: 'old-name',
+ name: 'custom-name',
status: 'offline',
directions: ['outbound']
};
@@ -543,16 +543,40 @@ describe('instances.js', () => {
address: '10.0.0.5',
port: 5555,
instanceId: 'remote-instance',
- name: 'new-name'
+ name: 'remote-hostname'
});
expect(result.created).toBe(false);
- expect(result.peer.name).toBe('new-name');
+ expect(result.peer.name).toBe('custom-name'); // user-set name preserved
expect(result.peer.status).toBe('online');
expect(result.peer.directions).toContain('inbound');
expect(result.peer.directions).toContain('outbound');
});
+ it('should auto-update name from announce when current name is an IP', async () => {
+ const existing = {
+ id: 'p1',
+ address: '10.0.0.5',
+ port: 5555,
+ instanceId: 'remote-instance',
+ name: '10.0.0.5',
+ status: 'offline',
+ directions: ['outbound']
+ };
+ readJSONFile.mockResolvedValue({ self: null, peers: [existing] });
+
+ const result = await handleAnnounce({
+ address: '10.0.0.5',
+ port: 5555,
+ instanceId: 'remote-instance',
+ name: 'remote-hostname'
+ });
+
+ expect(result.created).toBe(false);
+ expect(result.peer.name).toBe('remote-hostname'); // IP auto-updated to hostname
+ expect(result.peer.status).toBe('online');
+ });
+
it('should match existing peer by address+port when instanceId differs', async () => {
const existing = {
id: 'p1',