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: preserve primary review findings in the contradiction check (#8876)

[._.]/ Adam Eivyd032349317cc
diff --git a/server/lib/goalFidelity.js b/server/lib/goalFidelity.js
index dff2ce7748..86e4e8c743 100644
--- a/server/lib/goalFidelity.js
+++ b/server/lib/goalFidelity.js
@@ -313,9 +313,13 @@ export function mergeOutcomeReview({ number, prState }) {
*/
export function retainedProductionUses(objective, diff) {
const tokens = text => text.match(/[A-Za-z_$][\w$]*(?:[.-][\w$]+)*/g) || [];
- const names = new Set(tokens(objective));
+ const quotedNames = new Set([...objective.matchAll(/(?:^|\s)[`'"]([A-Za-z_$][\w$.-]*)[`'"](?=$|[\s.,;:!?])/g)].map(match => match[1]));
+ // Plain prose words (process, name, config, ...) are not removal targets.
+ // Keep explicitly quoted names and code-shaped identifiers.
+ const names = new Set(tokens(objective).filter(name => quotedNames.has(name) || /[-_.$]|[a-z][A-Z]|[A-Z].*[A-Z]/.test(name)));
const removed = new Set();
const survivors = [];
+ const seen = new Set();
let file = null;
let hunk = null;
let testFile = false;
@@ -335,7 +339,11 @@ export function retainedProductionUses(objective, diff) {
if (line.startsWith('-')) {
for (const name of matches) removed.add(name);
} else if (matches.length) {
- survivors.push({ file, hunk, line: content, identifiers: matches });
+ const key = JSON.stringify([file, hunk, content]);
+ if (!seen.has(key)) {
+ seen.add(key);
+ survivors.push({ file, hunk, line: content, identifiers: matches });
+ }
}
}
}
diff --git a/server/services/codeReview.js b/server/services/codeReview.js
index a3a8f17aa5..4336513265 100644
--- a/server/services/codeReview.js
+++ b/server/services/codeReview.js
@@ -1107,7 +1107,9 @@ export async function runLocalGoalFidelityReview({ backend, model, objective, di
if (!verdict) {
return { ok: false, backend, model: result.model, error: `${backend} returned no usable goal-fidelity verdict.` }
}
- if (verdict.verdict === 'ship') {
+ // Also sharpen an advisory fix-first: its original rationale can overlook
+ // the contradiction. A rethink already holds the run and is never replaced.
+ if (verdict.verdict !== 'rethink') {
const retained = retainedProductionUses(trimmedObjective, trimmedDiff)
if (retained.length) {
const evidence = JSON.stringify(retained)
@@ -1134,7 +1136,16 @@ export async function runLocalGoalFidelityReview({ backend, model, objective, di
const parsedAudit = extractJson(audit.content, { shapePredicate: value => value !== null && typeof value === 'object' && !Array.isArray(value) }).value
const auditedVerdict = normalizeGoalFidelityVerdict(parsedAudit)
if (!auditedVerdict) return { ok: false, backend, model: result.model, error: 'No usable production evidence verdict.' }
- if (auditedVerdict.verdict !== 'ship') Object.assign(verdict, auditedVerdict)
+ if (auditedVerdict.verdict !== 'ship') {
+ // This narrow check has no tests or scope diff. Preserve the primary
+ // verification/scope assessment and add only its production finding.
+ const findings = auditedVerdict.missing.length ? auditedVerdict.missing : [auditedVerdict.evidence].filter(Boolean)
+ Object.assign(verdict, normalizeGoalFidelityVerdict({
+ ...verdict,
+ verdict: auditedVerdict.verdict,
+ missing: [...new Set([...findings, ...verdict.missing])],
+ }))
+ }
}
}
return {
diff --git a/server/services/codeReview.test.js b/server/services/codeReview.test.js
index b15fcdc402..95722e9202 100644
--- a/server/services/codeReview.test.js
+++ b/server/services/codeReview.test.js
@@ -1050,7 +1050,7 @@ describe('codeReview helpers', () => {
// Transport/contract regression; the opt-in real-model test below checks judgement.
it.each(manifestCases)('preserves the bounded manifest calibration and verdict: %s', async (_name, diff, verdict) => {
- global.fetch = vi.fn(async (_url, init) => {
+ global.fetch = vi.fn().mockImplementationOnce(async (_url, init) => {
const { messages } = JSON.parse(init.body)
expect(messages[1].content).toContain(processManifestCase.objective)
expect(messages[1].content).toContain(diff.trim())
@@ -1065,7 +1065,7 @@ describe('codeReview helpers', () => {
verdict, missing: verdict === 'ship' ? [] : ['complete production manifest removal'],
unrequested: [], evidence: 'Registry regression assertions are present only in cases carrying the test diff.',
}) } }] })
- })
+ }).mockResolvedValue(completion({ ...rejection, verdict }))
const result = await runLocalGoalFidelityReview({ backend: 'ollama', model: 'example-model', objective: processManifestCase.objective, diff })
expect(result).toMatchObject({ ok: true, verdict })
})
@@ -1100,7 +1100,7 @@ describe('codeReview helpers', () => {
it('independently checks surviving production evidence before returning a primary ship', async () => {
global.fetch = vi.fn().mockResolvedValueOnce(completion(shipVerdict)).mockResolvedValueOnce(completion(rejection))
const result = await runLocalGoalFidelityReview({ backend: 'ollama', model: 'example-model', objective: removalObjective, diff: incompleteRemoval })
- expect(result).toMatchObject({ ok: true, ...rejection })
+ expect(result).toMatchObject({ ok: true, ...rejection, evidence: shipVerdict.evidence })
expect(global.fetch).toHaveBeenCalledTimes(2)
const audit = JSON.parse(global.fetch.mock.calls[1][1].body)
expect(audit).not.toHaveProperty('tools')
@@ -1120,13 +1120,37 @@ describe('codeReview helpers', () => {
expect(global.fetch).toHaveBeenCalledTimes(2)
})
- it.each(['rethink', 'fix-first'])('preserves the primary %s without spending another provider call', async verdict => {
- global.fetch = vi.fn().mockResolvedValue(completion({ ...rejection, verdict }))
+ it('adds the contradiction without replacing the primary scope or verification assessment', async () => {
+ const primary = { verdict: 'fix-first', missing: ['a required retry'], unrequested: ['an unrelated feature'], evidence: 'No verification was supplied.' }
+ global.fetch = vi.fn().mockResolvedValueOnce(completion(primary)).mockResolvedValueOnce(completion({ ...rejection, missing: [] }))
const result = await runLocalGoalFidelityReview({ backend: 'ollama', model: 'example-model', objective: removalObjective, diff: incompleteRemoval })
- expect(result).toMatchObject({ ok: true, verdict })
+ expect(result).toMatchObject({ ok: true, verdict: 'fix-first', missing: [rejection.evidence, ...primary.missing], unrequested: primary.unrequested, evidence: primary.evidence })
+ })
+
+ it('does not turn repeated generic objective words into production checks', async () => {
+ global.fetch = vi.fn().mockResolvedValue(completion(shipVerdict))
+ const result = await runLocalGoalFidelityReview({
+ backend: 'ollama', model: 'example-model', objective: 'Update the process config name',
+ diff: 'diff --git a/runtime.js b/runtime.js\n+++ b/runtime.js\n@@ -1,2 +1,1 @@\n-process config name\n process config name',
+ })
+ expect(result).toMatchObject({ ok: true, ...shipVerdict })
expect(global.fetch).toHaveBeenCalledTimes(1)
})
+ it('preserves a primary rethink without spending another provider call', async () => {
+ global.fetch = vi.fn().mockResolvedValue(completion({ ...rejection, verdict: 'rethink' }))
+ const result = await runLocalGoalFidelityReview({ backend: 'ollama', model: 'example-model', objective: removalObjective, diff: incompleteRemoval })
+ expect(result).toMatchObject({ ok: true, verdict: 'rethink' })
+ expect(global.fetch).toHaveBeenCalledTimes(1)
+ })
+
+ it('preserves a primary fix-first even when the surviving-use check ships', async () => {
+ global.fetch = vi.fn().mockResolvedValueOnce(completion(rejection)).mockResolvedValueOnce(completion(shipVerdict))
+ const result = await runLocalGoalFidelityReview({ backend: 'ollama', model: 'example-model', objective: removalObjective, diff: incompleteRemoval })
+ expect(result).toMatchObject({ ok: true, ...rejection })
+ expect(global.fetch).toHaveBeenCalledTimes(2)
+ })
+
it.each(['transport', 'malformed'])('does not fall back to ship when the production check fails: %s', async failure => {
global.fetch = vi.fn().mockResolvedValueOnce(completion(shipVerdict))
if (failure === 'transport') global.fetch.mockRejectedValueOnce(new Error('connection lost'))
@@ -1143,7 +1167,7 @@ describe('codeReview helpers', () => {
`+++ b/${'x'.repeat(300)}.js`,
'@@ -1,201 +1,200 @@',
'-retired-worker',
- ...Array(200).fill(' retired-worker'),
+ ...Array.from({ length: 200 }, (_, index) => ` retired-worker + ${index}`),
].join('\n')
global.fetch = vi.fn().mockResolvedValue(completion(shipVerdict))
const result = await runLocalGoalFidelityReview({ backend: 'ollama', model: 'example-model', objective: removalObjective, diff })
@@ -1171,8 +1195,10 @@ describe('codeReview helpers', () => {
if (expected === 'ship') expect(result).toMatchObject({ verdict: 'ship', missing: [], unrequested: [] })
else expect(['fix-first', 'rethink'], JSON.stringify(result)).toContain(result.verdict)
if (_name === 'runtime process entry retained') {
- expect([...result.missing, result.evidence].join(' ')).toMatch(/portos-ui/i)
- expect([...result.missing, result.evidence].join(' ')).toMatch(/apps\.js|runtime|processes/i)
+ const explanation = [...result.missing, result.evidence].join(' ')
+ expect(explanation).toMatch(/portos-ui/i)
+ expect(explanation).toMatch(/apps\.js|runtime/i)
+ expect(explanation).toMatch(/retain|remain|surviv|still|contradict/i)
}
}, 190_000)