fix(maf): harden phase 5 approval safety

This commit is contained in:
董宏凯 committed 2026-08-02 14:32:49 +08:00
1 parent f82363d81f
commit a55992e31c
11 files changed
+489 -146

No files matched your search

@@ -147,8 +147,8 @@ class MafRoundtableConfig(BaseModel):
description="外部写入审批有效期(秒);到期后自动拒绝,绝不执行。",
)
approval_scan_interval_seconds: int = Field(
default=10,
ge=1,
default=30,
ge=5,
le=3600,
description="MAF approval expiry scan interval in seconds",
)
@@ -26,7 +26,7 @@ def _now() -> datetime:
def action_to_dict(row: MafRoundtableActionRow) -> dict[str, Any]:
"""Serialise an action ORM row to a plain dict (public — reused by the store facade)."""
"""Serialise an action ORM row to the internal persistence representation."""
return {
"id": row.id,
"session_id": row.session_id,
@@ -52,16 +52,35 @@ def action_to_dict(row: MafRoundtableActionRow) -> dict[str, Any]:
def action_to_public_dict(action: Mapping[str, Any]) -> dict[str, Any]:
"""Return the allow-listed action representation exposed by MAF HTTP APIs.
"""Return only the stable, audit-safe Action DTO fields."""
Target lease keys and idempotency keys are persistence/coordinator
details. They must never cross the public boundary.
"""
return {
field: action[field]
for field in _PUBLIC_ACTION_FIELDS
if field in action
}
public = dict(action)
public.pop("target_key", None)
public.pop("idempotency_key", None)
return public
_PUBLIC_ACTION_FIELDS: tuple[str, ...] = (
"id",
"session_id",
"run_id",
"agent_id",
"tool_name",
"logical_action_id",
"turn_index",
"risk_level",
"status",
"arguments",
"result",
"external_object_id",
"approval_id",
"attempt_count",
"started_at",
"finished_at",
"created_at",
"updated_at",
)
# Back-compat alias for internal callers that used the old private name.