feat(mcp): let update_transaction mark a transaction one-time

JU
20h ago
+186-4

Problem

MCP clients can find a transaction and change its name, notes, category, merchant and tags, but they can't mark it one-time. An assistant that has spotted a trip, a hospital bill or a large one-off purchase skewing the user's budgets has to send them to the web UI and walk them through the toggle on each transaction.

The one-time kind already exists (Transaction kind one_time, set by the toggle on the transaction page): the transaction stays in the history and in the Reports list of biggest expenses, and is left out of budget, income and spending totals. get_transactions and the transactions API already expose kind (#4422). Only the write path for assistants is missing.

Part of #3140 (user story 26: mark a transaction one-time from the assistant).

Related: #1994 (excluded versus one-time transactions). This PR doesn't depend on #1995 and keeps whatever one-time means in reports.

Change

update_transaction takes an optional one_time boolean:

  • true sets the kind to one_time, false sets it back to standard.
  • The kind goes through the same nested entryable_attributes path the web toggle uses, so entry.lock_saved_attributes! locks it against provider syncs like the other edits, and immediate rules see the change.
  • Transfer kinds (funds_movement, cc_payment, loan_payment, investment_contribution) are rejected with not_one_time_eligible instead of being reset to standard. Those kinds belong to a Transfer record and are changed through the transfer tools.
  • read_write shares can't change it, matching TransactionsController#permitted_entry_params (annotate only).
  • Non-boolean values return invalid_one_time.
  • The response now includes kind, so the client can confirm the change.

The tool description explains when to use it, so assistants pick it for unusual expenses rather than excluding them (exclude_transaction removes them from reports entirely).

Tests

Added to test/models/assistant/function/update_transaction_test.rb:

  • marks a transaction one-time and back to regular
  • marking one-time keeps category, notes and tags
  • does not mark transfer legs one-time
  • rejects a non-boolean one_time
  • does not let read-write collaborators change one-time

Validation

  • bin/rails test test/models/assistant/function/update_transaction_test.rb: 12 runs, 0 failures.
  • bin/rails test (full suite): 21063 runs, 11 failures/errors, none in code this PR touches. All are from the local environment, not the change: 9 pass once this machine's proxy and ANTHROPIC_BASE_URL variables are unset, 1 (AiNetworkPolicyTest) passes with a UTF-8 locale, and 1 (Provider::OpenaiTest Ruby-style inspect) expects Ruby 3.4's Hash#inspect. The suite ran on Ruby 3.3.6 because 3.4.13 wasn't available here; CI covers 3.4.13.
  • bin/rubocop on the changed files: no offenses.
  • bin/brakeman --no-pager: no warnings.
  • No ERB, JavaScript or UI changes, so ERB lint, Biome and system tests don't apply.

Not in this PR

A rule action "Set as one-time". It would need a new Rule::ActionExecutor and is a separate change.


Summary by cubic

Lets MCP clients mark a transaction as one-time through the update_transaction tool, so assistants can flag unusual expenses like trips or hospital bills without sending users to the web UI.

update_transaction now takes an optional one_time boolean. true sets the kind to one_time (kept in transaction history and the Reports biggest-expenses list, but left out of budget, income, and spending totals); false resets it to standard. The change goes through the same nested entry path as the web toggle: the kind is locked, the entry is marked user-modified so provider syncs keep it, and the kind is re-checked under a row lock so a concurrent transfer or split committed since the first check is seen. Split parents and transfer kinds are rejected (split_parent, not_one_time_eligible), read_write shares can't change it, and non-boolean values return invalid_one_time. The response now includes kind.

Summary by CodeRabbit

  • New Features
    • You can now mark eligible transactions as one-time or change them back to standard. Categories, notes, and tags are preserved when changing a transaction’s kind, and the updated kind is included in the response.
  • Bug Fixes
    • One-time status changes are limited to supported transactions, and invalid values are rejected. Read-write collaborators cannot change a transaction’s name or one-time status. Changes are also rejected if a transaction is no longer eligible.