fix: ASRX legacy 檔無 status 時推導 has_transcript + 補 segment_count
Core Test / lint-and-test (push) Has been cancelled
Cross-Project Integration / integration (push) Has been cancelled

- AUTO-REPAIR: asrx.json 無 status 但有 segments → 推導 has_transcript 並回寫
- 修正 has_transcript 被誤映射為 SilentAudio 的 bug
- segment_count 正確帶入
This commit is contained in:
Accusys
2026-11-19 12:54:26 +08:00
parent 3a6f9b0044
commit 3d56151787
+27 -5
View File
@@ -1154,6 +1154,7 @@ impl JobWorker {
);
// Special handling for ASR: read status from output JSON
// Fallback: if no status field but has segments, infer "has_transcript"
let mut asr_status_value: Option<String> = None;
if processor_type == crate::core::db::ProcessorType::Asrx {
if let Ok(json_str) = std::fs::read_to_string(&output_path) {
@@ -1164,6 +1165,26 @@ impl JobWorker {
"[AUTO-REPAIR] ASR status from file: {}",
status
);
} else {
// Legacy file without status: infer from segments
let seg_count = json_val.get("segments")
.and_then(|s| s.as_array())
.map(|a| a.len())
.unwrap_or(0);
if seg_count > 0 {
asr_status_value = Some("has_transcript".to_string());
info!(
"[AUTO-REPAIR] ASR status inferred from {} segments: has_transcript",
seg_count
);
// Backfill the status into the JSON file
let mut patched = json_val.clone();
patched["status"] = serde_json::Value::String("has_transcript".to_string());
patched["segment_count"] = serde_json::Value::Number(seg_count.into());
if let Ok(updated) = serde_json::to_string_pretty(&patched) {
let _ = std::fs::write(&output_path, updated);
}
}
}
}
}
@@ -1182,12 +1203,13 @@ impl JobWorker {
crate::core::db::ProcessorType::Asrx => {
// Update asr_status from JSON
if let Some(asr_status) = asr_status_value.clone() {
let status_enum = match asr_status.as_str() {
"no_audio_track" => crate::core::processor::AsrStatus::NoAudioTrack,
"silent_audio" => crate::core::processor::AsrStatus::SilentAudio,
_ => crate::core::processor::AsrStatus::SilentAudio,
let (status_enum, seg_count) = match asr_status.as_str() {
"no_audio_track" => (crate::core::processor::AsrStatus::NoAudioTrack, 0),
"silent_audio" => (crate::core::processor::AsrStatus::SilentAudio, 0),
"has_transcript" => (crate::core::processor::AsrStatus::HasTranscript, 1),
_ => (crate::core::processor::AsrStatus::SilentAudio, 0),
};
if let Err(e) = self.db.update_asr_status(result_id, &status_enum, 0).await {
if let Err(e) = self.db.update_asr_status(result_id, &status_enum, seg_count).await {
warn!("[AUTO-REPAIR] Failed to update asr_status for {}: {}", job.uuid, e);
} else {
info!("[AUTO-REPAIR] Updated asr_status to '{}' for {}", asr_status, job.uuid);