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): run watcher blocks on idle path + cap PR page safely
[._.]/ Adam Eivyda1078d86bdb
diff --git a/server/services/cosTaskGenerator.js b/server/services/cosTaskGenerator.jsindex 6cfa88394e..9afb2f7314 100644--- a/server/services/cosTaskGenerator.js+++ b/server/services/cosTaskGenerator.js@@ -1026,85 +1026,15 @@ async function generateManagedAppImprovementTask(app, state) {emitLog('info', `Generating improvement task for ${app.name}: ${nextType} (${selectionReason})`, { appId: app.id, analysisType: nextType });- // Get interval settings to determine provider/model and pipeline config- const interval = await taskSchedule.getTaskInterval(nextType);-- const metadata = {- app: app.id,- appName: app.name,- repoPath: app.repoPath,- analysisType: nextType,- autoGenerated: true,- comprehensiveImprovement: true- };-- // Apply sanitized task-type-specific metadata from schedule config (e.g., useWorktree, simplify, pipeline)- const sanitizedGlobalMeta = sanitizeTaskMetadata(interval.taskMetadata);- if (sanitizedGlobalMeta) {- Object.assign(metadata, sanitizedGlobalMeta);- }-- // Apply sanitized per-app taskMetadata overrides (merge on top of global).- // Strip managed-agent fields from the override first so an existing- // app-level value for a now-managed field can't overwrite the global's- // enforced default (the UI locks the toggle, the merge has to honor that).- const appOverrides = await getAppTaskTypeOverrides(app.id);- const strippedAppOverride = taskSchedule.stripManagedAgentOptionsFromOverride(- nextType, appOverrides[nextType]?.taskMetadata- );- const sanitizedAppMeta = sanitizeTaskMetadata(strippedAppOverride);- if (sanitizedAppMeta) {- Object.assign(metadata, sanitizedAppMeta);- }-- initializePipelineMetadata(metadata);- if (shouldSkipForPrecondition(metadata, app, nextType)) return null;-- const planMeta = await applyPlanIdMetadata(nextType, app.repoPath, metadata);- if (planMeta.skipReason) {- emitLog('info', `Skipping ${nextType} for ${app.name}: ${planMeta.skipReason}`, { appId: app.id });- return null;- }- const planConstraintBlock = buildPlanConstraintBlock(metadata.planId);-- const promptTemplate = metadata.pipeline?.stages- ? await taskSchedule.getStagePrompt(nextType, 0)- : await taskSchedule.getTaskPrompt(nextType);- const reviewersCsv = normalizeReviewers(metadata).join(',');- const description = promptTemplate- .replace(/\{appName\}/g, app.name)- .replace(/\{repoPath\}/g, app.repoPath)- .replace(/\{appId\}/g, app.id)- .replace(/\{reviewers\}/g, reviewersCsv)- .replace(/\{planConstraint\}/g, () => planConstraintBlock);-- applyAppWorktreeDefault(metadata, app);-- if (interval.providerId) {- metadata.provider = interval.providerId;- metadata.providerId = interval.providerId;- }- if (interval.model) {- metadata.model = interval.model;- } else if (!metadata.provider) {- // Only default to Claude when no per-stage provider overrides the selection- metadata.model = 'claude-opus-4-5-20251101';- }-- const approval = await resolveConfidenceApproval(state, `app-improve:${nextType}`, `Task app-improve:${nextType} for ${app.name}`);-- const task = {- id: `app-improve-${app.id}-${nextType}-${Date.now().toString(36)}`,- status: 'pending',- priority: state.config.idleReviewPriority || 'MEDIUM',- priorityValue: PRIORITY_VALUES[state.config.idleReviewPriority] || 2,- description,- metadata,- taskType: 'internal',- ...approval- };-- return task;+ // Delegate the actual task build to the per-type generator so the dynamic+ // blocks run on the idle-review path too: pr-watcher's PR poll ++ // {prData}/{repoFullName}/{defaultBranch} injection, and reference-watch's+ // {referenceData} injection. Without delegation this path replaced only the+ // generic placeholders, so a watcher type selected here would spawn a prompt+ // with the literal {prData}/{referenceData} markers and never poll. The+ // recordExecution + activity bump above already accounted for the idle+ // spawn; the per-type generator does not record execution itself.+ return generateManagedAppImprovementTaskForType(nextType, app, state);}/**diff --git a/server/services/prWatcher.js b/server/services/prWatcher.jsindex 3f84fca773..dfa627b2f7 100644--- a/server/services/prWatcher.js+++ b/server/services/prWatcher.js@@ -29,10 +29,16 @@ import { getAppById, updateApp } from './apps.js';import { getOriginInfo } from '../lib/gitRemote.js';import { PR_AUTHOR_FILTERS } from '../lib/validation.js';-// Bound the gh query + the per-run dispatch. An app left unwatched for a long-// time could otherwise surface a huge batch; 50 open PRs is already far beyond-// a single-user app's normal state.-const PR_LIST_LIMIT = 50;+// Bound the gh query. The high-water mark (computePrCheck) advances to the max+// open PR number it saw, so it can only correctly drain a backlog it received+// in full: if `gh pr list` truncated the page, new PRs numbered below the+// page's minimum would be marked seen without ever dispatching. gh returns+// newest-first, so truncation drops the OLDEST new PRs. We set the cap high+// enough (200) that a single-user app's default branch realistically never+// truncates, and `checkPullRequests` emits a loud warning (never silent) if it+// ever does — at which point the operator should run the watcher again or raise+// the cap. 200 matches the limit github.js#syncRepos already uses.+const PR_LIST_LIMIT = 200;// Cache the gh-authenticated login for the process lifetime. It's the PortOS// operator's identity and effectively never changes within a run; re-resolving@@ -190,6 +196,12 @@ 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.+ 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.`);+ }const lastSeen = readPrWatcherState(app).lastSeenPrNumber;const prevLastSeen = Number.isInteger(lastSeen) ? lastSeen : null;