fix(tool): race condition in dynamic Action wrapper class creation#2224
fix(tool): race condition in dynamic Action wrapper class creation#2224VascoSch92 merged 23 commits intomainfrom
Conversation
- Simplify builtin agent tests (no mocks, focus on registry contracts) - Extend delegation example to demonstrate built-in explore/bash agents Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: OpenHands Bot <contact@all-hands.dev>
all-hands-bot
left a comment
There was a problem hiding this comment.
Solid fix for the TOCTOU race in dynamic action type creation. The lock usage is textbook correct and the tests properly reproduce the race condition.
Minor: PR title appears incomplete ("fix(tool): but") and description has placeholder text - might want to update those before merging.
|
@OpenHands Can you double-check that the tests is really reproducing the bug and that the fix is good? |
|
I'm on it! VascoSch92 can track my progress at all-hands.dev |
SummaryI have completed a comprehensive verification of the race condition fix in PR #2224. Here's what I found: ✅ Bug Reproduction Verified
✅ Fix Validation Complete
✅ No Additional Changes Needed
The PR is ready as-is - the tests effectively reproduce the bug and the fix properly resolves the race condition without introducing regressions. |
all-hands-bot
left a comment
There was a problem hiding this comment.
🟢 Good taste - Textbook TOCTOU race fix. Lock scope is correct, tests use real concurrency with Barrier to force the race, and the solution is as simple as it gets. This is exactly how you fix a race condition: protect the entire check-create-store sequence with a single lock. No deadlock risk, minimal performance impact, solves the real problem. LGTM.
|
@OpenHands Do a /codereview-roasted on this PR. |
|
I'm on it! enyst can track my progress at all-hands.dev |
This comment was marked as duplicate.
This comment was marked as duplicate.
|
(OpenHands-GPT-5.2) 🟡 Taste rating: Acceptable (but messy) This PR does fix a real race, but it’s also doing a bunch of unrelated stuff (built-in subagents, delegation metrics semantics, example churn). That’s not “good taste”: it makes review harder and increases the chance you ship an unrelated regression under the cover of a concurrency fix. [CRITICAL ISSUES] (things that can bite real users)
[IMPROVEMENT OPPORTUNITIES] (good taste / simplification)
[TESTING GAPS / FLAKINESS RISKS]
VERDICT✅ Worth merging for the race fix, but the PR is doing too much at once and includes a couple of “looks like validation but isn’t” design choices (tool registration logging) plus policy-vs-enforcement confusion (“read-only” explore with terminal). KEY INSIGHT: The locking fix is fine; the bigger risk here is scope creep and introducing behavioral/logging changes that aren’t directly related to the race and are harder to reason about. |
😅 |
|
@enyst Actually, I think there might be an issue with the review you requested. The reviewer is referring to changes that aren't present in this PR. For example, your comment above relates to the built-in agent explorer, but that agent wasn't added in this PR. I suspect the reviewer had access to the wrong diff. |
API breakage checks (Griffe)Result: Passed |
Agent server REST API breakage checks (OpenAPI)Result: Passed |
Summary
Fix #2199
create_action_type_with_risk()and_create_action_type_with_summary()to prevent concurrent threads from creating duplicate wrapper classes with the same nametype(), and register two distinct class objects under the same__name__, causing_get_checked_concrete_subclasses(Action)to raiseValueError("Duplicate class definition ...")Tests
tests/sdk/tool/test_tool.pythat spawn 8 threads hitting the same wrapper function simultaneouslyChecklist
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.12-nodejs22golang: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:4bc57c3-pythonRun
All tags pushed for this build
About Multi-Architecture Support
4bc57c3-python) is a multi-arch manifest supporting both amd64 and arm644bc57c3-python-amd64) are also available if needed