Files read back from disk are cast to their types instead of validated

Đang mở
#502 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
56/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
backend, data

Hướng nghiên cứu

Start by reading the listed readers in src/utils/sessions.ts, src/utils/recordingIndex.ts, src/utils/perf.ts, src/utils/logTail.ts, and src/utils/events.ts, then trace how their parsed records are consumed. Run npm run build && npm test to establish the current behavior. Add boundary validation that drops malformed entries and check the event log’s optional typed fields; done means the acceptance criteria hold and the tests pass.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

effort: medium priority: low tech-debt

Summary

Files read back from disk are cast to their types instead of validated. These files are documented as readable from caller-written or older-version sources (stem-keyed sidecars, logs "a caller wrote"). A record or line with the wrong shape surfaces later as a TypeError far from the read (for example "s.ocr is not iterable" in search_recording) or as NaN in summaries, instead of being skipped at the boundary the way a torn line is. For sessions.json a single non-object entry makes the whole registry count as corrupt.

Where

  • src/utils/sessions.ts:207
  • src/utils/recordingIndex.ts:359
  • src/utils/recordingIndex.ts:436
  • src/utils/perf.ts:128
  • src/utils/logTail.ts:96
  • src/utils/events.ts:266

Details

parseDisk is JSON.parse(...) as SessionRecord[] followed by data.map((r) => [r.id, r]). parseIndex checks only version, that segments is an array, and that fingerprint is truthy, yet itemsOf iterates s.ocr of every segment. parsePerfJsonl and the log reader push JSON.parse(row) as PerfSample / as LogLine. Only the event log has a real check (normalizeEvent, added in #437 for caller-written logs), and it validates t, type, x, y but spreads the other fields (durationSec, keys, button, delta) through unchecked.

Impact

These files are documented as readable from caller-written or older-version sources (stem-keyed sidecars, logs "a caller wrote"). A record or line with the wrong shape surfaces later as a TypeError far from the read (for example "s.ocr is not iterable" in search_recording) or as NaN in summaries, instead of being skipped at the boundary the way a torn line is. For sessions.json a single non-object entry makes the whole registry count as corrupt.

How to see it

Put {"version":<INDEX_VERSION>,"fingerprint":{},"segments":[{"start":0,"end":1}]} next to a recording as its index and run search_recording on it.

Suggested fix

Give each reader a small normalize* like normalizeEvent (or a zod schema; zod is already a dependency): drop entries that fail, and in parseDisk filter to objects with a string id and a known status. Check the optional typed fields in normalizeEvent.

Acceptance criteria

  • Each step of the plan lands on its own with the tests passing
  • No behavior change

Getting started

  • Relevant files: src/utils/sessions.ts, src/utils/recordingIndex.ts, src/utils/perf.ts, src/utils/logTail.ts, src/utils/events.ts
  • How to run tests: npm run build && npm test (also npm run typecheck and npm run lint)
  • Related docs: CONTRIBUTING.md, AGENTS.md

Filed by repo-audit/full-audit at b8156ef. Severity: low. Effort: M. audit-key: tech-debt|src/utils/sessions.ts|SessionStore.parseDisk

Ngôn ngữ chính
TypeScript
Star
1
Fork
4
Merge trung bình
3 ngày 4 giờ
Pull request đã merge (30 ngày)
4

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của TMHSDigital/screencast-mcp

Tất cả issue của TMHSDigital/screencast-mcp

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.