From 1d58e5b50998444d5e972c51412f4b913a0fadcf Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 14 Sep 2026 05:23:13 +0200 Subject: [PATCH] fix: the take-home sheet gives a reasoning model room to think and still write The 1,800-token ceiling was spent entirely on hidden reasoning, so the sheet came back empty. Same budget as the answer path now, with one retry at a larger budget if the reply is still blank. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01Dv6sqaY6Vq3ChZHMem3cnU --- src/utils/patientTakehome.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/utils/patientTakehome.js b/src/utils/patientTakehome.js index 3351cd9f..7e98c03a 100644 --- a/src/utils/patientTakehome.js +++ b/src/utils/patientTakehome.js @@ -27,13 +27,22 @@ async function generatePatientTakehome(opts) { { role: 'system', content: behavior }, { role: 'user', content: 'Clinical answer:\n' + answer + '\n\nWrite the patient take-home sheet now.' } ]; + // The budget covers the model's hidden reasoning as well as the sheet. At + // 1,800 tokens a reasoning model (DeepSeek flash spent 8,400 characters + // thinking about a discharge sheet) hit the limit before writing a word and + // the user saw "empty take-home sheet". Same ceiling as the answer path, + // and one retry with more room when the reply still comes back empty. var ai; - try { - ai = await opts.callAI(messages, assistantGenerationOptions({ model: opts.model || undefined, temperature: 0.15, maxTokens: 1800 })); - } catch (err) { - err = err || new Error('Take-home generation failed'); - if (!err.statusCode && !err.response) err.statusCode = 502; - throw err; + var budgets = [5000, 9000]; + for (var attempt = 0; attempt < budgets.length; attempt++) { + try { + ai = await opts.callAI(messages, assistantGenerationOptions({ model: opts.model || undefined, temperature: 0.15, maxTokens: budgets[attempt] })); + } catch (err) { + err = err || new Error('Take-home generation failed'); + if (!err.statusCode && !err.response) err.statusCode = 502; + throw err; + } + if (ai && String(ai.content || '').trim()) break; } var text = stripCitationTokens(ai && ai.content || '').slice(0, MAX_RESULT_CHARS); if (!text) { e = new Error('The model returned an empty take-home sheet'); e.statusCode = 502; throw e; }