Repository navigation
feat(approval): make Formal review context-aware - #337
zhixiongzh wants to merge 5 commits into
Conversation
|
head_sha: 变更摘要本 PR 将 Formal 审批从「仅看当前轮次风险谓词、失败回落到 Direct」升级为「上下文感知 + 布尔判定」策略:所有谓词统一返回 主要改动
|
|
head_sha: 代码审查审查结论
💬 仅评论 |
| if active_session is not None: | ||
| effective_client_kwargs["session"] = active_session | ||
| if session_context.load_tool_history_prefix is not None: | ||
| effective_client_kwargs[TOOL_HISTORY_PREFIX_KWARG] = session_context.load_tool_history_prefix |
There was a problem hiding this comment.
head_sha: a5d20d487a7d8c7c8fda0f3d7c566f6dd4afb736
🟡 Medium Priority
新增链路里 SessionContext.load_tool_history_prefix(sessions.py:105)默认为 None,本 diff 中只有两处读取方:agent.py:567-568(非 None 时才塞进 _chrys_tool_history_prefix)与 loop.py:1731-1732(非 None 时才 await)。在本 PR 的 14 个改动文件中没有任何地方给它赋值,也没有任何外部调用点能在本次改动前就赋值一个此时才新增的属性,因此在 src/chrys/kernel 范围内该分支恒为假,_tool_history_prefix 永远为空元组。
后果(文档承诺与实现不一致):docs/en、docs/zh-Hans 的 approval.md 新增段落声称「当 Responses 会话通过服务端续接时,逐项风险检查也会使用 iCode 本地保存的可见历史」,PR 描述也声称「earlier turns may contain a user restriction that still applies」。由于 provider 续接时本轮的 self._messages 只包含本轮新增消息,跨轮的可见历史只能来自这个前缀钩子;钩子无人赋值 ⇒ 跨轮历史缺失 ⇒ user_boundary/软规则拿不到上一轮用户限制作为证据,Formal 可能直接返回 ALLOW 自动放行用户此前明确禁止的操作(该路径属于 fail-open 方向,与本次改动的安全目标相反)。同时这段新增 plumbing 无法被任何测试覆盖。
建议:为 load_tool_history_prefix 提供真正的赋值方(由持有本地历史的 history/context provider 写入 SessionContext),或删除 agent.py/loop.py 中的该 kwarg 传递;若暂不实现,应在文档中说明 provider 续接场景不包含跨轮历史。
|
看一下这 5 项建议是否合理:
|
|
复核了
当前分支与 另外main有些改动有conflicts,建议rebase一下 |
cc5f1d4 to
5691ee2
Compare
|
[P2,新发现] 审批进行中撤回的用户指令仍可能被用于自动批准。 撤回会从当前上下文移除排队消息,但已经发给裁判的请求保留了旧快照。我用模拟引擎确认,裁判在撤回后仍能基于该消息发布批准,仲裁路径也没有重新校验证据。建议在自动放行前核对本次审查使用的排队消息 ID,发现撤回时重新审查或转人工确认。arbitration.py |
|
@0x7c13 感谢复核!第一点想先和你确认一下设计。用户在 Agent 运行时提交的补充消息,排队期间仍可取消,所以建议 Formal 只把已送达的用户消息作为审批依据。如果用户希望补充指令立即影响当前审批,可以点击「立即发送」。提交成功后,如果动作仍在等待审批,Formal 就用更新后的上下文重新审查。这样,裁判不会提前引用一条用户仍可取消的消息。你觉得按这个时点处理合适吗? 整文件清空按之前沟通的范围处理。本 PR 聚焦 Formal,沿用现有黑白名单逻辑。Git 工作区内非敏感路径的 |
同意,没问题,Formal 只使用已送达的用户消息。建议以实际进入模型请求的消息为准,普通排队和「立即发送」按钮被接受都早于这个时点。 刚核对过,PR head 仍是 5691ee2。,但当前代码仍会把可撤回的排队消息交给 Formal,旧裁决因此仍可能在消息撤回后自动放行。当前代码 建议等「只使用已送达消息」的改动落地,并验证「立即发送」后旧审批失效,再合入。整文件清空已明确留到后续 PR,可以从 #337 的合入阻塞项移除。 |
Signed-off-by: zhixiongzh <zhixiong.zhuang96@gmail.com>
Signed-off-by: zhixiongzh <zhixiong.zhuang96@gmail.com>
…n Formal Include queued user instructions that are already available to approval but have yet to reach the main agent. Preserve parent conversation context for sub-agent reviews and identify delegation text as agent-authored. Pair each ask_user answer with the question and options shown to the user. Scope the pairing to its tool-call batch so reused call IDs cannot mix answers across turns. Keep the original answer and label hook additions or replacements separately in the review prompt. Include the tool kind, workspace roots, and current time in the pending action. Update the integration assertions and document how ACP hands failed or timed-out Formal reviews to the user.
Distinguish workflow input and sub-agent delegation from real user instructions. Filter system reminders before rewriting roles. Keep queued inputs in submission order across tool batches, child approvals, and retries. Deduplicate consumed messages by ID and drop withdrawn inputs from delegation snapshots.
Keep Formal evidence in the order the model actually received it and exclude queued input that has not been delivered. Invalidate an in-flight review when a user message steers the turn, and preserve the public judge interface.
5691ee2 to
26f12a2
Compare
|
复核了
看下这些问题是否合理 |
Paired: GitHub #337 ↔ GitCode !234
What type of PR is this?
/kind feature
What does this PR do / why do we need it:
Follow-up to #83. Earlier turns may contain a user restriction that still applies or explicit consent for the pending action. Reviewing only the current turn can miss either. Formal now uses the conversation context actually delivered to the model as evidence and evaluates the pending action separately.
Spec
trueorfalse. Formal no longer falls back to Direct. Invalid responses are retried within the existing review budget; exhausted retries, failures, and timeouts require human review.scope_escalationwithuser_boundary. Formal checks specific restrictions or preconditions set by the user. Inferred task scope alone does not trigger this rule.data_exfiltrationfocuses on sensitive transfers. Deletion includes removing files or folders and emptying an existing file; ordinary writes and partial edits do not by themselves count as deletion.iCode applies the rules in order: hard rules → user boundary → uncleared soft rules → automatic approval. The approval dialog shows rules requiring human review, and the audit records predicate matches and applicable consent results.
ask_userevidence. Each verified answer is paired with its displayed question and options and scoped to the matching tool call. Hook changes are represented separately.Formal remains opt-in; Direct remains the default.
Scope of this PR
This PR leaves the tool allowlist and denylist logic unchanged. In a Git workspace, an existing allowlist can therefore auto-approve a
write_filecall that empties a file at a non-sensitive path before the action reaches Formal. A follow-up PR should address this alongside the syntax-tree parsing work in #225.Which issue(s) this PR fixes:
No linked issue. Follow-up to #83.
What scenarios were tested, and what were the verification results:
After rebasing onto
upstream/mainat3930a4f8, Smart Test passed: 19,647 tests passed, 69 skipped, and 3 warnings; 1,028 architecture tests passed. The Smart Test selected 20,744 of 42,700 collected non-integration tests.Self-checklist:
ApprovalJudge.evaluate()interface and existing settings are unchanged.