From 68332e94d5e0b78b1535d6b5c8f052784c98b72b Mon Sep 17 00:00:00 2001 From: JazMaybe Date: Fri, 27 Nov 2026 16:10:08 +0800 Subject: [PATCH 1/6] fix(composer): keep the reasoning mode separate from this turn's effort - Existing chats can select Auto again: choosing it sends set_thinking_level, so the session really switches instead of only redrawing the picker. - The picker's selected mode is no longer overwritten by this turn's effort, by another tab's change, or by a stale readback; a mode no session recorded stays unknown instead of looking like a fixed level. - An earlier branch shows its recorded mode and cannot steer the live session; returning to the current native tip restores control. - A draft that creates its runtime before the first prompt reads the confirmed mode on first attach, and a mode chosen while creation is in flight reaches that runtime. - set_thinking_level and cycle_thinking_level share a bounded acknowledgement wait (504 thinking_level_timeout) without retrying or replacing the session. - The wide picker no longer caps its label at 100px. Verification: npm run typecheck; npm run build; bun test hooks/useAgentSession.rpc.test.mjs (358 pass); components/ChatInput.reasoning.test.mjs + lib/session-reader.test.mjs + lib/agent-command.test.mjs (99 pass, 1 skip); eslint on the changed files is clean. Full suite on this tree: 5093 tests, 4916 pass, 162 skip, 15 fail, of which 13 also fail on 4be697c4; the other two appeared only in this run and pass 3/3 when run alone (one of them also passed four rounds under 32-way CPU load). --- CHANGELOG.md | 1 + app/api/sessions/[id]/route.ts | 2 + app/globals.css | 5 +- components/ChatInput.fullscreen.test.mjs | 2 +- components/ChatInput.reasoning.test.mjs | 63 +++ components/ChatInput.test.mjs | 4 +- components/ChatInput.tsx | 50 ++- components/ChatWindow.tsx | 7 +- hooks/useAgentSession-stream.ts | 11 +- hooks/useAgentSession.rpc.test.mjs | 476 ++++++++++++++++++++++- hooks/useAgentSession.ts | 239 +++++++++--- lib/agent-command.test.mjs | 48 +++ lib/agent-command.ts | 6 +- lib/hosts/session-ops.ts | 4 + lib/i18n/locales/en.json | 6 + lib/i18n/locales/ja.json | 6 + lib/i18n/locales/zh-CN.json | 6 + lib/i18n/locales/zh-TW.json | 6 + lib/omp/auth-broker.test.mjs | 4 +- lib/pi-types.ts | 4 + lib/rpc-manager.ts | 21 +- lib/session-reader.test.mjs | 71 +++- lib/session-reader.ts | 45 ++- lib/session-routes.test.mjs | 22 +- lib/types.ts | 5 + 25 files changed, 994 insertions(+), 120 deletions(-) create mode 100644 components/ChatInput.reasoning.test.mjs diff --git a/CHANGELOG.md b/CHANGELOG.md index 860deda7f..ce5b0dcde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ All notable changes to **omp-web** (`@kahme247/ompweb`) are documented in this f ### Fixed +- **Switch an existing chat back to Auto reasoning.** The composer shows the selected mode separately from this turn's effort, follows changes made in another tab, and restores the mode when you reopen the chat. Viewing an earlier branch shows its recorded mode without changing the live session. Older sessions without a recorded mode no longer appear to have selected a fixed level. - **Horizontal scrollbars no longer clip file-panel tabs.** The tab row keeps its full height in narrow panels, including on mobile. - **Refreshing Usage applies changed prices, and says when it fails.** Prices edited in `models.yml` now apply to existing sessions on refresh; they used to keep the old prices until the web server restarted. A refresh that fails now shows the error above the last report instead of leaving it up without a word. - **Show the generation-speed pill in the top bar again.** Since the header opener was split from the file-panel close control, the pill's box sized to zero width and its narrow-header rule hid it on every screen; it now keeps its width. Phone-width screens still hide it. diff --git a/app/api/sessions/[id]/route.ts b/app/api/sessions/[id]/route.ts index eebaba262..ff9ba16d1 100644 --- a/app/api/sessions/[id]/route.ts +++ b/app/api/sessions/[id]/route.ts @@ -68,6 +68,8 @@ function navigationShape(value: SessionReadValue): SessionReadValue { ...value.info, model: value.context.model, thinkingLevel: value.context.thinkingLevel, + observedThinkingLevel: value.context.observedThinkingLevel, + configuredThinkingLevel: value.context.configuredThinkingLevel, }, context: null, }; diff --git a/app/globals.css b/app/globals.css index 4d9954a33..1e4fc27c9 100644 --- a/app/globals.css +++ b/app/globals.css @@ -2258,7 +2258,6 @@ html[data-touch-targets="accessible"] :is(.image-lightbox-stepper button, .image .composer-thinking-control { flex: 0 1 auto; min-width: 24px !important; - max-width: 100px; } .composer-thinking-glyph { display: inline-flex; @@ -2351,7 +2350,7 @@ html[data-touch-targets="accessible"] :is(.image-lightbox-stepper button, .image } @container (max-width: 400px) { .composer-thinking-control > button > svg, - .composer-thinking-glyph[data-level] + .composer-thinking-label, + .composer-thinking-glyph + .composer-thinking-label, .composer-fast-control > span, .composer-slow-control > span { display: none; @@ -2402,7 +2401,7 @@ html[data-touch-targets="accessible"] :is(.image-lightbox-stepper button, .image max-width: 28px; } .composer-thinking-control > button > svg, - .composer-thinking-glyph[data-level] + .composer-thinking-label { + .composer-thinking-glyph + .composer-thinking-label { display: none; } .composer-thinking-control > button > .composer-thinking-glyph { diff --git a/components/ChatInput.fullscreen.test.mjs b/components/ChatInput.fullscreen.test.mjs index d065c0c3e..d6ab98287 100644 --- a/components/ChatInput.fullscreen.test.mjs +++ b/components/ChatInput.fullscreen.test.mjs @@ -24,7 +24,7 @@ async function renderComposer(t, props = {}) { const view = render(React.createElement(ChatInput, { async onSend(message) { sent.push(message); return { status: "accepted" }; }, onThinkingLevelChange() {}, - thinkingLevel: "auto", + configuredThinkingLevel: "auto", isStreaming: false, ...props, })); diff --git a/components/ChatInput.reasoning.test.mjs b/components/ChatInput.reasoning.test.mjs new file mode 100644 index 000000000..c1d11f901 --- /dev/null +++ b/components/ChatInput.reasoning.test.mjs @@ -0,0 +1,63 @@ +import assert from "node:assert/strict"; +import "../tests/setup-dom.mjs"; +import test from "node:test"; +import React from "react"; +import { cleanup, fireEvent, render } from "@testing-library/react/pure.js"; +import { ChatInput } from "./ChatInput.tsx"; + +window.matchMedia = globalThis.matchMedia; + +for (const [configuredThinkingLevel, observedThinkingLevel, label] of [ + ["auto", "low", "Auto (this turn: low)"], + ["auto", undefined, "Auto"], + ["low", "low", "Fixed: low"], + [undefined, "low", "Level: low"], + [undefined, undefined, "Thinking level"], +]) { + test(`reasoning picker: ${label}`, (t) => { + t.after(cleanup); + const changes = []; + const view = render(React.createElement(ChatInput, { + onSend() {}, isStreaming: false, configuredThinkingLevel, observedThinkingLevel, + onThinkingLevelChange: level => changes.push(level), + })); + const trigger = view.container.querySelector(".composer-thinking-control > button"); + if (!configuredThinkingLevel && !observedThinkingLevel) { + assert.ok(trigger.querySelector('.composer-thinking-glyph[aria-hidden="true"] svg'), "compact picker needs a neutral glyph"); + } + assert.equal(trigger.textContent, label); + assert.ok(trigger.getAttribute("aria-label").endsWith(label)); + fireEvent.click(trigger); + assert.deepEqual(view.queryAllByRole("menuitemradio", { checked: true }).map(row => row.textContent), + configuredThinkingLevel ? [configuredThinkingLevel === "auto" ? "Auto" : configuredThinkingLevel] : []); + fireEvent.click(view.getByRole("menuitemradio", { name: "low" })); + assert.deepEqual(changes, configuredThinkingLevel === "low" ? [] : ["low"]); + }); +} + +for (const locked of ["thinkingLevelDisabled", "isStreaming"]) { + test(`reasoning picker cannot submit while ${locked}`, (t) => { + t.after(cleanup); + const view = render(React.createElement(ChatInput, { onSend() {}, onThinkingLevelChange() {}, [locked]: true })); + assert.equal(view.container.querySelector(".composer-thinking-control > button").disabled, true); + }); +} + +for (const [mode, observed, useDraftThinkingDefault, label, selected] of [ + ["medium", "low", false, "Fixed: medium", "medium → low"], + ["auto", "low", false, "Auto (this turn: low)", "Auto"], + [undefined, "low", false, "Level: low", undefined], + ["auto", undefined, true, "Use omp default", "Use omp default"], +]) { + test(`model mapping and draft semantics: ${label}`, (t) => { + t.after(cleanup); + const view = render(React.createElement(ChatInput, { + onSend() {}, onThinkingLevelChange() {}, configuredThinkingLevel: mode, observedThinkingLevel: observed, + useDraftThinkingDefault, thinkingLevelMap: { medium: "low", low: "minimal" }, + })); + const trigger = view.container.querySelector(".composer-thinking-control > button"); + assert.equal(trigger.textContent, label); + fireEvent.click(trigger); + assert.deepEqual(view.queryAllByRole("menuitemradio", { checked: true }).map(row => row.textContent), selected ? [selected] : []); + }); +} diff --git a/components/ChatInput.test.mjs b/components/ChatInput.test.mjs index f5847700c..d18b84fa0 100644 --- a/components/ChatInput.test.mjs +++ b/components/ChatInput.test.mjs @@ -12,13 +12,13 @@ test("provider-defined reasoning levels appear once in the trigger", () => { const html = renderToStaticMarkup(React.createElement(ChatInput, { async onSend() { return { status: "accepted" }; }, onThinkingLevelChange() {}, - thinkingLevel, + configuredThinkingLevel: thinkingLevel, isStreaming: false, })); const dom = new JSDOM(html); try { const trigger = dom.window.document.querySelector(".composer-thinking-control > button"); - assert.equal(trigger.textContent, thinkingLevel); + assert.equal(trigger.textContent, `Fixed: ${thinkingLevel}`); assert.ok(trigger.getAttribute("aria-label").endsWith(`: ${thinkingLevel}`)); } finally { dom.window.close(); diff --git a/components/ChatInput.tsx b/components/ChatInput.tsx index 719af6332..53c7ebfb4 100644 --- a/components/ChatInput.tsx +++ b/components/ChatInput.tsx @@ -2,7 +2,7 @@ import React, { useRef, useState, useCallback, useEffect, useLayoutEffect, useImperativeHandle, forwardRef, memo, KeyboardEvent } from "react"; import { createPortal } from "react-dom"; -import { ChevronDown, ClipboardPaste, CornerDownRight, ListChecks, Loader2, Maximize2, Mic, Paperclip, Plus, RotateCw, Shrink, Snail, Sparkles, Terminal, Wrench, X, Zap } from "lucide-react"; +import { Brain, ChevronDown, ClipboardPaste, CornerDownRight, ListChecks, Loader2, Maximize2, Mic, Paperclip, Plus, RotateCw, Shrink, Snail, Sparkles, Terminal, Wrench, X, Zap } from "lucide-react"; import { getSubmitDuringRunBehavior, isWordCompletionEnabled } from "@/lib/composer-prefs"; import type { BuiltinSlashCommandResult, CompactResultInfo, PromptSendOptions, PromptSubmissionResult, QueuedMessages, SlashCommandInfo } from "@/hooks/useAgentSession"; import type { ActiveGoal, ActivePlan } from "@/lib/web-mode-state"; @@ -215,7 +215,10 @@ interface Props { onAbortCompaction?: () => void; isCompacting?: boolean; compactResult?: CompactResultInfo | null; - thinkingLevel?: string; + configuredThinkingLevel?: string; + observedThinkingLevel?: string; + thinkingLevelDisabled?: boolean; + useDraftThinkingDefault?: boolean; onThinkingLevelChange?: (level: string) => void; availableThinkingLevels?: string[] | null; thinkingLevelMap?: Record | null; @@ -373,7 +376,7 @@ function menuDropStyle(placement: MenuPlacement, maxHeight: number | null): Reac export const ChatInput = memo(forwardRef(function ChatInput({ onSend, onPredictWord, onPredictWordFeedback, onAbort, onSteer, onFollowUp, isStreaming, model, isAutoModelSelection, modelNames, modelList, modelError, modelsLoading, onModelChange, fastModeEnabled, fastModeActive, usageLimit, fastModeSupported, onFastModeChange, slowModeSupported, slowModeEnabled, slowModeScope, onSlowModeChange, onAbortCompaction, isCompacting, compactResult, - thinkingLevel, onThinkingLevelChange, availableThinkingLevels, thinkingLevelMap, modelNameOverride, + configuredThinkingLevel, observedThinkingLevel, thinkingLevelDisabled, useDraftThinkingDefault, onThinkingLevelChange, availableThinkingLevels, thinkingLevelMap, modelNameOverride, toolPreset, onToolPresetChange, sessionToolPreset, isNewSession, retryInfo, queuedMessages, inputHistory = [], onAbortRetry, slashCommands, slashCommandsLoading, onLoadSlashCommands, @@ -2301,21 +2304,26 @@ export const ChatInput = memo(forwardRef(function ChatIn const activeToolCount = getToolPresetToolCount(activeToolPreset); const toolsetBadgeLabel = `tools: ${activeToolPreset}${activeToolCount === null ? "" : ` (${activeToolCount})`}`; const restrictedToolPreset = toolPresetKnown && activeToolPreset !== "full" ? activeToolPreset : null; + const thinkingDisabled = isStreaming || !!thinkingLevelDisabled; + const autoOptionLabel = useDraftThinkingDefault ? t("chatInput.thinkingAuto") : t("chatInput.reasoningAuto"); const thinkingDisplayLabel = (() => { - const lvl = thinkingLevel ?? "auto"; - if (lvl === "auto" || !thinkingLevelMap) return lvl; - return thinkingLevelMap[lvl] ?? lvl; + if (configuredThinkingLevel === "auto") { + return observedThinkingLevel && observedThinkingLevel !== "auto" + ? t("chatInput.reasoningAutoTurn", { level: observedThinkingLevel }) + : autoOptionLabel; + } + if (configuredThinkingLevel) return t("chatInput.reasoningFixed", { level: configuredThinkingLevel }); + if (observedThinkingLevel) return t("chatInput.reasoningLevel", { level: observedThinkingLevel }); + return t("chatInput.reasoningUnknown"); })(); const thinkingLevelOptions = React.useMemo( () => selectableThinkingLevels(availableThinkingLevels), [availableThinkingLevels], ); - // A run starting mid-interaction must not leave the reasoning menu - // open: the level only applies to the next prompt, and the trigger is - // disabled while streaming. + // A run or a pending change can lock an already open picker. useEffect(() => { - if (isStreaming) setThinkingDropdownOpen(false); - }, [isStreaming]); + if (thinkingDisabled) setThinkingDropdownOpen(false); + }, [thinkingDisabled]); useEffect(() => { if (!modelDropdownOpen) { @@ -3681,7 +3689,7 @@ export const ChatInput = memo(forwardRef(function ChatIn
@@ -3734,9 +3744,9 @@ export const ChatInput = memo(forwardRef(function ChatIn
{thinkingLevelOptions.map((lvl) => { - const isActive = (thinkingLevel ?? "auto") === lvl; - const mappedVal = (lvl !== "auto" && thinkingLevelMap) ? thinkingLevelMap[lvl] : undefined; - const displayLabel = (mappedVal != null && mappedVal !== lvl) ? mappedVal : lvl; + const isActive = configuredThinkingLevel === lvl; + const mapped = thinkingLevelMap && Object.hasOwn(thinkingLevelMap, lvl) ? thinkingLevelMap[lvl] : undefined; + const displayLabel = lvl === "auto" ? autoOptionLabel : mapped && mapped !== lvl ? `${lvl} → ${mapped}` : lvl; return (