Skip to content

Protect unsaved voucher content from MCP draft replacement - #139

Merged
perNyfelt merged 5 commits into
mainfrom
fix/126-protect-unsaved-voucher-drafts
Nov 13, 2026
Merged

perNyfelt merged 5 commits into
mainfrom
fix/126-protect-unsaved-voucher-drafts

Conversation

@perNyfelt

@perNyfelt perNyfelt commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

MCP clients could silently discard a voucher the user was composing by staging the next proposal. set_active_voucher_draft now refuses to replace meaningful unsaved content unless replace_unsaved: true is explicitly supplied. Refusals return ok: false, error_code: unsaved_changes, and has_unsaved_changes: true.

The check and replacement run together on Swing's event thread. Protection covers descriptions, incomplete lines, attachments, text in active cell editors, drafts retained while browsing saved vouchers, and deliberate date/series changes compared with the blank editor's initial values. That baseline is remembered with the draft and restored across browsing, including vouchers in other series. Empty active cell editors and unchanged defaults count as blank. Explicit replacement cancels any active cell edit.

get_active_voucher_draft leaves the editor untouched. The editing flag appears only at the top level. When editing: true, returned lines contain committed model values and exclude in-progress cell text. has_unsaved_changes is true/false when known and null when the editor or snapshot is unavailable. An empty editor returns error_code: no_draft. Unexpected read failures are logged and return a neutral tool error directing the client to the application log; parameter errors on writes retain the existing JSON-RPC invalid-parameters behavior. Amount parsing has a friendly fallback instead of raw JDK messages. Tool and skill documentation describe these responses.

SwingThreading.runOnEdt now propagates all RuntimeExceptions from the EDT unchanged, where previously only IllegalArgumentException was unwrapped. This preserves the distinction between validation errors and state conflicts. The description label now references its input through labelFor, improving accessibility and allowing tests to locate the field semantically.

Validation: ./gradlew spotlessApply, ./gradlew codenarcMain codenarcTest, targeted voucher draft/MCP tests, and ./gradlew build passed. Full suite: 837 tests, zero failures, 11 skipped. Regression coverage includes reading partially typed accounts/amounts without model events, empty active editors, deliberate date/series changes, structured refusal fields, unavailable/read-error paths, amount errors, EDT execution, attachments, and retained drafts. Cross-series Prev/Next tests verify both blank drafts and deliberate date/series choices, including repeated returns.

No schema or migration changes; no visible UI layout changes.

Closes #126.

@perNyfelt
perNyfelt merged commit 6637d37 into main Nov 13, 2026
3 checks passed
@perNyfelt
perNyfelt deleted the fix/126-protect-unsaved-voucher-drafts branch November 13, 2026 20:19
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.

MCP set_active_voucher_draft silently discards unsaved editor content - refuse unless replace_unsaved is set

1 participant