fix(code-exec): propagate agent-turn context into tool worker threads
Worker threads that dispatch Hermes tools started with an empty contextvars.Context and no thread-local approval/sudo callbacks. Add tools/thread_context.propagate_context_to_thread factoring that capture/install/clear lifecycle (mirrors the GHSA-qg5c-hvr5-hjgr pattern), and refactor agent/tool_executor onto it so the security-critical logic lives in one audited place. Update the contextvar-propagation source guard for the new call shape. Refs #33057
This commit is contained in:
@@ -197,6 +197,19 @@ def test_run_agent_concurrent_executor_wraps_submit_with_copy_context():
|
||||
and call.args[1].id == "_run_tool"
|
||||
):
|
||||
tool_submits.append(("fixed", call))
|
||||
# Fixed (shared helper): executor.submit(
|
||||
# propagate_context_to_thread(_run_tool), ...) — the helper in
|
||||
# tools/thread_context.py does copy_context().run(...) internally and
|
||||
# additionally propagates the thread-local approval/sudo callbacks.
|
||||
elif (
|
||||
isinstance(first, ast.Call)
|
||||
and isinstance(first.func, ast.Name)
|
||||
and first.func.id == "propagate_context_to_thread"
|
||||
and first.args
|
||||
and isinstance(first.args[0], ast.Name)
|
||||
and first.args[0].id == "_run_tool"
|
||||
):
|
||||
tool_submits.append(("fixed", call))
|
||||
|
||||
assert tool_submits, (
|
||||
"Could not locate `executor.submit(... _run_tool ...)` in "
|
||||
|
||||
Reference in New Issue
Block a user