Repository navigation
Description
Problem
Every model on a reader-added "Another OpenAI-compatible service…" endpoint is built by customModel, which pins maxTokens: 4_096 (ui-packages/web/src/core/models/byok/runtime.ts:42-56). The agent passes no maxTokens of its own (ui-packages/web/src/core/agent/definition.ts:31-38), so pi-ai falls back to the model's number (options?.maxTokens ?? model.maxTokens, and contextWindow: 0 — "unknown" — returns it unclamped), and every request carries a 4,096-token output cap.
So a reader who brought a key for a vendor outside the eight presets (Qwen's compatible mode, MiniMax, SiliconFlow, an ollama or LM Studio endpoint, a company relay) gets answers cut mid-sentence at 4,096 tokens — 32× under GLM's 131,072 and 94× under DeepSeek's 384,000, the ceilings the same conversation runs under on the free allowance or any preset (pi's catalog data). The only symptom is the notice "The response reached its output limit." (ui-packages/web/src/features/conversation/use-conversation/messages.ts:74-75), and nothing anywhere raises it: the provider dialog holds name, address, key and models only (ui-packages/web/src/features/settings/model-providers/index.tsx:29-45). Regenerating (#42) hits the same wall.
The same number breaks the repair path for long conversations: a compaction summary is clamped to model.maxTokens, and a cut summary throws "The summary reached its output limit and was not saved." (ui-packages/web/src/features/assistant/compaction.ts:101-111) — on a custom endpoint an entire conversation must summarize inside 4,096 tokens or compaction fails outright.
PRODUCT.md keeps the own-key path "open, not hidden"; a silent 32–94× output handicap that only that path carries is neither.
Proposal
- Stop pinning every custom model at 4,096: send a generous ceiling, or none where the endpoint derives one from the model, so a reply ends when it ends.
- Keep
contextWindow: 0as today — unknown stays unknown; the change is about the ceiling sent, not a guessed window. - If a number must be kept, show it next to the model in the provider dialog and let the reader raise it; a hidden constant plus a one-line notice is the state to remove.
- Compaction and the length notice keep following whatever ceiling the model then carries.
Goal
After this, a reader asking their own OpenAI-compatible endpoint for a long comparison or a full-document summary gets the whole answer: replies through a custom endpoint are no longer stopped at 4,096 output tokens, and a compaction summary on such a model no longer fails merely because the conversation is long.
Verification
test -z "$(grep -n 'maxTokens: 4_096' ui-packages/web/src/core/models/byok/runtime.ts)"
pnpm --filter @gamma-reader/web test --silent
pnpm checkRefs
- ui-packages/web/src/core/models/byok/runtime.ts:42-56 —
customModelpinsmaxTokens: 4_096;contextWindow: 0documented as unknown - ui-packages/web/src/core/agent/definition.ts:31-38 — no maxTokens override, so the model's number applies
- @earendil-works/pi-ai
api/simple-options.js—options?.maxTokens ?? model.maxTokens;contextWindow <= 0returns the value unclamped - pi catalog data (
providers/data/zai-coding-cn.json,deepseek.json) — glm-5.3 maxTokens 131,072; deepseek-flash / v4-pro 384,000 - ui-packages/web/src/features/conversation/use-conversation/messages.ts:74-75 — the only reader-visible symptom
- ui-packages/web/src/features/settings/model-providers/index.tsx:29-45 — the provider dialog has no field for a ceiling
- ui-packages/web/src/features/assistant/compaction.ts:101-111 — a summary is clamped to
model.maxTokensand a cut one fails the run - ui-packages/web/PRODUCT.md — "that path is open, not hidden"
- Long conversations hit the context wall silently — every follow-up then fails, with no warning and no repair path #70 — the context-wall issue whose repair is compaction; on a custom endpoint that repair is capped at 4,096 too
- Let a reader replace a stored key in place — the only action on a configured provider today is Remove, which drops the model selection and switches conversations to the free allowance #174, Remember the reader's model choice for new conversations — today every New chat silently returns to the free shared allowance, however often they pick their own key #184, No-key chat is a dead end — the only 'Add your own model…' entry hides exactly when no model exists #159, Say when a conversation's own-key model is gone — it silently switches to the free shared allowance today #164 — the own-key family this extends: once the key can be replaced and the choice remembered, what the model may write should not depend on which door it came from
Activity
bencode commentedon Oct 23, 2026
Independent review — posted by the scheduled issue-reviewer loop, independent of the authoring session.
Evidence audit (HEAD
da3dfad): confirmed, every anchor exact.byok/runtime.ts:42-56pinsmaxTokens: 4_096withcontextWindow: 0;agent/definition.ts:31-38(streamFn) passes nomaxTokens; pi-aidist/api/simple-options.js:23isoptions?.maxTokens ?? model.maxTokensand:5-10returns it unclamped whencontextWindow <= 0— all verified in the vendored package. Catalog numbers check out (glm-5.3 = 131,072; deepseek-flash / v4-pro = 384,000 → 32× / 94×). The symptom notice (messages.ts:74-75), the ceiling-less provider dialog (index.tsx:29-45), and the compaction clamp + failure (compaction.ts:101-111) are all as described. #70 closed, #159/#164/#174/#184 open as referenced.Duplicate check: none across open + closed titles.
Sensor: lint ✓ · verify ✗ (expected —
maxTokens: 4_096still atruntime.ts:55).Sharpening:
Model.maxTokensis type-required (pi-ai/dist/types.d.ts:648) and per-request omission falls back to it, so "send none" isn't reachable through pi's options today — the realistic shapes are a generous finite ceiling or the reader-visible field. Worth stating in the proposal so implementation doesn't chase an impossible branch.! grep "maxTokens: 4_096") passes on any rename even if a cap remains. Prefer an outcome anchor: a unit test oncustomModelasserting the built model's ceiling is either the generous default or a reader-configured value, and one on the compaction clamp following that ceiling.Valid; stays open.
bencode commentedon Oct 24, 2026
Independent re-review — posted by the scheduled issue-reviewer loop, independent of the session that authored this issue. Audited against
main@90b046f; last review stood atmain@da3dfad.Drift check: 2 commits since the last review (
93563a2styles.css only, plus its merge) — no code drift. Anchors re-confirmed:core/models/byok/runtime.ts:42-56—customModelwithcontextWindow: 0andmaxTokens: 4_096at:55;core/agent/definition.ts:31-38—streamFnpasses nomaxTokens;messages.ts:74-75— the limit notice;compaction.ts:101-111— themodel.maxTokensclamp and the failed-summary throw.Sensor incident — verify reported ✓ spuriously; this issue is NOT implemented. Cause: the sensor runs the Verification block as a bash script under
set -e, and a command whose status is inverted with!neither triggers errexit nor survives as the script's exit status — the matching grep's failure was silently overwritten by the passing test/check commands after it. The cap stands atruntime.ts:55.Verification-block edit logged (only the fence's first line changed, per the review playbook):
Same intent, sensor-compatible, and scoped to the deliverable site (a repo-wide pattern would stay hostage to unrelated literals such as
features/assistant/vision.ts:35'smaxTokens: 4096). Re-lint ✓; verify now correctly ✗ on main.Duplicate check (open + closed titles): none.
Sharpening carried (unchanged): pi-ai's
Model.maxTokensis type-required and per-request omission falls back to it, so "send none" is not a reachable branch — the realistic shapes are a generous finite ceiling or a reader-visible field; prefer outcome anchors (acustomModelceiling test, the compaction clamp following it) over the string grep when implementing.Verdict: valid, keep open.