feat(maf): Phase 5 - action coordinator, approval flow, frontend MAF roundtable pages

- Backend: action_coordinator, capability_snapshot, event_normalizer, tool_executor updates
- Backend: approved_tool_executor with write guard, action leases, migration script
- Frontend: maf-roundtable module (API client, event timeline, approval cards, fact flow panel)
- Frontend: MafRoutes, MafSessionsPage, MafRunDetailPage
- Tests: action_leases, migration_phase5, phase5_entry_e2e, real_write_e2e/http_e2e
- Docs: update implementation plan

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
董宏凯andCursor committed 2026-08-02 13:07:21 +08:00
1 parent 21c4c898e7
commit f82363d81f
55 files changed
+6304 -167

No files matched your search

@@ -316,6 +316,10 @@ class WorkflowRunner:
logger.warning("Cannot resume run %s: no pending_approvals in checkpoint", run_id)
return run
# Expire due approvals before inspecting the checkpoint. This is a
# fail-closed server transition; a late HTTP approval cannot revive it.
await self._service.store.expire_due_approvals(run_id=run_id)
# Check if any approval is still pending — if so, don't resume yet.
any_pending = False
for pa in state.pending_approvals:
@@ -365,14 +369,15 @@ class WorkflowRunner:
from app.maf_roundtable.event_normalizer import make_action_rejected
# Conditional transition (waiting_approval → rejected) — never
# overwrite a terminal state via a generic update.
await self._service.store.actions.mark_rejected(action_id)
await self._adapter._emit_critical(run_id, make_action_rejected(
pa.get("agent_id", ""),
state.current_round,
action_id=action_id,
approval_id=approval_id,
decided_by=approval.get("decided_by", ""),
))
changed = await self._service.store.actions.mark_rejected(action_id)
if changed:
await self._adapter._emit_critical(run_id, make_action_rejected(
pa.get("agent_id", ""),
state.current_round,
action_id=action_id,
approval_id=approval_id,
decided_by=approval.get("decided_by", ""),
))
action_outcomes.append({"action_id": action_id, "status": "rejected"})
# Phase-3 P1-3: move the ledger row out of pending into the
# failed/unknown partition as rejected.
@@ -478,6 +483,37 @@ class WorkflowRunner:
# P0-3: determine parent run status from action outcomes.
statuses = {o.get("status") for o in action_outcomes}
# A target held by another approved write remains pending for an
# explicit later resume. It is never retried automatically.
if "waiting_target_lease" in statuses:
from app.maf_roundtable.event_normalizer import make_action_waiting_target_lease
state.status = "waiting_approval"
for outcome in action_outcomes:
if outcome.get("status") == "waiting_target_lease":
await self._adapter._emit_critical(
run_id,
make_action_waiting_target_lease(
next(
(str(pa.get("agent_id") or "") for pa in state.pending_approvals if pa.get("action_id") == outcome.get("action_id")),
"",
),
state.current_round,
action_id=str(outcome.get("action_id") or ""),
tool_name=str(outcome.get("tool_name") or ""),
),
)
await self._service.store.runs.update_run(run_id, {
"status": "waiting_approval",
"maf_checkpoint": state.to_dict(),
})
await self._service.store.sessions.update_session(
session_id,
user_id=self._user_id,
fields={"status": "waiting_approval", "fact_ledger": state.fact_ledger},
)
return await self._service.store.runs.get_run(run_id)
# While any action is still in_progress (another executor running it),
# the parent run stays running — never write finished_at, never finalize.
if "in_progress" in statuses:
@@ -572,6 +608,44 @@ class WorkflowRunner:
if session is None:
return run
expired_actions = await self._service.store.recover_expired_action_leases(run_id=run_id)
if expired_actions:
from app.maf_roundtable.event_normalizer import make_action_unknown
expired_ids = {action["id"] for action in expired_actions}
for action in expired_actions:
record_action_transition(
state.fact_ledger,
action_id=action["id"],
tool_name=action.get("tool_name", ""),
status="unknown",
agent_id=action.get("agent_id", ""),
)
await self._adapter._emit_critical(
run_id,
make_action_unknown(
action.get("agent_id", ""),
int(action.get("turn_index") or state.current_round),
action_id=action["id"],
reason_code="target_lease_expired_during_execution",
),
)
state.pending_approvals = [
item for item in state.pending_approvals
if item.get("action_id") not in expired_ids
]
state.status = "waiting_input"
await self._service.store.runs.update_run(run_id, {
"status": "waiting_input",
"maf_checkpoint": state.to_dict(),
})
await self._service.store.sessions.update_session(
state.session_id,
user_id=self._user_id,
fields={"status": "waiting_input", "fact_ledger": state.fact_ledger},
)
return await self._service.store.runs.get_run(run_id)
# Ensure threads still bound.
participants = await self._service.store.participants.list_participants(state.session_id)
thread_map = await self._adapter.ensure_threads(state.session_id, run_id, participants)