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:
董宏凯 committed 2026-08-07 00:04:55 +08:00
1 parent a786cdcad0
commit 1aeee86984
24 files changed
+4706 -47

No files matched your search

@@ -875,8 +875,9 @@ async def test_sse_generator_realtime_terminal_stops(svc, store, hub):
@pytest.mark.asyncio
async def test_p0_1_atomic_projection_both_events_or_neither(svc, store):
"""agent.message.completed must atomically project both
agent.message.complete AND seat.delivery.submitted."""
"""A genuine seat delivery (agent.message.completed with a seat delivery
execution_stage) must atomically project both agent.message.complete AND
seat.delivery.submitted."""
import uuid
from sqlalchemy import select
@@ -914,7 +915,11 @@ async def test_p0_1_atomic_projection_both_events_or_neither(svc, store):
"event_type": "agent.message.completed",
"agent_id": "seat_a",
"turn_index": 1,
"payload": {"content": "result", "schema_status": "valid"},
"payload": {
"content": "result",
"schema_status": "valid",
"execution_stage": "expert",
},
}
written = await svc.bridge_workflow_event(
@@ -1020,7 +1025,7 @@ async def test_p0_1_projection_failure_does_not_duplicate_on_retry(svc, store):
id="audit_retry_1", session_id=session.id, run_id=run.id,
seq=1, event_type="agent.message.completed",
agent_id="seat_a", turn_index=0,
payload_json={"content": "done"},
payload_json={"content": "done", "execution_stage": "expert"},
))
await svc.bridge_workflow_event(
@@ -1029,7 +1034,7 @@ async def test_p0_1_projection_failure_does_not_duplicate_on_retry(svc, store):
"event_type": "agent.message.completed",
"agent_id": "seat_a",
"turn_index": 0,
"payload": {"content": "done"},
"payload": {"content": "done", "execution_stage": "expert"},
},
source_audit_event_id="audit_retry_1",
)