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(cos): surface improvement-disabled state on Schedule tab and reject on-demand triggers when master Improve toggle is off

[._.]/ Adam Eivy5f5078cf49ae
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index ab03aa8efc..d99169278e 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -10,6 +10,7 @@
## Fixed
+- **CoS on-demand task triggers no longer silently drop when the master Improve toggle is off.** Triggering a scheduled task (e.g. `feature-ideas` for `critical-mass`) showed a "queued" toast but nothing ever ran — the only log was `On-demand task requested: <type>`. Root cause: `dequeueNextTask`/`evaluateTasks` cleared the request and `continue`d without logging when `state.config.improvementEnabled` was `false`, and `triggerOnDemandTask` only validated the per-task-type `enabled` flag, so the request was accepted then quietly dropped downstream. Fix: (1) `triggerOnDemandTask` now checks the master flag and rejects with `Improvement is disabled — enable it in CoS → Config to run on-demand tasks`; the trigger route propagates that as HTTP 409 so the user sees a real error toast. (2) The two silent-drop branches now `emitLog('warn', …)` so any path that bypasses the trigger guard is still visible. (3) `getScheduleStatus` now returns `improvementEnabled` so the Schedule tab can render a banner ("Improvement is disabled — enable it in CoS → Config") and disable every Run Now / Run on App button (with an explanatory tooltip) instead of letting users queue requests that won't run. (4) Extracted `isImprovementEnabled(state)` in `cosState.js` to replace the same nullish-coalesce expression duplicated 6× across `cos.js` and `taskSchedule.js`. Files: `server/services/cosState.js`, `server/services/taskSchedule.js`, `server/services/cos.js`, `server/routes/cosScheduleRoutes.js`, `server/routes/cosScheduleRoutes.test.js`, `client/src/components/cos/tabs/ScheduleTab.jsx`.
- **Sidebar nav labels truncate instead of pushing the container wider.** Long nav labels (e.g. third-party app names) could force the sidebar's flex container to overflow horizontally on narrower viewports, distorting the rest of the layout. Added `min-w-0` to every flex parent in the nav row tree and `truncate` to the label `<span>` elements (top-level links, section buttons, and child links), plus `shrink-0` on the child icon so it can't be squeezed out, and `overflow-x-hidden min-w-0` on the `<nav>` itself so the scroll axis stays vertical. File: `client/src/components/Layout.jsx`.
- **CoS agent PRs now actually open.** Every recent CoS-agent automation that finished its work and pushed its branch was failing at the PR-creation step with `Failed to create PR for <branch>: spawn is not defined`, then triggering `[Recovery] Investigate and retry failed PR for branch …` recovery tasks for the orchestrator to clean up. Root cause: a refactor (commit `17311282`) extracted `execGit` to `server/lib/execGit.js` and dropped the `import { spawn } from 'child_process'` line from `server/services/git.js` — but `createPR()` still calls `spawn('gh', …)` directly, so every PR creation hit a `ReferenceError`. The existing `cleanupAgentWorktree` test suite mocked `git.createPR` so the bug never surfaced in CI. Restored the import and added `server/services/git.test.js` with a regression test that calls the real `createPR` against a non-existent path: success path returns `{ success: false, error: '<gh failure>' }` instead of throwing. The recovery flow continues to work as a safety net, but agents will now hit the happy path and open the PR directly. Files: `server/services/git.js`, `server/services/git.test.js` (new).
diff --git a/client/src/components/cos/tabs/ScheduleTab.jsx b/client/src/components/cos/tabs/ScheduleTab.jsx
index 753d7f5fee..3e2afa1602 100644
--- a/client/src/components/cos/tabs/ScheduleTab.jsx
+++ b/client/src/components/cos/tabs/ScheduleTab.jsx
@@ -40,6 +40,10 @@ const BADGE_COLORS = {
const badge = (variant) => `text-xs font-medium px-2.5 py-1 rounded-full border ${BADGE_COLORS[variant] || BADGE_COLORS.gray}`;
+const IMPROVEMENT_DISABLED_TITLE = 'Improvement is disabled — enable it in CoS → Config';
+const triggerButtonClass = (disabled) =>
+ `flex items-center gap-1 px-3 py-1.5 text-sm rounded transition-colors ${disabled ? 'bg-port-border/30 text-gray-500 cursor-not-allowed' : 'bg-port-accent/20 hover:bg-port-accent/30 text-port-accent'}`;
+
const INTERVAL_BADGE_VARIANT = {
daily: 'accent',
weekly: 'purple',
@@ -245,7 +249,7 @@ function PipelineStageConfig({ taskType, config, providers, onUpdate, updating,
);
}
-function GlobalConfigControls({ taskType, config, onUpdate, onTrigger, onReset, category: _category, providers, apps, updating, setUpdating, allTaskTypes }) {
+function GlobalConfigControls({ taskType, config, onUpdate, onTrigger, onReset, category: _category, providers, apps, updating, setUpdating, allTaskTypes, improvementDisabled }) {
const [selectedType, setSelectedType] = useState(config.type);
const [selectedProviderId, setSelectedProviderId] = useState(config.providerId || '');
const [selectedModel, setSelectedModel] = useState(config.model || '');
@@ -521,15 +525,16 @@ function GlobalConfigControls({ taskType, config, onUpdate, onTrigger, onReset,
{activeApps.length > 0 ? (
<div className="relative" ref={appSelectorRef}>
<button
- onClick={() => setShowAppSelector(!showAppSelector)}
- className="flex items-center gap-1 px-3 py-1.5 text-sm bg-port-accent/20 hover:bg-port-accent/30 text-port-accent rounded transition-colors"
- title="Run this task on a specific app"
+ onClick={() => !improvementDisabled && setShowAppSelector(!showAppSelector)}
+ disabled={improvementDisabled}
+ className={triggerButtonClass(improvementDisabled)}
+ title={improvementDisabled ? IMPROVEMENT_DISABLED_TITLE : 'Run this task on a specific app'}
>
<Play size={14} />
Run on App
<ChevronDown size={12} className={`transition-transform ${showAppSelector ? 'rotate-180' : ''}`} />
</button>
- {showAppSelector && (
+ {showAppSelector && !improvementDisabled && (
<div className="absolute bottom-full left-0 mb-1 z-50 w-64 max-w-[calc(100vw-2rem)] max-h-64 overflow-y-auto bg-port-card border border-port-border rounded-lg shadow-lg">
<div className="p-2 border-b border-port-border">
<span className="text-xs text-gray-400">Select an app to run {taskType} on:</span>
@@ -555,8 +560,9 @@ function GlobalConfigControls({ taskType, config, onUpdate, onTrigger, onReset,
) : (
<button
onClick={() => onTrigger(taskType)}
- className="flex items-center gap-1 px-3 py-1.5 text-sm bg-port-accent/20 hover:bg-port-accent/30 text-port-accent rounded transition-colors"
- title="Run this task immediately (bypasses schedule)"
+ disabled={improvementDisabled}
+ className={triggerButtonClass(improvementDisabled)}
+ title={improvementDisabled ? IMPROVEMENT_DISABLED_TITLE : 'Run this task immediately (bypasses schedule)'}
>
<Play size={14} />
Run Now
@@ -759,7 +765,7 @@ function PerAppOverrideList({ taskType, config, apps, onUpdateOverride, onBulkTo
);
}
-function AppTaskTypeRow({ taskType, config, onUpdate, onTrigger, onReset, providers, apps, onUpdateOverride, onBulkToggleOverride, allTaskTypes }) {
+function AppTaskTypeRow({ taskType, config, onUpdate, onTrigger, onReset, providers, apps, onUpdateOverride, onBulkToggleOverride, allTaskTypes, improvementDisabled }) {
const [expanded, setExpanded] = useState(false);
const [updating, setUpdating] = useState(false);
@@ -848,6 +854,7 @@ function AppTaskTypeRow({ taskType, config, onUpdate, onTrigger, onReset, provid
updating={updating}
setUpdating={setUpdating}
allTaskTypes={allTaskTypes}
+ improvementDisabled={improvementDisabled}
/>
</div>
@@ -864,7 +871,7 @@ function AppTaskTypeRow({ taskType, config, onUpdate, onTrigger, onReset, provid
);
}
-function AppTaskTypeSection({ tasks, onUpdate, onTrigger, onReset, providers, apps, onUpdateOverride, onBulkToggleOverride }) {
+function AppTaskTypeSection({ tasks, onUpdate, onTrigger, onReset, providers, apps, onUpdateOverride, onBulkToggleOverride, improvementDisabled }) {
const taskEntries = Object.entries(tasks || {});
if (taskEntries.length === 0) return null;
@@ -896,6 +903,7 @@ function AppTaskTypeSection({ tasks, onUpdate, onTrigger, onReset, providers, ap
onUpdateOverride={onUpdateOverride}
onBulkToggleOverride={onBulkToggleOverride}
allTaskTypes={allTaskTypes}
+ improvementDisabled={improvementDisabled}
/>
))}
</div>
@@ -1002,6 +1010,8 @@ export default function ScheduleTab({ apps }) {
);
}
+ const improvementDisabled = schedule.improvementEnabled === false;
+
return (
<div className="space-y-6">
<div className="flex items-center justify-between">
@@ -1021,6 +1031,19 @@ export default function ScheduleTab({ apps }) {
</button>
</div>
+ {improvementDisabled && (
+ <div className="flex items-start gap-2 px-4 py-3 bg-port-warning/10 border border-port-warning/30 rounded-lg text-sm text-port-warning">
+ <AlertCircle size={16} className="shrink-0 mt-0.5" />
+ <div>
+ <div className="font-medium">Improvement is disabled</div>
+ <div className="text-xs text-port-warning/80 mt-1">
+ No scheduled or on-demand improvement tasks will run. Enable the <span className="font-mono">Improve</span> toggle in
+ {' '}<a href="/cos/config" className="underline hover:text-port-warning">CoS → Config</a> to use this page.
+ </div>
+ </div>
+ </div>
+ )}
+
{schedule.onDemandRequests?.length > 0 && (
<div className="bg-port-accent/10 border border-port-accent/30 rounded-lg p-4">
<h4 className="text-sm font-medium text-port-accent mb-2">Pending On-Demand Tasks</h4>
@@ -1043,6 +1066,7 @@ export default function ScheduleTab({ apps }) {
apps={apps}
onUpdateOverride={handleUpdateAppOverride}
onBulkToggleOverride={handleBulkToggleOverride}
+ improvementDisabled={improvementDisabled}
/>
{schedule.lastUpdated && (
diff --git a/server/routes/cosScheduleRoutes.js b/server/routes/cosScheduleRoutes.js
index 4cb48b5d37..7ad7591f44 100644
--- a/server/routes/cosScheduleRoutes.js
+++ b/server/routes/cosScheduleRoutes.js
@@ -105,6 +105,9 @@ router.post('/schedule/trigger', asyncHandler(async (req, res) => {
}
const request = await taskSchedule.triggerOnDemandTask(taskType, appId);
+ if (request?.error) {
+ throw new ServerError(request.error, { status: 409, code: 'TRIGGER_REJECTED' });
+ }
res.json({ success: true, request });
}));
diff --git a/server/routes/cosScheduleRoutes.test.js b/server/routes/cosScheduleRoutes.test.js
index 98f86e483a..6dfb1b680b 100644
--- a/server/routes/cosScheduleRoutes.test.js
+++ b/server/routes/cosScheduleRoutes.test.js
@@ -176,6 +176,17 @@ describe('CoS Schedule Routes', () => {
expect(response.status).toBe(400);
});
+
+ it('should return 409 when triggerOnDemandTask returns an error', async () => {
+ taskSchedule.triggerOnDemandTask.mockResolvedValue({ error: 'Improvement is disabled — enable it in CoS → Config to run on-demand tasks' });
+
+ const response = await request(app)
+ .post('/api/cos/schedule/trigger')
+ .send({ taskType: 'feature-ideas', appId: 'critical-mass' });
+
+ expect(response.status).toBe(409);
+ expect(response.body.error || response.body.message || '').toMatch(/disabled/i);
+ });
});
describe('GET /api/cos/schedule/on-demand', () => {
diff --git a/server/services/cos.js b/server/services/cos.js
index 897eecce77..eedb898439 100644
--- a/server/services/cos.js
+++ b/server/services/cos.js
@@ -35,7 +35,7 @@ import { getUserTimezone, getLocalParts, nextLocalTime, todayInTimezone } from '
import { PORTOS_UI_URL } from '../lib/ports.js';
// Shared state management (extracted to avoid circular deps)
-import { loadState, saveState, withStateLock, ensureDirectories, AGENTS_DIR, REPORTS_DIR, SCRIPTS_DIR, ROOT_DIR, isDaemonRunning, setDaemonRunning } from './cosState.js';
+import { loadState, saveState, withStateLock, ensureDirectories, isImprovementEnabled, AGENTS_DIR, REPORTS_DIR, SCRIPTS_DIR, ROOT_DIR, isDaemonRunning, setDaemonRunning } from './cosState.js';
// Events and logging (canonical source: cosEvents.js)
import { cosEvents, emitLog } from './cosEvents.js';
@@ -655,11 +655,8 @@ export async function evaluateTasks() {
for (const request of onDemandRequests) {
if (tasksToSpawn.length >= availableSlots) break;
- // Unified on-demand handling (no category split)
- const improvementEnabled = state.config.improvementEnabled ??
- (state.config.selfImprovementEnabled || state.config.appImprovementEnabled);
-
- if (!improvementEnabled) {
+ if (!isImprovementEnabled(state)) {
+ emitLog('warn', `On-demand request dropped — improvement is disabled (Config → Improve)`, { requestId: request.id, taskType: request.taskType });
await taskSchedule.clearOnDemandRequest(request.id);
continue;
}
@@ -912,11 +909,7 @@ export async function evaluateTasks() {
* @returns {Object|null} Generated task or null if nothing to do
*/
async function generateIdleReviewTask(state) {
- // Check if improvement tasks are enabled (unified flag, with backward compat)
- const improvementEnabled = state.config.improvementEnabled ??
- (state.config.selfImprovementEnabled || state.config.appImprovementEnabled);
-
- if (!improvementEnabled) {
+ if (!isImprovementEnabled(state)) {
emitLog('debug', 'Improvement tasks are disabled');
return null;
}
@@ -957,10 +950,7 @@ async function generateIdleReviewTask(state) {
async function queueEligibleImprovementTasks(state, cosTaskData) {
const { getDueTasks, shouldRunTask, getNextTaskType, recordExecution } = await import('./taskSchedule.js');
- // Check unified improvement flag (with backward compat)
- const improvementEnabled = state.config.improvementEnabled ??
- (state.config.selfImprovementEnabled || state.config.appImprovementEnabled);
- if (!improvementEnabled) return;
+ if (!isImprovementEnabled(state)) return;
// Get existing pending/in_progress system tasks to avoid duplicates
// Also skip task types where a user-terminated blocked task exists (user intentionally killed it)
@@ -2281,10 +2271,8 @@ async function dequeueNextTask() {
for (const request of onDemandRequests) {
if (spawned >= availableSlots) break;
- // Unified on-demand handling (no category split)
- const improvEnabled = state.config.improvementEnabled ??
- (state.config.selfImprovementEnabled || state.config.appImprovementEnabled);
- if (!improvEnabled) {
+ if (!isImprovementEnabled(state)) {
+ emitLog('warn', `On-demand request dropped — improvement is disabled (Config → Improve)`, { requestId: request.id, taskType: request.taskType });
await taskScheduleMod.clearOnDemandRequest(request.id);
continue;
}
diff --git a/server/services/cosState.js b/server/services/cosState.js
index 84ba826f33..5b9e8b2800 100644
--- a/server/services/cosState.js
+++ b/server/services/cosState.js
@@ -103,6 +103,13 @@ function isValidJSON(str) {
// All mutations go through withStateLock, so the cache stays consistent.
let stateCache = null;
+// Master "Improve" flag with backward compat for the legacy split self/app flags.
+// Falls through only when improvementEnabled is null/undefined — explicit `false` wins.
+export function isImprovementEnabled(state) {
+ return state.config.improvementEnabled ??
+ (state.config.selfImprovementEnabled || state.config.appImprovementEnabled);
+}
+
export async function loadState() {
if (stateCache) return stateCache;
diff --git a/server/services/taskSchedule.js b/server/services/taskSchedule.js
index 75b413181f..73f59c8376 100644
--- a/server/services/taskSchedule.js
+++ b/server/services/taskSchedule.js
@@ -20,6 +20,7 @@ import { cosEvents, emitLog } from './cosEvents.js';
import { DAY, ensureDir, HOUR, loadSlashdoFile, readJSONFile, PATHS, safeDate } from '../lib/fileUtils.js';
import { getAdaptiveCooldownMultiplier } from './taskLearning.js';
import { isTaskTypeEnabledForApp, getAppTaskTypeInterval, getActiveApps, getAppTaskTypeOverrides } from './apps.js';
+import { loadState, isImprovementEnabled } from './cosState.js';
import { PORTOS_UI_URL, PORTOS_API_URL } from '../lib/ports.js';
import { getUserTimezone, getLocalParts } from '../lib/timezone.js';
import { parseCronToNextRun } from './eventScheduler.js';
@@ -1892,12 +1893,18 @@ export async function deleteTemplateTask(templateId) {
export async function triggerOnDemandTask(taskType, appId = null) {
const schedule = await loadSchedule();
- // Reject if the task type is disabled
+ // Cheap per-task-type check first; the master-flag check pays a state.json read.
const interval = schedule.tasks[taskType];
if (interval && !interval.enabled) {
return { error: `Task type '${taskType}' is disabled` };
}
+ // Reject if the master Improve toggle is off — request would be silently dropped downstream
+ const state = await loadState();
+ if (!isImprovementEnabled(state)) {
+ return { error: 'Improvement is disabled — enable it in CoS → Config to run on-demand tasks' };
+ }
+
if (!schedule.onDemandRequests) {
schedule.onDemandRequests = [];
}
@@ -1942,9 +1949,12 @@ export async function clearOnDemandRequest(requestId) {
// ============================================================
export async function getScheduleStatus() {
- const schedule = await loadSchedule();
+ // Surface the master Improve toggle so the UI can disable Run Now affordances
+ const [schedule, state] = await Promise.all([loadSchedule(), loadState()]);
+
const status = {
lastUpdated: schedule.lastUpdated,
+ improvementEnabled: isImprovementEnabled(state),
tasks: {},
templates: schedule.templates,
onDemandRequests: schedule.onDemandRequests || [],