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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (codex): correct autopilot budget + self-rejection handling
[._.]/ Adam Eivy74c7fc0054eb
diff --git a/server/services/creative/toolRegistry.js b/server/services/creative/toolRegistry.jsindex 8c84da9528..e03b64f729 100644--- a/server/services/creative/toolRegistry.js+++ b/server/services/creative/toolRegistry.js@@ -222,8 +222,12 @@ export async function dispatchCreativeTool(name, args = {}, ctx = {}) {};}- // execute mode — charge the daily action budget for llm/render tools first.- if (BUDGETED_COST_CLASSES.has(tool.costClass)) {+ // execute mode — charge the daily action budget for llm/render tools first,+ // EXCEPT self-budgeting tools: a long-running coordinator (Series Autopilot)+ // budget-gates and records each of its own LLM/render steps against the same+ // cos budget internally, so charging one action here would double-count and,+ // under a tight cap, consume the last action before the run does any work.+ if (BUDGETED_COST_CLASSES.has(tool.costClass) && !tool.selfBudgeted) {const status = await getDomainBudgetStatus(BUDGET_DOMAIN);if (!status.withinBudget) {console.log(`⛔ creative dispatch ${name} over budget (${BUDGET_DOMAIN} ${status.exceeded})`);@@ -239,6 +243,17 @@ export async function dispatchCreativeTool(name, args = {}, ctx = {}) {try {const result = await tool.execute(parsed, ctx);const timingMs = Date.now() - startedAt;+ // A wrapped service that self-gates returns `{ rejected: true, ... }` instead+ // of throwing (e.g. Series Autopilot when cos autonomy is `off`, reachable+ // when creative is explicitly overridden to `execute` over an `off` cos).+ // Surface that honestly through the one chokepoint rather than reporting a+ // clean `executed` — otherwise the ledger and orchestrator record a+ // successful start for a run the inner gate refused.+ if (result && result.rejected === true) {+ console.log(`🚫 creative dispatch ${name} rejected by wrapped service (${result.mode ?? 'gate'})`);+ await recordLedger(ctx, { ...base, outcome: 'rejected', timingMs });+ return { ok: false, rejected: true, reason: result.reason || 'tool-rejected', mode, tool: name, result, timingMs };+ }console.log(`✅ creative dispatch ${name} executed in ${timingMs}ms`);await recordLedger(ctx, { ...base, outcome: 'executed', timingMs });return { ok: true, mode, tool: name, longRunning: Boolean(tool.longRunning), result, timingMs };diff --git a/server/services/creative/toolRegistry.test.js b/server/services/creative/toolRegistry.test.jsindex 840a06bca3..2c544c8460 100644--- a/server/services/creative/toolRegistry.test.js+++ b/server/services/creative/toolRegistry.test.js@@ -70,6 +70,7 @@ import { dispatchTool as dispatchVoiceTool } from '../voice/tools.js';import { getDomainBudgetStatus, recordDomainUsage } from '../domainUsage.js';import { createSeries } from '../pipeline/series.js';import { generateStage } from '../pipeline/textStages.js';+import { startSeriesAutopilot } from '../pipeline/seriesAutopilot.js';import { enqueueJob } from '../mediaJobQueue/index.js';import {CREATIVE_TOOLS,@@ -247,6 +248,27 @@ describe('budget charging', () => {expect(generateStage).not.toHaveBeenCalled();expect(recordDomainUsage).not.toHaveBeenCalled();});++ it('does NOT charge a self-budgeting tool (Series Autopilot charges its own steps)', async () => {+ setMode('execute');+ const out = await dispatchCreativeTool('pipeline_startSeriesAutopilot', { seriesId: 'ser1' });+ expect(out.ok).toBe(true);+ expect(startSeriesAutopilot).toHaveBeenCalled();+ expect(getDomainBudgetStatus).not.toHaveBeenCalled();+ expect(recordDomainUsage).not.toHaveBeenCalled();+ });+});++describe('wrapped-service self-rejection', () => {+ it('surfaces a tool that returns { rejected: true } as a rejected dispatch, not executed', async () => {+ setMode('execute');+ startSeriesAutopilot.mockResolvedValueOnce({ rejected: true, mode: 'off' });+ const appendLedger = vi.fn(async () => {});+ const out = await dispatchCreativeTool('pipeline_startSeriesAutopilot', { seriesId: 'ser1' }, { appendLedger });+ expect(out).toMatchObject({ ok: false, rejected: true });+ expect(out.result).toEqual({ rejected: true, mode: 'off' });+ expect(appendLedger.mock.calls[0][0].outcome).toBe('rejected');+ });});describe('run ledger append', () => {diff --git a/server/services/creative/tools/pipeline.js b/server/services/creative/tools/pipeline.jsindex cbc0deca44..79f82455fa 100644--- a/server/services/creative/tools/pipeline.js+++ b/server/services/creative/tools/pipeline.js@@ -75,6 +75,10 @@ export const PIPELINE_TOOLS = [description: 'Start (or no-op resume) the Series Autopilot for a series. Long-running: returns a run handle; progress and pauses arrive via events. Autopilot has its own cos-off gate; the orchestrator gate applies first.',costClass: COST_LLM,longRunning: true,+ // Self-budgeting: the autopilot budget-gates and records each of its own+ // LLM/render steps against the cos budget internally, so the dispatcher must+ // NOT also charge one action for the start call (see dispatchCreativeTool).+ selfBudgeted: true,schema: z.object({ seriesId: z.string().min(1), options: z.record(z.any()).optional() }),parameters: {type: 'object',