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

address review (codex): never persist an explicit uiPort for served-by-API apps

Adam Eivye29800a30ff7
diff --git a/server/routes/apps.js b/server/routes/apps.js
index 2e50842f1e..d78bfdc68f 100644
--- a/server/routes/apps.js
+++ b/server/routes/apps.js
@@ -548,6 +548,17 @@ router.put('/:id', asyncHandler(async (req, res, next) => {
);
}
+ // Served-by-API apps have NO explicit uiPort — it's always derived from
+ // apiPort on read. The modal still echoes the displayed (derived) uiPort on
+ // every save, so never let it be written to apps.json as an explicit field:
+ // doing so would freeze uiPort at its old value and stop it tracking a later
+ // apiPort change (e.g. API 6000→7000 must re-derive uiPort 7000, not keep a
+ // stored 6000). Any genuine change was already rejected above, so a
+ // remaining uiPort here is the harmless echo — strip it.
+ if (currentPort.uiPort === undefined && Number.isInteger(derivedUiPort) && 'uiPort' in data) {
+ delete data.uiPort;
+ }
+
// Persist the value-keyed remap (distinct ports) and the targeted edits
// (shared-value ports) in ONE atomic write. Doing them as two separate
// writes would let the value-keyed pass land on disk before a later
diff --git a/server/routes/apps.test.js b/server/routes/apps.test.js
index e79ea0bf9b..ef71d0739b 100644
--- a/server/routes/apps.test.js
+++ b/server/routes/apps.test.js
@@ -374,9 +374,11 @@ describe('Apps Routes', () => {
expect(appsService.updateApp).not.toHaveBeenCalled();
});
- it('does not reject when a rename echoes the derived uiPort unchanged (served-by-API)', async () => {
- // Same served-by-API shape, but the modal echoes the derived uiPort (6000)
- // unchanged on a rename — a no-op that must NOT 422.
+ it('strips the echoed derived uiPort so it is never persisted as an explicit field', async () => {
+ // Same served-by-API shape; the modal echoes the derived uiPort (6000)
+ // unchanged on a rename. That must NOT 422, but it also must NOT be stored
+ // as an explicit uiPort (which would stop it tracking apiPort) — the route
+ // strips it before updateApp.
const mockApp = { id: 'app-001', name: 'App', type: 'node', repoPath: process.cwd(), apiPort: 6000, uiPort: 6000, devUiPort: 5556 };
appsService.getAppById.mockResolvedValue(mockApp);
streamingDetect.parseEcosystemFromPath.mockResolvedValue({
@@ -390,7 +392,38 @@ describe('Apps Routes', () => {
expect(response.status).toBe(200);
expect(streamingDetect.writeEcosystemPortEdits).not.toHaveBeenCalled();
- expect(appsService.updateApp).toHaveBeenCalled();
+ // uiPort stripped — updateApp must not receive it as an explicit field.
+ const updateArg = appsService.updateApp.mock.calls[0][1];
+ expect(updateArg).not.toHaveProperty('uiPort');
+ expect(updateArg.name).toBe('Renamed');
+ });
+
+ it('changing apiPort on a served-by-API app persists the API port and drops the echoed derived uiPort', async () => {
+ // The real bug: API 6000→7000 with the modal echoing the OLD derived
+ // uiPort 6000. The apiPort edit must persist via the value-keyed rewrite,
+ // and the echoed uiPort must be stripped so it re-derives to 7000 (not
+ // frozen at 6000).
+ const mockApp = { id: 'app-001', name: 'App', type: 'node', repoPath: process.cwd(), apiPort: 6000, uiPort: 6000, devUiPort: 5556 };
+ appsService.getAppById.mockResolvedValue(mockApp);
+ streamingDetect.parseEcosystemFromPath.mockResolvedValue({
+ processes: [{ name: 'srv', ports: { api: 6000, devUi: 5556 } }]
+ });
+ appsService.updateApp.mockResolvedValue({ ...mockApp, apiPort: 7000 });
+
+ const response = await request(app)
+ .put('/api/apps/app-001')
+ .send({ apiPort: 7000, uiPort: 6000 });
+
+ expect(response.status).toBe(200);
+ // apiPort (distinct, value-keyed) persisted; uiPort echo not in the remap.
+ expect(streamingDetect.writeEcosystemPortEdits).toHaveBeenCalledWith(
+ process.cwd(),
+ [[6000, 7000]],
+ []
+ );
+ const updateArg = appsService.updateApp.mock.calls[0][1];
+ expect(updateArg).not.toHaveProperty('uiPort'); // re-derives from new apiPort
+ expect(updateArg.apiPort).toBe(7000);
});
it('does not reject a non-port edit on an app whose top-level ports are not stored (derived)', async () => {