[Bounty proposal] fix(cli): harden conversations_to_tsv against speaker 0 drops, lone surrogates, and non-atomic writes ( proposed)
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:
-
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,
0evaluates toFalse. When segment transcripts assignspeaker = 0(orspeaker = "0"),if speaker:evaluated toFalse, dropping the speaker label prefix while speaker 1, 2, etc. retained it. - Fix: Safely probe
speaker_name,speaker,speaker_label, andspeaker_id, explicitly checkingval is not None and not isinstance(val, bool)and stripping whitespace so speaker0is consistently formatted as"0: <text>", whilespeaker: Falseis properly ignored.
- In
-
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 unhandledUnicodeEncodeError. - Fix: Added
strip_surrogates(value: str) -> strto drop unpaired surrogates while preserving valid text across all fields and transcripts.
- When conversations contain unpaired UTF-16 surrogates (e.g.
-
Non-Atomic File Output:
- Writing directly with
dest_path.write_textleft partial, corrupted.tsvfiles if disk was full or the process was interrupted. - Fix: Implemented atomic writes via a sibling temporary file (
.{name}.tmp.{pid}) andos.replace, with automatic cleanup on failure.
- Writing directly with
-
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.
- Added
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 speaker0and"0"are formatted correctly andspeaker: Falseis excluded.test_lone_surrogates_stripped_without_encode_error: verifies lone surrogates are stripped and byte encoding succeeds withoutUnicodeEncodeError.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
- PayPal:
I would like to work on this. I will open a pull request that addresses the acceptance criteria.
@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.
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! 🙏