fix: red-team round 3 hardening across desktop, mobile, core and server

Batch of red-team r3 fixes that were in the working tree before the
2026-09-28 design overhaul, committed as one unit with their tests.

- desktop main: STT timeouts and sidecar, voice recording store, sync
  (credentials, audio, knowledge reindex, push gates), runtime
  provisioner, update policy, AltGr keybindings, voice-command policy,
  dictionary file codec/limits, meeting transcript condensing and a
  local recording ledger so interrupted-session recovery only closes
  meetings this device recorded (a phone's live meeting is left alone).
- mobile: login CSRF via implicit token callbacks rejected, account
  deletion/retention, durable queue retention, knowledge realtime
  without unfiltered DELETE, meeting re-record failure paths, cloud STT
  client, preferences store/resync.
- core: text chunking splits long unbroken transcripts to fit, template
  field policy, dictionary limits, meeting markdown inline handling.
- server: payple webhook policy and cancellation order scope, meeting
  document generation quota, team RPC null-role guard, unified LLM
  quota in-flight accounting, knowledge chunk vector index, meeting
  re-record failure paths (migrations 20260929*).
- ci: portable/runtime feed gates, update-policy schema, Forgejo file
  delete and alias planning.

Four older tests are updated to the new contracts rather than the old
behavior: token-pair auth callbacks are rejected, knowledge realtime no
longer subscribes to DELETE, long transcript lines are split, and
meeting recovery requires the local recording ledger for empty rows.
This commit is contained in:
Yun Chan 2026-09-28 20:45:52 +09:00
parent 2428ede03d
commit ba9ef9741e
161 changed files with 17056 additions and 2379 deletions

View file

@ -25,10 +25,19 @@ export const CAPTION_STREAMING_DEFAULTS = {
/** 다음 인식에 넘기는 앞 문맥 길이 (자) */
contextChars: 200,
/** 문맥 다듬기 결과가 원문에서 이 비율 이상 바뀌면 버린다 */
refineMaxChangeRatio: 0.35
refineMaxChangeRatio: 0.35,
/** 인식이 연속 실패하면 첫 재시도까지 기다리는 시간 (실패마다 두 배) */
failureBackoffBaseMs: 500,
/** 연속 실패 재시도 간격 상한 */
failureBackoffMaxMs: 8000,
/** 인식이 계속 실패하는 동안 들고 있을 오디오 상한 — 넘는 앞부분은 버린다 */
failureRetainMs: 24000
} as const
export type CaptionTickAction = 'finalize' | 'force-commit' | 'partial' | 'trim-idle' | 'wait'
/**
* - drop-overflow: 인식이 계속 실패해 버퍼가 상한을 넘었다 — 앞부분을 버린다(무한 증가·전체 재전송 방지).
*/
export type CaptionTickAction = 'finalize' | 'force-commit' | 'partial' | 'trim-idle' | 'drop-overflow' | 'wait'
export interface CaptionTickInput {
/** 확정되지 않은 오디오 길이 */
@ -41,6 +50,20 @@ export interface CaptionTickInput {
sincePartialMs: number
/** 인식이 진행 중인가 (한 트랙에 한 건만) */
busy: boolean
/** 연속 인식 실패 수 (성공하면 0). 생략하면 0 */
consecutiveFailures?: number
/** 마지막 실패 이후 지난 시간 */
sinceFailureMs?: number
}
/** 연속 실패 n 번 뒤 다음 인식까지 기다릴 시간 (지수 백오프). 실패가 없으면 0. */
export function captionFailureBackoffMs(
consecutiveFailures: number,
opts: Partial<typeof CAPTION_STREAMING_DEFAULTS> = {}
): number {
if (consecutiveFailures <= 0) return 0
const o = { ...CAPTION_STREAMING_DEFAULTS, ...opts }
return Math.min(o.failureBackoffMaxMs, o.failureBackoffBaseMs * 2 ** Math.min(consecutiveFailures - 1, 16))
}
/** 매 틱마다 무엇을 할지 정한다. */
@ -51,6 +74,13 @@ export function decideCaptionTick(
const o = { ...CAPTION_STREAMING_DEFAULTS, ...opts }
if (input.busy) return 'wait'
if (!input.hasVoice) return input.bufferMs > o.idleKeepMs ? 'trim-idle' : 'wait'
// 인식이 계속 실패하면(사이드카 다운·모델 로드 실패) 버퍼를 자르지 못한다 — 매 틱 전체 버퍼로
// 재시도하지 않고 물러서며, 상한을 넘은 앞부분은 버린다.
const failures = input.consecutiveFailures ?? 0
if (failures > 0) {
if (input.bufferMs > o.failureRetainMs) return 'drop-overflow'
if ((input.sinceFailureMs ?? Number.MAX_SAFE_INTEGER) < captionFailureBackoffMs(failures, o)) return 'wait'
}
if (input.bufferMs < o.minAudioMs) return 'wait'
if (input.sinceVoiceMs >= o.silenceCommitMs) return 'finalize'
if (input.bufferMs >= o.maxBufferMs) return 'force-commit'