refactor: enhance retry mechanism with flexible context management#8284
refactor: enhance retry mechanism with flexible context management#8284xtco3o wants to merge 1 commit intoblock:mainfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 961b9855cc
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
961b985 to
a97cba8
Compare
|
All requested refactors have been completed:
|
a97cba8 to
e579037
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e579037a3d
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
53da0c8 to
2bf500b
Compare
|
Resolved Codex Review:
|
2bf500b to
091b5e5
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 091b5e5bc8
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
183b468 to
5a0749e
Compare
DOsinga
left a comment
There was a problem hiding this comment.
Review
Thanks for the contribution — the reset_context feature is a useful idea. A few things need addressing before this can move forward:
Needs an issue first
This adds a new feature (the reset_context field and the feedback-loop retry path) without a prior issue or discussion. Per our contributing guidelines, please open an issue describing the use case and proposed design so we can discuss it before the code: https://github.com/block/goose/blob/main/CONTRIBUTING.md#discussions-issues-and-prs
on_failure error handling is broken in the non-reset path
Codex flagged this correctly. execute_on_failure_command returns Err on non-zero exit, and handle_retry_logic propagates it with ?:
let on_failure_details = if let Some(on_failure_cmd) = &retry_config.on_failure {
Some(execute_on_failure_command(on_failure_cmd, retry_config).await?)
} else {
None
};This means when reset_context: false and the on_failure command fails, the retry aborts entirely. The code below that builds a message with "with failure" status is dead — it can never be reached. You need to decide: should a failing on_failure command abort the retry, or should its output be fed back to the agent? The current code tries to do both and achieves neither.
Remove test_retry_result_enum
This test just asserts that enum variants are not equal to each other and that Clone/Debug work. It can never catch a real bug — please remove it.
Integration tests needed
The new reset_context: false path has no integration test that exercises handle_retry_logic end-to-end. crates/goose/tests/agent.rs already has a retry_tests module — please add tests there (following the mock-provider pattern from max_turns_tests) that cover:
reset_context: trueresets conversation history (existing behavior, but worth pinning)reset_context: falseappends failure feedback as an agent-only user message with stdout/stderrreset_context: falsewith a failing on_failure command (once you fix the error handling)- truncation actually kicks in when output exceeds the limits
Minor
- Comments like
// Execute on_failure if configuredand// Add Success Check failure infojust restate what the next line does — remove them. truncate_outputmixeslen()(bytes) with the "chars" label in the truncation message — pick one unit and be consistent.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e809fe9239
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
goose/crates/goose/src/agents/agent.rs
Line 1734 in b71ec20
In the retry path, handle_retry_logic runs before messages_to_add is merged into conversation, and when a retry is requested this branch unconditionally clears messages_to_add. With reset_context: false, that drops the just-produced assistant response from persisted history, so the next attempt only sees synthetic failure feedback and loses the model’s immediate prior turn, which defeats the intended context-preserving behavior.
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
d3d2577 to
5556cc6
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5556cc6fab
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f67e6e97bd
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0e26f05bbc
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…edback Signed-off-by: ai <myaier@googlegroups.com>
f260f57 to
577d4a6
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 577d4a652b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // above (std::mem::take), so we must save even when retry added | ||
| // nothing — otherwise the assistant reply is lost from session. | ||
| session_manager.replace_conversation(&session_config.id, &conversation).await?; |
There was a problem hiding this comment.
Keep append-only persistence on non-retry turns
This branch now persists with replace_conversation even when retry logic returns false because it was skipped or all checks passed, so ordinary no-tool turns rewrite the entire transcript. Since replace_conversation deletes and reinserts all session messages, long chats now pay O(n) database writes per turn (O(n²) across a session), which can materially slow interactions and increase lock contention compared with the previous append-only add_message path.
Useful? React with 👍 / 👎.
Refactors the retry mechanism with flexible context management and enhanced safety.
Key Changes:
reset_contextsupport.stdout,stderr, andexit_status.agent_only()to keep UI clean.SuccessCheckResultandExecutionDetails.