Skip to content

Long threads load in pages and render lighter, safer file restores, and triage polish - #1792

Merged
currentbits merged 17 commits into
mainfrom
feat/long-thread-perf-and-safety
Oct 30, 2026
Merged

currentbits merged 17 commits into
mainfrom
feat/long-thread-perf-and-safety

Conversation

@currentbits

Copy link
Copy Markdown
Owner

Long threads load and render faster, file restores are safer, and settling, notifications and question cards fit a many-threads workflow better.

Long threads (#1785, #1786, #1787)

  • Opening a long thread fetches the latest 300 messages. Older pages load from a "Load older messages" control. On a synthetic 5000-message thread, the open payload went from 1.08 MB to 66 KB (about 16× smaller). ⌘F with no hits, and ⌘K or pinned jumps to a message outside the loaded page, fetch the full history once. Export reads the full history. Streaming updates are unchanged: only the new tail is sent.
  • Settled transcript rows skip layout and paint while off-screen (content-visibility: auto). Nothing is unmounted, so find, selection and jumps keep working. The live streaming row is excluded. This matters most after repeated "Show earlier".
  • The Changes panel and turn diff panel no longer re-render on every streamed token. They're memoized with stable handlers, and a render-count test pins it.
  • New setting: "Start diff files collapsed" for the Changes panel, the PR code tab and turn diffs. Click a file header to expand it, and choosing a file from the list expands it too.

Safety (#1788)

  • Restoring files is refused while another thread is working in the same checkout, whether that's a shared worktree or a non-worktree thread on the project folder. Conversation-only rewind is still allowed.
  • Fixed a race between restoring files and sending a message. A message sent while a checkpoint restore or rewind was in flight could start a run in the half-restored tree. Restores now hold the thread until they finish. There's a test that reproduces it with a slow restore.
  • Interrupted runs resume once after a restart by default. Anyone who explicitly chose "off" keeps "off".

Triage (#1789, #1790)

  • A new question or approval card no longer jumps in while you're typing. A small notice above the composer says what's waiting, and for approvals adds that sending will decline and redirect. Click it to open the card now; otherwise the card appears after 1.5s without typing.
  • Back-to-back messages you send group into one burst, with one shared time.
  • Settling the open thread (⌘⇧A or the settle button) moves to the next thread. Undo goes back to the settled thread.
  • Notifications show the outcome: a ✓, ✕ or ● title prefix on macOS, which ignores custom icons, and coloured status icons on Windows and Linux.

Known limits (listed rather than silently cut)

  • Turn stepping (Alt+↑/↓) stops at the oldest loaded turn.
  • A quick action run while you're scrolled past the first page re-collapses the view to the latest page.
  • The pre-existing scroll-to-bottom on a new approval still fires while that card is held back.
  • Settle-advance follows the unfiltered sidebar order, not sidebar search or filters.

Checks (run locally on the merged branch, electron suite in a CI-matching environment)

  • npm run typecheck and the preload sync check: clean
  • npm run test:renderer: 3605 pass, 0 fail
  • npm run test:electron: 5489 pass, 0 fail
  • npm run test:core: 38 pass. npm run test:memory: 246 pass.
  • npx vite build: succeeds

Closes #1785, closes #1786, closes #1787, closes #1788, closes #1789, closes #1790.

🤖 Generated with Claude Code

Willem and others added 17 commits October 30, 2026 22:13
Settling (not un-settling) the currently open thread now selects the
next thread in buildFlatSidebar's eligible order (pinned/active/
working/snoozed); the last item falls back to the previous one, and a
lone thread leaves selection unchanged. Settling a different thread
from the sidebar does not move selection. Undo re-selects the settled
thread.

One shared fix in App.tsx's handleSetSettled covers the ⌘⇧A shortcut,
the sidebar card's settle button, and ThreadView's settle action.
Adds the pure nextThreadAfterSettle helper next to stepVisibleId in
sidebarSelection.ts.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…the same checkout

Crew/orchestrator workers can share a worktree, and threads without their
own worktree share the project checkout. rewindThread only checked whether
THIS thread was running, so a sibling thread actively writing in the same
directory could race a restoreFiles hard reset. Add
siblingRunningSameCheckout (effective cwd = worktreePath || project.path)
and gate it at every file-mutating entry point: rewindThread's restoreFiles
branch, undoRewindThread's restore, and restoreCheckpoint itself (covers
git:restoreCheckpoint and the thrash-detector rollback). Conversation-only
rewind (no restoreFiles) is unaffected.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
notificationOptions now accepts an optional {event, platform}: for a
done/failed/waiting transition ("waiting" covers both an approval
prompt and a question card, same mapping threadNotifyState already
uses), macOS gets a status glyph prefixed onto the title (checkmark /
cross / dot) since Electron's Notification `icon` field is documented
to be ignored there for the app's own icon; Windows/Linux get a
generated 48x48 status-color PNG via the returned iconBuffer.

The PNG is hand-built with node:zlib (deflate) and a small CRC32 table
at call time, no image dependency and nothing committed to the repo.
notify.js stays electron-free so its tests keep running under plain
`node --test`; main.js's notifyThreadComplete turns iconBuffer into a
NativeImage via the electron it already has. Calling without `event`
(e.g. ciFailedNotification) is unchanged.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…ry streamed token (#1787)

ChangesPanel and TurnDiffPanel were plain function components mounted from
ThreadView, which re-renders on every stream tick. Wrap both in React.memo
and stabilize the two props ThreadView was recreating inline on every render
(onCommitAndPr, onComment's diff-comment handler, TurnDiffPanel's
onModeChange) with useCallback so the memo actually holds. Added a render-
count regression test (same ThreadCard/#617 .type-probe pattern already used
in sidebar.test.tsx) that mounts ThreadView with the Changes panel open,
pushes several streamed-token updates, and asserts the render count does not
grow.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…chose

resumeInterruptedRuns shipped opt-in (#1512 I3) and normalizeSettings wrote
false into every stored settings object, so an unset value was
indistinguishable from an explicit false. Add resumeInterruptedRunsSet, a
marker setSettings stamps the moment a user actually patches this key
(either direction). normalizeSettings now defaults the flag to true unless
that marker is present, so a never-touched store (or one that only ever saw
the old backfilled false) heals to on, while an explicit true or false
survives every reload. The once-only autoResumedAt cap per thread is
unchanged.

Updates the full-settings snapshot tests (auto-settle-settings,
budget-spend), the auto-resume default/opt-out tests, the dev/browser
settings fixture, and the SettingsModal renderer test/fixture default.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
The tail window (#564/#1475) already bounds mounted DOM to ~120 entries
regardless of thread length, and React's own commit cost per streamed
append stays sub-millisecond at any n (measured 500/3000/8000-message
synthetic threads). The real unbounded-growth path is a reader who
clicks "Show earlier" repeatedly without returning to the bottom: the
window keeps growing (mounted rows go from 104 to 1664+ after 15 clicks
on an 8000-message thread in testing), and every one of those mounted
rows used to cost full browser layout/paint even while scrolled far out
of view.

Add a `.settledRow` class (content-visibility: auto + contain-intrinsic-
size) to message rows and finished tool-call groups, skipping it only
for the row the live turn is currently writing into (streaming message,
running tool, thinking card) so active updates never thrash containment.
This is the same native technique already used for long file lists
(FilesPane.module.css); it keeps every row mounted, so find, selection,
jump-to-turn, and revealMessageId continue to work exactly as before.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…#1786)

threads:get now returns only the newest page of messages by default
(electron/store.js getMessagesPage, 300-message default) plus
hasOlderMessages/totalMessageCount; a new threads:getOlderMessages fetches
the previous page by cursor. Plumbed through ipc-threads.js, the shared
ipcChannels.ts table (regenerated preload.js), ipc.ts types, webScopes.js,
the browser-dev fixture (src/dev/threads.ts) and the renderer test fixture
(test/support/fakeCoder.ts), sharing the slice logic via a new
src/shared/messagePaging.ts helper on the TS side.

Streaming pushes (runner.js pushDetail) keep requesting the full array
(limit: Infinity) so the existing firstChanged tail-diff still only ships
new messages; mergeThreadPatch now always carries hasOlderMessages/
totalMessageCount forward from the open detail instead of trusting a
patch's value, since a streamed patch is never page-aware.

Renderer: useCoder exposes loadOlderMessages (prepends the previous page)
and ensureFullHistory (fetches everything once, for a feature that needs
a message outside the loaded page). ThreadView wires a "Load older
messages" control once its local tail window is exhausted, and triggers
ensureFullHistory when a reveal target (useTranscriptFind zero hits, or
a ⌘K jump) isn't in the loaded page.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
New pref (src/uiPrefs.ts, Settings General Display) defaults off. When on,
each file's diff body starts collapsed in the Changes panel, the PR code
tab, and turn diffs, behind a shared per-file collapse header (chevron,
file path) exported from TurnDiffPanel.tsx. Clicking the header toggles it;
selecting a file from the list/tree always expands it. Large-diff hiding is
unaffected: it still gates whether a patch exists before collapse applies.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…ight

Investigated the rollback/send race for #1788: rewindThread (restoreFiles)
and restoreCheckpoint never marked the thread busy in the runner's `active`
map, so startRun's only guard (`active.has(threadId)`) let a message sent
mid-restore spawn a turn into the worktree while `git reset --hard` was
still running, or land that turn's own post-turn checkpoint on a
half-restored tree. A real window, confirmed with an injected slow restore.

Add a dedicated per-thread `restoringThreads` set and `withRestoreHold`,
separate from `active` on purpose: Stop only ever inspects `active` and
unconditionally terminalizes whatever it finds there, so folding the hold
into `active` would let Stop clear it early (there is no process to kill
for a restore, the git calls are already near-instant) and reopen the same
race. startRun now refuses with a clear message while the hold is up.
restoreCheckpoint takes the hold for its whole mutation (covers
git:restoreCheckpoint and the thrash-detector rollback); undoRewindThread's
own hard reset takes it directly.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Electron: store.getMessagesPage (newest page, before-cursor paging,
limit: Infinity, unknown cursor/thread boundary cases), services
getThreadDetail/getOlderMessages, and the threads:get / threads:peek /
threads:getOlderMessages IPC handlers end to end. Updates the two
hand-rolled fake stores in threadReport.test.js that lacked
getMessagesPage.

Renderer: mergeThreadPatch preserves hasOlderMessages/totalMessageCount
across a streamed tail patch (threadPatch.test.ts); ThreadView renders
the "Load older messages" control once the local tail window is
exhausted, prepends the fetched page, and falls back to
onEnsureFullHistory when a reveal target isn't in the loaded page
(threadView.test.tsx).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…sing

QuestionPrompt/permission/plan cards used to mount the instant
thread.pendingQuestion or detail.pendingPermission appeared, snapping focus
inside the scrolled transcript away from whatever the user was mid-typing.
Composer now reports last-keystroke/focus/emptiness to ThreadView via
onComposerActivity; a card that arrives within 1.5s of the last keystroke,
while the composer is focused and non-empty, is held back behind a compact
notice on the composer's status lip instead, until 1.5s of no typing or a
click on the notice. The underlying pendingPermission/pendingQuestion data
is untouched by the defer, so a held-back card still counts as "open" for
the #1762 decline-and-redirect send path.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…urst

Consecutive user messages with no agent output between them (queued
follow-ups, steer messages, quick corrections) used to render as N separate
bubbles. userMessageBursts (src/components/thread/messages.tsx) is a pure
helper over the same DisplayEntry[] row list ThreadView already builds: it
tags each user message first/middle/last/single, breaking the run on any
non-user row (tool group, worklog, or a non-user message). ThreadView wires
the position into MessageBlock via data-burst; CSS tightens the vertical
gap and flattens the touching corners within a burst. Each message keeps
its own Copy/Edit/Pin on hover; only the last message's footer carries a
shared time for the group.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
# Conflicts:
#	test/threadView.test.tsx
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T21:48:08.214551Z 412142b PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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: 412142b095

ℹ️ 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 +2091 to +2093
messages: page.messages,
hasOlderMessages: page.hasOlder,
totalMessageCount: page.totalCount,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Reconcile paged messages with full-transcript patch offsets

For threads exceeding 300 messages, this returns a suffix while runner.pushDetail still computes messagesFrom against the full transcript. mergeThreadPatch interprets that offset relative to the loaded suffix: updating message 499 in a 500-message thread returns null and triggers reloadDetail, which fetches another default page on every streaming push and discards any additionally loaded history. A shrinking patch with an offset within the page length can instead silently retain the wrong messages. Carry and account for the page's absolute offset, or otherwise establish a consistent patch base before merging.

Useful? React with 👍 / 👎.

Comment thread src/useCoder.ts
Comment on lines +1192 to +1193
return api.threads
.peek(threadId, { limit: Infinity })

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 Use a JSON-safe limit for full-history requests

In the browser/web-access client, src/wireClient.ts serializes invocation arguments with JSON.stringify, so Infinity becomes null. Store.getMessagesPage then falls back to the default 300-message limit rather than returning the full history. Consequently, searching for or revealing an older message cannot load it through this fallback, and the returned detail still reports older history. Use a finite sufficiently large limit or an explicit JSON-safe full-history option.

Useful? React with 👍 / 👎.

// back: fetch the rest of the transcript once and let the next render's
// hits recompute over it (#1786).
useEffect(() => {
if (!session.open || !session.query.trim() || hits.length > 0) return;

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 Fetch older search results even when the loaded page has matches

When a query matches both the newest page and unloaded history, this early return prevents the older matches from ever being fetched. The find bar reports only the loaded matches, and its next/previous controls wrap within that incomplete set, so users cannot reach older occurrences without manually loading the transcript first. Request full history for an active nonempty query whenever older messages remain, rather than only when the loaded page has zero hits.

Useful? React with 👍 / 👎.

@currentbits
currentbits merged commit 377df10 into main Oct 30, 2026
6 checks passed
@currentbits
currentbits deleted the feat/long-thread-perf-and-safety branch October 30, 2026 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment