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: move GitHub threads read on the website out of Needs you (#13171)

Adam Eivy63e8a7917388
diff --git a/client/src/components/github/GitHubInboxTab.jsx b/client/src/components/github/GitHubInboxTab.jsx
index 9745aec07c..b318b6975b 100644
--- a/client/src/components/github/GitHubInboxTab.jsx
+++ b/client/src/components/github/GitHubInboxTab.jsx
@@ -56,12 +56,12 @@ const MORE_ACTIONS = [
// Mirrors HANDLED_DECISIONS in server/lib/githubNotificationTriage.js:
// nothing is left for you on these threads, so they sit under Handled.
const HANDLED_DECISIONS = new Set(['handled-by-pr-workflow', 'duplicate', 'handed-off', 'suggest-mark-read']);
-const nothingLeft = (row) => !row.suspect && HANDLED_DECISIONS.has(row.decision);
+const nothingLeft = (row) => row.readOnGithub || (!row.suspect && HANDLED_DECISIONS.has(row.decision));
// Whether a row still belongs in the view after an action moved it.
const VIEW_MATCHERS = {
'needs-you': (row) => row.state === 'open' && !row.suspect && !nothingLeft(row),
- suspect: (row) => row.state === 'open' && row.suspect,
+ suspect: (row) => row.state === 'open' && !row.readOnGithub && row.suspect,
handled: (row) => row.state !== 'open' || nothingLeft(row),
all: () => true,
};
@@ -181,6 +181,7 @@ function NotificationRow({ notification, accountLabel, busy, onAction }) {
{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>}
{handled && <Pill tone="muted">{STATE_LABELS[notification.state] || notification.state}</Pill>}
</div>
{!handled && notification.agent?.refused && (
diff --git a/server/lib/db/schema/githubNotifications.js b/server/lib/db/schema/githubNotifications.js
index fa0f23532b..3e26063031 100644
--- a/server/lib/db/schema/githubNotifications.js
+++ b/server/lib/db/schema/githubNotifications.js
@@ -36,6 +36,10 @@ export const githubNotificationsDdl = [
`ALTER TABLE github_notifications ADD COLUMN IF NOT EXISTS suspect BOOLEAN NOT NULL DEFAULT FALSE`,
`ALTER TABLE github_notifications ADD COLUMN IF NOT EXISTS evidence JSONB NOT NULL DEFAULT '{}'::jsonb`,
`ALTER TABLE github_notifications ADD COLUMN IF NOT EXISTS triaged_for TIMESTAMPTZ`,
+ // Handled on GitHub (#13171): the REST API cannot tell Done from read, so an
+ // open row that turned read there without PortOS reading it is shown under
+ // Handled. Cleared by new activity. A PortOS read/done never sets it.
+ `ALTER TABLE github_notifications ADD COLUMN IF NOT EXISTS read_on_github_at TIMESTAMPTZ`,
`CREATE TABLE IF NOT EXISTS github_notification_sync (
account_id TEXT PRIMARY KEY,
last_modified TEXT,
diff --git a/server/services/githubNotifications.db.test.js b/server/services/githubNotifications.db.test.js
index c8244ccdf3..2629eddfa3 100644
--- a/server/services/githubNotifications.db.test.js
+++ b/server/services/githubNotifications.db.test.js
@@ -213,6 +213,31 @@ 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 () => {
+ let inbox = [thread('161'), thread('162'), thread('163')];
+ const actions = mockGh((args) => githubListing(args, inbox));
+ await syncAccountNotifications(account.id);
+ const view = async (name) => (await listNotifications({ accountId: account.id, view: name })).notifications.map((row) => row.threadId).sort();
+ expect(await view('needs-you')).toEqual(['161', '162', '163']);
+
+ // 161 is Done on the website and 163 only read there (both stay in the
+ // all=true listing as read, whose cursor does not move); 162 is read
+ // through PortOS.
+ await applyNotificationAction(account.id, '162', 'read');
+ 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(actions).toEqual([]);
+
+ inbox = [thread('161', { updatedAt: '2026-10-02T10:00:00Z' })];
+ await syncAccountNotifications(account.id);
+ expect(await view('needs-you')).toContain('161');
+ expect(await view('handled')).not.toContain('161');
+ });
+
it('treats a 304 as unchanged and keeps rows', async () => {
mockGh((args) => githubListing(args, [thread('201')]));
await syncAccountNotifications(account.id);
diff --git a/server/services/githubNotifications.js b/server/services/githubNotifications.js
index f0fa064ac3..abf703a7ff 100644
--- a/server/services/githubNotifications.js
+++ b/server/services/githubNotifications.js
@@ -138,6 +138,12 @@ const UPSERT_SQL = `INSERT INTO github_notifications (
html_url = EXCLUDED.html_url,
latest_comment_api_url = EXCLUDED.latest_comment_api_url,
unread = EXCLUDED.unread,
+ -- Read on GitHub while open and unread here (PortOS's own read clears
+ -- unread first, so never lands here). New activity or unread clears it.
+ read_on_github_at = CASE
+ WHEN EXCLUDED.unread OR EXCLUDED.gh_updated_at > github_notifications.gh_updated_at THEN NULL
+ WHEN github_notifications.unread AND github_notifications.state = 'open' THEN COALESCE(github_notifications.read_on_github_at, NOW())
+ ELSE github_notifications.read_on_github_at END,
-- New activity brings back a thread marked done, and an unsubscribed one
-- (GitHub re-subscribes on a fresh mention or review request). Muted stays.
-- An unread thread is in GitHub's inbox (marking one done reads it), so it
@@ -179,12 +185,16 @@ const listedIds = (listing) => listing.threads.map((thread) => String(thread?.id
// Only a complete listing says anything about the threads it does not name.
async function reconcileListings(client, accountId, { inbox, unread }) {
+ let readOnGithub = 0;
if (unread.complete) {
- await client.query(
- `UPDATE github_notifications SET unread = FALSE, updated_at = NOW()
+ // Reading a thread on GitHub does not move the `all=true` cursor, so a
+ // thread that turned read there is only seen here (#13171).
+ ({ rowCount: readOnGithub } = await client.query(
+ `UPDATE github_notifications SET unread = FALSE, updated_at = NOW(),
+ read_on_github_at = CASE WHEN state = 'open' THEN NOW() ELSE read_on_github_at END
WHERE account_id = $1 AND unread AND NOT (thread_id = ANY($2::text[]))`,
[accountId, listedIds(unread)],
- );
+ ));
}
// GitHub's `all=true` listing still includes threads marked done (as
// read), so only a thread missing from the whole listing is known gone.
@@ -197,6 +207,7 @@ async function reconcileListings(client, accountId, { inbox, unread }) {
[accountId, listedIds(inbox)],
);
}
+ return readOnGithub;
}
async function syncAccountNow(account, automate) {
@@ -205,11 +216,18 @@ async function syncAccountNow(account, automate) {
const listedAt = new Date();
const inbox = await fetchListing(account, env, { all: true, ifModifiedSince: listingCursor(cursor?.last_modified) });
if (inbox.notModified) {
- await query('UPDATE github_notification_sync SET last_sync_at = NOW(), last_error = \'\', updated_at = NOW() WHERE account_id = $1', [account.id]);
+ // The cursor only moves on new activity, not on reads: re-read the small
+ // unread listing so a thread read on GitHub leaves Needs you.
+ const unread = await fetchListing(account, env, { all: false });
+ const readOnGithub = await withTransaction(async (client) => {
+ const count = await reconcileListings(client, account.id, { inbox, unread });
+ await client.query('UPDATE github_notification_sync SET last_sync_at = NOW(), last_error = \'\', updated_at = NOW() WHERE account_id = $1', [account.id]);
+ return count;
+ });
// Threads past the last run's triage cap still need a decision.
const triage = await triageAccountNotifications(account, env);
const assist = await runAutomation(account, env, automate);
- if (triage.triaged || assist.sorted || assist.acted || assist.handedOff) githubNotificationEvents.emit('changed', { accountId: account.id });
+ if (readOnGithub || triage.triaged || assist.sorted || assist.acted || assist.handedOff) githubNotificationEvents.emit('changed', { accountId: account.id });
return { accountId: account.id, changed: false, fetched: 0, triage, assist };
}
// The `all=true` listing can run past MAX_PAGES and is a delta after the
@@ -277,9 +295,9 @@ export async function syncAllNotifications(options = {}) {
// or merged) is Handled while it is still open on GitHub.
const HANDLED_SQL = `decision IN (${HANDLED_DECISIONS.map((decision) => `'${decision}'`).join(', ')})`;
const VIEW_FILTERS = {
- 'needs-you': `state = 'open' AND NOT suspect AND (decision IS NULL OR NOT ${HANDLED_SQL})`,
- suspect: "state = 'open' AND suspect",
- handled: `(state <> 'open' OR (NOT suspect AND ${HANDLED_SQL}))`,
+ 'needs-you': `state = 'open' AND read_on_github_at IS NULL AND NOT suspect AND (decision IS NULL OR NOT ${HANDLED_SQL})`,
+ suspect: "state = 'open' AND read_on_github_at IS NULL AND suspect",
+ handled: `(state <> 'open' OR read_on_github_at IS NOT NULL OR (NOT suspect AND ${HANDLED_SQL}))`,
all: 'TRUE',
};
@@ -305,6 +323,7 @@ const toApi = (row, accountsById) => {
title: row.subject_title,
htmlUrl: row.html_url,
unread: row.unread,
+ readOnGithub: Boolean(row.read_on_github_at) && row.state === 'open',
state: row.state,
decision: row.decision || null,
trust: row.trust || null,