Skip to content

fix(threads): stop persisting legacy fallback threads when AI failed#51

Merged
m-szymanska merged 1 commit into
developfrom
fix/no-persist-failed-fallback
Jul 6, 2026
Merged

fix(threads): stop persisting legacy fallback threads when AI failed#51
m-szymanska merged 1 commit into
developfrom
fix/no-persist-failed-fallback

Conversation

@m-szymanska

Copy link
Copy Markdown
Contributor

Problem

When the AI runtime is unavailable (dead/missing API key), the legacy assistive fallback persisted every failed attempt as a conversation thread with an "AI Failed" assistant message. After the thread-heal fix (#49) these junk threads became visible, cluttering the history rail — including repeated recordings of the same utterance producing 3-4 identical junk threads.

Fix

  • Extracted legacy_fallback_assistant_text(status, text) -> Option<String>: Failed/SkippedNone (no thread persisted, warn! logged), Applied/AiNoopSome(text) (persisted as before — partial success unaffected).
  • No retry-loop dedup needed: verified there is no per-attempt retry in code; the observed duplicates were separate recordings on a dead key, all extinguished at the source by this change.

Tests

  • New unit test legacy_fallback_skips_persist_on_failed_status covering all four status arms.
  • Gates: cargo fmt --check, cargo clippy --all-targets -- -D warnings, cargo test -p codescribe (239 passed), cargo test -p codescribe-core (645 passed) — all green.

🤖 Generated with Claude Code

…iled

A dead API key drove every assistive send through the legacy formatter
fallback, and each attempt persisted an "AI Failed" thread — the operator
saw ~12 junk conversations (with 3-4 duplicates per utterance) after a
key outage. A failed formatting attempt is not a conversation, so it must
not land on disk.

Extract the status->assistant-text mapping into a pure
`legacy_fallback_assistant_text` helper: Failed and Skipped now yield None
(no persist), while Applied and AiNoop still return the text and persist
as before. run_legacy_send_path warns on Failed so the skipped attempt is
still visible in logs.

Since the wild duplicates were all failed attempts (both send callsites
invoke the runtime exactly once per stop/hold — there is no per-attempt
retry loop in code), suppressing Failed persistence removes the duplicate
garbage at the source; no dedup loop change is needed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

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

Copy link
Copy Markdown

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 introduces a helper function legacy_fallback_assistant_text to prevent persisting failed or skipped legacy formatter attempts as threads, addressing an issue where failed attempts resulted in duplicate garbage threads. It also adds corresponding unit tests. The review feedback suggests simplifying a redundant condition in run_legacy_send_path where assistant_text.is_none() is checked alongside the Failed status.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread app/controller/helpers.rs
Comment on lines +872 to 876
if assistant_text.is_none() && status == crate::ai_formatting::AiFormatStatus::Failed {
warn!(
"Legacy formatter failed; skipping thread persist for this attempt (a failed attempt is not a conversation)"
);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The check assistant_text.is_none() is redundant. Since legacy_fallback_assistant_text is guaranteed to return None when the status is AiFormatStatus::Failed, checking status == crate::ai_formatting::AiFormatStatus::Failed is sufficient. Simplifying this condition improves code readability.

Suggested change
if assistant_text.is_none() && status == crate::ai_formatting::AiFormatStatus::Failed {
warn!(
"Legacy formatter failed; skipping thread persist for this attempt (a failed attempt is not a conversation)"
);
}
if status == crate::ai_formatting::AiFormatStatus::Failed {
warn!(
"Legacy formatter failed; skipping thread persist for this attempt (a failed attempt is not a conversation)"
);
}

@m-szymanska m-szymanska merged commit 241bcfc into develop Jul 6, 2026
2 checks passed
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