Skip to content

sessionId-to-recording resolution is copied in five places, and the copies have drifted #395

Backlog

Description

@TMHSDigital

Summary

resolveRecording and resolveSource are near duplicates, and three more inline copies (review_recording, chapters, read_events) skip whenFinalized and the file-exists check. A tool called right after stop_recording can read a recording that is still being finalized.

Where

  • src/utils/recordingIndex.ts:609-627
  • src/utils/bugReport.ts:314-330
  • src/tools/reviewRecording.ts:40-49
  • src/tools/chapters.ts:87-94
  • src/tools/readEvents.ts:66-82
  • src/utils/finalizers.ts:21-25

Details

resolveRecording (recordingIndex.ts:609) and resolveSource (bugReport.ts:314) are nearly identical. Both look up the session, refuse a live one, await whenFinalized(record.id), check that the file exists, and pick up the event log; one also returns markers, the other the record. Three more inline copies leave steps out. reviewRecording.ts:40-49, chapters.ts:87-94 and readEvents.ts:66-82 never call whenFinalized and never check that the file exists. readEvents and chapters accept both input and sessionId (chapters: input ??= record.outputPath), while resolveRecording rejects that ("Provide exactly one of"). Error wording differs too: "stop it first" vs "stop_recording it first". finalizers.ts:6-8 explains why the wait exists: the event log, app logs and perf "finish converting after ffmpeg exits".

Impact

Every tool that accepts sessionId reimplements the lookup, and fixes do not reach all copies: the finalize wait was added to two of five. read_events, chapters and review_recording on a session that ended without stop_recording (max duration, closed window, stopWhen, a hotkey) can read an event log or markers before finalization ends, so they see a missing file or a partial one. Each new session-aware tool is a sixth copy. The same goes for the 15 tool files that handle sessionId.

Steps to reproduce

Static. Start a recording with events: true, maxDurationSec: 3. Call read_events with that sessionId right after the status turns stopped, while the event finalizer from startRecording.ts:391 is still running. read_events does not wait on whenFinalized, so it can report "No event log at ...". Timing-dependent; not reproduced live.

Suggested fix

Incremental plan. Step 1: move one resolveSessionMedia(args, { allowBoth?: boolean }) into src/utils/sessionSource.ts, returning { path, eventsPath, markers, record? } and built from resolveRecording. Make resolveRecording and resolveSource thin wrappers so nothing else changes. Step 2: switch bug_report, step_guide, index_recording and search_recording to call it directly, then delete the wrappers. Step 3: switch review_recording, chapters and read_events one at a time. Each adopts the finalize wait and the existence check. Keep chapters' "input overrides sessionId" behind allowBoth if it is intended. Tests first: a unit test per caller with a fake store, covering a live session, a missing file, and a pending finalizer (resolution must wait for trackFinalizer's promise). Pin the error messages so the wording can be unified on purpose.

Acceptance criteria

  • One shared resolver is used by all five call sites
  • Every sessionId path waits for whenFinalized and checks that the file exists
  • Error wording is the same everywhere

Getting started

  • Relevant files: src/utils/recordingIndex.ts, src/utils/bugReport.ts, src/tools/reviewRecording.ts, src/tools/chapters.ts
  • Run tests: npm test (also npm run typecheck and npm run lint); see CONTRIBUTING.md
  • If you change a tool's schema or description, run npm run docs

Filed by repo-audit/full-audit at f0e5ebd. Severity: medium. Effort: S. audit-key: tech-debt|src/utils/recordingIndex.ts|resolveRecording

Activity

  1. added
    effort: small
    tech-debt
    on Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort: smallpriority: mediumtech-debt

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions