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: move read GitHub threads to Handled and clear them in bulk (#13252)
[._.]/1710c03ba428
diff --git a/client/src/components/github/GitHubInboxTab.jsx b/client/src/components/github/GitHubInboxTab.jsxindex 217da0abcf..1d6a746c7d 100644--- a/client/src/components/github/GitHubInboxTab.jsx+++ b/client/src/components/github/GitHubInboxTab.jsx@@ -58,13 +58,12 @@ const MORE_ACTIONS = [];// Whether a row still belongs in the view after an action moved it. Mirrors-// VIEW_FILTERS in server/services/githubNotifications.js: the inbox holds every-// open thread GitHub still has unread or PortOS has not seen read there,-// whatever its decision.+// VIEW_FILTERS in server/services/githubNotifications.js: the inbox holds+// unread open threads, whatever their decision.const VIEW_MATCHERS = {- 'needs-you': (row) => row.state === 'open' && !row.readOnGithub && !row.suspect,- suspect: (row) => row.state === 'open' && !row.readOnGithub && row.suspect,- handled: (row) => row.state !== 'open' || row.readOnGithub,+ 'needs-you': (row) => row.state === 'open' && row.unread && !row.readOnGithub && !row.suspect,+ suspect: (row) => row.state === 'open' && row.unread && !row.readOnGithub && row.suspect,+ handled: (row) => row.state !== 'open' || !row.unread || row.readOnGithub,all: () => true,};const belongsInView = (row, view) => VIEW_MATCHERS[view](row);@@ -235,7 +234,7 @@ function NotificationRow({ notification, accountLabel, busy, onAction, onUpdated{notification.yourRepo && <Pill tone="accent">Your repo</Pill>}{notification.repoPrivate && <Pill tone="muted">Private</Pill>}{trust && <Pill tone={trust.tone}>{trust.label}</Pill>}- {notification.readOnGithub && <Pill tone="muted">Read on GitHub</Pill>}+ {notification.state === 'open' && !notification.unread && <Pill tone="muted">{notification.readOnGithub ? 'Read on GitHub' : 'Read'}</Pill>}{handled && <Pill tone="muted">{STATE_LABELS[notification.state] || notification.state}</Pill>}{!handled && notification.agentFailed && (<Link to={agentFailedLink(notification.agentFailed)} className="rounded hover:underline">@@ -461,7 +460,7 @@ export default function GitHubInboxTab() {</div><SummaryTiles view={view} counts={data.counts} onSelect={setView} />- {(data.counts?.['with-agents'] > 0 || (view === 'needs-you' && data.counts?.finished > 0)) && (+ {(data.counts?.['with-agents'] > 0 || (view === 'needs-you' && data.counts?.clearable > 0)) && (<div className="flex flex-wrap items-center gap-x-4 gap-y-2">{data.counts['with-agents'] > 0 && (<p className="flex items-center gap-1.5 text-xs text-gray-400">@@ -469,7 +468,7 @@ export default function GitHubInboxTab() {{formatCount(data.counts['with-agents'])} with an agent now</p>)}- {view === 'needs-you' && data.counts.finished > 0 && (+ {view === 'needs-you' && data.counts.clearable > 0 && (<buttontype="button"onClick={clearFinished}@@ -477,7 +476,7 @@ export default function GitHubInboxTab() {className="inline-flex min-h-[36px] items-center gap-1.5 rounded-lg border border-port-border bg-port-card px-3 py-1.5 text-xs text-gray-200 hover:border-gray-500 disabled:opacity-60"><CheckCheck size={13} aria-hidden="true" />- {clearing ? 'Marking done…' : `Mark ${formatCount(data.counts.finished)} finished done`}+ {clearing ? 'Marking done…' : `Mark ${formatCount(data.counts.clearable)} finished or read done`}</button>)}</div>diff --git a/client/src/pages/GitHub.test.jsx b/client/src/pages/GitHub.test.jsxindex fddf37a284..03238c6e6b 100644--- a/client/src/pages/GitHub.test.jsx+++ b/client/src/pages/GitHub.test.jsx@@ -514,10 +514,24 @@ describe('GitHub inbox tab', () => {expect(await screen.findByText('Your inbox is clear.')).toBeTruthy();});- it('marks every finished thread done in one tap', async () => {+ it('labels handled read threads with where they were read', async () => {+ mock.getGitHubNotifications.mockResolvedValue({+ notifications: [+ { ...NOTIFICATION, unread: false },+ { ...NOTIFICATION, threadId: '102', title: 'Read elsewhere', unread: false, readOnGithub: true },+ ],+ counts: { 'needs-you': 0, handled: 2 }, sync: {},+ });+ await renderInbox();+ fireEvent.click(screen.getByRole('button', { name: /Handled/ }));+ expect(await screen.findByText('Read')).toBeTruthy();+ expect(screen.getByText('Read on GitHub')).toBeTruthy();+ });++ it('marks every finished or read thread done in one tap', async () => {mock.getGitHubNotifications.mockResolvedValue({notifications: [NOTIFICATION, { ...NOTIFICATION, threadId: '102', title: 'Folded CI notice', decision: 'duplicate' }],- counts: { 'needs-you': 2, suspect: 0, handled: 0, all: 2, finished: 1 },+ counts: { 'needs-you': 2, suspect: 0, handled: 0, all: 2, finished: 1, clearable: 3 },sync: {},});mock.clearFinishedGitHubNotifications.mockResolvedValue({ cleared: 1, failed: 0 });@@ -526,7 +540,7 @@ describe('GitHub inbox tab', () => {expect(await screen.findByText('Folded CI notice')).toBeTruthy();// Its suggestion is the action itself.expect(screen.getAllByRole('button', { name: 'Mark done' }).length).toBe(1);- fireEvent.click(screen.getByRole('button', { name: 'Mark 1 finished done' }));+ fireEvent.click(screen.getByRole('button', { name: 'Mark 3 finished or read done' }));await waitFor(() => expect(mock.clearFinishedGitHubNotifications).toHaveBeenCalledWith(null));});diff --git a/server/services/githubNotifications.db.test.js b/server/services/githubNotifications.db.test.jsindex 778c46c19c..56e637357a 100644--- a/server/services/githubNotifications.db.test.js+++ b/server/services/githubNotifications.db.test.js@@ -218,7 +218,7 @@ describe.skipIf(!runDb)('GitHub notifications inbox against Postgres', () => {expect(await ids()).toEqual(['151', '152']);});- it('moves a thread read on GitHub to Handled without a gh write, keeps a PortOS read in Needs you, and brings it back on new activity', async () => {+ it('moves a thread read on GitHub to Handled without a gh write, moves a PortOS read to Handled, and brings it back on new activity', async () => {let inbox = [thread('161'), thread('162'), thread('163')];const actions = mockGh((args) => githubListing(args, inbox));await syncAccountNotifications(account.id);@@ -229,13 +229,16 @@ describe.skipIf(!runDb)('GitHub notifications inbox against Postgres', () => {// all=true listing as read, whose cursor does not move); 162 is read// through PortOS.await applyNotificationAction(account.id, '162', 'read');+ expect(await view('needs-you')).toEqual(['161', '163']);+ expect(await view('handled')).toEqual(['162']);actions.length = 0;inbox = [{ ...inbox[0], unread: false }, { ...inbox[1], unread: false }, { ...inbox[2], unread: false }];await syncAccountNotifications(account.id);- expect(await view('needs-you')).toEqual(['162']);- expect(await view('handled')).toEqual(['161', '163']);- expect((await listNotifications({ accountId: account.id, view: 'handled' })).notifications[0]).toMatchObject({ readOnGithub: true, state: 'open' });+ expect(await view('needs-you')).toEqual([]);+ expect(await view('handled')).toEqual(['161', '162', '163']);+ expect((await listNotifications({ accountId: account.id, view: 'handled' })).notifications.find((row) => row.threadId === '161')).toMatchObject({ readOnGithub: true, state: 'open' });expect(actions).toEqual([]);+ expect((await listNotifications({ accountId: account.id })).counts).toMatchObject({ 'needs-you': 0, clearable: 3 });inbox = [thread('161', { updatedAt: '2026-10-02T10:00:00Z' })];await syncAccountNotifications(account.id);@@ -371,12 +374,26 @@ describe.skipIf(!runDb)('GitHub notifications inbox against Postgres', () => {// there, until it is marked done, which one tap does for every finished thread.const inbox = await listNotifications({ accountId: account.id });expect(inbox.notifications.map((row) => row.threadId)).toEqual(['702', '701']);- expect(inbox.counts).toMatchObject({ 'needs-you': 2, finished: 1 });+ expect(inbox.counts).toMatchObject({ 'needs-you': 2, finished: 1, clearable: 1 });expect(await clearFinishedNotifications({ accountId: account.id })).toEqual({ cleared: 1, failed: 0 });expect(actions).toEqual([['DELETE', 'notifications/threads/701']]);expect((await listNotifications({ accountId: account.id })).notifications.map((row) => row.threadId)).toEqual(['702']);});+ it('clears read threads from either source in one tap without learning or clearing suspect threads', async () => {+ mockGh((args) => githubListing(args, [thread('711'), thread('712'), thread('713')]));+ await syncAccountNotifications(account.id);+ await applyNotificationAction(account.id, '711', 'read');+ await query(`UPDATE github_notifications SET unread = FALSE, read_on_github_at = NOW(),+ suspect = (thread_id = '713') WHERE account_id = $1 AND thread_id IN ('712', '713')`, [account.id]);+ const actions = mockGh(() => listing([]));+ expect((await listNotifications({ accountId: account.id })).counts).toMatchObject({ 'needs-you': 0, clearable: 2 });+ expect(await clearFinishedNotifications({ accountId: account.id })).toEqual({ cleared: 2, failed: 0 });+ expect(actions.sort()).toEqual([['DELETE', 'notifications/threads/711'], ['DELETE', 'notifications/threads/712']]);+ expect((await getNotification(account.id, '713')).state).toBe('open');+ expect((await query('SELECT * FROM github_notification_rules WHERE account_id = $1', [account.id])).rows).toEqual([]);+ });+it('links a deployment approval to its waiting run, keeps it in front of you, and clears it once the run stops waiting', async () => {await updateAccount(account.id, { mode: 'assist' });const login = account.login;diff --git a/server/services/githubNotifications.js b/server/services/githubNotifications.jsindex 1bdedf68ad..6cd0de813f 100644--- a/server/services/githubNotifications.js+++ b/server/services/githubNotifications.js@@ -298,15 +298,14 @@ export async function syncAllNotifications(options = {}) {return results;}-// The inbox mirrors GitHub's: every open thread is in it until marked done,-// whatever its decision says (a pill on the row). Finished threads are those-// the inbox can clear in one tap.+// The inbox holds unread open threads, whatever their decision. The operator+// can clear finished or read threads in one tap without teaching a rule.const FINISHED_SQL = `decision IN (${FINISHED_DECISIONS.map((decision) => `'${decision}'`).join(', ')})`;+const CLEARABLE_SQL = `state = 'open' AND NOT suspect AND (${FINISHED_SQL} OR NOT unread)`;const VIEW_FILTERS = {- // Read on the GitHub website without PortOS reading it: the operator handled it there (#13171).- 'needs-you': "state = 'open' AND read_on_github_at IS NULL AND NOT suspect",- suspect: "state = 'open' AND read_on_github_at IS NULL AND suspect",- handled: "(state <> 'open' OR read_on_github_at IS NOT NULL)",+ 'needs-you': "state = 'open' AND unread AND read_on_github_at IS NULL AND NOT suspect",+ suspect: "state = 'open' AND unread AND read_on_github_at IS NULL AND suspect",+ handled: "(state <> 'open' OR NOT unread OR read_on_github_at IS NOT NULL)",all: 'TRUE',};@@ -384,7 +383,8 @@ export async function listNotifications({ accountId = null, view = 'needs-you' }query(`SELECT ${NOTIFICATION_VIEWS.map((name) => `COUNT(*) FILTER (WHERE ${VIEW_FILTERS[name]})::int AS "${name}"`).join(', ')},COUNT(*) FILTER (WHERE state = 'open' AND decision = 'handed-off')::int AS "with-agents",- COUNT(*) FILTER (WHERE state = 'open' AND NOT suspect AND ${FINISHED_SQL})::int AS finished+ COUNT(*) FILTER (WHERE state = 'open' AND NOT suspect AND ${FINISHED_SQL})::int AS finished,+ COUNT(*) FILTER (WHERE ${CLEARABLE_SQL})::int AS clearableFROM github_notifications WHERE account_id = ANY($1::text[])`,[ids],),@@ -466,9 +466,10 @@ export async function applyNotificationAction(accountId, threadId, action, { actconst ACCOUNT_FAILURES = new Set(['GITHUB_ACCOUNT_DISABLED', 'GITHUB_ACCOUNT_UNAVAILABLE']);/**- * Mark every open finished thread done on GitHub (one account, or all), as- * the operator but without teaching learned rules: the decision already says- * nothing is left. One failed thread is counted, never stops the rest.+ * Mark every open non-suspect finished or read thread done on GitHub (one+ * account, or all), as the operator but without teaching learned rules:+ * reading a thread does not decide how future threads should be handled.+ * One failed thread is counted, never stops the rest.*/export async function clearFinishedNotifications({ accountId = null } = {}) {const accounts = (await listAccounts()).filter(isActive).filter((account) => !accountId || account.id === accountId);@@ -476,7 +477,7 @@ export async function clearFinishedNotifications({ accountId = null } = {}) {let failed = 0;for (const account of accounts) {const { rows } = await query(- `SELECT thread_id, decision FROM github_notifications WHERE account_id = $1 AND state = 'open' AND NOT suspect AND ${FINISHED_SQL}+ `SELECT thread_id, decision FROM github_notifications WHERE account_id = $1 AND ${CLEARABLE_SQL}ORDER BY gh_updated_at DESC`,[account.id],);@@ -489,7 +490,7 @@ export async function clearFinishedNotifications({ accountId = null } = {}) {}// An account gh cannot act as fails every thread the same way.if (ACCOUNT_FAILURES.has(error.code)) {- console.error(`❌ Could not mark finished GitHub notifications done for ${account.host}: ${error.message}`);+ console.error(`❌ Could not mark finished or read GitHub notifications done for ${account.host}: ${error.message}`);failed += rows.length - index;break;}@@ -498,7 +499,7 @@ export async function clearFinishedNotifications({ accountId = null } = {}) {}if (rows.length) githubNotificationEvents.emit('changed', { accountId: account.id });}- console.log(`🧹 Marked ${cleared} finished GitHub notification(s) done${failed ? `, ${failed} failed` : ''}`);+ console.log(`🧹 Marked ${cleared} finished or read GitHub notification(s) done${failed ? `, ${failed} failed` : ''}`);return { cleared, failed };}