代码提交
This commit is contained in:
1 parent
d93cc62806
commit
ddf83f7728
25 files changed
+4086
-424
No files matched your search
@@ -473,9 +473,16 @@ class DeerFlowAgentAdapter:
|
||||
# ── P1.6: audit event persistence ───────────────────────────────────────
|
||||
|
||||
async def _emit_critical(self, run_id: str, event: dict[str, Any]) -> None:
|
||||
"""Emit a critical audit event. Failure raises AuditEventError."""
|
||||
"""Emit a critical audit event. Failure raises AuditEventError.
|
||||
|
||||
The persisted audit event row's ``id`` is passed to the conversation
|
||||
bridge as ``source_audit_event_id`` so projection dedup is always
|
||||
keyed on the real audit row — not on an ephemeral input field that
|
||||
may be absent for critical events.
|
||||
"""
|
||||
persisted: dict[str, Any] | None = None
|
||||
try:
|
||||
await self._service.append_event(
|
||||
persisted = await self._service.append_event(
|
||||
run_id=run_id,
|
||||
user_id=self._user_id,
|
||||
event_type=event["event_type"],
|
||||
@@ -488,7 +495,11 @@ class DeerFlowAgentAdapter:
|
||||
raise AuditEventError(
|
||||
f"Critical audit event '{event.get('event_type')}' failed to persist: {exc}"
|
||||
) from exc
|
||||
await self._bridge_conversation_event(run_id, event)
|
||||
await self._bridge_conversation_event(
|
||||
run_id,
|
||||
event,
|
||||
source_audit_event_id=persisted["id"] if persisted else None,
|
||||
)
|
||||
|
||||
async def _emit(self, run_id: str, event: dict[str, Any]) -> None:
|
||||
"""Emit a non-critical event (agent.message.delta). Failure degrades gracefully.
|
||||
@@ -507,8 +518,9 @@ class DeerFlowAgentAdapter:
|
||||
if event_type in _CRITICAL_EVENT_TYPES:
|
||||
await self._emit_critical(run_id, event)
|
||||
return
|
||||
persisted: dict[str, Any] | None = None
|
||||
try:
|
||||
await self._service.append_event(
|
||||
persisted = await self._service.append_event(
|
||||
run_id=run_id,
|
||||
user_id=self._user_id,
|
||||
event_type=event_type,
|
||||
@@ -520,15 +532,29 @@ class DeerFlowAgentAdapter:
|
||||
except Exception:
|
||||
logger.warning("non-critical event %s failed for run %s (degraded)", event_type, run_id, exc_info=True)
|
||||
return
|
||||
await self._bridge_conversation_event(run_id, event)
|
||||
await self._bridge_conversation_event(
|
||||
run_id,
|
||||
event,
|
||||
source_audit_event_id=persisted["id"] if persisted else None,
|
||||
)
|
||||
|
||||
async def _bridge_conversation_event(self, run_id: str, event: dict[str, Any]) -> None:
|
||||
async def _bridge_conversation_event(
|
||||
self,
|
||||
run_id: str,
|
||||
event: dict[str, Any],
|
||||
*,
|
||||
source_audit_event_id: str | None = None,
|
||||
) -> None:
|
||||
"""Best-effort projection into the V2 conversation event stream.
|
||||
|
||||
The per-run audit write above remains authoritative. A projection
|
||||
failure must not cause a tool to execute twice or turn a completed
|
||||
seat run into a false runtime failure; reconnect/recovery can rebuild
|
||||
the conversation view from the audit ledger later.
|
||||
seat run into a false runtime failure.
|
||||
|
||||
``source_audit_event_id`` is the real persisted audit row id — it is
|
||||
always preferred over ``event["id"]`` / ``event["source_event_id"]``
|
||||
for dedup (P0-4 fix). When the bridge retries after a restart, the
|
||||
same audit id ensures the conversation event is written exactly once.
|
||||
|
||||
P0-3: the entire ``app.state`` resolution is best-effort. If any link
|
||||
is missing (no app, no state, no conversation service), the projection
|
||||
@@ -547,7 +573,11 @@ class DeerFlowAgentAdapter:
|
||||
if not callable(bridge):
|
||||
return
|
||||
try:
|
||||
await bridge(run_id=run_id, event=event)
|
||||
await bridge(
|
||||
run_id=run_id,
|
||||
event=event,
|
||||
source_audit_event_id=source_audit_event_id,
|
||||
)
|
||||
except Exception: # noqa: BLE001 - audit already persisted
|
||||
logger.warning(
|
||||
"conversation event projection failed for run %s (%s)",
|
||||
|
||||
Reference in new issue
Block a user