From 216dacb0f21ef9f6dbee6b15e8b63c331cf56638 Mon Sep 17 00:00:00 2001 From: jtricerolph Date: Sat, 25 Jul 2026 09:30:15 +0000 Subject: [PATCH] Raise output token cap; add one-time note about the rota-methodology fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MAX_OUTPUT_TOKENS was 600 and briefings were hitting it mid-sentence (confirmed on a live generation — cut off mid-bullet). Raised to 900. Also adds a time-boxed methodology note (expires 29/07/2026) so the model doesn't flag the 25/07 base-cost-only rota fix as an unexplained swing when it sees a prior insight's rota variance figures differ — it was told to compare against recent insights explicitly, and without this note it correctly but unhelpfully treated a deliberate correction as an open question needing clarification. Co-Authored-By: Claude Sonnet 5 --- backend/src/jobs/ai-insights.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/backend/src/jobs/ai-insights.js b/backend/src/jobs/ai-insights.js index 0892ce1..f4a6ab9 100644 --- a/backend/src/jobs/ai-insights.js +++ b/backend/src/jobs/ai-insights.js @@ -6,9 +6,14 @@ import { forecastDayCost } from '../lib/forecast.js' export const DEFAULT_MODEL = 'claude-haiku-4-5-20251001' export const DEFAULT_DAILY_TOKEN_BUDGET = 5000 -const MAX_OUTPUT_TOKENS = 600 +const MAX_OUTPUT_TOKENS = 900 export const MANUAL_RATE_LIMIT_MINUTES = 5 +// One-time context so the model doesn't flag the 25/07 rota-methodology fix (oncost-inclusive +// -> base-pay-only comparison) as an unexplained swing when it sees a prior insight's figures +// change. Safe to delete this constant and its usage below once it's a few days stale. +const METHOD_CHANGE_NOTE_UNTIL = '2026-07-29' + function toISODate(d) { return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}` } @@ -358,6 +363,19 @@ export function buildPrompt(monthProgress, priorPeriod, rotaVsActual, forecast, const lines = [] + if (recentInsights.length && toISODate(new Date()) <= METHOD_CHANGE_NOTE_UNTIL) { + lines.push('## Methodology Note (25/07/2026)') + lines.push( + "The Rota vs Actual Variance comparison was corrected on 25/07/2026 to use base pay only on both " + + "sides (previously actual cost included employer NI oncosts while rota did not, since Workforce's " + + "schedules API never supplies oncosts — this inflated every rota variance figure by roughly 14-20%). " + + "If a recent previous insight below shows a notably different rota variance figure for the same " + + "department than today's, that is this correction taking effect, not a real change in performance — " + + "do not describe it as unexplained or needing clarification." + ) + lines.push('') + } + if (recentInsights.length) { lines.push('## Recent Previous Insights (most recent first — reference these, do not just repeat them)') for (const r of recentInsights) {