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): pin derived uiPort to the new value instead of deleting it

Adam Eivy1eb79cd0fc5f
diff --git a/server/routes/apps.js b/server/routes/apps.js
index 3fb436af9d..17ea7eece5 100644
--- a/server/routes/apps.js
+++ b/server/routes/apps.js
@@ -550,15 +550,18 @@ 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 (uiIsDerived && 'uiPort' in data) {
- delete data.uiPort;
+ // Served-by-API apps have NO explicit uiPort in the config — it's derived
+ // from apiPort on read. Pin the stored uiPort to the NEW derived value so it
+ // tracks the (possibly just-changed) API port. Deleting it from this partial
+ // update is NOT enough: updateApp merges omitted fields over the existing
+ // record, so a stale explicit `uiPort` left by an earlier refresh would
+ // survive (truthy) and block re-derivation — after API 6000→7000 the GET
+ // path would keep returning the old 6000. Writing the derived value
+ // overwrites any stale stored port and self-corrects on every API change.
+ // (uiIsDerived is computed from the parsed CONFIG, not apps.json, so it's
+ // true even when apps.json already holds a stale explicit value.)
+ if (uiIsDerived) {
+ data.uiPort = derivedUiPort;
}
// Persist the value-keyed remap (distinct ports) and the targeted edits
diff --git a/server/routes/apps.test.js b/server/routes/apps.test.js
index a3020c390e..b17ee160d1 100644
--- a/server/routes/apps.test.js
+++ b/server/routes/apps.test.js
@@ -377,8 +377,8 @@ describe('Apps Routes', () => {
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.
+ // as a STALE explicit uiPort — the route pins it to the current derived
+ // value so it keeps tracking apiPort instead of freezing.
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({
@@ -392,24 +392,25 @@ describe('Apps Routes', () => {
expect(response.status).toBe(200);
expect(streamingDetect.writeEcosystemPortEdits).not.toHaveBeenCalled();
- // uiPort stripped — updateApp must not receive it as an explicit field.
+ // uiPort pinned to the derived value (= unchanged apiPort 6000) so a stale
+ // stored value can't survive the merge.
const updateArg = appsService.updateApp.mock.calls[0][1];
- expect(updateArg).not.toHaveProperty('uiPort');
+ expect(updateArg.uiPort).toBe(6000);
expect(updateArg.name).toBe('Renamed');
});
- it('changing apiPort on a served-by-API app (UI following the new API port) persists the API port and drops the echoed uiPort', async () => {
+ it('changing apiPort on a served-by-API app (UI following the new API port) persists the API port and pins uiPort to the new derived value', async () => {
// Valid combined save: API 6000→7000 with the UI following to 7000 (the
// derived port tracks the new API port). The apiPort edit persists via the
- // value-keyed rewrite; the echoed uiPort is compared against the NEW
- // derived value (7000), accepted, and stripped so it re-derives from the
- // new apiPort rather than being frozen as an explicit field.
+ // value-keyed rewrite; the stored uiPort is overwritten with the NEW
+ // derived value (7000) so a stale 6000 can't survive the updateApp merge
+ // and block re-derivation.
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 });
+ appsService.updateApp.mockResolvedValue({ ...mockApp, apiPort: 7000, uiPort: 7000 });
const response = await request(app)
.put('/api/apps/app-001')
@@ -423,7 +424,7 @@ describe('Apps Routes', () => {
[]
);
const updateArg = appsService.updateApp.mock.calls[0][1];
- expect(updateArg).not.toHaveProperty('uiPort'); // re-derives from new apiPort
+ expect(updateArg.uiPort).toBe(7000); // pinned to new derived value
expect(updateArg.apiPort).toBe(7000);
});