Originally created by: Akarsh-Hegde
Stacked on [#112] (
feat/mlx-dynamic-model-selection). Base is that branch, notmain— merge after [#112]. Both editrun_task_linker_mlx.py; stacking avoids the conflict.
This is a no-op for every model the classifier can select today. OptiQ has a 128k window (→ ~436k-char budget) and every selectable MLX model is ≥16k, so nothing truncates and the rendered prompt is byte-identical to the current static path (verified). No production inputs change → no eval cycle required.
What it delivers is principled hardening + insurance, not a behavior change:
It does not fix Apple FM for the classifier — its system prompt alone (~4.85k tok) overflows a ~4k window regardless of user-message budgeting (deferred KAN-97 work).
run_task_linker_mlx: read the model's max_position_embeddings from its config.json (authoritative, can't drift like a hand-kept map; clamped + conservative fallback), measure the fixed system prompt with the real loaded tokenizer (dominant constant term), and derive user_message_char_budget = (ctx − output_reserve − system − margin) × chars_per_token. Conservative chars/token biases toward truncating slightly early (overflow is fatal; under-fill is a mild quality cost)._prompts.build_user_message(…, char_budget=…): keep session_text at its normal cap; absorb overflow by truncating the candidate list first; only shrink session_text toward a floor when even the candidate floor won't fit. Both floored._resolve_model_id: an explicit SESSION_TEXT_CAP env (incl. 0) pins the legacy static behaviour and disables the dynamic budget (eval reproducibility). char_budget=None preserves exact prior behaviour for non-MLX callers.pm_tasks (~1.3k chars), nowhere near the ~436k budget → no-op deployment-wide./classify_sessions round-trips; budget log shows the tokenizer-measured system prompt (4790 tok).char_budget=None default is backward-compatible).Caveat: "guaranteed fit" holds except in a ~5–5.5k-token window band too small to host the classifier at all — academic; no selectable model lives there.
A true small-window path for the classifier (Apple FM etc.) needs a SKILL.md/system-prompt redesign — separate, eval-gated, KAN-97.
🤖 Generated with Claude Code
Ticket changed by: adityaharishch