Skip to content

Stop FastMCP callable caches from retaining dropped tools - #6147

Merged
zzstoatzz merged 3 commits into
PrefectHQ:mainfrom
PennEwan:codex/fix-6115-tool-cache
Nov 10, 2026
Merged

zzstoatzz merged 3 commits into
PrefectHQ:mainfrom
PennEwan:codex/fix-6115-tool-cache

Conversation

@PennEwan

Copy link
Copy Markdown
Contributor

FastMCP's process-wide callable caches retained tool closures after their servers were dropped, including the captured per-user data. Store wrapper and adapter metadata on the function or bound instance instead, so references between a callable and its cached values can be collected together. Callables that cannot own this metadata run uncached; ordinary type adapters keep the existing bounded cache. Runtime cache entries are discarded when a tool function is pickled for a task.

This fixes the FastMCP-owned retention in #6115. The independent signature and parameter caches in uncalled-for still retain functions until released there; that remaining dependency issue is tracked in chrisguidry/uncalled-for#21. The lifecycle regression isolates those third-party caches and does not claim that a full application using the current dependency has no remaining retention.

Fixes #6115

Co-authored-by: hanhyperfx 331364095+hanhyperfx@users.noreply.github.com

Generated with OpenAI Codex.

Fixes PrefectHQ#6115

Generated with OpenAI Codex.

Co-authored-by: hanhyperfx <331364095+hanhyperfx@users.noreply.github.com>
@github-actions

This comment has been minimized.

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-29T10:19:12.023206Z 4d4bea0 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@marvin-context-protocol marvin-context-protocol Bot added bug Something isn't working. Reports of errors, unexpected behavior, or broken functionality. server Related to FastMCP server implementation or server-side functionality. labels Oct 29, 2026

@fastmcp-triage-reviewer fastmcp-triage-reviewer Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review by the FastMCP triage reviewer bot.

Changing FastMCP's own callable caches fixes the retention of removed tools' closures, without lifecycle workarounds. The earlier concern about functools.partial doesn't hold: partials have a writable __dict__ and support weak references. No changes requested.

Closures are fully released only once the uncalled-for caches are cleared too, which is outside this PR.

Checks

Reviewed at 4d4bea0. Nine lifetime tests fail on main and all 12 pass here, plus 200 neighboring tests. Client checks across tools, prompts, resources and templates agree.


Generated by Claude Code

Copy link
Copy Markdown
Contributor Author

At the reviewed head 4d4bea0dc80b031839d11463f9c27278a29d5d2c, the applicable changed-file prek run and normal commit hooks passed locally, including Ruff, ty, gitleaks and codespell. Local neighboring checks covered dependency/session/type-adapter paths, resources/templates/prompts and task snapshot restore. The independent triage probe's distinction matches this PR's scope: it removes FastMCP-owned retention, while uncalled-for still retains callables independently. Maintainer assignment and substantive upstream CI remain pending; the local results are not a claim of CI or merge readiness.

@zzstoatzz
zzstoatzz merged commit 713f247 into PrefectHQ:main Nov 10, 2026
26 checks passed
zzstoatzz added a commit that referenced this pull request Nov 10, 2026
* Revert "fix: preserve referenced schema definitions (#5588)"

This reverts commit 5f1d152.

* Revert "fix(server): rebuild tool argument errors instead of echoing pydantic's (#6107)"

This reverts commit 8fba5f7.

* Revert "Advertise the MCP Apps extension only when the server serves an app (#5062)"

This reverts commit b89222b.

* Revert "fix(tasks): retain results after tool removal (#5507)"

This reverts commit 711575a.

* Revert "fix(client): Prevent stale ClientGroup refreshes from replacing newer routes (#5543)"

This reverts commit 365d5d2.

* Revert "fix(prompts): honor field aliases when rendering prompts (#5836)"

This reverts commit a450fd8.

* Revert "Stop FastMCP callable caches from retaining dropped tools (#6147)"

This reverts commit 713f247.

* Revert "feat(auth): Add KeystoneTokenVerifier (#6264)"

This reverts commit c33f3de.

* Revert "fix(json-schema): keep x-unsupported-pattern when a format is set (#5731)"

This reverts commit dc9849d.

* Revert "Roll back the tool stamp when a tool registration is rejected (#5798)"

This reverts commit d6566c5.

* Revert "fix(server): validate cursors when pagination is disabled (#6045)"

This reverts commit 4917bee.

* Revert "Keep constraints on scalar schema references (#6041)"

This reverts commit e5176c9.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working. Reports of errors, unexpected behavior, or broken functionality. bypass-issue-check server Related to FastMCP server implementation or server-side functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tool function caches keep the tools of dropped servers alive

2 participants