mirror of
https://github.com/dtzp555-max/ocp.git
synced 2026-07-21 21:15:09 +00:00
fix(server): empty CLAUDE_MAX_PROMPT_CHARS falls back to derived default (PR #179 review)
Reviewer regression: `!= null` treated an EMPTY env value ("CLAUDE_MAX_PROMPT_CHARS="
in an EnvironmentFile/.env) as explicit -> parseInt("") = NaN -> guard disabled + a
false "[System] Note: 0 older messages were truncated" injected into every prompt.
Extracted resolvePromptCharBudget() (truthiness contract, matching the old
`parseInt(env || default)` behavior) into lib/prompt.mjs so the semantics are
mutation-tested: switching back to != null fails the empty-string test. +2 tests, 349/0.
Co-Authored-By: Claude <claude-opus-4-8> <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude <claude-opus-4-8> <noreply@anthropic.com>
parent
8405e30d0e
commit
e912903ba5
@@ -41,3 +41,14 @@ export function derivePromptCharBudget(models, { charsPerToken = 3, floor = 1500
|
||||
if (windows.length === 0) return floor;
|
||||
return Math.max(floor, Math.max(...windows) * charsPerToken);
|
||||
}
|
||||
|
||||
// Resolve the effective budget from the env var + SPOT. TRUTHINESS (not != null) on the env
|
||||
// value deliberately: an EMPTY value ("CLAUDE_MAX_PROMPT_CHARS=" in a systemd EnvironmentFile
|
||||
// or .env) must mean "use the default" — exactly the old `parseInt(env || "150000")` contract.
|
||||
// Treating "" as explicit gives parseInt("") = NaN, and a NaN cap silently DISABLES the
|
||||
// runaway-context guard while injecting a false "[System] Note: 0 older messages were
|
||||
// truncated" line into every prompt (caught in PR #179 review). Non-empty garbage still
|
||||
// parses to NaN — the pre-existing class, slated for parseIntEnv routing in PR #154.
|
||||
export function resolvePromptCharBudget(rawEnv, models, opts) {
|
||||
return rawEnv ? parseInt(rawEnv, 10) : derivePromptCharBudget(models, opts);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user