feat(bot): persist user messages and refine session handling

Add logic to save user messages to session history for better traceability and context continuity. Simplify session creation error handling and remove redundant warning on closed response channel. Update README with guidance on maintaining production-ready source code.
This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2025-11-07 10:26:34 -03:00
parent ab7abacbe3
commit 856e2f0252
2 changed files with 9 additions and 6 deletions

View file

@ -16,3 +16,4 @@ When initial attempts fail, sequentially try these LLMs:
- If a big req. fail, specify a @code file that has similar pattern or sample from official docs.
- **Final validation**: Use prompt "cargo check" with gpt-oss-120b
- Be humble, one requirement, one commit. But sometimes, freedom of caos is welcome - when no deadlines are set.
- Keep in the source codebase only deployed and tested source, no lab source code in main project. At least, use optional features to introduce new behaviour gradually in PRODUCTION.

View file

@ -362,10 +362,13 @@ impl BotOrchestrator {
let mut sm = self.state.session_manager.lock().await;
sm.get_session_by_id(session_id)?
}
.ok_or_else(|| {
error!("Failed to create session for streaming");
"Failed to create session"
})?;
.ok_or_else(|| "Failed to create session")?;
// Save user message to history
{
let mut sm = self.state.session_manager.lock().await;
sm.save_message(session.id, user_id, 1, &message.content, 1)?;
}
if message.message_type == 4 {
if let Some(context_name) = &message.context_name {
@ -598,7 +601,6 @@ io::stdout().flush().unwrap();
};
if response_tx.send(partial).await.is_err() {
warn!("Response channel closed, stopping stream processing");
break;
}
}