From a3adb72be48cb3f14304a1459b94f12a1873cdfc Mon Sep 17 00:00:00 2001 From: BeLazy167 Date: Fri, 21 Aug 2026 17:50:02 -0500 Subject: [PATCH] Fix the install break in write_models_tsv, and read contexts from the right surface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A fresh install from main currently FAILS (verified: exit 1, right after "default model"). Two bugs: - The row loop's last statement is `[ -n id ] && [ -n ctx ] && printf`, which returns non-zero when the final row has no context window. That makes the whole `while` non-zero and `set -e` aborts the installer. A row without a context window is normal, not an error. - write_models_tsv was fed the Anthropic surface's body (/v1/models), which publishes no context windows at all — so even without the crash every model would fall back to the hardcoded table. That table omits gpt-5.6-luna, gpt-5.6-terra, gpt-5.5 and gpt-5.3-codex, which would then inherit Claude Code's 200k assumption and re-compact on every turn: exactly the reported symptom, on exactly the model reported (luna). Now fetches the OpenAI-compat surface (/models), which carries `_qbraid.maxTokens`. Verified: install exits 0, models.tsv has all 12 correct windows (gpt-5.6-* = 1_050_000, gpt-5.4* = 400_000, claude-* = 1_000_000/200_000), and default / gpt-1M / gpt-400k sessions all answer. Also confirms the [1m] suffix is safe: Claude Code strips it before the request, so the gateway never sees claude-sonnet-4-6[1m] (which it 404s). --- install.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/install.sh b/install.sh index a2b2b7c..b9635b2 100755 --- a/install.sh +++ b/install.sh @@ -248,8 +248,15 @@ EOF -e 's/.*"maxTokens"[[:space:]]*:[[:space:]]*\([0-9][0-9]*\).*/\1/p' \ -e 's/.*"context_window"[[:space:]]*:[[:space:]]*\([0-9][0-9]*\).*/\1/p' \ -e 's/.*"contextWindow"[[:space:]]*:[[:space:]]*\([0-9][0-9]*\).*/\1/p' | head -1) - [ -n "$id" ] && [ -n "$context" ] && printf '%s\t%s\n' "$id" "$context" + # A row without a context window is normal (the Anthropic surface does + # not publish one), NOT an error. Without the `|| true` this compound is + # the loop's last statement, so a final context-less row made the whole + # `while` return non-zero and `set -e` aborted the installer. + if [ -n "$id" ] && [ -n "$context" ]; then + printf '%s\t%s\n' "$id" "$context" + fi || true done >> "$tmp" + true awk -F '\t' 'NF == 2 { values[$1]=$2 } END { for (id in values) print id "\t" values[id] }' "$tmp" | sort > "$dest" rm -f "$tmp" @@ -1082,6 +1089,11 @@ EOF printf '%s\n' "$PROFILE_LABEL" > "$PROFILE_DIR/label" printf '%s\n' "$PROFILE_LABEL_SOURCE" > "$PROFILE_DIR/label-source" [ -z "$ORG_ID" ] || printf '%s\n' "$ORG_ID" > "$PROFILE_DIR/organization-id" +# The Anthropic surface (/v1/models) publishes no context windows; the +# OpenAI-compat surface (/models) carries them under `_qbraid.maxTokens`. +# Fetch that one, or every GPT model falls back to Claude Code's 200k +# assumption and long sessions re-compact on every turn. +api_get "$GATEWAY_URL/models" "$API_KEY" write_models_tsv "$PROFILE_DIR/models.tsv" "${API_BODY:-}" chmod 600 "$PROFILE_DIR/env" "$PROFILE_DIR/label" "$PROFILE_DIR/models.tsv" "$PROFILE_DIR/organization-id" 2>/dev/null || true umask "$OLD_UMASK"