Rebuild tool catalogs by upsert-then-prune so reads never see an emptied catalog - #2125
Open
ian-pascoe wants to merge 1 commit into
Open
ian-pascoe wants to merge 1 commit into
ian-pascoe wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Tool-catalog rebuilds used to delete every
toolanddefinitionrow for a connection and then re-insert them. D1 has no interactive transactions (interactiveTransactions: false), so each statement commits on its own:cloudflare_comcatalog with 42 of 3600 tools.The rebuild is now upsert-then-prune:
created_atnow means "first seen");Definitions are written before the tools that
$refthem and pruned after the tools that stop referencing them. Rows go in calls bounded by serialized size: fumadb runs a multi-statement D1 upsert as one native batch, and Cloudflare's catalog (37 MB) exceeded D1's 32 MiB RPC limit (#2123). The empty-catalog clears and removal cascades are unchanged.Related: #2122, #2123.
Verification
New
catalog-persist.test.tsruns rebuilds on the D1 adapter options, with an adapter proxy that pauses or fails writes and enforces a scaled-down batch payload cap:toolwrite still sees the full previous catalog; afterwards, added, removed and updated tools and definitions are exact and the connection is stamped;All four fail against the previous implementation: the mid-rebuild read got
[], the unchanged rebuild deletedtoolanddefinition, the failed rebuild emptied the catalog, and the oversized catalog kept 1 of 400 tools.Production (self-hosted Cloudflare deployment,
cloudflare_comstale-marked, then 20 searches during the rebuild): the first search saw the previous 42 tools (never 0), and every later search saw 3600. D1 afterwards: stamped, 3600 distinct tools, 6900 definitions, with noexceeded*outcomes and no sync failures inwrangler tail. In 40 back-to-back searches across GitHub, Stripe and Cloudflare, 1 returnedsession_reset, down from ~50% before.oxfmt --check .oxlint -c .oxlintrc.jsonc . --deny-warningstsgo --noEmit) incore/sdkcore/sdk947; also on the combined stack:plugins/openapi338,plugins/mcp311,plugins/graphql118Checklist