Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions docs/agent-profile-upgrade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Upgrade Enterprise Agent Profiles

This release adopts the SDK 1.58.1 launch contract. The Enterprise Python SDK,
agent-server and tools packages, the lint environment, and the bundled sandbox
image must use the same released version. External Helm/runtime-api image pins
must be updated by their deployment owner as well.

## Before deploying

1. Back up the database, encryption key configuration and current application/image versions.
2. Freeze settings and profile writes before starting any new application pods.
Stop integration workers that can save settings too. Keep the freeze in place
until every old application pod and writer has stopped.
3. Run `uv run python -m scripts.audit_agent_profiles` against the target database
with the new release's normal database and encryption configuration. It is
read-only and prints only organization/profile ids and finding counts.
An exit status of 2 requires repair or a compatible newer release before
proceeding. Never delete opaque profiles to make the audit pass.
4. Run `uv run alembic heads` and verify one head. The profile-tools migration is
revision 200 after the personal-profile column in 199. Do not reuse or edit the released revision 175.

A rolling update with unrestricted old writers is unsafe: older releases can
remove profiles they cannot parse when saving an envelope. The new release
preserves those opaque entries, but cannot change writers that still run old
code. This upgrade therefore requires a write freeze and a complete writer
cutover, rather than relying on mixed-version saves.

## Migration and cutover

Run `uv run alembic upgrade head` with the writes still frozen. Revision 200
changes only OpenHands profiles at a known legacy schema version (missing, 1 or
2) whose `tools` is `[]`: those old Cloud profiles always launched the standard
set, so they become `tools: null`. Current profiles at version 3 retain a
purposefully empty list. Nonempty tool selections, ids, active pointers, future
versions and invalid version markers are preserved.

The migration reports scanned, migrated and unreadable organization counts and
logs only ids for unreadable envelopes. A successful Alembic run with unreadable
rows is not a clean preflight. Rerun the read-only audit and resolve every blocking
finding before enabling profile writes. Invalid active profiles now reject
launches instead of falling back to broader settings; ordinary settings remain
readable for repair.

Start the new application pods and workers, verify their installed packages and
sandbox images, then unfreeze writes. Validate a profile with no tools, a profile
with selected tools, an ACP profile, a scoped secret list and a missing reference.
Check materialize versus actual launch, persona/suffix preservation and child
conversation profile inheritance.

Existing conversations remain readable. New launches into older/custom sandboxes
require SDK >=1.54.0 and return an actionable upgrade error otherwise. Replace
those sandboxes using the normal lifecycle; do not assume changing the default
image upgrades an already running sandbox.

## Rollback

After profile writes resume, do not roll back to an older application image that
cannot preserve version-3 or opaque entries. Keep writers frozen and roll forward
to a compatible image. If an older image is unavoidable, restore the pre-upgrade
database snapshot and matching encryption configuration together, accounting for
all writes since that backup. Alembic downgrade does not reconstruct the meaning
of an old empty tool list and is not a data rollback.

## Compatibility boundaries

OpenHands launches use the supported raw-agent transport because SDK 1.58.1
settings cannot carry the web sandbox's `cli_mode: false` security prompt flag,
PLAN presets or request-level raw prompts. The app builds from resolved profile
settings and uses the sandbox's advertised browser availability with the SDK tool
resolver. Explicit tool selections remain authoritative; defaults retain model
switching even when the optional child-conversation launcher is enabled. The
sandbox still finalizes runtime context (including time, memory and skills).
ACP launches continue to forward resolved settings for runtime finalization.

Profile secret selection filters stored, integration and request-provided secrets.
The Azure DevOps credential-helper token written during repository setup remains
registered for output masking even when omitted from that selection. Profile
secret selection does not revoke credentials already present in the workspace.

Profile MCP selection filters the user's configured MCP catalog, as defined by
the SDK. Enterprise's platform MCP integration remains a separate serving-layer
integration. Exact parent MCP inheritance within task/workflow delegates is
upstream work in software-agent-sdk#5743; this release preserves the SDK's
existing delegation scope rules.

Canvas's default-profile migration and editor gating are owned by
OpenHands/OpenHands#17991. This backend release does not remove the Canvas default
branch or claim that adding client skills produces catalog parity.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
Data migration: no backfill. Existing rows read back as ``NULL`` (an empty
collection); a member sees only the org profiles until they save a personal one.

Revision ID: 198
Revises: 197
Revision ID: 199
Revises: 198
Create Date: 2026-10-24
"""

Expand All @@ -23,8 +23,8 @@
import sqlalchemy as sa
from alembic import op

revision: str = '198'
down_revision: str | None = '197'
revision: str = '199'
down_revision: str | None = '198'
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None

Expand Down
84 changes: 84 additions & 0 deletions migrations/versions/200_unset_empty_agent_profile_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
"""Store agent profiles' empty ``tools`` as unset.

``[]`` selects no tools while ``null`` selects the standard set; existing
``[]`` rows were saved meaning the standard set.

Revision ID: 200
Revises: 199
Create Date: 2026-09-30 00:00:00.000000
"""

import json
import logging
from typing import Any, Sequence

import sqlalchemy as sa
from alembic import op

revision: str = '200'
down_revision: str | None = '199'
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None

logger = logging.getLogger(__name__)


def _schema_version(profile: dict[str, Any]) -> int:
version = profile.get('schema_version', 1)
if type(version) is int and version in (1, 2):
return version
return 3


def _unset_empty_tools(agent_profiles: dict[str, Any]) -> bool:
changed = False
for profile in (agent_profiles.get('profiles') or {}).values():
if (
isinstance(profile, dict)
and profile.get('agent_kind', 'openhands') == 'openhands'
and profile.get('tools') == []
and _schema_version(profile) < 3
):
profile['tools'] = None
changed = True
return changed


def upgrade() -> None:
from storage.encrypt_utils import decrypt_value, encrypt_value

bind = op.get_bind()
rows = bind.execute(
sa.text('SELECT id, agent_profiles FROM org WHERE agent_profiles IS NOT NULL')
).mappings()
scanned = migrated = skipped = 0
for row in list(rows):
scanned += 1
try:
agent_profiles = json.loads(decrypt_value(row['agent_profiles']))
if not isinstance(agent_profiles, dict) or not _unset_empty_tools(
agent_profiles
):
continue
except Exception:
skipped += 1
logger.warning('Skipping org %s: unreadable agent_profiles', row['id'])
continue
bind.execute(
sa.text('UPDATE org SET agent_profiles = :agent_profiles WHERE id = :id'),
{
'agent_profiles': encrypt_value(json.dumps(agent_profiles)),
'id': row['id'],
},
)
migrated += 1
logger.info(
'Agent profile tool migration: scanned=%s migrated=%s unreadable=%s',
scanned,
migrated,
skipped,
)


def downgrade() -> None:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from typing import TYPE_CHECKING, Any, AsyncGenerator
from uuid import UUID

from openhands.sdk.settings import ACPAgentSettings, OpenHandsAgentSettings

if TYPE_CHECKING:
import httpx

Expand Down Expand Up @@ -323,7 +325,7 @@ def _merge_skills(self, skill_lists: list[list[Skill]]) -> list[Skill]:
async def _load_skills_and_update_agent(
self,
sandbox: SandboxInfo,
agent: Agent,
agent: Agent | OpenHandsAgentSettings | ACPAgentSettings,
remote_workspace: AsyncRemoteWorkspace,
selected_repository: str | None,
project_dir: str,
Expand Down
Loading
Loading