fix(hunt): open findings outside chat and calls (121c)
- toasts: status-change and agent-run toasts follow Do not disturb, pause, OS quiet mode and "Hide in calls"; a toast window the OS closed is dropped - switcher: the highlighted message stays highlighted when server results arrive; new chat keeps the highlighted person - mcp: a write-without-review window only covers the agent it was granted to; an extra request with invalid arguments returns an error; install follows a symlinked config - session: only the batch that forced a token refresh clears the flag - search: an explicit null in the answer no longer empties all results Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@@ -539,8 +539,17 @@ impl NotificationCenter {
539
539
self.sync_windows(cx);
540
540
}
541
541
542
fn own_feature_decision(&self, cx: &mut Context<Self>) -> Decision {
543
let environment = self.environment("", cx);
544
decide_proposal(
545
&self.settings,
546
teams_core::DesktopNotifications::MatchAllChats,
547
environment,
548
)
549
}
550
542
551
fn present_status_change(&mut self, user_id: &str, text: &str, cx: &mut Context<Self>) {
543
if self.settings.do_not_disturb {
552
if !self.own_feature_decision(cx).toast {
544
553
return;
545
554
}
546
555
let (name, conversation_id) = {
@@ -571,6 +580,10 @@ impl NotificationCenter {
571
580
}
572
581
573
582
pub fn present_agent_run(&mut self, run: &AgentRun, cx: &mut Context<Self>) {
583
let decision = self.own_feature_decision(cx);
584
if !decision.toast {
585
return;
586
}
574
587
let failed = matches!(run.state, RunState::Failed { .. });
575
588
let verb = if failed { "failed" } else { "finished" };
576
589
let body = if failed {
@@ -609,8 +622,7 @@ impl NotificationCenter {
609
622
.format(crate::format::clock_format())
610
623
.to_string();
611
624
}
612
let quiet = self.settings.do_not_disturb || self.app.read(cx).mode.demo;
613
if self.settings.sounds.notification_sound && !quiet {
625
if decision.sound && !self.app.read(cx).mode.demo {
614
626
self.play_notification_sound(cx);
615
627
}
616
628
self.sync_windows(cx);
@@ -849,6 +861,7 @@ impl NotificationCenter {
849
861
.handle
850
862
.update(cx, |_, window, _| window.remove_window())
851
863
.is_ok()
864
|| !window_is_open(window.handle.window_id(), cx)
852
865
});
853
866
if closed {
854
867
self.call_windows.remove(&key);
@@ -1016,6 +1029,7 @@ impl NotificationCenter {
1016
1029
.handle
1017
1030
.update(cx, |_, window, _| window.remove_window())
1018
1031
.is_ok()
1032
|| !window_is_open(window.handle.window_id(), cx)
1019
1033
});
1020
1034
if closed {
1021
1035
self.windows.remove(&id);
@@ -1464,6 +1478,12 @@ fn open_popup<V: Into<AnyView>>(
1464
1478
});
1465
1479
}
1466
1480
1481
fn window_is_open(window_id: WindowId, cx: &App) -> bool {
1482
cx.windows()
1483
.iter()
1484
.any(|window| window.window_id() == window_id)
1485
}
1486
1467
1487
fn own_presence(state: &AppState) -> PresenceKind {
1468
1488
state
1469
1489
.directory
@@ -539,8 +539,17 @@ impl NotificationCenter {539
self.sync_windows(cx);539
self.sync_windows(cx);540
}540
}541
541
542
fn own_feature_decision(&self, cx: &mut Context<Self>) -> Decision {543
let environment = self.environment("", cx);544
decide_proposal(545
&self.settings,546
teams_core::DesktopNotifications::MatchAllChats,547
environment,548
)549
}550
542
fn present_status_change(&mut self, user_id: &str, text: &str, cx: &mut Context<Self>) {551
fn present_status_change(&mut self, user_id: &str, text: &str, cx: &mut Context<Self>) {543
if self.settings.do_not_disturb {552
if !self.own_feature_decision(cx).toast {544
return;553
return;545
}554
}546
let (name, conversation_id) = {555
let (name, conversation_id) = {@@ -571,6 +580,10 @@ impl NotificationCenter {571
}580
}572
581
573
pub fn present_agent_run(&mut self, run: &AgentRun, cx: &mut Context<Self>) {582
pub fn present_agent_run(&mut self, run: &AgentRun, cx: &mut Context<Self>) {583
let decision = self.own_feature_decision(cx);584
if !decision.toast {585
return;586
}574
let failed = matches!(run.state, RunState::Failed { .. });587
let failed = matches!(run.state, RunState::Failed { .. });575
let verb = if failed { "failed" } else { "finished" };588
let verb = if failed { "failed" } else { "finished" };576
let body = if failed {589
let body = if failed {@@ -609,8 +622,7 @@ impl NotificationCenter {609
.format(crate::format::clock_format())622
.format(crate::format::clock_format())610
.to_string();623
.to_string();611
}624
}612
let quiet = self.settings.do_not_disturb || self.app.read(cx).mode.demo;625
if decision.sound && !self.app.read(cx).mode.demo {613
if self.settings.sounds.notification_sound && !quiet {614
self.play_notification_sound(cx);626
self.play_notification_sound(cx);615
}627
}616
self.sync_windows(cx);628
self.sync_windows(cx);@@ -849,6 +861,7 @@ impl NotificationCenter {849
.handle861
.handle850
.update(cx, |_, window, _| window.remove_window())862
.update(cx, |_, window, _| window.remove_window())851
.is_ok()863
.is_ok()864
|| !window_is_open(window.handle.window_id(), cx)852
});865
});853
if closed {866
if closed {854
self.call_windows.remove(&key);867
self.call_windows.remove(&key);@@ -1016,6 +1029,7 @@ impl NotificationCenter {1016
.handle1029
.handle1017
.update(cx, |_, window, _| window.remove_window())1030
.update(cx, |_, window, _| window.remove_window())1018
.is_ok()1031
.is_ok()1032
|| !window_is_open(window.handle.window_id(), cx)1019
});1033
});1020
if closed {1034
if closed {1021
self.windows.remove(&id);1035
self.windows.remove(&id);@@ -1464,6 +1478,12 @@ fn open_popup<V: Into<AnyView>>(1464
});1478
});1465
}1479
}1466
1480
1481
fn window_is_open(window_id: WindowId, cx: &App) -> bool {1482
cx.windows()1483
.iter()1484
.any(|window| window.window_id() == window_id)1485
}1486
1467
fn own_presence(state: &AppState) -> PresenceKind {1487
fn own_presence(state: &AppState) -> PresenceKind {1468
state1488
state1469
.directory1489
.directory@@ -379,11 +379,22 @@ impl NewChatDraft {
379
379
return;
380
380
}
381
381
self.searching = false;
382
let held = self
383
.results(cx)
384
.into_iter()
385
.nth(self.highlighted)
386
.map(|pick| pick.user_id);
382
387
match result {
383
388
Ok(Ok(users)) => self.remote = users.into_iter().filter_map(pick_from_user).collect(),
384
389
_ => self.search_failed = true,
385
390
}
386
self.highlighted = 0;
391
self.highlighted = held
392
.and_then(|user_id| {
393
self.results(cx)
394
.iter()
395
.position(|pick| pick.user_id == user_id)
396
})
397
.unwrap_or(0);
387
398
cx.notify();
388
399
}
389
400
@@ -379,11 +379,22 @@ impl NewChatDraft {379
return;379
return;380
}380
}381
self.searching = false;381
self.searching = false;382
let held = self383
.results(cx)384
.into_iter()385
.nth(self.highlighted)386
.map(|pick| pick.user_id);382
match result {387
match result {383
Ok(Ok(users)) => self.remote = users.into_iter().filter_map(pick_from_user).collect(),388
Ok(Ok(users)) => self.remote = users.into_iter().filter_map(pick_from_user).collect(),384
_ => self.search_failed = true,389
_ => self.search_failed = true,385
}390
}386
self.highlighted = 0;391
self.highlighted = held392
.and_then(|user_id| {393
self.results(cx)394
.iter()395
.position(|pick| pick.user_id == user_id)396
})397
.unwrap_or(0);387
cx.notify();398
cx.notify();388
}399
}389
400
@@ -320,6 +320,11 @@ impl Switcher {
320
320
if generation != self.generation {
321
321
return;
322
322
}
323
let held_message = self
324
.highlighted
325
.checked_sub(self.results.len() + self.people.len())
326
.and_then(|index| self.messages.get(index))
327
.map(|message| message.message_id.clone());
323
328
let shown_titles: HashSet<String> = self
324
329
.results
325
330
.iter()
@@ -346,7 +351,15 @@ impl Switcher {
346
351
now.offset().fix(),
347
352
);
348
353
self.messages = merge_messages(&self.local_messages, server, MAX_MESSAGE_RESULTS);
349
self.highlighted = self.highlighted.min(self.result_count().saturating_sub(1));
354
let held_position = held_message.and_then(|message_id| {
355
self.messages
356
.iter()
357
.position(|message| message.message_id == message_id)
358
});
359
self.highlighted = match held_position {
360
Some(position) => self.results.len() + self.people.len() + position,
361
None => self.highlighted.min(self.result_count().saturating_sub(1)),
362
};
350
363
cx.notify();
351
364
}
352
365
@@ -320,6 +320,11 @@ impl Switcher {320
if generation != self.generation {320
if generation != self.generation {321
return;321
return;322
}322
}323
let held_message = self324
.highlighted325
.checked_sub(self.results.len() + self.people.len())326
.and_then(|index| self.messages.get(index))327
.map(|message| message.message_id.clone());323
let shown_titles: HashSet<String> = self328
let shown_titles: HashSet<String> = self324
.results329
.results325
.iter()330
.iter()@@ -346,7 +351,15 @@ impl Switcher {346
now.offset().fix(),351
now.offset().fix(),347
);352
);348
self.messages = merge_messages(&self.local_messages, server, MAX_MESSAGE_RESULTS);353
self.messages = merge_messages(&self.local_messages, server, MAX_MESSAGE_RESULTS);349
self.highlighted = self.highlighted.min(self.result_count().saturating_sub(1));354
let held_position = held_message.and_then(|message_id| {355
self.messages356
.iter()357
.position(|message| message.message_id == message_id)358
});359
self.highlighted = match held_position {360
Some(position) => self.results.len() + self.people.len() + position,361
None => self.highlighted.min(self.result_count().saturating_sub(1)),362
};350
cx.notify();363
cx.notify();351
}364
}352
365
@@ -213,8 +213,24 @@ struct WireResult {
213
213
source: Value,
214
214
}
215
215
216
/// `#[serde(default)]` covers a missing field, not an explicit null; one null would empty the whole answer.
217
fn without_nulls(value: &Value) -> Value {
218
match value {
219
Value::Object(fields) => Value::Object(
220
fields
221
.iter()
222
.filter(|(_, field)| !field.is_null())
223
.map(|(name, field)| (name.clone(), without_nulls(field)))
224
.collect(),
225
),
226
Value::Array(items) => Value::Array(items.iter().map(without_nulls).collect()),
227
other => other.clone(),
228
}
229
}
230
216
231
pub fn parse_suggestions(body: &Value) -> Suggestions {
217
let wire: WireSuggestions = WireSuggestions::deserialize(body).unwrap_or_default();
232
let wire: WireSuggestions =
233
WireSuggestions::deserialize(without_nulls(body)).unwrap_or_default();
218
234
let mut suggestions = Suggestions {
219
235
best_matches: wire
220
236
.layout_hints
@@ -261,7 +277,7 @@ pub fn parse_suggestions(body: &Value) -> Suggestions {
261
277
}
262
278
263
279
pub fn parse_query_results(body: &Value) -> QueryResults {
264
let wire: WireQuery = WireQuery::deserialize(body).unwrap_or_default();
280
let wire: WireQuery = WireQuery::deserialize(without_nulls(body)).unwrap_or_default();
265
281
let mut results = QueryResults {
266
282
search_terms: wire.search_terms,
267
283
..QueryResults::default()
@@ -213,8 +213,24 @@ struct WireResult {213
source: Value,213
source: Value,214
}214
}215
215
216
/// `#[serde(default)]` covers a missing field, not an explicit null; one null would empty the whole answer.217
fn without_nulls(value: &Value) -> Value {218
match value {219
Value::Object(fields) => Value::Object(220
fields221
.iter()222
.filter(|(_, field)| !field.is_null())223
.map(|(name, field)| (name.clone(), without_nulls(field)))224
.collect(),225
),226
Value::Array(items) => Value::Array(items.iter().map(without_nulls).collect()),227
other => other.clone(),228
}229
}230
216
pub fn parse_suggestions(body: &Value) -> Suggestions {231
pub fn parse_suggestions(body: &Value) -> Suggestions {217
let wire: WireSuggestions = WireSuggestions::deserialize(body).unwrap_or_default();232
let wire: WireSuggestions =233
WireSuggestions::deserialize(without_nulls(body)).unwrap_or_default();218
let mut suggestions = Suggestions {234
let mut suggestions = Suggestions {219
best_matches: wire235
best_matches: wire220
.layout_hints236
.layout_hints@@ -261,7 +277,7 @@ pub fn parse_suggestions(body: &Value) -> Suggestions {261
}277
}262
278
263
pub fn parse_query_results(body: &Value) -> QueryResults {279
pub fn parse_query_results(body: &Value) -> QueryResults {264
let wire: WireQuery = WireQuery::deserialize(body).unwrap_or_default();280
let wire: WireQuery = WireQuery::deserialize(without_nulls(body)).unwrap_or_default();265
let mut results = QueryResults {281
let mut results = QueryResults {266
search_terms: wire.search_terms,282
search_terms: wire.search_terms,267
..QueryResults::default()283
..QueryResults::default()@@ -234,3 +234,15 @@ fn unknown_shape_parses_to_empty_results() {
234
234
QueryResults::default()
235
235
);
236
236
}
237
238
#[test]
239
fn a_null_where_a_list_is_expected_keeps_the_other_results() {
240
let mut body = fixture(SUGGESTIONS);
241
body["LayoutHints"] = serde_json::Value::Null;
242
let suggestions = parse_suggestions(&body);
243
assert_eq!(
244
suggestions.people,
245
parse_suggestions(&fixture(SUGGESTIONS)).people
246
);
247
assert!(!suggestions.people.is_empty());
248
}
@@ -234,3 +234,15 @@ fn unknown_shape_parses_to_empty_results() {234
QueryResults::default()234
QueryResults::default()235
);235
);236
}236
}237
238
#[test]239
fn a_null_where_a_list_is_expected_keeps_the_other_results() {240
let mut body = fixture(SUGGESTIONS);241
body["LayoutHints"] = serde_json::Value::Null;242
let suggestions = parse_suggestions(&body);243
assert_eq!(244
suggestions.people,245
parse_suggestions(&fixture(SUGGESTIONS)).people246
);247
assert!(!suggestions.people.is_empty());248
}@@ -390,8 +390,11 @@ impl AgentHub {
390
390
self.wake.notify_waiters();
391
391
}
392
392
393
pub fn needs_review(&self, conversation_id: &str) -> bool {
394
self.policy().review && self.free_writing(conversation_id).is_none()
393
pub fn needs_review(&self, conversation_id: &str, agent: Option<&str>) -> bool {
394
let granted = self
395
.free_writing(conversation_id)
396
.is_some_and(|grant| grant.agent.is_none() || grant.agent.as_deref() == agent);
397
self.policy().review && !granted
395
398
}
396
399
397
400
pub fn pending_proposal(&self, conversation_id: &str) -> Option<Proposal> {
@@ -1033,18 +1036,21 @@ mod tests {
1033
1036
#[test]
1034
1037
fn a_free_writing_window_skips_review_until_it_ends_or_stops() {
1035
1038
let (hub, _receiver, _store) = hub_with(open_policy());
1036
assert!(hub.needs_review("c1"));
1039
let claude = Some("claude");
1040
assert!(hub.needs_review("c1", claude));
1037
1041
hub.grant_free_writing(
1038
1042
"c1",
1039
1043
Utc::now() + chrono::Duration::minutes(15),
1040
1044
Some("claude".to_owned()),
1041
1045
);
1042
assert!(!hub.needs_review("c1"));
1043
assert!(hub.needs_review("c2"));
1046
assert!(!hub.needs_review("c1", claude));
1047
assert!(hub.needs_review("c1", Some("codex")));
1048
assert!(hub.needs_review("c1", None));
1049
assert!(hub.needs_review("c2", claude));
1044
1050
hub.stop_free_writing("c1");
1045
assert!(hub.needs_review("c1"));
1051
assert!(hub.needs_review("c1", claude));
1046
1052
hub.grant_free_writing("c1", Utc::now() - chrono::Duration::seconds(1), None);
1047
assert!(hub.needs_review("c1"));
1053
assert!(hub.needs_review("c1", claude));
1048
1054
let kinds: Vec<Option<DateTime<Utc>>> = hub
1049
1055
.events_after(0)
1050
1056
.0
@@ -390,8 +390,11 @@ impl AgentHub {390
self.wake.notify_waiters();390
self.wake.notify_waiters();391
}391
}392
392
393
pub fn needs_review(&self, conversation_id: &str) -> bool {393
pub fn needs_review(&self, conversation_id: &str, agent: Option<&str>) -> bool {394
self.policy().review && self.free_writing(conversation_id).is_none()394
let granted = self395
.free_writing(conversation_id)396
.is_some_and(|grant| grant.agent.is_none() || grant.agent.as_deref() == agent);397
self.policy().review && !granted395
}398
}396
399
397
pub fn pending_proposal(&self, conversation_id: &str) -> Option<Proposal> {400
pub fn pending_proposal(&self, conversation_id: &str) -> Option<Proposal> {@@ -1033,18 +1036,21 @@ mod tests {1033
#[test]1036
#[test]1034
fn a_free_writing_window_skips_review_until_it_ends_or_stops() {1037
fn a_free_writing_window_skips_review_until_it_ends_or_stops() {1035
let (hub, _receiver, _store) = hub_with(open_policy());1038
let (hub, _receiver, _store) = hub_with(open_policy());1036
assert!(hub.needs_review("c1"));1039
let claude = Some("claude");1040
assert!(hub.needs_review("c1", claude));1037
hub.grant_free_writing(1041
hub.grant_free_writing(1038
"c1",1042
"c1",1039
Utc::now() + chrono::Duration::minutes(15),1043
Utc::now() + chrono::Duration::minutes(15),1040
Some("claude".to_owned()),1044
Some("claude".to_owned()),1041
);1045
);1042
assert!(!hub.needs_review("c1"));1046
assert!(!hub.needs_review("c1", claude));1043
assert!(hub.needs_review("c2"));1047
assert!(hub.needs_review("c1", Some("codex")));1048
assert!(hub.needs_review("c1", None));1049
assert!(hub.needs_review("c2", claude));1044
hub.stop_free_writing("c1");1050
hub.stop_free_writing("c1");1045
assert!(hub.needs_review("c1"));1051
assert!(hub.needs_review("c1", claude));1046
hub.grant_free_writing("c1", Utc::now() - chrono::Duration::seconds(1), None);1052
hub.grant_free_writing("c1", Utc::now() - chrono::Duration::seconds(1), None);1047
assert!(hub.needs_review("c1"));1053
assert!(hub.needs_review("c1", claude));1048
let kinds: Vec<Option<DateTime<Utc>>> = hub1054
let kinds: Vec<Option<DateTime<Utc>>> = hub1049
.events_after(0)1055
.events_after(0)1050
.01056
.0@@ -21,6 +21,8 @@ fn sibling(path: &Path, prefix: &str, suffix: &str) -> PathBuf {
21
21
}
22
22
23
23
pub(super) fn write_atomic(path: &Path, contents: &str) -> Result<(), InstallError> {
24
let resolved = fs::canonicalize(path).unwrap_or_else(|_| path.to_path_buf());
25
let path = resolved.as_path();
24
26
let existing = fs::metadata(path).ok();
25
27
if let Some(parent) = path.parent() {
26
28
fs::create_dir_all(parent).map_err(|error| InstallError::io(parent, error))?;
@@ -21,6 +21,8 @@ fn sibling(path: &Path, prefix: &str, suffix: &str) -> PathBuf {21
}21
}22
22
23
pub(super) fn write_atomic(path: &Path, contents: &str) -> Result<(), InstallError> {23
pub(super) fn write_atomic(path: &Path, contents: &str) -> Result<(), InstallError> {24
let resolved = fs::canonicalize(path).unwrap_or_else(|_| path.to_path_buf());25
let path = resolved.as_path();24
let existing = fs::metadata(path).ok();26
let existing = fs::metadata(path).ok();25
if let Some(parent) = path.parent() {27
if let Some(parent) = path.parent() {26
fs::create_dir_all(parent).map_err(|error| InstallError::io(parent, error))?;28
fs::create_dir_all(parent).map_err(|error| InstallError::io(parent, error))?;@@ -47,8 +47,14 @@ impl ToolSession {
47
47
}
48
48
49
49
pub async fn call(&self, name: &str, arguments: &str) -> Result<String, String> {
50
let parsed: Value = serde_json::from_str(arguments).unwrap_or(Value::Object(Map::new()));
51
let arguments = parsed.as_object().cloned().unwrap_or_default();
50
let arguments = if arguments.trim().is_empty() {
51
Map::new()
52
} else {
53
serde_json::from_str::<Value>(arguments)
54
.ok()
55
.and_then(|parsed| parsed.as_object().cloned())
56
.ok_or_else(|| "arguments are not a JSON object".to_owned())?
57
};
52
58
let params = CallToolRequestParams::new(name.to_owned()).with_arguments(arguments);
53
59
let result = self
54
60
.client
@@ -47,8 +47,14 @@ impl ToolSession {47
}47
}48
48
49
pub async fn call(&self, name: &str, arguments: &str) -> Result<String, String> {49
pub async fn call(&self, name: &str, arguments: &str) -> Result<String, String> {50
let parsed: Value = serde_json::from_str(arguments).unwrap_or(Value::Object(Map::new()));50
let arguments = if arguments.trim().is_empty() {51
let arguments = parsed.as_object().cloned().unwrap_or_default();51
Map::new()52
} else {53
serde_json::from_str::<Value>(arguments)54
.ok()55
.and_then(|parsed| parsed.as_object().cloned())56
.ok_or_else(|| "arguments are not a JSON object".to_owned())?57
};52
let params = CallToolRequestParams::new(name.to_owned()).with_arguments(arguments);58
let params = CallToolRequestParams::new(name.to_owned()).with_arguments(arguments);53
let result = self59
let result = self54
.client60
.client@@ -756,7 +756,7 @@ impl TeamsTools {
756
756
);
757
757
let (reply_to_message_id, agent, session_id) =
758
758
(params.reply_to_message_id, params.agent, params.session_id);
759
let direct = !self.hub.needs_review(&conversation_id);
759
let direct = !self.hub.needs_review(&conversation_id, agent.as_deref());
760
760
let free_writing_ask =
761
761
params
762
762
.ask_free_writing
@@ -884,7 +884,9 @@ impl TeamsTools {
884
884
"emoji is not a reaction Teams supports, use a single common emoji".to_owned(),
885
885
);
886
886
}
887
let direct = !self.hub.needs_review(¶ms.conversation_id);
887
let direct = !self
888
.hub
889
.needs_review(¶ms.conversation_id, params.agent.as_deref());
888
890
let reaction = self
889
891
.hub
890
892
.add_reaction_proposal(NewReactionProposal {
@@ -756,7 +756,7 @@ impl TeamsTools {756
);756
);757
let (reply_to_message_id, agent, session_id) =757
let (reply_to_message_id, agent, session_id) =758
(params.reply_to_message_id, params.agent, params.session_id);758
(params.reply_to_message_id, params.agent, params.session_id);759
let direct = !self.hub.needs_review(&conversation_id);759
let direct = !self.hub.needs_review(&conversation_id, agent.as_deref());760
let free_writing_ask =760
let free_writing_ask =761
params761
params762
.ask_free_writing762
.ask_free_writing@@ -884,7 +884,9 @@ impl TeamsTools {884
"emoji is not a reaction Teams supports, use a single common emoji".to_owned(),884
"emoji is not a reaction Teams supports, use a single common emoji".to_owned(),885
);885
);886
}886
}887
let direct = !self.hub.needs_review(¶ms.conversation_id);887
let direct = !self888
.hub889
.needs_review(¶ms.conversation_id, params.agent.as_deref());888
let reaction = self890
let reaction = self889
.hub891
.hub890
.add_reaction_proposal(NewReactionProposal {892
.add_reaction_proposal(NewReactionProposal {@@ -136,14 +136,24 @@ impl Session {
136
136
pub async fn batch(&self, requests: &[Request], scope: &Scope) -> Result<Vec<ApiResponse>> {
137
137
let mut results: Vec<Option<ApiResponse>> = vec![None; requests.len()];
138
138
let mut pending: Vec<usize> = (0..requests.len()).collect();
139
let mut forced_here = false;
139
140
for attempt in 0..=self.config.max_throttle_retries {
140
141
let batch: Vec<&Request> = pending.iter().map(|&index| &requests[index]).collect();
141
let answers = self.run_with_fresh_token(&batch, scope).await?;
142
let answers = match self.run_with_fresh_token(&batch, scope).await {
143
Ok(answers) => answers,
144
Err(error) => {
145
if forced_here {
146
self.force_refresh.store(false, Ordering::SeqCst);
147
}
148
return Err(error);
149
}
150
};
142
151
let unauthorized_first_try =
143
152
attempt == 0 && answers.iter().any(|answer| answer.status == 401);
144
153
if unauthorized_first_try {
145
154
// A CAE-revoked token stays unexpired in the app cache, so only a refresh-token grant replaces it.
146
155
self.force_refresh.store(true, Ordering::SeqCst);
156
forced_here = true;
147
157
self.reload_all().await;
148
158
sleep(self.config.unauthorized_reload_wait).await;
149
159
self.drop_all().await;
@@ -156,8 +166,9 @@ impl Session {
156
166
retry.push(index);
157
167
}
158
168
}
159
if !unauthorized_first_try {
169
if forced_here && !unauthorized_first_try {
160
170
self.force_refresh.store(false, Ordering::SeqCst);
171
forced_here = false;
161
172
}
162
173
if retry.is_empty() || attempt == self.config.max_throttle_retries {
163
174
break;
@@ -136,14 +136,24 @@ impl Session {136
pub async fn batch(&self, requests: &[Request], scope: &Scope) -> Result<Vec<ApiResponse>> {136
pub async fn batch(&self, requests: &[Request], scope: &Scope) -> Result<Vec<ApiResponse>> {137
let mut results: Vec<Option<ApiResponse>> = vec![None; requests.len()];137
let mut results: Vec<Option<ApiResponse>> = vec![None; requests.len()];138
let mut pending: Vec<usize> = (0..requests.len()).collect();138
let mut pending: Vec<usize> = (0..requests.len()).collect();139
let mut forced_here = false;139
for attempt in 0..=self.config.max_throttle_retries {140
for attempt in 0..=self.config.max_throttle_retries {140
let batch: Vec<&Request> = pending.iter().map(|&index| &requests[index]).collect();141
let batch: Vec<&Request> = pending.iter().map(|&index| &requests[index]).collect();141
let answers = self.run_with_fresh_token(&batch, scope).await?;142
let answers = match self.run_with_fresh_token(&batch, scope).await {143
Ok(answers) => answers,144
Err(error) => {145
if forced_here {146
self.force_refresh.store(false, Ordering::SeqCst);147
}148
return Err(error);149
}150
};142
let unauthorized_first_try =151
let unauthorized_first_try =143
attempt == 0 && answers.iter().any(|answer| answer.status == 401);152
attempt == 0 && answers.iter().any(|answer| answer.status == 401);144
if unauthorized_first_try {153
if unauthorized_first_try {145
// A CAE-revoked token stays unexpired in the app cache, so only a refresh-token grant replaces it.154
// A CAE-revoked token stays unexpired in the app cache, so only a refresh-token grant replaces it.146
self.force_refresh.store(true, Ordering::SeqCst);155
self.force_refresh.store(true, Ordering::SeqCst);156
forced_here = true;147
self.reload_all().await;157
self.reload_all().await;148
sleep(self.config.unauthorized_reload_wait).await;158
sleep(self.config.unauthorized_reload_wait).await;149
self.drop_all().await;159
self.drop_all().await;@@ -156,8 +166,9 @@ impl Session {156
retry.push(index);166
retry.push(index);157
}167
}158
}168
}159
if !unauthorized_first_try {169
if forced_here && !unauthorized_first_try {160
self.force_refresh.store(false, Ordering::SeqCst);170
self.force_refresh.store(false, Ordering::SeqCst);171
forced_here = false;161
}172
}162
if retry.is_empty() || attempt == self.config.max_throttle_retries {173
if retry.is_empty() || attempt == self.config.max_throttle_retries {163
break;174
break;