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: address findings from the v2.43.0 release review

[._.]/ Adam Eivy997dbdd7de7e
diff --git a/client/src/components/city/CityVitalsList.jsx b/client/src/components/city/CityVitalsList.jsx
index ec53daca4e..c3514e7fac 100644
--- a/client/src/components/city/CityVitalsList.jsx
+++ b/client/src/components/city/CityVitalsList.jsx
@@ -1,5 +1,5 @@
import { useNavigate } from 'react-router';
-import { formatDurationMs, formatMonthDay } from '../../utils/formatters';
+import { formatDurationMs } from '../../utils/formatters';
import { StatButton, metricColor } from './cityHudBits';
// The System Vitals rows (uptime, health CPU/MEM/DISK, agents, stopped, archived,
@@ -121,7 +121,7 @@ export default function CityVitalsList({
<div className="flex items-center justify-between">
<span className="font-pixel text-[9px] text-cyan-500/40 tracking-widest">SYS.OK</span>
<span className="font-pixel text-[9px] text-cyan-500/40 tracking-widest">
- {formatMonthDay(new Date()).toUpperCase()}
+ {new Date().toLocaleDateString('en-US', { month: 'short', day: 'numeric' }).toUpperCase()}
</span>
</div>
</div>
diff --git a/client/src/components/digital-twin/ScaleInput.test.jsx b/client/src/components/digital-twin/ScaleInput.test.jsx
index 02bd58b93a..35d49a992c 100644
--- a/client/src/components/digital-twin/ScaleInput.test.jsx
+++ b/client/src/components/digital-twin/ScaleInput.test.jsx
@@ -45,19 +45,27 @@ describe('ScaleInput accessibility', () => {
expect(screen.getByRole('group', { name: 'Rating scale' })).toBeTruthy();
});
- it('reports the chosen value on click and on keyboard activation', () => {
+ it('reports the chosen value on click', () => {
const onChange = vi.fn();
render(<ScaleInput value={null} onChange={onChange} />);
const btn = screen.getByRole('button', { name: '5 - Strongly Agree' });
fireEvent.click(btn);
expect(onChange).toHaveBeenCalledWith(5);
- // Native <button> maps Enter/Space to a click, so focus + keyboard activation
- // reaches the same handler.
+ expect(onChange).toHaveBeenCalledTimes(1);
+ });
+
+ it('is focusable and rendered as a native <button>, so Enter/Space activation is the browser\'s job, not this component\'s', () => {
+ // jsdom's `fireEvent.keyDown` does NOT synthesize a click the way a real
+ // browser does for a native button — asserting keyboard activation here
+ // would just be asserting two clicks fired back-to-back. The real
+ // guarantee is that this stays a native <button> (which the browser maps
+ // Enter/Space → click for) rather than a non-native element with only an
+ // onClick handler.
+ render(<ScaleInput value={null} onChange={() => {}} />);
+ const btn = screen.getByRole('button', { name: '5 - Strongly Agree' });
+ expect(btn.tagName).toBe('BUTTON');
btn.focus();
expect(document.activeElement).toBe(btn);
- fireEvent.keyDown(btn, { key: 'Enter' });
- fireEvent.click(btn);
- expect(onChange).toHaveBeenCalledTimes(2);
});
it('does not fire onChange while disabled', () => {
diff --git a/client/src/components/pipeline/SeriesAutopilotSchedule.jsx b/client/src/components/pipeline/SeriesAutopilotSchedule.jsx
index d29abd6aeb..6a2bc951be 100644
--- a/client/src/components/pipeline/SeriesAutopilotSchedule.jsx
+++ b/client/src/components/pipeline/SeriesAutopilotSchedule.jsx
@@ -129,7 +129,8 @@ export default function SeriesAutopilotSchedule({ series, providers = [], active
const setModel = async (model) => persist({ ...entry, model: model || undefined });
const setEffort = async (effort) => persist({ ...entry, effort: effort || undefined });
// Stored as a plain boolean; `runOptionsFor` forwards only an explicit `true`,
- // so an unticked schedule still inherits the saved pipelineEditorialChecks default.
+ // so an unticked schedule still leaves each stage's own pinned provider/model
+ // (from the Prompts page) in effect instead of overriding it.
const setOverrideStagePins = async (on) => persist({ ...entry, overrideStagePins: on });
const removeSchedule = async () => {
diff --git a/client/src/components/usage/SubscriptionSavingsCard.jsx b/client/src/components/usage/SubscriptionSavingsCard.jsx
index c9b1db8f92..fd469e80d1 100644
--- a/client/src/components/usage/SubscriptionSavingsCard.jsx
+++ b/client/src/components/usage/SubscriptionSavingsCard.jsx
@@ -74,12 +74,12 @@ export function buildCostPatch(drafts, families) {
return patch;
}
-function CostInput({ row, value, onChange }) {
+function CostInput({ row, value, onChange, idPrefix }) {
return (
<div className="flex items-center gap-1">
<span className="text-gray-500 text-xs">$</span>
<input
- id={`subscription-cost-${row.family}`}
+ id={`${idPrefix}-subscription-cost-${row.family}`}
type="number"
inputMode="decimal"
min="0"
@@ -192,11 +192,11 @@ export default function SubscriptionSavingsCard({ savings, onSaved }) {
{families.map((row) => (
<div key={row.family} className="bg-port-bg border border-port-border rounded-lg p-3 space-y-2">
<div className="flex items-center justify-between gap-2">
- <label htmlFor={`subscription-cost-${row.family}`} className="text-sm font-medium text-white truncate">
+ <label htmlFor={`mobile-subscription-cost-${row.family}`} className="text-sm font-medium text-white truncate">
{row.label}
{!row.enabled && <Pill tone="context" size="xs" className="ml-2">disabled</Pill>}
</label>
- <CostInput row={row} value={displayValue(drafts, row)} onChange={onChange} />
+ <CostInput row={row} value={displayValue(drafts, row)} onChange={onChange} idPrefix="mobile" />
</div>
<div className="grid grid-cols-3 gap-2 text-[11px] text-white">
{rowCells(row).map((cell) => (
@@ -242,13 +242,13 @@ export default function SubscriptionSavingsCard({ savings, onSaved }) {
{families.map((row) => (
<tr key={row.family} className="border-t border-port-border text-white">
<td className="py-2 pr-2">
- <label htmlFor={`subscription-cost-${row.family}`} className="font-medium cursor-pointer">
+ <label htmlFor={`desktop-subscription-cost-${row.family}`} className="font-medium cursor-pointer">
{row.label}
</label>
{!row.enabled && <Pill tone="context" size="xs" className="ml-2">disabled</Pill>}
</td>
<td className="py-2 px-2">
- <CostInput row={row} value={displayValue(drafts, row)} onChange={onChange} />
+ <CostInput row={row} value={displayValue(drafts, row)} onChange={onChange} idPrefix="desktop" />
</td>
{rowCells(row).map((cell) => (
<td key={cell.key} className="py-2 px-2 text-right text-gray-300">
diff --git a/client/src/pages/QuotaBurn.jsx b/client/src/pages/QuotaBurn.jsx
index b9c1f0b5c4..ed3d698232 100644
--- a/client/src/pages/QuotaBurn.jsx
+++ b/client/src/pages/QuotaBurn.jsx
@@ -131,12 +131,21 @@ export default function QuotaBurn() {
// `persistRef` above.
const saveRef = useRef(null);
const hasConfigRef = useRef(false);
+ // Pure request-ordering guard for `load()`, distinct from `editSeqRef` above
+ // (which only tracks the user's own edits). The manual Refresh button and the
+ // background poll can both have a `load()` in flight at once — a family scrape
+ // takes 10-20s, longer than the poll interval — so a slower, earlier-started
+ // request can resolve AFTER a faster, later one and silently revert the page
+ // to stale numbers. Only the response to the most recently issued request may
+ // write state.
+ const loadSeqRef = useRef(0);
// Every failure — first load, manual refresh, or a background poll — is
// reported by `loadError` and rendered as this page's ONE banner, so the
// caller doesn't need the cause back.
const load = useCallback(async (refresh = false) => {
const seq = editSeqRef.current;
+ const requestSeq = ++loadSeqRef.current;
// `silent: true` because the failure is rendered by this page's own banner
// rather than the request helper's toast — see client/src/CLAUDE.md's
// silent-vs-toasting rule.
@@ -150,6 +159,10 @@ export default function QuotaBurn() {
// nothing has to clear the previous failure, or the banner goes on blaming
// a network error for what is now the server returning no plan.
if (data === READ_FAILED) return;
+ // A slower, earlier-started `load()` (e.g. a poll issued before a manual
+ // Refresh) resolving after a fresher one must not overwrite what the fresher
+ // response already wrote.
+ if (loadSeqRef.current !== requestSeq) return;
// Cleared on ANY successful read, including the polls: the last error no
// longer describes the page once the server has answered.
setLoadError(null);
diff --git a/client/src/utils/formatters.js b/client/src/utils/formatters.js
index 11a7ef13d5..d47f3650f8 100644
--- a/client/src/utils/formatters.js
+++ b/client/src/utils/formatters.js
@@ -331,12 +331,15 @@ export function formatPercent(value, { decimals = 1, fallback = '—' } = {}) {
* `trimWhole` drops the `.00` on a round figure — for a price the user typed
* ($200/mo), not for a computed total, where aligned cents are the point.
*
- * @param {number} value - Dollar amount (nullish renders as $0.00)
- * @param {{ signed?: boolean, trimWhole?: boolean }} [options]
+ * @param {number} value - Dollar amount (nullish renders as $0.00; a non-nullish
+ * value that fails to parse as a finite number — NaN, a broken calc — renders
+ * `fallback` instead, so a computation failure never masquerades as "$0.00")
+ * @param {{ signed?: boolean, trimWhole?: boolean, fallback?: string }} [options]
* @returns {string} e.g. "$12.34", "-$5.00", "$200"
*/
-export function formatUsd(value, { signed = false, trimWhole = false } = {}) {
- const n = Number(value) || 0;
+export function formatUsd(value, { signed = false, trimWhole = false, fallback = '—' } = {}) {
+ const n = value === null || value === undefined ? 0 : Number(value);
+ if (!Number.isFinite(n)) return fallback;
const magnitude = signed ? Math.abs(n) : n;
const body = trimWhole && Number.isInteger(magnitude) ? String(magnitude) : magnitude.toFixed(2);
return `${signed && n < 0 ? '-' : ''}$${body}`;
diff --git a/scripts/migrations/262-revive-null-app-blocked-merge-followups.js b/scripts/migrations/262-revive-null-app-blocked-merge-followups.js
index d9c2ed5770..821461e605 100644
--- a/scripts/migrations/262-revive-null-app-blocked-merge-followups.js
+++ b/scripts/migrations/262-revive-null-app-blocked-merge-followups.js
@@ -82,7 +82,11 @@ const QUEUE_FILES = [
*/
async function queuePaths(rootDir) {
const raw = await readFile(join(rootDir, 'data', 'cos', 'state.json'), 'utf-8').catch(() => null);
- const config = raw ? JSON.parse(raw)?.config ?? {} : {};
+ // A truncated/corrupted state.json (left behind by a prior crash) must not
+ // abort this migration and every one after it — fall back to the defaults
+ // exactly as a missing file already does.
+ const parsed = raw ? (() => { try { return JSON.parse(raw); } catch { return null; } })() : null;
+ const config = parsed?.config ?? {};
return QUEUE_FILES.map(({ configKey, file }) => (
typeof config[configKey] === 'string' && config[configKey] ? config[configKey] : file
));
diff --git a/scripts/migrations/262-revive-null-app-blocked-merge-followups.test.js b/scripts/migrations/262-revive-null-app-blocked-merge-followups.test.js
index 223f16cde2..fa00b3a08e 100644
--- a/scripts/migrations/262-revive-null-app-blocked-merge-followups.test.js
+++ b/scripts/migrations/262-revive-null-app-blocked-merge-followups.test.js
@@ -184,6 +184,17 @@ describe('migration 262 up()', () => {
expect(parseTasksMarkdown(await readFile(join(rootDir, 'data', 'custom-cos.md'), 'utf-8'))[0].status).toBe('pending');
});
+ // A prior crash can leave data/cos/state.json truncated/corrupted. That must
+ // fall back to the default queue paths exactly like a missing file, not abort
+ // this migration (and every one queued after it in the same run).
+ it('falls back to the default queue paths when state.json is corrupted', async () => {
+ await mkdir(join(rootDir, 'data', 'cos'), { recursive: true });
+ await writeFile(join(rootDir, 'data', 'cos', 'state.json'), '{not valid json');
+ await writeFile(cosTasks(), queue([strandedFollowUp('sys-rl-1')]));
+ await expect(migration.up({ rootDir, now: STAMP })).resolves.toMatchObject({ ok: true, revived: 1 });
+ expect(parseTasksMarkdown(await readFile(cosTasks(), 'utf-8'))[0].status).toBe('pending');
+ });
+
it('is idempotent across runs', async () => {
await writeFile(cosTasks(), queue([strandedFollowUp('sys-rl-1')]));
await migration.up({ rootDir, now: STAMP });
diff --git a/server/routes/settings.js b/server/routes/settings.js
index a525c5355a..aa268d7868 100644
--- a/server/routes/settings.js
+++ b/server/routes/settings.js
@@ -2,6 +2,7 @@ import { Router } from 'express';
import { z } from 'zod';
import { getSettings, updateSettingsWith } from '../services/settings.js';
import { getAiAssignments, updateAiAssignment } from '../services/aiAssignments.js';
+import { saveSubscriptionCosts } from '../services/subscriptionCosts.js';
import {
setCodexParallelLimit,
CODEX_PARALLEL_MIN,
@@ -272,12 +273,21 @@ router.put('/', asyncHandler(async (req, res) => {
// would bypass the current-password proof the /api/auth/password routes
// require. Secrets are write-only through their dedicated routes
// (/api/auth/password, /api/github/secrets, etc.).
- const { secrets: _ignoredSecrets, catalogUserTypes: _ignoredTypes, ...settingsPatch } = req.body || {};
+ // subscriptionCosts is excluded from the generic shallow spread below and
+ // routed through the same per-family merge PUT /api/usage/subscriptions
+ // uses (saveSubscriptionCosts) — a shallow `{ ...current, ...settingsPatch }`
+ // would replace the whole map, silently dropping any family the incoming
+ // patch didn't mention.
+ const { secrets: _ignoredSecrets, catalogUserTypes: _ignoredTypes, subscriptionCosts: subscriptionCostsPatch, ...settingsPatch } = req.body || {};
// updateSettingsWith (not updateSettings) so we can re-inject persisted
// write-only tokens the incoming patch omits, against the freshest snapshot
// inside the write queue (see preserveExternallyOwnedKeys).
- const merged = await updateSettingsWith((current) =>
+ let merged = await updateSettingsWith((current) =>
preserveExternallyOwnedKeys({ ...current, ...settingsPatch }, current));
+ if (subscriptionCostsPatch !== undefined) {
+ const costs = await saveSubscriptionCosts(subscriptionCostsPatch);
+ merged = { ...merged, subscriptionCosts: costs };
+ }
// The queue caches codex.parallelLimit in-process; sync it from the
// merged value so a save takes effect without a restart and without
// re-reading the file.
diff --git a/server/services/cosTaskGenerator.js b/server/services/cosTaskGenerator.js
index 00ffb85ad0..e0ea730e94 100644
--- a/server/services/cosTaskGenerator.js
+++ b/server/services/cosTaskGenerator.js
@@ -1890,6 +1890,12 @@ async function generateManagedAppImprovementTask(app, state, { ignoreTaskId = nu
if (appRequests.length > 0) {
const request = appRequests[0];
await taskSchedule.clearOnDemandRequest(request.id);
+ // Only a human "Run" may clear the drain's brakes (park state, dispatch
+ // count); the policy lives in applyOnDemandRunResets so this idle-review
+ // path can't drift from its spawnPriority0OnDemand siblings — without it,
+ // a currently drain-capped or parked perpetual type dequeued here stays
+ // capped/parked and the explicit "Run" silently produces no task.
+ await taskSchedule.applyOnDemandRunResets(request, app.id);
nextType = request.taskType;
selectionReason = 'on-demand';
emitLog('info', `Processing on-demand app task request: ${nextType} for ${app.name}`, { requestId: request.id });