Skip to content

fix: ask before registering a recording whose surgery was not registered - #58

Merged
tabedzki merged 3 commits into
mainfrom
t3/confirm-surgery-registration
Dec 1, 2026
Merged

tabedzki merged 3 commits into
mainfrom
t3/confirm-surgery-registration

Conversation

@tabedzki

@tabedzki tabedzki commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

🤖 AI text below 🤖

Fixes #56

Follows #51 (merged). Stacked on #57: merge that first (it changes the same registerSurgery catch block); GitHub then retargets this PR to main.

Problem

With "Add surgery & insertion device if missing ?" checked, createRecording opens the surgery dialog (addSurgeryData, blocked on uiwait) and then carries on whatever happened there:

  • If the surgery insert fails, registerSurgery shows "Surgery data could not be registered" and closes the dialog. Nothing is reported to Slack.
  • If the user closes the dialog (Cancel or the window's close button), nothing is inserted.

In both cases createRecording goes on to move the files to cup with copyRecording (ROBOCOPY /MOV, so the local copies are deleted) and registers the recording without a surgery. Nobody is told.

Fix

  • The surgery dialog records how it ended in app.AllSurgeryStuff.outcome. createComponentsSurgeryFigure starts it as 'closed'. registerSurgery sets 'registered' after the commit, or 'failed' as the first line of its catch. It closes the surgery figure after the try, so nothing after the commit can turn a registered surgery into a failed one. addSurgeryData now returns it, and the classdef declaration is updated to match.
  • registerSurgery reports a failed insert to Slack through notifySlackJobFailure('Surgery registration', ...), the same way createRecording, CreateNewJob and RerunJob report their failures. The context lists system, modality, subject, user, surgery date and device count. It no longer shows its own error dialog: that uiconfirm did not wait, so the prompt below could open on top of it. The error is kept in app.AllSurgeryStuff.error_message and shown in the prompt instead.
  • New repo-root helper confirmRecordingWithoutSurgery(subject, outcome, askFcn, error_message). If the surgery was registered it returns true without asking. Otherwise it tells the operator why (the insert failed, with its error, and was reported to Slack; or the dialog was closed) and asks Register without surgery / Cancel. Cancel is the default, closing the prompt also counts as Cancel, and any other answer stops. An unknown outcome is an error, which lands in createRecording's existing "Recording preparation" catch, so it also stops before the move.
  • createRecording calls it right after the surgery dialog, inside the preparation try and before copyRecording. On Cancel it re-enables the button, sets the GUI back to "Ready" and returns. Nothing has been moved or written at that point.
  • The registerSurgery rollback goes through fix: never let a failed rollback skip the write callbacks' error handling #57's cancelOpenTransaction. The vendored toolboxes and dj_local_conf.json are untouched.

Screenshots

The prompt createRecording shows before any file is moved, when the surgery insert failed:

Surgery not registered, insert failed

and when the surgery dialog was closed:

Surgery not registered, dialog closed

Rendered in MATLAB R2023b by calling the PR's code with a stand-in figure, not on a rig. confirmRecordingWithoutSurgery built the text; the error is an example.

Tests

  • New tests/TestRecordingWithoutSurgery.m, added to CI, AGENTS.md and README.md. It needs no DB and no GUI, because the prompt is a stub:
    • confirmRecordingWithoutSurgery doesn't ask when the surgery was registered. It asks, naming the subject and the reason, for 'failed' and 'closed'. Cancel is the default and the cancel option. Cancel, closing the prompt and unexpected answers ('', [], cells, wrong case, string arrays) all stop. Only the exact proceed option (char or string) goes ahead. Unknown outcomes are an error, and string inputs are accepted. A failed insert's error appears in the prompt as given (including %), and a closed dialog shows no error.
    • All 14 tests fail on 8bd2fb5c, where the helper doesn't exist.
  • All MATLAB suites pass (80 tests, with fix: never let a failed rollback skip the write callbacks' error handling #57) and test_jsonencodepretty passes, on R2023b. The RecordingProcessJobGUI class still loads, and addSurgeryData declares the outcome output. uvx prek run --all-files passes.

Not tested: a real registration through the GUI on a rig (dialog closed, insert failed, then Cancel and proceed), or a real Slack post from registerSurgery.

Assisted-by: ClaudeCode:claude-opus-5-5

With "Add surgery & insertion device if missing ?" checked, createRecording
opened the surgery dialog and then carried on whatever happened there. A
failed surgery insert, or a dialog closed without registering, still moved
the files to cup (ROBOCOPY /MOV, local copies deleted) and registered the
recording without a surgery. The failed insert only showed a dialog and was
not reported to Slack.

- The surgery dialog now records how it ended (registered, failed or
  closed), and addSurgeryData returns it.
- registerSurgery reports a failed insert to Slack through
  notifySlackJobFailure, like the other write callbacks.
- When the surgery was not registered, createRecording asks the operator
  (confirmRecordingWithoutSurgery) whether to register the recording without
  it, before any file is moved. Cancel, the default, stops there and frees
  the button again.

Whether a missing surgery should block the recording is still open, so
this does not block it.

Fixes #56

Assisted-by: ClaudeCode:claude-opus-5-5
They grepped createRecording, registerSurgery and the surgery dialog for
specific wording, so they broke on harmless rewording. The remaining tests
cover confirmRecordingWithoutSurgery itself.

Assisted-by: ClaudeCode:claude-opus-5-5
…swer

The error uiconfirm in registerSurgery has no output, so it does not wait.
The figure closed at once and createRecording opened its 'Surgery not
registered' prompt on the same figure, which could cover the error. The
prompt now shows the error itself, and registerSurgery only keeps it.

registerSurgery also closes the surgery figure after the try, so nothing
that runs after the commit can turn a registered surgery into a failed one.

Assisted-by: ClaudeCode:claude-opus-5-5
@vrrigs
vrrigs force-pushed the t3/confirm-surgery-registration branch from d8ba6bf to 10a6d5e Compare December 1, 2026 21:15
@tabedzki
tabedzki marked this pull request as ready for review December 1, 2026 21:58
Base automatically changed from t3/handle-rollback-failures to main December 1, 2026 22:18
@tabedzki
tabedzki merged commit f4651f4 into main Dec 1, 2026
7 checks passed
@tabedzki
tabedzki deleted the t3/confirm-surgery-registration branch December 1, 2026 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A failed or skipped surgery registration still moves and registers the recording

1 participant