Skip to content

fix(sqlite): expose vfs runtime helpers#4888

Draft
NathanFlurry wants to merge 1 commit intomock-agentic-loop/serverless-configure-retryfrom
mock-agentic-loop/sqlite-vfs-runtime-helpers
Draft

fix(sqlite): expose vfs runtime helpers#4888
NathanFlurry wants to merge 1 commit intomock-agentic-loop/serverless-configure-retryfrom
mock-agentic-loop/sqlite-vfs-runtime-helpers

Conversation

@NathanFlurry
Copy link
Copy Markdown
Member

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Copy link
Copy Markdown
Member Author

NathanFlurry commented May 3, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@railway-app
Copy link
Copy Markdown

railway-app Bot commented May 3, 2026

🚅 Deployed to the rivet-pr-4888 environment in rivet-frontend

Service Status Web Updated (UTC)
website 😴 Sleeping (View Logs) Web May 3, 2026 at 12:20 am
frontend-inspector ❌ Build Failed (View Logs) Web May 3, 2026 at 12:10 am
frontend-cloud ❌ Build Failed (View Logs) Web May 3, 2026 at 12:10 am
ladle ❌ Build Failed (View Logs) Web May 3, 2026 at 12:10 am
mcp-hub ✅ Success (View Logs) Web May 3, 2026 at 12:09 am
kitchen-sink ❌ Build Failed (View Logs) Web May 3, 2026 at 12:09 am

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented May 3, 2026

Code Review

Overview

This PR does two things:

  1. Introduces a block_on_runtime helper to safely call async code from synchronous SQLite VFS callbacks regardless of the current Tokio runtime context.
  2. Exposes sqlite_vfs_metrics() through the NativeDatabaseHandleSqliteVfsVfsContext chain, making VFS performance data accessible from rivetkit-core's SqliteDb.

block_on_runtime — Core Logic

The new helper is the right fix. Without it, calling runtime.block_on() from within a multi-thread Tokio runtime panics with "Cannot block the current thread from within an async context." Using block_in_place moves the work to a dedicated thread, resolving the panic.

Edge case concern — CurrentThread runtime arm:

The Ok(_) arm catches a CurrentThread runtime. If block_on_runtime were ever invoked from within an async task on a CurrentThread scheduler (e.g. a #[tokio::test] that calls into SQLite directly without spawn_blocking), runtime.block_on() would panic because it is not re-entrant. This is safe for the current call sites (VFS C callbacks are invoked synchronously from rusqlite / spawn_blocking context, not inside a running async task), but it is fragile. A brief comment explaining why the CurrentThread path is safe would help:

// CurrentThread runtimes are only in-flight when running a task; VFS callbacks
// are always invoked from synchronous (spawn_blocking or non-async) contexts,
// so block_on is safe without block_in_place here.
Ok(_) | Err(_) => runtime.block_on(future),

Indentation — Style Issue

Several changed call sites gain an extra leading tab compared to surrounding code. For example in block_on_buffered_commit the outer let result = block is indented one extra level, and in VfsContext::new's #[cfg(test)] branch the new block_on_runtime call has two extra tabs. These look like editor artifacts and are worth fixing before merge (even though cargo fmt runs at merge time, the manual misalignment is noticeable).


Metrics Exposure

Clean and consistent with the existing snapshot_preload_hints pattern. The visibility chain (pub(crate) on SqliteVfs, pub on NativeDatabaseHandle) is appropriate. The #[cfg(not(feature = "sqlite-local"))] stub in rivetkit-core correctly mirrors the pattern already used for VfsPreloadHintSnapshot.

One minor note: SqliteVfsMetricsSnapshot is structurally duplicated between depot-client/src/vfs.rs and rivetkit-core/src/actor/sqlite.rs. This is the established pattern, so no action needed — just worth keeping in mind if the struct ever gains new fields.


Summary

Area Finding
Correctness block_on_runtime logic is sound for all current call sites
Robustness Missing comment explaining why CurrentThreadblock_on is safe
Style Extra leading indentation on several changed lines
Tests No tests for block_on_runtime across MT vs CT runtime scenarios
Metrics API Clean, consistent with existing patterns

The fix is small and targeted. The main ask is adding the inline comment on the CurrentThread arm and cleaning up the indentation before merging.

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.

1 participant