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 (codex): gate Ask review-queue rows on assistant-turn presence
Adam Eivy273a3ea8f31c
diff --git a/server/services/askConversations.js b/server/services/askConversations.jsindex e8a2f9fb18..1465a58a2b 100644--- a/server/services/askConversations.js+++ b/server/services/askConversations.js@@ -150,6 +150,13 @@ export async function listConversations({ limit = 50 } = {}) {createdAt: conv.createdAt,updatedAt: conv.updatedAt,turnCount: Array.isArray(conv.turns) ? conv.turns.length : 0,+ // Count assistant turns separately: a conversation can have turns+ // (turnCount > 0) with only a user turn when an Ask stream errors or the+ // client disconnects before any assistant text is persisted. Promotion+ // needs an assistant answer, so consumers must gate on this, not turnCount.+ assistantTurnCount: Array.isArray(conv.turns)+ ? conv.turns.filter((t) => t?.role === 'assistant').length+ : 0,promoted: !!conv.promoted,});}diff --git a/server/services/askConversations.test.js b/server/services/askConversations.test.jsindex a5a888591d..0b9bcd6600 100644--- a/server/services/askConversations.test.js+++ b/server/services/askConversations.test.js@@ -130,6 +130,25 @@ describe('askConversations', () => {expect(summaries[0].turnCount).toBe(1);});+ it('counts assistant turns separately from total turns', async () => {+ // A user-only conversation (e.g. the assistant stream errored before any+ // answer persisted) has turnCount > 0 but no assistant turn — consumers+ // that offer promote-to-target must gate on assistantTurnCount.+ const userOnly = await convs.createConversation({ title: 'user only' });+ await convs.appendTurn(userOnly.id, { role: 'user', content: 'q with no answer' });+ const answered = await convs.createConversation({ title: 'answered' });+ await convs.appendTurn(answered.id, { role: 'user', content: 'q' });+ await convs.appendTurn(answered.id, { role: 'assistant', content: 'a' });++ const summaries = await convs.listConversations();+ const u = summaries.find((s) => s.id === userOnly.id);+ const a = summaries.find((s) => s.id === answered.id);+ expect(u.turnCount).toBe(1);+ expect(u.assistantTurnCount).toBe(0);+ expect(a.turnCount).toBe(2);+ expect(a.assistantTurnCount).toBe(1);+ });+it('prunes non-promoted conversations older than 30 days', async () => {const stale = await convs.createConversation({ title: 'stale' });// Backdate the file by writing a stale updatedAt. We cheat by re-savingdiff --git a/server/services/reviewQueue.js b/server/services/reviewQueue.jsindex 9bffca7317..bcf79c9340 100644--- a/server/services/reviewQueue.js+++ b/server/services/reviewQueue.js@@ -127,9 +127,14 @@ const PRODUCERS = [// goal via a picker (see map() below). Drilling into /ask still works for a// per-turn promote the queue's latest-turn shortcut doesn't cover.async gather() {- // Conversations with content that haven't been promoted to brain/task/goal.+ // Conversations with a promotable assistant answer that haven't been+ // promoted to brain/task/goal. Gate on assistantTurnCount, NOT turnCount:+ // an Ask conversation whose stream errored (or whose client disconnected)+ // before the assistant turn persisted still has the user turn (turnCount+ // > 0), but promoteLatestAssistantTurn would fail with NO_ASSISTANT_TURN —+ // so advertising a promote action on it would be a dead-end button.const convs = await askConversations.listConversations({ limit: PER_SOURCE_LIMIT * 2 });- return convs.filter(c => !c.promoted && (c.turnCount || 0) > 0);+ return convs.filter(c => !c.promoted && (c.assistantTurnCount || 0) > 0);},// Inline promote targets the UI can offer without a per-turn drill-down.// The queue picks the conversation's latest assistant turn server-side, sodiff --git a/server/services/reviewQueue.test.js b/server/services/reviewQueue.test.jsindex cda1bd69b8..df6b7f401c 100644--- a/server/services/reviewQueue.test.js+++ b/server/services/reviewQueue.test.js@@ -68,11 +68,15 @@ describe('reviewQueue.buildQueue', () => {});});- it('only surfaces unpromoted ask conversations with content', async () => {+ it('only surfaces unpromoted ask conversations that have an assistant answer', async () => {askConversations.listConversations.mockResolvedValue([- { id: 'a1', title: 'has content', promoted: false, turnCount: 2, updatedAt: '2026-06-03T10:00:00.000Z' },- { id: 'a2', title: 'already promoted', promoted: true, turnCount: 3 },- { id: 'a3', title: 'no turns', promoted: false, turnCount: 0 }+ { id: 'a1', title: 'has content', promoted: false, turnCount: 2, assistantTurnCount: 1, updatedAt: '2026-06-03T10:00:00.000Z' },+ { id: 'a2', title: 'already promoted', promoted: true, turnCount: 3, assistantTurnCount: 2 },+ { id: 'a3', title: 'no turns', promoted: false, turnCount: 0, assistantTurnCount: 0 },+ // turnCount > 0 but NO assistant turn (stream errored / client disconnected+ // before the answer persisted). Promoting it would fail NO_ASSISTANT_TURN,+ // so it must NOT be surfaced as a promotable row.+ { id: 'a4', title: 'user turn only', promoted: false, turnCount: 1, assistantTurnCount: 0 }]);const queue = await buildQueue();const askRows = queue.items.filter(i => i.source === 'ask');@@ -166,7 +170,7 @@ describe('reviewQueue.buildQueue', () => {it('tags resolvable rows with an inline action verb, leaves no-clean-resolve sources without one', async () => {brain.getInboxLog.mockResolvedValue([{ id: 'b1', capturedText: 'classify', capturedAt: '2026-06-03T10:00:00.000Z' }]);cosTaskStore.getCosTasks.mockResolvedValue({ awaitingApproval: [{ id: 'sys-1', description: 'approve me', priority: 'HIGH', createdAt: '2026-06-03T09:00:00.000Z' }] });- askConversations.listConversations.mockResolvedValue([{ id: 'a1', title: 'promote me', promoted: false, turnCount: 1 }]);+ askConversations.listConversations.mockResolvedValue([{ id: 'a1', title: 'promote me', promoted: false, turnCount: 1, assistantTurnCount: 1 }]);proactiveAlerts.generateAlerts.mockResolvedValue({ alerts: [{ type: 'disk', severity: 'critical', title: 'crit', detail: 'full', link: '/apps' }] });backup.getState.mockResolvedValue({ status: 'error', error: 'disk full' });const queue = await buildQueue();@@ -182,7 +186,7 @@ describe('reviewQueue.buildQueue', () => {it('attaches source-appropriate meta chips when the raw field is present', async () => {brain.getInboxLog.mockResolvedValue([{ id: 'b1', capturedText: 'classify', source: 'voice', capturedAt: '2026-06-03T10:00:00.000Z' }]);- askConversations.listConversations.mockResolvedValue([{ id: 'a1', title: 'promote me', promoted: false, turnCount: 4 }]);+ askConversations.listConversations.mockResolvedValue([{ id: 'a1', title: 'promote me', promoted: false, turnCount: 4, assistantTurnCount: 2 }]);cosTaskStore.getCosTasks.mockResolvedValue({ awaitingApproval: [{ id: 'sys-1', description: 'approve me', priority: 'MEDIUM', createdAt: '2026-06-03T09:00:00.000Z' }] });messageDrafts.listDrafts.mockResolvedValue([{ id: 'd1', status: 'draft', subject: 's', to: ['[email protected]'], sendVia: 'gmail', updatedAt: '2026-06-03T08:00:00.000Z' }]);proactiveAlerts.generateAlerts.mockResolvedValue({ alerts: [{ type: 'system_resource', severity: 'critical', title: 'mem', detail: 'high', link: '/apps' }] });@@ -211,7 +215,7 @@ describe('reviewQueue.buildQueue', () => {});it('advertises Ask promote targets (brain/task) and no other source carries them', async () => {- askConversations.listConversations.mockResolvedValue([{ id: 'a1', title: 'promote me', promoted: false, turnCount: 1 }]);+ askConversations.listConversations.mockResolvedValue([{ id: 'a1', title: 'promote me', promoted: false, turnCount: 1, assistantTurnCount: 1 }]);brain.getInboxLog.mockResolvedValue([{ id: 'b1', capturedText: 'classify', capturedAt: '2026-06-03T10:00:00.000Z' }]);const queue = await buildQueue();const ask = queue.items.find(i => i.source === 'ask');@@ -222,7 +226,7 @@ describe('reviewQueue.buildQueue', () => {});it('adds the goal target + active-goal options to Ask rows when goals exist', async () => {- askConversations.listConversations.mockResolvedValue([{ id: 'a1', title: 'promote me', promoted: false, turnCount: 1 }]);+ askConversations.listConversations.mockResolvedValue([{ id: 'a1', title: 'promote me', promoted: false, turnCount: 1, assistantTurnCount: 1 }]);identity.getGoals.mockResolvedValue({goals: [{ id: 'g1', title: 'Ship inbox zero', status: 'active' },@@ -237,7 +241,7 @@ describe('reviewQueue.buildQueue', () => {});it('degrades to no goal target when the goal store fails', async () => {- askConversations.listConversations.mockResolvedValue([{ id: 'a1', title: 'promote me', promoted: false, turnCount: 1 }]);+ askConversations.listConversations.mockResolvedValue([{ id: 'a1', title: 'promote me', promoted: false, turnCount: 1, assistantTurnCount: 1 }]);identity.getGoals.mockRejectedValue(new Error('goals unreadable'));const queue = await buildQueue();const ask = queue.items.find(i => i.source === 'ask');@@ -247,7 +251,7 @@ describe('reviewQueue.buildQueue', () => {});it('skips malformed goal entries without sinking the whole queue', async () => {- askConversations.listConversations.mockResolvedValue([{ id: 'a1', title: 'promote me', promoted: false, turnCount: 1 }]);+ askConversations.listConversations.mockResolvedValue([{ id: 'a1', title: 'promote me', promoted: false, turnCount: 1, assistantTurnCount: 1 }]);// A null / non-object entry must not throw synchronously in the filter —// that would run before the per-producer catch and sink every source.identity.getGoals.mockResolvedValue({ goals: [null, 'bogus', { id: 'g1', title: 'Real goal', status: 'active' }] });