Skip to content

feat(rule_agent): safety findings carry hit call_indices for span anchoring - #504

Merged
e06084 merged 1 commit into
MigoXLab:devfrom
e06084:feat/safety-finding-call-indices
Sep 17, 2026
Merged

e06084 merged 1 commit into
MigoXLab:devfrom
e06084:feat/safety-finding-call-indices

Conversation

@e06084

@e06084 e06084 commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

背景

安全层规则命中时,finding 只在英文句子里写位置("...call 10 (exec_command)..."),没有结构化的位置字段。下游平台(如 dingo-saas 的评估报告)要把 finding 标记到轨迹里对应的那次调用,只能靠正则从句子里抠 "call N"——句子格式一改就崩,很脆弱。

改动

5 条安全规则命中时,除现有英文 finding 外,在 reason[1] 的 JSON 里新增 call_indices(0-based,与规则读取的 tool-call 序列对齐,call N == index N-1):

  • Destructive / SensitiveAccess / SecretExposure / GatewayBypass:在 finding 循环里收集命中索引,传给 _safety_flag
  • GatewayBypass:标记的是"直接联网的那次调用"(违规发生处),不是更早的 policy refusal。
  • SandboxExplicitlyDisabled:自建 reason,追加相同的 reason[1] JSON 形态,call_indices 由 offenders 换算。

call_indices 仅在有命中时出现;干净通过不带此字段,reason[1] 形态与现有 {findings, total} 完全兼容,下游旧读者无需改。

测试

新增 TestFindingsCarryHitCallIndices,覆盖全部 5 条规则、多命中按序、以及干净通过不带字段。test_rule_agent_safety.py 全绿(65 passed)。

🤖 Generated with Claude Code

…horing

A safety finding names its position in prose ("call 3"), but a platform that
anchors the finding onto a specific trace span needs that position as data, not
scraped from a sentence that could be reworded. All five safety rules now emit
0-based `call_indices` in the reason[1] JSON, aligned with the tool-call
sequence the rule read (`call N` in prose == index N-1):

- Destructive / SensitiveAccess / SecretExposure / GatewayBypass collect the
  offending index in their finding loop and pass it to `_safety_flag`.
- GatewayBypass marks the direct-network call (where the bypass happened), not
  the earlier policy refusal.
- SandboxExplicitlyDisabled builds its own reason, so it appends the same
  reason[1] shape with `call_indices` derived from its offenders.

`call_indices` is present only when there is at least one hit; a clean pass
carries none. Adds TestFindingsCarryHitCallIndices covering all five rules,
multiple hits, and the clean-pass case.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@e06084
e06084 merged commit cde72d7 into MigoXLab:dev Sep 17, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant