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

Preserve schedule and catalog edits on failed actions (#11786)

[._.]/c7bd4d6d098a
diff --git a/client/src/components/cos/tabs/schedule/GlobalConfigControls.jsx b/client/src/components/cos/tabs/schedule/GlobalConfigControls.jsx
index 4030506d20..45197b0c01 100644
--- a/client/src/components/cos/tabs/schedule/GlobalConfigControls.jsx
+++ b/client/src/components/cos/tabs/schedule/GlobalConfigControls.jsx
@@ -62,8 +62,13 @@ export default function GlobalConfigControls({ taskType, config, onUpdate, onTri
config.description || '',
async (next) => {
setUpdating(true);
- await onUpdate(taskType, { description: next.trim() || null }).catch(() => {});
- setUpdating(false);
+ try {
+ await onUpdate(taskType, { description: next.trim() || null });
+ } catch {
+ // The field draft owns its error state; keep the editor usable.
+ } finally {
+ setUpdating(false);
+ }
},
);
// Comma-separated free text, committed to taskMetadata.issueExcludeLabels
@@ -75,10 +80,13 @@ export default function GlobalConfigControls({ taskType, config, onUpdate, onTri
(config.taskMetadata?.issueExcludeLabels || []).join(', '),
async (next) => {
setUpdating(true);
- await onUpdate(taskType, {
- taskMetadata: { ...(config.taskMetadata || {}), issueExcludeLabels: next.split(',').map((s) => s.trim()).filter(Boolean) }
- });
- setUpdating(false);
+ try {
+ await onUpdate(taskType, {
+ taskMetadata: { ...(config.taskMetadata || {}), issueExcludeLabels: next.split(',').map((s) => s.trim()).filter(Boolean) }
+ });
+ } finally {
+ setUpdating(false);
+ }
}
);
// Provider/model/effort pins are shared with the schedule card's quick
@@ -119,10 +127,12 @@ export default function GlobalConfigControls({ taskType, config, onUpdate, onTri
setCronEditing(false);
setUpdating(true);
setSelectedType(newType);
- await onUpdate(taskType, { type: newType, cronExpression: null, autoStart: false }).catch(() => {
- setSelectedType(config.type);
- });
- setUpdating(false);
+ try {
+ const ok = await onUpdate(taskType, { type: newType, cronExpression: null, autoStart: false }).catch(() => false);
+ if (ok === false) setSelectedType(config.type);
+ } finally {
+ setUpdating(false);
+ }
};
// Perpetual is orthogonal to the cadence — toggling it never touches `type`,
@@ -131,68 +141,90 @@ export default function GlobalConfigControls({ taskType, config, onUpdate, onTri
// handleToggleEnabled rather than attaching its own rejection handler.
const handlePerpetualToggle = async () => {
setUpdating(true);
- await onUpdate(taskType, { perpetual: !config.perpetual, ...(config.type === 'on-demand' && !config.perpetual ? { autoStart: config.autoStart ?? false } : {}) });
- setUpdating(false);
+ try {
+ await onUpdate(taskType, { perpetual: !config.perpetual, ...(config.type === 'on-demand' && !config.perpetual ? { autoStart: config.autoStart ?? false } : {}) });
+ } finally {
+ setUpdating(false);
+ }
};
const handleCronSave = async (expr) => {
setUpdating(true);
- await onUpdate(taskType, { type: 'cron', cronExpression: expr }).catch(() => {
- setSelectedType(config.type);
- });
- setCronEditing(false);
- setUpdating(false);
+ try {
+ const ok = await onUpdate(taskType, { type: 'cron', cronExpression: expr }).catch(() => false);
+ if (ok !== false) setCronEditing(false);
+ } finally {
+ setUpdating(false);
+ }
};
const handleRecheckCronSave = async (expr) => {
setUpdating(true);
- await onUpdate(taskType, { recheckCron: expr }).catch(() => {});
- setRecheckEditing(false);
- setUpdating(false);
+ try {
+ const ok = await onUpdate(taskType, { recheckCron: expr }).catch(() => false);
+ if (ok !== false) setRecheckEditing(false);
+ } finally {
+ setUpdating(false);
+ }
};
const isPaused = !config.enabled;
const handleToggleEnabled = async () => {
setUpdating(true);
- await onUpdate(taskType, { enabled: isPaused });
- setUpdating(false);
+ try {
+ await onUpdate(taskType, { enabled: isPaused });
+ } finally {
+ setUpdating(false);
+ }
};
const handleIssueAuthorFilterChange = async (value) => {
setUpdating(true);
- await onUpdate(taskType, {
- taskMetadata: { ...(config.taskMetadata || {}), issueAuthorFilter: value }
- });
- setUpdating(false);
+ try {
+ await onUpdate(taskType, {
+ taskMetadata: { ...(config.taskMetadata || {}), issueAuthorFilter: value }
+ });
+ } finally {
+ setUpdating(false);
+ }
};
const handleSwarmCountChange = async (value) => {
setUpdating(true);
// 0 = off, 2..12 = swarm size (server keeps both; 1/out-of-range are dropped).
// taskMetadata is replaced wholesale server-side, so spread the existing keys.
- await onUpdate(taskType, {
- taskMetadata: { ...(config.taskMetadata || {}), swarmCount: value }
- });
- setUpdating(false);
+ try {
+ await onUpdate(taskType, {
+ taskMetadata: { ...(config.taskMetadata || {}), swarmCount: value }
+ });
+ } finally {
+ setUpdating(false);
+ }
};
// Release options are ON unless explicitly false, so the toggle writes an
// explicit boolean either way.
const handleReleaseOptionToggle = async (field) => {
setUpdating(true);
- await onUpdate(taskType, {
- taskMetadata: { ...(config.taskMetadata || {}), [field]: config.taskMetadata?.[field] === false }
- });
- setUpdating(false);
+ try {
+ await onUpdate(taskType, {
+ taskMetadata: { ...(config.taskMetadata || {}), [field]: config.taskMetadata?.[field] === false }
+ });
+ } finally {
+ setUpdating(false);
+ }
};
const handleBranchesPerAgentChange = async (value) => {
setUpdating(true);
- await onUpdate(taskType, {
- taskMetadata: { ...(config.taskMetadata || {}), branchesPerAgent: value }
- });
- setUpdating(false);
+ try {
+ await onUpdate(taskType, {
+ taskMetadata: { ...(config.taskMetadata || {}), branchesPerAgent: value }
+ });
+ } finally {
+ setUpdating(false);
+ }
};
// '' drops the key so the task inherits its app's `defaultPrCompletion` —
@@ -203,10 +235,13 @@ export default function GlobalConfigControls({ taskType, config, onUpdate, onTri
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);
+ try {
+ await onUpdate(taskType, {
+ taskMetadata: value ? { ...rest, prCompletion: value } : rest
+ });
+ } finally {
+ setUpdating(false);
+ }
};
const handleResetReviewConfig = async () => {
@@ -215,18 +250,22 @@ export default function GlobalConfigControls({ taskType, config, onUpdate, onTri
const taskMetadata = Object.fromEntries(
Object.entries(metadata).filter(([key]) => !REVIEW_CONFIG_KEYS.includes(key))
);
- await onUpdate(taskType, { taskMetadata });
- setUpdating(false);
+ try {
+ await onUpdate(taskType, { taskMetadata });
+ } finally {
+ setUpdating(false);
+ }
};
const handleSavePrompt = async () => {
setUpdating(true);
const prompt = promptValue.trim() === '' ? null : promptValue;
- await onUpdate(taskType, { prompt }).catch(() => {
- setPromptValue(config.prompt || '');
- });
- setEditingPrompt(false);
- setUpdating(false);
+ try {
+ const ok = await onUpdate(taskType, { prompt }).catch(() => false);
+ if (ok !== false) setEditingPrompt(false);
+ } finally {
+ setUpdating(false);
+ }
};
const claimFlow = !!config.taskMetadata?.claimFlow || ISSUE_AUTHOR_FILTER_TASK_TYPES.has(taskType);
@@ -648,8 +687,11 @@ export default function GlobalConfigControls({ taskType, config, onUpdate, onTri
disabled={updating}
onChange={async (dataInputs) => {
setUpdating(true);
- await onUpdate(taskType, { dataInputs });
- setUpdating(false);
+ try {
+ await onUpdate(taskType, { dataInputs });
+ } finally {
+ setUpdating(false);
+ }
}}
/>
@@ -662,14 +704,17 @@ export default function GlobalConfigControls({ taskType, config, onUpdate, onTri
className={`w-full flex items-center justify-between gap-3 min-h-[44px] rounded px-2 -mx-2 text-left ${updating ? 'opacity-60 cursor-not-allowed' : 'cursor-pointer hover:bg-port-card/30 active:bg-port-card/50'}`}
onClick={async () => {
setUpdating(true);
- await onUpdate(taskType, {
- taskMetadata: toggleFileIssuesMetadata(
- config.taskMetadata,
- !fileIssuesEffective(config),
- config.doWorkRequiresWorktree,
- )
- });
- setUpdating(false);
+ try {
+ await onUpdate(taskType, {
+ taskMetadata: toggleFileIssuesMetadata(
+ config.taskMetadata,
+ !fileIssuesEffective(config),
+ config.doWorkRequiresWorktree,
+ )
+ });
+ } finally {
+ setUpdating(false);
+ }
}}
>
<div className="min-w-0 flex-1">
diff --git a/client/src/components/cos/tabs/schedule/GlobalConfigControls.test.jsx b/client/src/components/cos/tabs/schedule/GlobalConfigControls.test.jsx
index d6717c35b3..3e39880539 100644
--- a/client/src/components/cos/tabs/schedule/GlobalConfigControls.test.jsx
+++ b/client/src/components/cos/tabs/schedule/GlobalConfigControls.test.jsx
@@ -401,6 +401,61 @@ describe('GlobalConfigControls — cadence + perpetual', () => {
});
});
+describe('GlobalConfigControls — failed saves', () => {
+ it('rolls back a cadence change when onUpdate resolves false and releases the busy state', async () => {
+ const onUpdate = vi.fn().mockResolvedValue(false);
+ const setUpdating = vi.fn();
+ renderControls({ config: { type: 'cron' }, onUpdate, setUpdating });
+
+ await act(async () => fireEvent.change(screen.getByLabelText('Interval Type'), { target: { value: 'on-demand' } }));
+
+ expect(screen.getByLabelText('Interval Type')).toHaveValue('cron');
+ expect(setUpdating).toHaveBeenLastCalledWith(false);
+ });
+
+ it('keeps the cron draft open when onUpdate resolves false and releases the busy state', async () => {
+ const onUpdate = vi.fn().mockResolvedValue(false);
+ const setUpdating = vi.fn();
+ renderControls({ onUpdate, setUpdating });
+ const expression = screen.getByLabelText('Cron expression');
+ fireEvent.change(expression, { target: { value: '15 8 * * *' } });
+
+ await act(async () => fireEvent.click(screen.getByRole('button', { name: 'Save schedule' })));
+
+ expect(screen.getByLabelText('Cron expression')).toHaveValue('15 8 * * *');
+ expect(screen.getByText('Unsaved changes — save before closing')).toBeInTheDocument();
+ expect(setUpdating).toHaveBeenLastCalledWith(false);
+ });
+
+ it('keeps a first cron draft visible when an on-demand task fails to save it', async () => {
+ const onUpdate = vi.fn().mockResolvedValue(false);
+ renderControls({ config: { type: 'on-demand' }, onUpdate });
+ await act(async () => fireEvent.change(screen.getByLabelText('Interval Type'), { target: { value: 'cron' } }));
+ const expression = screen.getByLabelText('Cron expression');
+ fireEvent.change(expression, { target: { value: '15 8 * * *' } });
+
+ await act(async () => fireEvent.click(screen.getByRole('button', { name: 'Save schedule' })));
+
+ expect(screen.getByLabelText('Interval Type')).toHaveValue('cron');
+ expect(screen.getByLabelText('Cron expression')).toHaveValue('15 8 * * *');
+ expect(screen.getByText('Unsaved changes — save before closing')).toBeInTheDocument();
+ });
+
+ it('keeps the prompt draft open when onUpdate resolves false and releases the busy state', async () => {
+ const onUpdate = vi.fn().mockResolvedValue(false);
+ const setUpdating = vi.fn();
+ renderControls({ onUpdate, setUpdating });
+ fireEvent.click(screen.getByRole('button', { name: 'Edit prompt' }));
+ const prompt = screen.getByLabelText('Task prompt');
+ fireEvent.change(prompt, { target: { value: 'new prompt draft' } });
+
+ await act(async () => fireEvent.click(screen.getByRole('button', { name: 'Save Prompt' })));
+
+ expect(screen.getByLabelText('Task prompt')).toHaveValue('new prompt draft');
+ expect(setUpdating).toHaveBeenLastCalledWith(false);
+ });
+});
+
// A stall (the forge CLI failing several evaluations in a row) can coexist
// with an apparently-healthy "Draining" state — the gate skips without
// parking on purpose (#7551) — so it must render regardless of park state.
diff --git a/client/src/components/cos/tabs/schedule/PerAppOverrideList.jsx b/client/src/components/cos/tabs/schedule/PerAppOverrideList.jsx
index ac40a669b8..c68337c693 100644
--- a/client/src/components/cos/tabs/schedule/PerAppOverrideList.jsx
+++ b/client/src/components/cos/tabs/schedule/PerAppOverrideList.jsx
@@ -20,8 +20,11 @@ export default function PerAppOverrideList({ taskType, config, apps, providers,
const handleBulkToggle = async () => {
setBulkUpdating(true);
const newEnabled = !allEnabled;
- await onBulkToggleOverride(taskType, newEnabled);
- setBulkUpdating(false);
+ try {
+ await onBulkToggleOverride(taskType, newEnabled);
+ } finally {
+ setBulkUpdating(false);
+ }
};
return (
diff --git a/client/src/pages/CatalogIngredient.jsx b/client/src/pages/CatalogIngredient.jsx
index d5b42dd161..51d2362e3d 100644
--- a/client/src/pages/CatalogIngredient.jsx
+++ b/client/src/pages/CatalogIngredient.jsx
@@ -305,16 +305,21 @@ export default function CatalogIngredient() {
// the media kind (image→reference, audio, video) from the MIME and stores the
// bytes in the matching federating library dir. Reconcile via refreshMedia.
const handleUploadFile = useCallback(async (file) => {
- if (!record || !file) return;
- const dataBase64 = arrayBufferToBase64(await file.arrayBuffer());
- const ok = await uploadCatalogIngredientMediaFile(
- record.id,
- { dataBase64, mimeType: file.type || 'application/octet-stream', filename: file.name },
- { silent: true },
- ).then(() => true).catch((err) => { toast.error(err?.message || 'Upload failed'); return false; });
- if (!ok) return;
- refreshMedia();
- toast.success('File attached');
+ if (!record || !file) return false;
+ try {
+ const dataBase64 = arrayBufferToBase64(await file.arrayBuffer());
+ await uploadCatalogIngredientMediaFile(
+ record.id,
+ { dataBase64, mimeType: file.type || 'application/octet-stream', filename: file.name },
+ { silent: true },
+ );
+ refreshMedia();
+ toast.success('File attached');
+ return true;
+ } catch (err) {
+ toast.error(err?.message || 'Upload failed');
+ return false;
+ }
}, [record, refreshMedia]);
// Attach a recorded voice memo — the server transcribes it via Whisper and
@@ -375,10 +380,10 @@ export default function CatalogIngredient() {
};
const handleRestore = async (revisionId) => {
- if (!record) return;
+ if (!record) return false;
const updated = await restoreCatalogIngredientRevision(record.id, revisionId, {}, { silent: true })
.catch((err) => { toast.error(err?.message || 'Restore failed'); return null; });
- if (!updated) return;
+ if (!updated) return false;
// Re-apply the restored state into the editable form so the page reflects
// the rollback without a full reload.
setRecord((prev) => ({ ...prev, ...updated }));
@@ -387,6 +392,7 @@ export default function CatalogIngredient() {
setPayload(updated.payload && typeof updated.payload === 'object' ? { ...updated.payload } : {});
toast.success('Restored');
refreshRevisions();
+ return true;
};
const confirmDelete = async () => {
@@ -1219,8 +1225,11 @@ function MediaPanel({ media, missingMedia, onAttach, onSetPortrait, onDetach, on
const doUpload = async (file) => {
if (!file || busy) return;
setBusy(true);
- await onUploadFile(file);
- setBusy(false);
+ try {
+ await onUploadFile(file);
+ } finally {
+ setBusy(false);
+ }
};
const onDrop = (e) => {
@@ -1604,9 +1613,11 @@ function RevisionsPanel({ revisions, current, fields, onRestore }) {
const handleRestore = async (id) => {
setRestoring(id);
- await onRestore(id);
- setRestoring(null);
- setPendingRestore(null);
+ try {
+ if (await onRestore(id)) setPendingRestore(null);
+ } finally {
+ setRestoring(null);
+ }
};
return (
diff --git a/client/src/pages/CatalogIngredient.test.jsx b/client/src/pages/CatalogIngredient.test.jsx
index 337a4a28ff..deea105e69 100644
--- a/client/src/pages/CatalogIngredient.test.jsx
+++ b/client/src/pages/CatalogIngredient.test.jsx
@@ -64,6 +64,7 @@ vi.mock('../services/apiCatalog', () => ({
unlinkCatalogIngredientRelation: vi.fn(),
listCatalogIngredientRevisions: vi.fn(async () => ({ items: [] })),
restoreCatalogIngredientRevision: vi.fn(),
+ uploadCatalogIngredientMediaFile: vi.fn(),
listCatalogIngredientMedia: vi.fn(async () => []),
listCatalogIngredientMissingMedia: vi.fn(async () => ({ missing: [] })),
attachCatalogIngredientMedia: vi.fn(),
@@ -114,7 +115,8 @@ vi.mock('../components/TagPicker', () => ({
vi.mock('../components/ui/Toast', () => ({ default: { success: vi.fn(), error: vi.fn(), info: vi.fn() } }));
import CatalogIngredient, { buildGenerationPromptSeed } from './CatalogIngredient';
-import { getCatalogIngredientDetails, unlinkCatalogIngredientRelation, updateCatalogIngredient, detachCatalogIngredientMedia } from '../services/apiCatalog';
+import { getCatalogIngredientDetails, unlinkCatalogIngredientRelation, updateCatalogIngredient, detachCatalogIngredientMedia, restoreCatalogIngredientRevision, uploadCatalogIngredientMediaFile } from '../services/apiCatalog';
+import toast from '../components/ui/Toast';
const renderPage = async (path = '/catalog/character/cat-chr-1') => {
const router = createMemoryRouter([
@@ -131,9 +133,46 @@ beforeEach(() => {
updateCatalogIngredient.mockReset();
unlinkCatalogIngredientRelation.mockReset();
detachCatalogIngredientMedia.mockReset();
+ restoreCatalogIngredientRevision.mockReset();
+ uploadCatalogIngredientMediaFile.mockReset();
});
describe('CatalogIngredient — character sheet', () => {
+ it('reports a rejected file read and re-enables the upload control', async () => {
+ await renderPage();
+ const fileInput = document.querySelector('input[type="file"][accept="image/*,audio/*,video/*"]');
+ const unreadable = { name: 'example.png', type: 'image/png', arrayBuffer: vi.fn().mockRejectedValue(new Error('File unavailable')) };
+
+ await act(async () => {
+ fireEvent.change(fileInput, { target: { files: [unreadable] } });
+ await Promise.resolve();
+ });
+
+ await waitFor(() => expect(toast.error).toHaveBeenCalledWith('File unavailable'));
+ await waitFor(() => expect(fileInput).toBeEnabled());
+ expect(uploadCatalogIngredientMediaFile).not.toHaveBeenCalled();
+ });
+
+ it('keeps revision restore confirmation open when restore fails', async () => {
+ getCatalogIngredientDetails.mockImplementation(async () => ({
+ ...detailsOf(CHAR_FIXTURE),
+ revisions: [
+ { id: 'rev-latest', source: 'save', name: 'Current', createdAt: '2026-10-17T00:00:00Z' },
+ { id: 'rev-old', source: 'save', name: 'Earlier', createdAt: '2026-10-16T00:00:00Z' },
+ ],
+ }));
+ restoreCatalogIngredientRevision.mockRejectedValue(new Error('Restore failed'));
+ await renderPage();
+
+ fireEvent.click(await screen.findByRole('button', { name: 'Restore', exact: true }));
+ const confirmation = screen.getByRole('group', { name: 'Confirm restore of Earlier' });
+ fireEvent.click(screen.getByRole('button', { name: 'Restore', exact: true }));
+
+ await waitFor(() => expect(toast.error).toHaveBeenCalledWith('Restore failed'));
+ expect(confirmation).toBeInTheDocument();
+ expect(confirmation.querySelector('button')).toHaveTextContent('Restore');
+ });
+
// The h1 is the ONLY place the ingredient's name appears on this route, and
// clipped text is neither selectable nor expandable — the tooltip is the sole
// access path to the rest of a long name on a phone (#5694).