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
+62
-1
@@ -31,6 +31,7 @@ from __future__ import annotations
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from sqlalchemy import (
|
||||
Boolean,
|
||||
CheckConstraint,
|
||||
ForeignKey,
|
||||
Integer,
|
||||
@@ -368,7 +369,8 @@ class MafRoundtableSeatRunRow(Base):
|
||||
# migration / manual SQL honest. Keep in sync with VALID_EXECUTION_STAGES.
|
||||
CheckConstraint(
|
||||
"execution_stage IN ('legacy','planner','expert','format_repair',"
|
||||
"'cross_review','cross_review_repair','finalizer','group_chat')",
|
||||
"'cross_review','cross_review_repair','finalizer','group_chat',"
|
||||
"'rework','manager_review')",
|
||||
name="ck_maf_seat_runs_execution_stage",
|
||||
),
|
||||
)
|
||||
@@ -406,6 +408,64 @@ class MafRoundtableSeatRunRow(Base):
|
||||
)
|
||||
|
||||
|
||||
# ── 8b. seat tasks (Stage 4 / R3-Q quality state machine) ─────────────────
|
||||
|
||||
|
||||
class MafRoundtableSeatTaskRow(Base):
|
||||
"""One seat task with its frozen contract and quality lifecycle.
|
||||
|
||||
Stage 4 (R3-Q): each manager dispatch assignment becomes one seat task.
|
||||
The row persists the whole acceptance state machine
|
||||
(``assigned → delivering → submitted → manager_review →
|
||||
accepted / rework / reassigned / exhausted / controlled_gap``) together
|
||||
with the frozen ``contract_json``, the latest ``delivery_json``,
|
||||
``deterministic_check_json``, ``review_decision_json`` and a per-attempt
|
||||
``history_json``. When every rework/reassign cap is exhausted the task
|
||||
ends as ``controlled_gap`` with a ``gap_json`` risk record that the final
|
||||
report must carry — it is never disguised as an accepted delivery.
|
||||
|
||||
``task_key`` is stable per (run, original assignment); reassignment only
|
||||
changes ``agent_id`` and never creates a new task.
|
||||
"""
|
||||
|
||||
__tablename__ = "maf_roundtable_seat_tasks"
|
||||
__table_args__ = (
|
||||
UniqueConstraint("run_id", "task_key", name="uq_maf_seat_tasks_run_task"),
|
||||
CheckConstraint(
|
||||
"status IN ('assigned','delivering','submitted','manager_review',"
|
||||
"'accepted','rework','reassigned','exhausted','controlled_gap')",
|
||||
name="ck_maf_seat_tasks_status",
|
||||
),
|
||||
)
|
||||
|
||||
id: Mapped[str] = mapped_column(String(64), primary_key=True)
|
||||
session_id: Mapped[str] = mapped_column(
|
||||
String(64), ForeignKey("maf_roundtable_sessions.id", ondelete="CASCADE"), nullable=False, index=True
|
||||
)
|
||||
run_id: Mapped[str] = mapped_column(
|
||||
String(64), ForeignKey("maf_roundtable_runs.id", ondelete="CASCADE"), nullable=False, index=True
|
||||
)
|
||||
task_key: Mapped[str] = mapped_column(String(128), nullable=False)
|
||||
# Current owning seat (changes on reassignment).
|
||||
agent_id: Mapped[str] = mapped_column(String(64), nullable=False, index=True)
|
||||
original_agent_id: Mapped[str] = mapped_column(String(64), nullable=False)
|
||||
status: Mapped[str] = mapped_column(String(32), default="assigned", index=True)
|
||||
required: Mapped[bool] = mapped_column(Boolean, default=True)
|
||||
attempt_count: Mapped[int] = mapped_column(Integer, default=0)
|
||||
rework_count: Mapped[int] = mapped_column(Integer, default=0)
|
||||
reassign_count: Mapped[int] = mapped_column(Integer, default=0)
|
||||
contract_json: Mapped[dict | None] = mapped_column(PortableJSON(), nullable=True)
|
||||
delivery_json: Mapped[dict | None] = mapped_column(PortableJSON(), nullable=True)
|
||||
deterministic_check_json: Mapped[dict | None] = mapped_column(PortableJSON(), nullable=True)
|
||||
review_decision_json: Mapped[dict | None] = mapped_column(PortableJSON(), nullable=True)
|
||||
history_json: Mapped[list | None] = mapped_column(PortableJSON(), nullable=True)
|
||||
gap_json: Mapped[dict | None] = mapped_column(PortableJSON(), nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(BeijingDateTime(), nullable=False, default=_now)
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
BeijingDateTime(), nullable=False, default=_now, onupdate=_now
|
||||
)
|
||||
|
||||
|
||||
# ── 9. action secrets (encrypted actual execution params, server-only) ────
|
||||
|
||||
|
||||
@@ -576,5 +636,6 @@ __all__ = [
|
||||
"MafRoundtableParticipantRow",
|
||||
"MafRoundtableRunRow",
|
||||
"MafRoundtableSeatRunRow",
|
||||
"MafRoundtableSeatTaskRow",
|
||||
"MafRoundtableSessionRow",
|
||||
]
|
||||
Reference in new issue
Block a user