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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
// Source: ~/claudecode/openclaudecode/src/utils/conversationRecovery.ts
use serde::{Deserialize, Serialize};
use std::collections::HashSet;
use std::fs;
use std::path::PathBuf;
/// Represents a recovered conversation state.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ConversationRecovery {
/// Deserialized message history
pub messages: Vec<serde_json::Value>,
/// Turn interruption state detected during recovery
pub turn_interruption_state: TurnInterruptionState,
/// Session ID if available
pub session_id: Option<String>,
}
/// Represents the state of a turn interruption detected during conversation recovery.
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum TurnInterruptionState {
/// No interruption detected
None,
/// Session was interrupted mid-prompt with the interrupted message
InterruptedPrompt { message: serde_json::Value },
}
/// Result of deserializing messages with interrupt detection.
#[derive(Clone, Debug)]
pub struct DeserializeResult {
/// Filtered and normalized messages
pub messages: Vec<serde_json::Value>,
/// Detected turn interruption state
pub turn_interruption_state: TurnInterruptionState,
}
/// No-response sentinel content used when a conversation needs to be API-valid.
pub const NO_RESPONSE_REQUESTED: &str = "(no response requested)";
/// Continuation message appended when a turn was interrupted mid-stream.
pub const CONTINUE_PROMPT: &str = "Continue from where you left off.";
/// Migrate legacy attachment types to current types for backward compatibility.
///
/// Transforms old `new_file` and `new_directory` attachment types to current `file`
/// and `directory` types, adding displayPath when missing.
fn migrate_legacy_attachment(message: &serde_json::Value) -> serde_json::Value {
let msg_type = message.get("type").and_then(|v| v.as_str());
if msg_type != Some("attachment") {
return message.clone();
}
let mut msg = message.clone();
let attachment = msg.get_mut("attachment");
if let Some(attachment) = attachment {
let att_type = attachment.get("type").and_then(|v| v.as_str()).map(|s| s.to_string());
// Transform legacy new_file type
if att_type == Some("new_file".to_string()) {
if let Some(filename) = attachment.get("filename").and_then(|v| v.as_str()) {
if let Some(obj) = attachment.as_object_mut() {
obj.insert("type".to_string(), serde_json::json!("file"));
obj.insert("displayPath".to_string(), serde_json::json!(filename));
}
}
return msg;
}
// Transform legacy new_directory type
if att_type == Some("new_directory".to_string()) {
if let Some(path) = attachment.get("path").and_then(|v| v.as_str()) {
if let Some(obj) = attachment.as_object_mut() {
obj.insert("type".to_string(), serde_json::json!("directory"));
obj.insert("displayPath".to_string(), serde_json::json!(path));
}
}
return msg;
}
// Backfill displayPath for attachments from old sessions
if attachment.get("displayPath").is_none() {
let path = attachment
.get("filename")
.or_else(|| attachment.get("path"))
.or_else(|| attachment.get("skillDir"))
.and_then(|v| v.as_str());
if let Some(path) = path {
if let Some(obj) = attachment.as_object_mut() {
obj.insert("displayPath".to_string(), serde_json::json!(path));
}
}
}
}
msg
}
/// Strip invalid permissionMode values from deserialized user messages.
fn strip_invalid_permission_modes(messages: &mut Vec<serde_json::Value>) {
let valid_modes: HashSet<&str> = ["default", "auto", "auto-accept", "auto-deny", "bypass"]
.iter()
.cloned()
.collect();
for msg in messages.iter_mut() {
if let Some(msg_type) = msg.get("type").and_then(|v| v.as_str()) {
if msg_type == "user" {
if let Some(msg_obj) = msg.as_object_mut() {
if let Some(pm) = msg_obj.get("permissionMode").and_then(|v| v.as_str()) {
if !valid_modes.contains(pm) {
msg_obj.remove("permissionMode");
}
}
}
}
}
}
}
/// Filter out unresolved tool uses from message history.
/// Removes assistant messages whose tool_use blocks have no matching tool_result,
/// and any synthetic messages that follow them.
fn filter_unresolved_tool_uses(messages: &[serde_json::Value]) -> Vec<serde_json::Value> {
// First pass: collect all tool_result IDs
let mut tool_result_ids: HashSet<String> = HashSet::new();
for msg in messages {
if let Some(msg_type) = msg.get("type").and_then(|v| v.as_str()) {
if msg_type == "user" {
if let Some(content) = msg.get("message").and_then(|v| v.get("content")) {
if let Some(blocks) = content.as_array() {
for block in blocks {
if let Some(t) = block.get("type").and_then(|v| v.as_str()) {
if t == "tool_result" {
if let Some(id) =
block.get("tool_use_id").and_then(|v| v.as_str())
{
tool_result_ids.insert(id.to_string());
}
}
}
}
}
}
}
}
}
// Second pass: filter out assistant messages with unmatched tool_uses
let mut result = Vec::new();
for msg in messages {
if let Some(msg_type) = msg.get("type").and_then(|v| v.as_str()) {
if msg_type == "assistant" {
if let Some(content) = msg.get("message").and_then(|v| v.get("content")) {
if let Some(blocks) = content.as_array() {
let has_unresolved = blocks.iter().any(|block| {
if let Some(t) = block.get("type").and_then(|v| v.as_str()) {
if t == "tool_use" {
if let Some(id) = block.get("id").and_then(|v| v.as_str()) {
return !tool_result_ids.contains(id);
}
}
}
false
});
if has_unresolved {
continue;
}
}
}
}
}
result.push(msg.clone());
}
result
}
/// Filter out orphaned thinking-only assistant messages that can cause API errors
/// during resume. These occur when streaming yields separate messages per content
/// block and interleaved user messages prevent proper merging by message.id.
fn filter_orphaned_thinking_messages(messages: &[serde_json::Value]) -> Vec<serde_json::Value> {
// Remove assistant messages that contain only thinking/redacted_thinking content
// with no text or tool_use blocks, as these orphans can cause API validation errors.
messages
.iter()
.filter(|msg| {
if let Some(msg_type) = msg.get("type").and_then(|v| v.as_str()) {
if msg_type == "assistant" {
if let Some(content) = msg.get("message").and_then(|v| v.get("content")) {
if let Some(blocks) = content.as_array() {
// If ALL blocks are thinking types, it's an orphan
let all_thinking = blocks.iter().all(|block| {
if let Some(t) = block.get("type").and_then(|v| v.as_str()) {
t == "thinking" || t == "redacted_thinking"
} else {
false
}
});
return !all_thinking || blocks.is_empty();
}
}
}
}
true
})
.cloned()
.collect()
}
/// Filter out assistant messages with only whitespace text content.
/// This can happen when model outputs "\n\n" before thinking, user cancels mid-stream.
fn filter_whitespace_only_assistant_messages(
messages: &[serde_json::Value],
) -> Vec<serde_json::Value> {
messages
.iter()
.filter(|msg| {
if let Some(msg_type) = msg.get("type").and_then(|v| v.as_str()) {
if msg_type == "assistant" {
if let Some(content) = msg.get("message").and_then(|v| v.get("content")) {
// Check if all text content blocks contain only whitespace
if let Some(blocks) = content.as_array() {
let all_whitespace = blocks.iter().all(|block| {
if let Some(t) = block.get("type").and_then(|v| v.as_str()) {
if t == "text" {
block
.get("text")
.and_then(|v| v.as_str())
.map(|s| s.trim().is_empty())
.unwrap_or(true)
} else {
true // Non-text blocks are OK
}
} else {
false
}
});
// If ALL text blocks are whitespace AND there are no non-text blocks, filter it
return !all_whitespace;
}
}
}
}
true
})
.cloned()
.collect()
}
/// Detects whether the conversation was interrupted mid-turn based on the last message.
///
/// An assistant as last message (after filtering unresolved tool_uses) is treated as
/// a completed turn because stop_reason is always null on persisted messages in the
/// streaming path.
fn detect_turn_interruption(messages: &[serde_json::Value]) -> TurnInterruptionState {
if messages.is_empty() {
return TurnInterruptionState::None;
}
// Find the last turn-relevant message, skipping system/progress and
// synthetic API error assistant messages.
let last_relevant = messages.iter().rev().find(|msg| {
if let Some(msg_type) = msg.get("type").and_then(|v| v.as_str()) {
if msg_type == "system" || msg_type == "progress" {
return false;
}
// Skip API error assistant messages
if msg_type == "assistant" {
if let Some(is_api_error) = msg.get("isApiErrorMessage").and_then(|v| v.as_bool())
{
return !is_api_error;
}
}
return true;
}
false
});
let Some(last_msg) = last_relevant else {
return TurnInterruptionState::None;
};
let msg_type = last_msg.get("type").and_then(|v| v.as_str());
match msg_type {
Some("assistant") => {
// In the streaming path, stop_reason is always null on persisted messages
// because messages are recorded at content_block_stop time. After
// filterUnresolvedToolUses has removed assistant messages with unmatched
// tool_uses, an assistant as the last message means the turn most likely
// completed normally.
TurnInterruptionState::None
}
Some("user") => {
// Check isMeta and isCompactSummary
let is_meta = last_msg.get("isMeta").and_then(|v| v.as_bool()).unwrap_or(false);
let is_compact = last_msg
.get("isCompactSummary")
.and_then(|v| v.as_bool())
.unwrap_or(false);
if is_meta || is_compact {
return TurnInterruptionState::None;
}
// Check if this is a tool_result message
if is_tool_use_result_message(last_msg) {
// Brief mode drops the trailing assistant text block, so a completed
// brief-mode turn legitimately ends on a tool_result.
// Without this check, resume misclassifies every brief-mode session as interrupted.
if is_terminal_tool_result(last_msg, messages) {
return TurnInterruptionState::None;
}
return TurnInterruptionState::None; // Interrupted mid-turn after tool result
}
// Plain text user prompt - CC hadn't started responding
TurnInterruptionState::InterruptedPrompt {
message: last_msg.clone(),
}
}
Some("attachment") => {
// Attachments are part of the user turn - the user provided context but
// the assistant never responded.
TurnInterruptionState::None // Treated as interrupted but without specific message
}
_ => TurnInterruptionState::None,
}
}
/// Check if a user message is a tool_result message.
fn is_tool_use_result_message(msg: &serde_json::Value) -> bool {
if let Some(msg_type) = msg.get("type").and_then(|v| v.as_str()) {
if msg_type == "user" {
if let Some(content) = msg.get("message").and_then(|v| v.get("content")) {
if let Some(blocks) = content.as_array() {
return !blocks.is_empty()
&& blocks.iter().all(|block| {
block
.get("type")
.and_then(|v| v.as_str())
.map(|t| t == "tool_result")
.unwrap_or(false)
});
}
}
}
}
false
}
/// Check if a tool_result is from a terminal tool that completes a turn.
/// Walks back to find the assistant tool_use that this result belongs to.
fn is_terminal_tool_result(
_result: &serde_json::Value,
_messages: &[serde_json::Value],
) -> bool {
// In the TS version, this checks for BRIEF_TOOL_NAME, LEGACY_BRIEF_TOOL_NAME,
// and SEND_USER_FILE_TOOL_NAME. Since these are feature-flagged in TS,
// we conservatively return false (no known terminal tools in the Rust build).
false
}
/// Deserialize messages from serialized format, filtering unresolved tool uses,
/// orphaned thinking messages, and whitespace-only assistant messages.
/// Appends a synthetic assistant sentinel when the last message is from the user.
pub fn deserialize_messages(serialized_messages: &[serde_json::Value]) -> Vec<serde_json::Value> {
deserialize_messages_with_interrupt_detection(serialized_messages).messages
}
/// Like deserialize_messages, but also detects whether the session was interrupted
/// mid-turn. Used by the SDK resume path to auto-continue interrupted turns after
/// a gateway-triggered restart.
pub fn deserialize_messages_with_interrupt_detection(
serialized_messages: &[serde_json::Value],
) -> DeserializeResult {
// Transform legacy attachment types before processing
let migrated: Vec<serde_json::Value> = serialized_messages
.iter()
.map(migrate_legacy_attachment)
.collect();
// Strip invalid permissionMode values from deserialized user messages.
let mut migrated = migrated;
strip_invalid_permission_modes(&mut migrated);
// Filter out unresolved tool uses
let filtered_tool_uses = filter_unresolved_tool_uses(&migrated);
// Filter out orphaned thinking-only assistant messages
let filtered_thinking = filter_orphaned_thinking_messages(&filtered_tool_uses);
// Filter out assistant messages with only whitespace text content
let filtered_messages = filter_whitespace_only_assistant_messages(&filtered_thinking);
// Detect turn interruption
let internal_state = detect_turn_interruption(&filtered_messages);
// Transform mid-turn interruptions into interrupted_prompt by appending
// a synthetic continuation message
let mut messages = filtered_messages;
let turn_interruption_state = if matches!(
internal_state,
TurnInterruptionState::None // The TS "interrupted_turn" case maps to no specific message
) {
// Check if the last message is a user message (plain text, not meta)
if let Some(last) = messages.last() {
if let Some(msg_type) = last.get("type").and_then(|v| v.as_str()) {
if msg_type == "user" {
let is_meta = last.get("isMeta").and_then(|v| v.as_bool()).unwrap_or(false);
let is_compact = last
.get("isCompactSummary")
.and_then(|v| v.as_bool())
.unwrap_or(false);
if !is_meta && !is_compact {
// Append continuation message
let continuation = create_user_message(CONTINUE_PROMPT, true);
messages.push(continuation.clone());
return DeserializeResult {
messages,
turn_interruption_state: TurnInterruptionState::InterruptedPrompt {
message: continuation,
},
};
}
}
}
}
TurnInterruptionState::None
} else {
internal_state
};
// Append a synthetic assistant sentinel after the last user message so
// the conversation is API-valid if no resume action is taken.
if let Some(last) = messages.last() {
if let Some(msg_type) = last.get("type").and_then(|v| v.as_str()) {
if msg_type == "user" {
let sentinel = create_assistant_message(NO_RESPONSE_REQUESTED);
messages.push(sentinel);
}
}
}
DeserializeResult {
messages,
turn_interruption_state,
}
}
/// Create a user message with the given content.
fn create_user_message(content: &str, is_meta: bool) -> serde_json::Value {
serde_json::json!({
"type": "user",
"message": {
"content": content
},
"isMeta": is_meta
})
}
/// Create an assistant message with the given text content.
fn create_assistant_message(content: &str) -> serde_json::Value {
serde_json::json!({
"type": "assistant",
"message": {
"content": [{
"type": "text",
"text": content
}]
}
})
}
/// Restore skill state from invoked_skills attachments in messages.
/// This ensures that skills are preserved across resume after compaction.
pub fn restore_skill_state_from_messages(messages: &[serde_json::Value]) {
// In the TS version, this calls addInvokedSkill for each skill in the attachments.
// The Rust implementation would need access to the global skill state.
// This is a simplified placeholder that logs what would be restored.
for message in messages {
if let Some(msg_type) = message.get("type").and_then(|v| v.as_str()) {
if msg_type == "attachment" {
if let Some(attachment) = message.get("attachment") {
if let Some(att_type) = attachment.get("type").and_then(|v| v.as_str()) {
if att_type == "invoked_skills" {
if let Some(skills) = attachment.get("skills").and_then(|v| v.as_array())
{
for skill in skills {
if let (Some(name), Some(path), Some(_content)) = (
skill.get("name").and_then(|v| v.as_str()),
skill.get("path").and_then(|v| v.as_str()),
skill.get("content"),
) {
log::debug!(
"Restoring invoked skill: {} at {}",
name,
path
);
}
}
}
}
if att_type == "skill_listing" {
// A prior process already injected the skills-available reminder.
// Without this, every resume re-announces the same tokens.
log::debug!("Suppressing duplicate skill listing reminder");
}
}
}
}
}
}
}
/// Recover conversation from a session ID or most recent session.
/// Loads, deserializes, and processes messages for resume.
pub async fn recover_conversation(session_id: &str) -> Result<ConversationRecovery, String> {
// Load messages from session storage
let messages = load_conversation_state().unwrap_or_default();
// Restore skill state from invoked_skills attachments before deserialization.
restore_skill_state_from_messages(&messages);
// Deserialize messages to handle unresolved tool uses and ensure proper format
let deserialized = deserialize_messages_with_interrupt_detection(&messages);
// Process session start hooks for resume
let hook_messages = process_session_start_hooks("resume", session_id).await;
// Append hook messages to the conversation
let mut final_messages = deserialized.messages;
final_messages.extend(hook_messages);
Ok(ConversationRecovery {
messages: final_messages,
turn_interruption_state: deserialized.turn_interruption_state,
session_id: if session_id.is_empty() {
None
} else {
Some(session_id.to_string())
},
})
}
/// Save conversation state to disk.
/// Serializes messages to a JSON file for persistence.
pub fn save_conversation_state(messages: Vec<serde_json::Value>) -> Result<(), String> {
let path = get_conversation_state_path();
let json = serde_json::to_string_pretty(&messages)
.map_err(|e| format!("Failed to serialize conversation state: {}", e))?;
fs::write(&path, json).map_err(|e| format!("Failed to write conversation state: {}", e))?;
log::debug!("Saved conversation state to {}", path.display());
Ok(())
}
/// Load conversation state from disk.
/// Returns the most recently saved conversation state, or None if not found.
pub fn load_conversation_state() -> Option<Vec<serde_json::Value>> {
let path = get_conversation_state_path();
if !path.exists() {
return None;
}
let content = match fs::read_to_string(&path) {
Ok(c) => c,
Err(e) => {
log::error!("Failed to read conversation state: {}", e);
return None;
}
};
match serde_json::from_str(&content) {
Ok(messages) => Some(messages),
Err(e) => {
log::error!("Failed to parse conversation state: {}", e);
None
}
}
}
/// Get the path to the conversation state file.
fn get_conversation_state_path() -> PathBuf {
let mut path = dirs::config_dir().unwrap_or_else(|| PathBuf::from("."));
path.push("ai-agent");
path.push("conversation_state.json");
path
}
/// Process session start hooks for resume.
/// Returns messages to append to the conversation.
async fn process_session_start_hooks(event: &str, session_id: &str) -> Vec<serde_json::Value> {
// In the TS version, this calls processSessionStartHooks which runs registered hooks.
// This is a simplified placeholder that would run registered session start hooks.
log::debug!("Processing session start hooks: event={}, session={}", event, session_id);
// Hook messages would be added by registered hooks here.
vec![]
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_deserialize_empty_messages() {
let result = deserialize_messages_with_interrupt_detection(&[]);
assert!(result.messages.is_empty());
assert!(matches!(result.turn_interruption_state, TurnInterruptionState::None));
}
#[test]
fn test_deserialize_messages_with_assistant_last() {
let messages = vec![
serde_json::json!({
"type": "user",
"message": { "content": "Hello" }
}),
serde_json::json!({
"type": "assistant",
"message": { "content": [{ "type": "text", "text": "Hi there!" }] }
}),
];
let result = deserialize_messages_with_interrupt_detection(&messages);
// Last message is assistant, so no interruption detected
assert!(matches!(result.turn_interruption_state, TurnInterruptionState::None));
// Should have original 2 messages (no sentinel appended)
assert_eq!(result.messages.len(), 2);
}
#[test]
fn test_deserialize_messages_with_user_last() {
let messages = vec![serde_json::json!({
"type": "user",
"message": { "content": "Hello" }
})];
let result = deserialize_messages_with_interrupt_detection(&messages);
// Last message is user, so interruption detected
assert!(matches!(
result.turn_interruption_state,
TurnInterruptionState::InterruptedPrompt { .. }
));
// Should have user + continuation + sentinel messages
assert_eq!(result.messages.len(), 3);
}
#[test]
fn test_create_user_message() {
let msg = create_user_message("test content", false);
assert_eq!(msg.get("type").and_then(|v| v.as_str()), Some("user"));
}
#[test]
fn test_create_assistant_message() {
let msg = create_assistant_message("test response");
assert_eq!(msg.get("type").and_then(|v| v.as_str()), Some("assistant"));
}
#[test]
fn test_migrate_legacy_attachment_new_file() {
let msg = serde_json::json!({
"type": "attachment",
"attachment": {
"type": "new_file",
"filename": "/path/to/file.txt"
}
});
let migrated = migrate_legacy_attachment(&msg);
let att_type = migrated.get("attachment").and_then(|v| v.get("type")).and_then(|v| v.as_str());
assert_eq!(att_type, Some("file"));
}
#[test]
fn test_filter_unresolved_tool_uses() {
let messages = vec![
serde_json::json!({
"type": "assistant",
"message": { "content": [{ "type": "tool_use", "id": "tool-1", "name": "Read" }] }
}),
serde_json::json!({
"type": "assistant",
"message": { "content": [{ "type": "text", "text": "Hello" }] }
}),
];
let filtered = filter_unresolved_tool_uses(&messages);
// Assistant with unresolved tool_use should be filtered out
assert_eq!(filtered.len(), 1);
}
#[test]
fn test_is_tool_use_result_message() {
let msg = serde_json::json!({
"type": "user",
"message": { "content": [{ "type": "tool_result", "tool_use_id": "tool-1" }] }
});
assert!(is_tool_use_result_message(&msg));
let msg2 = serde_json::json!({
"type": "user",
"message": { "content": "Hello" }
});
assert!(!is_tool_use_result_message(&msg2));
}
}