Skip to content

feat(media): transcribe voice notes and video notes with a local Whisper program - #183

Merged
neoromantic merged 26 commits into
neoromantic:mainfrom
ertembiyik:ertembiyik/NO-TASK/transcribe
Nov 22, 2026
Merged

neoromantic merged 26 commits into
neoromantic:mainfrom
ertembiyik:ertembiyik/NO-TASK/transcribe

Conversation

@ertembiyik

@ertembiyik ertembiyik commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Release scope

Run tg media transcribe --chat me --id 42 to recognize one voice or video note with local Whisper. Import and sync perform no recognition. Configure the executable and model using transcribe.local.command and transcribe.local.model. Language detection is the default.

tg messages search --query "harbor" --count --snippet includes stored transcripts for the selected account. Every message counts once. A spoken match has transcriptMatch: true and its snippet quotes the speech. Replaced attachments and known protected notes or chats cannot match through stored speech.

The implementation checks attachment identity before processing, saving and returning results. Interrupting the CLI stops the local process tree and removes temporary WAV files. Identical audio in a batch is recognized once. Full offline verification on the updated branch passed 1,338 unit tests and 438 CLI tests. A live Saved Messages run for the release candidate is outstanding.

Issue #102 tracks additional providers, opt-in onboarding, history and queue controls, spending limits and optional text cleanup.

Original proposal and earlier verification

What and why

tg media transcribe --chat <peer> --id <id> [--id …] turns voice notes and video notes into text with a speech-to-text program installed on this machine (whisper.cpp, or an openai-whisper-compatible CLI such as mlx-whisper), stores the text, and tg messages shows it in each item's transcript. This is the local-model part of #102. Refs #102

The need: an agent reading a chat skips every voice note and video note. One real chat had about 400 of them, 170 minutes of audio. What worked there was a hand-written pipeline: download each file, convert it with ffmpeg, run a local Whisper model. This PR is that pipeline as one command.

Before

$ tg media transcribe --chat me --id 1
USAGE tg media download|clean
…
Unknown command transcribe

After (real output from the e2e fakes: message 1 is already stored, 3 is a photo, 4 is silent)

$ tg media transcribe --chat me --id 1 --id 2 --id 3 --id 4
{"success":true,"data":{"chatId":5550001,"messageId":1,"text":"Meet me at the harbor at eight.","language":"en","source":"local","runner":"whisper","model":"large-v3-turbo","cached":true}}
{"success":true,"data":{"chatId":5550001,"messageId":2,"text":"A round video from the lake.","language":"en","source":"local","runner":"whisper","model":"large-v3-turbo","cached":false}}
{"success":false,"error":{"code":"MEDIA_UNSUPPORTED","message":"Message 3 in chat 5550001 is not a voice note or video note","details":{"chatId":5550001,"messageId":3,"kind":"photo","reason":"not_speech"}}}
{"success":true,"data":{"chatId":5550001,"messageId":4,"text":"","language":null,"source":"local","runner":null,"model":null,"cached":false}}
stderr:  Transcribed 3 of 4 messages, 1 failed
exit 1

tg messages get then shows the stored text on voice and video notes, and transcript: null on every other item:

"attachment": { "kind": "voice", … },
"transcript": { "text": "Meet me at the harbor at eight.", "language": "en", "source": "local", "model": "large-v3-turbo" }

A setup dead end says what to run. Real output of the real whisper-cli with no model set (home directory shortened to ~):

$ tg media transcribe --chat me --id 1
{"success":false,"error":{"code":"INVALID_ARGS","message":"whisper.cpp needs a model file: transcribe.model is not set","details":{"runner":"/opt/homebrew/bin/whisper-cli","model":null},"suggestion":"Run whisper.cpp with a model: download the 574 MB model and point tg at it: curl -L --create-dirs -o ~/.cache/whisper-cli/ggml-large-v3-turbo-q5_0.bin https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-large-v3-turbo-q5_0.bin && tg config set transcribe.model ~/.cache/whisper-cli/ggml-large-v3-turbo-q5_0.bin"}}
Situation Error suggestion
no program on PATH TRANSCRIBER_NOT_FOUND (new code, exit 1) Install whisper.cpp: brew install whisper-cpp ffmpeg, then the download and config commands above; on Apple Silicon also uv tool install mlx-whisper; on Windows uv tool install whisper-ctranslate2
no ffmpeg TRANSCRIBER_NOT_FOUND brew install ffmpeg
whisper.cpp, transcribe.model not set INVALID_ARGS the download command and tg config set transcribe.model …
transcribe.model names a missing file INVALID_ARGS the download command for that path
the program ran and failed GENERAL_ERROR for that message none; details has its exit code and the end of its stderr

The issue's three questions

  • Telegram's own transcription can't cover a chat. A Premium account transcribed one message through messages.transcribeAudio, then got a flood wait of about 1,950 s. So it is not in this PR; it can come later as an explicit per-message source.

  • Size and speed of a local model, Russian and English. Nine made-up clips, 295 s of English and Russian speech, on an M4 Pro, all with large-v3-turbo:

    Program One process for all files One process per file
    mlx-whisper 31.0 s 69.8 s
    whisper.cpp (ggml-large-v3-turbo-q5_0, 574 MB) 37.8 s 50.3 s
    openai-whisper, CPU 280.7 s 412.4 s

    Each program differed from the script by 0 to 7 words per clip, mostly number formatting ("десять" and "10"). All three answer digital silence with "Thank you.", and no_speech_prob doesn't flag it, so tg stores audio whose peak is below -60 dB as empty text without running the program.

  • Where the audio goes. The file is downloaded from Telegram into the account's media cache, as tg media download does, converted by ffmpeg in a temp directory that is removed afterwards, and given to the program on this machine. Nothing leaves the machine. The Python programs download their model on first use; tg never downloads a model. docs/media.md says this.

How it works

  • tg bundles and downloads nothing. It runs transcribe.command, or the first of whisper-cli, mlx_whisper, whisper-ctranslate2 and whisper on PATH. whisper.cpp comes first: it is one native program for macOS, Linux and Windows and within about 25% of the fastest here. mlx-whisper is the faster option on Apple Silicon.
  • Each file comes through tg media download's code path, unchanged: cache first, resume, content protection refused. Read-only mode allows the command and allowedChats applies, as for media download.
  • One run of the program handles every file, so the model loads once. ffmpeg first converts each file to 16 kHz mono WAV, because whisper.cpp reads neither Opus nor MP4. mlx_whisper is the exception: it writes every result of one run under the first file's name, so it runs once per file.
  • Transcripts are stored in a new message_transcripts table, keyed by chat and message. A second run, or the same file in another message, is answered from it with cached: true; --force transcribes again.
  • Output: one message prints the usual envelope. Several print one JSON line each, in --id order, and exit 1 when any failed, as feat(media): download several messages in one run, with name templates #181 does for downloads.
  • Config: transcribe.command, transcribe.model and transcribe.language, on a new string value type in the config module. feat(media): download several messages in one run, with name templates #181 left its config.json defaults out because that type was missing; it can use this one.

Decisions you may want to change:

  • Whole-run problems fail the run (no program, a bad chat, a rate limit); a problem with one message fails that message only.
  • The suggested model path is ~/.cache/whisper-cli/ (under $XDG_CACHE_HOME when that is set), not tg's data directory: other programs that run whisper.cpp can use the same file.
  • The model is chosen for the user: tg passes large-v3-turbo to whisper and whisper-ctranslate2, whose own defaults are turbo and small.
  • The silence threshold is -60 dB, and a silent result stores runner, model and language as null.
  • transcript is on every message item, null unless a voice or video note has a stored transcript. Only those rows query the table.
  • For whisper.cpp, model is the model file's name, not its path, so output holds no home directory.

Left out of #102, on purpose:

  • Telegram's messages.transcribeAudio and an external API as sources.
  • Searching transcripts: the FTS index is fed by triggers on messages_cache and needs its own change.
  • --type, --since, --until and --limit: feat(messages): filter messages list by --type, --since and --until #180 adds the first three to tg messages list, and this command should reuse them once that lands. Until then any command that prints IDs can feed it.
  • A live test in src/__integration__/: not added. I checked live by hand (below).

One edit to a shared test helper: src/__e2e__/helpers/cli.ts starts the CLI with process.execPath instead of bun. The transcribe tests give the CLI a PATH that holds only the fakes, so Bun has to be named by path; otherwise Homebrew's bin, with a real ffmpeg and Whisper, would come along.

This touches src/commands/messages/helpers.ts, src/types/index.ts and src/utils/output.ts, as #176, #177 and #178 did; main is merged in, see the update below.

Rework after the design comment (69349cd..d386ff1)

The local path now sits behind one provider protocol, and the four regressions from the comment are fixed with tests. Where this section and the sections above disagree, this one is current.

  • One protocol (src/commands/media/transcription-provider.ts). A provider declares, before anything runs: where the audio or message reference goes (sendsTo, null for this machine), whether a request can cost money, its input (the message itself, or audio as the original file or 16 kHz WAV), batch size, concurrency and maximum duration. It returns text, language and model, or a failure marked rejected, retry_later or outcome_unknown (never retried, nothing stored).
  • One pipeline (transcription-pipeline.ts) for every provider: eligibility (the same check as tg media download, before any reuse), reuse keyed to the file the message holds now, setup, limits, audio only if the provider reads audio and only in the format it takes, the provider, a second eligibility check before each save, temp cleanup.
  • Only the local provider is implemented (local-provider.ts): the same programs, config keys, output and stored columns as before. No schema change; existing rows stay valid.
  • Proved with fakes in tests only: a provider that reads the message triggers no download and no ffmpeg; one that uploads the original file gets its bytes unconverted; an unknown outcome is reported as such and stores nothing; ready results of a batch survive another message's failure.
  • The four regressions, each a failing e2e test first: a changed attachment is transcribed again and tg messages hides the stale transcript; SIGTERM and SIGINT stop ffmpeg or the program, remove the temporary audio and exit 130; a missing program fails only the messages that need it, ready results are printed; content protection is checked before a stored transcript is returned.
  • Also from the table: unsupported media is refused before its bytes are transferred, and a transcript is not stored for a message the cache keeps out.
  • Checked live on a personal account with whisper.cpp: two stored notes answered from the store, then transcribed again with --force in 4.5 s with the same result; a photo refused; tg messages get shows the transcript; no temporary files left.
  • After the rework: bun run check clean (Knip included), bun run test 2058 pass, bun run test:e2e 477 pass, 0 fail.

Update: main merged in (5443e73)

  • main moved to oxfmt and oxlint with the landmines rules, and moved every test beside its code. This branch follows: the same behaviour and output, the code restyled, prose comments and explicit return types removed.
  • Tests moved with main's layout: src/test/media-transcribe.e2e.test.ts, and local-provider.test.ts and transcription-pipeline.test.ts in src/commands/media/.
  • The SIGTERM e2e test waited with a fixed sleep and a raised timeout, which the new rules forbid; it now waits on a file watch. Its assertions are unchanged.
  • This and feat(media): download several messages in one run, with name templates #181 will conflict in download-media.ts (both rework the online check); whichever lands second gets the fold-in from me.
  • After the merge: bun run check clean (format, lint, types, Knip), bun run test 1217 pass, bun run test:e2e 359 pass, 0 fail. Totals are lower than before because main merged and removed many tests.

How I checked it

  • E2E with a fake ffmpeg and one fake program per output shape (15 tests): one voice note stored and shown by tg messages get; several IDs with the program started once; mlx_whisper once per file; whisper.cpp with a model file and -l auto; silent audio stored empty with no program call; a stored transcript reused, by message and by file, and --force; a content-protected message refused exactly as tg media download refuses it; each setup error with its suggestion; the converted audio removed from the temp directory when the whole run fails.

  • Unit tests for both JSON parsers on real output of whisper.cpp 1.9.5 and mlx-whisper 0.4.3, for detection, and for the suggestion on macOS, Linux and Windows.

  • Real programs on an M4 Pro, from the media cache of a scratch data directory with made-up clips: whisper.cpp, mlx-whisper and openai-whisper each transcribed an English voice note, a Russian voice note and an English video note correctly, and stored the silent clip as empty.

  • Live, on a personal account with whisper.cpp: a voice note and a video note in Saved Messages, neither in the media cache, transcribed in one command in 8 s including the two downloads; the same command again answered both with cached: true; tg messages get showed the transcript.

  • Not verified: whisper-ctranslate2 and Windows (flags checked in its source), Linux, and Homebrew's whisper.cpp on Linux.

  • bun run check: clean. bun run test: 2315 pass, 0 fail. bun run test:e2e: 448 pass, 0 fail. Two tests in commands.e2e.test.ts that try the network ("should try to fetch from API…") hit their 5 s timeout in some runs on this machine; they do the same on main (1 of 8 runs) and this PR doesn't touch them.

  • Tests pass locally and use made-up data only

  • README, docs and affected demos follow the product content standard (docs/media.md, docs/cli-commands.md, docs/configuration.md, docs/database-schema.md, docs/api-design.md, README, CHANGELOG)

  • Title follows the repo's commit style: Conventional Commits (feat: …, fix: …) unless AGENTS.md says otherwise

Update: second code review (5c91284)

A second, independent review of this branch. Each point below was first shown by a failing test, then fixed.

  • A runner that wrote parseable output and then exited non-zero produced a stored transcript. Any non-zero exit now fails every message of that run.
  • An interrupted run can no longer report success: cancellation is checked right after the provider answers and again before printing. SIGHUP is handled like SIGINT and SIGTERM, and the temp directory is removed on every exit, a second interrupt included.
  • A rejected result is never retryable (a network error kept its own flag); retry_later always is. outcome_unknown is unchanged: details.outcome: "unknown", not retryable, nothing stored.
  • With no transcriber installed, a message the cache does not hold fails with the setup error before Telegram is contacted; it used to fail on missing credentials. In that case it no longer reuses a transcript stored for the same file in another message.
  • Checked and unchanged: docs/media.md already says which runners download their model on first use.

After these commits: bun run check clean, bun run test 1219 pass, bun run test:e2e 362 pass, 0 fail.

Update: main merged in (649eef9)

main up to #220 merged in, no conflicts and no changes to this branch's code.

After the merge: bun run check clean, bun run test 1230 pass, bun run test:e2e 363 pass, 0 fail.

Update: main merged in (853a651)

main up to 0.15.1 and #232 merged in. Conflicts: CHANGELOG.md (the entry of this PR now sits under the new ## [Unreleased]) and src/commands/media/download-media.ts. getClientForAccount() is async since #226, so tg media transcribe and checkedAttachment await the client. No behaviour change. The follow-up of 19 November (protected content in the message reader) is not in this merge.

After the merge: bun run check clean, bun run test 1242 pass, bun run test:e2e 389 pass, 0 fail.

Update: stored transcripts of protected content (5252139)

The message reader applies the offline protection check that tg media transcribe and tg media download make, from one function (cachedProtection in src/commands/media/protection.ts). Once the cache knows a message or its chat is protected, every tg messages item has transcript: null for it; the stored row stays. The e2e cases cover a message and a chat that become protected after they were transcribed, on both paths: tg media transcribe refuses, tg messages get and list show no transcript. Both failed on the reader before the change.

bun run check clean, bun run test 1242 pass, bun run test:e2e 390 pass, 0 fail.

Update: main merged in (ac85803)

main up to 0.15.2 (#234) merged in. One conflict: CHANGELOG.md (the entry of this PR stays under ## [Unreleased], above the new 0.15.2 section). No code change in this PR. The Windows download fix of #234 in src/commands/media/download-media.ts merged without a conflict.

After the merge: bun run check clean, bun run test 1242 pass, bun run test:e2e 390 pass, 0 fail.

🤖 Generated with Claude Code

ertembiyik and others added 2 commits November 18, 2026 11:15
…per program

tg media transcribe turns voice notes and video notes into text with a
speech-to-text program on this machine (whisper.cpp or an
openai-whisper-compatible CLI), stores it in message_transcripts and
shows it in the transcript field of message items.

tg finds the program on PATH or runs transcribe.command, and never
bundles or downloads a model. Setup errors carry the commands to run in
their suggestion.

Refs neoromantic#102

Co-Authored-By: Claude Fable 5.2 <[email protected]>
The setup errors suggested <data dir>/models/. The model file is not
specific to tg: any program that runs whisper.cpp can use it, so the
suggestion is now $XDG_CACHE_HOME/whisper-cli/, else ~/.cache/whisper-cli/.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
ertembiyik and others added 3 commits November 18, 2026 14:24
helpers.ts: a message item gets the transcript and the rich text (neoromantic#186). CHANGELOG: both sides' entries kept. Per-message error lines and the docs example carry retryable (neoromantic#177).

Co-Authored-By: Claude Fable 5.2 <[email protected]>
main now has neoromantic#179 (neoromantic#188). No conflict.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
main is now the 0.14.0 release (neoromantic#189). This PR's changelog entries move
back under Unreleased: a plain merge left them in the released section.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@neoromantic

Copy link
Copy Markdown
Owner

Design research for #102

The local Whisper implementation gives us a concrete starting point. We want to design transcription as a full CLI feature before accepting an implementation. Transcript search is in scope for the first release. Let's use this PR to discuss the design. The command names, provider integrations, queue design and acceptance cases below are proposals. Implementation and merge are pending that discussion.

What setup should feel like

Transcription starts off for every account. After a successful interactive phone or QR login, ask once in the terminal whether to configure it. The same settings should be available later through the CLI. The existing tg config path/get/set commands are the natural home. Non-interactive login should keep working for scripts.

One possible terminal interaction, with made-up data:

$ tg config transcribe --account demo
When should tg transcribe?
  [ ] New messages from now on
  [ ] Existing history, once
      With both unchecked, only explicit requests run.

Recognize audio with    Local Whisper / custom executable / Telegram / cloud model
Clean up text with      Off / choose a text model

Selecting history opens a chat and date-range choice. New messages and history can be selected independently. Before saving, show which program or service receives the audio, which receives the text, and any spending limit. Keep language auto-detection and the option to specify a local command. Discover local programs and the presence of known ENV keys without sending a sample, printing a key or enabling a provider. An agent should be able to inspect and apply the same choices using flags or structured input.

Providers and readable text

Support both direct provider credentials and a user-selected Vercel AI Gateway key. Evaluate the Vercel AI SDK to avoid maintaining a separate client for every model. Show models by what they can do. The audio candidates include ElevenLabs Scribe, OpenAI, Gemini Transcribe and xAI Grok STT, alongside local tools and Telegram's own transcription. Claude is a candidate for editing the text. A Gateway choice should name the actual model. Decide which direct and Gateway combinations we can test and support before advertising them. The source order in #102, particularly what should happen when Telegram returns a flood wait, remains a design question. A fallback that changes where audio goes or incurs a charge needs to be part of the user's selection. AI SDK transcription · Gateway audio · Gemini transcription · xAI speech to text

Save the original transcript as soon as recognition succeeds. Optional cleanup gives a fast model the text. The message shows the cleaned version when accepted and the original remains accessible. A failed edit leaves the original readable. Running cleanup again should cost one text operation and zero audio operations. For search, the proposal is to index the displayed version, identify a transcript match and return the message once. The exact search flag and whether ordinary message searches should include transcripts are open.

Large imports, overload and spending

Message sync should finish independently of speech recognition. If the user selects only new messages, importing 400 old recordings should create zero speech jobs. For an explicitly selected history run, preview eligible and already completed counts, known audio duration, incomplete cache coverage, estimated cost and, once measured, an ETA. The PR's M4 Pro benchmark took about 38 seconds with whisper.cpp and 281 seconds with CPU Whisper for the same 295 seconds of audio. That difference matters more to a user than a generic progress spinner.

Use a resumable per-account queue with bounded concurrency. Give incoming notes priority over the next history batch. Pausing, restarting or opening settings twice must preserve completed work and avoid duplicate charges. Include recognition and cleanup in the cost preview. One candidate is an account budget plus an optional cap per history run, with a reservation before a paid submission. Honor provider backoff. If a response is lost after a provider may have accepted the request, reconcile its job ID or show an unknown outcome before offering a potentially billable retry.

Acceptance cases to discuss

Scenario Observable outcome
Install, login or skip setup with local tools and cloud keys present Zero model calls or background transcription jobs. A second account makes its own choice.
Import 400 synthetic voice notes, receive a new note, restart mid-batch Sync and cache reads continue. The new note gets the next available slot ahead of history. Completed work survives restart. Measure elapsed time, model starts, queue delay and peak temporary storage.
Two workers approach the spending limit, then a provider returns 429 or loses its reply The ledger covers in-flight work. Status shows the reason for waiting. Verify the number of actual billable submissions.
Reuse protected media, replace an attachment during recognition, or fetch a group message excluded from the cache Check eligibility before cache reuse and again before saving. No protected content is sent, no stale transcript is displayed, and excluded group history stays out of persistent storage.
Unsupported media, mixed cached/uncached IDs, or cancellation during ffmpeg/Whisper Reject the media before transferring its bytes. Preserve ready results in the batch, stop the child process and remove temporary audio on normal interruption.
Cleanup succeeds, fails, or changes the displayed text The original remains available. Search finds the current version once, drops stale matches after an edit and stays isolated by account.
Verify supported routes Offline tests with fake runners/providers, Russian and English synthetic samples with names, numbers, negation, quiet speech and silence. Opt-in release checks for each advertised route and a Saved Messages smoke test as requested in #102.

The current head already gives us regression cases. At dfadb63, an offline check returned the old transcript after the attachment changed, SIGTERM left a temporary WAV, and a missing runner suppressed a ready result in a mixed batch. Static review also found transcript-cache returns before the existing content-protection check. These belong in the baseline tests whichever design we choose. Cache reuse · Temporary files · Message output

The decisions worth discussing here first are the search default, provider/fallback choices and how to make a history run's time and cost clear before starting it. Those decisions should determine how we refactor the local command and split the work.

ertembiyik and others added 8 commits November 18, 2026 20:38
main now has neoromantic#175 (neoromantic#194), neoromantic#174 and neoromantic#155. helpers.ts: the item reader takes main's raw string, with the transcript kept. sql.test.ts uses main's cache helper. CHANGELOG: both sides kept.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
main now has neoromantic#195: Knip in bun run check, and long as a runtime dependency. No conflict; the check is clean.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
A changed attachment returned the old transcript, SIGTERM left the
converted audio behind, a missing program hid a ready result in a batch,
and a stored transcript skipped the content-protection check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…regressions

The local programs become a provider behind TranscriptionProvider, and
one pipeline gives every provider the same steps: eligibility before
reuse, reuse keyed to the file as it is now, setup per message, download
and audio only for providers that read audio, a second check before
saving, temporary audio removed on interrupt (exit 130).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…holds now

tg messages hid no stale transcript after an attachment changed, and a
transcript copied from the same file in another message skipped the
save-time check. Also covers cancellation during ffmpeg.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ertembiyik

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review. I reworked the branch around one provider protocol instead of patching the local path, and kept the scope to what exists today.

The protocol. A provider declares, before anything runs: where the audio or message reference goes, whether a request can cost money, its input (the message itself, or audio as the original file or 16 kHz WAV), batch size, concurrency and maximum duration. It returns text, language and model, or a failure marked rejected, retry later, or outcome unknown (never retried, nothing stored). One pipeline runs the same steps for every provider: eligibility, reuse keyed to the current file, setup, limits, audio only if needed, the provider, a second eligibility check before each save, temp cleanup. It was shaped against three cases (a local program, a cloud API that takes bytes and bills, Telegram's own transcription that takes a message ID), and only the local provider is implemented.

Your four regressions are offline tests now and fixed: a changed attachment, SIGTERM (exit 130, child stopped, WAV removed), a missing runner in a mixed batch, protection before reuse. The description has the details.

Proposed split into separate issues, each on top of this protocol: cloud and Telegram providers, the queue with budgets, the setup flow, text clean-up, search.

Your three questions:

  • Search default: your call; the protocol doesn't constrain it. Indexing the displayed version and returning a message once fits the stored row as it is.
  • Providers and fallback: selection by a config key and a flag once there is a second provider. A fallback that changes where audio goes or adds cost should be the user's explicit choice; the declarations (sendsTo, cost) make that checkable.
  • Time and cost before a history run: the declarations plus cached durations give the count, total duration, destination and cost class before anything runs. Prices and an ETA need data the protocol doesn't hold yet.

Does this split work for you?

Conflicts came from main's oxfmt reformat, comment and return-type sweeps and the test colocation; the transcribe additions were reapplied onto main's versions (access, media, helpers, config, schema, types, download-media's shared cached/online checks, README) and the config and sql test cases moved into main's colocated files. The branch's new code and tests now follow main's lint (no prose comments, inferred return types with satisfies contracts), its tests sit beside their modules or in src/test, and the SIGTERM e2e waits on a file watch instead of polling with a raised timeout.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
ertembiyik and others added 5 commits November 19, 2026 19:52
A runner that wrote parseable JSON and then exited with an error still
produced a stored transcript. Any non-zero exit now fails every message
of that run.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
A provider's rejected result kept the retryable flag of its error, so a
rejection caused by a network error read as retryable. rejected is now
never retryable; retry_later always is.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…sages

For a message the cache does not hold, the pipeline asked Telegram for it
before reporting that ffmpeg or the runner was missing, so without
credentials the setup error was hidden behind a credentials error. Such
a message now fails with the setup problem when the provider is not ready.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
SIGHUP killed tg without removing the converted audio, and a second
interrupt exited before the pipeline removed it. A signal that arrived
while the runner's output was read still let the results be stored and
printed with exit 0. SIGHUP now stops a run like SIGINT and SIGTERM, the
temporary root is removed on every exit, and cancellation is checked
after the provider call and before the results are printed.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@neoromantic

Copy link
Copy Markdown
Owner

Yes, the split works for me. Thanks for reworking the local path and adding the four regression tests. Let's keep #183 focused on the local command and shared provider interface, with linked issues under #102 for terminal setup, the queue and spending limits, Telegram and cloud providers, optional text cleanup, and search. Transcript search is part of the first release. #102 should carry the acceptance criteria that span those issues.

Before we settle the individual designs, I'd like us to agree on one end-to-end CLI scenario here. Here is the first-release experience I propose we test with a synthetic chat:

  1. I connect an account in the terminal. I can skip transcription setup or revisit it through tg config. The CLI can discover installed tools and the presence of provider keys. Skipping setup makes zero model calls. I can choose new messages, an explicit history range, or both. My second account starts with its own settings.
  2. I choose new messages and import a chat containing 400 old voice notes. Message sync completes normally and those 400 notes create zero recognition jobs. If I later select that history, the CLI previews how many notes still need work, their known duration, where audio and optional cleanup text will go, and the estimated cost and time. Unknown estimates are shown explicitly. I confirm the scope and spending limit before a paid run.
  3. While history runs, I can read messages and see the first transcript after the first batch. A newly arrived note gets the next available slot. Temporary audio stays bounded by the active batch. Pausing and restarting preserves completed work. If a provider may already have billed a request, the queue surfaces the unknown outcome before any resubmission. A fallback that changes the recipient or adds a charge requires my prior choice.
  4. I can read the original transcript, optionally clean it up with a text model, and find the displayed wording through message search. A match returns the message once. Re-running cleanup makes zero speech calls. Whether an ordinary search includes transcripts by default is still open.

One concrete follow-up for #183 is consistent handling of protected content. Once the cache learns that a previously transcribed message or its chat is protected, tg media transcribe refuses it, but the shared message reader still attaches the stored text for the same file. I'd like a regression case covering both paths and the same visibility rule carried into search. The batch preparation loop also explains the first-result criterion above: today it prepares the full list before calling Whisper. Message reader · Batch preparation

Does that sequence work with the proposed split? In particular, I'd like to hear how you would handle a Telegram flood wait during a history run when the user has only authorized Telegram. That is a useful case for agreeing on the queue and provider behavior together.

ertembiyik and others added 2 commits November 20, 2026 20:22
…anscribe

# Conflicts:
#	CHANGELOG.md
#	src/commands/media/download-media.ts
The message reader now applies the offline protection check that
tg media transcribe and tg media download use (message flags, the chat's
cached noforwards and its last online check), from one function in
src/commands/media/protection.ts. The regression case covers a message
and a chat that become protected after they were transcribed.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@ertembiyik

Copy link
Copy Markdown
Contributor Author

The sequence works with the split.

Protected content is fixed in 5252139. The message reader now makes the same offline check as tg media transcribe, from one function (cachedProtection), so a stored transcript of a message or chat the cache knows is protected comes back as transcript: null; the row stays. The regression cases cover a message and a chat that become protected after transcription, on both paths. Search can call the same function.

First result: today the pipeline checks every ID, then downloads and converts all the audio, then calls the provider, and the local provider declares one batch for the whole run. For the queue issue I'd prepare each batch inside its worker, so temp audio is bounded by concurrency × batch size, and give the local provider a finite batch size. I'd leave that out of #183 unless you want it here.

Flood wait with only Telegram authorized: FLOOD_WAIT means Telegram refused before doing anything, so it is retry_later, never outcome_unknown, and nothing switches provider because the run has one. In the queue I'd defer the job to now + wait without counting an attempt, as the daemon does for sync jobs, keep finished work, and show "waiting until X" in status. Message sync is unaffected: the block is per method. A newly arrived note waits behind the same deferral. A one-shot tg media transcribe returns RATE_LIMITED (exit 5) with wait_seconds instead of sleeping. Still open: a request interrupted after it was sent is outcome_unknown; if Telegram's transcription has a quota, the queue should surface that before resubmitting.

@neoromantic
neoromantic merged commit f2380ee into neoromantic:main Nov 22, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants