← Back to Pull requests

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

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Dec 05, 2026 06:02 UTC
Author

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.

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.

    <!-- This is an auto-generated description by cubic. -->
    ---

    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.

    <sup>Written for commit d585a2055555747d2814ce14f790affa87c9cf2a. Summary will update on new commits.</sup>

    <a href="https://cubic.dev/pr/we-promise/sure/pull/6180?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a>

    <!-- End of auto-generated description by cubic. -->

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->
    <!-- coderabbit-ai-generated:v1 -->

    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.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: jjmata Review duration: 517m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #6180"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 27.7% · Safe to merge
    27.7%