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([issue-749]): address codex+claude review of runner state layer

[._.]/ Adam Eivyb6f949c10cdd
diff --git a/server/cos-runner/runnerState.js b/server/cos-runner/runnerState.js
index 5ecc74b0f4..11b9e9828a 100644
--- a/server/cos-runner/runnerState.js
+++ b/server/cos-runner/runnerState.js
@@ -38,6 +38,8 @@ export async function loadState() {
* which also handles ensureDir, JSON stringification, and the Windows rename fallback.
*/
export function saveState(state) {
- stateLock = stateLock.then(() => atomicWrite(STATE_FILE, state));
+ // Swallow a prior write's rejection before chaining so one failed write can't
+ // poison the lock and silently skip every subsequent save.
+ stateLock = stateLock.catch(() => {}).then(() => atomicWrite(STATE_FILE, state));
return stateLock;
}
diff --git a/server/cos-runner/runnerState.test.js b/server/cos-runner/runnerState.test.js
index 712200ce6d..f72f900938 100644
--- a/server/cos-runner/runnerState.test.js
+++ b/server/cos-runner/runnerState.test.js
@@ -8,10 +8,14 @@ describe('cos-runner runnerState', () => {
// STATE_FILE is computed from PATHS.cos at module-load time, so each test
// points PATHS.cos at a fresh temp dir and re-imports the module.
+ // resetModules() MUST run BEFORE importing fileUtils — otherwise the reset
+ // discards the mutated instance and runnerState.js re-imports a fresh
+ // fileUtils whose PATHS.cos points back at the real data/cos dir, letting the
+ // tests read and clobber the live runner-state.json.
const loadModule = async () => {
+ vi.resetModules();
const fileUtils = await import('../lib/fileUtils.js');
fileUtils.PATHS.cos = tmpDir;
- vi.resetModules();
return import('./runnerState.js');
};
diff --git a/server/cos-runner/streamJsonParser.js b/server/cos-runner/streamJsonParser.js
index afef8742df..ff325ae3dc 100644
--- a/server/cos-runner/streamJsonParser.js
+++ b/server/cos-runner/streamJsonParser.js
@@ -1,8 +1,8 @@
/**
* CoS Runner — Stream-JSON parsing layer
*
- * Self-contained (no imports out to other PortOS modules beyond fs/path-free
- * pure helpers) so the isolated `portos-cos` PM2 process stays standalone.
+ * Self-contained — no imports, pure functions only — so the isolated
+ * `portos-cos` PM2 process stays standalone.
* NOTE: an equivalent parser also lives in server/services/agentCliSpawning.js
* for the in-process spawn path; the two are intentionally separate copies
* because cos-runner must not pull in the main server's dependency graph.