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-2610]): guard hand-edited historyCap so a malformed value can't wipe history

[._.]/ Adam Eivy713c1365f553
diff --git a/server/services/modelPersonality.js b/server/services/modelPersonality.js
index 028d5253ba..c876e813b3 100644
--- a/server/services/modelPersonality.js
+++ b/server/services/modelPersonality.js
@@ -46,7 +46,14 @@ const settingsFile = () => join(PATHS.data, 'model-personality', 'settings.json'
export async function getSettings() {
const stored = await readJSONFile(settingsFile(), {});
- return { ...DEFAULT_SETTINGS, ...(stored && typeof stored === 'object' ? stored : {}) };
+ const merged = { ...DEFAULT_SETTINGS, ...(stored && typeof stored === 'object' ? stored : {}) };
+ // Guard hand-edited settings: a malformed historyCap would flow into
+ // `list.slice(0, historyCap)` and silently wipe the whole history
+ // (`slice(0, 'abc')` → `[]`). Same rule as backup.js's settings guards.
+ if (!Number.isInteger(merged.historyCap) || merged.historyCap < 1 || merged.historyCap > 1000) {
+ merged.historyCap = DEFAULT_SETTINGS.historyCap;
+ }
+ return merged;
}
export async function updateSettings(patch = {}) {
diff --git a/server/services/modelPersonality.test.js b/server/services/modelPersonality.test.js
index d01838205b..fd2ec7022b 100644
--- a/server/services/modelPersonality.test.js
+++ b/server/services/modelPersonality.test.js
@@ -188,6 +188,20 @@ describe('history & settings', () => {
expect(await svc.getHistory()).toEqual([]);
});
+ it('falls back to the default historyCap when a hand-edited value is malformed', async () => {
+ const { writeFileSync, mkdirSync } = await import('fs');
+ mkdirSync(join(TEST_DATA_ROOT, 'model-personality'), { recursive: true });
+ writeFileSync(
+ join(TEST_DATA_ROOT, 'model-personality', 'settings.json'),
+ JSON.stringify({ historyCap: 'abc' })
+ );
+ expect((await svc.getSettings()).historyCap).toBe(svc.DEFAULT_SETTINGS.historyCap);
+ // The malformed cap must not wipe history via slice(0, 'abc') → [].
+ mockProfileRun();
+ await svc.runPersonalityTest({ providerId: 'prov-1', includeAlignment: false });
+ expect(await svc.getHistory()).toHaveLength(1);
+ });
+
it('merges settings over defaults and persists them', async () => {
expect(await svc.getSettings()).toEqual({ ...svc.DEFAULT_SETTINGS });
const next = await svc.updateSettings({ historyCap: 42 });