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
refactor: centralize task readiness reason contract (#9311)
[._.]/ Adam Eivy721c6baf2fd2
diff --git a/client/src/components/cos/tabs/schedule/GlobalConfigControls.jsx b/client/src/components/cos/tabs/schedule/GlobalConfigControls.jsxindex d7a79e5321..4030506d20 100644--- a/client/src/components/cos/tabs/schedule/GlobalConfigControls.jsx+++ b/client/src/components/cos/tabs/schedule/GlobalConfigControls.jsx@@ -9,6 +9,7 @@ import InfoTooltip from '../../../ui/InfoTooltip';import { FormField } from '../../../ui/FormField';import { formatDateTime } from '../../../../utils/formatters';import { formatSkipCauses } from '../../../../lib/perpetualSkipCauses';+import { TASK_READINESS_REASON } from '../../../../../../server/lib/taskReadinessReasons.js';import { useCodeReviewDefaults } from '../../../../hooks/useCodeReviewDefaults';import useReviewerModelOptions from '../../../../hooks/useReviewerModelOptions';import { reviewerModelsFromDefaults, reviewerEffortsFromDefaults } from '../../../../lib/reviewerModels';@@ -423,7 +424,7 @@ export default function GlobalConfigControls({ taskType, config, onUpdate, onTri);}// Global (non-app) perpetual task: the global status.reason is accurate.- if (status.reason === 'perpetual-parked') {+ if (status.reason === TASK_READINESS_REASON.PERPETUAL_PARKED) {const skipSummary = formatSkipCauses(status.parkSkipCauses);return (<>@@ -434,7 +435,7 @@ export default function GlobalConfigControls({ taskType, config, onUpdate, onTri</>);}- if (status.reason === 'perpetual-drain' || status.reason === 'perpetual-recheck') {+ if (status.reason === TASK_READINESS_REASON.PERPETUAL_DRAIN || status.reason === TASK_READINESS_REASON.PERPETUAL_RECHECK) {return (<>{stallNote}diff --git a/client/src/components/cos/tabs/schedule/scheduleConstants.js b/client/src/components/cos/tabs/schedule/scheduleConstants.jsindex b126abfbd9..39b938e53c 100644--- a/client/src/components/cos/tabs/schedule/scheduleConstants.js+++ b/client/src/components/cos/tabs/schedule/scheduleConstants.js@@ -6,6 +6,7 @@ import {import { timeUntil } from '../../../../utils/formatters';import { describeCron, summarizeAppSchedules } from '../../../../utils/cronHelpers';import { formatSkipCauses } from '../../../../lib/perpetualSkipCauses';+import { TASK_READINESS_REASON } from '../../../../../../server/lib/taskReadinessReasons.js';// The cadence model is two variants; `perpetual` is an orthogonal flag that// renders as its own badge alongside whichever one is selected.@@ -138,6 +139,7 @@ export const STATUS_GROUPS = {'on-demand': { label: 'On-Demand', dot: 'bg-gray-400', order: 1 },waiting: { label: 'Waiting', dot: 'bg-port-warning', order: 2 },disabled: { label: 'Disabled', dot: 'bg-gray-600', order: 3 },+ unknown: { label: 'Unknown', dot: 'bg-port-warning', order: 4 },};/**@@ -158,6 +160,26 @@ export function isManualOnlyCadence({ type, perpetual, autoStart, appSchedules }return type === 'on-demand' && (!perpetual || autoStart === false);}+// Explicit rendering coverage for every wire reason. The cadence group still+// depends on the task config; a new reason must be classified deliberately.+export const TASK_READINESS_REASON_RENDERING = Object.freeze({+ [TASK_READINESS_REASON.REQUIRES_INSTALL_WIDE_TARGET]: 'cadence',+ [TASK_READINESS_REASON.DISABLED]: 'cadence',+ [TASK_READINESS_REASON.FEATURE_DISABLED]: 'cadence',+ [TASK_READINESS_REASON.ON_DEMAND_ONLY]: 'cadence',+ [TASK_READINESS_REASON.WEEKDAY_ONLY]: 'cadence',+ [TASK_READINESS_REASON.DISABLED_FOR_APP]: 'cadence',+ [TASK_READINESS_REASON.FAILURE_PARKED]: 'cadence',+ [TASK_READINESS_REASON.PERPETUAL_PARKED]: 'cadence',+ [TASK_READINESS_REASON.PERPETUAL_RECHECK]: 'cadence',+ [TASK_READINESS_REASON.PERPETUAL_DRAIN]: 'cadence',+ [TASK_READINESS_REASON.INVALID_CRON]: 'cadence',+ [TASK_READINESS_REASON.CRON_DUE]: 'cadence',+ [TASK_READINESS_REASON.CRON_COOLDOWN]: 'cadence',+ [TASK_READINESS_REASON.FAILURE_COOLDOWN]: 'cadence',+ [TASK_READINESS_REASON.WAITING_ON_DEPENDENCIES]: 'waiting',+});+// Classify a task config into one status group (mutually exclusive).// Disabled wins over everything; then dependency-wait; then cadence — a// perpetual on-demand task is "active" because its drain runs unattended, and@@ -165,7 +187,9 @@ export function isManualOnlyCadence({ type, perpetual, autoStart, appSchedules }// without anybody pressing Run, which is what this group means.export function getTaskStatusGroup(config) {if (!config?.enabled) return 'disabled';- if (config.status?.reason === 'waiting-on-dependencies') return 'waiting';+ const reason = config.status?.reason;+ if (reason != null && !Object.hasOwn(TASK_READINESS_REASON_RENDERING, reason)) return 'unknown';+ if (TASK_READINESS_REASON_RENDERING[reason] === 'waiting') return 'waiting';return isManualOnlyCadence(config) ? 'on-demand' : 'active';}@@ -257,6 +281,7 @@ export function coverageTone(enabled, total) {export function describeNextRun(config) {const group = getTaskStatusGroup(config);if (group === 'disabled') return { text: 'Paused', tone: 'text-gray-500' };+ if (group === 'unknown') return { text: 'Unknown schedule state', tone: 'text-port-warning', warn: true };if (group === 'waiting') {const deps = config.status?.pendingDeps?.join(', ');return {@@ -288,7 +313,7 @@ export function describeNextRun(config) {return { text: 'draining — runs back-to-back until done', tone: 'text-port-success' };}// Global (non-app) perpetual task: the global status.reason is accurate.- if (config.status?.reason === 'perpetual-parked') {+ if (config.status?.reason === TASK_READINESS_REASON.PERPETUAL_PARKED) {const next = config.status?.nextRunAt;const skipSummary = formatSkipCauses(config.status?.parkSkipCauses);const skipSuffix = skipSummary ? ` — ${skipSummary}` : '';@@ -334,6 +359,7 @@ export const TASK_FILTERS = [{ id: 'on-demand', label: 'On-Demand', emptyMessage: 'No on-demand tasks.', match: ([, config]) => getTaskStatusGroup(config) === 'on-demand' },{ id: 'waiting', label: 'Waiting', emptyMessage: 'No tasks waiting on dependencies.', match: ([, config]) => getTaskStatusGroup(config) === 'waiting' },{ id: 'disabled', label: 'Disabled', emptyMessage: 'No disabled tasks.', match: ([, config]) => getTaskStatusGroup(config) === 'disabled' },+ { id: 'unknown', label: 'Unknown', emptyMessage: 'No tasks with unknown status.', match: ([, config]) => getTaskStatusGroup(config) === 'unknown' },];export const DEFAULT_FILTER_ID = TASK_FILTERS[0].id;diff --git a/client/src/components/cos/tabs/schedule/scheduleConstants.test.js b/client/src/components/cos/tabs/schedule/scheduleConstants.test.jsindex 25833d4298..fe1706b8c8 100644--- a/client/src/components/cos/tabs/schedule/scheduleConstants.test.js+++ b/client/src/components/cos/tabs/schedule/scheduleConstants.test.js@@ -1,5 +1,6 @@+import { TASK_READINESS_REASONS } from '../../../../../../server/lib/taskReadinessReasons.js';import { describe, it, expect } from 'vitest';-import { isManualOnlyCadence, getTaskStatusGroup, taskSortKey, TASK_FILTERS, STATUS_GROUPS, describeNextRun, coverageTone, setMetadataOverride, toggleMetadataField, fileIssuesEffective, managedAgentOptionsFor, toggleFileIssuesMetadata, prReviewerStageRole, stagePublicReviewPosture, togglePrReviewerActions, suggestedOrderSteps, compareBySuggestedOrder } from './scheduleConstants';+import { isManualOnlyCadence, getTaskStatusGroup, TASK_READINESS_REASON_RENDERING, taskSortKey, TASK_FILTERS, STATUS_GROUPS, describeNextRun, coverageTone, setMetadataOverride, toggleMetadataField, fileIssuesEffective, managedAgentOptionsFor, toggleFileIssuesMetadata, prReviewerStageRole, stagePublicReviewPosture, togglePrReviewerActions, suggestedOrderSteps, compareBySuggestedOrder } from './scheduleConstants';describe('pr-reviewer pipeline helpers', () => {it('recognizes semantic roles and legacy prompt-key stages', () => {@@ -127,6 +128,15 @@ describe('toggleMetadataField', () => {});});+describe('readiness reason rendering', () => {+ it('classifies every current wire reason and exposes an unknown peer reason', () => {+ expect(new Set(Object.keys(TASK_READINESS_REASON_RENDERING))).toEqual(new Set(TASK_READINESS_REASONS));+ const config = { enabled: true, type: 'cron', status: { reason: 'future-unknown-reason' } };+ expect(getTaskStatusGroup(config)).toBe('unknown');+ expect(describeNextRun(config)).toMatchObject({ text: 'Unknown schedule state', warn: true });+ });+});+describe('getTaskStatusGroup', () => {it('classifies a disabled task as disabled regardless of type', () => {expect(getTaskStatusGroup({ enabled: false, type: 'daily' })).toBe('disabled');diff --git a/server/lib/README.md b/server/lib/README.mdindex 77f4949737..4358271774 100644--- a/server/lib/README.md+++ b/server/lib/README.md@@ -502,6 +502,8 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub| `claimContinuation.js` | Claim-flow relaunch pointer. `claimContinuationBranch(claimTarget)` is the `claim/issue-<n>` or `claim/<key>` branch a pinned target checks out. `claimContinuationPointer(...)` names the `claim-*` worktree already holding that branch when a relaunch should finish it in place (locked, prunable, unmanaged, or occupied by another running/paused agent → null). `claimContinuationWorkspace(...)` turns a still-on-disk pointer into the cwd the next agent uses without moving the directory. || `scheduledTaskTypes.js` | Registered scheduled task names (`SELF_IMPROVEMENT_TASK_TYPES`), shared by schedule configuration and authoritative skill routing; plus the retired-name map (`TASK_TYPE_RENAMES`, `currentTaskTypeName`, `taskExecutionKey`) for tasks and records written before a task rename. || `scheduleRunOrder.js` | Storage rules for a task's advisory `suggestedAfter` list — which OTHER scheduled tasks to run first. `normalizeSuggestedAfter` drops blanks, duplicates and self-references and caps at `SUGGESTED_AFTER_MAX`; the shipped order it defaults to is `auditCatalog.AUDIT_SUGGESTED_AFTER`, layered at read time in `getScheduleStatus`. Advisory only — the ENFORCED dependency field is `runAfter`. Pure — no I/O. |+| `taskReadinessReasons.js` | Stable scheduled-task readiness reason codes, membership set, shared by the server and Schedule UI (pure browser-safe leaf). |+| `taskReadinessSchema.js` | Server-side Zod enum for the scheduled-task readiness wire reason, derived from `taskReadinessReasons.js`. || `taskTargetScope.js` | Target scope for a scheduled task type: `INSTALL_WIDE_TASK_TYPES`, `MANAGED_APP_TARGET_TASK_TYPES`, `PROGRAMMATIC_SCHEDULED_TASK_TYPES`, `isProgrammaticScheduledTaskType`, `requiresManagedAppTarget`, `requiresInstallWideTarget`. Declared here (not in `services/taskScheduleRegistry.js`, which re-exports it) so `quotaBurnValidation.js` can reject a burn reference with the wrong target scope without importing upward into services. || `taxonomyTally.js` | Generic taxonomy tally + top-N-line render engine shared by the two Layered Intelligence leaf taxonomies (`services/layeredIntelligenceRejections.js`, `layeredIntelligenceExecutionFailures.js`). `createTaxonomyTally({predicate, select, field, vocabulary, sentinel, glossFn, gapWording})` is the single composed seam — it binds a taxonomy config into `{summarize, format}`, where `summarize(records)` yields the three-bucket `{entries, unknown, unclassified, diagnosed, total}` tally (commonest-first + taxonomy-order tie-break) and `format(records, limit)` renders one prompt line naming every non-zero gap. Also exports the two leaf utilities the classifiers use directly: `normalizeToken(value)` (lowercase + separator-collapse for label/category matching) and `formatTaxonomyToken(token, labels)` (gloss-map render, nullish→'', unglossed passthrough). Pure leaf — imports nothing from the LI graph. || `appPromptPlaceholders.js` | `applyAppPlaceholders(text, app)` — expand `{appName}` / `{repoPath}` / `{appId}` / `{appSlug}` in a CoS prompt template. The ONE owner of that chain: four renderers (`cosTaskGenerator.js`'s claim-work router and JIRA per-ticket builder, `cosTaskPreStepBlocks.js`'s scheduled builder, `referenceRepos.js`) each used to spell it themselves and drifted. Function-form replacers throughout, since a name/path/id is free text a `$` can appear in. Callers expand their own injected blocks (`{trackerInstructions}`, `{modeInstructions}`) FIRST — those blocks carry app placeholders of their own. Pure. |diff --git a/server/lib/index.js b/server/lib/index.jsindex 65b5598c5a..10ab68477d 100644--- a/server/lib/index.js+++ b/server/lib/index.js@@ -464,6 +464,8 @@ export * from './taskTargetBranch.js';export * from './claimContinuation.js';export * from './scheduledTaskTypes.js';export * from './scheduleRunOrder.js';+export * from './taskReadinessReasons.js';+export * from './taskReadinessSchema.js';export * from './taskTargetScope.js';export * from './taxonomyTally.js';export * from './worktreeOwnership.js';diff --git a/server/lib/taskReadinessReasons.js b/server/lib/taskReadinessReasons.jsnew file mode 100644index 0000000000..aa0217a870--- /dev/null+++ b/server/lib/taskReadinessReasons.js@@ -0,0 +1,22 @@+// Stable wire codes shared by scheduling, workflow projections, and the Schedule UI.+// Keep values unchanged: federated peers and clients may run different versions.+export const TASK_READINESS_REASON = Object.freeze({+ REQUIRES_INSTALL_WIDE_TARGET: 'requires-install-wide-target',+ DISABLED: 'disabled',+ FEATURE_DISABLED: 'feature-disabled',+ ON_DEMAND_ONLY: 'on-demand-only',+ WEEKDAY_ONLY: 'weekday-only',+ DISABLED_FOR_APP: 'disabled-for-app',+ FAILURE_PARKED: 'failure-parked',+ PERPETUAL_PARKED: 'perpetual-parked',+ PERPETUAL_RECHECK: 'perpetual-recheck',+ PERPETUAL_DRAIN: 'perpetual-drain',+ INVALID_CRON: 'invalid-cron',+ CRON_DUE: 'cron-due',+ CRON_COOLDOWN: 'cron-cooldown',+ FAILURE_COOLDOWN: 'failure-cooldown',+ WAITING_ON_DEPENDENCIES: 'waiting-on-dependencies',+});++export const TASK_READINESS_REASONS = Object.freeze(Object.values(TASK_READINESS_REASON));+export const TASK_READINESS_REASON_SET = new Set(TASK_READINESS_REASONS);diff --git a/server/lib/taskReadinessReasons.test.js b/server/lib/taskReadinessReasons.test.jsnew file mode 100644index 0000000000..e943453298--- /dev/null+++ b/server/lib/taskReadinessReasons.test.js@@ -0,0 +1,19 @@+import { describe, expect, it } from 'vitest';+import { readFileSync } from 'node:fs';+import { TASK_READINESS_REASON, TASK_READINESS_REASONS, TASK_READINESS_REASON_SET } from './taskReadinessReasons.js';+import { taskReadinessReasonSchema } from './taskReadinessSchema.js';++const service = readFileSync(new URL('../services/taskSchedule.js', import.meta.url), 'utf8');+const readiness = service.split('async function evaluateTaskReadiness(')[1]?.split('\n/**')[0];++describe('scheduled-task readiness wire reasons', () => {+ it('keeps the emitted set equal to the declared wire enum', () => {+ expect(readiness).toBeTruthy();+ expect(readiness).not.toMatch(/reason:\s*['"]/);+ const emittedKeys = [...readiness.matchAll(/reason:\s*TASK_READINESS_REASON\.([A-Z_]+)/g)].map(match => match[1]);+ expect(new Set(emittedKeys)).toEqual(new Set(Object.keys(TASK_READINESS_REASON)));+ expect(new Set(TASK_READINESS_REASONS)).toEqual(TASK_READINESS_REASON_SET);+ for (const reason of TASK_READINESS_REASONS) expect(taskReadinessReasonSchema.parse(reason)).toBe(reason);+ expect(taskReadinessReasonSchema.safeParse('future-unknown-reason').success).toBe(false);+ });+});diff --git a/server/lib/taskReadinessSchema.js b/server/lib/taskReadinessSchema.jsnew file mode 100644index 0000000000..d65da057f5--- /dev/null+++ b/server/lib/taskReadinessSchema.js@@ -0,0 +1,6 @@+import { z } from 'zod';+import { TASK_READINESS_REASONS } from './taskReadinessReasons.js';++// Validation for the server's schedule-status wire value. The shared reason+// leaf stays importable from the browser without an npm dependency.+export const taskReadinessReasonSchema = z.enum(TASK_READINESS_REASONS);diff --git a/server/services/taskSchedule.js b/server/services/taskSchedule.jsindex b55f51fd68..c069d08c04 100644--- a/server/services/taskSchedule.js+++ b/server/services/taskSchedule.js@@ -20,6 +20,7 @@*/import { taskExecutionKey as executionKey } from '../lib/scheduledTaskTypes.js';+import { TASK_READINESS_REASON } from '../lib/taskReadinessReasons.js';import { cosEvents, emitLog } from './cosEvents.js';import { formatSkipCauses } from '../lib/perpetualSkipCauses.js';import { DAY, safeDate } from '../lib/fileUtils.js';@@ -854,7 +855,7 @@ async function checkRunAfterDeps(schedule, taskType, appId = null, featureEnableasync function evaluateTaskReadiness(taskType, appId, { featureEnabled, continuingPerpetualDrain, schedule: injected = null }) {if (appId && requiresInstallWideTarget(taskType)) {- return { shouldRun: false, reason: 'requires-install-wide-target' };+ return { shouldRun: false, reason: TASK_READINESS_REASON.REQUIRES_INSTALL_WIDE_TARGET };}// `loadSchedule` is an uncached disk read plus a merge over every shipped// task default, and a caller building ONE status payload asks this question@@ -865,14 +866,14 @@ async function evaluateTaskReadiness(taskType, appId, { featureEnabled, continuiconst interval = schedule.tasks[taskType];if (!interval || !interval.enabled) {- return { shouldRun: false, reason: 'disabled' };+ return { shouldRun: false, reason: TASK_READINESS_REASON.DISABLED };}if (!(await featureEnabled(interval))) {- return { shouldRun: false, reason: 'feature-disabled', feature: interval.feature };+ return { shouldRun: false, reason: TASK_READINESS_REASON.FEATURE_DISABLED, feature: interval.feature };}// The maintainer role owns recurring cadence; this card is its manual door.- if (taskType === 'development-watchdog') return { shouldRun: false, reason: 'on-demand-only' };+ if (taskType === 'development-watchdog') return { shouldRun: false, reason: TASK_READINESS_REASON.ON_DEMAND_ONLY };// Fetch timezone once for reuse across weekday and cron checksconst timezone = await getUserTimezone();@@ -881,14 +882,14 @@ async function evaluateTaskReadiness(taskType, appId, { featureEnabled, continuiif (interval.weekdaysOnly) {const { dayOfWeek } = getLocalParts(new Date(), timezone);if (dayOfWeek === 0 || dayOfWeek === 6) {- return { shouldRun: false, reason: 'weekday-only' };+ return { shouldRun: false, reason: TASK_READINESS_REASON.WEEKDAY_ONLY };}}if (appId) {const enabledForApp = await isTaskTypeEnabledForApp(appId, taskType);if (!enabledForApp) {- return { shouldRun: false, reason: 'disabled-for-app' };+ return { shouldRun: false, reason: TASK_READINESS_REASON.DISABLED_FOR_APP };}}@@ -926,7 +927,7 @@ async function evaluateTaskReadiness(taskType, appId, { featureEnabled, continuiif (appExecution.failureParkedAt) {return {shouldRun: false,- reason: 'failure-parked',+ reason: TASK_READINESS_REASON.FAILURE_PARKED,failureParkedAt: appExecution.failureParkedAt,failureParkReason: appExecution.failureParkReason || null,consecutiveFailures: Number(appExecution.consecutiveFailures) || 0@@ -948,13 +949,13 @@ async function evaluateTaskReadiness(taskType, appId, { featureEnabled, continuiif (parkUntil && now < parkUntil) {return {shouldRun: false,- reason: 'perpetual-parked',+ reason: TASK_READINESS_REASON.PERPETUAL_PARKED,nextRunAt: new Date(parkUntil).toISOString(),parkReason: appExecution.parkReason || null,parkActionableCount: appExecution.parkActionableCount ?? null};}- return parkUntil ? { shouldRun: true, reason: 'perpetual-recheck' } : null;+ return parkUntil ? { shouldRun: true, reason: TASK_READINESS_REASON.PERPETUAL_RECHECK } : null;};switch (effectiveType) {@@ -964,8 +965,8 @@ async function evaluateTaskReadiness(taskType, appId, { featureEnabled, continui// Missing autoStart preserves existing automatic drains across upgrades.// Manual drains only refill after their own successful completion.result = isPerpetual && (interval.autoStart !== false || continuingPerpetualDrain)- ? (perpetualParkResult() || { shouldRun: true, reason: 'perpetual-drain' })- : { shouldRun: false, reason: 'on-demand-only' };+ ? (perpetualParkResult() || { shouldRun: true, reason: TASK_READINESS_REASON.PERPETUAL_DRAIN })+ : { shouldRun: false, reason: TASK_READINESS_REASON.ON_DEMAND_ONLY };break;case INTERVAL_TYPES.CRON: {@@ -976,7 +977,7 @@ async function evaluateTaskReadiness(taskType, appId, { featureEnabled, continuiconst parked = perpetualParkResult();if (parked) { result = parked; break; }if (continuingPerpetualDrain) {- result = { shouldRun: true, reason: 'perpetual-drain' };+ result = { shouldRun: true, reason: TASK_READINESS_REASON.PERPETUAL_DRAIN };break;}// Unparked: the cron evaluation below decides whether to INITIATE a@@ -986,7 +987,7 @@ async function evaluateTaskReadiness(taskType, appId, { featureEnabled, continui// Cron expression: per-app override (stored as the interval string) or global configconst cronExpr = effectiveCron;if (!isCronExpression(cronExpr)) {- result = { shouldRun: false, reason: 'invalid-cron' };+ result = { shouldRun: false, reason: TASK_READINESS_REASON.INVALID_CRON, cronExpression: cronExpr };break;}@@ -998,13 +999,13 @@ async function evaluateTaskReadiness(taskType, appId, { featureEnabled, continuiconst fromDate = new Date(Math.max(lastRun || 0, minuteStart - 1));const nextRun = parseCronToNextRun(cronExpr, fromDate, timezone);if (!nextRun) {- result = { shouldRun: false, reason: 'invalid-cron', cronExpression: cronExpr };+ result = { shouldRun: false, reason: TASK_READINESS_REASON.INVALID_CRON, cronExpression: cronExpr };break;}if (now >= nextRun.getTime()) {- result = { shouldRun: true, reason: 'cron-due', cronExpression: cronExpr, nextRunAt: nextRun.toISOString() };+ result = { shouldRun: true, reason: TASK_READINESS_REASON.CRON_DUE, cronExpression: cronExpr, nextRunAt: nextRun.toISOString() };} else {- result = { shouldRun: false, reason: 'cron-cooldown', cronExpression: cronExpr,+ result = { shouldRun: false, reason: TASK_READINESS_REASON.CRON_COOLDOWN, cronExpression: cronExpr,nextRunAt: nextRun.toISOString() };}break;@@ -1012,7 +1013,7 @@ async function evaluateTaskReadiness(taskType, appId, { featureEnabled, continuidefault:// Unreachable once normalized — an unreadable cadence must never auto-run.- result = { shouldRun: false, reason: 'on-demand-only' };+ result = { shouldRun: false, reason: TASK_READINESS_REASON.ON_DEMAND_ONLY };}// Escalating failure backoff (#2616): a type with recent consecutive failures@@ -1029,7 +1030,7 @@ async function evaluateTaskReadiness(taskType, appId, { featureEnabled, continuiif (sinceFailure < backoffMs) {result = {shouldRun: false,- reason: 'failure-cooldown',+ reason: TASK_READINESS_REASON.FAILURE_COOLDOWN,consecutiveFailures,failureBackoffMs: backoffMs,nextRunIn: backoffMs - sinceFailure,@@ -1045,7 +1046,7 @@ async function evaluateTaskReadiness(taskType, appId, { featureEnabled, continuiif (result.shouldRun && interval.runAfter?.length > 0) {const depCheck = await checkRunAfterDeps(schedule, taskType, appId, featureEnabled);if (!depCheck.satisfied) {- return { shouldRun: false, reason: 'waiting-on-dependencies', pendingDeps: depCheck.pending };+ return { shouldRun: false, reason: TASK_READINESS_REASON.WAITING_ON_DEPENDENCIES, pendingDeps: depCheck.pending };}}diff --git a/server/services/taskSchedule.test.js b/server/services/taskSchedule.test.jsindex 9fc8e7c25d..1877268a07 100644--- a/server/services/taskSchedule.test.js+++ b/server/services/taskSchedule.test.js@@ -1118,6 +1118,16 @@ describe('taskSchedule', () => {})describe('shouldRunTask', () => {+ it('keeps invalid cron verdicts one shape before and after cron parsing', async () => {+ mockSchedule({ tasks: { 'ui-bugs': { type: 'cron', enabled: true, cronExpression: 'not a cron' } } })+ const malformed = await shouldRunTask('ui-bugs')+ mockSchedule({ tasks: { 'ui-bugs': { type: 'cron', enabled: true, cronExpression: '0 7 * * *' } } })+ parseCronToNextRun.mockReturnValue(null)+ const unresolvable = await shouldRunTask('ui-bugs')+ expect(malformed).toEqual({ shouldRun: false, reason: 'invalid-cron', cronExpression: null })+ expect(unresolvable).toEqual({ shouldRun: false, reason: 'invalid-cron', cronExpression: '0 7 * * *' })+ })+it('does not run a task whose required instance feature is disabled', async () => {isInstanceFeatureEnabled.mockResolvedValue(false)mockSchedule({ tasks: { 'jira-sprint-manager': { type: 'rotation', enabled: true } } })diff --git a/server/services/workflow.js b/server/services/workflow.jsindex e1a2c8b35d..685a3e74ef 100644--- a/server/services/workflow.js+++ b/server/services/workflow.js@@ -22,6 +22,7 @@*/import { getScheduleStatus } from './taskSchedule.js';+import { TASK_READINESS_REASON } from '../lib/taskReadinessReasons.js';import { DEFAULT_PERPETUAL_RECHECK_MS } from './taskScheduleConstants.js';import { AUDIT_TASK_TYPES } from '../lib/auditCatalog.js';import { dedupeByKey } from '../lib/arrayUtils.js';@@ -181,7 +182,7 @@ export async function getWorkflowGraph({ horizonHours = 24, from = new Date() }// — that field drives warning styling in the UI. Other shouldRun=false states (cooldown,// weekday-only, disabled-for-app, etc.) are exposed via `statusReason` so the UI can// render them as neutral "waiting" rather than a warning.- blocked: info.status?.reason === 'waiting-on-dependencies' ? info.status.reason : null,+ blocked: info.status?.reason === TASK_READINESS_REASON.WAITING_ON_DEPENDENCIES ? info.status.reason : null,statusReason: info.status?.shouldRun === false ? info.status.reason : null,shouldRun: info.status?.shouldRun === true,// Why the task is due right now (e.g. 'weekly-due', 'cron-catch-up',@@ -500,7 +501,7 @@ function appendCronOccurrences({ node, expression, startMs, endMs, timezone, tarfunction projectPerpetual(node, startMs, endMs, timezone, occurrences, windows) {const perpetual = node.perpetualStatus;const allTrackedAppsParked = perpetual?.trackedAppCount > 0 && perpetual.parkedAppCount === perpetual.trackedAppCount;- const draining = node.shouldRun && !perpetual?.globalParked && !allTrackedAppsParked && node.statusReason !== 'perpetual-parked';+ const draining = node.shouldRun && !perpetual?.globalParked && !allTrackedAppsParked && node.statusReason !== TASK_READINESS_REASON.PERPETUAL_PARKED;// A cron+perpetual task rechecks on its own expression (computePerpetualRecheckAt// derives the park from it); an on-demand one uses `recheckCron`.