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
fix([issue-12584]): name withheld assessment codes and re-arm on policy save
[._.]/ Adam Eivydf2e8d549cea
diff --git a/client/src/components/models/ModelAbuseGuardPanel.jsx b/client/src/components/models/ModelAbuseGuardPanel.jsxindex 6a936817da..31554754b4 100644--- a/client/src/components/models/ModelAbuseGuardPanel.jsx+++ b/client/src/components/models/ModelAbuseGuardPanel.jsx@@ -103,6 +103,7 @@ export default function ModelAbuseGuardPanel() {});const currentStageId = installingStage || (installing ? stages.find((stage) => !stage.ready)?.id : null);const overallReady = guardStatus?.ready === true;+ const contributionBlocked = guardStatus?.contributionAssessment?.ready === false;const incomplete = guardStatus?.setupState === 'incomplete' || (!overallReady && (guardStatus?.modelCached || guardStatus?.venvReady));return (@@ -121,7 +122,9 @@ export default function ModelAbuseGuardPanel() {<p className="text-xs text-port-accent mt-0.5">Required by default · local classifier</p></div></div>- {overallReady ? (+ {contributionBlocked && overallReady ? (+ <span className="text-xs px-2 py-1 rounded border border-port-warning/40 text-port-warning">Not ready</span>+ ) : overallReady ? (<span className="text-xs px-2 py-1 rounded border border-port-success/40 text-port-success">Ready</span>) : guardStatus ? (<span className="text-xs px-2 py-1 rounded border border-port-warning/40 text-port-warning">{incomplete ? 'Setup incomplete' : 'Not installed'}</span>diff --git a/client/src/components/models/ModelAbuseGuardPanel.test.jsx b/client/src/components/models/ModelAbuseGuardPanel.test.jsxindex bce505bb1a..285f0a0a57 100644--- a/client/src/components/models/ModelAbuseGuardPanel.test.jsx+++ b/client/src/components/models/ModelAbuseGuardPanel.test.jsx@@ -64,6 +64,7 @@ describe('ModelAbuseGuardPanel', () => {contributionAssessment: { ready: false, code: 'untrusted-content-model-required' } });await renderPanel();expect(await screen.findByText(/assessment is not ready \(untrusted-content-model-required\)/)).toBeInTheDocument();+ expect(screen.getByText('Not ready').className).toContain('text-port-warning');});it('offers repair for partial setup and disables installation without Python', async () => {diff --git a/server/routes/settings.js b/server/routes/settings.jsindex f28c7ccca3..75d7d69a22 100644--- a/server/routes/settings.js+++ b/server/routes/settings.js@@ -781,6 +781,11 @@ const saveSettingsPatch = async (body, slicePatch) => {// already emitted it — so an added/removed/edited schedule takes effect// immediately without a restart, and this route stays decoupled from the// autopilot pipeline graph.+ if (settingsPatch.untrustedContent !== undefined) {+ const { clearPendingMergeAssessmentHolds } = await import('../services/prWatcher.js');+ await clearPendingMergeAssessmentHolds()+ .catch((err) => console.error(`❌ Could not re-arm pending-merge assessments after a policy save: ${err.message}`));+ }return sanitizeSettingsForResponse(merged);};diff --git a/server/routes/settings.test.js b/server/routes/settings.test.jsindex 425c546982..fc11efc245 100644--- a/server/routes/settings.test.js+++ b/server/routes/settings.test.js@@ -25,6 +25,9 @@ afterAll(async () => {const reconcileEidoverseRuntime = vi.hoisted(() => vi.fn(async () => ({ running: true })));vi.mock('../services/eidoverseRuntime.js', () => ({ reconcileEidoverseRuntime }));+const clearPendingMergeAssessmentHolds = vi.hoisted(() => vi.fn(async () => {}));+vi.mock('../services/prWatcher.js', () => ({ clearPendingMergeAssessmentHolds }));+// In-memory settings store backing the mocked service.let store = {};@@ -193,6 +196,7 @@ describe('Settings routes — untrusted-content policy', () => {const saved = await request(buildApp()).put('/api/settings').send({ untrustedContent: policy });expect(saved.status).toBe(200);expect(store.untrustedContent).toEqual(policy);+ expect(clearPendingMergeAssessmentHolds).toHaveBeenCalledTimes(1);const read = await request(buildApp()).get('/api/settings');expect(read.body.untrustedContent.sources).toEqual(policy.sources);});@@ -211,6 +215,7 @@ describe('Settings routes — untrusted-content policy', () => {expect(store).toEqual(previous);}expect(updateSettingsWith).not.toHaveBeenCalled();+ expect(clearPendingMergeAssessmentHolds).not.toHaveBeenCalled();});});diff --git a/server/services/prWatcher.js b/server/services/prWatcher.jsindex 71c6fd7329..5ab5c7a03d 100644--- a/server/services/prWatcher.js+++ b/server/services/prWatcher.js@@ -288,6 +288,24 @@ async function mutatePendingMergePrs(appId, mutate) {});}+// A policy save re-arms withheld merges even when the saved JSON is unchanged:+// the usual fix is a provider default model, which is not part of the policy+// document. Only an attention string that names the withheld code is cleared.+export async function clearPendingMergeAssessmentHolds() {+ const apps = await getActiveApps().catch(() => []);+ for (const app of apps) {+ if (!readPendingMergePrs(app).some((entry) => entry?.assessmentWithheld)) continue;+ await mutatePendingMergePrs(app.id, (current) => current.map((entry) => {+ const held = entry?.assessmentWithheld;+ if (!held) return entry;+ const { assessmentWithheld: _held, attention, ...rest } = entry;+ const heldCode = typeof held.code === 'string' ? held.code : '';+ if (typeof attention === 'string' && heldCode && attention.includes(heldCode)) return rest;+ return attention === undefined ? rest : { ...rest, attention };+ }));+ }+}+/*** Persist a merge-only PR for the next existing pr-watcher tick. The source* task carries only the fields the escalation path needs to recreate today's@@ -676,14 +694,16 @@ async function runPendingMergePrs(app, { spendTicks, receipts = null }) {readIssue: async (number) => safeJSONParse(await execGh(['api', '--hostname', githubApiHost(origin.host), `repos/${origin.fullName}/issues/${number}`,], undefined, { ...forgeExec, backoffKey: repoSpec }).catch(() => null), null),- }).catch((err) => {- console.warn(`⚠️ Contribution assessment for PR #${entry.prNumber} threw: ${err.message}`);- return { ok: false, code: 'security-action-assessment-error' };- });+ }).catch(() => ({ ok: false, code: 'security-action-assessment-error' }));if (!assessment.ok) {const code = assessment.code || 'security-action-assessment-unavailable';const detail = assessment.cause ? `${code}: ${assessment.cause}` : code;- withheldReason = `the complete current contribution assessment was unavailable or withheld (${detail})`;+ // `message` is server-authored. A thrown error's message is not: it can+ // echo the contribution, so the catch above records only the code.+ const message = typeof assessment.message === 'string'+ ? assessment.message.replace(/[\r\n]+/g, ' ').trim().slice(0, 240)+ : '';+ withheldReason = message ? `${detail} — ${message}` : detail;// Evidence, mutable-state, transport and provider-readiness failures// can clear on a retry of the same head; only a stable outcome of this// head under this configuration is cached.@@ -712,7 +732,8 @@ async function runPendingMergePrs(app, { spendTicks, receipts = null }) {}const merge = admitted.result;if (merge.ownerDeferred || merge.ownerBlocked) {- outcomes.set(key, merge.ownerBlocked ? { ...entry, recoveryBlocked: merge.ownerBlocked } : entry);+ const retained = assessmentWithheld ? { ...entry, assessmentWithheld } : entry;+ outcomes.set(key, merge.ownerBlocked ? { ...retained, recoveryBlocked: merge.ownerBlocked } : retained);result.waiting = (result.waiting || 0) + 1;if (merge.ownerBlocked) await notifyPendingMergeTimeout(app, entry, null,`PR #${entry.prNumber} remains owned by task ${binding.taskId}: ${merge.ownerBlocked}.`);diff --git a/server/services/prWatcher.test.js b/server/services/prWatcher.test.jsindex a59cc288b2..ec073a11d7 100644--- a/server/services/prWatcher.test.js+++ b/server/services/prWatcher.test.js@@ -68,6 +68,11 @@ vi.mock('./apps.js', () => ({}),}));+const tasksById = vi.hoisted(() => new Map());+vi.mock('./cosTaskStore.js', () => ({+ getTaskById: async (id) => tasksById.get(id) ?? null,+}));+const getOriginInfoMock = vi.fn();vi.mock('../lib/gitRemote.js', () => ({getOriginInfo: (...args) => getOriginInfoMock(...args),@@ -83,6 +88,7 @@ import {queuePendingMerge,isPendingMergeReady,processPendingMergePrs,+ clearPendingMergeAssessmentHolds,sweepPendingMergePrs,MAX_PENDING_MERGE_TICKS,checkPullRequests,@@ -114,6 +120,7 @@ beforeEach(() => {spawnReviewLoopFollowUpMock.mockResolvedValue({ id: 'follow-up-1' });getOriginInfoMock.mockReset();mockApps.clear();+ tasksById.clear();__resetSelfLoginCache();});@@ -308,43 +315,58 @@ describe('merge-only PR watcher', () => {describe('a withheld contribution assessment', () => {const modelRequired = { ok: false, code: 'untrusted-content-model-required', message: 'No eligible API provider has a default model.' };+ const head = 'a'.repeat(40);+ const handoff = (headSha = head) => ({+ headSha, repository: 'github.com/o/r', agentId: 'agent-88', taskId: 'task-88',+ receiptId: 'receipt-88', prCompletion: 'merge-on-green',+ });+ const armOwner = () => {+ tasksById.set('task-88', { id: 'task-88', status: 'completed', metadata: { prCompletion: 'merge-on-green' } });+ };const sweep = async (app) => {const logged = vi.spyOn(console, 'error').mockImplementation(() => {});try { return { result: await processPendingMergePrs(app), lines: logged.mock.calls.map(call => String(call[0])) }; }finally { logged.mockRestore(); }};- it('names the assessment code in the log line and the deadline notification', async () => {- const app = pendingApp([pendingMerge({ ticks: MAX_PENDING_MERGE_TICKS - 1 })]);+ it('names the assessment code in the log line, attention, and the deadline notification', async () => {+ const app = pendingApp([pendingMerge({ ticks: MAX_PENDING_MERGE_TICKS - 1, handoff: handoff() })]);mockApps.set(app.id, app);+ armOwner();installPendingEvidence();screenMock.mockResolvedValue(modelRequired);const { lines } = await sweep(app);- expect(lines.some(line => line.includes('Deterministic merge failed for PR #88') && line.includes('untrusted-content-model-required'))).toBe(true);+ const kept = readPendingMergePrs(mockApps.get(app.id))[0];+ expect(lines.some(line => line.includes('Deterministic merge failed for PR #88') && line.includes('untrusted-content-model-required')+ && !line.includes('assessment was unavailable or withheld'))).toBe(true);+ expect(kept.attention).toContain('untrusted-content-model-required');expect(addNotificationMock).toHaveBeenCalledWith(expect.objectContaining({description: expect.stringContaining('untrusted-content-model-required'),}));});- it('reports a thrown assessment as security-action-assessment-error', async () => {+ it('reports a thrown assessment as security-action-assessment-error without logging the error text', async () => {const app = pendingApp();mockApps.set(app.id, app);installPendingEvidence();- screenMock.mockRejectedValue(new Error('boom'));+ screenMock.mockRejectedValue(new Error('contribution body must stay out of the log'));const warned = vi.spyOn(console, 'warn').mockImplementation(() => {});const { lines } = await sweep(app);warned.mockRestore();expect(lines.some(line => line.includes('security-action-assessment-error'))).toBe(true);+ expect(lines.some(line => line.includes('contribution body must stay out of the log'))).toBe(false);+ expect(warned.mock.calls.some(call => String(call[0]).includes('contribution body must stay out of the log'))).toBe(false);});it('is not re-assessed, and takes no admission lease, while the head and policy are unchanged', async () => {- const app = pendingApp();+ const app = pendingApp([pendingMerge({ handoff: handoff() })]);mockApps.set(app.id, app);+ armOwner();installPendingEvidence();screenMock.mockResolvedValue(modelRequired);await sweep(app);expect(screenMock).toHaveBeenCalledTimes(1);- expect(readPendingMergePrs(mockApps.get(app.id))[0].assessmentWithheld).toMatchObject({ headSha: 'a'.repeat(40), policy: 'policy-1' });+ expect(readPendingMergePrs(mockApps.get(app.id))[0].assessmentWithheld).toMatchObject({ headSha: head, policy: 'policy-1' });// A live parent holding the lease would defer any entry that asked for it.const { claimMergeAdmission } = await import('./cosMergeAdmission.js');@@ -359,6 +381,58 @@ describe('merge-only PR watcher', () => {await claimMergeAdmission({ agentId: 'parent', action: 'release', token: lease.token, outcome: 'leave-open' });});+ it('re-arms a bound entry when the policy is saved again without a fingerprint change', async () => {+ const app = pendingApp([pendingMerge({ ticks: MAX_PENDING_MERGE_TICKS - 1, handoff: handoff() })]);+ mockApps.set(app.id, app);+ armOwner();+ installPendingEvidence();+ screenMock.mockResolvedValue(modelRequired);+ await sweep(app);+ const withheld = readPendingMergePrs(mockApps.get(app.id))[0];+ expect(withheld.assessmentWithheld).toMatchObject({ headSha: head, policy: 'policy-1', code: expect.stringContaining('untrusted-content-model-required') });+ expect(withheld.attention).toContain('untrusted-content-model-required');+ await clearPendingMergeAssessmentHolds();+ const cleared = readPendingMergePrs(mockApps.get(app.id))[0];+ expect(cleared.assessmentWithheld).toBeUndefined();+ expect(cleared.attention).toBeUndefined();+ expect(cleared.handoff.headSha).toBe(head);+ screenMock.mockResolvedValue({ ok: true, screening: { safe: true } });+ mergePrMock.mockResolvedValue({ success: true });+ expect(await processPendingMergePrs(mockApps.get(app.id))).toMatchObject({ merged: 1 });+ expect(screenMock).toHaveBeenCalledTimes(2);+ });++ it('keeps an unrelated attention when a policy save clears the assessment hold', async () => {+ const app = pendingApp([pendingMerge({+ handoff: handoff(),+ attention: 'forge-unreadable',+ assessmentWithheld: { headSha: head, code: 'untrusted-content-model-required', policy: 'policy-1', reason: 'untrusted-content-model-required' },+ })]);+ mockApps.set(app.id, app);+ await clearPendingMergeAssessmentHolds();+ const kept = readPendingMergePrs(mockApps.get(app.id))[0];+ expect(kept.assessmentWithheld).toBeUndefined();+ expect(kept.attention).toBe('forge-unreadable');+ });++ it('re-arms a bound entry when the handed-off head moves', async () => {+ const app = pendingApp([pendingMerge({ handoff: handoff() })]);+ mockApps.set(app.id, app);+ armOwner();+ const evidence = installPendingEvidence();+ screenMock.mockResolvedValue(modelRequired);+ await sweep(app);+ const nextHead = 'b'.repeat(40);+ const stored = readPendingMergePrs(mockApps.get(app.id))[0];+ expect(stored.assessmentWithheld.headSha).toBe(head);+ mockApps.set(app.id, { ...mockApps.get(app.id), pendingMergePrs: [{ ...stored, handoff: handoff(nextHead) }] });+ evidence.pr.headRefOid = nextHead;+ screenMock.mockResolvedValue({ ok: true, screening: { safe: true } });+ mergePrMock.mockResolvedValue({ success: true });+ expect(await processPendingMergePrs(mockApps.get(app.id))).toMatchObject({ merged: 1 });+ expect(screenMock).toHaveBeenCalledTimes(2);+ });+it.each([['a changed policy', () => fingerprintMock.mockResolvedValue('policy-2'), () => {}],['a new head', () => {}, (e) => { e.pr.headRefOid = 'b'.repeat(40); }],@@ -439,7 +513,7 @@ describe('merge-only PR watcher', () => {screenMock.mockRejectedValue(new Error('Provider unavailable'));expect(await processPendingMergePrs(app)).toMatchObject({ merged: 0, timedOut: 1 });expect(addNotificationMock).toHaveBeenCalledWith(expect.objectContaining({- description: expect.stringContaining('assessment was unavailable or withheld'),+ description: expect.stringContaining('security-action-assessment-error'),}));expect(readPendingMergePrs(mockApps.get(app.id))).toEqual([]);});