Repository navigation
fix(sdk): add v1->v2 settings migration that canonicalizes agent_kind - #3069
Conversation
Python API breakage checks — ✅ PASSEDResult: ✅ PASSED |
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
Coverage Report •
|
||||||||||||||||||||
The v1.19.0 LLMAgentSettings -> OpenHandsAgentSettings rename changed the canonical agent_kind discriminator from 'llm' to 'openhands' but did not bump the persisted-settings schema_version or register a migration. Persisted rows that still carry the legacy agent_kind='llm' now break callers that validate against the canonical OpenHandsAgentSettings class (or that route through the discriminated union expecting routing to match the deployed code path). This is an in-band incident triage: - enterprise/server/routes/org_models.py OrgResponse.from_org and OrgDefaultsSettingsResponse.from_org go through AgentSettings from_persisted, which already runs schema migrations on load. They inherit the fix automatically once this migration ships. - The point hot-fix in OpenHands/OpenHands#14263 (force agent_kind='openhands' in OrgStore.get_agent_settings_from_org) becomes redundant on top of this migration. Changes: - Bump AGENT_SETTINGS_SCHEMA_VERSION 1 -> 2. - Register _migrate_agent_settings_v1_to_v2 that rewrites legacy agent_kind='llm' to 'openhands'. The two classes are field- compatible (LLMAgentSettings only narrows the discriminator literal), and LLMAgentSettings is scheduled for removal in v1.22.0, so canonicalizing on read is safe and consistent with the deprecation direction. - Update existing migration tests for the new current_version (the v1 -> v2 step bumps schema_version on every from_persisted call, including the v0 entry-point and the ACP no-op path). - Add test for the new canonicalization migration. Co-authored-by: openhands <openhands@all-hands.dev>
f88f559 to
6c23aab
Compare
all-hands-bot
left a comment
There was a problem hiding this comment.
🟢 Good taste - Clean migration fix following established patterns
This PR correctly implements the missing v1→v2 schema migration to canonicalize the deprecated agent_kind: 'llm' discriminator to 'openhands'. The implementation follows the existing migration framework pattern and includes proper test coverage.
[RISK ASSESSMENT]
- [Overall PR]
⚠️ Risk Assessment: 🟢 LOW
This is a targeted data migration that fixes a production incident. The change:
- Follows the existing migration framework pattern (
_migrate_agent_settings_v1_to_v2registered at version 1) - Only canonicalizes a discriminator value between field-compatible classes (
LLMAgentSettings→OpenHandsAgentSettings) - Is backward compatible (reads old persisted data correctly without losing fields)
- Has good test coverage including the new migration path
- Makes no changes to runtime agent behavior or evaluation-affecting logic
VERDICT:
✅ Worth merging: Clean fix for a production incident with appropriate test coverage and no design concerns.
KEY INSIGHT:
This demonstrates the importance of bumping schema versions and registering migrations whenever persisted data contracts change—even for "cosmetic" changes like renaming classes or narrowing discriminator literals. The missing v1→v2 migration turned a field-compatible refactor into a production incident. Consider adding a CI check that detects discriminator literal changes in persisted models and requires a corresponding schema version bump.
all-hands-bot
left a comment
There was a problem hiding this comment.
✅ QA Report: PASS
The migration correctly canonicalizes agent_kind: 'llm' → 'openhands' and resolves the production incident.
Does this PR achieve its stated goal?
Yes. The PR successfully adds a v1→v2 settings migration that canonicalizes the deprecated agent_kind: 'llm' discriminator to the canonical 'openhands' value. This fixes the production incident where new cloud users encountered 500 errors because persisted org settings had agent_kind: 'openhands' (the post-v1.19.0 canonical value), but validation code expected agent_kind: 'llm'. With this migration in place, AgentSettings.from_persisted(...) now handles both legacy and canonical discriminator values correctly, eliminating the validation error that was causing the 500s.
| Phase | Result |
|---|---|
| Environment Setup | ✅ Dependencies installed, dev environment ready |
| CI Status | ✅ 21 passing, 7 pending (builds), 0 failing |
| Functional Verification | ✅ All migration scenarios verified end-to-end |
Functional Verification
Test 1: Legacy v1 payload with agent_kind='llm'
Step 1 — Establish the test case:
Simulates org settings created before the v1.19.0 LLMAgentSettings → OpenHandsAgentSettings rename.
from openhands.sdk import AgentSettings, OpenHandsAgentSettings
legacy_v1 = AgentSettings.from_persisted(
{"schema_version": 1, "agent_kind": "llm", "llm": {"model": "test-model"}}
)Step 2 — Verify migration output:
Type: OpenHandsAgentSettings
agent_kind: openhands
schema_version: 2
llm.model: test-model
Result: ✅ Migration correctly canonicalized 'llm' → 'openhands' and bumped schema_version to 2.
Test 2: Production incident scenario (new user with agent_kind='openhands')
Step 1 — Reproduce the production failure scenario:
Simulates the exact case that caused 500 errors: org settings persisted with agent_kind: 'openhands' (the canonical value) but schema_version: 1 (because they were created after the rename but before this migration was added).
new_user_data = {
"schema_version": 1,
"agent_kind": "openhands",
"llm": {"model": "anthropic/claude-sonnet-4"}
}
settings = AgentSettings.from_persisted(new_user_data)Step 2 — Verify the fix handles it correctly:
Type: OpenHandsAgentSettings
agent_kind: openhands
schema_version: 2
Result: ✅ The migration handles already-canonical payloads correctly (no-op for the discriminator, but still bumps schema_version).
Test 3: v0→v1→v2 migration chain
Step 1 — Test the full migration chain:
legacy_v0 = AgentSettings.from_persisted({"llm": {"model": "v0-model"}})Step 2 — Verify all migrations applied:
Type: OpenHandsAgentSettings
agent_kind: openhands
schema_version: 2
Result: ✅ The v0→v1→v2 migration chain works correctly.
Test 4: ACP agent (discriminator should not be affected)
Step 1 — Test non-LLM agent kind:
acp_v1 = AgentSettings.from_persisted(
{
"schema_version": 1,
"agent_kind": "acp",
"acp_command": ["npx", "-y", "claude-agent-acp"]
}
)Step 2 — Verify ACP discriminator unchanged:
Type: ACPAgentSettings
agent_kind: acp
schema_version: 2
Result: ✅ The migration correctly only rewrites 'llm' → 'openhands', leaving other discriminators untouched.
Test 5: Test suite validation
Ran the full settings test suite:
uv run pytest tests/sdk/test_settings.py -xvsOutput:
======================== 37 passed, 9 warnings in 0.11s ========================
Result: ✅ All 37 tests pass, including:
test_agent_settings_from_persisted_migrates_v0_llm_payload(updated to expectschema_version=2)test_agent_settings_from_persisted_canonicalizes_legacy_llm_kind(new test for v1→v2 migration)test_agent_settings_from_persisted_dispatches_current_acp_payload(updated to expectschema_version=2)test_agent_settings_from_persisted_rejects_newer_schema_version(updated to reject v3, not v2)
Issues Found
None.
…OpenHands#3069) Co-authored-by: openhands <openhands@all-hands.dev>
…OpenHands#3069) Co-authored-by: openhands <openhands@all-hands.dev>
Why
Production incident: new cloud users could sign up but were 500'd on every action. Root cause as identified by the on-call team:
Background: when the
LLMAgentSettings→OpenHandsAgentSettingsrename landed in v1.19.0, the canonical discriminator value flipped from"llm"to"openhands", but the persisted-settingsschema_versionwas not bumped and no migration was registered. The cloud'sfrom_orgcall sites already go throughAgentSettings.from_persisted(...), which runs the migration framework — they just hit no migration that would normalize the discriminator, so the legacy/canonical mismatch leaks through to validation.A point hot-fix already shipped on the cloud side (OpenHands/OpenHands#14263) that force-sets
agent_kind = 'openhands'inOrgStore.get_agent_settings_from_org. That becomes redundant once this migration ships.How migrations work in the SDK
The framework already exists in
openhands-sdk/openhands/sdk/settings/model.py:AgentSettingsandConversationSettingscarry aschema_version: intfield, with the current value pinned by module-level constantsAGENT_SETTINGS_SCHEMA_VERSION/CONVERSATION_SETTINGS_SCHEMA_VERSION.from_persisted(data)classmethod runs_apply_persisted_migrations(...), which readsschema_version(defaulting to0), then walks a registered{old_version: migrator_callable}dict until it reaches the current version. Each migrator is(dict) -> dictand must advanceschema_versionstrictly.validate_agent_settings) routes the payload to the correct concrete class.Until this PR there was exactly one migration:
v0 -> v1(added theagent_kindfield). The v1.19.0 rename should have come with av1 -> v2migration, but didn't. This PR adds it.Changes
AGENT_SETTINGS_SCHEMA_VERSION1 → 2._migrate_agent_settings_v1_to_v2that rewrites legacyagent_kind: 'llm'→'openhands'.LLMAgentSettingsis field-compatible withOpenHandsAgentSettings(it only narrows the discriminator literal).LLMAgentSettingsis scheduled for removal in v1.22.0, so canonicalizing on read just hastens what was already going to happen.AgentSettings.from_persisted(...)consistently lands on the canonicalOpenHandsAgentSettings/ACPAgentSettingsvariants regardless of how the data was originally persisted.current_version(thev0 → v1 → v2chain bumpsschema_version == 2on the v0-entry-point test, and the v1-entry-point ACP test now also lands onschema_version == 2).schema_version=2toschema_version=3.test_agent_settings_from_persisted_canonicalizes_legacy_llm_kindto exercise the new migration directly.How to test
Type
Notes
prepare-release.ymlworkflow per.github/workflows/README-RELEASE.md, so this PR intentionally does not touch anypyproject.tomlversions.agent_kind = 'openhands'inOrgStore.get_agent_settings_from_orgcan be reverted once this SDK release is consumed — the migration handles that case correctly throughfrom_persisted.schema_versionbump + matching migration. That's worth a follow-up — the existingapi-breakagechecker tracks public API surface, not persisted-shape semantics.This PR was created by an AI agent (OpenHands) on behalf of @robert-brennan during the incident response.
Agent Server images for this PR
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdknikolaik/python-nodejs:python3.13-nodejs22-slimgolang:1.21-bookwormPull (multi-arch manifest)
# Each variant is a multi-arch manifest supporting both amd64 and arm64 docker pull ghcr.io/openhands/agent-server:6c23aab-pythonRun
All tags pushed for this build
About Multi-Architecture Support
6c23aab-python) is a multi-arch manifest supporting both amd64 and arm646c23aab-python-amd64) are also available if needed