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): bail on truncated PR pages + clear watcher state on global disable
[._.]/ Adam Eivy10d0a111ddeb
diff --git a/server/services/apps.js b/server/services/apps.jsindex 640e761aa8..03383103ab 100644--- a/server/services/apps.js+++ b/server/services/apps.js@@ -451,6 +451,26 @@ export async function updateAppTaskTypeOverride(id, taskType, { enabled, intervareturn { id, ...data.apps[id] };}+/**+ * Clear the pr-watcher high-water mark on every app. Called when pr-watcher is+ * disabled GLOBALLY (CoS → Schedule), the counterpart to the per-app disable+ * clears in updateAppTaskTypeOverride/bulk/toggle-all — so a later global+ * re-enable baselines silently instead of dispatching the backlog of PRs+ * opened while it was paused. See prWatcher.js.+ */+export async function clearAllPrWatcherState() {+ const data = await loadApps();+ let changed = false;+ for (const app of Object.values(data.apps)) {+ if (app.prWatcherState) {+ delete app.prWatcherState;+ changed = true;+ }+ }+ if (changed) await saveApps(data);+ return { changed };+}+/*** Bulk update a task type override for all active (non-archived) apps*/diff --git a/server/services/prWatcher.js b/server/services/prWatcher.jsindex 4376ec0c27..d9767dca74 100644--- a/server/services/prWatcher.js+++ b/server/services/prWatcher.js@@ -201,11 +201,15 @@ export async function checkPullRequests(app, { authorFilter = 'any' } = {}) {if (prs === null) {return { ok: false, reason: 'pr-list-failed', repoFullName, defaultBranch };}- // No silent caps: if the page was truncated, the high-water mark could skip- // the oldest new PRs (gh returns newest-first). Surface it rather than drop- // them quietly — realistically unreachable for a single-user repo.+ // Truncated page: gh returns newest-first, so advancing the high-water mark+ // to the page's max would mark the oldest unseen new PRs as seen without ever+ // dispatching them — and they'd never recover. Bail WITHOUT advancing the+ // mark instead; the next run retries, and once the open-PR count drops below+ // the cap the watcher resumes. No silent skip, no data loss. Realistically+ // unreachable for a single-user repo at a 200 cap.if (prs.length >= PR_LIST_LIMIT) {- console.warn(`⚠️ pr-watcher: ${repoFullName} returned ${prs.length} open PRs (cap ${PR_LIST_LIMIT}) — the oldest new PRs beyond the page may be skipped this cycle. Re-run the watcher or raise PR_LIST_LIMIT.`);+ console.warn(`⚠️ pr-watcher: ${repoFullName} has ≥${PR_LIST_LIMIT} open PRs — deferring (not advancing the high-water mark) so no newly-opened PR is skipped.`);+ return { ok: false, reason: 'too-many-open-prs', repoFullName, defaultBranch };}const lastSeen = readPrWatcherState(app).lastSeenPrNumber;diff --git a/server/services/taskSchedule.js b/server/services/taskSchedule.jsindex 7dc43ee6b8..a9d8b91437 100644--- a/server/services/taskSchedule.js+++ b/server/services/taskSchedule.js@@ -20,7 +20,7 @@ import { cosEvents, emitLog } from './cosEvents.js';import { DAY, ensureDir, HOUR, readJSONFile, PATHS, safeDate } from '../lib/fileUtils.js';import { isPlainObject } from '../lib/objects.js';import { getAdaptiveCooldownMultiplier } from './taskLearning.js';-import { isTaskTypeEnabledForApp, getAppTaskTypeInterval, getActiveApps, getAppTaskTypeOverrides } from './apps.js';+import { isTaskTypeEnabledForApp, getAppTaskTypeInterval, getActiveApps, getAppTaskTypeOverrides, clearAllPrWatcherState } from './apps.js';import { loadState, isImprovementEnabled } from './cosState.js';import { getUserTimezone, getLocalParts } from '../lib/timezone.js';import { parseCronToNextRun, parseCronToPrevRun } from './eventScheduler.js';@@ -511,6 +511,17 @@ export async function updateTaskInterval(taskType, settings) {enforceManagedAgentOptions(taskType, schedule.tasks[taskType]);await saveSchedule(schedule);++ // Globally disabling pr-watcher clears every app's high-water mark, mirroring+ // the per-app disable clears in apps.js — so a later global re-enable+ // baselines silently instead of dispatching the backlog of PRs opened while+ // it was paused. (`enabled` arrives as a real boolean from the schedule route.)+ if (taskType === 'pr-watcher' && settings.enabled === false) {+ await clearAllPrWatcherState().catch((err) => {+ emitLog('warn', `pr-watcher global-disable state clear failed: ${err.message}`, {}, '📅 TaskSchedule');+ });+ }+emitLog('info', `Updated task interval for ${taskType}`, { taskType, settings }, '📅 TaskSchedule');cosEvents.emit('schedule:changed', { taskType, settings });diff --git a/server/services/taskSchedule.test.js b/server/services/taskSchedule.test.jsindex 8a4b6ead14..45fe842eab 100644--- a/server/services/taskSchedule.test.js+++ b/server/services/taskSchedule.test.js@@ -46,7 +46,8 @@ vi.mock('./apps.js', () => ({isTaskTypeEnabledForApp: vi.fn().mockResolvedValue(true),getAppTaskTypeInterval: vi.fn().mockResolvedValue(null),getActiveApps: vi.fn().mockResolvedValue([]),- getAppTaskTypeOverrides: vi.fn().mockResolvedValue({})+ getAppTaskTypeOverrides: vi.fn().mockResolvedValue({}),+ clearAllPrWatcherState: vi.fn().mockResolvedValue({ changed: false })}))vi.mock('../lib/ports.js', () => ({@@ -101,7 +102,7 @@ import {import { loadState } from './cosState.js'import { readJSONFile } from '../lib/fileUtils.js'-import { isTaskTypeEnabledForApp, getAppTaskTypeInterval } from './apps.js'+import { isTaskTypeEnabledForApp, getAppTaskTypeInterval, clearAllPrWatcherState } from './apps.js'import { getLocalParts } from '../lib/timezone.js'import { getAdaptiveCooldownMultiplier } from './taskLearning.js'import { parseCronToNextRun, parseCronToPrevRun } from './eventScheduler.js'@@ -295,6 +296,19 @@ describe('taskSchedule', () => {expect(result.type).toBe('daily')expect(result.enabled).toBe(true)})++ it('clears all pr-watcher state when pr-watcher is globally disabled', async () => {+ clearAllPrWatcherState.mockClear()+ await updateTaskInterval('pr-watcher', { enabled: false })+ expect(clearAllPrWatcherState).toHaveBeenCalledTimes(1)+ })++ it('does not clear pr-watcher state on enable or on other task disables', async () => {+ clearAllPrWatcherState.mockClear()+ await updateTaskInterval('pr-watcher', { enabled: true })+ await updateTaskInterval('security', { enabled: false })+ expect(clearAllPrWatcherState).not.toHaveBeenCalled()+ })})describe('managed agent options', () => {