Skip to content

fix(windows): 收口录音会话失败态#66

Merged
appergb merged 1 commit into
Open-Less:mainfrom
Cooper-X-Oak:codex/windows-session-error-pr
Apr 30, 2026
Merged

fix(windows): 收口录音会话失败态#66
appergb merged 1 commit into
Open-Less:mainfrom
Cooper-X-Oak:codex/windows-session-error-pr

Conversation

@Cooper-X-Oak
Copy link
Copy Markdown
Contributor

@Cooper-X-Oak Cooper-X-Oak commented Apr 30, 2026

摘要

关联 fork 验证:Cooper-X-Oak#12

本 PR 是从 fork/dev 已验证批次拆出的第五个最小 upstream 维护项:收口 Windows 录音会话失败态,避免缺 ASR 凭据或空转写继续走成功/插入链路。

fork/dev 先行验证

修复 / 新增 / 改进

  • 录音开始前检查当前 ASR provider 凭据。
  • Volcengine 缺 App Key / Access Key 时直接返回 Error,不启动录音。
  • Whisper 缺 API Key 时直接返回 Error,不启动录音。
  • ASR 返回空 transcript 时写入 history 失败记录:insertStatus=failederrorCode=emptyTranscript
  • 空转写不再进入 polishing / insertion / Done capsule,避免误报成功。

兼容

  • 不包含:启动路径、热键 core、麦克风权限、设置页凭据保存、真实 ASR smoke 脚本。
  • 对现有用户 / 本地环境 / 构建流程的影响:缺 ASR 凭据和空转写会更早以错误态呈现,不再进入后续插入链路。

测试计划

  • 命令:npm run build
  • 结果:TypeScript + Vite build 通过。
  • 命令:openless-all/app/scripts/windows-build-gnu.ps1
  • 结果:Windows GNU build/msi/nsis 通过,仅既有 warning。
  • 命令:git diff --check
  • 结果:通过。
  • fork PR CI:test(windows): 收敛 fork dev 真机回归批次 Cooper-X-Oak/openless#12 Windows Tauri checks / Sourcery review 均通过。

Summary by Sourcery

Enforce ASR credential validation and empty-transcript handling in the Windows recording session lifecycle to prevent failed dictations from proceeding as successful sessions.

Bug Fixes:

  • Block session start when Whisper or Volcengine ASR credentials are missing, surfacing an explicit error instead of proceeding with recording.
  • Record dictation sessions with empty ASR transcripts as failed history entries and stop further processing instead of treating them as successful insertable results.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Apr 30, 2026

Reviewer's Guide

Adds explicit ASR credential gating before starting Windows recording sessions and records empty ASR transcripts as failed dictation history entries, preventing them from flowing through the normal success/polishing/insertion pipeline.

Sequence diagram for Windows begin_session ASR credential gating

sequenceDiagram
    actor User
    participant WindowsApp
    participant Coordinator
    participant CredentialsVault
    participant CapsuleEmitter

    User->>WindowsApp: trigger_recording
    WindowsApp->>Coordinator: begin_session

    Coordinator->>CredentialsVault: get_active_asr
    CredentialsVault-->>Coordinator: active_asr

    alt active_asr == whisper
        Coordinator->>CredentialsVault: get AsrApiKey
        CredentialsVault-->>Coordinator: api_key
        alt api_key is empty
            Coordinator->>Coordinator: ensure_asr_credentials returns Err
            Coordinator->>CapsuleEmitter: emit_capsule Error
            Coordinator->>Coordinator: set SessionPhase Idle
            Coordinator-->>WindowsApp: Err message
        else api_key present
            Coordinator->>Coordinator: ensure_asr_credentials returns Ok
            Coordinator->>Coordinator: proceed to ensure_microphone_permission
        end
    else active_asr != whisper (Volcengine)
        Coordinator->>Coordinator: read_volc_credentials
        Coordinator-->>Coordinator: creds app_id, access_token
        alt app_id or access_token empty
            Coordinator->>Coordinator: ensure_asr_credentials returns Err
            Coordinator->>CapsuleEmitter: emit_capsule Error
            Coordinator->>Coordinator: set SessionPhase Idle
            Coordinator-->>WindowsApp: Err message
        else volc credentials present
            Coordinator->>Coordinator: ensure_asr_credentials returns Ok
            Coordinator->>Coordinator: proceed to ensure_microphone_permission
        end
    end
Loading

Sequence diagram for end_session empty transcript handling

sequenceDiagram
    participant Coordinator
    participant AsrProvider
    participant HistoryStore
    participant CapsuleEmitter

    Coordinator->>AsrProvider: end_session collect_raw_transcript
    AsrProvider-->>Coordinator: RawTranscript text, duration_ms

    Coordinator->>Coordinator: check raw.text.trim().is_empty()
    alt raw text is empty
        Coordinator->>HistoryStore: append DictationSession
        HistoryStore-->>Coordinator: append Result
        Coordinator->>CapsuleEmitter: emit_capsule Error
        Coordinator->>Coordinator: set SessionPhase Idle
        Coordinator-->>AsrProvider: Err empty transcript
    else raw text non empty
        Coordinator->>CapsuleEmitter: emit_capsule Polishing
        Coordinator->>Coordinator: polish_or_passthrough
    end
Loading

Updated class diagram for coordinator ASR gating and dictation session failure

classDiagram
    class Inner {
      +Prefs prefs
      +HistoryStore history
      +State state
    }

    class Prefs {
      +PrefsValue get()
    }

    class PrefsValue {
      +PolishMode default_mode
    }

    class State {
      +SessionPhase phase
    }

    class SessionPhase {
      <<enumeration>>
      Idle
      Recording
      Polishing
      Inserting
      Error
    }

    class DictationSession {
      +String id
      +String created_at
      +String raw_transcript
      +String final_text
      +PolishMode mode
      +String app_bundle_id
      +String app_name
      +InsertStatus insert_status
      +String error_code
      +u64 duration_ms
      +u32 dictionary_entry_count
    }

    class InsertStatus {
      <<enumeration>>
      Pending
      Succeeded
      Failed
    }

    class HistoryStore {
      +Result append(DictationSession session)
    }

    class RawTranscript {
      +String text
      +u64 duration_ms
    }

    class CredentialsVault {
      +String get_active_asr()
      +Result get(CredentialAccount account)
    }

    class CredentialAccount {
      <<enumeration>>
      AsrApiKey
    }

    class CoordinatorModule {
      +Result begin_session(Inner inner)
      +Result end_session(Inner inner)
      +Result ensure_microphone_permission(Inner inner)
      +Result ensure_asr_credentials()
      +void emit_capsule(Inner inner, CapsuleState state, float progress, u64 elapsed, String message, String payload)
      +Vec enabled_phrases(Inner inner)
    }

    class CapsuleState {
      <<enumeration>>
      Idle
      Recording
      Polishing
      Inserting
      Error
    }

    Inner --> Prefs
    Inner --> HistoryStore
    Inner --> State
    HistoryStore --> DictationSession
    DictationSession --> InsertStatus
    CoordinatorModule --> Inner
    CoordinatorModule --> RawTranscript
    CoordinatorModule --> CredentialsVault
    CredentialsVault --> CredentialAccount
    CoordinatorModule --> CapsuleState
    CoordinatorModule --> SessionPhase
    CoordinatorModule --> InsertStatus
    CoordinatorModule --> DictationSession
Loading

File-Level Changes

Change Details Files
Gate session start on presence of valid ASR credentials and surface failure to UI/error state.
  • Introduce ensure_asr_credentials helper to validate active ASR provider credentials (Whisper API key or Volcengine App Key/Access Key).
  • Call ASR credential gate at the beginning of begin_session and abort session start when credentials are missing.
  • Emit an Error capsule and reset session phase to Idle when ASR credential validation fails, returning a descriptive error message.
openless-all/app/src-tauri/src/coordinator.rs
Treat empty ASR transcripts as failed sessions and avoid further processing.
  • Add early check for empty transcript in end_session and construct a DictationSession with InsertStatus::Failed and error_code=emptyTranscript.
  • Append failed empty-transcript sessions to history while logging any append failures.
  • Emit an Error capsule, reset session phase to Idle, and return an error string instead of continuing to polishing/insertion for empty transcripts.
openless-all/app/src-tauri/src/coordinator.rs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • In ensure_asr_credentials, treating any non-"whisper" value from CredentialsVault::get_active_asr() as Volcengine could give misleading errors if a new ASR provider is configured; consider matching explicitly on known providers and returning a distinct error for unknown/unsupported values.
  • The "ASR returned empty transcript" error string is duplicated in end_session; consider extracting this into a shared constant or error type so that the user-facing message and any future mapping to error codes stay consistent.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `ensure_asr_credentials`, treating any non-`"whisper"` value from `CredentialsVault::get_active_asr()` as Volcengine could give misleading errors if a new ASR provider is configured; consider matching explicitly on known providers and returning a distinct error for unknown/unsupported values.
- The "ASR returned empty transcript" error string is duplicated in `end_session`; consider extracting this into a shared constant or error type so that the user-facing message and any future mapping to error codes stay consistent.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@appergb appergb force-pushed the codex/windows-session-error-pr branch from da16537 to 08b6dd8 Compare April 30, 2026 06:24
@appergb appergb merged commit 848cfc3 into Open-Less:main Apr 30, 2026
2 checks passed
appergb pushed a commit that referenced this pull request Apr 30, 2026
包含本轮所有合并:
- Codex 终审两条 HIGH (cancel race) 修复 (PR #79)
- 6 个 Cooper-X-Oak/Codex bot PRs 自动合并 (#44 #49 #53 #68 #72 #73)
- 2 个有冲突 PR 本地 rebase 后合并 (#66 cancel + 空转写并存 / #67 Windows docs)
- README 破图修复 (PR #80)
- workflow-scope 受限的 #48 + #75 由用户在 GitHub UI 直接合并

3 处版本字段同步:package.json + tauri.conf.json + Cargo.toml
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