Skip to content

fix some stability problems and rework terminal UI chips#28

Merged
monatis merged 4 commits intomainfrom
stability
May 6, 2026
Merged

fix some stability problems and rework terminal UI chips#28
monatis merged 4 commits intomainfrom
stability

Conversation

@monatis
Copy link
Copy Markdown
Contributor

@monatis monatis commented May 6, 2026

No description provided.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances the robustness of the agent's reasoning loop by ensuring terminal assistant messages are persisted during cancellations, LLM failures, and when reaching maximum iterations. It introduces a helper function for message persistence, improves error handling for subagents, and updates the terminal UI to display character counts for tool results. Additionally, the memory module's message retrieval order was corrected to follow insertion order, and several mutex poisoning handling improvements were implemented across the codebase. The review comment correctly identifies a significant opportunity to reduce code duplication in the cancellation handling logic using a macro.

Comment thread src/agent/mod.rs
Comment on lines 1735 to +1758
if cancel_token.is_cancelled() {
persist_terminal_assistant_message(
&mut mem,
&logger_tx,
&name,
&inbound.chat_id,
cancel_notice,
)
.await;
return Ok(String::new());
}
let tool_result = match fin {
ToolExecutionFinished::Completed(res) => res,
ToolExecutionFinished::Cancelled => return Ok(String::new()),
ToolExecutionFinished::Cancelled => {
persist_terminal_assistant_message(
&mut mem,
&logger_tx,
&name,
&inbound.chat_id,
cancel_notice,
)
.await;
return Ok(String::new());
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There's a lot of repetition in the cancellation handling logic. The block for persist_terminal_assistant_message followed by return Ok(String::new()) is duplicated in many places within this function (e.g., lines 1412-1419, 1549-1557, 1653-1661, 1736-1743, 1749-1757, 1785-1793, 1851-1860, 1990-1998).

To improve maintainability and reduce code duplication, you could define a local macro to encapsulate this logic. This would make the code cleaner and less error-prone if this logic needs to be changed in the future.

Example of a macro:

macro_rules! persist_and_cancel {
    () => {{
        persist_terminal_assistant_message(
            &mut mem,
            &logger_tx,
            &name,
            &inbound.chat_id,
            cancel_notice,
        )
        .await;
        return Ok(String::new());
    }};
}

Then you could use it like persist_and_cancel!() in all the cancellation handling branches.

@monatis monatis merged commit e67cfd6 into main May 6, 2026
@monatis monatis deleted the stability branch May 6, 2026 23:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant