Skip to content

feat: Allow attaching/changing repository for existing conversations#12671

Merged
hieptl merged 38 commits intoOpenHands:mainfrom
MkDev11:feat/change-conversation-repository
Feb 25, 2026
Merged

feat: Allow attaching/changing repository for existing conversations#12671
hieptl merged 38 commits intoOpenHands:mainfrom
MkDev11:feat/change-conversation-repository

Conversation

@MkDev11
Copy link
Copy Markdown
Contributor

@MkDev11 MkDev11 commented Jan 29, 2026

Summary of PR

This PR implements the ability to attach or change a Git repository for existing conversations, addressing Issue #12628.

Changes

Backend:

  • Extended AppConversationUpdateRequest model with optional selected_repository, selected_branch, and git_provider fields
  • Updated update_app_conversation service method to use Pydantic's model_fields_set for proper partial updates, allowing fields to be explicitly set to None (to remove repository association)

Frontend:

  • Added updateConversationRepository API method in the conversation service
  • Created useUpdateConversationRepository mutation hook with optimistic updates and error handling
  • Created ChangeRepositoryModal component with repository dropdown for selecting/changing repositories
  • Added "Change Repository" / "Attach Repository" button to the GitControlBar
  • Added i18n translations for all 14 supported languages
  • Added unit tests for the mutation hook

User Experience

  • Users can now attach a repository to conversations that were started without one
  • Users can change the repository mid-conversation if they need to switch context
  • Users can remove the repository association if needed
  • The button dynamically shows "Attach Repository" or "Change Repository" based on current state

Demo Screenshots/Videos

Attach Repository Button Attach Repository Modal
image image
Change Repository Button Change Repository Modal
image image

Change Type

  • Bug fix
  • New feature
  • Breaking change
  • Refactor
  • Other (dependency update, docs, typo fixes, etc.)

Checklist

  • I have read and reviewed the code and I understand what the code is doing.
  • I have tested the code to the best of my ability and ensured it works as expected.

Fixes

Resolves #12628

Release Notes

  • Include this change in the Release Notes.

Users can now attach or change the Git repository for existing conversations. A new "Change Repository" button in the conversation view allows selecting a different repository or attaching one to conversations that were started without a repository.

Implements issue OpenHands#12628 - Allow users to change or attach a repository
to an existing conversation.

Backend changes:
- Extend AppConversationUpdateRequest model with selected_repository,
  selected_branch, and git_provider fields (all optional)
- Update service to only update fields that are explicitly provided (not None)

Frontend changes:
- Add updateConversationRepository API method to V1ConversationService
- Create useUpdateConversationRepository mutation hook
- Add ChangeRepositoryModal component for repository selection UI
- Add 'Change Repository' / 'Attach Repository' button to GitControlBar
- Add i18n keys for repository update messages

Tests:
- Add unit tests for useUpdateConversationRepository hook
Copy link
Copy Markdown
Collaborator

@hieptl hieptl left a comment

Choose a reason for hiding this comment

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

Hello @MkDev11,

We have created a Slack thread to discuss the UI aspects of this pull request:
#12671 (comment)

Before we proceed with the review and merging, we will need to wait for the UI feedback shared in that thread. This will help ensure we are aligned and that all UI considerations are properly addressed.

Thank you very much for your contribution and for taking the time to create this pull request. We truly appreciate your efforts! 🙏

@mamoodi
Copy link
Copy Markdown
Collaborator

mamoodi commented Jan 29, 2026

Thank you for your contribution! Based on Hieptl's comment, I'm going to put this into draft since it's going to be work in progress. Once ready please set it to ready for review again.

@mamoodi mamoodi marked this pull request as draft January 29, 2026 17:05
@MkDev11
Copy link
Copy Markdown
Contributor Author

MkDev11 commented Feb 3, 2026

I will close this pr until the design is ready.

@MkDev11 MkDev11 closed this Feb 3, 2026
@MkDev11 MkDev11 reopened this Feb 6, 2026
@MkDev11 MkDev11 marked this pull request as ready for review February 9, 2026 12:41
Copy link
Copy Markdown
Collaborator

@all-hands-bot all-hands-bot left a comment

Choose a reason for hiding this comment

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

Overall this is a well-implemented feature with good test coverage and i18n support. I found one breaking change and a few UX/type safety improvements to consider.

Comment thread openhands/app_server/app_conversation/app_conversation_models.py
Comment thread frontend/src/components/features/chat/change-repository-modal.tsx Outdated
Comment thread frontend/src/components/features/chat/change-repository-modal.tsx Outdated
Comment thread frontend/src/components/features/chat/git-control-bar.tsx Outdated
Comment thread frontend/src/components/features/chat/change-repository-modal.tsx Outdated
Comment thread frontend/src/hooks/mutation/use-update-conversation-repository.ts
Comment thread openhands/app_server/app_conversation/app_conversation_models.py
Comment thread frontend/src/components/features/chat/change-repository-modal.tsx Outdated
Comment thread frontend/src/components/features/chat/change-repository-modal.tsx Outdated
Comment thread frontend/src/components/features/chat/git-control-bar.tsx Outdated
Comment thread frontend/src/components/features/chat/change-repository-modal.tsx Outdated
Comment thread frontend/src/hooks/mutation/use-update-conversation-repository.ts
@MkDev11 MkDev11 requested a review from hieptl February 9, 2026 13:33
…sations

- Add new OpenRepositoryModal component with repo and branch selection
- Replace ChangeRepositoryModal with OpenRepositoryModal in GitControlBar
- Fix duplicate 'No Repo Connected' badges with conditional rendering
- Fix repository dropdown display by using correct value/repositoryName props
- Add i18n keys for OPEN_REPOSITORY, SELECT_OR_INSERT_LINK, NO_REPO_CONNECTED
MkDev11 and others added 3 commits February 19, 2026 15:18
The test was failing in CI likely due to floating point precision issues
when comparing accumulated costs. Using pytest.approx resolves this.
@hieptl
Copy link
Copy Markdown
Collaborator

hieptl commented Feb 19, 2026

Hello @MkDev11,

I noticed a few issues while testing the pull request locally and wanted to share them with you.

Issue 1:

  • The styling of the “Select or insert a link” text does not align with the version on the home page.
  • The “Select or insert a link” text and the Git provider dropdown are not on the same row. On the home page, they appear on a single row.
  • The icon before “Open Repository” is missing.

Note: It may be worth considering defining reusable components that can be shared between both views, rather than duplicating styling and components. This could help reduce duplication and improve consistency.

Please refer to the images below for additional context:

Conversation page:
conversation

Home page:
home

Issue 2:
When selecting a repository from the modal, the Most Recent Repositories list is not updated. On the home page, after selecting a repository and clicking the Launch button, this list is updated correctly. Please refer to the image below for additional context.

issue2

Issue 3:

  • Step 1: Ask the agent to create a long-running task, such as “Create a Hello World app in React.”
  • Step 2: While the agent is running, select a repository from the modal and click the Launch button.
  • Step 3: The message “Clone hieptl-org1/test-openhands and checkout branch main.” is not sent as expected.

Please refer to the video below for additional context.

issue3.mov

Thank you! 🙏

MkDev11 and others added 2 commits February 19, 2026 14:44
- Fix modal styling to match home page (RepoForkedIcon, text-sm white text, gap-[10px])
- Add addRecentRepository call when launching repo from modal
- Fix stale closure: use useRef for webSocketStatus in onSuccess callback
@malhotra5 malhotra5 marked this pull request as draft February 20, 2026 19:21
@MkDev11 MkDev11 marked this pull request as ready for review February 21, 2026 19:15
@MkDev11
Copy link
Copy Markdown
Contributor Author

MkDev11 commented Feb 21, 2026

Hello @MkDev11,

I noticed a few issues while testing the pull request locally and wanted to share them with you.

Issue 1:

  • The styling of the “Select or insert a link” text does not align with the version on the home page.
  • The “Select or insert a link” text and the Git provider dropdown are not on the same row. On the home page, they appear on a single row.
  • The icon before “Open Repository” is missing.

Note: It may be worth considering defining reusable components that can be shared between both views, rather than duplicating styling and components. This could help reduce duplication and improve consistency.

Please refer to the images below for additional context:

Conversation page: conversation

Home page: home

Issue 2: When selecting a repository from the modal, the Most Recent Repositories list is not updated. On the home page, after selecting a repository and clicking the Launch button, this list is updated correctly. Please refer to the image below for additional context.

issue2 Issue 3:
  • Step 1: Ask the agent to create a long-running task, such as “Create a Hello World app in React.”
  • Step 2: While the agent is running, select a repository from the modal and click the Launch button.
  • Step 3: The message “Clone hieptl-org1/test-openhands and checkout branch main.” is not sent as expected.

Please refer to the video below for additional context.

issue3.mov
Thank you! 🙏

@hieptl 3 issues are fixed

@hieptl
Copy link
Copy Markdown
Collaborator

hieptl commented Feb 23, 2026

Hello @MkDev11,

The third issue mentioned in my previous comment still occurs on my end. Please see the steps below for clarification:

  • Step 1: Ask the agent to create a long-running task, such as “Create a Hello World app in React.”
  • Step 2: While the agent is running, select a repository from the modal and click the Launch button.
  • Step 3: The message “Clone hieptl-org1/test-openhands and checkout branch main.” is not sent as expected.

Please refer to the video below for additional context:

issue.mov

Thank you very much! 🙏

The send function captured in onSuccess holds a stale v1Context.sendMessage
that references a now-closed WebSocket. Using sendRef.current ensures we
always call the latest send with the current WebSocket connection.
@MkDev11
Copy link
Copy Markdown
Contributor Author

MkDev11 commented Feb 23, 2026

@hieptl can you please review the change again?

@hieptl
Copy link
Copy Markdown
Collaborator

hieptl commented Feb 24, 2026

@hieptl can you please review the change again?

Hello @MkDev11,

The issue mentioned in my previous comment still occurs on my end. Please see the steps below for clarification:

Step 1: Ask the agent to create a long-running task, such as “Create a Hello World app in React.”
Step 2: While the agent is running, select a repository from the modal and click the Launch button.
Step 3: The message “Clone hieptl-org1/test-openhands and checkout branch main.” is not sent as expected.

Please refer to the video below for additional context:

issue.mov

Thank you very much! 🙏

MkDev11 and others added 2 commits February 24, 2026 11:11
…dWebSocketStatus

Also check conversation ID prefix (task-*) to handle cases where
conversation data is temporarily undefined during query refetch.
@MkDev11
Copy link
Copy Markdown
Contributor Author

MkDev11 commented Feb 24, 2026

@hieptl sorry for the mistake, I didn't push the latest changes. please review the changes and the video link.
https://www.loom.com/share/23c07a8a8efa4035a7d15cb682718146

@hieptl
Copy link
Copy Markdown
Collaborator

hieptl commented Feb 24, 2026

Hello @MkDev11,

For your reference, the issue is still present. Please see the video below for additional details. You can reproduce it using the prompt “Create a hello world app in React.” There’s no need to wait for the agent to finish.

According to the video, when it begins creating a new React project, you can try attaching an existing repository—you should then be able to observe the issue more clearly.

npx create-react-app hello-world-react
issue.mov

Thank you very much! 🙏

Use setOptimisticUserMessage() to show the clone command in the chat
immediately, matching the behavior of regular user messages.
@MkDev11
Copy link
Copy Markdown
Contributor Author

MkDev11 commented Feb 24, 2026

@hieptl fixed again.

@hieptl
Copy link
Copy Markdown
Collaborator

hieptl commented Feb 24, 2026

Hello @MkDev11,

I found another issue while testing the pull request locally and wanted to share it for visibility.

Steps to reproduce:

  • Step 1: Create a new conversation.
  • Step 2: Attach a repository from GitLab and observe the UI behavior.

Current behavior:
The agent attempts to clone the repository from GitHub first before switching to GitLab.

Expected behavior:
The agent should clone the selected repository directly from the chosen Git provider.

Please feel free to refer to the video below for additional context.

issue1.mov

Potential solution:
One possible and relatively straightforward approach would be to adjust the prompt based on the selected Git provider. At the moment, the prompt appears as follows:

Clone hieptl.developer-group/hieptl.developer-project and check out branch add-batman-microagent.

If GitLab is selected as the provider, the prompt could instead be structured like this (and similarly for other Git providers):

Clone hieptl.developer-group/hieptl.developer-project from GitLab and check out branch add-batman-microagent.

This is only a suggested approach, and we would need to test it carefully to ensure it behaves reliably across all supported scenarios.

Thank you! 🙏

MkDev11 and others added 2 commits February 24, 2026 21:14
Add provider name (GitHub, GitLab, etc.) to clone prompt so agent
clones from the correct source instead of defaulting to GitHub.

Added unit tests for clone prompt format.
@MkDev11
Copy link
Copy Markdown
Contributor Author

MkDev11 commented Feb 24, 2026

image @hieptl Thanks for your another feedback. I fixed the issue as well, please review the screenshot and the changes.

Copy link
Copy Markdown
Collaborator

@hieptl hieptl left a comment

Choose a reason for hiding this comment

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

Thank you! 🙏

@hieptl hieptl merged commit 51b989b into OpenHands:main Feb 25, 2026
17 checks passed
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.

[Feature Request] Allow attaching/changing repository for existing conversations

4 participants