Files
lg-smtv-mcp/docs/adr/0004-sequenced-temp-captures-with-cleanup-and-sweep.md
kiskaadee b41a721086
Core Architecture & Invariant CI / validate (push) Successful in 16s
docs(reconcile): align M1/M2 docs with merged capture slice
Reconcile repository documentation with the merged M2 capture
implementation (#12 / PR #15, merge commit c7e2618) and its review
remediation (61d2315, CR-01..CR-11). Resolves the CR-10 follow-up.

- README.md: flip status banner, component table, capture channel,
  M2 milestone row, requirements, and doc index from "planned" to
  implemented; scope the remaining M2 work to #13.
- ARCHITECTURE.md: extend scope to M1 + M2 capture; replace the
  dashed "None in M1" FrameCapturer seam with the real
  TvManager -> CaptureClient -> AsyncSshCaptureTransport edge; add a
  capture component row, correct data-flow step 3, document the
  Developer Mode SSH/SFTP device boundary and known_hosts policy, and
  record the 6.0s + 1.5s capture budget as a constraint.
- ROADMAP.md: update Current Direction; reduce Near Term to #13 and
  #17; add a "M2: Capture & E2E Hardening (partial)" Completed
  section covering #11 (PR #14) and #12 (PR #15).
- docs/designs/lg-smtv-mcp.md: drop all five planned markers; correct
  the sweep_temp_files signature to include `exclude`; fix the
  returnValue contract to "exactly True" -> otherwise
  SCREENSHOT_UNAVAILABLE (was: false -> COMMAND_FAILED); document the
  in-flight capture sweep exclusion; restructure the M2 plan into
  "Completed Milestone M2 Slices" so only #13 remains active; add a
  Last reconciled line.
- docs/adr/0003: status -> implemented in M2 #12 / PR #15.
- docs/adr/0004: status -> implemented, plus a dated Amendment
  (2026-11-16) recording CR-01's in-flight sweep exclusion and its
  rationale (the transport connects lazily after the capture request,
  so an unconditional sweep would delete the frame about to be read).
2026-11-16 23:35:09 -05:00

2.0 KiB
Raw Permalink Blame History

ADR-0004: Sequenced Temp Captures with Cleanup and Sweep

  • Status: Accepted (implemented in M2 #12 / PR #15; amended 2026-11-16)
  • Date: 2026-11-15
  • Deciders: kiskaadee

Context and Problem Statement

ssap://com.webos.service.capture/executeOneShot writes screenshots to a path on the TV's /tmp filesystem (~1.2 GB RAM). Writing to a fixed path risks reading stale frames on silent failure, while uncleaned unique paths can exhaust TV RAM.

Decision Outcome

Chosen option: "Capture to /tmp/lg_smtv_cap_<seq>.jpg, pull bytes into memory only on returnValue: true, delete via finally: sftp.remove() under a 1–2s grace period, and sweep /tmp/lg_smtv_cap_*.jpg on SFTP connect/reconnect", because it prevents both stale-frame reads and /tmp memory exhaustion.

Consequences

  • Positive: Guarantees fresh frame reads per sequence number and bounds /tmp usage even when captures fail or time out.
  • Negative: Requires a 6s shared capture deadline plus 1–2s cleanup grace inside the 25s ui_lock budget.

Alternatives Considered

  • Fixed /tmp/test.jpg overwrite path: Rejected because if executeOneShot fails silently or races, SFTP pull can read a stale screenshot from an earlier step.

Amendment (2026-11-16)

PR #15 review (CR-01) found that sweeping unconditionally on a new SFTP session deletes the screenshot executeOneShot has just written, because the transport connects lazily after the capture request. The decision above stands, with one refinement: sweep_temp_files accepts exclude: str | None, and _ensure_sftp passes the in-flight remote_path, so a session sweep removes only stale captures left by earlier sessions or crashes. Guarded by test_async_ssh_capture_transport_sweep_preserves_in_flight_remote_path.