Skip to content

Add basic thread forking from the sidebar#4390

Open
colonelpanic8 wants to merge 10 commits into
pingdotgg:mainfrom
colonelpanic8:t3code/add-thread-forking
Open

Add basic thread forking from the sidebar#4390
colonelpanic8 wants to merge 10 commits into
pingdotgg:mainfrom
colonelpanic8:t3code/add-thread-forking

Conversation

@colonelpanic8

@colonelpanic8 colonelpanic8 commented Jul 23, 2026

Copy link
Copy Markdown

What Changed

  • adds a provider-aware thread.fork orchestration command and persists fork lineage
  • adds Fork thread to the web/desktop sidebar thread context menu
  • clones the conversation through its latest completed assistant turn, then opens the fork as a normal full thread
  • supports native forking for Codex, Claude, and OpenCode
  • removes the response-level fork controls and fork-to-side-panel UI

Why

The basic fork interaction should feel like cloning a thread: right-click it in the sidebar, fork it, and continue in an independent copy. Branching from an older response can be added later, but it should not complicate the first version or introduce a separate side-chat surface.

UI Changes

Right-click a supported thread in the sidebar and select Fork thread. The action is disabled while the latest turn is running or before the thread has a completed assistant response. A successful fork appears as <original title> (fork) and opens in the normal full-thread route.

There is no split view, embedded side chat, or per-response fork button.

Checklist

  • focused server, contracts, client-runtime, and web tests pass (326 tests)
  • affected server, contracts, client-runtime, and web typechecks pass
  • targeted formatting and lint checks pass
  • refreshed UI capture (the collaborative preview automation failed to attach to the isolated test app)

Note

Add thread forking from the sidebar and assistant message timeline

  • Adds a 'Fork thread' context menu item in both sidebar variants and a per-message fork button in the assistant timeline; both are gated on provider fork capability (codex, claudeAgent, opencode).
  • Introduces a thread.fork command and thread.forked event in the contracts layer; the decider clones messages up to the specified source turn (excluding streaming messages), rewrites attachment ids, and records fork lineage.
  • The Claude, Codex, and OpenCode provider adapters each implement native session forking (sessionFork: "native"), forwarding fork context to their respective SDKs.
  • The projection pipeline persists fork lineage columns (forked_from_thread_id, forked_from_turn_id) via migration 035, inherits messages from the source thread, and physically copies attachment files into fork-owned paths post-transaction.
  • The projector removes the MAX_THREAD_MESSAGES cap, so threads now retain an unbounded message history.
  • Risk: Removing the message cap is a behavioral change that may increase memory and storage usage for long-lived threads.

Macroscope summarized b779c54.


Note

High Risk
Touches orchestration, durable projections, attachment lifecycle, and provider session start/fork paths; unbounded message retention may increase memory and storage for long threads.

Overview
Adds end-to-end thread forking: a thread.fork command emits thread.forked with inherited history through a chosen completed turn, fork lineage on threads, and fork-owned message/attachment ids (createForkedAttachmentId). The SQL projection copies attachment files on fork, keeps inherited :fork: messages across revert, and migration 035 stores forked_from_* columns.

Provider integration — Codex, Claude, and OpenCode declare sessionFork: "native" and receive forkFrom (turn index/id + source resume cursor) when a forked thread starts; ProviderCommandReactor walks nested fork lineage to the provider-owning ancestor. getCommandReadModel now loads full per-thread message history (not capped like shell snapshots).

Client@t3tools/client-runtime/thread-forking gates fork UI; sidebar Fork thread and chat Fork from this response call useForkThread / threadEnvironment.fork. In-memory projection drops the 2,000-message cap so command/read models can retain complete history.

Reviewed by Cursor Bugbot for commit b779c54. Bugbot is set up for automated code reviews on this repo. Configure here.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8f6c076f-409d-4cd4-b64d-3139ba22c936

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:XL 500-999 changed lines (additions + deletions). labels Jul 23, 2026
Comment thread apps/server/src/orchestration/Layers/ProviderCommandReactor.ts
Comment thread apps/server/src/orchestration/Layers/ProviderCommandReactor.ts
Comment thread apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts
Comment thread apps/server/src/orchestration/Layers/ProjectionPipeline.ts
Comment thread apps/server/src/orchestration/Layers/ProviderCommandReactor.ts
Comment thread apps/server/src/orchestration/Layers/ProjectionPipeline.ts
@macroscopeapp

macroscopeapp Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Needs human review

This PR introduces a new thread forking feature with substantial scope: new database schema, new event/command types, provider API integrations for Codex/Claude/OpenCode, and new UI components in sidebar and chat view. New user-facing capabilities of this magnitude warrant human review.

You can customize Macroscope's approvability policy. Learn more.

@colonelpanic8
colonelpanic8 force-pushed the t3code/add-thread-forking branch from 29c1ba0 to bf7ab07 Compare July 23, 2026 20:32
@github-actions github-actions Bot added size:XXL 1,000+ changed lines (additions + deletions). and removed size:XL 500-999 changed lines (additions + deletions). labels Jul 23, 2026
Comment thread apps/server/src/orchestration/decider.ts
Comment thread apps/server/src/provider/Layers/ProviderService.ts
Comment thread apps/server/src/provider/Layers/OpenCodeAdapter.ts Outdated
Comment thread apps/server/src/orchestration/Layers/ProjectionPipeline.ts
Comment thread apps/mobile/src/features/threads/ThreadRouteScreen.tsx
Comment thread apps/server/src/provider/Layers/CodexSessionRuntime.ts
Comment thread apps/server/src/provider/Layers/ProviderService.ts
@colonelpanic8
colonelpanic8 force-pushed the t3code/add-thread-forking branch 2 times, most recently from ac92627 to eb09585 Compare July 23, 2026 21:00
Comment thread apps/web/src/components/ChatView.tsx Outdated
Comment thread apps/server/src/orchestration/decider.ts
Comment thread apps/server/src/orchestration/decider.ts
Comment thread apps/server/src/orchestration/projector.ts
@colonelpanic8
colonelpanic8 force-pushed the t3code/add-thread-forking branch 2 times, most recently from 2e90fb7 to 3360755 Compare July 23, 2026 22:28
Comment thread apps/server/src/orchestration/decider.ts
@colonelpanic8
colonelpanic8 force-pushed the t3code/add-thread-forking branch 2 times, most recently from 0ae7550 to 0258dca Compare July 24, 2026 01:50
Comment thread apps/server/src/orchestration/Layers/ProjectionSnapshotQuery.ts
@colonelpanic8 colonelpanic8 changed the title Add thread forking across web and mobile Add basic thread forking from the sidebar Jul 24, 2026
Comment thread apps/web/src/components/Sidebar.tsx
@colonelpanic8
colonelpanic8 force-pushed the t3code/add-thread-forking branch 2 times, most recently from b9b18e0 to f4474ea Compare July 24, 2026 06:13
Comment thread apps/web/src/hooks/useForkThread.ts Outdated
@colonelpanic8
colonelpanic8 force-pushed the t3code/add-thread-forking branch 2 times, most recently from 9ac81ba to ece3d88 Compare July 25, 2026 00:01
@colonelpanic8
colonelpanic8 force-pushed the t3code/add-thread-forking branch from ece3d88 to b779c54 Compare July 25, 2026 03:23

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b779c54. Configure here.

isRevertingCheckpoint={isRevertingCheckpoint}
{...(isServerThread && supportsSelectedResponseFork(activeProviderStatus?.driver)
? { onForkFromResponse, isForkingResponse }
: {})}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Timeline fork uses composer provider

Medium Severity

Per-message fork actions are gated on activeProviderStatus?.driver, which follows the thread composer’s selected provider instance before the thread’s session or model binding. Sidebar fork uses the thread’s provider instance instead, so the timeline can hide fork on supported threads or show it when native fork will fail.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit b779c54. Configure here.

colonelpanic8 added a commit to colonelpanic8/t3code that referenced this pull request Jul 25, 2026
…ted response from the sidebar)

# Conflicts:
#	apps/web/src/components/Sidebar.tsx
colonelpanic8 added a commit to colonelpanic8/t3code that referenced this pull request Jul 25, 2026
…ted response from the sidebar)

# Conflicts:
#	apps/web/src/components/Sidebar.tsx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL 1,000+ changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants