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: tolerate trailing commas when rescuing a printed no-tool stage deliverable

[._.]/ Adam Eivy998958adea14
diff --git a/server/lib/agentSentinel.js b/server/lib/agentSentinel.js
index c69b727d53..af2f53b8e5 100644
--- a/server/lib/agentSentinel.js
+++ b/server/lib/agentSentinel.js
@@ -171,9 +171,16 @@ export async function salvageSentinelPayload(contents) {
*
* Blocks are walked in REVERSE closing order — the model's final answer wins
* over an earlier prompt echo of the same schema, and an enclosing object wins
- * over its own nested children. Strict `safeJSONParse` per block (no lenient
- * repair): a transcript is not a file the agent committed to, so "almost JSON"
- * there stays a miss.
+ * over its own nested children. Each candidate goes through
+ * `tryParseWithRepair` rather than a bare strict parse: for a tool-free
+ * programmatic-I/O stage (e.g. pr-reviewer's no-filesystem-access review role),
+ * the transcript print IS the committed deliverable — there is no `.agent-done`
+ * file to fall back to — so it deserves the same trailing-comma / orphan-brace
+ * repair tolerance `salvageSentinelPayload` already applies to a written
+ * sentinel. The repairs are conservative and string-aware (never touch content
+ * that already parses, never fix unquoted keys or other non-JSON prose), so a
+ * genuinely non-JSON block (an object-literal echo, truncated prose) still
+ * fails to parse and is skipped.
*
* Async + LAZY imports for the same reason as `salvageSentinelPayload` — the
* barrel re-export of this module must not statically pull jsonExtract's
@@ -189,15 +196,15 @@ export async function extractSentinelPayloadFromTranscript(transcript, isPayload
if (typeof isPayload !== 'function') return none;
const { stripAnsi } = await import('./ansiStrip.js');
- const { findAllBalancedBlocks } = await import('./jsonExtract.js');
+ const { findAllBalancedBlocks, tryParseWithRepair } = await import('./jsonExtract.js');
const blocks = findAllBalancedBlocks(stripAnsi(transcript));
for (let i = blocks.length - 1; i >= 0; i -= 1) {
- const parsed = safeJSONParse(blocks[i], null, { allowArray: false });
+ const { value: parsed, error } = tryParseWithRepair(blocks[i]);
// `typeof` guard, not just truthiness: the `in` check below throws on a
// primitive, and a best-effort salvage must never be the thing that breaks
// finalize.
- if (!parsed || typeof parsed !== 'object') continue;
+ if (error || !parsed || typeof parsed !== 'object' || Array.isArray(parsed)) continue;
// Two shapes reach a transcript: the documented `{ summary, payload }`
// envelope the agent should have written to the sentinel, and the BARE
// payload object — what a model answering in the terminal actually prints.
diff --git a/server/lib/agentSentinel.test.js b/server/lib/agentSentinel.test.js
index e7ab04e00c..270a8140b8 100644
--- a/server/lib/agentSentinel.test.js
+++ b/server/lib/agentSentinel.test.js
@@ -203,6 +203,16 @@ describe('extractSentinelPayloadFromTranscript', () => {
.toEqual({ summary: '', payload: null });
});
+ it('recovers a printed deliverable that has a trailing comma before a closing brace', async () => {
+ // Observed in the wild: a no-tool review stage printed a well-formed
+ // verdict, but one nested array item had a trailing comma before its
+ // closing `}` — strict JSON.parse rejected the whole block and the
+ // review was discarded as "no output" even though it approved the PR.
+ const transcript = '```json\n{"analysis":"a","proposal":{"scope":"self-improve","title":"t",}}\n```';
+ const { payload } = await extractSentinelPayloadFromTranscript(transcript, isReasonerPayload);
+ expect(payload.proposal.title).toBe('t');
+ });
+
it('recovers the answer even when an earlier line left an unmatched quote', async () => {
const { payload } = await extractSentinelPayloadFromTranscript(`\u2502 renaming "foo\n${ANSWER}`, isReasonerPayload);
expect(payload).not.toBeNull();