Skip to content

Add setting to collapse tool activity by default - #9803

Merged
danielhanchen merged 11 commits into
unslothai:mainfrom
Imagineer99:feat/collapse-tool-activity
Aug 27, 2026
Merged

danielhanchen merged 11 commits into
unslothai:mainfrom
Imagineer99:feat/collapse-tool-activity

Conversation

@Imagineer99

@Imagineer99 Imagineer99 commented Aug 26, 2026 •

Copy link
Copy Markdown
Member

Summary

  • add a persisted, opt-in Collapse tool activity by default setting under Settings → Chat
  • collapse terminal, Python, code execution, web search, knowledge search, and grouped live tool output when enabled
  • keep approval prompts visible and preserve manual expansion of collapsed tool activity

UI proof

The comparison uses the same deterministic running-tool scene and persisted preference on both sides:

  • BEFORE (5449d35ed): output visible, 320 px high; answer begins at 516.9 px
  • AFTER (50f9bdaac): output collapsed to 0 px; answer begins at 173.9 px
  • manual expansion on AFTER restores the output successfully

Before and after comparison showing tool output collapsed

Testing

  • npm test — 5,205 passed, 0 failed
  • npm run typecheck
  • npm run i18n:check
  • git diff --check

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 50f9bdaac9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +14 to +16
useEffect(() => {
if (collapseByDefault) {
setOpen(false);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve manual expansion as collapsed tools update

With the preference enabled, manually expanding a running web-search, knowledge-base, or code-execution card is only temporary: when isRunning changes on completion or hasText changes as the model resumes, this effect runs again and unconditionally closes the card. This interrupts inspection of live output and contradicts the row's manual expansion behavior; automatic closing should respond to enabling the preference or initial state without overriding a subsequent setOpen(true).

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 275daa2: manual expansion now survives live status/text updates while the preference remains enabled, with browser and unit regression coverage.

@Imagineer99

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 275daa2a36

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +66 to +68
const [uncontrolledOpen, setUncontrolledOpen] = useState(
() => defaultOpen && !collapseByDefault,
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Apply preference changes to uncontrolled tool cards

When the preference changes while a terminal or Python call is mounted, this initializer is not rerun, so uncontrolledOpen retains its previous value. Consequently, enabling the setting during a running call leaves that card expanded, while disabling it leaves a currently collapsed call closed; the web-search, knowledge-base, and code-execution cards do react immediately through useToolActivityOpen, making the setting inconsistent across the tool types it claims to control.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c019d86: mounted uncontrolled cards now synchronize when the preference changes, while manual state remains stable between preference changes. Covered by browser A/B and unit regressions.

@Imagineer99

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@Imagineer99

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: c019d86709

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Imagineer99 and others added 5 commits August 27, 2026 11:25
Collapse tool activity by default hid the thing being approved. A gated
call sits in status running, so terminal and Python cards used to be open
at exactly that moment via defaultOpen={isRunning}; with the preference on
they initialise closed instead. Radix does not mount closed content, so
the command or script is absent from the DOM rather than merely scrolled
away, while Allow / Always allow / Deny render as siblings outside the
card and stay on screen. The trigger carries only command.slice(0, 60),
with no ellipsis to say it was cut, and Always allow grants a session-wide
whitelist keyed on the tool name.

tool-group.tsx already gets this right one level up by keeping
hasPendingConfirmation outside the !collapseByDefault guard. This gives
the row the same escape hatch: a new awaitingApproval prop on
ToolFallbackRoot that pins the card open above both the preference and
open, wired from the two cards that already compute it. Once approval is
granted the pin releases and the preference takes over again.

Generic MCP cards are left alone on purpose. They pass no defaultOpen and
were already collapsed while gated, so that is a separate change rather
than a regression this PR introduced.

Measured on chromium, firefox, webkit and branded Edge: with the
preference on and a call parked, the collapsed card reports height 0 with
its payload absent from the DOM before this change, and the full command
readable after it.
ToolFallbackRoot was taught to re-derive its uncontrolled state when the
preference changes, but ToolGroupRoot kept a plain useState(defaultOpen)
and never read the preference at all. ToolGroupImpl passes open only while
it is forcing the group open and undefined the rest of the time, so that
uncontrolled state is what is on screen for most of a group's life: a
group the user expanded by hand stayed expanded when the setting was
turned on, while every card inside it closed.

Same syncToolActivityPreference treatment, so the two roots now follow one
policy. The open={forceOpen ? true : undefined} flip is untouched, and a
pending confirmation still forces the group open regardless.

Also stops latching forcedOpenRef for live output that was never shown.
Latching it while collapsed records a force nobody saw, so turning the
preference off mid-turn snapped every such group open at once. A pending
confirmation still latches, because that one is visible either way.
…namespace

settings.chat.thinking.collapseToolActivityByDefault has nothing to do
with thinking. The group is a translation namespace with no title of its
own, so nothing user-visible changes, but twelve locale files now show a
tool-activity string nested under thinking: with no context, which invites
mistranslation.

Moves it to its own settings.chat.tools group, alongside the existing
settings.chat.artifacts, and drops the redundant ToolActivity infix now
that the group carries it: settings.chat.tools.collapseByDefault, matching
settings.chat.thinking.collapseByDefault. The key is new and unshipped, so
this is free now and costs twelve files again after release.
Four of the eleven tests read their own implementation and checked for a
substring. That passes for any build containing the characters, so it
survives the feature being broken and dies on a reformat, which is the
wrong way round in both directions. Demonstrated: two mutations that kept
every searched string intact, one pinning uncontrolled cards permanently
open and one force-enabling the opt-in for every existing user on
hydration, left the whole suite green; a local rename plus a formatter
pass, which changes no behaviour at all, broke two of them.

The store is a plain .ts module, so the compatibility claim is now made
against a real hydrate: a legacy record holding every pre-PR key and no
collapseToolActivityByDefault is staged in localStorage before the import,
and the test asserts the setting comes up off, the other six preferences
survive, the setters survive, an enabled value round-trips, and an
unreadable record falls back to defaults.

The cards are .tsx and this runner cannot execute JSX, so their claims
move from substring matching to the TypeScript AST: the shape of isOpen
and forceOpen, which operand carries the approval signal, which arm reads
the preference, and where the Python script cell is rendered. Both
mutations above now fail three tests.

Rendered behaviour that no static assertion can reach gets a browser
harness instead, following the PW_ENGINE convention in
playwright_settings_tabs.py. Thirteen scenes: baseline, fresh mount,
manual expansion surviving live updates, a live toggle on mounted cards
and groups, reload persistence, scroll movement, approval visibility,
StrictMode, RTL, prefers-reduced-motion, a forty-flip toggle storm, a
localStorage that throws the way Safari private browsing does, and nine
malformed persisted records. Green on chromium, firefox, webkit and
branded Edge; ten scenes fail under the mutations above.

The scroll scene records rather than asserts. A close the preference
causes settles the page differently from a close a click causes, the same
way on all four engines, but routing the preference-driven close through
useCollapseScrollLock moves neither number, so the lock is not the
mechanism and the right target is not yet known.
@danielhanchen
danielhanchen self-requested a review as a code owner August 27, 2026 10:55
@danielhanchen

Copy link
Copy Markdown
Member

Thank you for the PR! The goal here is to let a chat that uses a lot of tools stop being mostly tool output. As a summary, this PR adds a persisted Chat setting that keeps terminal, Python, code-execution, web-search, knowledge-search and grouped tool activity collapsed, centralises the open-state transitions into two pure reducers so a manual expansion survives streaming updates, moves the Python script inside the collapsible when the setting is on, and adds the setting to Settings, search and all twelve locales.

I reviewed it, then simulated it, and pushed four commits to this branch. Details below.

Heads up on 2bf26c03d

That commit flips the default to on, ?? true, so this is no longer opt-in: every existing install starts collapsing tool activity the moment it upgrades. That is your call to make and I have not reverted it, but it changes the weight of three things that were minor while the setting was opt-in:

  • a parked allow/deny prompt now hides its command for everyone, not just for people who asked for quiet. That is what commit 1 below fixes, and it goes from nice-to-have to load-bearing.
  • the Python script, and its download button, are now behind a click by default. That reproduces the user-visible symptom of [Bug] Python code not always output in Chat #7165 for everyone. I left the behaviour alone and corrected the comment above it, which still claimed the old invariant.
  • the setting's description says "Keep tool inputs and outputs collapsed while tools run". The behaviour is not limited to while they run: completed cards in scrollback are collapsed too, and so is everything after a reload. Worth rewording now that it is the default. I did not touch the eleven translations for this.

What I pushed

Commit What
1 c48e71210 Keep an approval prompt's command and script visible
2 6cbc32841 Apply the collapse preference to mounted tool groups
3 b1dae3d2f Move the setting out of the thinking translation namespace
4 5f98e90bf Assert the preference instead of its source text

1. Approval context. A gated call sits in status: running, so defaultOpen={isRunning} used to make terminal and Python cards open at exactly the moment a decision was asked for. With the setting on they initialise closed, and Radix does not mount closed content, so the command is absent from the DOM rather than merely scrolled away. Meanwhile Allow / Always allow / Deny render as siblings outside the card and stay on screen. All the user sees is command.slice(0, 60), cut with no ellipsis to say so, and "Always allow" then grants a session-wide whitelist keyed on the tool name. tool-group.tsx already had the right shape one level up, keeping hasPendingConfirmation outside the !collapseByDefault guard; this gives the row the same escape hatch via a new awaitingApproval prop, wired from the two cards that already compute it. The pin releases once approval is granted. Generic MCP cards are untouched on purpose: they pass no defaultOpen and were already collapsed while gated, so that is a separate change rather than something this PR broke.

2. Groups. ToolFallbackRoot learned to re-derive its uncontrolled state when the preference changes, but ToolGroupRoot kept a plain useState(defaultOpen) and never read the preference. ToolGroupImpl passes open only while it is forcing the group, and undefined the rest of the time, so a group the user expanded by hand stayed expanded when the setting was turned on while every card inside it closed. Same syncToolActivityPreference treatment, so both roots now follow one policy. Also stopped latching forcedOpenRef for live output that was never shown, since a latch set while collapsed records a force nobody saw and turning the setting off mid-turn snapped every such group open at once.

3. Naming. settings.chat.thinking.collapseToolActivityByDefault has nothing to do with thinking. Nothing user-visible changes, but twelve locale files showed a tool-activity string nested under thinking: with no context. Moved to its own settings.chat.tools group next to the existing settings.chat.artifacts, dropping the now-redundant infix. Free while the key is unshipped, twelve files again afterwards.

4. Tests. Four of the eleven read their own implementation and checked for a substring. I demonstrated both failure directions rather than asserting them:

  • two mutations that kept every searched string intact, one pinning uncontrolled cards permanently open and one force-enabling the setting for every existing user on hydration, left the whole suite green at 5,758 passing;
  • a local variable rename plus a formatter pass, which changes no behaviour whatsoever, broke two of them.

The store is a plain .ts module, so the compatibility claim is now made against a real hydrate: a legacy record holding every pre-PR key is staged in localStorage before the import, and the test asserts the resulting value, that the other six preferences survive, that the setters survive, and that an unreadable record falls back to defaults. The cards are .tsx and this runner cannot execute JSX, so those claims moved from substring matching to the TypeScript AST. Both mutations now fail three tests.

Simulation

Everything below ran on the merge of this branch with current main as well as on the branch alone.

npm test        5,766 passed, 0 failed   (5,200 on the merge base, so the delta is this PR)
npm run typecheck / i18n:check / i18n:check:strict / build / bundle:check    all pass
git diff --check    clean

biome:check and lint are red, but they are red on main too and no new finding lands on a file this PR touches.

New browser harness at studio/frontend/smoke-tool-activity.html and tests/studio/playwright_tool_activity.py, following the PW_ENGINE convention already in playwright_settings_tabs.py. Thirteen scenes: baseline, fresh mount, manual expansion surviving live updates, a live toggle on mounted cards and groups, reload persistence, scroll movement, approval visibility, StrictMode, RTL, prefers-reduced-motion, a forty-flip toggle storm, a localStorage that throws the way Safari private browsing does, and nine malformed persisted records.

Engine Stands in for Result
chromium Chrome 13/13
firefox Firefox 13/13
webkit Safari 13/13
chromium channel=msedge Edge, branded build 13/13

Ten of the thirteen fail under the mutations above, so the harness is doing work.

Things I did not fix

Scroll position on a preference-driven close. Closing a card by flipping the setting settles the page about 665px from where closing the same card with the chevron settles it, identically on all four engines. The obvious cause is that only handleOpenChange calls useCollapseScrollLock, so a close the preference caused never locks. I wrote that fix, measured it, and it moved neither number, so the lock is not the mechanism and I removed it rather than ship a no-op with a confident comment on it. The scene records both numbers instead of asserting, so whoever picks this up has a baseline.

Non-boolean persisted values. ?? true only replaces null and undefined, so a hand-edited record containing "false", 1, {} or [] reaches state verbatim and reads as truthy. Confirmed on all four engines. This is true of all six booleans in that store rather than of this field, it is not reachable from Studio's own UI, and fixing it breaks three source-text tests in other files, so it wants its own PR.

What this could not answer

No GPU or hardware path is involved: the diff is entirely under studio/frontend/, so there is nothing for a CPU/NVIDIA/AMD matrix to bind to. Linux is what ran here. Windows is covered by this repo's own Frontend unit tests (Windows) job and the new tests avoid POSIX-only paths, but I did not execute it. There is no macOS frontend job. webkit and branded Edge are proxies, not real Safari and not a real Windows Edge.

Worth knowing when you read the checks on this PR: every job on the previous head died at a uniform ~1h59m, which is the shared Actions queue timing out rather than anything about this code.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5f98e90bfb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +87 to +88
if (syncedUncontrolledState !== uncontrolledState) {
setUncontrolledState(syncedUncontrolledState);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the viewport on preference-driven closes

When the setting is enabled while the user is viewing a tall, open terminal or Python card, this direct state update closes the disclosure without going through handleOpenChange, the only path that initiates the close/scroll handling; the same bypass exists for controlled cards and tool groups. The added Playwright scene 6 records the resulting regression: a preference-driven close pulls the answer upward by most of the collapsed height while a trigger-driven close keeps it approximately in place, so users can return from Settings to a substantially displaced chat viewport.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rejecting this one, and the scene it cites is being fixed because it is what produced the claim.

I tested the stated mechanism three ways: the lock left where it is (handleOpenChange only), moved to a post-commit useLayoutEffect on the isOpen transition, and called during render before the state commit. All three produce identical numbers to the pixel, so routing the preference-driven close through the close/scroll handling changes nothing and useCollapseScrollLock is not the mechanism.

The reason is that scene 6 was measuring how the two arms were driven, not what they ran. It centred the answer, which puts the card off-screen, and Playwright's click() scrolls its target into view before clicking, so the chevron arm got a free scrollIntoView the preference arm never got. Driven from the same place, with the card in view so a click has nothing to scroll:

chevron     scrollTop 0, answer -806, -806, -806
preference  scrollTop 0, answer -806, -806, -806

Identical, and -806 is just the height of the content that collapsed. There is no viewport regression between the two paths.

Scene 6 now scrolls the card into view rather than the answer, and asserts the two paths agree within 8px and that neither moves the scroll position, instead of recording a number I could not explain. My earlier note in this PR describing a 665px gap was wrong for the same reason.

setOpen(false);
}
}, [isRunning, hasText]);
const [open, setOpen] = useToolActivityOpen(isRunning, hasText);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep confirmation-gated search inputs expanded

In Ask permission mode the backend confirmation-gates every local tool call, and both web search and knowledge search are wrapped with withToolConfirmation, but this hook now initializes their running cards as closed under the default preference and neither component passes the pending-confirmation override. The terminal/Python fix therefore does not cover these search tools: the Allow/Always allow/Deny controls remain visible while a long query is truncated in the closed trigger and its full input is hidden, so the user must discover and expand the row before they can inspect what they are approving.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, and the gap was wider than the two tools named. Web search, knowledge search and code execution all go through useToolActivityOpen, all three are wrapped in withToolConfirmation, and all three render the thing being approved (query, query, executed code) inside ToolFallbackContent while Allow / Always allow / Deny render outside the card. Fixing only terminal and Python left the same hole in three more places.

All five gated cards now take toolCallId, read useToolAwaitingApproval, and pass awaitingApproval to ToolFallbackRoot. The AST test that pinned the pair now pins all five, and the browser scene that checks a parked card stays readable now runs against the controlled path as well as the uncontrolled one. Green on chromium, firefox, webkit and branded Edge.

pre-commit-ci Bot and others added 2 commits August 27, 2026 11:12
The approval fix covered terminal and Python and stopped there. Web search,
knowledge search and code execution all resolve their open state through
useToolActivityOpen, all three are wrapped in withToolConfirmation, and all
three render the thing being approved inside ToolFallbackContent while
Allow / Always allow / Deny render outside the card. Under the default-on
preference their running cards initialise closed, so Ask permission mode
asked for a decision about a query or a block of code that only appeared
truncated in the trigger.

All five gated cards now take toolCallId, read useToolAwaitingApproval and
pass awaitingApproval through, so the override is uniform rather than
per-card. The AST test that pinned two files pins five, and the browser
scene for a parked card runs against the controlled path as well as the
uncontrolled one.
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

danielhanchen added a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Aug 27, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: f4b228220a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment-only pass over the files this PR touches, verified by comment_tools.py:
10/10 comment-only, no code changed. Cuts the long explanatory blocks added
during review down to the point they were making, and collapses the harness and
driver headers. Tests, typecheck and the browser scenes unchanged and green.
@danielhanchen
danielhanchen merged commit 4c144b1 into unslothai:main Aug 27, 2026
3 of 35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants