Commit 35750b8
committed
fix(safety): apply same multi-block aggregation fix to UnsafeLocalCodeExecutor
AI Code Review critical pointed out TWO copies of the worst-report aggregation logic: _wrapper._scan_code_input (fixed in 1f15282) AND _unsafe_local_code_executor.py:130-149 (still had the bug). The executor copy also only promoted a block to worst on DENY or same-decision-higher-risk, so [safe_python (ALLOW), bash 'sleep 100 &' (NEEDS_HUMAN_REVIEW)] kept worst=ALLOW — same fail-open bypass. Apply the same (decision_rank, risk_rank) tuple comparison here.
Also fix AI Code Review suggestion: executor returned stderr='TOOL_SAFETY_DENY: ...' for BOTH deny and review-blocks, inconsistent with ToolSafetyFilter which distinguishes TOOL_SAFETY_DENY vs TOOL_SAFETY_NEEDS_REVIEW. Now picks the label based on report.decision so audits/logs don't mislabel review-blocks as deny.
Also document in safety_wrapper docstring that only keyword args are scanned (AI Code Review suggestion: positional args bypass _extract_script; documenting this is the lightweight fix since signature inspection is brittle for variadic callables).
Add two regression tests (run on CI where docker is installed): test_unsafe_local_code_executor_multi_block_aggregates_review and test_unsafe_local_code_executor_review_label_differs_from_deny.1 parent 1f15282 commit 35750b8
3 files changed
Lines changed: 70 additions & 6 deletions
File tree
- tests/tool_safety
- trpc_agent_sdk
- code_executors/local
- safety
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
Lines changed: 19 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
124 | 132 | | |
125 | 133 | | |
126 | 134 | | |
| |||
142 | 150 | | |
143 | 151 | | |
144 | 152 | | |
145 | | - | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
146 | 159 | | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | 160 | | |
151 | 161 | | |
152 | 162 | | |
| |||
156 | 166 | | |
157 | 167 | | |
158 | 168 | | |
159 | | - | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
160 | 174 | | |
161 | 175 | | |
162 | 176 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
201 | | - | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
202 | 212 | | |
203 | 213 | | |
204 | 214 | | |
| |||
0 commit comments