Skip to content

feat(app): batch speaker labeling session with deferred summary reprocess - #21121

Merged
Git-on-my-level merged 4 commits into
mainfrom
lane/speaker-draft-labeling
Oct 10, 2026
Merged

Git-on-my-level merged 4 commits into
mainfrom
lane/speaker-draft-labeling

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

Problem

  1. Labeling speakers in a conversation's transcript regenerated the whole summary after almost every label. The 4 s quiet period fired whenever the reader paused to read, so "Reprocessing conversation…" and the "Labeled as X · Labeled 1 line · Voice not learned yet" card kept churning while they were relabeling many speakers.
  2. Some transcript lines rendered centered, for example short replies like "Maybe" or "No." inside a turn.
  3. Labeling was one line at a time: tapping a name labeled only that line unless the reader ticked "Also tag later speech".

Design

Labeling pass (draft session), in ConversationDetailProvider

  • Every label from the transcript tab, and the new Select entry, starts a pass on the open conversation (beginSpeakerLabelingSession). A bar above the transcript shows "Labeled N lines" with Undo, Select and Done.
  • During a pass, nothing regenerates. _scheduleAutomaticSpeakerSummaryRefresh returns early for the pass's conversation, so pauses between labels no longer trigger a reprocess. The "Update summary with new names" action is hidden while the pass is open, because Done does the same job.
  • The pass ends with at most one regeneration:
    • Done regenerates immediately. If a save is still in flight, it regenerates as soon as that save is acknowledged (_confirmedSpeakerLabelingSessionIds).
    • Leaving the page auto-confirms through the existing exit path (_finishSpeakerLabelingSession → _regenerateSpeakerSummaryAfterExit).
    • Backgrounding the app (AppLifecycleState.paused) is treated like Done, so the result lands on the page if the reader returns.
    • Switching conversations uses the existing flush.
    • Ending a pass that is already over is a no-op. A pass that changed nothing regenerates nothing. Labeling after Done starts a new pass. Any other regeneration also ends the pass.
    • Page-scoped end calls take the page's conversation id, so a detail page underneath another one cannot end the top page's pass.
  • Undo steps back through this pass's actions. It restores each line's previous label locally and saves it again, grouped per original label (lines from one action can carry different labels; "no label" is person_id: null). It runs on the same save queue and generation/rollback machinery. If the restore save fails, the lines roll forward to what the server still has.
  • The outcome card ("Labeled as X · voice learning") no longer appears after each label. It waits until Done and then shows the last person tagged.
  • The 4 s quiet-period path is still there for any assignment made without a pass. All existing quiet-period tests are unchanged.

Persistence is unchanged

Every label still saves immediately through assignBulkConversationTranscriptSegments, with the existing optimistic edit, save queue, generation checks and rollback. The pass only controls when the summary regenerates and how much feedback appears. No backend or API changes.

Centered-line fix (app/lib/widgets/transcript.dart)

  • Root cause (transcript.dart:876, default Column centering): ListView.builder wrapped every segment after the first in Column(mainAxisSize: min, children: [SizedBox(height: 4), child]). A Column centers its children by default and gives them loose width. A detail line that starts a turn contains the full-width name Row, so it filled the width and looked left-aligned. A line that does not start a turn (no name row) and is shorter than the viewport shrank to its text width and was centered.
  • That explains why the bug was intermittent and why it only hit short continuation lines. textAlign was already left; the problem was the wrapper's alignment, not the text's.
  • The wrapper has existed since 79441c4. It became visible when the detail view moved to un-bubbled _buildDetailLine lines; bubble lines are full-width Rows.
  • Fix: the separator is now Padding(top: 4). Every line gets the same tight width as line 0.

Easier labeling

  • Multi-select. A Select button sits next to the "Transcript · N speakers" heading, and there is also one in the pass bar. In selection mode every line shows a check circle, and tapping anywhere on a line toggles it. The bar reads "N selected" with Cancel and Name Speaker. One startSpeakerAssignment call labels all selected lines.
  • Quick picker (speaker_quick_picker.dart). Chips assign with one tap, with no Save step. Order: people already named in this conversation (most lines first), then most recently used (speakerLabelLastUsedMs), then alphabetical. "You" and "Add Person" (inline name field) are always there, plus search above 10 people.
  • Turn-level labeling (per voice). Tapping a speaker's name in the detail transcript now opens the sheet with "Also tag later speech" on (defaultApplyToSpeaker: true). One Save names every line of that voice, through the existing speakerId bulk path. The sheet lists those lines so the reader can uncheck any.

Deviations from the brief (and why)

  • Long-press does not enter selection mode. Long-press on transcript words already selects text for copying, and app/docs/ux-contract.md §4 says multi-select is a "Select" entry, not the long-press itself. Selection mode starts from Select instead.
  • The bar sits at the top, not the bottom. The bottom of the detail page already holds the pinned Ask Omi / playback bar.
  • No first-run tip yet, and no new l10n keys. The session that wrote this could not run scripts/l10n.py, flutter gen-l10n or any Flutter command, and generated l10n files must never be edited by hand. All UI strings therefore reuse existing keys: done, undo, cancel, selectOption, nameSpeakerTitle, selectedCount, speakerLabelLinesLabeled, addPerson, you, enterPersonsName, searchPeople, save.
    • Translations for a speakerLabelingSessionTip key ("Tip: label all speakers, then tap Done to update the summary once.") are ready in all 49 locales. Wiring it up is: one l10n.py add, a SharedPreferencesUtil().speakerLabelingTipShown check (getter/setter already added), and one Text in SpeakerLabelingSessionBar.
  • Backgrounding is treated as Done, not as a page exit. The page is still alive, so the regenerated summary should land on it rather than be discarded the way the exit path discards it. It is still one regeneration per pass.

Known limitations

  • The first-run tip is deferred. It needs a new l10n key; see above.
  • Long-press still selects text. It does not enter selection mode; Select does.

Tests

  • test/providers/speaker_summary_refresh_test.dart, new group "labeling pass" (10 tests):
    • pauses never regenerate, and Done regenerates once
    • Done, leave and dispose together still give a single regeneration
    • an empty pass regenerates nothing
    • Done while a save is in flight regenerates once, after it lands
    • leaving the page auto-confirms once, and only for its own conversation
    • a page underneath cannot end the top page's pass
    • labeling after Done starts a new pass with its own regeneration
    • switching conversations flushes the pass
    • Undo restores and re-saves mixed labels
    • a failed Undo rolls forward
    • a failed save leaves nothing to undo
  • test/widgets/speaker_labeling_session_test.dart:
    • alignment regression: short lines between long ones share the long line's left edge, and textAlign is left
    • Select → toggle 2 lines → quick picker → a single save of a,c → "Labeled 2 lines" → no regeneration during a 10 s pause → Done → exactly 1 regeneration, then the outcome card
    • selection mode toggles lines instead of opening the name sheet; Cancel works; Done after no changes regenerates nothing
    • Undo in the bar
    • quick-picker ordering
  • The visual audit speaker_labels.dart is updated: the checkbox is now on by default, and Done comes before the outcome card.
  • Widget-test fixture note: the "labeling pass" widget fixtures are built inside each test body, not in setUp. The provider's save queue starts from a completed Future.value(). If that future is created outside the testWidgets fake-async zone, awaiting it resumes on the real microtask queue. tester.pump never drains that queue, so the first save only ran after the test body had finished. This was a test-harness artifact, not a product bug: in the app, the provider and its futures share one zone.
  • Run locally: flutter test test/providers/speaker_summary_refresh_test.dart test/widgets/speaker_labeling_session_test.dart test/widgets/transcript_test.dart test/widgets/transcript_heading_test.dart test/widgets/name_speaker_sheet_test.dart passed, 94/94.
  • ⚠️ Not run locally: flutter analyze and make preflight were blocked by the session's permission mode. Watch the Dart analyze lane.

Review fixes

  1. A sync-bridge ID change no longer ends the open pass. Before, when a label save on a v5 sync-donor ID refreshed into the survivor, only the summary-refresh state moved to the survivor ID. The pass stayed on the donor ID, so the bar disappeared, Done, background and exit did nothing, and the summary never regenerated.
    • Both bridge paths (the post-save refresh and the rejection response) now go through one _adoptBridgedConversation. It moves everything to the survivor ID: _labelingSessionId, the confirmed and ended pass sets, _automaticSpeakerSummaryRefreshIds and _speakerSummaryConversationId. The undo stack is keyed by segment, so it carries over unchanged.
    • The page still holds the donor ID. Page-scoped confirmSpeakerLabelingSession and leaveSpeakerLabelingSession calls now resolve that ID through _bridgedConversationIds. The page's own Done, background and exit still end its pass, and a page underneath still can't. The aliases are cleared when the provider switches to another conversation.
    • The post-drain scheduling in _finishSpeakerSave also resolves through the bridge. A Done or exit pressed while the bridging save was still in flight now regenerates the survivor once.
  2. A partly failed multi-label Undo leaves local labels matching the server. Chosen option: paint local state to match the server rather than sending a compensating save. Groups that saved stay undone; only the lines whose group did not save roll forward to the labels the server still has. The failure is reported the same way as before (undoLastSpeakerLabel returns false).
    • Why: a compensating save can also fail, which brings back the same divergence. Painting what the server actually acknowledged keeps local equal to server in every end state, with no extra request.
  • New tests in speaker_summary_refresh_test.dart:
    • a partial Undo failure, asserting local labels equal a fake server's labels line by line
    • a bridge mid-pass keeps the pass active (bar, count, Undo), the donor-ID Done regenerates the survivor exactly once, and a page underneath can't end it
    • Done or leave while the bridging save is in flight regenerates the survivor once

🤖 Generated with Claude Code

Line-Count-Exception: app/lib/backend/preferences.dart | 1500 -> 1505 | adds the speakerLabelingTipShown preference flag alongside the existing preference accessors; splitting the file for 5 lines would fragment related storage accessors
Line-Count-Exception: app/lib/pages/conversation_detail/conversation_detail_provider.dart | 1293 -> 1514 | the labeling-pass session state machine (session lifecycle, bridge adoption, undo groups, deferred reprocess scheduling) is one cohesive provider concern; splitting it across files would scatter the generation/rollback invariants this PR is careful to keep together

UI-Evidence: none -- behavior-level changes (session bar, picker sheet, alignment) verified by widget tests comparing rendered line positions; no emulator capture available in this environment.

Failure-Class: none

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-10T08:29:12.676814Z 2dbc7d1 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Git-on-my-level Git-on-my-level added the ci:full Maintainer-granted: run full CI on this fork PR label Oct 10, 2026

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7d4da9750b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

segments: provider.conversation.transcriptSegments,
unresolvedSpeakers: provider.conversation.speakerResolution?.status == 'unavailable',
// The name heads a turn; naming it names that voice's lines, which the sheet lists to uncheck.
defaultApplyToSpeaker: true,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid grouping unresolved voices by raw speaker ID

When speakerResolution.status == 'unavailable', equal raw speaker IDs from different recordings are explicitly not comparable, but this default preselects every segment with the same ID and saves them through the bulk speakerId path unless the user manually unchecks them. Naming one turn can therefore relabel unrelated voices in a merged conversation; keep bulk-by-voice off for unresolved conversations.

AGENTS.md reference: app/AGENTS.md:L3-L4

Useful? React with 👍 / 👎.

Comment on lines +192 to +194
} else if (target.status == ConversationStatus.completed && target.structured.overview.trim().isNotEmpty) {
_automaticSpeakerSummaryRefreshIds.add(target.id);
if (!_isDisposed && identical(conversationOrNull, target)) _speakerSummaryConversationId = target.id;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Clear pending refresh when undo removes every edit

When the user labels a line and then undoes the only action, the undo stack and displayed count become empty, but the original assignment's _automaticSpeakerSummaryRefreshIds entry remains and this successful restore adds/retains it. Pressing Done consequently reprocesses the conversation even though the transcript is back to its original state, recreating the unnecessary summary churn this session is intended to avoid.

Useful? React with 👍 / 👎.

Comment on lines +137 to +140
Future<void> _undoLabel(ConversationDetailProvider provider) async {
OmiHaptics.light();
final undone = await provider.undoLastSpeakerLabel();
if (!undone && mounted) OmiFeedback.error(context, context.l10n.failedToSaveCheckConnection);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Rewind deferred outcome when undo succeeds

After a person assignment saves, _deferredOutcome records that assignment, but a successful Undo only restores the provider state and leaves this value unchanged. Pressing Done after undoing the last assignment—or undoing Jordan after an earlier Maya assignment—therefore shows an outcome card for a label that no longer exists; update or clear the deferred outcome along with the undo.

Useful? React with 👍 / 👎.

Comment on lines +145 to +148
TextField(
controller: _search,
onChanged: (_) => setState(() {}),
decoration: InputDecoration(hintText: l10n.searchPeople, prefixIcon: const Icon(Icons.search, size: 18)),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Replace the picker search with OmiSearchField

The app UI contract requires searches to use OmiSearchField, but the new people search introduces a locally configured TextField. This bypasses the repository's shared search behavior and styling, including the standard clear affordance; use the shared primitive as other people/contact pickers do.

AGENTS.md reference: app/AGENTS.md:L3-L4

Useful? React with 👍 / 👎.

Comment on lines +95 to +101
void beginSpeakerLabelingSession() {
final target = conversationOrNull;
if (target == null || _labelingSessionId == target.id) return;
_labelingSessionId = target.id;
_labelingUndo.clear();
_endedSpeakerLabelingSessionIds.remove(target.id);
_confirmedSpeakerLabelingSessionIds.remove(target.id);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Carry labeling state across sync bridge redirects

For a sync-donor conversation, a successful speaker save calls refreshConversation(), which can replace the donor ID with its bridged survivor and migrates the existing summary-refresh IDs, but not the new _labelingSessionId or confirmed-session state. Once the cached conversation has the survivor ID, speakerLabelingSessionActive becomes false, the bar disappears, and neither Done nor page exit regenerates the summary for the saved labels; migrate the labeling session and its undo/confirmation state when adopting the survivor.

Useful? React with 👍 / 👎.

Comment on lines +183 to +187
for (final MapEntry(key: (isUser, personId), value: ids) in groups.entries) {
final saved = await _assignSpeaker(target.id, ids, isUser: isUser, personId: personId);
if (!saved) {
_rollbackSpeakerAssignment(target, restore.keys.toList(), current, generation, null);
return false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Handle partial failures while restoring mixed labels

An undo covering lines with different previous labels sends one restore request per group. If an earlier group succeeds and a later group returns false or throws, this path rolls every local line forward to current, even though the server has already restored the successful group, leaving the UI inconsistent with persisted data and discarding the undo entry; either compensate the completed groups or preserve the per-group server result and retry state.

Useful? React with 👍 / 👎.

Comment on lines +1318 to +1329
if (selected != null && toggle != null) {
final isSelected = selected.contains(data.id);
// The line's own targets (the name, the words) stand down: a tap anywhere toggles the check.
line = Semantics(
button: true,
selected: isSelected,
child: GestureDetector(
key: ValueKey('transcript_select_${data.id}'),
behavior: HitTestBehavior.opaque,
onTap: () {
OmiHaptics.selection();
toggle(data);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Exclude Omi speech from line-selection labeling

Selection mode adds a labeling toggle to every detail line, including segments whose speakerId is omiSpeakerId; the normal speaker target deliberately disables naming those segments. A user can now select Omi speech and choose “You,” which sets isUser and persists the assistant's words as the owner's speech, violating the transcript's fixed Omi attribution; omit these segments from selection or disable their toggles.

AGENTS.md reference: app/AGENTS.md:L3-L4

Useful? React with 👍 / 👎.

Comment on lines +175 to +177
try {
await previousSave;
if (_speakerEditGenerationByConversation[target.id] != generation) return false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Roll back an undo superseded by a newer label

Undo applies the restored values optimistically before awaiting the save queue. If another label is started while that queue is still blocked, it advances the conversation generation, causing this early return; any restored lines not touched by the newer label remain reverted locally even though no restore request reached the server, and the popped undo entry is no longer retryable. Serialize edits during undo or roll those optimistic values forward before returning false.

Useful? React with 👍 / 👎.

Comment on lines +169 to +175
for (final person in visible)
OmiFilterChip(
key: Key('speaker_quick_picker_person_${person.id}'),
label: person.name,
selected: false,
onSelected: () => _pick(person.id, person.name),
),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Bound the people rendered by the quick picker

When the account has many saved people, the initial empty-query state puts every person into a Wrap inside a SingleChildScrollView, so opening the picker eagerly builds and lays out the entire collection even though a search field is available. Unlike the existing name-speaker picker, which caps its initial grid, this can make the sheet noticeably slow or unusable for large people lists; cap the unfiltered chips or use a lazy list.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2dbc7d1db7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +50 to +52
child: Row(
children: [
Expanded(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Make the labeling bar responsive to text scaling

At 200% text scale or on narrow devices with longer localized labels, this single Row cannot fit its fixed-size Undo/Select/Done controls—or Cancel/Name Speaker controls—even after the title collapses, producing a RenderFlex overflow and clipped actions. The app UI contract explicitly requires text containers to support 200% scaling, so let the actions wrap or switch to an adaptive multi-row layout.

AGENTS.md reference: app/AGENTS.md:L3-L4

Useful? React with 👍 / 👎.

Comment on lines +20 to +23
return showOmiSheet<void>(
context: context,
title: context.l10n.nameSpeakerTitle,
builder: (_) => SpeakerQuickPicker(segments: segments, onPicked: onPicked),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Guard dismissal after entering a new person name

When the user taps Add Person and types a name, this remains a freely dismissible showOmiSheet, so a swipe-down, system back, or scrim tap silently discards the dirty input. The app UI contract requires sheets that edit something to use showOmiEditSheet/OmiEditSheet and confirm before dismissing dirty state; route the add-person form through that guarded behavior.

AGENTS.md reference: app/AGENTS.md:L3-L4

Useful? React with 👍 / 👎.

Comment on lines +416 to +420
if (provider.speakerLabelingSessionActive || selection != null)
SpeakerLabelingSessionBar(
linesRelabeled: provider.speakerLabelingSessionLineCount,
selectedCount: selection?.length,
onDone: () => _finishLabeling(provider),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep the pending labeling action visible on Summary

After a label is saved, switching from Transcript to Summary leaves the labeling session active but moves this bar—and its only Done action—off-screen inside the inactive transcript tab. Automatic regeneration remains suppressed for the active session, so the Summary tab can display stale speaker names indefinitely with no visible indication or way to apply the pending update unless the user knows to return to Transcript; either finish the pass on tab change or surface its pending action outside the transcript-only subtree.

Useful? React with 👍 / 👎.

@Git-on-my-level
Git-on-my-level merged commit 49c522a into main Oct 10, 2026
44 checks passed
@Git-on-my-level
Git-on-my-level deleted the lane/speaker-draft-labeling branch October 10, 2026 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:full Maintainer-granted: run full CI on this fork PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant