Repository navigation
fix(agent-server): fall back to shared workspace on unborn worktree base - #6216
Open
xxwtiancai wants to merge 2 commits into
Open
xxwtiancai wants to merge 2 commits into
xxwtiancai wants to merge 2 commits into
Conversation
A context-window-rejected agent call emits a CondensationRequest and the condenser answers with a Condensation, but nothing ever stopped that cycle: _is_stuck_context_window_error was an unconditional stub, so a conversation whose prompt never fits kept burning one rejected agent call plus one summarizer call per iteration until max_iteration_per_run. Implement the detection: the run is stuck when every event in the trailing window after the last user message belongs to such rejected-call/condensation cycles, with at least one CondensationRequest (which proactive token/event-pressure condensation does not emit) and no action, observation, or agent message between them. The existing 10-event scenario gate and the STUCK run-loop exit bound the detection; a user message still resets the window. Fixes OpenHands#6104
A fresh parent conversation initializes its workspace as a git repository without committing, so HEAD is unborn. The worktree planner accepted the repository anyway and `git worktree add ... HEAD` failed with HTTP 500 on the default child launch, instead of using the existing shared-workspace fallback. The planner now resolves the worktree start point and, for the default base, verifies it resolves to a commit: an unborn HEAD (exit code 1) produces no plan, so the child shares the parent's directory and reports isolation "shared". Explicit head/ref bases keep their current error semantics, any other git failure still propagates, and the plan carries the selected ref (not a resolved hash) so remote branch tracking configuration survives. Fixes OpenHands#6186
xxwtiancai
marked this pull request as ready for review
October 25, 2026 09:17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
HUMAN:
Problem: Launching a child workspace on an unborn HEAD fails with an unhandled HTTP 500 error.
Fix: Resolves the default base ref first, falling back to shared workspace on unborn HEADs while keeping explicit ref errors strict.
Verification: Verified against live server regression: child launch succeeds with HTTP 201 and isolation: "shared" without fake commits.
AGENT:
Why
A normal parent conversation in an empty workspace initializes Git without making a commit. Creating a child with the default
worktreeisolation then failed with HTTP 500: the worktree planner accepted the repository, butgit worktree add ... HEADcannot branch from an unborn HEAD. Explicitisolation: sharedavoided the failure, so only the default path was broken. Fixes #6186.Summary
_plan_conversation_worktreenow resolves the worktree start point at plan time and, for the defaultbase="default_branch", verifies it resolves to a commit (git rev-parse --verify --quiet <ref>^{commit}). Exit code 1 — the unborn HEAD of a repository initialized without a commit — produces no plan, so conversation creation uses the existing shared-workspace fallback and the response reportsisolation: "shared". Any other git failure still propagates, so other Git errors are not silently treated as an empty repository.base="head"/base="ref"keep their current error semantics; a missing explicitly requested ref remains an error.git worktree addpreserves remote branch tracking configuration on the new branch.isolationfield descriptions inStartChildConversationRequestand thestart_child_conversationtool to say "git repository with a usable base commit". The TypeScript client's generated schema intentionally stays untouched here — it is generated from the pinned released Agent Server image and is refreshed by the post-release version-bump workflow.Issue Number
Fixes #6186
How to Test
New coverage (the live-server test and the unborn-HEAD planner test both fail with the original
GitCommandError: git worktree add ... HEAD/ HTTP 500 before the change and pass after):test_child_launch_in_fresh_workspace_preserves_unborn_repository(real HTTP server): fresh parent →.gitexists with unborn HEAD → default child launch returns 201 withisolation: "shared"and the parent link; no initial commit is invented and the pre-existing file plus unborn repository survive child launch and cleanup.start_point == "origin/<default>"(worktree isolation retained); explicitbase="head"on an unborn repo → plan still produced and_create_conversation_worktreestill raises (current semantics preserved).Full files pass after the change:
tests/agent_server/test_conversation_service.py(141),tests/cross/test_remote_conversation_live_server.py(34 passed, 1 skipped),tests/agent_server/test_parent_child_conversations.py+tests/tools/child_conversation(31). Pre-commit (ruff, pycodestyle, pyright, import rules) passes on all changed files.Video/Screenshots
Non-visual bug; reproduction notes instead of media:
POST /api/conversations/{id}/children→ HTTP 500 fromgit worktree add -b openhands/<child-id> ... HEAD(fatal: invalid reference: HEAD).isolation: "shared".Type