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.
Problem
The guard-then-copy state-update pattern
is copy-pasted 5 times across
_runAgentTurn/send()inlib/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...developdiff.Fix direction
Factor the pattern into a small
_updateState(ChatState Function(ChatState) update)helper used at all 5 call sites.