fix: serialize default assistant tool updates (v5.0 backport)

Merged
WE
16h ago
+514-246

Description

Serialize default Chat tool changes so concurrent updates preserve other selections. This prerequisite supplies the shared database locking helper used by the MCP transaction backport.

Manual cherry-pick of #16336 from main (c7f9a0e8592f7d78b5a4841f394fd4982bd82084). The original stack merged on main; its automatic release backport did not run. This cherry-pick applied without code changes.

This is the prerequisite for the five MCP backports: #16414, #16417, #16418, #16419, and #16413.

How Has This Been Tested?

Validated the complete backport stack on release/v5.0:

  • 202 frontend component tests passed across MCP configuration, authentication, setup, default Chat, and OpenAPI plugins.
  • 353 backend MCP, route-contract, and OpenAPI availability tests passed.
  • Changed-file pre-commit checks passed, including Python and TypeScript typing, coverage, lint, formatting, translations, and feature-map integrity.
  • PostgreSQL setup and locking tests could not start: local PostgreSQL refused connections on port 5432.
  • Live provider OAuth was not rerun locally. Release CI will run on this PR.

Additional Options

  • [Optional] Please cherry-pick this PR to the latest release version.

Summary by cubic

Backports the fix for races between concurrent writers of the default assistant's tool list. This is a manual cherry-pick of #16336 (the automatic release backport did not run) and is the prerequisite for the five MCP transaction backports.

Bug Fixes

  • All writers now lock the default persona row; the full-list update changes persona__tool rows with core SQL, so concurrent deletes no longer fail with StaleDataError.
  • Custom tool create and update routes take the persona lock before saving the tool, sharing one lock order with selection writes so the two cannot deadlock.

New Features

  • Adds PATCH /admin/default-assistant/tools with {tool_ids, enabled}, which only adds or removes the given tools, and switches MCP enable, plugin forms, Chat Preferences toggles, and the e2e helper to it.
  • Errors from the default assistant router now surface as OnyxError instead of HTTPException, and the full-list PATCH /admin/default-assistant still works.