Skip to content

fix(agent-profiles): keep the member's agent kind in sync with the active agent profile (OHE-3851) - #1150

Merged
hieptl merged 2 commits into
mainfrom
hiep/ohe-3851-stale-member-agent_kind-after-switching-the-active-agent
Nov 5, 2026
Merged

hieptl merged 2 commits into
mainfrom
hiep/ohe-3851-stale-member-agent_kind-after-switching-the-active-agent

Conversation

@hieptl

@hieptl hieptl commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

HUMAN:

  • A human has tested these changes.

AGENT:


Why

Activating an agent profile only writes org_member.active_agent_profile_id. The agent_kind in org_member.agent_settings_diff keeps whatever onboarding or POST /api/v1/settings last wrote, and a plain SaasSettingsStore.load() composes agent_kind from that diff. After a user sets up an ACP agent and then switches the active agent profile back to OpenHands, the persisted view still says acp while the launch view runs OpenHands:

  • GET /api/settings reports ACP. When no active profile resolves, Canvas falls back to that value and shows the ACP model picker on the home page.
  • A launch with no active profile, for example after the active profile is deleted, runs the composed settings and starts an ACP conversation.
  • get_current_managed_llm_key, clear_stale_org_level_llm_key_if_managed and rotate_managed_llm_key classify from the plain load and bail for ACP. _maybe_refresh_managed_llm_key then logs skip_no_current_managed_key and never verifies or rotates a stale managed key on an OpenHands launch.

Summary

  • Activating a personal or organization profile now writes the profile's agent_kind into the member's agent_settings_diff when it differs from the composed kind. Only the discriminator is written: the profile's settings are still resolved at conversation start, and agent_settings_applied stays false.
  • Saving the active personal profile with a different kind does the same, because an overwrite keeps the profile id and the pointer never moves. Organization profiles are OpenHands-only, so they need no hook.
  • New tests in tests/unit/test_agent_profiles.py cover the switch back for the settings view, the managed-key check the launch refresh relies on, a kind-changing save, and a launch with no active profile.

Issue Number

OHE-3851. Fixes #1005.

How to Test

uv run python -m pytest tests/unit/test_agent_profiles.py
uv run python -m pytest tests/unit/test_saas_settings_store.py -k "managed_key or acp or agent_profile"

97 tests pass (the store tests start Postgres through Docker), and the 5 new tests fail on main. ruff 0.12.5, the version pre-commit pins, is clean, and mypy reports nothing new on the touched file.

To check it by hand on a cloud account:

  1. Finish onboarding with an ACP agent such as Codex. GET /api/settings returns agent_settings.agent_kind: "acp".
  2. In Settings > Agents, activate an OpenHands agent profile. GET /api/settings now returns "openhands".
  3. Delete that profile and start a new conversation from the home page. It starts as an OpenHands conversation, not an ACP one.
  4. Activate an ACP profile. GET /api/settings returns "acp" again.

I have not run this on a deployed environment yet.

Video/Screenshots

Backend only.

Type

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

Notes


Enterprise server image for this PR:

ghcr.io/openhands/enterprise-server:sha-729dcce

…tive agent profile (OHE-3851)

Activating an agent profile only moved the member's pointer, so the
agent_kind in org_member.agent_settings_diff kept whatever onboarding or
POST /api/v1/settings last wrote. After an ACP setup and a switch back to
an OpenHands profile, a plain settings load still composed agent_kind
"acp":

- GET /api/settings reported ACP, so Canvas showed the ACP model picker.
- A launch with no active profile ran the composed settings and started
  an ACP conversation.
- The managed-key helpers classify from the plain load, so the launch-time
  refresh skipped the member and never verified or rotated a stale
  managed key.

Activation now writes the profile's agent_kind into the member diff when
it differs from the composed kind, for personal and organization profiles.
Saving the active personal profile with a different kind does the same,
because an overwrite keeps the profile id and the pointer never moves.
Nothing else from the profile is written; its settings are still resolved
at conversation start.
@github-actions github-actions Bot added the type: fix A bug fix label Nov 3, 2026
@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  server/routes
  agent_profiles.py 514, 813
Project Total  

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

@hieptl
hieptl marked this pull request as ready for review November 4, 2026 07:34

@tofarr tofarr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🍰

@hieptl
hieptl merged commit 08d9cff into main Nov 5, 2026
22 checks passed
@hieptl
hieptl deleted the hiep/ohe-3851-stale-member-agent_kind-after-switching-the-active-agent branch November 5, 2026 14:31
@openhands-release-bot openhands-release-bot Bot added the released: 1.87.0 Shipped in 1.87.0 label Nov 5, 2026
@openhands-release-bot

Copy link
Copy Markdown
Contributor

🚀 Released in 1.87.0.

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

Labels

released: 1.87.0 Shipped in 1.87.0 type: fix A bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stale member agent_kind after switching the active agent profile from ACP back to OpenHands disables managed-key refresh

2 participants