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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (claude): report which envelope field was unusable, suppress collateral pause reports, harden test isolation
Adam Eivy1966acde297c
diff --git a/client/src/components/apps/LayeredIntelligenceTab.test.jsx b/client/src/components/apps/LayeredIntelligenceTab.test.jsxindex a7993d46e6..ff0a6ff346 100644--- a/client/src/components/apps/LayeredIntelligenceTab.test.jsx+++ b/client/src/components/apps/LayeredIntelligenceTab.test.jsx@@ -29,7 +29,7 @@ describe('describeLastRun', () => {it('surfaces an unparseable reasoning response as a warning with actionable prose', () => {const r = describeLastRun({ lastRunAt: at, lastRunAction: 'no-op', lastRunReason: 'unparseable-response' });expect(r.tone).toBe('warn');- expect(r.text).toMatch(/no usable JSON/i);+ expect(r.text).toMatch(/no usable answer/i);});it('treats a genuine no-proposal run as neutral (not an error)', () => {@@ -65,7 +65,7 @@ describe('LayeredIntelligenceTab last-run status', () => {it('renders the durable last-run line when the config carries a run outcome', () => {render(<LayeredIntelligenceTab li={li({ lastRunAt: '2026-07-09T20:29:05.000Z', lastRunAction: 'no-op', lastRunReason: 'unparseable-response' })} onChange={noop} providers={[]} isPortos loaded />);expect(screen.getByText(/Last run/i)).toBeInTheDocument();- expect(screen.getByText(/no usable JSON/i)).toBeInTheDocument();+ expect(screen.getByText(/no usable answer/i)).toBeInTheDocument();});it('omits the last-run line before the loop has ever run', () => {diff --git a/client/src/utils/layeredIntelligenceReasons.js b/client/src/utils/layeredIntelligenceReasons.jsindex 9658657656..df2ab2691d 100644--- a/client/src/utils/layeredIntelligenceReasons.js+++ b/client/src/utils/layeredIntelligenceReasons.js@@ -20,7 +20,7 @@ export const LI_NEUTRAL_REASONS = new Set([const LI_REASON_LABELS = {'no-provider': 'no AI provider is configured for it',- 'unparseable-response': 'the reasoning model returned no usable JSON — try a non-reasoning model or an API provider',+ 'unparseable-response': 'the reasoning model returned no usable answer — no JSON at all, or an envelope field it got wrong (see the server log for which) — try a non-reasoning model or an API provider','no-proposal': 'the loop had nothing to propose','scope-suppressed': "the proposal's scope isn't allowed for this app",'hard-gate-excluded': "excluded before filing — the loop's own execution is degraded and this proposal maps to self-improve scope or a chronically-failing domain",diff --git a/client/src/utils/layeredIntelligenceReasons.test.js b/client/src/utils/layeredIntelligenceReasons.test.jsindex 825833469f..8ebd6f5e56 100644--- a/client/src/utils/layeredIntelligenceReasons.test.js+++ b/client/src/utils/layeredIntelligenceReasons.test.js@@ -3,7 +3,7 @@ import { formatLiReason, liReasonTone, LI_NEUTRAL_REASONS } from './layeredInteldescribe('formatLiReason', () => {it('glosses a plain reason token', () => {- expect(formatLiReason({ action: 'no-op', reason: 'unparseable-response' })).toMatch(/no usable JSON/i);+ expect(formatLiReason({ action: 'no-op', reason: 'unparseable-response' })).toMatch(/no usable answer/i);expect(formatLiReason({ action: 'no-op', reason: 'no-provider' })).toMatch(/no AI provider/i);});diff --git a/server/services/autonomousJobs/layeredIntelligenceHooks.js b/server/services/autonomousJobs/layeredIntelligenceHooks.jsindex 0ca3ce69a9..99a7d7584e 100644--- a/server/services/autonomousJobs/layeredIntelligenceHooks.js+++ b/server/services/autonomousJobs/layeredIntelligenceHooks.js@@ -601,7 +601,17 @@ export async function processTaskOutput({ appId, success, payload, agentId } = {// A null envelope never reaches here with a non-empty list (the validator returns// the empty triple for it), and the ternary below short-circuits on it anyway; the// `= []` destructuring default keeps a stubbed validator from throwing.+ //+ // Asymmetry, unchanged from #2727 and deliberate: a SURVIVING proposal overwrites+ // `reason` on every branch of the filing path below, so a junk `analysis` alongside+ // a filed proposal records the filing outcome — but a surviving `pause` does NOT+ // re-derive `reason`, so it still applies its blocking label while the run records+ // `unparseable-response`. The proposal is the run's deliverable; a pause is a side+ // effect, and a reasoner that got another field wrong is worth surfacing.const malformedEnvelope = invalidFields.length > 0+ // Name the offending fields — `unparseable-response` alone can't tell an operator+ // whether the model returned no JSON at all or one wrong-typed key.+ if (malformedEnvelope) console.warn(`⚠️ Layered Intelligence: ${app.name} reasoner envelope has unusable fields: ${invalidFields.join(', ')}`)let filedNumber = nulllet filedKey = nulldiff --git a/server/services/autonomousJobs/layeredIntelligenceHooks.test.js b/server/services/autonomousJobs/layeredIntelligenceHooks.test.jsindex b4ee5d427d..cd1c61cb7a 100644--- a/server/services/autonomousJobs/layeredIntelligenceHooks.test.js+++ b/server/services/autonomousJobs/layeredIntelligenceHooks.test.js@@ -18,7 +18,11 @@ vi.mock('../../lib/workTracker.js', async (importActual) => {};});-vi.mock('../../lib/fileUtils.js', () => ({+// Only `tryReadFile` is stubbed — the rest passes through so the real validator this+// suite imports for the #4166 end-to-end case can load its own module graph (its+// constants reach `PATHS`/`DAY` through here). fileUtils has no load-time side effects.+vi.mock('../../lib/fileUtils.js', async (importOriginal) => ({+ ...(await importOriginal()),tryReadFile: vi.fn().mockResolvedValue(null)}));@@ -133,6 +137,10 @@ import { resolveAppWorkTracker } from '../../lib/workTracker.js';import { tryReadFile } from '../../lib/fileUtils.js';import { getProviderById } from '../providers.js';import { getTaskInterval } from '../taskSchedule.js';+// The REAL validator (its own module, so untouched by the `../layeredIntelligence.js`+// mock above) — used by the #4166 end-to-end case so the envelope→reason verdict is+// exercised through production validation, not a hand-written stub of it.+import { validateReasonerResponse as realValidateReasonerResponse } from '../layeredIntelligence/proposal.js';const APP = { id: 'app-1', name: 'App One', repoPath: '/repo', taskTypeOverrides: {} };@@ -158,6 +166,9 @@ beforeEach(() => {// so without this a test that arms the gate would leak into later ones.li.computeHardExclusionGate.mockReturnValue({ excluded: false, reason: null });li.computeHardExclusionNotice.mockReturnValue('');+ // Same leak guard for the validator (#4166): a test that hands back a non-empty+ // `invalidFields` would otherwise make every later run read as unparseable-response.+ li.validateReasonerResponse.mockReturnValue({ proposal: null, pause: null, invalidFields: [] });});describe('buildTaskInput', () => {@@ -612,6 +623,30 @@ describe('processTaskOutput', () => {}});+ it('reaches the same verdict through the REAL validator (#4166)', async () => {+ // End-to-end over the two halves this suite otherwise stubs apart: the real+ // envelope validation feeding the real reason classification.+ li.validateReasonerResponse.mockImplementation(realValidateReasonerResponse);+ for (const payload of [{ analysis: 7 }, { analysis: 'x', pause: { reason: 'no target' } }, { proposal: { title: '' } }]) {+ const out = await processTaskOutput({ appId: 'app-1', success: true, payload });+ expect(out).toMatchObject({ action: 'no-op', reason: 'unparseable-response' });+ }+ for (const payload of [{ analysis: 'nothing worth proposing', proposal: null }, { analysis: '' }]) {+ const out = await processTaskOutput({ appId: 'app-1', success: true, payload });+ expect(out).toMatchObject({ action: 'no-op', reason: 'no-proposal' });+ }+ });++ it('logs which envelope fields were unusable (#4166)', async () => {+ // `unparseable-response` alone can't tell an operator whether the model returned+ // no JSON at all or one wrong-typed key — the offending names must reach the log.+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});+ li.validateReasonerResponse.mockReturnValue({ proposal: null, pause: null, invalidFields: ['analysis', 'pause'] });+ await processTaskOutput({ appId: 'app-1', success: true, payload: { analysis: 7, pause: 3 } });+ expect(warn).toHaveBeenCalledWith(expect.stringContaining('analysis, pause'));+ warn.mockRestore();+ });+it('treats an explicit proposal:null as a legitimate empty answer, not malformed (#2727)', async () => {li.validateReasonerResponse.mockReturnValue({ proposal: null, pause: null, invalidFields: [] });const out = await processTaskOutput({ appId: 'app-1', success: true, payload: { analysis: 'nothing to propose', proposal: null } });diff --git a/server/services/layeredIntelligence.test.js b/server/services/layeredIntelligence.test.jsindex beadbad0ee..e80a615a0a 100644--- a/server/services/layeredIntelligence.test.js+++ b/server/services/layeredIntelligence.test.js@@ -415,6 +415,26 @@ describe('validateReasonerResponse', () => {expect(validateReasonerResponse({ proposal: null, pause: { blockOnIssue: 'this', reason: 'x' } }).invalidFields).toEqual(['pause']);});+ it('does not double-report a "this" pause dropped as collateral of an invalid proposal', () => {+ // The pause is well-formed — it was dropped only because the proposal it pointed+ // at failed validation. One root cause, one report.+ const r = validateReasonerResponse({+ proposal: { scope: 'nuke', slug: 'x', title: 'X' },+ pause: { blockOnIssue: 'this', reason: 'block on the new one' }+ });+ expect(r.pause).toBe(null);+ expect(r.invalidFields).toEqual(['proposal']);+ });++ it('still reports a "this" pause that is itself malformed alongside a bad proposal', () => {+ // No reason → the pause is broken on its own terms, not collateral.+ const r = validateReasonerResponse({+ proposal: { scope: 'nuke', slug: 'x', title: 'X' },+ pause: { blockOnIssue: 'this', reason: '' }+ });+ expect(r.invalidFields).toEqual(['proposal', 'pause']);+ });+it('treats an absent or explicitly-null field as absent, never malformed', () => {expect(validateReasonerResponse({ analysis: 'nothing to propose', proposal: null, pause: null }).invalidFields).toEqual([]);expect(validateReasonerResponse({ proposal: null }).invalidFields).toEqual([]);diff --git a/server/services/layeredIntelligence/proposal.js b/server/services/layeredIntelligence/proposal.jsindex 35f60e02b8..2defadbffb 100644--- a/server/services/layeredIntelligence/proposal.js+++ b/server/services/layeredIntelligence/proposal.js@@ -2,7 +2,8 @@* Layered Intelligence — reasoner-output validation & hand-off shaping* (#2842 split of layeredIntelligence.js).*- * Validates the model's JSON into a `{ analysis, proposal, pause }` triple, resolves+ * Validates the model's JSON into an `{ analysis, proposal, pause, invalidFields }`+ * result (the usable triple plus the malformed-field report, #4166), resolves* the pause target, and decides whether/how a filed proposal becomes an autonomous* CoS hand-off task. Also the tracker→filer dispatch table.*/@@ -28,7 +29,10 @@ import { normalizeSlug } from './dedup.js';* caller deciding whether a run was malformed must not have to re-derive per-field* validity: `{"analysis": 7}` reads as a legitimate empty answer without this.* `null`/`undefined` is ABSENT, not wrong-typed — an explicit `proposal: null` is- * the documented "nothing to propose" answer and never lands here.+ * the documented "nothing to propose" answer and never lands here. Deliberately+ * ONLY `null`: the prompt documents `null` for "not proposing"/"not pausing", so a+ * model emitting `false` or `"none"` instead is a wrong-typed field and is reported+ * (this already matched the pre-#4166 treatment of a `false` proposal).*/export function validateReasonerResponse(parsed) {const out = { analysis: '', proposal: null, pause: null, invalidFields: [] };@@ -58,6 +62,13 @@ export function validateReasonerResponse(parsed) {if (p != null && !out.proposal) out.invalidFields.push('proposal');const pause = parsed.pause;+ // A well-formed `blockOnIssue: "this"` pause is dropped as COLLATERAL when the+ // proposal it pointed at was itself supplied-but-invalid. The pause isn't the+ // malformed part, so it doesn't earn its own `invalidFields` entry — one root+ // cause, one report. With no proposal supplied at all, `"this"` points at nothing+ // and the pause IS malformed. Either way `invalidFields` is already non-empty, so+ // this only sharpens the report, never the malformed/clean verdict.+ let pauseCollateral = false;if (pause && typeof pause === 'object' && !Array.isArray(pause)) {const reason = typeof pause.reason === 'string' ? pause.reason.trim() : '';const target = pause.blockOnIssue;@@ -66,9 +77,11 @@ export function validateReasonerResponse(parsed) {// "this" requires a surviving proposal to block on; else an explicit issue number.if (reason && ((isThis && out.proposal) || num)) {out.pause = { blockOnIssue: isThis ? 'this' : num, reason };+ } else if (reason && isThis) {+ pauseCollateral = out.invalidFields.includes('proposal');}}- if (pause != null && !out.pause) out.invalidFields.push('pause');+ if (pause != null && !out.pause && !pauseCollateral) out.invalidFields.push('pause');return out;}