Repository navigation
fix(sdk): resolve secret lookups outside the state lock before async tools run - #6662
Merged
Merged
Conversation
…tools run Under arun() each tool masks its observation in a worker thread while the run loop holds the state lock. A LookupSecret made there could call a server on the same event loop that registers secrets on the conversation, which waits on that lock: the request blocked until httpx's 30 s timeout, the lookup failed, and the value stayed unmasked in the observation. Before running a tool batch, astep now resolves uncached lookups in a worker thread with the lock released, repeating until the registry is stable, as it already does before masking an agent message. Masking under the lock then finds every value cached. The resolution loop moves out of mask_secrets_in_output into SecretRegistry.resolve_uncached_values. Fixes #6642 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ArwwLKWzfpSTpRccheeWP
Contributor
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
Contributor
Coverage Report •
|
||||||||||||||||||||||||||||||
This comment has been minimized.
This comment has been minimized.
enyst
marked this pull request as ready for review
November 9, 2026 09:18
all-hands-bot
approved these changes
Nov 9, 2026
all-hands-bot
left a comment
Collaborator
There was a problem hiding this comment.
This review was posted by an AI agent (OpenHands).
Reviewed the diff, surrounding locking code, linked issues, and CI on head d48eb1f0. This is an in-scope Python SDK change (agent/secret behavior in this repository's ownership), so I continued with a technical review.
What I verified in the workspace:
- The extracted
SecretRegistry.resolve_uncached_values()is behavior-preserving: same back-off (FAILED_LOOKUP_RETRY_SECONDS), same_exported_valuesskip, same failure marking, andmask_secrets_in_outputstill resolves before masking. No new redaction path or sentinel is introduced — masking still funnels through the existing registry helpers, per the repo's secrets guidance. - The new resolution loop in
Agent._aexecute_actionsmatches the two existing patterns inastep(message masking and_arequires_user_confirmation): snapshotsecret_sources, run the lookup in a worker thread underconversation._released_state_lock_during_io(), and repeat until the registry is stable.lock.owned()makes the context manager a no-op for directastepcallers that don't hold the lock, and both_aexecute_actionscall sites guard against empty batches. - The regression test exercises the real path — real
arun(), real loopback HTTP server on the run's own event loop, realLookupSecretover httpx, and a realupdate_secrets()that takes the state lock while answering. No mocks. It passes on head in under a second; the identical scenario blocks onmainbecause the pre-tool resolution does not exist there (30 s httpx timeout vs. immediate registration), which reproduces the issue's root cause rather than forging it. - Focused tests:
tests/sdk/agent/test_async_secret_masking.py5/5 pass. Broader:tests/sdk/agent999 passed,tests/sdk/conversation985 passed. The one failure I saw (test_local_conversation_mcp.py::test_slow_mcp_servers_start_side_by_side) also fails withmain's code in this environment, so it is pre-existing and unrelated. - No public API, serialized-event, or persistence surface changes; the sync
run()path is untouched, as documented. The known limitation (a secret registered by a tool during its own execution) is explicitly scoped out in the PR notes and was not part of the reported bug.
Non-blocking observations:
- CI on this exact head is green except "Validate PR description". That check fails only because umbrella issue #6660 carries neither
ready-for-devnor a pre-rollout creation date — a repository issue-readiness gate, not a code defect. The directly linked fix issue #6642 does carryready-for-devandpriority:high. Worth flagging to the author so the PR can unblock, but it does not affect the technical assessment of this change. - The stability loop repeats while lookups keep registering new sources. This matches the pre-existing design of the other two released-lock call sites and is bounded in practice; not a new concern.
✅ APPROVED
1 of 5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
HUMAN:
This PR proposes a fix for a bug uncovered during the first full agentic run of
verify-sdk.AGENT:
I'm an AI agent (Claude Code) helping Engel Nyst (@enyst) with project maintenance.
Requested by Engel · project thread
Why
Under
arun(), a secret looked up for the first time while masking a tool observation could stay in clear text. Each tool masks its observation in a worker thread while the run loop holds the state lock. When theLookupSecretserver runs on the same event loop and registers secrets on the conversation while answering (update_secrets, which takes the lock), the request blocked until httpx's 30 s timeout, the lookup failed, and the back-off left the value unmasked. The same lookup made while masking an agent message worked, becauseastepalready releases the lock for it.Summary
Agent._aexecute_actionsresolves uncached secret lookups in a worker thread with the state lock released (_released_state_lock_during_io), repeating until the registry is stable, before the tool batch runs. It is the same patternastepuses before masking an agent message and_arequires_user_confirmationuses for audit events.mask_secrets_in_outputintoSecretRegistry.resolve_uncached_values(), unchanged (same back-off), so both callers share it.S13.mask-asyncnow describes the expected behavior instead of the known failure.Issue Number
Fixes #6642 (umbrella #6660)
How to Test
test_async_tool_observation_lookup_does_not_wait_on_state_lockserves the lookup on the run's own loop and registers a secret while answering. It times out onmainand passes here in a fraction of a second.the values are <secret-hidden> and <secret-hidden>in 0.4 s (it wasloop-valin clear text after 30.5 s); the message case is unchanged at 0.1 s.tests/sdk/agentandtests/sdk/conversation: 1985 passed.Video/Screenshots
Not applicable.
Type
Notes
run()path is unchanged; the map's sync bullets already pass.Generated by Claude Code
🐳 Agent Server images for this PR — GHCR package, pull/run commands, and all pushed tags (click to expand)
• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server
Variants & Base Images
eclipse-temurin:17-jdkpython-node-runtimepython-node-runtimepython-node-runtimegolang: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:d48eb1f-pythonRun
All tags pushed for this build
About Multi-Architecture Support
d48eb1f-python) is a multi-arch manifest supporting both amd64 and arm64d48eb1f-python-amd64) are also available if needed