Skip to content

Session/recording robustness: event-log overwrite, recycled server pid, stale-lock race, find_text regex #185

Closed

Description

@TMHSDigital

Why it matters

Several smaller robustness gaps can leave recordings or the session registry in a bad state. None of them is common, but each is silent when it happens.

  1. The event log ignores overwrite. With events: true, start_recording writes <base>.events.jsonl and appends to <base>.events.raw without checking the existing-file protection that applies to output (Enhancement: tools silently overwrite an existing output path #37).
    • src/tools/startRecording.ts:176 (eventPaths(output)); the writeFileSync in src/utils/events.ts:314.
  2. A recycled server pid keeps a crashed record "recording" forever. isForeignLiveRecording trusts isAlive(serverPid), which also returns true on EPERM, so a crashed server's pid that has been reused by any other process makes the record look foreign and live. pruneRecords never prunes active records, so list_sessions shows a phantom recording indefinitely.
    • src/utils/sessions.ts:94-114, :407.
  3. Stale-lock takeover race. Two waiters can both judge the lock stale. A unlinks it and takes it, then B unlinks A's fresh lock and takes it too, so both run the read-merge-write at once and one update is lost.
    • src/utils/sessions.ts:240-246.
    • sleepSync (Atomics.wait) also blocks the event loop for up to about 3 s.
  4. find_text runs a user regex on the main thread. new RegExp(query, "gi") with matchAll (src/utils/ocr.ts:142). A catastrophic pattern such as (a+)+$ freezes the whole server, including stop_recording and the shutdown handlers. Local trust model, so this is hardening rather than a vulnerability.

Suggested approach

  1. Run the event sibling paths through the same overwrite check as output.
  2. Record the owner's process image and start time, and check both instead of the pid alone.
  3. Take over a stale lock by renaming it to a unique name and re-checking, and shorten the synchronous waits.
  4. Cap the query length and run the match with a time budget (or in a worker).

Done when

Each item has a fix and a unit test.

Activity

  1. added
    enhancement
    priority: low
    effort: medium
    impact: low
    on Oct 25, 2026
  2. TMHSDigital commented on Oct 25, 2026

    @TMHSDigital
    OwnerAuthor

    One more registry race for this issue. SessionStore.update (src/utils/sessions.ts:357-363) builds { ...cur, ...patch } from this instance's in-memory snapshot, and the dirty overlay (:321-323) then replaces the copy on disk. So if instance A's recording ends at max_duration and A writes endReason and the events summary, a later stop_recording from instance B, whose snapshot still says "recording", erases those fields. Fix: inside the lock, apply the patch to the record as it currently is on disk.

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: mediumenhancementimpact: lowpriority: low

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions