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

let scheduled CoS tasks pick what happens after their PR opens

[._.]/ Adam Eivy0bd85f3d94da
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 12bc2af0f9..b0bbac5afe 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -28,6 +28,8 @@
Deliberately kept narrow: Biome's formatter and assist actions are off (turning them on would rewrite all 1859 files in one unreviewable diff), and the rule set is an explicit list rather than Biome's broader `recommended` preset, so this is a tooling swap and not a silent change to lint policy. Adopting more of Biome's rules is a separate decision.
+- **A scheduled Chief of Staff task can now say what happens after it opens its PR, the same way a manually-entered task already could.** The task-entry form has carried an "After opening PR" choice — review then merge, merge on green CI, or leave the PR open for you — but the Schedule tab's per-task config only had the Open PR toggle, so every scheduled task was stuck on whatever its target app defaulted to. Not every recurring task wants a reviewer chain (a dependency refresh or a catalog sync is fine merging on green CI), and some you'd rather look at yourself before they land. The same three choices now sit under Agent Options on each scheduled task, alongside a fourth "App default" that leaves the decision to the target app exactly as it works today — so nothing changes for a task you don't touch, and PortOS's own self-improvement runs, which have no app, keep falling back to merging on green CI. Each app's row in the same drawer gets the same choice as an "Inherit (…)" override, next to the ones it already has for issue-author filter and swarm mode — so one app that wants review doesn't force review on every app the task runs against. The reviewer picker follows the choice rather than the Open PR toggle: it stays visible for review-then-merge and for the inherited default (an app may well default to review), and disappears for the two policies that never run a reviewer, where it was previously offering a reviewer list nothing would read. A task carrying the legacy `reviewLoop` bit — the pre-`prCompletion` spelling of the same decision — now shows "Review then merge" rather than claiming to be unpinned, and picking any policy retires the old bit so it can't outvote what you just chose.
+
## Fixed
- **Quota-burn tasks were queued and then never picked up, so the window they were meant to spend expired unspent anyway.** Three separate faults, each of which alone was enough to strand a burn. First, a queued burn inherited the per-app *review cooldown* — a 30-minute throttle re-stamped by every task that completes on that app. On an app that carries any other recurring CoS work (a perpetual claim-issue drain, which is itself exempt from the cooldown and therefore keeps completing) the cooldown never lapses, so the burn task sat in Pending indefinitely while agents ran past it. The cooldown was never this task's throttle: the burn plan's own gate ladder — the reset horizon, the family's reserve, and `maxDispatchesPerWindow` — is checked before the task is queued at all, so burns now bypass it, as pipeline continuations and perpetual drains already did. Tasks already queued carry no marker, so migration 225 back-fills it onto them rather than leaving them stranded — and a stranded burn is worse than late, because `addTask` dedupes on description + app, so a pending twin makes the runner report "an identical burn task is already pending" and that job in the plan is permanently unreachable. Second, the runner always walked the family's job plan from the top, and an `agent-prompt` job always probes as "work pending" (its probe only checks that an app and a provider resolve) — so job #1 won every dispatch forever and the other seven audits in an eight-job plan never ran once. The walk now resumes after the family's last dispatch, read from the run log rather than a second cursor file, and still runs the first job with pending work from there, so a probing job like `universe-bible-images` keeps its ordering. Third, the plan only advanced once per `checkIntervalMinutes` — at the 12-hour default, two dispatches a day against an allowance of five on a five-hour window. Each finished burn agent now re-evaluates its own family, so the plan is walked one agent at a time until a gate actually closes; the chain is bounded by the same ledger every other cycle charges, and switching the feature off ends it immediately. That re-evaluation reads only the burning family's quota card rather than respawning every enabled provider's TUI for numbers it then discards — a per-family scrape the usage page already asked for this way.
diff --git a/client/src/components/apps/EditAppDrawer.jsx b/client/src/components/apps/EditAppDrawer.jsx
index be82ab6dc3..d3aca614c9 100644
--- a/client/src/components/apps/EditAppDrawer.jsx
+++ b/client/src/components/apps/EditAppDrawer.jsx
@@ -11,7 +11,7 @@ import useDrawerTab from '../../hooks/useDrawerTab';
import { copyToClipboard } from '../../lib/clipboard';
import LayeredIntelligenceTab, { buildLayeredIntelligenceUpdate, buildLayeredIntelligenceScheduleUpdate } from './LayeredIntelligenceTab';
import { PROVIDER_TYPES } from '../../utils/providers';
-import { DEFAULT_PR_COMPLETION, PR_COMPLETION_OPTIONS } from '../cos/constants';
+import { DEFAULT_PR_COMPLETION, PR_COMPLETION_OPTIONS, prCompletionOption } from '../cos/constants';
import { WORK_TRACKER_OPTIONS, WORK_TRACKER_LABELS } from './constants';
const TABS = [
@@ -776,7 +776,7 @@ export default function EditAppDrawer({ app, onClose, onSave }) {
))}
</select>
<p className="mt-1 text-xs text-gray-500">
- {PR_COMPLETION_OPTIONS.find(option => option.value === formData.defaultPrCompletion)?.description}
+ {prCompletionOption(formData.defaultPrCompletion)?.description}
</p>
</div>
</div>
diff --git a/client/src/components/cos/TaskAddForm.jsx b/client/src/components/cos/TaskAddForm.jsx
index e2f3037cc2..e3a48360b4 100644
--- a/client/src/components/cos/TaskAddForm.jsx
+++ b/client/src/components/cos/TaskAddForm.jsx
@@ -8,7 +8,7 @@ import { ATTACHMENT_ACCEPT } from '../../utils/fileUpload';
import FilePickerButton from '../ui/FilePickerButton';
import { formatBytes } from '../../utils/formatters';
import { filterSelectableModels, isTuiProvider, isCliProvider, isProcessProvider, isCodexProvider } from '../../utils/providers';
-import { DEFAULT_PR_COMPLETION, DEFAULT_REVIEWERS, DEFAULT_REVIEW_STOP_MODE, PR_COMPLETION_OPTIONS } from './constants';
+import { DEFAULT_PR_COMPLETION, DEFAULT_REVIEWERS, DEFAULT_REVIEW_STOP_MODE, PR_COMPLETION_OPTIONS, prCompletionOption } from './constants';
import { clickableProps } from '../../lib/a11yKeyboard';
import { slashdoLabel } from '../../lib/slashdoCatalog';
import ReviewerPicker from './ReviewerPicker';
@@ -558,7 +558,7 @@ export default function TaskAddForm({ providers, apps, onTaskAdded, compact = fa
<select
id="task-pr-completion"
value={prCompletion}
- title={PR_COMPLETION_OPTIONS.find(option => option.value === prCompletion)?.description}
+ title={prCompletionOption(prCompletion)?.description}
onChange={(e) => setPrCompletion(e.target.value)}
className="min-w-44 rounded border border-port-border bg-port-bg px-2 py-1 text-sm text-white focus:border-port-accent focus:outline-hidden"
>
diff --git a/client/src/components/cos/constants.js b/client/src/components/cos/constants.js
index 232740c55c..2003ebd3e2 100644
--- a/client/src/components/cos/constants.js
+++ b/client/src/components/cos/constants.js
@@ -171,8 +171,27 @@ export const PR_COMPLETION_OPTIONS = [
{ value: 'leave-open', label: 'Leave PR open', description: 'Open the PR and stop so you can inspect and merge it yourself.' }
];
+export const prCompletionOption = (value) => PR_COMPLETION_OPTIONS.find(option => option.value === value);
+
export const DEFAULT_PR_COMPLETION = 'review-then-merge';
+// The policy a task falls back to when nothing pins `prCompletion` — mirrors the
+// `resolvePrCompletion` fallback in server/lib/prDisposition.js (legacy
+// `reviewLoop` records aside). Scheduled tasks inherit their app's
+// `defaultPrCompletion` first, so this is only the floor.
+export const IMPLICIT_PR_COMPLETION = 'merge-on-green';
+
+// Which option a stored taskMetadata pins, or '' when nothing does (inherit).
+// Legacy `reviewLoop` records are the pre-`prCompletion` spelling of
+// review-then-merge, so a control seeded from this shows what will actually
+// happen rather than claiming to be unpinned. Client mirror of
+// `resolvePrCompletion` in server/lib/prDisposition.js, minus its
+// IMPLICIT_PR_COMPLETION floor — that floor is what "inherit" resolves to.
+export function pinnedPrCompletion(metadata) {
+ if (prCompletionOption(metadata?.prCompletion)) return metadata.prCompletion;
+ return metadata?.reviewLoop === true || metadata?.reviewLoop === 'true' ? 'review-then-merge' : '';
+}
+
// Reviewer choices for the Review Loop. `copilot` requests a GitHub Copilot
// review via the native reviewer API; CLI reviewers (claude/antigravity/codex/grok)
// instruct the follow-up agent to invoke the named CLI; local-LLM reviewers
diff --git a/client/src/components/cos/tabs/schedule/AppOverrideRow.jsx b/client/src/components/cos/tabs/schedule/AppOverrideRow.jsx
index a4b2eee9a7..1d12506640 100644
--- a/client/src/components/cos/tabs/schedule/AppOverrideRow.jsx
+++ b/client/src/components/cos/tabs/schedule/AppOverrideRow.jsx
@@ -1,10 +1,10 @@
import { useState, memo } from 'react';
import AppIcon from '../../../AppIcon';
import CronInput from '../../../CronInput';
-import { AGENT_OPTIONS, ISSUE_AUTHOR_FILTER_OPTIONS, ISSUE_AUTHOR_FILTER_TASK_TYPES, SWARM_COUNT_OPTIONS, SWARM_TASK_TYPES, toggleAppMetadataOverride, agentOptionButtonClass } from '../../constants';
+import { AGENT_OPTIONS, ISSUE_AUTHOR_FILTER_OPTIONS, ISSUE_AUTHOR_FILTER_TASK_TYPES, PR_COMPLETION_OPTIONS, pinnedPrCompletion, prCompletionOption, SWARM_COUNT_OPTIONS, SWARM_TASK_TYPES, toggleAppMetadataOverride, agentOptionButtonClass } from '../../constants';
import { isCronExpression, describeCron } from '../../../../utils/cronHelpers';
import ToggleSwitch from '../../../ToggleSwitch';
-import { INTERVAL_LABELS } from './scheduleConstants';
+import { INTERVAL_LABELS, setMetadataOverride } from './scheduleConstants';
const AppOverrideRow = memo(function AppOverrideRow({ app, taskType, globalIntervalType, globalTaskMetadata, managedAgentOptions, override, onUpdate }) {
const [updating, setUpdating] = useState(false);
@@ -12,6 +12,9 @@ const AppOverrideRow = memo(function AppOverrideRow({ app, taskType, globalInter
const isEnabled = override?.enabled === true;
const currentInterval = override?.interval || null;
const hasCron = isCronExpression(currentInterval);
+ // Same effective-value rule the AGENT_OPTIONS buttons use: this app's override
+ // wins, else the global config. No PR, nothing to decide about one.
+ const opensPR = (override?.taskMetadata?.openPR ?? globalTaskMetadata?.openPR) === true;
const handleToggle = async () => {
setUpdating(true);
@@ -45,34 +48,20 @@ const AppOverrideRow = memo(function AppOverrideRow({ app, taskType, globalInter
setUpdating(false);
};
- // claim-issue per-app author filter. '' = inherit the global default; any
- // other value writes a per-app override. The server replaces taskMetadata
- // wholesale, so preserve the app's other override keys (worktree, etc.).
- const handleIssueAuthorFilterChange = async (value) => {
+ // Per-app override for one non-boolean knob. '' = inherit the global default
+ // (see setMetadataOverride for the set-or-clear rule).
+ const handleOverrideChange = async (field, value) => {
setUpdating(true);
- const next = { ...(override?.taskMetadata || {}) };
- if (value === '') delete next.issueAuthorFilter;
- else next.issueAuthorFilter = value;
- const taskMetadata = Object.keys(next).length ? next : null;
+ const taskMetadata = setMetadataOverride(override?.taskMetadata, field, value);
await onUpdate(app.id, taskType, { taskMetadata }).catch(() => {});
setUpdating(false);
};
- // claim-issue per-app swarm override. '' = inherit the global default; '0'
- // = explicit off; 2..6 = swarm with that many agents. Sent as a Number: the
- // server's sanitizer KEEPS an explicit 0 (it's how a per-app override turns
- // swarm off even when the global default has it on) and 2..6; only 1 /
- // out-of-range / non-integer are dropped. Inherit is the absent key (deleted
- // above), distinct from a stored 0.
- const handleSwarmCountChange = async (raw) => {
- setUpdating(true);
- const next = { ...(override?.taskMetadata || {}) };
- if (raw === '') delete next.swarmCount;
- else next.swarmCount = Number(raw);
- const taskMetadata = Object.keys(next).length ? next : null;
- await onUpdate(app.id, taskType, { taskMetadata }).catch(() => {});
- setUpdating(false);
- };
+ // Swarm count goes as a Number: the server's sanitizer KEEPS an explicit 0
+ // (how a per-app override turns swarm off even when the global default has it
+ // on) and 2..6; only 1 / out-of-range / non-integer are dropped. Inherit is
+ // the absent key, distinct from a stored 0.
+ const handleSwarmCountChange = (raw) => handleOverrideChange('swarmCount', raw === '' ? '' : Number(raw));
return (
<div className="flex flex-col sm:flex-row sm:flex-wrap sm:items-center gap-2 sm:gap-3 py-2 px-3 rounded hover:bg-port-card/30">
@@ -149,10 +138,26 @@ const AppOverrideRow = memo(function AppOverrideRow({ app, taskType, globalInter
})}
</div>
+ {opensPR && (
+ <select
+ value={pinnedPrCompletion(override?.taskMetadata)}
+ onChange={(e) => handleOverrideChange('prCompletion', e.target.value)}
+ disabled={updating}
+ aria-label={`After opening PR for ${app.name}`}
+ title="What happens to the PR this app's runs open"
+ className="bg-port-card border border-port-border rounded px-2 py-1.5 text-xs text-white min-w-[120px] min-h-[40px]"
+ >
+ <option value="">Inherit ({prCompletionOption(pinnedPrCompletion(globalTaskMetadata))?.label || 'app default'})</option>
+ {PR_COMPLETION_OPTIONS.map(opt => (
+ <option key={opt.value} value={opt.value}>{opt.label}</option>
+ ))}
+ </select>
+ )}
+
{ISSUE_AUTHOR_FILTER_TASK_TYPES.has(taskType) && (
<select
value={override?.taskMetadata?.issueAuthorFilter || ''}
- onChange={(e) => handleIssueAuthorFilterChange(e.target.value)}
+ onChange={(e) => handleOverrideChange('issueAuthorFilter', e.target.value)}
disabled={updating}
aria-label={`Issue author filter for ${app.name}`}
title="Which open issues this app may claim"
diff --git a/client/src/components/cos/tabs/schedule/AppOverrideRow.test.jsx b/client/src/components/cos/tabs/schedule/AppOverrideRow.test.jsx
new file mode 100644
index 0000000000..5cdd11f0b5
--- /dev/null
+++ b/client/src/components/cos/tabs/schedule/AppOverrideRow.test.jsx
@@ -0,0 +1,72 @@
+import { describe, it, expect, vi, afterEach } from 'vitest';
+import { render, screen, fireEvent, cleanup, act } from '@testing-library/react';
+
+import AppOverrideRow from './AppOverrideRow';
+
+const APP = { id: 'app-1', name: 'Acme' };
+
+function renderRow({ globalTaskMetadata = {}, override = null, onUpdate = vi.fn().mockResolvedValue(undefined) } = {}) {
+ render(
+ <AppOverrideRow
+ app={APP}
+ taskType="feature-ideas"
+ globalIntervalType="daily"
+ globalTaskMetadata={globalTaskMetadata}
+ managedAgentOptions={[]}
+ override={override}
+ onUpdate={onUpdate}
+ />
+ );
+ return onUpdate;
+}
+
+const prSelect = () => screen.queryByLabelText('After opening PR for Acme');
+
+afterEach(() => {
+ cleanup();
+ vi.clearAllMocks();
+});
+
+describe('AppOverrideRow — After opening PR override', () => {
+ it('is absent when neither the app nor the global config opens a PR', () => {
+ renderRow({ globalTaskMetadata: { useWorktree: true, openPR: false } });
+ expect(prSelect()).not.toBeInTheDocument();
+ });
+
+ it('appears when the app override turns Open PR on for an otherwise-off task', () => {
+ renderRow({ globalTaskMetadata: { openPR: false }, override: { taskMetadata: { openPR: true } } });
+ expect(prSelect()).toBeInTheDocument();
+ });
+
+ it('names the inherited policy on the Inherit option', () => {
+ renderRow({ globalTaskMetadata: { openPR: true, prCompletion: 'merge-on-green' } });
+ expect(prSelect()).toHaveValue('');
+ expect(screen.getByRole('option', { name: 'Inherit (Merge on green CI)' })).toBeInTheDocument();
+ });
+
+ it('falls back to "app default" when the global config pins nothing', () => {
+ renderRow({ globalTaskMetadata: { openPR: true } });
+ expect(screen.getByRole('option', { name: 'Inherit (app default)' })).toBeInTheDocument();
+ });
+
+ it('writes the override without disturbing the app\'s other overrides', async () => {
+ const onUpdate = renderRow({
+ globalTaskMetadata: { openPR: true },
+ override: { taskMetadata: { simplify: false } },
+ });
+ await act(async () => { fireEvent.change(prSelect(), { target: { value: 'leave-open' } }); });
+ expect(onUpdate).toHaveBeenCalledWith('app-1', 'feature-ideas', {
+ taskMetadata: { simplify: false, prCompletion: 'leave-open' },
+ });
+ });
+
+ it('clears the override back to inherit', async () => {
+ const onUpdate = renderRow({
+ globalTaskMetadata: { openPR: true },
+ override: { taskMetadata: { prCompletion: 'leave-open' } },
+ });
+ expect(prSelect()).toHaveValue('leave-open');
+ await act(async () => { fireEvent.change(prSelect(), { target: { value: '' } }); });
+ expect(onUpdate).toHaveBeenCalledWith('app-1', 'feature-ideas', { taskMetadata: null });
+ });
+});
diff --git a/client/src/components/cos/tabs/schedule/GlobalConfigControls.jsx b/client/src/components/cos/tabs/schedule/GlobalConfigControls.jsx
index 73b1a03714..69a57240d3 100644
--- a/client/src/components/cos/tabs/schedule/GlobalConfigControls.jsx
+++ b/client/src/components/cos/tabs/schedule/GlobalConfigControls.jsx
@@ -1,7 +1,7 @@
import { useState, useEffect } from 'react';
import { RotateCcw, AlertCircle } from 'lucide-react';
import CronInput from '../../../CronInput';
-import { AGENT_OPTIONS, DEFAULT_REVIEW_STOP_MODE, PR_AUTHOR_FILTER_OPTIONS, ISSUE_AUTHOR_FILTER_OPTIONS, ISSUE_AUTHOR_FILTER_TASK_TYPES, SWARM_COUNT_OPTIONS, SWARM_TASK_TYPES } from '../../constants';
+import { AGENT_OPTIONS, DEFAULT_REVIEW_STOP_MODE, IMPLICIT_PR_COMPLETION, PR_AUTHOR_FILTER_OPTIONS, PR_COMPLETION_OPTIONS, pinnedPrCompletion, prCompletionOption, ISSUE_AUTHOR_FILTER_OPTIONS, ISSUE_AUTHOR_FILTER_TASK_TYPES, SWARM_COUNT_OPTIONS, SWARM_TASK_TYPES } from '../../constants';
import ReviewerPicker from '../../ReviewerPicker';
import Banner from '../../../ui/Banner';
import InfoTooltip from '../../../ui/InfoTooltip';
@@ -17,6 +17,11 @@ import PromptEditor from './PromptEditor';
import RunTaskButton from './RunTaskButton';
import { INTERVAL_DESCRIPTIONS, toggleMetadataField } from './scheduleConstants';
+// Shown for the unpinned ('' → inherit) choice: the task type is global, so the
+// policy is whatever each target app configured, and PortOS's own self-improvement
+// runs (no app) land on the server-side fallback.
+const PR_COMPLETION_INHERIT_HINT = `Uses the target app's "After opening PR" default (Apps → Edit App), or "${prCompletionOption(IMPLICIT_PR_COMPLETION)?.label}" when it has none.`;
+
export default function GlobalConfigControls({ taskType, config, onUpdate, onTrigger, onReset, category: _category, providers, apps, updating, setUpdating, allTaskTypes, improvementDisabled }) {
const reviewDefaults = useCodeReviewDefaults();
// Resolved model lists for the reviewer table's Model column (the picker itself
@@ -154,6 +159,20 @@ export default function GlobalConfigControls({ taskType, config, onUpdate, onTri
setUpdating(false);
};
+ // '' drops the key so the task inherits its app's `defaultPrCompletion` —
+ // which works because no DEFAULT_TASK_INTERVALS entry ships a `prCompletion`
+ // for loadSchedule to merge back underneath. The legacy `reviewLoop` bit is
+ // the pre-`prCompletion` spelling of the same decision, so it goes too rather
+ // than outvoting whatever the user just picked.
+ const handlePrCompletionChange = async (value) => {
+ setUpdating(true);
+ const { prCompletion: _pinned, reviewLoop: _legacy, ...rest } = config.taskMetadata || {};
+ await onUpdate(taskType, {
+ taskMetadata: value ? { ...rest, prCompletion: value } : rest
+ });
+ setUpdating(false);
+ };
+
const handleSavePrompt = async () => {
setUpdating(true);
const prompt = promptValue.trim() === '' ? null : promptValue;
@@ -164,6 +183,14 @@ export default function GlobalConfigControls({ taskType, config, onUpdate, onTri
setUpdating(false);
};
+ const prCompletion = pinnedPrCompletion(config.taskMetadata);
+ // Reviewers only run under review-then-merge, so the picker hides for the two
+ // policies that never reach them — but an unpinned ('') task may still inherit
+ // review-then-merge from its app, so that keeps it.
+ const reviewersApply = config.taskMetadata?.openPR
+ ? prCompletion === '' || prCompletion === 'review-then-merge'
+ : !!config.taskMetadata?.reviewLoop;
+
const selectedProvider = providers?.find(p => p.id === (selectedProviderId || ''));
const availableModels = filterSelectableModels(selectedProvider?.models);
const status = config.status || {};
@@ -433,7 +460,25 @@ export default function GlobalConfigControls({ taskType, config, onUpdate, onTri
);
})}
</div>
- {(config.taskMetadata?.reviewLoop || config.taskMetadata?.openPR) && (
+ {config.taskMetadata?.openPR && (
+ <FormField label="After opening PR" className="mt-3" labelClassName="text-sm text-gray-400 block mb-2">
+ <select
+ value={prCompletion}
+ onChange={(e) => handlePrCompletionChange(e.target.value)}
+ disabled={updating}
+ className="w-full bg-port-card border border-port-border rounded px-3 py-2 text-white text-sm"
+ >
+ <option value="">App default</option>
+ {PR_COMPLETION_OPTIONS.map(option => (
+ <option key={option.value} value={option.value}>{option.label}</option>
+ ))}
+ </select>
+ <p className="text-xs text-gray-500 mt-1">
+ {prCompletionOption(prCompletion)?.description || PR_COMPLETION_INHERIT_HINT}
+ </p>
+ </FormField>
+ )}
+ {reviewersApply && (
<div className="mt-3 pl-2">
<ReviewerPicker
reviewers={config.taskMetadata?.reviewers ?? (config.taskMetadata?.reviewer ? [config.taskMetadata.reviewer] : reviewDefaults.reviewers)}
diff --git a/client/src/components/cos/tabs/schedule/GlobalConfigControls.test.jsx b/client/src/components/cos/tabs/schedule/GlobalConfigControls.test.jsx
new file mode 100644
index 0000000000..cb8b22c447
--- /dev/null
+++ b/client/src/components/cos/tabs/schedule/GlobalConfigControls.test.jsx
@@ -0,0 +1,110 @@
+import { describe, it, expect, vi, afterEach } from 'vitest';
+import { render, screen, fireEvent, cleanup } from '@testing-library/react';
+
+// The two hooks are the component's only API callers — stub them so the test
+// exercises the config controls, not the network.
+vi.mock('../../../../hooks/useCodeReviewDefaults', () => ({
+ useCodeReviewDefaults: () => ({
+ reviewers: ['copilot'],
+ usernames: [],
+ optionalReviewers: [],
+ reviewerMaxRounds: {},
+ stopMode: 'clean',
+ reviewerApplies: false,
+ }),
+}));
+vi.mock('../../../../hooks/useReviewerModelOptions', () => ({
+ default: () => ({ optionsByReviewer: {}, freeText: {}, unavailable: {}, loaded: true }),
+}));
+vi.mock('../../ReviewerPicker', () => ({
+ default: () => <div data-testid="reviewer-picker" />,
+}));
+
+import GlobalConfigControls from './GlobalConfigControls';
+
+const BASE_CONFIG = {
+ type: 'daily',
+ enabled: true,
+ providerId: null,
+ model: null,
+ effort: null,
+ prompt: 'do the thing',
+ status: {},
+};
+
+function renderControls({ taskMetadata, onUpdate = vi.fn() } = {}) {
+ render(
+ <GlobalConfigControls
+ taskType="feature-ideas"
+ config={{ ...BASE_CONFIG, taskMetadata }}
+ onUpdate={onUpdate}
+ onTrigger={() => {}}
+ onReset={() => {}}
+ providers={[]}
+ apps={[]}
+ updating={false}
+ setUpdating={() => {}}
+ allTaskTypes={['feature-ideas']}
+ />
+ );
+ return onUpdate;
+}
+
+const prSelect = () => screen.queryByLabelText('After opening PR');
+
+afterEach(() => {
+ cleanup();
+ vi.clearAllMocks();
+});
+
+describe('GlobalConfigControls — After opening PR', () => {
+ it('hides the selector when the task does not open a PR', () => {
+ renderControls({ taskMetadata: { useWorktree: true, openPR: false } });
+ expect(prSelect()).not.toBeInTheDocument();
+ });
+
+ it('defaults an unpinned task to the app-default option', () => {
+ renderControls({ taskMetadata: { useWorktree: true, openPR: true } });
+ expect(prSelect()).toHaveValue('');
+ expect(screen.getByTestId('reviewer-picker')).toBeInTheDocument();
+ });
+
+ it('shows a legacy reviewLoop task the policy it actually runs under', () => {
+ renderControls({ taskMetadata: { useWorktree: true, openPR: true, reviewLoop: true } });
+ expect(prSelect()).toHaveValue('review-then-merge');
+ });
+
+ // Keeps unrelated keys, and drops the legacy reviewLoop bit so it can't
+ // outvote the pin the user just made.
+ it('persists the picked policy into taskMetadata', () => {
+ const onUpdate = renderControls({ taskMetadata: { useWorktree: true, openPR: true, simplify: true, reviewLoop: true } });
+ fireEvent.change(prSelect(), { target: { value: 'merge-on-green' } });
+ expect(onUpdate).toHaveBeenCalledWith('feature-ideas', {
+ taskMetadata: { useWorktree: true, openPR: true, simplify: true, prCompletion: 'merge-on-green' },
+ });
+ });
+
+ it('clears the pin (back to the app default) when App default is picked', () => {
+ const onUpdate = renderControls({ taskMetadata: { useWorktree: true, openPR: true, prCompletion: 'leave-open' } });
+ expect(prSelect()).toHaveValue('leave-open');
+ fireEvent.change(prSelect(), { target: { value: '' } });
+ expect(onUpdate).toHaveBeenCalledWith('feature-ideas', {
+ taskMetadata: { useWorktree: true, openPR: true },
+ });
+ });
+
+ it.each(['merge-on-green', 'leave-open'])('hides the reviewer picker for %s', (prCompletion) => {
+ renderControls({ taskMetadata: { useWorktree: true, openPR: true, prCompletion } });
+ expect(screen.queryByTestId('reviewer-picker')).not.toBeInTheDocument();
+ });
+
+ it('keeps the reviewer picker for review-then-merge', () => {
+ renderControls({ taskMetadata: { useWorktree: true, openPR: true, prCompletion: 'review-then-merge' } });
+ expect(screen.getByTestId('reviewer-picker')).toBeInTheDocument();
+ });
+
+ it('keeps the reviewer picker for a legacy reviewLoop task that opens no PR', () => {
+ renderControls({ taskMetadata: { useWorktree: true, openPR: false, reviewLoop: true } });
+ expect(screen.getByTestId('reviewer-picker')).toBeInTheDocument();
+ });
+});
diff --git a/client/src/components/cos/tabs/schedule/scheduleConstants.js b/client/src/components/cos/tabs/schedule/scheduleConstants.js
index 2ea7c4e686..b14d92bd1c 100644
--- a/client/src/components/cos/tabs/schedule/scheduleConstants.js
+++ b/client/src/components/cos/tabs/schedule/scheduleConstants.js
@@ -156,6 +156,18 @@ export const TASK_FILTERS = [
];
export const DEFAULT_FILTER_ID = TASK_FILTERS[0].id;
+// Set or clear one per-app taskMetadata override key. '' is every override
+// select's "Inherit" option, and deletes the key so the global config decides
+// again; the server replaces taskMetadata wholesale, so the app's other override
+// keys ride along. Returns null once nothing is overridden, which is how a row
+// drops its override object entirely.
+export function setMetadataOverride(taskMetadata, field, value) {
+ const next = { ...(taskMetadata || {}) };
+ if (value === '') delete next[field];
+ else next[field] = value;
+ return Object.keys(next).length ? next : null;
+}
+
// Toggle a global taskMetadata field, enforcing the openPR→useWorktree invariant.
// Persists both true and false values so explicit overrides survive the server-side
// merge with task-type defaults (e.g., feature-ideas defaults openPR to true).
diff --git a/client/src/components/cos/tabs/schedule/scheduleConstants.test.js b/client/src/components/cos/tabs/schedule/scheduleConstants.test.js
index cc46acf6a7..18f1ed922a 100644
--- a/client/src/components/cos/tabs/schedule/scheduleConstants.test.js
+++ b/client/src/components/cos/tabs/schedule/scheduleConstants.test.js
@@ -1,5 +1,44 @@
import { describe, it, expect } from 'vitest';
-import { getTaskStatusGroup, taskSortKey, TASK_FILTERS, STATUS_GROUPS, describeNextRun, coverageTone } from './scheduleConstants';
+import { getTaskStatusGroup, taskSortKey, TASK_FILTERS, STATUS_GROUPS, describeNextRun, coverageTone, setMetadataOverride, toggleMetadataField } from './scheduleConstants';
+
+describe('setMetadataOverride', () => {
+ it('sets a key without disturbing the app\'s other overrides', () => {
+ expect(setMetadataOverride({ useWorktree: true }, 'prCompletion', 'merge-on-green'))
+ .toEqual({ useWorktree: true, prCompletion: 'merge-on-green' });
+ });
+
+ it('deletes the key on the Inherit sentinel', () => {
+ expect(setMetadataOverride({ useWorktree: true, prCompletion: 'leave-open' }, 'prCompletion', ''))
+ .toEqual({ useWorktree: true });
+ });
+
+ it('keeps an explicit 0 — only "" means inherit', () => {
+ expect(setMetadataOverride(null, 'swarmCount', 0)).toEqual({ swarmCount: 0 });
+ });
+
+ it('returns null once nothing is overridden so the row drops its object', () => {
+ expect(setMetadataOverride({ prCompletion: 'leave-open' }, 'prCompletion', '')).toBeNull();
+ });
+});
+
+describe('toggleMetadataField', () => {
+ it('turns openPR on with the worktree it implies', () => {
+ expect(toggleMetadataField({ useWorktree: false, openPR: false }, 'openPR'))
+ .toEqual({ useWorktree: true, openPR: true });
+ });
+
+ it('turns openPR off with the worktree it depends on', () => {
+ expect(toggleMetadataField({ useWorktree: true, openPR: false }, 'useWorktree'))
+ .toEqual({ useWorktree: false, openPR: false });
+ });
+
+ // The invariant resolves in openPR's favor, so the worktree toggle can't strand
+ // a PR task with nowhere to branch — turn Open PR off first.
+ it('refuses to drop the worktree out from under an open PR', () => {
+ expect(toggleMetadataField({ useWorktree: true, openPR: true }, 'useWorktree'))
+ .toEqual({ useWorktree: true, openPR: true });
+ });
+});
describe('getTaskStatusGroup', () => {
it('classifies a disabled task as disabled regardless of type', () => {
diff --git a/server/services/subAgentSpawner.test.js b/server/services/subAgentSpawner.test.js
index e8eeadd054..8b9e5fbf18 100644
--- a/server/services/subAgentSpawner.test.js
+++ b/server/services/subAgentSpawner.test.js
@@ -366,6 +366,14 @@ describe('Worktree & metadata flag helpers', () => {
expect(metadata).toMatchObject({ useWorktree: true, openPR: true, prCompletion: 'leave-open' });
});
+ it('keeps a task-level PR completion pin over the app default', () => {
+ // The Schedule tab's "After opening PR" select writes this pin into the
+ // interval's taskMetadata — the more specific choice must win.
+ const metadata = { prCompletion: 'merge-on-green' };
+ applyAppWorktreeDefault(metadata, { defaultOpenPR: true, defaultPrCompletion: 'review-then-merge' });
+ expect(metadata.prCompletion).toBe('merge-on-green');
+ });
+
it('does not invent a disposition for a legacy app default', () => {
const metadata = {};
applyAppWorktreeDefault(metadata, { defaultOpenPR: true });