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 review (codex r2) — broken /new route, double-charge, fail-closed

[._.]/ Adam Eivy4f744ba364a7
diff --git a/client/src/App.jsx b/client/src/App.jsx
index 6c9dfea9e5..80c0239286 100644
--- a/client/src/App.jsx
+++ b/client/src/App.jsx
@@ -347,7 +347,9 @@ export default function App() {
<Route path="creative-director/:id" element={<CreativeDirectorOverviewRedirect />} />
<Route path="creative-director/:id/:tab" element={<CreativeDirectorDetail />} />
<Route path="creative-commission" element={<CreativeCommissions />} />
- <Route path="creative-commission/new" element={<CreativeCommissions />} />
+ {/* `:id` matches the literal `new` (create mode) too — a separate
+ static `new` route would render with no :id param and leave the
+ drawer closed, since React Router ranks the static segment higher. */}
<Route path="creative-commission/:id" element={<CreativeCommissions />} />
<Route path="image-gen" element={<RedirectWithSearch to="/media/image" />} />
<Route path="video-gen" element={<RedirectWithSearch to="/media/video" />} />
diff --git a/server/lib/navManifest.test.js b/server/lib/navManifest.test.js
index d69a6a179b..3dca30bb20 100644
--- a/server/lib/navManifest.test.js
+++ b/server/lib/navManifest.test.js
@@ -314,7 +314,6 @@ const NAV_COVERAGE_OPT_OUT = new Map([
['/login', 'auth gate — surfaced only when settings.secrets.auth is enabled, reached via 401 redirect'],
['/songbook/import', 'import-song form, reached via the "Import" button on /songbook'],
['/universes/new', 'create-mode sentinel for the Universe Builder editor'],
- ['/creative-commission/new', 'create-mode sentinel for the Creative Commission drawer'],
]);
// Element wrappers that forward to another route rather than render a page. A
diff --git a/server/services/creativeCommissions/scheduler.js b/server/services/creativeCommissions/scheduler.js
index e50ca84cdc..bdd29e1c32 100644
--- a/server/services/creativeCommissions/scheduler.js
+++ b/server/services/creativeCommissions/scheduler.js
@@ -140,7 +140,6 @@ export function stopCommissionScheduler() {
* each plan step through the gated `dispatchCreativeTool`).
*/
export async function runScheduledCommission(commissionId) {
- let charged = false;
try {
const commission = await getCommission(commissionId).catch(() => null);
if (!commission || commission.enabled === false) return;
@@ -150,19 +149,28 @@ export async function runScheduledCommission(commissionId) {
// Gate on creative autonomy mode + daily cos budget BEFORE spawning anything
// (the planner is itself an LLM call) — honors "off ⇒ no generation" and the
- // no-cold-LLM policy.
- const [{ loadState }, { getCreativeAutonomyMode }, { getDomainBudgetStatus, recordDomainUsage }] = await Promise.all([
+ // no-cold-LLM policy. Both reads FAIL CLOSED: if governance state can't be
+ // verified we skip rather than launch a paid planner on a permissive default.
+ const [{ loadState }, { getCreativeAutonomyMode }, { getDomainBudgetStatus }] = await Promise.all([
import('../cosState.js'),
import('../../lib/domainAutonomy.js'),
import('../domainUsage.js'),
]);
- const state = await loadState().catch(() => ({ config: {} }));
+ const state = await loadState().catch(() => null);
+ if (!state) {
+ await recordCommissionRun(commissionId, { status: 'skipped', reason: 'governance-unavailable' }).catch(() => {});
+ return;
+ }
const mode = getCreativeAutonomyMode(state.config);
if (mode !== 'execute') {
await recordCommissionRun(commissionId, { status: 'skipped', reason: `autonomy-${mode}` }).catch(() => {});
return;
}
- const budget = await getDomainBudgetStatus('cos').catch(() => ({ withinBudget: true }));
+ const budget = await getDomainBudgetStatus('cos').catch(() => null);
+ if (!budget) {
+ await recordCommissionRun(commissionId, { status: 'skipped', reason: 'budget-unavailable' }).catch(() => {});
+ return;
+ }
if (!budget.withinBudget) {
await recordCommissionRun(commissionId, { status: 'skipped', reason: 'budget' }).catch(() => {});
return;
@@ -175,16 +183,13 @@ export async function runScheduledCommission(commissionId) {
return;
}
- // Charge the planner action against the shared daily cos budget on admission.
- // The planner LLM call is enqueued via task:ready and bypasses
- // dequeueNextTask's allowance check, so without this two commissions firing
- // in the same tick could each observe the same remaining budget and overrun
- // the user's cap. Charging here narrows that window (refunded below if the
- // spawn fails). Not a hard reservation — the deeper fix is a shared
- // admission gate at the planner boundary (tracked on #2657).
- await recordDomainUsage('cos', { actions: 1 }).catch(() => {});
- charged = true;
-
+ // NOTE: we deliberately do NOT pre-charge the cos budget here. The planner
+ // spawns as a normal CoS agent (a `cd-` task) and is accounted by
+ // `completeAgent` → `recordDomainUsage('cos', { actions: 1 })` on completion,
+ // so a pre-charge would double-count. A hard concurrency/budget admission for
+ // the planner (routing it through dequeueNextTask instead of the direct
+ // task:ready emit shared with the CD directive flow) is the deeper CoS-queue
+ // gap tracked on #2657.
const [{ createProject }, { advanceAfterPlanStepSettled }, { defaultVideoModelId }] = await Promise.all([
import('../creativeDirector/local.js'),
import('../creativeDirector/planAdvance.js'),
@@ -222,11 +227,6 @@ export async function runScheduledCommission(commissionId) {
await advanceAfterPlanStepSettled(project.id);
} catch (err) {
console.error(`❌ Creative commission ${commissionId} fire failed: ${err?.message || err}`);
- // Refund the reserved planner action — the spawn threw, so it never ran.
- if (charged) {
- const { recordDomainUsage } = await import('../domainUsage.js').catch(() => ({}));
- await recordDomainUsage?.('cos', { actions: -1 }).catch(() => {});
- }
await recordCommissionRun(commissionId, { status: 'failed', error: err?.message || String(err) }).catch(() => {});
}
}
diff --git a/server/services/creativeCommissions/scheduler.test.js b/server/services/creativeCommissions/scheduler.test.js
index 21ee0f960e..aaf5c19596 100644
--- a/server/services/creativeCommissions/scheduler.test.js
+++ b/server/services/creativeCommissions/scheduler.test.js
@@ -139,8 +139,9 @@ describe('runScheduledCommission gates', () => {
}));
expect(advanceMock).toHaveBeenCalledWith('cd-xyz');
expect(recordRunMock).toHaveBeenCalledWith('commission-1', expect.objectContaining({ status: 'started', projectId: 'cd-xyz' }));
- // Reserves the planner action against the cos budget on admission.
- expect(recordUsageMock).toHaveBeenCalledWith('cos', { actions: 1 });
+ // The planner's cos action is accounted by completeAgent on completion — the
+ // fire handler must NOT pre-charge (that would double-count).
+ expect(recordUsageMock).not.toHaveBeenCalled();
});
it('caps the derived project name so createCollection (80-char limit) never fails', async () => {
@@ -152,11 +153,20 @@ describe('runScheduledCommission gates', () => {
expect(name.endsWith(new Date().toISOString().slice(0, 10))).toBe(true);
});
- it('does not charge the budget when a gate skips the fire', async () => {
- creativeModeMock.mockReturnValue('off');
+ it('fails closed (skips) when the autonomy/config read is unavailable', async () => {
+ loadStateMock.mockRejectedValueOnce(new Error('cos state read failed'));
getCommissionMock.mockResolvedValue(videoCommission());
await runScheduledCommission('commission-1');
- expect(recordUsageMock).not.toHaveBeenCalled();
+ expect(createProjectMock).not.toHaveBeenCalled();
+ expect(recordRunMock).toHaveBeenCalledWith('commission-1', expect.objectContaining({ status: 'skipped', reason: 'governance-unavailable' }));
+ });
+
+ it('fails closed (skips) when the budget read is unavailable', async () => {
+ budgetMock.mockRejectedValueOnce(new Error('budget read failed'));
+ getCommissionMock.mockResolvedValue(videoCommission());
+ await runScheduledCommission('commission-1');
+ expect(createProjectMock).not.toHaveBeenCalled();
+ expect(recordRunMock).toHaveBeenCalledWith('commission-1', expect.objectContaining({ status: 'skipped', reason: 'budget-unavailable' }));
});
it('skips generation (records skipped) when creative autonomy is off', async () => {