Deleting an instrument record leaves an orphaned session, and no endpoint can delete a session

Open
#1,883 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
1-2 days
Newbie friendliness
53/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
node.js, typescript

Research direction

Start with apps/api/src/instrument-records/instrument-records.service.ts and SessionsController to trace record deletion, session references, and the existing session routes. The issue lists three possible approaches but does not choose one; clarify the intended scope and check the relevant tests before making a change. Done means preventing or removing orphaned sessions as agreed, while preserving sessions that still have records.

Written by the indexing model from the issue text.

Description

Area: API Bug Difficulty: Medium Needs Decision Priority: Medium

Problem

Deleting an instrument record leaves its session in the database, and no endpoint can delete a session.

  • InstrumentRecordsService.deleteById (apps/api/src/instrument-records/instrument-records.service.ts) deletes the record and its files only.
  • SessionsController has only POST /sessions and GET /sessions.
  • The only path that deletes sessions is DELETE /subjects/:id?force=true, which deletes the whole subject.

Every session created by the bulk upload or by a form holds exactly one record, so each record delete leaves an empty session. These sessions:

  • count toward GET /summary counts.sessions and its trend,
  • appear in the session list and the subject's session history,
  • cannot be removed by an admin without direct database access.

Observed

On a production instance (v2.5.2), a cleanup of about 26,000 duplicate bulk-uploaded records through DELETE /instrument-records/:id would leave about 26,000 empty sessions. Before any cleanup, that instance already has 79 sessions with no record.

Options

  1. In deleteById, also delete the record's session in the same transaction when no other record references it.
  2. Add DELETE /sessions/:id (@RouteAccess({ action: 'delete', subject: 'Session' })), rejected while the session still has records.
  3. Both.

Option 1 stops new orphans. Option 2 (or a one-off migration) is still necessary to remove the sessions that are already orphaned.

Dominant language
TypeScript
Stars
119
Forks
19
Avg merge
1d 18h
Merged PRs (30d)
61

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from DouglasNeuroInformatics/OpenDataCapture

All issues in DouglasNeuroInformatics/OpenDataCapture

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.