Skip to content

feat(context branching): add context branching for threads#2091

Open
William-zgx wants to merge 10 commits intobytedance:mainfrom
William-zgx:context_branch
Open

feat(context branching): add context branching for threads#2091
William-zgx wants to merge 10 commits intobytedance:mainfrom
William-zgx:context_branch

Conversation

@William-zgx
Copy link
Copy Markdown

@William-zgx William-zgx commented Apr 10, 2026

Summary

  • implement minimal thread context branching across the backend thread flow and the frontend workspace navigation
  • add backend support for branch creation metadata and branch-aware thread operations
  • add frontend branch metadata, APIs, route helpers, and sidebar tree rendering for branch navigation

Scope

Testing

  • backend/.venv/bin/pytest backend/tests/test_threads_router.py -q
  • backend/.venv/bin/pytest backend/tests/test_provisioner_kubeconfig.py backend/tests/test_docker_sandbox_mode_detection.py -q
  • pnpm --dir frontend typecheck
  • pnpm --dir frontend exec node --test src/core/threads/utils.test.ts

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 10, 2026

CLA assistant check
All committers have signed the CLA.

@WillemJiang
Copy link
Copy Markdown
Collaborator

@William-zgx, thanks for your contribution. As it's a new feature, please create an issue with all your designs to disucss with the community first.

@William-zgx William-zgx changed the title feat: add context branching for threads feat(context branching): add context branching for threads Apr 10, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds minimal “context branching” support for threads by introducing backend lineage metadata + a branch creation endpoint, then wiring frontend APIs, routing helpers, and sidebar rendering to create and navigate branch threads.

Changes:

  • Backend: add POST /api/threads/{thread_id}/branches to fork a new thread from a checkpoint, copy selected thread-local files, and persist branch lineage metadata.
  • Frontend: add thread branch APIs/hooks and UI actions (create branch / back-to-parent), plus branch-aware routing.
  • Frontend: render recent chats as a parent/child tree using branch metadata.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
backend/app/gateway/routers/threads.py Adds branch create request/response models, file-copy helpers, LangGraph thread registration helpers, and the /branches endpoint.
backend/tests/test_threads_router.py Adds unit tests covering branching behavior, checkpoint selection, file copying, and rollback on failure.
frontend/src/core/threads/types.ts Introduces branch metadata types and request/response types for branching + thread records.
frontend/src/core/threads/utils.ts Adds agent-name normalization and branch metadata helpers; improves thread path resolution.
frontend/src/core/threads/api.ts Adds fetchThreadRecord and createThreadBranch API calls.
frontend/src/core/threads/hooks.ts Adds useThreadRecord and useCreateThreadBranch; updates rename to invalidate thread detail queries.
frontend/src/core/threads/index.ts Re-exports new thread API and utils.
frontend/src/components/workspace/thread-branch-actions.tsx Adds UI for creating branches and returning to parent thread.
frontend/src/components/workspace/recent-chat-list.tsx Builds and renders a branch tree in the sidebar recent chats list.
frontend/src/app/workspace/chats/[thread_id]/page.tsx Adds branch actions to the default chat header.
frontend/src/app/workspace/agents/[agent_name]/chats/[thread_id]/page.tsx Adds branch actions + redirects /agents/default/... back to default chat routes.
frontend/src/core/i18n/locales/en-US.ts Adds branching UI strings (English).
frontend/src/core/i18n/locales/zh-CN.ts Adds branching UI strings (Chinese).
frontend/src/core/i18n/locales/types.ts Adds branching translation schema.
frontend/next.config.js Adds gateway rewrites for additional /api/* endpoints including /api/threads/:path*.

Comment thread backend/app/gateway/routers/threads.py Outdated
Comment thread backend/app/gateway/routers/threads.py
Comment thread backend/app/gateway/routers/threads.py
Comment thread backend/app/gateway/routers/threads.py Outdated
Comment thread backend/app/gateway/routers/threads.py Outdated
Comment thread frontend/next.config.js
Comment thread backend/app/gateway/routers/threads.py
@WillemJiang
Copy link
Copy Markdown
Collaborator

@William-zgx, thanks for your contribution. Please take a look at the review comments.

@William-zgx
Copy link
Copy Markdown
Author

Addressed in d95980f. I added defensive branch-depth parsing, rollback on copy/store failures, skipped symlinks during branch file copy, cleared artifacts when outputs are not copied, aligned the timestamp description, and added the missing /api/threads rewrite.

@William-zgx
Copy link
Copy Markdown
Author

@William-zgx, thanks for your contribution. Please take a look at the review comments.

@WillemJiang Thanks, I’ve addressed the review comments, updated the PR, and resolved the related threads.

@William-zgx
Copy link
Copy Markdown
Author

@WillemJiang could you please take a look when you have a moment? I've addressed the review comments and updated the PR. Thanks!

William-zgx and others added 3 commits April 15, 2026 10:55
# Conflicts:
#	frontend/next.config.js
#	frontend/src/app/workspace/agents/[agent_name]/chats/[thread_id]/page.tsx
#	frontend/src/app/workspace/chats/[thread_id]/page.tsx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants