Skip to content

Recover a custom endpoint's context overflow like every other model's — the compact-and-continue rescue is gated on a context window no reader-added service has, so its long conversations dead-end in re-sends #285

Open

Description

@bencode

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:

  • compactBeforeSending never 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's isContextOverflow recognizes 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 whenever isContextOverflow matches the failed reply, independent of autoCompactionEnabled and 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

Activity

  1. added
    enhancement
    source:scheduled
    on Oct 28, 2026
  2. bencode commented on Oct 29, 2026

    @bencode
    OwnerAuthor

    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. Note needsCompaction (compaction.ts:161-163) carries the same predicate, so compactBeforeSending (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 — recoverFromOverflow returns at the first guard condition; the isContextOverflow check it never reaches is text-based (pi-ai OVERFLOW_PATTERNS: Anthropic, OpenAI-compatible, Ollama, LM Studio, MiniMax, DashScope/Qwen, and more), so the premise — the vendor's refusal alone is enough evidence — holds.
    • Dead end and surface: use-conversation/run.ts:85,101-104; token line with no ceiling at use-conversation/index.ts:88 (contextWindow || undefined) and composer/token-usage-status.tsx:13-15; manual /compact still offered at conversation-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):

    pnpm --filter @gamma-reader/web test --silent src/features/conversation/use-conversation/controller.test.ts -t "custom endpoint"
    pnpm check

    with the new case in use-conversation/controller.test.ts — where recoverFromOverflow is already tested — titled to match, e.g. recovers a custom-endpoint context overflow with no known window. Vitest exits non-zero when -t matches no test, which turns the gate into a real outcome anchor.

  3. bencode commented on Nov 1, 2026

    @bencode
    OwnerAuthor

    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 is autoCompactionEnabled(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 as maximumThreshold), identical to a 128k window's 40k. The body's arithmetic is exact.
    • pi-ai 1.2.0 OVERFLOW_PATTERNS is 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:

    1. pnpm … test --silent <file> -t … crashes: vitest 5 parses --silent fused with the following positional (TypeError: Unexpected value "--silent=<file>"), so it fails for the wrong reason even after implementation.
    2. Without --silent, vitest 5 with -t matching nothing exits 0 ("1 skipped") — the -t gate 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 on use-conversation, then pnpm check. Everything outside the block is untouched.

    Sharpening for the implementer:

    • The defect is pinned by a live assertion: it.each([0, 32_000, 127_999])('does not automatically compact or recover a %i window') (controller.test.ts:106-122) asserts window 0 ends failed: true with no retry. Window 0 must leave that list; that test turning is the honest diff marker.
    • Decide the small-window story explicitly: "independent of 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 keeps min(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.
  4. bencode commented on Nov 6, 2026

    @bencode
    OwnerAuthor

    Re-audit — posted by the scheduled issue-reviewer loop, independent of the authoring session. Third pass; main is still d05b6b6 (pulled today, "Already up to date"), so nothing can have moved — anchors re-opened fresh regardless.

  5. bencode commented on Nov 9, 2026

    @bencode
    OwnerAuthor

    Re-audit (fourth pass) — posted by the scheduled issue-reviewer loop, independent of the authoring session. main is still d05b6b6 ("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 (needsCompaction gate) and the recovery guard whose first condition is !autoCompactionEnabled(...) before isContextOverflow is 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 at controller.test.ts:107 (span 106-122 as cited). Verdict: valid, keep open (unchanged).

    Checks new this pass:

    Standing sharpenings unchanged after four passes: window 0 leaving the it.each list 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.

  6. bencode commented on Nov 11, 2026

    @bencode
    OwnerAuthor

    Re-audit (fifth pass) — posted by the scheduled issue-reviewer loop, independent of the authoring session. main is still d05b6b6 ("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' at controller.test.ts:107 (span 106-122). Verdict: valid, keep open (unchanged).

    Checks new this pass:

    Standing sharpenings unchanged after five passes: window 0 leaving the it.each list 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementsource:scheduled

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions