huskies: merge 736_story_drain_and_prepend_buffered_status_events_on_the_user_s_next_agent_message

This commit is contained in:
dave
2026-04-27 19:31:34 +00:00
parent aa7b26a24a
commit 63a30a9319
4 changed files with 182 additions and 2 deletions
+17
View File
@@ -100,6 +100,11 @@ impl AgentPool {
// (bug 118).
let resolved_name: String;
let key: String;
// Buffered status events accumulated while the agent was idle. Drained
// inside the lock (before the new entry replaces the old one) and
// formatted as a `<recent-events>` block for prepending to the first
// agent turn (story 736).
let prior_events: Option<String>;
{
let mut agents = self.agents.lock().map_err(|e| e.to_string())?;
@@ -249,6 +254,17 @@ impl AgentPool {
story '{story_id}' will be picked up when the agent becomes available"
));
}
// Drain accumulated status events from the previous session before
// replacing the entry with the new one. The drained items are
// formatted and prepended to the first agent turn (story 736).
prior_events = {
let items = agents
.get(&key)
.and_then(|a| a.status_buffer.as_ref().map(|b| b.drain()))
.unwrap_or_default();
crate::service::status::buffer::format_buffered_items(&items)
};
agents.insert(
key.clone(),
StoryAgent {
@@ -336,6 +352,7 @@ impl AgentPool {
self.watcher_tx.clone(),
Arc::clone(&self.merge_jobs),
inactivity_timeout_secs,
prior_events,
));
// Store the task handle while the agent is still Pending.