Skip to content

fix(agent-profiles): honor profile settings in cloud launches - #15228

Merged
simonrosenberg merged 11 commits into
mainfrom
fix-agent-profile-launch-snapshot
Jul 16, 2026
Merged

simonrosenberg merged 11 commits into
mainfrom
fix-agent-profile-launch-snapshot

Conversation

@simonrosenberg

@simonrosenberg simonrosenberg commented Jul 10, 2026 •

Copy link
Copy Markdown
Member

HUMAN:

  • A human has tested these changes.

AGENT:

Implemented and verified by Codex.


What this fixes

In simple terms: selecting an Agent Profile in OpenHands Cloud did not fully control the agent that launched.

Cloud correctly resolved the selected profile, but later launch code replaced parts of it. This could remove the profile's instructions, replace its chosen tools, and prevent tools: [] from creating a bare agent. The profile was also resolved a second time for provenance, so an edit made during startup could make the recorded profile revision differ from the settings that actually launched.

User-visible behavior

  • Profile instructions are preserved and launch-specific instructions are appended to them.
  • tools: null receives the normal cloud and browser tools.
  • tools: [] launches a deliberately bare agent.
  • An explicit tool list is preserved exactly.
  • Profile context, secrets, skills, and disabled skills are retained and merged with launch data.
  • Explicit per-conversation profile selection does not change the member's ambient active profile.
  • ACP/OpenHands selection and displayed profile provenance come from the same settings snapshot that built the agent.
  • Planning launches deliberately continue to use the constrained planning toolset, even if the profile is otherwise bare.
  • A profile that disables the switch-LLM tool remains authoritative even when the member has multiple saved LLM profiles.

There are no new UI components or API-contract changes. Existing UI that shows the launched Agent Profile now receives reliable profile ID and revision data.

Implementation

  • Resolve one launch snapshot per conversation-start attempt.
  • Thread that snapshot through OpenHands/ACP branching, agent construction, disabled-skill filtering, provider decisions, and provenance stamping.
  • Treat the resolved profile as the base configuration and apply cloud launch data additively.
  • Preserve the existing managed LLM and MCP overlays.
  • Let the SDK profile resolver own built-in switch-LLM tool gating instead of re-enabling the tool later in cloud launch code.

Validation

Real local HTTP validation

Started a local app-server harness using the production stream-start router, LiveStatusAppConversationService, SaasSettingsStore, and SDK profile resolver. It sent real requests to a separately running OpenHands agent-server through POST /api/conversations. Only cloud sandbox allocation/workspace bootstrap was replaced with a fixed local sandbox descriptor.

Five conversation launches reached READY:

  1. Ambient bare profile: zero tools; profile, request, and host instructions were composed; launch secrets and disabled skills survived; provenance recorded the ambient profile at revision 1.
  2. Explicit profile override: only terminal was present; the referenced MCP server was retained; provenance recorded the override while the ambient pointer remained unchanged.
  3. Default-tools profile: cloud defaults included terminal, file editor, task tracker, and browser tools.
  4. Planning launch from the bare profile: only the constrained planning tools were present and the planning prompt/instructions were retained.
  5. ACP profile: provider, model, MCP configuration, secrets, ACP tag, and profile provenance all matched the resolved profile.

The instrumentation recorded five resolved-profile loads for five starts: exactly one per conversation-start attempt.

Local automated checks

  • 148 passed: app-conversation service tests under pytest --forked -n 4.
  • 45 passed: enterprise Agent Profile tests under pytest --forked -n 4.
  • Root and enterprise pre-commit checks passed on all touched files, including Ruff, formatting, and mypy.
  • The five profile-focused app-conversation tests pass after the switch-tool regression coverage was added.
  • The broader SaaS settings/auth regression suites also passed; their existing aiosqlite event-loop shutdown warnings remain unchanged.

During review, the first CI run exposed a nondeterministic UUID generated during pytest collection. The parametrization was made deterministic and the production-style xdist topology was rerun locally.

GitHub CI

Current head 41c038438 completed all required CI checks successfully, including root and enterprise Python tests and lint, frontend lint, package/version checks, coverage, and app/enterprise image builds for both architectures.

Issues

Closes OpenHands/enterprise#59
Closes OpenHands/enterprise#51

Related: OpenHands/software-agent-sdk#3713 and OpenHands/software-agent-sdk#3978.

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Video/Screenshots

Not applicable; this is a backend correctness change with no visual layout changes.


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   --name openhands-app-45ed7cb   docker.openhands.dev/openhands/openhands:45ed7cb

@github-actions github-actions Bot added the type: fix A bug fix label Jul 10, 2026
@simonrosenberg
simonrosenberg marked this pull request as ready for review July 10, 2026 09:51
@github-actions

github-actions Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  openhands/app_server/app_conversation
  live_status_app_conversation_service.py 222-225, 234-252, 294-296, 310-314, 484-491, 571-591, 1722-1725, 1749-1759, 1820-1858, 2070-2073, 2155-2164
Project Total  

This report was generated by python-coverage-comment-action

@simonrosenberg simonrosenberg self-assigned this Jul 10, 2026
@simonrosenberg simonrosenberg added the qa-this Trigger OpenHands QA validation label Jul 10, 2026
@simonrosenberg simonrosenberg changed the title fix(agent-profiles): preserve cloud launch snapshot fix(agent-profiles): honor profile settings in cloud launches Jul 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

👋 Thanks for opening this PR!

Before review, please add a short note in the HUMAN: section at the top of the PR description telling maintainers, in your own words, what this PR does.

Please put that note between HUMAN: and the - [ ] A human has tested these changes. checkbox.

@enyst enyst left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Left a little nit question inline. We are trying to use stronger types, because they help the agent; they enable the agent-generated code to hit errors when it makes weird stuff, thus I think maybe it reduces the potential for avoidable bugs.

In other codebases, agent-sdk and openhands-cli I’m pretty sure, we have really tried to avoid getattr and the like as much as possible. I think not so much in the openhands codebase, it’s an older more chaotic codebase… but IMHO it’s not too late to start, if we can.

@simonrosenberg simonrosenberg added review-this Use OpenHands to review the PR qa-this Trigger OpenHands QA validation and removed qa-this Trigger OpenHands QA validation labels Jul 10, 2026
@simonrosenberg simonrosenberg added qa-this Trigger OpenHands QA validation and removed qa-this Trigger OpenHands QA validation labels Jul 13, 2026

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

✅ QA Report: PASS

Verified the Agent Profile launch path before/after the PR; the PR preserves profile-selected tools and context while keeping planning launches constrained.

Does this PR achieve its stated goal?

Yes. On origin/main, the same launch scenarios reproduced the reported bug: a bare profile (tools: []) and an explicit terminal-only profile both launched with the default cloud toolset, profile context was dropped, and SwitchLLMTool was re-added despite the profile disabling it. On PR head 41c038438, actual app-conversation start-request construction preserved tools: [], explicit tools, profile suffixes, secrets, skills, disabled skills, and the switch-LLM gate; planning launches still used only planning tools.

Phase Result
Environment Setup ✅ uv sync --frozen completed and the backend launch path imported successfully.
CI Status ✅ All sampled GitHub checks were green; only qa-changes was in progress because this QA review was running.
Functional Verification ✅ Before/after execution showed the bug on base and fixed behavior on the PR.
Functional Verification

Test 1: resolved Agent Profile settings drive the launched agent

Step 1 — Reproduce / establish baseline without the fix:

Ran the harness against origin/main after creating a detached worktree:

git worktree add -f --detach /tmp/oh-main origin/main
cd /tmp/oh-main
PYTHONPATH=/tmp/oh-main /home/runner/work/OpenHands/OpenHands/pr-repo/.venv/bin/python /tmp/qa_agent_profile_launch.py

Relevant output:

{
  "bare_profile": {
    "tool_count": 4,
    "tool_names": ["terminal", "file_editor", "task_tracker", "browser_tool_set"],
    "system_suffix": "REQUEST_SUFFIX",
    "secret_names": ["LAUNCH_SECRET"],
    "skill_names": [],
    "disabled_skills": [],
    "include_default_tools": ["FinishTool", "ThinkTool", "SwitchLLMTool"]
  },
  "explicit_tools_profile": {
    "tool_count": 4,
    "tool_names": ["terminal", "file_editor", "task_tracker", "browser_tool_set"]
  }
}

This confirms the bug: profile-selected tools and profile context were overwritten by cloud launch defaults, and the disabled switch-LLM tool was restored.

Step 2 — Apply the PR's changes:

Checked out the PR head already present in the workspace: 41c038438eb4637e04a45ab2eb062260d4ee02ff.

Step 3 — Re-run with the fix in place:

Ran the same harness against the PR checkout:

cd /home/runner/work/OpenHands/OpenHands/pr-repo
uv run python /tmp/qa_agent_profile_launch.py

Relevant output:

{
  "bare_profile": {
    "tool_count": 0,
    "tool_names": [],
    "system_suffix": "PROFILE_SUFFIX\n\nREQUEST_SUFFIX",
    "secret_names": ["LAUNCH_SECRET", "PROFILE_SECRET"],
    "skill_names": ["profile-skill"],
    "disabled_skills": ["member-disabled-skill", "disabled-profile-skill"],
    "include_default_tools": ["FinishTool", "ThinkTool"]
  },
  "default_tools_profile": {
    "tool_count": 4,
    "tool_names": ["terminal", "file_editor", "task_tracker", "browser_tool_set"]
  },
  "explicit_tools_profile": {
    "tool_count": 1,
    "tool_names": ["terminal"]
  }
}

This shows the PR fixes the core launch behavior: tools: [] stays bare, tools: null still gets cloud defaults, explicit tools are preserved, profile and launch context are merged, and the profile-disabled switch-LLM tool remains disabled.

Test 2: planning launches remain constrained

The same before/after harness also exercised a planning launch from a bare profile. On origin/main, planning already used the planning-only toolset but lost the profile suffix. On PR head, planning still launched with only planning tools and retained the profile context:

{
  "planning_from_bare_profile": {
    "tool_count": 3,
    "tool_names": ["glob", "grep", "planning_file_editor"],
    "system_suffix": "PROFILE_SUFFIX\n\n<IMPORTANT_PLANNING_BOUNDARIES>...\n\nREQUEST_SUFFIX"
  }
}

This confirms the PR did not regress the intentionally constrained planning toolset while fixing profile context preservation.

Issues Found

None.

AI disclosure: This QA review was created by an AI agent (OpenHands) on behalf of the requester.

@simonrosenberg
simonrosenberg requested a review from enyst July 16, 2026 10:25
@enyst

enyst commented Jul 16, 2026

Copy link
Copy Markdown
Member

@OpenHands do a /codereview-roasted on this pr. post your feedback as a review on gh api

@openhands-ai

openhands-ai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Uh oh! There was an unexpected error starting the job :(

@enyst enyst left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi — I’m OpenHands-GPT-5.6 on Engel’s MacBook.

🟢 Good taste

I independently traced the launch path against the SDK 1.36.0 contracts and found no blocking issue. The change resolves one launch snapshot and consistently reuses it for agent selection, construction, disabled-skill filtering, ACP metadata, and profile provenance. That removes the prior time-of-check/time-of-use mismatch without adding another source of truth.

The OpenHands branch now preserves the profile’s tri-state tool semantics (None = cloud defaults, [] = deliberately bare, explicit list = exact list), uses the resolved AgentContext as the base while additively composing launch suffixes and secrets, and leaves switch-LLM gating to the SDK setting. The ACP branch likewise keeps the resolved profile settings and deny-list while applying launch-only context. The explicit planning-tool override is clear and intentional.

The regression coverage exercises the important boundaries: tri-state tools, profile/member skill exclusions, profile and launch context composition, switch-tool disablement, planning launches, ACP context, one resolution per start, and matching provenance. The PR also includes concrete runtime evidence, and all required checks pass on the reviewed head.

[RISK ASSESSMENT]

  • [Overall PR] ⚠️ Risk Assessment: 🟡 MEDIUM
    This touches the central cloud conversation-start path and both OpenHands and ACP launch behavior, so the blast radius is meaningful. The implementation is narrowly scoped, preserves existing launch overlays, adds strong regression coverage, and has successful end-to-end and CI validation, which keeps the residual risk controlled.

VERDICT:
✅ Worth merging: The profile is now the authoritative launch base, while cloud-only overlays remain explicit and additive.

KEY INSIGHT:
A single resolved snapshot eliminates both configuration drift during startup and provenance drift after startup.

AI disclosure: This review was generated by OpenHands on Engel’s behalf.

@simonrosenberg
simonrosenberg merged commit cba5788 into main Jul 16, 2026
21 checks passed
@simonrosenberg
simonrosenberg deleted the fix-agent-profile-launch-snapshot branch July 16, 2026 11:42
@openhands-release-bot openhands-release-bot Bot added the released: cloud-1.47.0 Shipped in cloud-1.47.0 label Jul 21, 2026
@openhands-release-bot

Copy link
Copy Markdown
Contributor

🚀 Released in cloud-1.47.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

qa-this Trigger OpenHands QA validation released: cloud-1.47.0 Shipped in cloud-1.47.0 review-this Use OpenHands to review the PR type: fix A bug fix

Projects

None yet

3 participants