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

guard config merge against a non-object stored value

[._.]/ Adam Eivy215ff52446e6
diff --git a/server/services/cosState.js b/server/services/cosState.js
index 7e2bb878a1..009c12d3c9 100644
--- a/server/services/cosState.js
+++ b/server/services/cosState.js
@@ -153,7 +153,10 @@ function parseStateFile(content) {
* recovery path so a recovered config is normalized identically.
*/
function mergeStoredConfig(storedConfig) {
- const persistedConfig = { ...(storedConfig || {}) };
+ // `isPlainObject` before the spread, not `|| {}`: spreading a string yields
+ // one key per character, so a `"config": "…"` in a hand-edited state file
+ // would merge character indices over DEFAULT_CONFIG instead of being ignored.
+ const persistedConfig = isPlainObject(storedConfig) ? { ...storedConfig } : {};
// Migrate legacy split flags before merging defaults — DEFAULT_CONFIG.improvementEnabled = true
// would otherwise shadow a v1 file that only set selfImprovementEnabled/appImprovementEnabled.
@@ -342,7 +345,7 @@ export async function readAgentsStateForSafetyCheck() {
const agents = state?.agents;
return {
trusted,
- agents: trusted && agents && typeof agents === 'object' && !Array.isArray(agents) ? agents : null,
+ agents: trusted && isPlainObject(agents) ? agents : null,
};
}