Repository navigation
Description
Problem
A reader who adds "Another OpenAI-compatible service…" (Qwen's compatible mode, MiniMax, SiliconFlow, an ollama or LM Studio endpoint, a company relay) loses the app's entire long-conversation protection, silently, on exactly the path PRODUCT.md keeps "open, not hidden".
Every model on such a service is built by customModel with contextWindow: 0 — unknown (ui-packages/web/src/core/models/byok/runtime.ts:42-57). The context machinery is gated on knowing a window: autoCompactionEnabled = contextWindow >= 128_000 (ui-packages/web/src/core/agent/compaction.ts:49). For a custom model that gate is always false, so:
compactBeforeSendingnever compacts before a send (ui-packages/web/src/features/conversation/use-conversation/compaction.ts:73).recoverFromOverflow— the built-in rescue that answers a refused reply by summarizing once and continuing — returns before it checks anything (.../use-conversation/compaction.ts:87), even though pi-ai'sisContextOverflowrecognizes an overflow from the vendor's error text alone (Case 1 patterns: "exceeds the model's maximum context length", "prompt too long", Ollama, LM Studio, MiniMax, DashScope…; the window parameter is only needed for silent-overflow detection).- The token line under the message box shows the context count with no ceiling to read it against (
.../use-conversation/index.ts:88,.../conversation/token-usage.ts:15-16,.../composer/token-usage-status.tsx:13-15).
So the conversation grows until the first over-window send fails with the vendor's sentence (readable since #228), the draft is restored, and the reader re-sends into the same wall (.../use-conversation/run.ts:85,101-104). The manual /compact command still works on these models (.../conversation/conversation-panel.tsx:72-75) but nothing points to it. Every free-allowance and preset own-key model knows its window (deepseek/glm 1M, gpt-4.1 1M in pi's catalog), so the rescue runs everywhere except the custom path — the same path #199 already found silently handicapped.
Proposal
- In
recoverFromOverflow, run the rescue wheneverisContextOverflowmatches the failed reply, independent ofautoCompactionEnabledand of window knowledge — the vendor's refusal is the evidence; with no window,keepRecentFor(0)keeps the same 40k tokens a 128k-window model keeps. - Optionally, for small-window services the pattern rescue alone is not enough (40k kept can still overflow an 8k model): let the reader state the endpoint's context window in the provider dialog, custom services only, which also gives the token line its ceiling and turns on pre-send compaction.
Goal
After this, a reader on their own OpenAI-compatible endpoint whose conversation outgrows the model gets the same rescue as on the free allowance: the refused reply is answered by one summarization and the answer continues, instead of a dead end only /compact escapes; no custom-endpoint conversation ends in re-sends against the same wall.
Verification
grep -q "custom endpoint" ui-packages/web/src/features/conversation/use-conversation/controller.test.ts
pnpm --filter @gamma-reader/web test src/features/conversation/use-conversation
pnpm check(the case lives in controller.test.ts's conversation compaction describe, titled to contain "custom endpoint" — e.g. recovers a custom endpoint overflow with no known window — asserting that a reply on a contextWindow: 0 model failing with a recognized overflow error triggers the summarize-and-continue recovery; the grep is the title contract and fails until the case exists, the suite run is the outcome. The existing it.each([0, 32_000, 127_999]) currently asserts the opposite for window 0 and must turn with the fix)
Refs
- ui-packages/web/src/core/models/byok/runtime.ts:42-57 —
customModelsetscontextWindow: 0, documented as unknown - ui-packages/web/src/core/agent/compaction.ts:49 —
autoCompactionEnabledrequires>= 128_000 - ui-packages/web/src/features/conversation/use-conversation/compaction.ts:73,84-101 — pre-send and post-overflow paths both gated off at window 0
- ui-packages/web/src/features/conversation/use-conversation/run.ts:85,101-104 — where the rescue would run, and the dead end without it
- ui-packages/web/src/features/conversation/composer/token-usage-status.tsx:13-15 — context shown with no ceiling
- @earendil-works/pi-ai
utils/overflow.js— overflow detection by error text needs no window - 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 this machinery answers; this extends it to the one model population it is switched off for
- Let a custom endpoint answer past 4,096 tokens — every model added as 'Another OpenAI-compatible service' is hard-capped at 32–94× under the free allowance today, and nothing shows or lifts the ceiling #199 — the sibling custom-endpoint handicap (output ceiling); it explicitly left
contextWindow: 0as-is - Say a failed own-key reply in reader language — the notice shows the vendor's raw JSON error body today #228 — why the reader at least sees the vendor's sentence at the wall
Activity
bencode commentedon Oct 29, 2026
Posted by the scheduled issue-reviewer loop, independent of the authoring session.
Audit at d05b6b6 — valid, stays open. One verification hazard flagged below.
Evidence check — every anchor verified:
ui-packages/web/src/core/models/byok/runtime.ts:54—contextWindow: 0, commented "Unknown. Pi reads 0 as no known window".ui-packages/web/src/core/agent/compaction.ts:49—autoCompactionEnabled = contextWindow >= 128_000. NoteneedsCompaction(compaction.ts:161-163) carries the same predicate, socompactBeforeSending(use-conversation/compaction.ts:73) is a no-op at window 0 as well — both gates are as described.use-conversation/compaction.ts:84-92—recoverFromOverflowreturns at the first guard condition; theisContextOverflowcheck it never reaches is text-based (pi-aiOVERFLOW_PATTERNS: Anthropic, OpenAI-compatible, Ollama, LM Studio, MiniMax, DashScope/Qwen, and more), so the premise — the vendor's refusal alone is enough evidence — holds.use-conversation/run.ts:85,101-104; token line with no ceiling atuse-conversation/index.ts:88(contextWindow || undefined) andcomposer/token-usage-status.tsx:13-15; manual/compactstill offered atconversation-panel.tsx:72-75.Duplicate check (open + closed): none — #199 (output ceiling) and #70 (the original wall) are referenced as siblings, not overlaps.
Sensor: lint ✓; verify ✓ — but the verify pass is vacuous: both commands (existing suite,
pnpm check) pass on main today because the new recovery case does not exist yet. As written, this Verification block cannot distinguish implemented from not-implemented; no future reader of this loop should treat verify-pass here as an implemented signal until the block is tightened.Suggested tightening (copy-pasteable, fails on main until the behavior lands):
with the new case in
use-conversation/controller.test.ts— whererecoverFromOverflowis already tested — titled to match, e.g. recovers a custom-endpoint context overflow with no known window. Vitest exits non-zero when-tmatches no test, which turns the gate into a real outcome anchor.bencode commentedon Nov 1, 2026
Posted by the scheduled issue-reviewer loop, independent of the authoring session.
Re-audit at d05b6b6 (HEAD unchanged since the last review) — valid, stays open. Verification block repaired (edit logged below).
Premise re-checked, holds exactly:
recoverFromOverflow's first guard isautoCompactionEnabled(contextWindow)(use-conversation/compaction.ts:87) — window 0 exits before anything else runs.keepRecentFor(0) = min(40_000, 0.4 × compactionThreshold(0)) = 40_000(core/agent/compaction.ts:48-52— threshold(0) is already defined asmaximumThreshold), identical to a 128k window's 40k. The body's arithmetic is exact.OVERFLOW_PATTERNSis pure error-text regex (Anthropic, OpenAI-compatible, Ollama, LM Studio, MiniMax, DashScope…); the window argument only serves the silent-overflow cases.isContextOverflow(last, 0)matches a vendor's explicit refusal.Correction to my previous comment — its suggested gate was unusable twice over, now verified on this checkout:
pnpm … test --silent <file> -t …crashes: vitest 5 parses--silentfused with the following positional (TypeError: Unexpected value "--silent=<file>"), so it fails for the wrong reason even after implementation.--silent, vitest 5 with-tmatching nothing exits 0 ("1 skipped") — the-tgate would have been exactly as vacuous as the block it replaced.Body edit (Verification block only, re-linted ✓): first command is now
grep -q "custom endpoint" …/controller.test.ts(title contract, fails on main today — verify correctly ✗ now), then the suite onuse-conversation, thenpnpm check. Everything outside the block is untouched.Sharpening for the implementer:
it.each([0, 32_000, 127_999])('does not automatically compact or recover a %i window')(controller.test.ts:106-122) asserts window 0 endsfailed: truewith no retry. Window 0 must leave that list; that test turning is the honest diff marker.autoCompactionEnabled" as written also flips known 32k/127_999 windows. Gate "window unknown (0) OR ≥128k" keeps them silent; pattern-rescue-for-all is also defensible (a known 32k window keepsmin(40_000, 0.4×16_384) ≈ 6.5k, so the retry is not auto-doomed). Pick one, name the test so the choice is readable.bencode commentedon Nov 6, 2026
Re-audit — posted by the scheduled issue-reviewer loop, independent of the authoring session. Third pass;
mainis stilld05b6b6(pulled today, "Already up to date"), so nothing can have moved — anchors re-opened fresh regardless.runtime.ts:42-57(contextWindow: 0, "Unknown. Pi reads 0 as no known window");core/agent/compaction.ts:49(>= 128_000);use-conversation/compaction.ts:73(needsCompactiongate) andrecoverFromOverflowat:81-101(first guard!autoCompactionEnabled(...)returns beforeisContextOverflowis ever consulted);run.ts:85(rescue call afteragent.prompt) and:101-104(restoreToDraft— the re-send wall);composer/token-usage-status.tsx:13-15(ceiling ternary). The live counter-assertionit.each([0, 32_000, 127_999])('does not automatically compact or recover a %i window')still sits atcontroller.test.ts:106-122, asserting window 0 endsfailed: truewith exactly one request — the diff marker both prior reviews named.use-conversation/index.tsx:88; the file isindex.tsand the line is now:89(tokenUsage: … contextWindow || undefined). Content claim intact; the Verification block does not cite this path, so no body edit.contextWindow: 0alone.grep -q "custom endpoint" controller.test.tsexits 1 (0 matches), the title contract this loop added on 11-01 working as designed.it.eachlist (that test turning is the proof), and the implementer must choose the small-window story — rescue-for-unknown-0-only vs pattern-rescue-for-all, 32k/127_999 behavior differing between them — and name the new test so the choice is readable.bencode commentedon Nov 9, 2026
Re-audit (fourth pass) — posted by the scheduled issue-reviewer loop, independent of the authoring session.
mainis stilld05b6b6("Already up to date"), so nothing can have moved; anchors re-opened regardless —runtime.ts:54(contextWindow: 0),core/agent/compaction.ts:49(>= 128_000),use-conversation/compaction.ts:73(needsCompactiongate) and the recovery guard whose first condition is!autoCompactionEnabled(...)beforeisContextOverflowis ever consulted,run.ts:85,101-104,index.ts:89(the cosmetic drift already on record), and the live counter-assertion'does not automatically compact or recover a %i window'now atcontroller.test.ts:107(span 106-122 as cited). Verdict: valid, keep open (unchanged).Checks new this pass:
byok/runtime.ts— nothing in flight implements this.grep -q "custom endpoint" controller.test.tsre-run by hand: 0 matches, the title contract added on 11-01 still red as designed.Standing sharpenings unchanged after four passes: window 0 leaving the
it.eachlist is the honest diff marker, and the implementer must pick the small-window story (rescue-for-unknown-0 vs pattern-rescue-for-all) and name the test so the choice is readable.bencode commentedon Nov 11, 2026
Re-audit (fifth pass) — posted by the scheduled issue-reviewer loop, independent of the authoring session.
mainis stilld05b6b6("Already up to date"); anchors re-opened fresh —runtime.ts:54(contextWindow: 0),core/agent/compaction.ts:49(>= 128_000), and the live counter-assertion'does not automatically compact or recover a %i window'atcontroller.test.ts:107(span 106-122). Verdict: valid, keep open (unchanged).Checks new this pass:
byok/runtime.ts. No implementation in flight.grep -q "custom endpoint" controller.test.ts) re-run by hand: 0 matches, still red as designed.Standing sharpenings unchanged after five passes: window 0 leaving the
it.eachlist is the honest diff marker; the implementer must pick the small-window story (rescue-for-unknown-0 vs pattern-rescue-for-all) and name the test so the choice is readable.