From e06e5d87174253fff6773f66c714e46c0b8dd9ca Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Mon, 16 Nov 2026 14:54:55 +0100 Subject: [PATCH] Host: a job list JSON cannot hold is logged and skipped, not thrown out of every state change (#5802 review) native-job-store's save() serialised outside its guard: a value JSON cannot hold (a BigInt, a cycle) would still have thrown out of emit() on every change. It is now reported once per attempt as a programming error, the last good file stays, and the next good list is saved. A log line only, no app text. Test: native-job-store.test.mjs "a job list JSON cannot hold ...": fails on e19adee7e, 8/8 pass here. --- apps/host/server/native-job-store.mjs | 8 +++++++- apps/host/tests/native-job-store.test.mjs | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/apps/host/server/native-job-store.mjs b/apps/host/server/native-job-store.mjs index e09e9bd69e..3ee477fade 100644 --- a/apps/host/server/native-job-store.mjs +++ b/apps/host/server/native-job-store.mjs @@ -47,7 +47,13 @@ export function createJobStore(path, { return { save(jobs) { if (closed) return; - const text = JSON.stringify(jobs); + let text; + try { text = JSON.stringify(jobs); } + catch (error) { + // A value JSON cannot hold (a BigInt, a cycle) is a programming error, not a disk problem: say so and keep the last good file. + report(`[strata host] Job history could not be turned into JSON (${error.message}); the last saved history is kept, inference continues.`); + return; + } if (text === saved) { pending = null; if (timer !== null) clearTimer(timer); diff --git a/apps/host/tests/native-job-store.test.mjs b/apps/host/tests/native-job-store.test.mjs index cd7cb5fddd..c62ea5da2d 100644 --- a/apps/host/tests/native-job-store.test.mjs +++ b/apps/host/tests/native-job-store.test.mjs @@ -104,3 +104,17 @@ test('an unexpected polling callback failure does not leave polling stuck or rej assert.equal(changes,2); await controller.close(); }); + +// A value JSON cannot hold is reported and skipped like a disk failure: save() never throws out of emit() (GUI-1116 review of #5802). +test('a job list JSON cannot hold is reported, the last good file stays, and save does not throw', () => { + const f=fixture(); + f.store.save([{id:'one',state:'done'}]); + const cyclic={id:'two'};cyclic.self=cyclic; + assert.doesNotThrow(()=>f.store.save([cyclic])); + assert.doesNotThrow(()=>f.store.save([{id:'three',size:1n}])); + assert.deepEqual(JSON.parse(fs.readFileSync(f.path)),[{id:'one',state:'done'}]); + assert.equal(f.warnings.filter(w=>/could not be turned into JSON/.test(w)).length,2); + f.store.save([{id:'four',state:'done'}]); + assert.deepEqual(JSON.parse(fs.readFileSync(f.path)),[{id:'four',state:'done'}],'the next good list is saved'); + f.store.close(); +});