Skip to content

cli: bridge v2 waits for a voice message's transcript - #181

Open
morajabi wants to merge 1 commit into
mainfrom
cli/bridge-v2-voice-hold
Open

morajabi wants to merge 1 commit into
mainfrom
cli/bridge-v2-voice-hold

Conversation

@morajabi

Copy link
Copy Markdown
Contributor

Problem

Agents on bridge v2 (cli/src/bridge/v2/) got only the audio of a voice message, with the text "Review the attached voice message." Most agents can't listen to audio, so a voice message effectively arrived empty. The server does transcribe voice sent without text, but it delivers the transcript a few seconds later as an edit of the message. v2 dropped that edit as already seen. It also downloaded the audio before its dedupe check, so every replay or edit downloaded it again.

This fixes it in the bridge only. There are no protocol or server changes.

What changed

  • Hold. Once v2 decides to act on a voice message with no text, it holds the input instead of sending it. The hold is a record in the bridge's local ledger and keeps the full input, already built and authorized. While a message is held, the bridge shows the "working" indicator in the chat, repeated every 3 s.
  • Transcript before the deadline. The edit releases the hold. The agent gets Voice message (0:42), transcribed by Inline: followed by the transcript, and the audio is never downloaded.
  • Deadline first. The audio goes out as before, with a note that a transcript may follow. If the transcript arrives later, it goes to the agent once as its own input: Transcript of the voice message you received earlier (message N), ….
  • Restarts. Holds survive restarts. On startup, each hold is resumed and the message is looked up again. If the transcript is there it goes out at once; otherwise the hold waits until its original deadline. Held messages are never answered with "restarted before this ran".
  • Cancelling. /stop and the apps' Stop button drop the thread's holds, including pending late follow-ups. The Stop button only does this for someone allowed to stop the work.
  • Downloads. The ledger now records a message before any download, so replays and edits never fetch media again. This applies to all media.

Code: cli/src/bridge/v2/voice.rs (new), plus the wiring in runtime.rs and the table in ledger.rs.

New local ledger table: v2_voice_holds

This is a SQLite table in the bridge's local ledger, not a server database migration. It's additive (CREATE TABLE IF NOT EXISTS):

CREATE TABLE IF NOT EXISTS v2_voice_holds (
    input_id TEXT PRIMARY KEY, chat_id INTEGER NOT NULL, message_id INTEGER NOT NULL,
    duration_ms INTEGER, deadline_at INTEGER NOT NULL,
    delivered_audio INTEGER NOT NULL DEFAULT 0, held TEXT NOT NULL, created_at INTEGER NOT NULL
);

Behavior choices

  • No audio when there's a transcript. The agent gets the transcript text without the audio attached. Attaching it would mean downloading it, and the Codex driver rejects the whole input when audio is attached and its runtime doesn't support audio.
  • Transcript or caption? The server only transcribes voice sent without text, and writes the transcript through an edit. So voice whose text was edited in counts as the transcript. Voice sent with text keeps the sender's caption and gets the audio, as before. A caption the sender adds later by editing is also treated as the transcript.
  • Deadline: 15 s + 50% of the audio length, capped at 90 s. A message with unknown length waits 15 s. Audio over 600 s is never held, because the server never transcribes it.
  • Late transcripts follow up to 10 minutes after the deadline. After that the hold is dropped.
  • At most 64 waiting holds, as in bridge v1. Past that, voice goes out at once, as before.
  • A Skilled Agent is checked when the message arrives (refusals still answer right away) and applied when the message goes out.

Tests

New tests in the style of the existing v2 fault tests (real runtime, work actor, and SQLite ledger, with a scripted session). They cover:

  • transcript before the deadline
  • deadline before the transcript
  • a late transcript as a follow-up, sent only once
  • a restart while holding: a lookup that finds the transcript, and one that keeps waiting
  • a restart after the deadline passed
  • audio over 600 s
  • a message that already has its transcript
  • /stop while holding
  • the apps' Stop button, from someone with and without access
  • the "working" indicator: shown, repeated, and cleared

Plus unit tests for the deadline, the transcript/caption classification, the text formats, reading a looked-up message, and the ledger table surviving a reopen.

$ cargo fmt -p inline-cli -- --check          # exit 0
$ cargo clippy -p inline-cli --all-targets --locked -- -D warnings
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 39.94s
$ cargo test --locked -p inline-cli --no-fail-fast
unittests src/main.rs              test result: ok. 1197 passed; 0 failed; 16 ignored
tests/agent_json.rs                test result: ok. 15 passed; 0 failed
tests/diagnostic_privacy.rs        test result: ok. 2 passed; 0 failed
tests/ergonomics.rs                test result: ok. 17 passed; 0 failed
tests/provider_probe_terminal.rs   test result: FAILED. 0 passed; 1 failed
tests/setup_preflight.rs           test result: ok. 3 passed; 0 failed
tests/telemetry.rs                 test result: ok. 3 passed; 0 failed
tests/update_check.rs              test result: ok. 3 passed; 0 failed

provider_probe_terminal (claude_preflight_is_noninteractive_with_and_without_a_controlling_terminal) fails with "Claude is not authenticated" because Claude isn't logged in on the machine that ran these tests. It fails the same way on main without this change.

cargo fmt --all -- --check also flags crates/client/src/sdk_backend/bot_settings.rs, which this PR doesn't touch. It is already unformatted on main.

Not covered by tests

  • The real GetMessages call after a restart. Tests replace that one call with a canned message. The parsing of the result is shared with the real path and tested. The call itself needs a server, like the ignored v2 e2e tests.
  • The "working" request reaching Inline. Tests check what the bridge sends and when. The request itself needs a server.
  • A failed send dropping its hold. This happens when the thread's work stopped. It's a small, inspected path without its own test.

How to test manually

  1. cargo build -p inline-cli --release, then inline bridge stop.
  2. Run the bridge in the foreground with your bridge config: RUST_LOG=inline::bridge::v2=debug ./target/release/inline bridge run --config <bridge config.json>. The path is in the --config argument of the bridge's launchd agent.
  3. Send a voice message with no text to a v2 agent. You should see "working" and the log line voice held for its transcript. A few seconds later the agent should answer the transcript.
  4. To test a restart, press Ctrl-C within about 10 s of sending, then start the bridge again. It should answer the transcript, with no "restarted" notice.
  5. To test the deadline, turn off voice transcription in privacy settings and send one. After 15 s plus half its length, the audio and the note should go out.
  6. Run inline bridge start to return to the normal service.

🤖 Generated with Claude Code

v2 agents got only the audio of a voice message, with "Review the
attached voice message.", and dropped the server's transcript edit as
already seen. Every replay or edit also downloaded the audio again.

A voice message with no text is now held in a ledger record
(v2_voice_holds) until the transcript edit or a deadline of 15 s plus
half its length, at most 90 s:

- transcript first: it goes out as the message's text, no audio
- deadline first: the audio goes out as before, and a transcript that
  arrives within 10 minutes follows as its own input
- restart: holds resume, look the message up again, and are never
  reported as "restarted before this ran"
- /stop and the apps' Stop drop the thread's holds

Audio over 600 s is never held. The ledger records a message before
any download, so replays and edits never fetch media again. "Working"
shows while a message is held.

This branch has not been deployed

No deployments
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.

1 participant