fix(maf): harden stage-4 quality gate (P0/P1)
P0-1 migration: detect the same-named stage-3 execution_stage CHECK by sqltext (must contain rework + manager_review), SQLite rebuild / PG-MySQL drop+add, PG boolean default TRUE, validate_schema checks constraint content + seat_tasks status CHECK/unique/FKs; tests start from a real stage-3 schema. P0-2: a missing/invalid manager review (timeout/exception/empty/invalid JSON/missing per-seat decision) is never an acceptance - system rework under the cap, contract fallback (reassign/controlled_gap/ask_user) afterwards, source=system events. P0-3: unaccepted deliveries are isolated from the fact ledger, cross-review and final report (deferred merge, delivery_json envelope, accepted_task_results in checkpoint, accepted-only synthesis, no turn_results fallback). P0-4: seat-task init is atomic get-or-create over the full expected set; recovery fills missing tasks without overwriting frozen contracts; quality gate blocks missing required tasks. P1: zero config values honoured; duplicate detection persists SHA-256 conclusion digests in history (survives restarts); findings never satisfy evidence, evidence_refs must resolve to trusted ledger refs (unverified_evidence_ref); conversation SSE projection tests added and manager/finalizer messages are no longer mislabelled as seat.delivery.submitted.
This commit is contained in:
1 parent
a786cdcad0
commit
1aeee86984
24 files changed
+4706
-47
No files matched your search
@@ -36,8 +36,11 @@ from app.maf_roundtable.workflow_executors import (
|
||||
ManagerAnswerExecutor,
|
||||
ManagerDispatchExecutor,
|
||||
PlannerExecutor,
|
||||
QualityGateExecutor,
|
||||
QualitySeatTasksExecutor,
|
||||
RoundtableState,
|
||||
SeatExecutor,
|
||||
WaitingInputTerminalExecutor,
|
||||
WaitingTerminalExecutor,
|
||||
_agent_capabilities_from_snapshot,
|
||||
generate_final_report,
|
||||
@@ -165,6 +168,7 @@ class WorkflowRunner:
|
||||
or candidate_set
|
||||
or maf_v2_payload.get("dispatch_plan") is not None
|
||||
),
|
||||
quality_gate_enabled=self._resolve_quality_gate_enabled(maf_v2_payload),
|
||||
)
|
||||
|
||||
if state.dispatch_contract_enabled:
|
||||
@@ -220,6 +224,54 @@ class WorkflowRunner:
|
||||
except Exception: # noqa: BLE001
|
||||
return 600.0, True
|
||||
|
||||
def _resolve_quality_gate_enabled(self, maf_v2_payload: dict[str, Any]) -> bool:
|
||||
"""Resolve the per-run quality gate flag.
|
||||
|
||||
A boolean frozen in the session's ``maf_v2`` payload wins (sessions
|
||||
created before Stage 4 can opt out explicitly); otherwise the service
|
||||
config default applies.
|
||||
"""
|
||||
payload_flag = maf_v2_payload.get("quality_gate_enabled")
|
||||
if isinstance(payload_flag, bool):
|
||||
return payload_flag
|
||||
return bool(self._quality_settings()["enabled"])
|
||||
|
||||
@staticmethod
|
||||
def _cfg_int(cfg: Any, name: str, default: int) -> int:
|
||||
"""Config int where an explicit 0 is honoured (only None falls back).
|
||||
|
||||
``int(getattr(...) or default)`` would silently turn a deliberate
|
||||
``max_rework_attempts: 0`` back into the default — zero must mean zero.
|
||||
"""
|
||||
value = getattr(cfg, name, None)
|
||||
return default if value is None else int(value)
|
||||
|
||||
def _quality_settings(self) -> dict[str, Any]:
|
||||
try:
|
||||
from deerflow.config import get_app_config
|
||||
|
||||
cfg = get_app_config().maf_roundtable
|
||||
return {
|
||||
"enabled": bool(getattr(cfg, "quality_gate_enabled", True)),
|
||||
"max_rework_attempts": self._cfg_int(cfg, "max_rework_attempts", 2),
|
||||
"max_reassignments": self._cfg_int(cfg, "max_reassignments", 1),
|
||||
"min_delivery_chars": self._cfg_int(cfg, "min_delivery_chars", 40),
|
||||
"min_delivery_evidence": self._cfg_int(cfg, "min_delivery_evidence", 1),
|
||||
"fallback_policy": str(
|
||||
getattr(cfg, "default_fallback_policy", None)
|
||||
or "reassign_then_gap"
|
||||
),
|
||||
}
|
||||
except Exception: # noqa: BLE001
|
||||
return {
|
||||
"enabled": True,
|
||||
"max_rework_attempts": 2,
|
||||
"max_reassignments": 1,
|
||||
"min_delivery_chars": 40,
|
||||
"min_delivery_evidence": 1,
|
||||
"fallback_policy": "reassign_then_gap",
|
||||
}
|
||||
|
||||
def _participants_requiring_threads(
|
||||
self,
|
||||
participants: list[dict[str, Any]],
|
||||
@@ -344,6 +396,37 @@ class WorkflowRunner:
|
||||
|
||||
state.current_round = max(state.current_round, 1)
|
||||
cross_review = CrossReviewExecutor(self._adapter, state)
|
||||
|
||||
# Stage 4 (R3-Q): the quality seat-task loop + phase gate replace
|
||||
# the plain seat fan-out for V2 structured dispatch.
|
||||
if state.quality_gate_enabled:
|
||||
q = self._quality_settings()
|
||||
quality_seats = QualitySeatTasksExecutor(
|
||||
self._adapter,
|
||||
state,
|
||||
action_coordinator=self._action_coordinator,
|
||||
max_rework_attempts=q["max_rework_attempts"],
|
||||
max_reassignments=q["max_reassignments"],
|
||||
min_delivery_chars=q["min_delivery_chars"],
|
||||
min_delivery_evidence=q["min_delivery_evidence"],
|
||||
fallback_policy=q["fallback_policy"],
|
||||
)
|
||||
quality_gate = QualityGateExecutor(self._adapter, state)
|
||||
waiting_input_terminal = WaitingInputTerminalExecutor()
|
||||
return create_workflow(
|
||||
mode="structured",
|
||||
planner=quality_seats,
|
||||
cross_review=cross_review,
|
||||
seat_executors=[],
|
||||
approval_gate=approval_gate,
|
||||
finalizer=finalizer,
|
||||
waiting_terminal=waiting_terminal,
|
||||
seat_agent_ids=[],
|
||||
execution_mode=execution_mode,
|
||||
quality_gate=quality_gate,
|
||||
waiting_input_terminal=waiting_input_terminal,
|
||||
)
|
||||
|
||||
return create_workflow(
|
||||
mode="structured",
|
||||
planner=DispatchSeatEntryExecutor(state),
|
||||
|
||||
Reference in new issue
Block a user