Commit 5f9e7b1
committed
fix(safety): address CongkeChen review - bash path boundary, audit cross-process note, retry side effect doc
CI fix:
- _wrapper._deny_code_result fallback stub: yapf requires a blank line
between class declaration and first method (E301). Added blank lines
after `class _Outcome:` and `class _CodeExecutionResult:`.
Warning:
- _rules.DangerousFilesRule._check_bash: bash side system-dir and
forbidden-path matching used substring (`sd in line` / `fb in line`),
inconsistent with the Python side's path-boundary matching. So
`cat /etcetera/foo` was false-positive CRITICAL → DENY (matched /etc),
and `cat my.envrc` was false-positive → DENY (matched .env). Now both
reuse _matches_system_dir(line) and _matches_forbidden(line, policy)
so bash and Python sides agree.
- _audit._AUDIT_LOCK: add cross-process note explaining the lock is
process-local and long JSONL lines (>PIPE_BUF, ~4096 bytes on Linux)
may interleave/truncate across worker processes. Documents the three
mitigations (per-worker path, single writer, fcntl.flock).
- _unsafe_local_code_executor.execute_code: document the
OUTCOME_FAILED → error_retry_attempts side effect. Safety blocks map
to OUTCOME_FAILED (non-empty stderr), which _code_execution_processor
treats as an execution error and may retry up to 2 times. Each retry
is still intercepted (safe), but wastes a scan/LLM round-trip. Comment
notes a future refinement could use a dedicated marker to distinguish
"safety block" from "real execution error".
Tests:
- test_dangerous_files_bash_system_dir_boundary_not_substring: assert
`cat /etcetera/foo` does NOT trigger R001 (bash side, mirrors the
existing Python-side regression test).
- test_dangerous_files_bash_forbidden_path_boundary_not_substring:
assert `cat my.envrc` does NOT trigger forbidden-path R001 with
policy forbidden_paths=[".env"].
- test_resource_long_sleep_above_threshold_is_high: assert sleep 301
(max=300) is flagged HIGH.
- test_resource_sleep_at_threshold_is_allowed_bash: assert sleep 300
(== max) is NOT flagged (strict > boundary).1 parent d231f71 commit 5f9e7b1
5 files changed
Lines changed: 78 additions & 2 deletions
File tree
- tests/tool_safety
- trpc_agent_sdk
- code_executors/local
- safety
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
279 | 279 | | |
280 | 280 | | |
281 | 281 | | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
130 | 140 | | |
131 | 141 | | |
132 | 142 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
19 | 29 | | |
20 | 30 | | |
21 | 31 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
313 | 313 | | |
314 | 314 | | |
315 | 315 | | |
316 | | - | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
317 | 321 | | |
318 | 322 | | |
319 | 323 | | |
| |||
323 | 327 | | |
324 | 328 | | |
325 | 329 | | |
326 | | - | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
327 | 335 | | |
328 | 336 | | |
329 | 337 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
| 76 | + | |
75 | 77 | | |
76 | 78 | | |
77 | 79 | | |
| |||
0 commit comments