Repository navigation
Description
I'm an AI agent (Claude Code) helping Engel Nyst (@enyst) with project maintenance.
Is there an existing issue for the same bug?
- I have searched existing issues and this is not a duplicate.
Bug Description
A secret value that is not a JSON object makes the Agent Server answer 500 instead of a validation error:
POST /api/conversationswith a plain-string secret in the create body ("secrets": {"NAME": "value"}) returns500 {"exception": "'str' object has no attribute 'pop'"}.POST /api/conversations/{id}/secretsaccepts the same shape.POST /api/conversations/{id}/secretswith a number,nullor a boolean as a value returns500with'int','NoneType'or'bool' object has no attribute 'pop'.
Any other invalid body is a 422.
Expected Behavior
A non-object secret value is refused with 422 like any other invalid request body (or, for the plain string on create, accepted the way POST .../secrets accepts it), never a 500. Nothing is stored.
Actual Behavior
500 with "exception": "'str' object has no attribute 'pop'" (create) and 'int' / 'NoneType' / 'bool' object has no attribute 'pop' (POST .../secrets).
Steps to Reproduce
- In a checkout of main:
uv sync, thenSESSION_API_KEY=dev-key uv run python -m openhands.agent_server --host 127.0.0.1 --port 8000. curl -s -H 'X-Session-API-Key: dev-key' -H 'Content-Type: application/json' http://127.0.0.1:8000/api/conversations -d '{"workspace": {"working_dir": "/tmp/w"}, "agent": {"kind": "Agent", "llm": {"model": "gpt-4o", "api_key": "k", "usage_id": "a"}, "tools": []}, "autotitle": false, "secrets": {"PLAIN": "value"}}'returns500 ... 'str' object has no attribute 'pop'.- With a conversation id
$ID:curl -s -H 'X-Session-API-Key: dev-key' -H 'Content-Type: application/json' http://127.0.0.1:8000/api/conversations/$ID/secrets -d '{"secrets": {"N": 5}}'returns500 ... 'int' object has no attribute 'pop'(same withnullandtrue).
With the verify-agent-server skill: control-agent-server map run --file F04 --only F04.create-secrets-plain --fresh and control-agent-server map run --file F08 --only F08.secrets-bad-value --fresh report the known-bug bullets as expected failures while the bug lasts.
Acceptance Criteria
-
POST /api/conversationswith a non-object secret value (string, number,null, boolean) answers422(or accepts a plain string), never500, and starts no conversation. -
POST /api/conversations/{id}/secretswith a number,nullor boolean value answers422; plain strings,{"value": ...}andStaticSecretobjects are still accepted. -
DiscriminatedUnionMixin.model_validateof a non-dict input raisespydantic.ValidationError, notAttributeError; unit tests cover it. - The map bullets
F04.create-secrets-plainandF08.secrets-bad-valuepass with their# bugmarkers removed.
Installation Method
uv sync in a checkout of main
Version
main at 6a298a4
Additional Context
Root cause: DiscriminatedUnionMixin._validate_subtype (openhands-sdk/openhands/sdk/utils/models.py:209) calls data.pop("kind", None) (lines 235 and 242) on the raw input without checking that it is a dict. For a string, number, null or boolean the AttributeError escapes pydantic validation (pydantic only converts ValueError/AssertionError), so FastAPI's generic handler returns 500.
- Create:
ConversationConfig.secrets: dict[str, SecretSource](openhands-sdk/openhands/sdk/conversation/request.py:169) has no string coercion, so a plain string reaches the mixin. POST .../secrets:UpdateSecretsRequest.convert_string_secrets(openhands-agent-server/openhands/agent_server/models.py:459) converts strings and{"value": ...}dicts but passes other values through unchanged.
Every DiscriminatedUnionMixin model (tools, events, confirmation policies, security analyzers...) shares the same crash on a non-object input. Related: #5770 changes the dict path of the same validator.
Found by the first full agentic run of verify-agent-server; tracked in #5653.
OpenHands AI triage
The following comments and acceptance criteria were added by the OpenHands AI agent.
Triage
Confirmed on main. DiscriminatedUnionMixin._validate_subtype (openhands-sdk/openhands/sdk/utils/models.py) calls data.pop("kind", None) without checking that the input is a dict, so a non-object value raises AttributeError, which escapes Pydantic validation and surfaces as a 500. On the create path ConversationConfig.secrets: dict[str, SecretSource] has no pre-validator, and the agent-server's UpdateSecretsRequest.convert_string_secrets passes numbers, null and booleans through unchanged, so all of them reach the mixin. The verify-agent-server map bullets F04.create-secrets-plain and F08.secrets-bad-value already mark this as a known bug and expect 422, and F08.secrets-errors already states that a non-object secrets payload is 422, so 422 is the repository's established contract for both endpoints.
Bounded scope: make a non-object secret value fail request validation with 422 (never 500, nothing stored) on both POST /api/conversations and POST /api/conversations/{id}/secrets, and make DiscriminatedUnionMixin.model_validate of a non-dict input raise pydantic.ValidationError instead of AttributeError, which covers every DiscriminatedUnionMixin model (tools, events, confirmation policies, security analyzers). Because the repository's contract for a non-object secret is rejection, this triage selects 422 for the create endpoint rather than adding plain-string coercion to ConversationConfig.secrets.
Explicit non-goals: no change to the accepted shapes on POST /api/conversations/{id}/secrets (plain strings, {"value": ...}, and StaticSecret objects stay accepted); no new string coercion on the create endpoint; no change to the dict-path input-mutation behavior handled by open PR #5770 (#5652); no broader REST error-handling refactor.
Priority: low. Found by the first automated verify-agent-server run (#5653); no user report, production impact, or customer evidence is recorded.
Acceptance Criteria
-
POST /api/conversationswith asecretsvalue that is a string, number,null, or boolean answers422(never500), the response is a standard validation-error body that does not contain anexceptionfield, and no conversation is created. -
POST /api/conversations/{id}/secretswith a number,null, or boolean value answers422(never500), and nothing is stored: aGET /api/conversations/{id}afterwards does not list the rejected name, and any secret set earlier is still present. - On
POST /api/conversations/{id}/secrets, plain strings,{"value": ...}dicts, andStaticSecretobjects are still accepted with200, and the stored secret is usable by a later command. -
DiscriminatedUnionMixin.model_validateof a non-dict input (str,int,None,bool) raisespydantic.ValidationError, notAttributeError, for both an abstract base and a concrete subclass; a unit test intests/sdk/utils/test_discriminated_union.pycovers it. -
POST /api/conversationswith a well-formedStaticSecretstill returns201, confirming the accepted create path is unchanged. - The
# bugmarkers are removed fromF04.create-secrets-plainandF08.secrets-bad-value, andcontrol-agent-server map run --file F04 --only F04.create-secrets-plain --freshandcontrol-agent-server map run --file F08 --only F08.secrets-bad-value --freshpass.
Activity
enyst commentedon Oct 13, 2026
I'm an AI agent (Claude Code) helping Engel Nyst (@enyst) with project maintenance.
Fix proposed in #5798.
Decision needed (maintainer): should the create body accept a plain-string secret like
POST .../secretsdoes, or refuse it?DiscriminatedUnionMixinnow hands a non-dict input to pydantic, which reports amodel_typeValidationError), and the create body's schema (dict[str, SecretSource]) has never accepted plain strings.convert_string_secretscoercion toConversationConfig.secretstoo; plain strings on create would then be 201, the OpenAPI schema forsecretswould widen, and theF04.create-secrets-plainmap bullet would expect 201.Numbers,
nulland booleans onPOST .../secretsare 422 either way.Generated by Claude Code
enyst commentedon Oct 13, 2026
I'm an AI agent (Claude Code) helping Engel Nyst (@enyst) with project maintenance.
The triage's choice (422 on create, no new coercion) is what #5798 implements. On its acceptance criteria:
detaillist (model_attributes_typeatbody.secrets.<NAME>), with noexceptionfield; the router tests assert the location, and the map recipes now check the error type.start_conversation/update_secretsare not called. Accepted shapes onPOST .../secretsand a well-formedStaticSecreton create are unchanged (existing tests andF04.create-secrets,F08.secrets-update).ValidationErrorforstr,int,None,booland a list on an abstract base, concrete subclasses and a nested field (tests/sdk/utils/test_discriminated_union.py).xfailtwice.A maintainer can still choose parity with
POST .../secrets(accept plain strings on create); that would add coercion toConversationConfig.secretsand flipF04.create-secrets-plainto 201.Generated by Claude Code