feat(maf): add secure roundtable workflow runtime

This commit is contained in:
董宏凯 committed 2026-08-01 17:51:53 +08:00
1 parent e690475e6e
commit bd4131b4e2
52 files changed
+10315 -96

No files matched your search

@@ -118,6 +118,27 @@ class MafRunRepository:
)
await session.commit()
async def claim_for_resume(self, run_id: str) -> bool:
"""Run-level CAS gating post-approval execution: ``waiting_approval → running``.
After every approval is decided, exactly one concurrent ``resume()`` may
proceed to execute the approved actions and write the parent run's final
state. The winner (``rowcount == 1``) executes; every other concurrent
caller gets False and must return the current run WITHOUT writing a
terminal status (so it can never race a ``completed``/``failed`` write).
"""
async with self._sf() as session:
result = await session.execute(
update(MafRoundtableRunRow)
.where(
MafRoundtableRunRow.id == run_id,
MafRoundtableRunRow.status == "waiting_approval",
)
.values(status="running", started_at=_now(), updated_at=_now())
)
await session.commit()
return result.rowcount == 1 # type: ignore[union-attr]
async def bump_last_event_seq(self, run_id: str, seq: int) -> None:
"""Denormalized cache update — only bumps forward (max wins)."""
async with self._sf() as session: