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): treat a failed value-keyed remap as persist-nothing too

Adam Eivy70c3abee855b
diff --git a/server/services/streamingDetect.js b/server/services/streamingDetect.js
index 88aa56212d..5f096943b2 100644
--- a/server/services/streamingDetect.js
+++ b/server/services/streamingDetect.js
@@ -887,9 +887,14 @@ export async function writeEcosystemPortEdits(repoPath, remap, edits) {
const remapApplied = afterRemap !== content;
- // Any unpersistable targeted edit ⇒ the caller rejects the whole request,
- // so persist NOTHING (not even the value-keyed pass that did match).
- if (unapplied.length > 0) {
+ // Persist NOTHING when ANY part of the request is unpersistable — the caller
+ // rejects the whole update (422) in either of these cases, so a partial
+ // write would desync config from the un-updated registry:
+ // - a requested value-keyed remap matched no literal (`hasRemap` &&
+ // !remapApplied) — the symmetric twin of an unapplied targeted edit, and
+ // - any targeted edit couldn't be applied (`unapplied`).
+ const remapFailed = hasRemap && !remapApplied;
+ if (remapFailed || unapplied.length > 0) {
return { file: name, changed: false, remapApplied: false, applied: [], unapplied };
}
diff --git a/server/services/streamingDetect.test.js b/server/services/streamingDetect.test.js
index 4e3af0c1c7..024056e023 100644
--- a/server/services/streamingDetect.test.js
+++ b/server/services/streamingDetect.test.js
@@ -732,6 +732,29 @@ module.exports = { apps: [
expect(readFileSync(join(dir, 'ecosystem.config.cjs'), 'utf-8')).toBe(original);
});
+ it('persists NOTHING when the value-keyed remap matches no literal but a targeted edit would apply', async () => {
+ // Symmetric twin of the unapplied-targeted case: the distinct devUiPort
+ // remap (9999→7001) matches nothing in the config, but the shared uiPort
+ // targeted edit DOES apply. The route 422s on the failed remap, so the
+ // targeted rewrite must NOT have been written to disk.
+ dir = mkdtempSync(join(tmpdir(), 'eco-edits-'));
+ const original = `module.exports = { apps: [
+ { name: 'srv', script: 's.js', ports: { api: 6000, ui: 6000 } }
+] };
+`;
+ writeFileSync(join(dir, 'ecosystem.config.cjs'), original);
+ const result = await writeEcosystemPortEdits(
+ dir,
+ [[9999, 7001]], // remap matches nothing
+ [{ processName: 'srv', label: 'ui', oldPort: 6000, newPort: 7000 }] // targeted would apply
+ );
+ expect(result.changed).toBe(false);
+ expect(result.remapApplied).toBe(false);
+ // File unchanged — the applicable targeted edit was NOT written because the
+ // remap failed and the whole request will be rejected.
+ expect(readFileSync(join(dir, 'ecosystem.config.cjs'), 'utf-8')).toBe(original);
+ });
+
it('is a no-op when both remap and edits are empty', async () => {
dir = mkdtempSync(join(tmpdir(), 'eco-edits-'));
const original = `module.exports = { apps: [{ name: 'x', script: 's.js', env: { PORT: 6000 } }] };\n`;