Content-Length: 515972 | pFad | https://github.com/All-Hands-AI/OpenHands/pull/10293

CA refactor(git): principled way to set git configuration for agents & re-enable git settings in UI by xingyaoww · Pull Request #10293 · All-Hands-AI/OpenHands · GitHub
Skip to content

Conversation

xingyaoww
Copy link
Collaborator

@xingyaoww xingyaoww commented Aug 13, 2025

  • This change is worth documenting at https://docs.all-hands.dev/
  • Include this change in the Release Notes. If checked, you must provide an end-user friendly description for your change below

End-user friendly description of the problem this fixes or functionality this introduces.

refactor(git): principled way to set git configuration for agents;

Fixes a bug where git operations (like commits and pushes) would fail in warm runtimes due to missing git user configuration. This ensures that git commands work reliably in all runtime scenarios, including reused warm runtimes.


Summarize what the PR does, explaining any non-trivial design decisions.

This PR fixes a critical bug in the warm runtime system where git configuration was being lost when warm runtimes were claimed and reused.

Problem: Git configuration was set during action execution server initialization, but warm runtimes bypass this initialization step. When a warm runtime was claimed, the git user settings were missing, causing git operations to fail.

Solution: Move git configuration from the action execution server to the runtime client, ensuring git settings are applied after every runtime connection.

Key Changes:

  1. Removed git config from ActionExecutor: Eliminated git parameters and configuration commands from the action execution server
  2. Added git config to Runtime base class: New setup_git_config() method handles platform-specific git configuration
  3. Updated all runtime implementations: Local, Remote, Kubernetes, CLI, and Docker runtimes now call git config setup after connection

Technical Details:

  • Maintains platform-specific logic (Windows PowerShell vs Unix bash, local file-based vs global config)
  • Uses CmdRunAction to execute git config commands in the runtime environment
  • Includes proper error handling and logging for failed git commands
  • Backward compatible with no changes to external APIs

Workflow Fix:

  • Before: Git config set during server startup → lost in warm runtimes → git operations fail
  • After: Git config applied after every runtime connection → works for both fresh and warm runtimes

Screenshots:

Before setting anything in UI:
image

After setting (this pr also adjust the fontsize so it follow existing setting convention in LLM tab:
image
It is working
image

In CLI - does override user config:
image


Link of any specific issues this addresses:

This addresses the warm runtime git configuration bug reported in the deploy repository where git operations would fail when using warm runtimes due to missing user configuration. This is why #9942 didn't work

@xingyaoww can click here to continue refining the PR


To run this PR locally, use the following command:

GUI with Docker:

docker run -it --rm   -p 3000:3000   -v /var/run/docker.sock:/var/run/docker.sock   --add-host host.docker.internal:host-gateway   -e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:a65fb44-nikolaik   --name openhands-app-a65fb44   docker.all-hands.dev/all-hands-ai/openhands:a65fb44

CLI with uvx:

uvx --python 3.12 --from git+https://github.com/All-Hands-AI/OpenHands@fix-git-config-warm-runtime openhands

- Move git config from action execution server to runtime client
- Add setup_git_config() method to Runtime base class
- Update all runtime implementations to call git config after connection
- Remove git parameters from ActionExecutor and startup commands
- Ensure git config works for both fresh and warm runtimes

This fixes the bug where git operations would fail in warm runtimes
because git configuration was lost when warm runtimes were claimed.
- Replace environment variable check with explicit is_local_runtime parameter
- Local and CLI runtimes pass is_local_runtime=True
- Remote, Kubernetes, and Docker runtimes use default is_local_runtime=False
- Cleaner and more explicit runtime type detection
- Updated documentation to reflect the change
- Replace is_local_runtime with is_cli_runtime parameter
- CLI runtime now skips git config to preserve user's local settings
- Local runtime detection uses class name instead of parameter
- CLI runtime runs on user's machine and should respect existing git config
- Other runtimes (Local, Remote, Kubernetes, Docker) continue to set git config
- Updated documentation to reflect CLI runtime behavior
- All runtimes (Local, Remote, Kubernetes, Docker) now use global git config
- Removed complex platform-specific file-based config logic
- CLI runtime still skips git config to preserve user settings
- Simpler and more consistent approach across all runtime types
- Remove documentation from git tracking
- Update global config with git_user_name and git_user_email from settings
- Apply git configuration to all active runtimes when git settings are updated
- Update session config to ensure consistency across runtime operations
- Add error handling and logging for git configuration updates

This completes the nested runtime settings workflow:
1. Warm runtime starts without git configuration (deploy repo change)
2. User settings sent via POST /api/settings when runtime is claimed
3. Git configuration now applied immediately to the runtime
4. All subsequent commits use correct user identity

Fixes the issue where user git settings were received but not applied
to the runtime's git configuration.

Co-authored-by: openhands <openhands@all-hands.dev>
INIT_COMMANDS.append(
f'git config --global user.email "{self.git_user_email}"'
)
# Git configuration is now handled by the runtime client after connection
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Suggested change
# Git configuration is now handled by the runtime client after connection

- Chain git config commands together for efficiency (single cmd run instead of two)
- Simplify settings route by removing complex session update logic
- Remove documentation file and .gitignore entry as requested
- Git configuration will be applied when new sessions are initialized

This maintains the core functionality while making the code cleaner
and more efficient.

Co-authored-by: openhands <openhands@all-hands.dev>
@xingyaoww xingyaoww changed the title Fix git configuration for warm runtime bug refactor(git): principled way to set git configuration for agents Aug 13, 2025
Copy link
Collaborator

@tofarr tofarr left a comment

Choose a reason for hiding this comment

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

Nice - setting the git user and email as part of the settings makes sense

- Git configuration now happens automatically during setup_initial_env()
- Removed all manual setup_git_config() calls from runtime implementations
- CLI runtime sets is_cli_runtime flag to skip git configuration
- Simplified git configuration workflow for all runtime types

Co-authored-by: openhands <openhands@all-hands.dev>
Copy link

openhands-ai bot commented Aug 13, 2025

Looks like there are a few issues preventing this PR from being merged!

  • GitHub Actions are failing:
    • Lint
    • Run Python Tests
    • Docker

If you'd like me to help, just leave a comment, like

@OpenHands please fix the failing actions on PR #10293 at branch fix-git-config-warm-runtime

Feel free to include any additional details that might help me get this PR into a better state.

You can manage your notification settings

@xingyaoww xingyaoww changed the title refactor(git): principled way to set git configuration for agents refactor(git): principled way to set git configuration for agents & re-enable git settings in UI Aug 13, 2025
xingyaoww and others added 3 commits August 13, 2025 14:37
Co-authored-by: openhands <openhands@all-hands.dev>
@xingyaoww xingyaoww marked this pull request as ready for review August 13, 2025 18:42
@xingyaoww xingyaoww requested a review from amanape as a code owner August 13, 2025 18:42
git_user_email = self.config.git_user_email

# Skip git configuration for CLI runtime to preserve user's local git settings
is_cli_runtime = self.config.runtime == 'cli'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this special case include ‘local’ too? Or the local nested needs it set… hmm, globally?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah - basically local nested runtime needs it set :(

Copy link
Collaborator

@enyst enyst left a comment

Choose a reason for hiding this comment

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

I liked the other option too, sending git user/email in the RecallObs, but this is okay too.

It does seem to mean that if users use ‘local’ runtime, their global git config will be overwritten, though?

@xingyaoww
Copy link
Collaborator Author

It does seem to mean that if users use ‘local’ runtime, their global git config will be overwritten, though?

@enyst yes.. but now with CLI, i wonder if there's an actual use case for the standalone usage of local runtime though?

xingyaoww and others added 2 commits August 13, 2025 14:55
- Updated test_git_config_in_command_generation to test_git_config_not_in_command_generation
- Updated test_git_config_with_special_characters to test_git_config_with_special_characters_not_in_command
- Tests now correctly verify that git config is NOT passed as command-line arguments
- Git configuration is handled by runtime base class via git config commands, not CLI args
- All git config tests now pass (5/5)

Co-authored-by: openhands <openhands@all-hands.dev>
@xingyaoww xingyaoww enabled auto-merge (squash) August 13, 2025 19:10
@enyst
Copy link
Collaborator

enyst commented Aug 13, 2025

It does seem to mean that if users use ‘local’ runtime, their global git config will be overwritten, though?

@enyst yes.. but now with CLI, i wonder if there's an actual use case for the standalone usage of local runtime though?

That's a good point, except for Windows... I don't know if CLI works well on Windows
Cc: @li-boxuan

@xingyaoww
Copy link
Collaborator Author

@enyst happy to fix it follow-up PR if i eventually break it on windows.. But on the other hand, if CLI breaks on Windows, we should just fix the CLI, right 😄

- Removed '.git_config' assertions from test_multiple_multiline_commands and test_multi_cmd_run_in_single_line
- Git configuration is now handled by runtime base class via git config commands, not by creating .git_config files
- Windows tests now correctly reflect current architecture where git config is not stored as workspace files
- Tests focus on command execution functionality rather than git file presence

Co-authored-by: openhands <openhands@all-hands.dev>
@li-boxuan
Copy link
Collaborator

It does seem to mean that if users use ‘local’ runtime, their global git config will be overwritten, though?

@enyst yes.. but now with CLI, i wonder if there's an actual use case for the standalone usage of local runtime though?

Yes, headless mode with local runtime is how OpenHands works in terminal-bench harness. That being said, if openhands-cli can be made fully autonomous (non-interactive), I guess headless mode can be deprecated.

CLI worked on windows when I used it last time so I don’t think windows will be a concern.

@xingyaoww xingyaoww merged commit d256348 into main Aug 13, 2025
21 of 27 checks passed
@xingyaoww xingyaoww deleted the fix-git-config-warm-runtime branch August 13, 2025 20:45
JiseungHong added a commit to JiseungHong/OpenHands that referenced this pull request Aug 14, 2025
enyst pushed a commit that referenced this pull request Aug 15, 2025
…e-enable git settings in UI (#10293)

Co-authored-by: openhands <openhands@all-hands.dev>
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.

5 participants









ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/All-Hands-AI/OpenHands/pull/10293

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy