Skip to content

Commit 467e251

Browse files
klopez4212Mongo
andcommitted
Revive Huddle preparing dots for a genuinely new agent turn
The avatar used a single audio-seen latch (responseHasStarted): audio set it true and any later working signal within the 1.2 s cooldown cancelled the reset, keeping preparing UI and live-region semantics suppressed. That conflated late same-turn typing (correctly suppressed) with a new turn after the previous working signal already cleared (wrongly suppressed), so fast consecutive agent responses lost both the waiting cue and its accessibility announcement. Track whether the working signal has completed a cycle since audio latched. A false->true working transition after a completed cycle now clears the latch so preparing shows again, while late typing that never cleared stays suppressed. Adds a causal regression: audio -> late same-turn typing suppressed -> working clears -> new working within cooldown => preparing indicator and live semantics return. Co-authored-by: Mongo <9cfd347903944d5b85aa6c93d2ab67381b978a92a31914bca69998968752a1d7@buzz.block.builderlab.xyz> Signed-off-by: kenny lopez <[email protected]>
1 parent c769694 commit 467e251

2 files changed

Lines changed: 134 additions & 0 deletions

File tree

‎mobile/lib/features/channels/channel_detail_page/huddle_call_avatar.dart‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,51 @@ class _HuddleCallAvatar extends HookConsumerWidget {
3030
final reducedMotion = MediaQuery.disableAnimationsOf(context);
3131
final responseHasStarted = useState(false);
3232
final responseResetTimer = useRef<Timer?>(null);
33+
// Tracks the previous working signal so we can detect its edges, and
34+
// whether the working signal has cleared since audio latched the response.
35+
// A completed working cycle distinguishes a genuinely new turn from late
36+
// typing that merely trails the turn already spoken.
37+
final wasPreparing = useRef(false);
38+
final workingCycleCompleted = useRef(false);
3339
useEffect(() {
40+
final preparingStarted = preparingResponse && !wasPreparing.value;
41+
final preparingCleared = !preparingResponse && wasPreparing.value;
42+
wasPreparing.value = preparingResponse;
3443
if (active) {
44+
// Audio for the current turn latches that a response has begun and
45+
// starts a fresh turn, so any prior working cycle no longer applies.
3546
responseResetTimer.value?.cancel();
3647
responseResetTimer.value = null;
3748
responseHasStarted.value = true;
49+
workingCycleCompleted.value = false;
50+
} else if (preparingStarted &&
51+
responseHasStarted.value &&
52+
workingCycleCompleted.value) {
53+
// A new working turn began after the previous turn's working signal
54+
// already cleared, so the "already spoke" suppression no longer
55+
// applies — allow the preparing indicator to show again.
56+
responseResetTimer.value?.cancel();
57+
responseResetTimer.value = null;
58+
responseHasStarted.value = false;
59+
workingCycleCompleted.value = false;
3860
} else if (preparingResponse) {
61+
// Working signal (including late typing for the turn just spoken) holds
62+
// the suppression alive; keep the reset timer cancelled.
3963
responseResetTimer.value?.cancel();
4064
responseResetTimer.value = null;
4165
} else if (responseHasStarted.value && responseResetTimer.value == null) {
4266
responseResetTimer.value = Timer(_huddleAgentResponseResetDelay, () {
4367
responseResetTimer.value = null;
4468
responseHasStarted.value = false;
69+
workingCycleCompleted.value = false;
4570
});
4671
}
72+
// Record that this turn's working signal has completed a cycle once it
73+
// clears after audio latched, so the next working turn is not mistaken
74+
// for trailing typing.
75+
if (preparingCleared && responseHasStarted.value) {
76+
workingCycleCompleted.value = true;
77+
}
4778
return null;
4879
}, [active, preparingResponse, responseHasStarted.value]);
4980
useEffect(

‎mobile/test/features/channels/channel_detail_page_test.dart‎

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5892,6 +5892,109 @@ void main() {
58925892
);
58935893
});
58945894

5895+
testWidgets('revives response dots for a new turn after audio completes', (
5896+
tester,
5897+
) async {
5898+
// Regression: a completed working cycle followed by a genuinely new one
5899+
// must show the preparing indicator again. A single audio-seen latch
5900+
// conflates late same-turn typing (suppress) with a fresh turn (show).
5901+
final now = DateTime.now().millisecondsSinceEpoch ~/ 1000;
5902+
final typing = _FakeTypingNotifier(const [], channelId: _huddleChannelId);
5903+
final transport = _HuddleTestTransport(
5904+
peers: const {
5905+
1: HuddlePeer(pubkey: 'self', peerIndex: 1, epoch: 0),
5906+
2: HuddlePeer(pubkey: 'agent', peerIndex: 2, epoch: 0),
5907+
},
5908+
);
5909+
5910+
await tester.pumpWidget(
5911+
_buildTestable(
5912+
messages: [
5913+
_huddleMsg(
5914+
id: 'new-turn-after-audio',
5915+
kind: EventKind.huddleStarted,
5916+
pubkey: 'self',
5917+
createdAt: now,
5918+
),
5919+
],
5920+
users: const {
5921+
'agent': UserProfile(pubkey: 'agent', displayName: 'Pollen'),
5922+
'self': UserProfile(pubkey: 'self', displayName: 'Self'),
5923+
},
5924+
huddleMembers: [
5925+
ChannelMember(
5926+
pubkey: 'agent',
5927+
role: 'bot',
5928+
joinedAt: DateTime(2025),
5929+
),
5930+
],
5931+
huddleTypingNotifier: typing,
5932+
relayConfigNotifier: _HuddleRelayConfigNotifier(),
5933+
huddleCurrentPubkey: 'self',
5934+
huddleMediaFactory: _HuddleTestMedia.new,
5935+
huddleTransportFactory: (_) => transport,
5936+
),
5937+
);
5938+
await tester.pumpAndSettle();
5939+
await tester.tap(find.widgetWithText(FilledButton, 'Join'));
5940+
await tester.pumpAndSettle();
5941+
5942+
// Turn 1: audio speaks, then late same-turn typing must stay suppressed.
5943+
transport.emitRemoteAudio(peerIndex: 2);
5944+
await tester.pump();
5945+
await tester.pump(const Duration(milliseconds: 650));
5946+
typing.setEntries([
5947+
TypingEntry(
5948+
pubkey: 'agent',
5949+
expiresAtMs: DateTime.now().millisecondsSinceEpoch + 8000,
5950+
),
5951+
]);
5952+
await tester.pump();
5953+
await tester.pump(const Duration(milliseconds: 200));
5954+
expect(
5955+
find.byKey(const ValueKey('huddle-agent-preparing-response-agent')),
5956+
findsNothing,
5957+
);
5958+
5959+
// Turn 1's working signal completes.
5960+
typing.setEntries(const []);
5961+
await tester.pump();
5962+
await tester.pump(const Duration(milliseconds: 200));
5963+
5964+
// Turn 2: a fresh working signal within the 1.2 s cooldown must show the
5965+
// preparing indicator and announce it live again.
5966+
typing.setEntries([
5967+
TypingEntry(
5968+
pubkey: 'agent',
5969+
expiresAtMs: DateTime.now().millisecondsSinceEpoch + 8000,
5970+
),
5971+
]);
5972+
await tester.pump();
5973+
await tester.pump(const Duration(milliseconds: 200));
5974+
5975+
expect(
5976+
find.byKey(const ValueKey('huddle-agent-preparing-response-agent')),
5977+
findsOneWidget,
5978+
);
5979+
expect(
5980+
find.byKey(const ValueKey('huddle-avatar-image-agent')),
5981+
findsNothing,
5982+
);
5983+
expect(
5984+
find.bySemanticsLabel('Pollen, preparing a response'),
5985+
findsOneWidget,
5986+
);
5987+
expect(
5988+
tester
5989+
.getSemantics(
5990+
find.byKey(const ValueKey('huddle-participant-avatar-agent')),
5991+
)
5992+
.flagsCollection
5993+
.isLiveRegion,
5994+
isTrue,
5995+
);
5996+
});
5997+
58955998
testWidgets(
58965999
'does not restart the profile subscription on speaker-level updates',
58976000
(tester) async {

0 commit comments

Comments
 (0)