bugfix: remove redundant thinking updates and put a thinking timer above the prompt instead (#216)
I had Codex read #182 and draft a PR to fix it. This is its suggested approach. I've tested it and it works. It removes the purple `thinking for 386s` type lines entirely, and replaces them with a single yellow `thinking for #s` line: ``` thinking for 31s ╭────────────────────────────────────────╮ │( ● ) Thinking.. ╰────────────────────────────────────────╯ ``` prompt. I've been using it that way via `npm run dev`, and prefer it. ## What Empty "reasoning" updates were showing up as blank lines in the terminal chat history. We now short-circuit and return `null` whenever `message.summary` is empty, so those no-ops are suppressed. ## How - In `TerminalChatResponseReasoning`, return early if `message.summary` is falsy or empty. - In `TerminalMessageHistory`, drop any reasoning items whose `summary.length === 0`. - Swapped out the loose `any` cast for a safer `unknown`-based cast. - Rolled back the temporary Vitest script hacks that were causing stack overflows. ## Why Cluttering the chat with empty lines was confusing; this change ensures only real reasoning text is rendered. Reference: openai/codex#182 --------- Co-authored-by: Thibault Sottiaux <tibo@openai.com>
This commit is contained in:
@@ -72,30 +72,13 @@ export function TerminalChatResponseReasoning({
|
|||||||
}: {
|
}: {
|
||||||
message: ResponseReasoningItem & { duration_ms?: number };
|
message: ResponseReasoningItem & { duration_ms?: number };
|
||||||
}): React.ReactElement | null {
|
}): React.ReactElement | null {
|
||||||
// prefer the real duration if present
|
// Only render when there is a reasoning summary
|
||||||
const thinkingTime = message.duration_ms
|
if (!message.summary || message.summary.length === 0) {
|
||||||
? Math.round(message.duration_ms / 1000)
|
|
||||||
: Math.max(
|
|
||||||
1,
|
|
||||||
Math.ceil(
|
|
||||||
(message.summary || [])
|
|
||||||
.map((t) => t.text.length)
|
|
||||||
.reduce((a, b) => a + b, 0) / 300,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
if (thinkingTime <= 0) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box gap={1} flexDirection="column">
|
<Box gap={1} flexDirection="column">
|
||||||
<Box gap={1}>
|
{message.summary.map((summary, key) => {
|
||||||
<Text bold color="magenta">
|
|
||||||
thinking
|
|
||||||
</Text>
|
|
||||||
<Text dimColor>for {thinkingTime}s</Text>
|
|
||||||
</Box>
|
|
||||||
{message.summary?.map((summary, key) => {
|
|
||||||
const s = summary as { headline?: string; text: string };
|
const s = summary as { headline?: string; text: string };
|
||||||
return (
|
return (
|
||||||
<Box key={key} flexDirection="column">
|
<Box key={key} flexDirection="column">
|
||||||
|
|||||||
@@ -30,16 +30,14 @@ const MessageHistory: React.FC<MessageHistoryProps> = ({
|
|||||||
thinkingSeconds,
|
thinkingSeconds,
|
||||||
fullStdout,
|
fullStdout,
|
||||||
}) => {
|
}) => {
|
||||||
const [messages, debug] = useMemo(
|
// Flatten batch entries to response items.
|
||||||
() => [batch.map(({ item }) => item!), process.env["DEBUG"]],
|
const messages = useMemo(() => batch.map(({ item }) => item!), [batch]);
|
||||||
[batch],
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box flexDirection="column">
|
<Box flexDirection="column">
|
||||||
{loading && debug && (
|
{loading && (
|
||||||
<Box marginTop={1}>
|
<Box marginTop={1}>
|
||||||
<Text color="yellow">{`(${thinkingSeconds}s)`}</Text>
|
<Text color="yellow">{`thinking for ${thinkingSeconds}s`}</Text>
|
||||||
</Box>
|
</Box>
|
||||||
)}
|
)}
|
||||||
<Static items={["header", ...messages]}>
|
<Static items={["header", ...messages]}>
|
||||||
@@ -48,8 +46,13 @@ const MessageHistory: React.FC<MessageHistoryProps> = ({
|
|||||||
return <TerminalHeader key="header" {...headerProps} />;
|
return <TerminalHeader key="header" {...headerProps} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
// After the guard above `item` can only be a ResponseItem.
|
// After the guard above, item is a ResponseItem
|
||||||
const message = item as ResponseItem;
|
const message = item as ResponseItem;
|
||||||
|
// Suppress empty reasoning updates (i.e. items with an empty summary).
|
||||||
|
const msg = message as unknown as { summary?: Array<unknown> };
|
||||||
|
if (msg.summary?.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
key={`${message.id}-${index}`}
|
key={`${message.id}-${index}`}
|
||||||
|
|||||||
Reference in New Issue
Block a user