LibreChat/api/db
Danny Avila 3f2e4777cb
🛬 fix: Land MCP OAuth Callbacks on Waiting Connections (#15876)
* 🪪 fix: Adopt MCP OAuth Callback Tokens Without Re-Prompting or Losing the Lease

A chat request loading OAuth tokens joins the `mcp_get_tokens` flow a catalog
discovery left behind and polls it. The OAuth callback deletes that entry when
it stores the new tokens, so the poll ends with "Flow state not found", the
factory reports the tokens missing, drops the `mcp_oauth` flow the callback
just completed, and starts a second interactive flow. Once tokens arrive, the
connection leases the publication generation it captured before the wait; the
callback's publication moved it, so the connection is torn down as it connects
and the agent fails with AGENT_EXPECTED_MCP_TOOLS_UNAVAILABLE.

`createFlowWithHandler` now serves a completed result at once, monitors only
pending attempts and retained failures, and replaces a failure nobody retains;
a waiter whose flow disappears gets `FlowStateNotFoundError`. The factory
treats that as a credential change: it re-reads storage once, after letting
the connection build re-capture its generation. The authorization transaction
and a silent refresh attach the generation they publish to the tokens they
release, and a build adopts that generation for credentials obtained after
its capture.

* 🪪 fix: Claim Flow Attempts Atomically and Lease Under the Stored Generation

A connection now adopts a carried publication generation only while it is the
generation currently stored, instead of comparing the token's exchange time to
its capture, so a callback that exchanged before the build began and published
after it is still adopted and a retired generation still leaves the fence in
place. Installing a flow attempt is an atomic compare-and-set against the
attempt the caller observed, on Redis and on the default in-memory store, so
concurrent replacements of a failed attempt, or concurrent creations of an
absent one, run one handler while the rest join it. An aborted caller is
rejected before a cached result is served, and a joiner that aborts leaves the
shared flow to its owner and the other waiters.

* 🪪 fix: Return Generation-Tagged Callback Tokens and Route Flow Claims Through the Cluster Executor

The authorization transaction now returns the same generation-tagged tokens it
releases to the OAuth completion and the pending token waiters, so the callback
route's tool-flow completion carries the published generation to the connection
waiting on it. The Action OAuth and index-sync flow managers pass the
cluster-aware Redis script executor, so their flow claims and guarded
settlements route through slot-master selection and READONLY recovery instead
of the raw client.
2026-09-13 01:46:41 -04:00
..
connect.js 🈳 fix: Treat Blank Mongo Index Settings as Unset (#15809) 2026-09-09 23:24:18 -04:00
index.js
index.spec.js
indexSync.js 🛬 fix: Land MCP OAuth Callbacks on Waiting Connections (#15876) 2026-09-13 01:46:41 -04:00
indexSync.spec.js 🐇 refactor: Decouple Meilisearch From Document Saves (#15109) 2026-08-21 22:26:44 -04:00
models.js
utils.js
utils.spec.js