omi icon indicating copy to clipboard operation
omi copied to clipboard

[Bounty proposal] fix(cli): harden conversations_to_tsv against speaker 0 drops, lone surrogates, and non-atomic writes ( proposed)

Open pranav440 opened this issue 1 month ago • 3 comments

Summary

In sdks/python-cli/examples/conversations_to_tsv.py, exports from omi --json conversation list can contain edge-case transcript payload structures, numeric speaker identifiers, lone UTF-16 surrogates, or UTF-8 byte order marks (BOM). This PR hardens the TSV export pipeline against several failure modes:

  1. Speaker 0 Attribution Dropped:

    • In extract_transcript(item):
      speaker = seg.get("speaker") or seg.get("speaker_label")
      if text:
          if speaker:
              parts.append(f"{speaker}: {text}")
      
    • In Python, 0 evaluates to False. When segment transcripts assign speaker = 0 (or speaker = "0"), if speaker: evaluated to False, dropping the speaker label prefix while speaker 1, 2, etc. retained it.
    • Fix: Safely probe speaker_name, speaker, speaker_label, and speaker_id, explicitly checking val is not None and not isinstance(val, bool) and stripping whitespace so speaker 0 is consistently formatted as "0: <text>", while speaker: False is properly ignored.
  2. Lone Surrogates Crash (UnicodeEncodeError):

    • When conversations contain unpaired UTF-16 surrogates (e.g. \ud800), dest_path.write_text(..., encoding="utf-8") or stdout output raised unhandled UnicodeEncodeError.
    • Fix: Added strip_surrogates(value: str) -> str to drop unpaired surrogates while preserving valid text across all fields and transcripts.
  3. Non-Atomic File Output:

    • Writing directly with dest_path.write_text left partial, corrupted .tsv files if disk was full or the process was interrupted.
    • Fix: Implemented atomic writes via a sibling temporary file (.{name}.tmp.{pid}) and os.replace, with automatic cleanup on failure.
  4. UTF-8 BOM Support on Stdin:

    • Added .lstrip("\ufeff") to stdin streaming input, mirroring file reads to support UTF-8 BOM payloads from Windows shells and editors.

Verification & Unit Tests

Added 4 targeted test cases in sdks/python-cli/tests/test_conversations_to_tsv.py:

  • test_speaker_zero_and_alternate_speaker_keys_preserved: verifies speaker 0 and "0" are formatted correctly and speaker: False is excluded.
  • test_lone_surrogates_stripped_without_encode_error: verifies lone surrogates are stripped and byte encoding succeeds without UnicodeEncodeError.
  • test_cli_stdin_with_utf8_bom: verifies BOM-prefixed JSON on stdin parses cleanly.
  • test_atomic_write_creates_valid_file: verifies atomic replacement leaves no leftover temp files.

Test Run:

sdks/python-cli/tests/test_conversations_to_tsv.py: 16 passed in 0.25s
sdks/python-cli/tests/test_conversations_to_markdown.py: 20 passed
sdks/python-cli/tests/test_conversations_to_sqlite.py: 12 passed
Total: 48/48 passed

Bounty & Maintainer Notice

  • Proposed Bounty: $50 USD
  • Target Maintainers: @Git-on-my-level @kodjima33
  • Settlement:
    • PayPal: [email protected]
    • EVM / USDC Wallet: 0x8dDaD7F7D9C173c427488AEC48346dA305cb03fF

pranav440 avatar Oct 26 '26 11:10 pranav440

I would like to work on this. I will open a pull request that addresses the acceptance criteria.

airdropia avatar Oct 26 '26 14:10 airdropia

@kodjima33 I submitted #23751 for this issue, including the API transcript_segments shape, speaker zero, UTF-8/BOM handling and atomic output with concurrent-create, permission and symlink protection. Validation: 8 added regressions; 1005 CLI tests passed and 1 Windows-only skip; repository preflight and pre-push checks passed. The PR discloses Codex assistance and existing unrelated lint/type limitations.

Following the contribution guide's bounty-suggestion process, would you consider the reporter's proposed $50 USD for an accepted fix? Please confirm whether an amount is funded and whether this external contribution is eligible. I have not treated the proposal as an awarded or paid bounty.

ZhaZhaBei avatar Oct 26 '26 19:10 ZhaZhaBei

Thanks for putting this together. We aren't doing bounties at the moment, so we're closing the bounty proposal issues for now — thanks for the fix! 🙏

aryanorastar avatar Oct 31 '26 06:10 aryanorastar