Commit 0761054
committed
fix(safety): non-blocking review must not flip OUTCOME_FAILED; lazy get_tool_var
Warning:
- _unsafe_local_code_executor.execute_code: non-blocking
NEEDS_HUMAN_REVIEW previously appended the warning to error_parts,
which became stderr, which made create_code_execution_result set
outcome=OUTCOME_FAILED. _code_execution_processor then treated it as
an execution error and retried the already-allowed code up to
error_retry_attempts (default 2) times. This also was inconsistent
with ToolSafetyFilter._after (which keeps success=True and only
merges safety_warning). Now the warning goes through the SDK logger
(matching _filter._before), stderr stays empty, outcome stays
OUTCOME_OK, and the agent does not retry. The audit log still
records the NEEDS_HUMAN_REVIEW decision. Removed the now-unused
_pending_review_warning variable.
Suggestion:
- _filter.ToolSafetyFilter.__init__: the comment claimed "never pull
trpc_agent_sdk.tools package", but `from trpc_agent_sdk.tools.
_context_var import get_tool_var` actually executes
trpc_agent_sdk/tools/__init__.py, which imports mcp_tool /
file_tools / webfetch_tool and their optional deps (mcp, anthropic).
Replaced the eager import with a sys.modules lookup: we only attach
get_tool_var when the host application has already loaded
trpc_agent_sdk.tools._context_var, so the safety package never
triggers the heavy tools/__init__.py itself. When tools are loaded,
we reuse the exact same ContextVar instance so tool names resolve
correctly.
Tests:
- test_unsafe_local_code_executor: add
TestUnsafeLocalCodeExecutorSafetyGuardNonBlocking with
test_nonblocking_review_keeps_outcome_ok — asserts that
enable_safety_guard=True + block_on_review=False + NEEDS_HUMAN_REVIEW
script keeps outcome=OUTCOME_OK and executes exactly once (no retry).
- Clean up two pre-existing unused imports (AsyncMock,
create_code_execution_result) in the same test file so flake8 stays
clean on changed files.1 parent 5f9e7b1 commit 0761054
3 files changed
Lines changed: 72 additions & 25 deletions
File tree
- tests/code_executors/local
- trpc_agent_sdk
- code_executors/local
- safety
Lines changed: 46 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | 11 | | |
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
16 | 15 | | |
17 | 16 | | |
18 | 17 | | |
19 | | - | |
20 | 18 | | |
21 | 19 | | |
22 | 20 | | |
| |||
439 | 437 | | |
440 | 438 | | |
441 | 439 | | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
Lines changed: 13 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | 108 | | |
115 | 109 | | |
116 | 110 | | |
| |||
139 | 133 | | |
140 | 134 | | |
141 | 135 | | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
148 | 145 | | |
149 | | - | |
150 | | - | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
151 | 150 | | |
152 | 151 | | |
153 | 152 | | |
| |||
172 | 171 | | |
173 | 172 | | |
174 | 173 | | |
175 | | - | |
176 | | - | |
177 | 174 | | |
178 | 175 | | |
179 | 176 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
70 | | - | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
71 | 79 | | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
77 | 83 | | |
78 | 84 | | |
79 | 85 | | |
| |||
0 commit comments