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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//! The TUI's always-on prompter claim on its session (#8184).
//!
//! Why: the daemon only suspends a tool call on an `ask` rule while SOMEONE
//! is watching that session (#8100 — see
//! `crate::session::registry_prompters`); with no prompter the gate denies at
//! once. The only thing that claims a prompter on this transport is an open
//! `session.events` stream (`crate::session::events_stream::open`), and
//! `EngineState::run_chat_turn` used to issue `task.run` BEFORE opening one.
//! Since #8184 the interactive default runs the solo agent, whose first
//! `write_file`/`bash` call is gated, so that ordering raced the stream open:
//! a call that lost the race was denied with no prompt the user could answer.
//! Every reconnect gap in `pump_session_events` reopened the same hole.
//! What: [`hold_prompter_claim`] opens one dedicated `session.events` stream
//! at `setup()` time, CONFIRMS the claim exists before returning, and hands
//! the stream to a background task that drains and discards frames —
//! `pump_session_events` is what renders — reconnecting a bounded number of
//! times. The per-turn pump still claims its own prompter while it is up, so
//! a gap now needs BOTH streams down at once.
//! Test: `tests/tui_client_engine.rs::{setup_opens_a_prompter_claim_stream,
//! setup_fails_when_the_claim_stream_is_refused}` pin the ordering and the
//! confirmation deterministically;
//! `session::events_stream::events_stream_tests::session_events_stream_is_a_prompter`
//! and `task::executor::tests::solo_run_of_the_stock_pm_asks_before_write_file`
//! pin the daemon-side half this depends on — that an events stream, with no
//! `session.attach` anywhere, is the prompter a gated call suspends for. Both
//! run in-process because the `--stdio` e2e harness serves no stream requests
//! at all (`serve::transport`), so `session.events` is unreachable there.
use Arc;
use Ordering;
use ;
use ;
use EngineState;
use EngineError;
/// Open the claim stream and confirm it before returning.
///
/// Why the first frame is AWAITED and INSPECTED: `open_stream` returns once
/// the request is written, so a dial that succeeded proves nothing about the
/// daemon having run the handler that takes the claim. A refusal
/// (`session_not_found`) arrives as a terminal frame on the stream, not as a
/// dial error, so discarding the frame would let `setup` report success over a
/// session with no claim — the exact failure this module exists to prevent.
/// A received frame proves the daemon reached `events_stream::open`, which
/// claims the prompter before it sends anything.
///
/// # Errors
///
/// The dial failure; the daemon's own refusal, verbatim; or
/// [`EngineError::StreamClosed`] when the stream ends, or says nothing inside
/// [`DEFAULT_CALL_TIMEOUT`], before a first frame. `setup()` then reports a
/// daemon that answered `session.create` and could not be watched, rather than
/// starting a session whose every gated call would be denied unprompted.
/// Test: see the module docs.
pub async
/// One `session.events` dial: with no `after_seq` the daemon replays the ring,
/// then tails (`crate::session::events_stream::open`).
async