1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//! Flush mechanism for ACP connection
//!
//! This module provides helper functions to ensure all pending notifications
//! are sent before returning EndTurn to the client.
//!
//! ## The Problem
//!
//! The sacp library's `send_notification()` uses `unbounded_send()` which
//! returns immediately, but messages are processed asynchronously by the
//! outgoing_protocol_actor. This causes a race condition where EndTurn can
//! arrive before all notifications are sent.
//!
//! ## The Solution
//!
//! Since the sacp fork does not have a native flush() API yet, we use a
//! minimal fixed delay (5ms) to ensure message delivery. This is sufficient
//! because the SDK already implements query-scoped message channels,
//! preventing cross-query message mixing.
//!
//! See: docs/MESSAGE_ORDERING_ISSUE.md
use JrConnectionCx;
use AgentToClient;
/// Ensure all pending notifications have been flushed to the client
///
/// Since the sacp fork does not have a native flush() API yet,
/// we use a minimal fixed delay (5ms) to ensure message delivery.
/// This is sufficient because the SDK already implements query-scoped
/// message channels, preventing cross-query message mixing.
///
/// # Arguments
///
/// * `connection_cx` - The ACP connection context (unused but kept for API consistency)
/// * `notification_count` - Number of notifications sent (used for logging)
pub async