Skip to content

[Chore] Streaming state guard-then-copy pattern duplicated 5x in chat_notifier.dart #74

Description

@ASahu16

Problem

The guard-then-copy state-update pattern

if (state.valueOrNull != null) {
  state = AsyncData(state.requireValue.copyWith(...));
}

is copy-pasted 5 times across _runAgentTurn/send() in lib/features/chat/presentation/chat_notifier.dart (around line 566) instead of factored into one helper.

Why this matters

A future change to how streaming state is updated (e.g. handling a race where state briefly errors, or adding a new field) requires editing 5 call sites by hand; missing one produces an inconsistent state update on just that code path with no compiler error to catch it.

Found during v1.2.0 release-readiness code review of the main...develop diff.

Fix direction

Factor the pattern into a small _updateState(ChatState Function(ChatState) update) helper used at all 5 call sites.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    chatChat feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions