Files
SubMiner/backlog/tasks/task-75 - Move-mpv-osd-log-writes-to-buffered-async-path.md
sudacode 7e1a7df403 perf(main): buffer MPV OSD log writes asynchronously
Move OSD log appends off sync fs calls to reduce main-process blocking under frequent OSD activity. Add buffered flush wiring into quit cleanup so pending log lines are drained best-effort during shutdown.
2026-02-21 21:27:31 -08:00

3.5 KiB

id, title, status, assignee, created_date, updated_date, labels, dependencies, priority
id title status assignee created_date updated_date labels dependencies priority
TASK-75 Move mpv OSD log writes to buffered async path Done
2026-02-18 11:35 2026-02-21 23:48
logging
performance
main-process
low

Description

appendToMpvLog in src/main.ts uses synchronous fs operations on OSD writes. Frequent OSD activity can block the event loop and adds avoidable latency in main process runtime paths.

Action Steps

  1. Replace sync file writes with buffered async logger flow.
  2. Ensure log directory creation and write failures remain best-effort (non-fatal).
  3. Add flush behavior for shutdown to avoid dropping trailing log lines.
  4. Keep log format/path unchanged unless explicitly intended.
  5. Add tests for non-blocking behavior and graceful error handling.

Acceptance Criteria

  • #1 OSD log path no longer uses synchronous fs calls
  • #2 Logging remains best-effort and does not break runtime behavior on fs failure
  • #3 Shutdown flush behavior verified by tests

Implementation Plan

  1. Add failing tests for buffered async MPV OSD log behavior + explicit flush semantics in mpv-osd runtime tests.
  2. Replace sync mpv-osd log deps/handler with buffered async queue/drain implementation and expose flushMpvLog runtime surface.
  3. Wire flushMpvLog into onWillQuit cleanup deps/action path and main.ts runtime composition.
  4. Add shutdown-flush assertions in lifecycle cleanup tests.
  5. Run bun run build && bun run test:core:dist, then record AC/DoD evidence and finalize task metadata.

Implementation Notes

2026-02-21: Started execution in codex session codex-task75-mpv-osd-buffered-20260221T231816Z-yj32. Running writing-plans then executing-plans workflow; no commit requested.

Implemented buffered async MPV OSD log path in src/main/runtime/mpv-osd-log.ts with queued drains and explicit flushMpvLog() surface; removed sync fs dependency usage from runtime wiring in src/main.ts.

Wired shutdown flush into startup lifecycle cleanup via flushMpvLog dependency in app-lifecycle-main-cleanup + app-lifecycle-actions so quit cleanup invokes pending log drain before socket destroy.

Added/updated tests for async queueing, best-effort fs failures, runtime composition flush surface, and shutdown cleanup flush invocation across mpv-osd and lifecycle runtime tests.

Verification: bun run test:core:src PASS (219 pass, 0 fail); focused runtime tests PASS via bundled node lane: bun build ... --outdir /tmp/task75-tests && node --test /tmp/task75-tests/*.js.

bun run build currently fails on pre-existing unrelated tokenizer typing issue at src/core/services/tokenizer.ts (Logger not assignable to LoggerLike).

Final Summary

Moved MPV OSD log writes off sync fs APIs by introducing buffered async queue/drain behavior with explicit flush support and preserving best-effort failure semantics. Integrated shutdown flush into on-will-quit cleanup and added targeted runtime/lifecycle tests to verify queue flush + quit-time drain behavior without user-visible OSD regression.

Definition of Done

  • #1 Core tests pass with new logging path
  • #2 No user-visible regression in MPV OSD/log output behavior