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
Give required review-hub holds a permanent resolve button (#8007)
[._.]/ Adam Eivy1cbc0b00db28
diff --git a/server/lib/notificationTypes.js b/server/lib/notificationTypes.jsindex 8c6417a7ed..50bad2dda6 100644--- a/server/lib/notificationTypes.js+++ b/server/lib/notificationTypes.js@@ -49,7 +49,7 @@ export const NOTIFICATION_ACTION_POLICY = Object.freeze({actionKind: 'content.review',referenceFields: ['prNumber', 'reviewId', 'referenceId'],required: true,- operations: [{ id: 'review', label: 'Review', available: false }],+ operations: [{ id: 'complete', label: 'Mark resolved', available: true }],},[NOTIFICATION_TYPES.PLAN_QUESTION]: {label: 'Plan question',@@ -59,7 +59,7 @@ export const NOTIFICATION_ACTION_POLICY = Object.freeze({referenceFields: ['agentId', 'appId', 'referenceId'],fallbackDrillTo: '/cos',required: true,- operations: [{ id: 'review', label: 'Review', available: false }],+ operations: [{ id: 'complete', label: 'Mark resolved', available: true }],},[NOTIFICATION_TYPES.AUTOPILOT_PAUSED]: {label: 'Paused automation',@@ -69,7 +69,7 @@ export const NOTIFICATION_ACTION_POLICY = Object.freeze({referenceFields: ['autopilotPauseSeriesId', 'runId'],compoundReference: true,required: true,- operations: [{ id: 'resume', label: 'Resume', available: false }],+ operations: [{ id: 'complete', label: 'Mark resolved', available: true }],},});diff --git a/server/services/review.js b/server/services/review.jsindex 02a3dce334..a015d95eac 100644--- a/server/services/review.js+++ b/server/services/review.js@@ -579,7 +579,7 @@ async function updateStatusByReferenceId(referenceId, status) {const items = await loadItems();const matching = items.filter(i => i.metadata?.referenceId === referenceId && i.status === 'pending');- if (matching.length === 0) return;+ if (matching.length === 0) return [];const now = new Date().toISOString();for (const item of matching) {item.status = status;@@ -587,6 +587,7 @@ async function updateStatusByReferenceId(referenceId, status) {}await saveItems(items);for (const item of matching) reviewEvents.emit('item:updated', item);+ return matching;}export const dismissByReferenceId = (referenceId) => updateStatusByReferenceId(referenceId, 'dismissed');diff --git a/server/services/review.test.js b/server/services/review.test.jsindex 0f8b75e62f..e93d0ed7cc 100644--- a/server/services/review.test.js+++ b/server/services/review.test.js@@ -41,6 +41,7 @@ const {completeItem,reopenItem,dismissItem,+ dismissByReferenceId,updateItem,deleteItem,getBriefing,@@ -182,6 +183,31 @@ describe('review service', () => {});expect(atomicWrite).not.toHaveBeenCalled();});++ it('dismissByReferenceId returns the matched items so a caller can tell "resolved" from "nothing to resolve" (#8007)', async () => {+ const items = [{+ id: 'hold-1',+ type: 'alert',+ title: 'Goal-fidelity hold',+ status: 'pending',+ metadata: { referenceId: 'agent-1', category: 'goal-fidelity', sourceOwned: true },+ createdAt: '',+ updatedAt: '',+ }];+ readFile.mockResolvedValue(JSON.stringify(items));++ const matched = await dismissByReferenceId('agent-1');+ expect(matched).toHaveLength(1);+ expect(matched[0]).toMatchObject({ id: 'hold-1', status: 'dismissed' });+ expect(atomicWrite).toHaveBeenCalled();+ });++ it('dismissByReferenceId returns an empty array when no pending item matches', async () => {+ readFile.mockResolvedValue(JSON.stringify([]));++ await expect(dismissByReferenceId('nothing-pending')).resolves.toEqual([]);+ expect(atomicWrite).not.toHaveBeenCalled();+ });});describe('updateItem', () => {diff --git a/server/services/reviewActionAdapters.js b/server/services/reviewActionAdapters.jsindex 0caed48473..e3c9e42c3d 100644--- a/server/services/reviewActionAdapters.js+++ b/server/services/reviewActionAdapters.js@@ -74,7 +74,7 @@ export function adaptStoredReviewItem(item) {required: true,sourceOwned: true,drillTo: link || `/cos/agents/${encodeURIComponent(sourceRef)}`,- operations: [operation('review', 'Review', false)],+ operations: [operation('complete', 'Mark resolved')],meta: { category: 'goal-fidelity' },});}@@ -104,7 +104,7 @@ export function adaptStoredReviewItem(item) {required: true,sourceOwned: true,drillTo: link || '/cos',- operations: [operation('review', 'Review', false)],+ operations: [operation('complete', 'Mark resolved')],meta: { category: 'plan-question' },});}@@ -121,7 +121,7 @@ export function adaptStoredReviewItem(item) {required: true,sourceOwned: true,drillTo: link || `/pipeline/series/${encodeURIComponent(seriesId)}`,- operations: [operation('resume', 'Resume', false)],+ operations: [operation('complete', 'Mark resolved')],meta: { category: 'autopilot-paused' },});}@@ -137,7 +137,7 @@ export function adaptStoredReviewItem(item) {required: true,sourceOwned: true,drillTo: link || '/review',- operations: [operation('review', 'Review', false)],+ operations: [operation('complete', 'Mark resolved')],meta: { category: 'content-review' },});}@@ -155,12 +155,12 @@ export function adaptStoredReviewItem(item) {sourceOwned: true,triageOnly: true,drillTo: link || '/review',- operations: [operation('triage', 'Review', false)],+ operations: [operation('complete', 'Mark resolved')],meta: { category: 'legacy-review-triage', triage: true },});}-const notificationReference = (notification, policy) => {+export const notificationReference = (notification, policy) => {const metadata = notification?.metadata && typeof notification.metadata === 'object'? notification.metadata: {};diff --git a/server/services/reviewActionAdapters.test.js b/server/services/reviewActionAdapters.test.jsindex 625bb82ee6..4b1dd4ebaf 100644--- a/server/services/reviewActionAdapters.test.js+++ b/server/services/reviewActionAdapters.test.js@@ -29,7 +29,7 @@ describe('review action adapters', () => {});});- it('keeps uncorrelated legacy alerts as explicit triage, not generic completion', () => {+ it('gives an uncorrelated legacy alert a permanent resolve, not the generic todo completion', () => {const item = adaptStoredReviewItem({id: 'legacy-1',type: 'alert',@@ -43,7 +43,7 @@ describe('review action adapters', () => {actionKind: 'review.triage',triageOnly: true,sourceOwned: true,- operations: [{ id: 'triage', available: false }],+ operations: [{ id: 'complete', label: 'Mark resolved', available: true }],});});@@ -63,6 +63,25 @@ describe('review action adapters', () => {});});+ it('gives a goal-fidelity hold a permanent resolve operation (#8007)', () => {+ const item = adaptStoredReviewItem({+ id: 'review-3',+ type: 'alert',+ title: 'Goal-fidelity hold: run agent-1 may have built the wrong thing',+ status: 'pending',+ metadata: { referenceId: 'agent-1', category: 'goal-fidelity', agentId: 'agent-1' },+ });++ expect(item).toMatchObject({+ id: 'goal-fidelity:agent-1',+ sourceRef: 'agent-1',+ actionKind: 'goal-fidelity.review',+ required: true,+ sourceOwned: true,+ operations: [{ id: 'complete', label: 'Mark resolved', available: true }],+ });+ });+it('does not admit a paused automation without its series identity', () => {expect(adaptStoredReviewItem({id: 'paused-run-only',@@ -114,4 +133,40 @@ describe('review action adapters', () => {metadata: {},})).toBeNull();});++ it('gives a plan-question notification a permanent resolve operation (#8007)', () => {+ const item = adaptNotification({+ id: 'notification-3',+ type: NOTIFICATION_TYPES.PLAN_QUESTION,+ title: 'Plan question',+ message: 'Choose a direction',+ link: '/apps/example/documents',+ metadata: { agentId: 'agent-1' },+ });++ expect(item).toMatchObject({+ id: 'plan:agent-1',+ sourceRef: 'agent-1',+ required: true,+ operations: [{ id: 'complete', label: 'Mark resolved', available: true }],+ });+ });++ it('gives a paused-autopilot notification a permanent resolve operation (#8007)', () => {+ const item = adaptNotification({+ id: 'notification-4',+ type: NOTIFICATION_TYPES.AUTOPILOT_PAUSED,+ title: 'Autopilot paused',+ description: 'Needs human review',+ link: '/pipeline/series/series-1',+ metadata: { autopilotPauseSeriesId: 'series-1', runId: 'run-1' },+ });++ expect(item).toMatchObject({+ id: 'autopilot:series-1:run-1',+ sourceRef: 'series-1:run-1',+ required: true,+ operations: [{ id: 'complete', label: 'Mark resolved', available: true }],+ });+ });});diff --git a/server/services/reviewQueue.js b/server/services/reviewQueue.jsindex 67ca9e5f19..9a208bf4fb 100644--- a/server/services/reviewQueue.js+++ b/server/services/reviewQueue.js@@ -40,6 +40,7 @@ import * as reviewService from './review.js';import * as notifications from './notifications.js';import * as stackerNews from './stackerNews.js';import * as x from './x.js';+import { NOTIFICATION_ACTION_POLICY } from '../lib/notificationTypes.js';import { ServerError } from '../lib/errorHandler.js';import { safeJSONParse } from '../lib/fileUtils.js';import { getUserTimezone } from './userTimezone.js';@@ -1055,6 +1056,41 @@ async function resolveThreadAction(id, status) {return result;}+/**+ * A required action item may reach the queue as either a stored Review item+ * (`review.createItem`, category-based) or a notification (type-based, see+ * `NOTIFICATION_ACTION_POLICY`) — both are keyed under the same `actionSource`+ * vocabulary, and a queue row never records which origin produced it. Resolve+ * both projections so "Mark resolved" retires the hold regardless of which+ * producer raised it.+ */+async function resolveNotificationHold(actionSource, sourceRef) {+ if (!sourceRef) return [];+ const { notificationReference } = await import('./reviewActionAdapters.js');+ const records = await notifications.getNotifications({ includeHidden: true });+ const matches = (Array.isArray(records) ? records : []).filter((notification) => {+ const policy = NOTIFICATION_ACTION_POLICY[notification.type];+ return policy?.actionSource === actionSource && notificationReference(notification, policy) === sourceRef;+ });+ await Promise.all(matches.map((notification) => notifications.removeNotification(notification.id)));+ return matches;+}++/**+ * Owning primitive for the sourceRef-keyed required holds that have no+ * domain-specific resolution of their own (goal-fidelity, plan questions,+ * content reviews, paused autopilot) — a permanent acknowledge/dismiss, not a+ * change to what the underlying condition means (#8007).+ */+async function resolveSourceOwnedHold(actionSource, sourceRef) {+ const [reviewItems, notificationMatches] = await Promise.all([+ reviewService.dismissByReferenceId(sourceRef),+ resolveNotificationHold(actionSource, sourceRef),+ ]);+ const resolvedCount = (reviewItems?.length || 0) + notificationMatches.length;+ return resolvedCount > 0 ? { resolved: resolvedCount } : null;+}+const SOURCE_ACTIONS = Object.freeze({memory: Object.freeze({approve: (id) => resolveMemoryAction(id, 'approve'),@@ -1085,6 +1121,21 @@ const SOURCE_ACTIONS = Object.freeze({return submitAgentFeedback(id, input);},}),+ 'goal-fidelity': Object.freeze({+ complete: (id) => resolveSourceOwnedHold('goal-fidelity', id),+ }),+ plan: Object.freeze({+ complete: (id) => resolveSourceOwnedHold('plan', id),+ }),+ content: Object.freeze({+ complete: (id) => resolveSourceOwnedHold('content', id),+ }),+ autopilot: Object.freeze({+ complete: (id) => resolveSourceOwnedHold('autopilot', id),+ }),+ review: Object.freeze({+ complete: (id) => reviewService.dismissItem(id),+ }),});export async function resolveQueueItem(queueItemId, operation = 'resolve', input = {}) {diff --git a/server/services/reviewQueue.test.js b/server/services/reviewQueue.test.jsindex 09eadfe5ba..341d0ba6f6 100644--- a/server/services/reviewQueue.test.js+++ b/server/services/reviewQueue.test.js@@ -13,8 +13,8 @@ const messageDrafts = { listDrafts: vi.fn(), approveDraft: vi.fn() };const proactiveAlerts = { generateNonProductAlerts: vi.fn(), resolveHealthAlert: vi.fn() };const productMetrics = { getProductEngagement: vi.fn() };const backup = { getState: vi.fn() };-const reviewService = { getItems: vi.fn(), dismissByReferenceId: vi.fn(), completeItem: vi.fn(), reopenItem: vi.fn() };-const notifications = { getNotifications: vi.fn() };+const reviewService = { getItems: vi.fn(), dismissByReferenceId: vi.fn(), dismissItem: vi.fn(), completeItem: vi.fn(), reopenItem: vi.fn() };+const notifications = { getNotifications: vi.fn(), removeNotification: vi.fn() };// Mocked so the meta-field / buildQueue cases don't pull the brain/cos/identity// stack in transitively (askPromote imports all three). The promoteAskQueueItem// suite drives this mock directly.@@ -91,10 +91,11 @@ function resetEmpty() {productMetrics.getProductEngagement.mockResolvedValue({ actions: [] });backup.getState.mockResolvedValue({ status: 'ok', error: null });reviewService.getItems.mockResolvedValue([]);- reviewService.dismissByReferenceId.mockResolvedValue(undefined);+ reviewService.dismissByReferenceId.mockResolvedValue([]);reviewService.completeItem.mockResolvedValue({ id: 'todo-1', status: 'completed' });reviewService.reopenItem.mockResolvedValue({ id: 'todo-1', status: 'pending' });notifications.getNotifications.mockResolvedValue([]);+ notifications.removeNotification.mockResolvedValue({ success: true });identity.getGoals.mockResolvedValue({ goals: [] });stackerNews.listPendingReviewActions.mockResolvedValue([]);x.listPendingReviewActions.mockResolvedValue([]);@@ -576,7 +577,7 @@ describe('reviewQueue.buildQueue', () => {source: 'notifications',actionKind: 'plan.question',summary: 'Choose a direction',- operations: [{ id: 'review', available: false }],+ operations: [{ id: 'complete', label: 'Mark resolved', available: true }],});expect(queue.items.find(item => item.id === 'briefing:briefing-notification')).toBeUndefined();});@@ -1322,4 +1323,63 @@ describe('reviewQueue.resolveQueueItem', () => {cosTaskStore.approveTask.mockResolvedValue({ error: 'Task does not require approval' });await expect(resolveQueueItem('cos:sys-1')).rejects.toMatchObject({ status: 409 });});++ it('permanently resolves a goal-fidelity hold by dismissing the stored obligation (#8007)', async () => {+ reviewService.dismissByReferenceId.mockResolvedValue([{ id: 'review-1', status: 'dismissed' }]);+ notifications.getNotifications.mockResolvedValue([]);++ const result = await resolveQueueItem('goal-fidelity:agent-1', 'complete');++ expect(reviewService.dismissByReferenceId).toHaveBeenCalledWith('agent-1');+ expect(result).toMatchObject({ source: 'goal-fidelity', id: 'goal-fidelity:agent-1', operation: 'complete', resolved: true });+ });++ it('resolves a plan-question hold by retiring its notification, not just the stored item', async () => {+ reviewService.dismissByReferenceId.mockResolvedValue([]);+ notifications.getNotifications.mockResolvedValue([+ { id: 'plan-notification', type: 'plan_question', metadata: { agentId: 'agent-1' } },+ { id: 'other-notification', type: 'plan_question', metadata: { agentId: 'other-agent' } },+ ]);++ await expect(resolveQueueItem('plan:agent-1', 'complete')).resolves.toMatchObject({ resolved: true });++ expect(notifications.removeNotification).toHaveBeenCalledTimes(1);+ expect(notifications.removeNotification).toHaveBeenCalledWith('plan-notification');+ });++ it('resolves an autopilot-paused hold keyed on its compound seriesId:runId reference', async () => {+ reviewService.dismissByReferenceId.mockResolvedValue([]);+ notifications.getNotifications.mockResolvedValue([+ { id: 'pause-notification', type: 'autopilot_paused', metadata: { autopilotPauseSeriesId: 'series-1', runId: 'run-1' } },+ ]);++ await resolveQueueItem('autopilot:series-1:run-1', 'complete');++ expect(reviewService.dismissByReferenceId).toHaveBeenCalledWith('series-1:run-1');+ expect(notifications.removeNotification).toHaveBeenCalledWith('pause-notification');+ });++ it('resolves a content-review hold from its stored review item', async () => {+ reviewService.dismissByReferenceId.mockResolvedValue([{ id: 'review-2', status: 'dismissed' }]);+ notifications.getNotifications.mockResolvedValue([]);++ await expect(resolveQueueItem('content:malware-scan:report-1', 'complete')).resolves.toMatchObject({ resolved: true });+ expect(reviewService.dismissByReferenceId).toHaveBeenCalledWith('malware-scan:report-1');+ });++ it('404s a source-owned hold complete when nothing matches (already resolved elsewhere)', async () => {+ reviewService.dismissByReferenceId.mockResolvedValue([]);+ notifications.getNotifications.mockResolvedValue([]);++ await expect(resolveQueueItem('goal-fidelity:gone', 'complete')).rejects.toMatchObject({ status: 404 });+ });++ it('resolves a legacy uncorrelated alert by dismissing it by its own id', async () => {+ reviewService.dismissItem.mockResolvedValue({ id: 'legacy-1', status: 'dismissed' });++ await expect(resolveQueueItem('review:legacy-1', 'complete')).resolves.toMatchObject({+ source: 'review', operation: 'complete', resolved: true,+ });+ expect(reviewService.dismissItem).toHaveBeenCalledWith('legacy-1');+ });});