Skip to content

fix(app): keep a failed chat reply and its Try Again while chat is paused - #22894

Merged
kodjima33 merged 1 commit into
BasedHardware:mainfrom
sauranshbhardwaj:fix/chat-retry-keeps-reply-while-paused
Oct 21, 2026
Merged

kodjima33 merged 1 commit into
BasedHardware:mainfrom
sauranshbhardwaj:fix/chat-retry-keeps-reply-while-paused

Conversation

@sauranshbhardwaj

@sauranshbhardwaj sauranshbhardwaj commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

What's wrong

When a reply fails, chat shows an error with Try Again. If the usage-budget pause turns on while that error is on screen (ChatBudgetPause polls every 30 s and on resume), the composer is hidden but the failed reply and its Try Again stay. Tapping Try Again then:

// app/lib/providers/message_provider.dart
Future<void> retryFailedReply(ServerMessage message) async {
  final failed = _failedReplies.remove(message);
  ...
  messages.removeWhere((m) => identical(m, message));
  notifyListeners();
  await _streamReply(failed.text!, ...);
}

Future<void> _streamReply(...) async {
  if (chatAtCap != null) return;   // before the try/finally that calls setSendingMessage(false)
  1. The failed reply is removed, so the question is left with no answer and no way to retry it.
  2. Nothing is sent, and sendingMessage stays true, because the chat page's _retryReply sets it before calling retry and only _streamReply's finally clears it.
  3. When the pause ends (reset time, or Upgrade → _load()), the composer comes back, but chatMutationInProgress is still true, so every send is ignored without any message.
Try Again tapped while chat is paused before after
failed reply removed kept, Try Again still offered
composer after the pause ends sends ignored (sendingMessage stuck) works
request sent none none

Change

retryFailedReply returns early while chat is paused. It keeps the failed reply and its retry, and releases the composer the caller locked. Retry after the pause ends works as before. This is a 6-line guard and no other paths change.

Tests

test/providers/message_provider_failed_reply_test.dart: "Try Again while chat is paused keeps the failed reply and releases the composer". It fails a reply, applies an active ChatAtCap, and taps retry. The test expects nothing sent, the failed reply still last and retryable, and sendingMessage false. It then clears the pause and retries, which sends once and shows the reply. It fails on main because the failed reply vanishes.

  • flutter test test/providers/message_provider_failed_reply_test.dart test/providers/message_provider_chat_reliability_test.dart test/providers/chat_history_state_test.dart: 49 passed
  • bash test.sh: 6,743 passed, 23 skipped, exit 0

UI-Evidence: none -- the visible change is that a failed reply is not removed on a tap that sends nothing; the provider test pins the reply, its retry and the composer lock.

Failure-Class: none

View guided diff

@Git-on-my-level Git-on-my-level added positive-signal Automation verified a genuine fix/quality contribution flutter flutter work labels Oct 20, 2026
@Git-on-my-level

Copy link
Copy Markdown
Member

The fix is correct and nicely scoped — I verified the failure mode and the guard against both call paths; nothing blocking from me.

  • app/lib/providers/message_provider.dart:1035-1041 — the early return fires only while the pause is genuinely active (the chatAtCap getter at line 144 filters on ChatAtCap.active, so an expired cap doesn't block retry), and it releases the composer lock exactly like the pre-existing failed == null no-op branch below it. That lock matters: the chat page's _retryReply (app/lib/pages/chat/page.dart:736-742) sets sendingMessage before calling in, and previously nothing cleared it because _streamReply returns early on cap (line 844) before the try/finally that resets it (lines 992-998) — the stuck-composer bug you describe is real.
  • Keeping the _failedReplies entry intact (instead of the old _failedReplies.remove + messages.removeWhere at lines 1042-1049) means the question keeps its Try Again through the pause and retries cleanly afterward. I confirmed page.dart is the only production caller, so no other retry path changes behavior.
  • app/test/providers/message_provider_failed_reply_test.dart:66-101 — good coverage: nothing sent while paused, failed reply stays last/retryable, composer released, then full recovery after applyChatAtCap(null) with a successful resend. Follows the sibling test's replyStreamOverride pattern.
  • app/changelog/unreleased/20261020-chat-retry-while-paused.json — matches the existing one-line fragment convention.

USER IMPACT: Users who hit their chat usage cap no longer permanently lose a failed reply and its Try Again button by tapping retry while chat is paused — the retry just waits until the pause ends, and the composer keeps working.

Nothing material left for me; optional nit if you touch this again: a test where _chatAtCap is set but inactive (reset time passed) would pin the .active filtering in the getter.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Scoped bug fix: retryFailedReply dropped the failed reply and left sendingMessage stuck when chat was paused by the usage-budget gate. 6-line guard, test reproduces the stuck state on main, CI green.

@kodjima33
kodjima33 merged commit f50a28e into BasedHardware:main Oct 21, 2026
47 of 48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flutter flutter work positive-signal Automation verified a genuine fix/quality contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants