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 (claude): refund budget when a self-gated tool does no work
[._.]/ Adam Eivyadd6e7e2b1bf
diff --git a/server/services/creative/toolRegistry.js b/server/services/creative/toolRegistry.jsindex e03b64f729..8b45567b4f 100644--- a/server/services/creative/toolRegistry.js+++ b/server/services/creative/toolRegistry.js@@ -227,6 +227,7 @@ export async function dispatchCreativeTool(name, args = {}, ctx = {}) {// 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.+ let charged = false;if (BUDGETED_COST_CLASSES.has(tool.costClass) && !tool.selfBudgeted) {const status = await getDomainBudgetStatus(BUDGET_DOMAIN);if (!status.withinBudget) {@@ -235,6 +236,7 @@ export async function dispatchCreativeTool(name, args = {}, ctx = {}) {return { ok: false, rejected: true, reason: 'budget', exceeded: status.exceeded, mode, tool: name };}await recordDomainUsage(BUDGET_DOMAIN, { actions: 1 });+ charged = true;}const startedAt = Date.now();@@ -251,6 +253,11 @@ export async function dispatchCreativeTool(name, args = {}, ctx = {}) {// 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'})`);+ // The tool did no work — refund the action charged before execute so a+ // self-gated (non-selfBudgeted) tool doesn't burn budget on a no-op. Today+ // only the selfBudgeted autopilot self-rejects (never charged), so this is+ // defensive for future self-gating tools that keep the registry charge.+ if (charged) await recordDomainUsage(BUDGET_DOMAIN, { actions: -1 });await recordLedger(ctx, { ...base, outcome: 'rejected', timingMs });return { ok: false, rejected: true, reason: result.reason || 'tool-rejected', mode, tool: name, result, timingMs };}diff --git a/server/services/creative/toolRegistry.test.js b/server/services/creative/toolRegistry.test.jsindex 2c544c8460..ff58111e56 100644--- a/server/services/creative/toolRegistry.test.js+++ b/server/services/creative/toolRegistry.test.js@@ -269,6 +269,17 @@ describe('wrapped-service self-rejection', () => {expect(out.result).toEqual({ rejected: true, mode: 'off' });expect(appendLedger.mock.calls[0][0].outcome).toBe('rejected');});++ it('refunds the charged action when a non-selfBudgeted llm tool self-rejects', async () => {+ setMode('execute');+ // generateStage is COST_LLM and NOT selfBudgeted, so dispatch charges before+ // execute; a self-reject must refund so a no-op doesn't burn budget.+ generateStage.mockResolvedValueOnce({ rejected: true, reason: 'inner-gate' });+ const out = await dispatchCreativeTool('pipeline_generateStage', { issueId: 'i1', stageId: 'st1' });+ expect(out).toMatchObject({ ok: false, rejected: true, reason: 'inner-gate' });+ expect(recordDomainUsage).toHaveBeenCalledWith('cos', { actions: 1 });+ expect(recordDomainUsage).toHaveBeenCalledWith('cos', { actions: -1 });+ });});describe('run ledger append', () => {