is it expected that strings don't work as secrets ...
# proj-sdk
w
is it expected that strings don't work as secrets in RemoteWorkspace?
Copy code
[11/19/25 14:13:58] ERROR    HTTP request failed (422 Unprocessable Entity):           remote_conversation.py:61
                             {'detail': [{'type': 'union_tag_invalid', 'loc': ['body',
                             'secrets', 'GITHUB_TOKEN'], 'msg': "Input tag 'str' found
                             using kind_of() does not match any of the expected tags:
                             'LookupSecret', 'StaticSecret'", 'input':
                             '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', 'ctx':
                             {'discriminator': 'kind_of()', 'tag': 'str',
                             'expected_tags': "'LookupSecret', 'StaticSecret'"}}]}
c
String should be automatically converted to
StaticSecret
, this feels like a bug to me. Is that correct? @straight-sundown-84319
s
It should be
c
@wooden-umbrella-84098 could you share a minimal script to repro this so we can start an issue?
w
minimal no šŸ˜… but here's where it's failing: https://github.com/OpenHands/cve-demo/pull/6/files
I can see if openhands can repro
@nutritious-balloon-65098 try and repro this error
n
I'm on it! Robert Brennan can track my progress here.
I successfully reproduced and fixed the secrets bug in RemoteWorkspace where strings weren't working as secrets. Problem: The
RemoteConversation.update_secrets()
method was sending plain strings to the server, but the server expected
StaticSecret
objects with a discriminated union format, causing a 422 Unprocessable Entity error. Solution: Modified the method to automatically convert strings to
StaticSecret
objects using the existing
_wrap_secret()
helper and proper serialization. The fix ensures: • Strings are automatically converted to
StaticSecret
format:
{"kind": "StaticSecret", "value": "secret-value"}
• Both string and callable secrets work correctly • Backward compatibility is maintained Changes Made: 1. Core Fix: Updated
RemoteConversation.update_secrets()
in
remote_conversation.py
2. Enhanced Tests: Added comprehensive payload format verification in
test_remote_conversation.py
Verification: All tests pass, pre-commit checks pass, and manual verification confirms the fix works correctly. The changes have been committed locally. Would you like me to push these changes to a new branch and create a pull request, or would you prefer a different Git workflow? <sub>View full conversation</sub>
w
OK not exactly a minimal repro, but here's a repro https://github.com/rbren/cve-demo-2/blob/cf4cbf7baf2887b68178fd8b201dc9ad16a6bc88/cve_solver.py#L212 Using agent-server 1.2.0
also happens in 1.1.0
n
Final Summary I successfully reproduced and fixed the secrets bug where strings weren't being automatically converted to StaticSecret objects in RemoteWorkspace. āœ… Request Completely Addressed Original Request: "Reproduce and fix error where strings don't work as secrets in RemoteWorkspace - strings should be automatically converted to StaticSecret" Checklist of Completion: 1. āœ… Reproduced the error: Confirmed 422 Unprocessable Entity error when sending plain strings to server 2. āœ… Fixed the bug: Modified
RemoteConversation.update_secrets()
to automatically convert strings to StaticSecret objects 3. āœ… Automatic conversion: Implemented using existing
_wrap_secret()
helper function 4. āœ… Enhanced testing: Added comprehensive test assertions to verify payload format 5. āœ… Pushed to GitHub: Created PR #1231 with detailed description šŸ”§ Changes Made (Concise & Focused) Git diff shows exactly 2 files modified: •
remote_conversation.py
: Fixed
update_secrets()
method (13 lines changed) ā—¦ Added import for
_wrap_secret
ā—¦ Modified method to wrap secrets in StaticSecret objects before sending to server •
test_remote_conversation.py
: Enhanced existing tests (48 lines added) ā—¦ Added payload format verification for both string and callable secrets ā—¦ Verified StaticSecret object structure matches server expectations Total: 61 lines changed across 2 files - all changes directly address the reported bug. šŸš€ Work Already Completed & Pushed Pull Request: https://github.com/OpenHands/software-agent-sdk/pull/1231 • āœ… Changes pushed to
fix-secrets-staticSecret-conversion
branch • āœ… Draft PR created with comprehensive description • āœ… All tests passing (17/17 remote conversation tests) • āœ… Pre-commit hooks passed šŸ’” Server-Side Enhancement Opportunity Answer to your question: Yes, there could be a complementary server-side fix that would make the API more user-friendly by accepting both plain strings AND StaticSecret objects. The server could use a Pydantic
@field_validator
to automatically wrap plain strings in StaticSecret objects, eliminating the need for client-side conversion entirely. Current Status: The immediate bug is fixed with the client-side solution. A server-side enhancement would be a nice future improvement for better developer experience. <sub>View full conversation</sub>
Summary: Server-Side Secrets Fix Completed āœ… I have successfully created a new pull request with JUST the server-side changes to automatically convert string secrets to StaticSecret objects on the server side. āœ… Request Fulfillment Checklist - [ ] Created new pull request with server-side changes only - [ ] Automatic string-to-StaticSecret conversion implemented on server - [ ] Backward compatibility maintained for existing clients - [ ] Comprehensive testing added (9 total tests) - [ ] Clean, focused changes (3 files, 265 lines added) šŸ”§ Server-Side Implementation File:
openhands-agent-server/openhands/agent_server/models.py
• Added
convert_string_secrets
field validator to
UpdateSecretsRequest.secrets
• Automatically converts plain strings to
StaticSecret(value=SecretStr(string_value))
• Handles multiple input formats while preserving existing functionality 🧪 Testing Coverage Files:
tests/agent_server/test_models.py
+
tests/agent_server/test_conversation_router.py
• 7 unit tests for model validation (string conversion, mixed formats, edge cases) • 2 integration tests for API endpoint functionality • All tests passing āœ… šŸ“‹ Pull Request Created PR #1232: https://github.com/OpenHands/software-agent-sdk/pull/1232 • Status: Draft (ready for review) • Branch:
server-side-secrets-fix
• Changes: Server-side automatic string secret conversion • Backward Compatible: Existing clients continue working unchanged šŸŽÆ Problem Solved The original 422 validation error when sending plain string secrets is now resolved on the server side:
Copy code
Before: "Input tag 'str' found using kind_of() does not match any of the expected tags: 'LookupSecret', 'StaticSecret'"
After: Plain strings automatically converted to StaticSecret objects āœ…
The server-side solution is complete and ready for review. This complements the earlier client-side fix (PR #1231) to provide a comprehensive solution for the secrets compatibility issue. <sub>View full conversation</sub>
I successfully reproduced and fixed the error where strings don't work as secrets in RemoteWorkspace. Problem: Users encountered 422 Unprocessable Entity errors when passing plain strings as secrets because the server expected SecretSource objects. Solution: Implemented server-side automatic conversion by adding a Pydantic field validator to UpdateSecretsRequest.secrets that converts plain strings to StaticSecret objects while preserving existing SecretSource objects unchanged. Changes: • Added
convert_string_secrets
field validator in models.py • Created 7 comprehensive unit tests in test_models.py • Added 2 integration tests in test_conversation_router.py • Fixed discriminator to use correct class names • All tests passing, pre-commit hooks passed Result: • Before:
workspace.update_secrets({"API_KEY": "secret"})
→ āŒ 422 error • After:
workspace.update_secrets({"API_KEY": "secret"})
→ āœ… Works automatically Pull Request: https://github.com/OpenHands/software-agent-sdk/pull/1234 The fix is based on v1.2.0 release, maintains full backward compatibility, and enables natural string usage for secrets. <sub>View full conversation</sub>