Skip to content

Commit f421d52

Browse files
authored
feat(settings): retire thinking_budgets — Gemini SDK ignores it (issue #7) (#59)
The Settings UI's "Thinking budgets" section, the per-call-site int budget plumbing in nlp-service's _read_thinking_budget JSON-read path + cache, the db.ts getter/setter cluster, the API route validator, and the SQLite settings row + /data/llm-config.json mirror key are all removed. Migration v22 actively scrubs both stores on existing installs. Per-call-site budget VALUES (extract: 512, draft: 1024, etc.) STAY hardcoded in nlp-service/services/llm_client.py:_DEFAULT_THINKING_BUDGETS and continue to flow through LLMRequest.thinking_budget to both providers (GeminiProvider's thinking_config kwarg, DeepSeekProvider's conditional reasoning_effort enum). Behaviour reverts to the pre-a53c66b shape: hardcoded design intent, not user-tunable. Why now: per issue #7's "Evaluated and confirmed NOT to work" list, thinking_budget tuning is silently ignored on Gemini 2.5 models upstream (googleapis/python-genai#782). The user-visible knob (a53c66b, 2026-04-30) was added as a mitigation attempt for the structured-output repetition- loop bug; it never reliably did anything. The actual mitigations (json-repair salvage, halved-input fallback, _with_retry, DeepSeek alternative provider, per-source provider switching) are independent and stay in place. Why a migration: unlike retired toggles whose settings rows can re-enable a feature later, this knob is dead weight by construction. The JSON mirror at /data/llm-config.json lives on the kompl-data named volume which preserves orphan keys across rebuilds. v22 deletes both surfaces idempotently. v22 stacks on chore's v21 (deployment_mode purge). Behaviour: zero observable change on Gemini 2.5 (knob was upstream- ignored). Zero change on DeepSeek for default-budget call sites (most of them — LLMRequest.thinking_budget defaults to 0; DeepSeek only sets reasoning_effort when > 0). Removed: ~520 lines (Settings section + state hooks, db.ts getter/setter + types + const + validator function, API route validator + imports + GET field + POST type + knownFields entry, _thinking_cache, JSON-read logic in _read_thinking_budget, 2 test files totaling 13 tests). Schema bumps to v22 (migrate.py SCHEMA_VERSION, helpers/schema.sql:221, health/route.ts:58, integration-test.sh stage 1 assertion). Signed-off-by: tuirk <[email protected]>
1 parent 6317b2c commit f421d52

10 files changed

Lines changed: 44 additions & 522 deletions

File tree

‎app/src/__tests__/helpers/schema.sql‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,4 @@ CREATE INDEX idx_relationship_mentions_source ON relationship_mentions(source_id
218218
CREATE INDEX idx_collect_staging_session ON collect_staging(session_id);
219219
CREATE INDEX idx_collect_staging_session_status ON collect_staging(session_id, status);
220220

221-
INSERT INTO settings (key, value) VALUES ('schema_version', '21');
221+
INSERT INTO settings (key, value) VALUES ('schema_version', '22');

‎app/src/__tests__/thinking-budgets.test.ts‎

Lines changed: 0 additions & 109 deletions
This file was deleted.

‎app/src/app/api/health/route.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export async function GET() {
5555
nlpOk = nlpRes.ok;
5656
} catch { /* non-fatal */ }
5757

58-
const dbOk = dbWritable && allExpectedPresent && schemaVersion === 21;
58+
const dbOk = dbWritable && allExpectedPresent && schemaVersion === 22;
5959

6060
// status:'ok' requires DB healthy + NLP reachable + no vector backlog.
6161
// status:'degraded' means the app is serving but something needs attention.

‎app/src/app/api/settings/route.ts‎

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ import {
2424
getDailyCapUsd, setDailyCapUsd,
2525
getChatModel, setChatModel, isChatModel,
2626
getCompileModel, setCompileModel,
27-
getThinkingBudgets, setThinkingBudgets,
28-
THINKING_BUDGET_KEYS, type ThinkingBudgetKey,
2927
} from '../../../lib/db';
3028

3129
function buildResponse() {
@@ -49,7 +47,6 @@ function buildResponse() {
4947
daily_cap_usd: getDailyCapUsd(),
5048
chat_model: getChatModel(),
5149
compile_model: getCompileModel(),
52-
thinking_budgets: getThinkingBudgets(),
5350
};
5451
}
5552

@@ -74,7 +71,6 @@ export async function POST(request: Request) {
7471
daily_cap_usd?: number;
7572
chat_model?: string;
7673
compile_model?: string;
77-
thinking_budgets?: Partial<Record<ThinkingBudgetKey, number>>;
7874
};
7975

8076
const knownFields = [
@@ -88,7 +84,6 @@ export async function POST(request: Request) {
8884
'daily_cap_usd',
8985
'chat_model',
9086
'compile_model',
91-
'thinking_budgets',
9287
];
9388
if (!knownFields.some((f) => f in body)) {
9489
return NextResponse.json({ error: 'no recognized setting field in request body' }, { status: 422 });
@@ -229,30 +224,5 @@ export async function POST(request: Request) {
229224
setCompileModel(body.compile_model);
230225
}
231226

232-
if (body.thinking_budgets !== undefined) {
233-
if (typeof body.thinking_budgets !== 'object' || body.thinking_budgets === null || Array.isArray(body.thinking_budgets)) {
234-
return NextResponse.json(
235-
{ error: 'thinking_budgets must be an object mapping call-site name to integer in [-1, 24576]' },
236-
{ status: 422 },
237-
);
238-
}
239-
const patch = body.thinking_budgets as Record<string, unknown>;
240-
for (const [key, value] of Object.entries(patch)) {
241-
if (!THINKING_BUDGET_KEYS.includes(key as ThinkingBudgetKey)) {
242-
return NextResponse.json(
243-
{ error: `unknown thinking_budgets key: ${key}. Valid keys: ${THINKING_BUDGET_KEYS.join(', ')}` },
244-
{ status: 422 },
245-
);
246-
}
247-
if (!Number.isInteger(value) || (value as number) < -1 || (value as number) > 24576) {
248-
return NextResponse.json(
249-
{ error: `thinking_budgets.${key} must be an integer in [-1, 24576] (-1 = unlimited, 0 = off)` },
250-
{ status: 422 },
251-
);
252-
}
253-
}
254-
setThinkingBudgets(body.thinking_budgets);
255-
}
256-
257227
return NextResponse.json(buildResponse());
258228
}

0 commit comments

Comments
 (0)