Skip to content

fix: preserve checkpoints after failed LLM requests#9359

Open
wcqqq1214 wants to merge 1 commit into
AstrBotDevs:masterfrom
wcqqq1214:fix/9358-checkpoint-retry
Open

fix: preserve checkpoints after failed LLM requests#9359
wcqqq1214 wants to merge 1 commit into
AstrBotDevs:masterfrom
wcqqq1214:fix/9358-checkpoint-retry

Conversation

@wcqqq1214

@wcqqq1214 wcqqq1214 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #9358.

Modifications

  • Persist the current conversation history and checkpoint when an LLM request ends with a failed or non-assistant response.
  • Keep the failed response text out of the persisted assistant history.
  • Add a regression test covering retry checkpoint persistence.
  • This is not a breaking change.

Test Results

  • uv run pytest tests/test_conversation_checkpoint.py -q — 12 passed.
  • Related agent and checkpoint tests — 52 passed.
  • uv run pytest -q — 1855 passed, 6 warnings.
  • uv run ruff format . — passed.
  • uv run ruff check . — passed.
  • Real local SQLite persistence and checkpoint lookup test — passed.
  • scripts/pr_test_env.sh --profile neo --skip-sync --skip-lint — 12 passed and startup smoke test passed.

The full fast profile also exposed two unrelated pip_installer test failures caused by its log_cli=true output-capture combination; those tests pass when run independently.

Checklist

  • No new feature was added, so no prior feature discussion was required.
  • The changes are tested and verification results are included above.
  • No new dependencies were introduced.
  • The changes do not introduce malicious code.

Summary by Sourcery

Ensure conversation checkpoints and history are persisted when LLM requests fail or return non-assistant responses, without saving failed response content to assistant history.

Bug Fixes:

  • Persist conversation history and checkpoint metadata after failed or non-assistant LLM responses to support reliable retries.

Enhancements:

  • Refine history-saving logic to consistently apply checkpoint segments while skipping unsaved system/user/assistant messages as intended.

Tests:

  • Add an async regression test verifying checkpoint persistence and history contents when an LLM response indicates an upstream failure.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@wcqqq1214
wcqqq1214 marked this pull request as ready for review July 23, 2026 07:43
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. area:core The bug / feature is about astrbot's core, backend area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. labels Jul 23, 2026

@sourcery-ai sourcery-ai Bot left a comment

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.

Hey - I've left some high level feedback:

  • The new _save_to_history branch for failed/non-assistant responses duplicates the message filtering and checkpoint-handling logic that the assistant-success path uses; consider extracting this into a shared helper to keep the behavior consistent and reduce maintenance overhead.
  • The conditionals guarding the different save/return paths in _save_to_history (not user_aborted, llm_response is None, llm_response.role != "assistant", etc.) are now fairly intricate; adding a brief inline comment or restructuring to make the intent of each branch (success vs failure vs abort) clearer would help future readers avoid misinterpreting the flow.
  • In test_failed_llm_response_persists_checkpoint_for_retry, consider also asserting that no assistant message containing the failed completion_text is stored in the conversation history to more directly lock in the requirement that upstream error text is excluded.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `_save_to_history` branch for failed/non-assistant responses duplicates the message filtering and checkpoint-handling logic that the assistant-success path uses; consider extracting this into a shared helper to keep the behavior consistent and reduce maintenance overhead.
- The conditionals guarding the different save/return paths in `_save_to_history` (`not user_aborted`, `llm_response is None`, `llm_response.role != "assistant"`, etc.) are now fairly intricate; adding a brief inline comment or restructuring to make the intent of each branch (success vs failure vs abort) clearer would help future readers avoid misinterpreting the flow.
- In `test_failed_llm_response_persists_checkpoint_for_retry`, consider also asserting that no assistant message containing the failed `completion_text` is stored in the conversation history to more directly lock in the requirement that upstream error text is excluded.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core The bug / feature is about astrbot's core, backend area:provider The bug / feature is about AI Provider, Models, LLM Agent, LLM Agent Runner. size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]上游模型返回异常后,点击重试会提示Linked checkpoint not found

1 participant