Skip to content

Flush runtime object cache between STDIO requests - #463

Closed
lezama wants to merge 1 commit into
trunkfrom
fix/stdio-flush-runtime-object-cache
Closed

lezama wants to merge 1 commit into
trunkfrom
fix/stdio-flush-runtime-object-cache

Conversation

@lezama

@lezama lezama commented Nov 21, 2026 •

Copy link
Copy Markdown

Closes #462

wp mcp-adapter serve runs in a single long-lived PHP-CLI process. On sites without an external persistent object cache, WordPress keeps post, postmeta, usermeta, and option lookups in the in-memory $wp_object_cache for the lifetime of the process, so updates made by other processes (HTTP requests, cron, another WP-CLI command) stay invisible to subsequent STDIO calls.

This calls wp_cache_flush_runtime() in StdioServerBridge::handle_request() before processing each request, so every STDIO request reads fresh database state while leaving persistent object caches untouched.

Testing

  • Added StdioServerBridgeTest::test_handle_request_flushes_runtime_object_cache_between_requests() simulating an external DB update between two tools/call requests on the same bridge instance.
  • Ran composer lint (PHPCS) and composer phpstan locally with no errors.
Open WordPress Playground Preview

@lezama
lezama requested a review from a team as a code owner November 21, 2026 22:22
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: lezama <migueluy@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Copilot AI balanced review requested due to automatic review settings November 21, 2026 22:23
@codecov

codecov Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.14%. Comparing base (0af3bb9) to head (a7b0723).

Additional details and impacted files
@@            Coverage Diff            @@
##              trunk     #463   +/-   ##
=========================================
  Coverage     93.13%   93.14%           
  Complexity     1386     1386           
=========================================
  Files            60       60           
  Lines          4023     4024    +1     
=========================================
+ Hits           3747     3748    +1     
  Misses          276      276           
Flag Coverage Δ
unit 93.14% <100.00%> (+<0.01%) ⮆ïļ

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
ðŸ“Ē Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄ïļ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • ðŸ“Ķ JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ðŸŸĄ Changes recommended

The runtime cache flush lacks a capability check, causing diagnostics on every valid STDIO message with unsupported persistent cache backends without clearing the cache.

1 open issue
What changed in this PR

Addresses #462 by refreshing WordPress’s runtime object cache between requests in the long-lived wp mcp-adapter serve process, preventing stale database reads on sites without a persistent object cache.

Changes:

  • Calls wp_cache_flush_runtime() before processing each parsed STDIO request.
  • Adds a regression test that simulates an external database update and checks that subsequent requests see fresh values while preserving the selected user.
File Description
tests/​phpunit/​Unit/​Cli/​StdioServerBridgeTest.php Tests cache freshness and user identity across sequential requests.
includes/​Cli/​StdioServerBridge.php Adds runtime-cache flushing before request processing.

Review effort: Balanced


// Clear the process-local runtime object cache so long-lived STDIO sessions
// read fresh database state updated by other processes (HTTP, cron, WP-CLI).
wp_cache_flush_runtime();
@galatanovidiu

Copy link
Copy Markdown
Contributor

I'm going with #413 for #409 and closing this PR as a duplicate. #413 checks wp_cache_supports( 'flush_runtime' ) before flushing, so drop-ins without support are left alone.

The fix and regression test here worked in my test too. The second tools/call returned the updated value.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flush runtime object cache between STDIO requests in wp mcp-adapter serve

3 participants