Skip to content

[slop]fix(rivetkit): remove async drizzle db proxy#4984

Open
abcxff wants to merge 1 commit intomainfrom
05-06-_slop_fix_rivetkit_remove_async_drizzle_db_proxy
Open

[slop]fix(rivetkit): remove async drizzle db proxy#4984
abcxff wants to merge 1 commit intomainfrom
05-06-_slop_fix_rivetkit_remove_async_drizzle_db_proxy

Conversation

@abcxff
Copy link
Copy Markdown
Contributor

@abcxff abcxff commented May 6, 2026

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

@railway-app
Copy link
Copy Markdown

railway-app Bot commented May 6, 2026

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

Service Status Web Updated (UTC)
kitchen-sink ❌ Build Failed (View Logs) Web May 7, 2026 at 5:09 pm
website 😴 Sleeping (View Logs) Web May 7, 2026 at 3:08 am
frontend-inspector ❌ Build Failed (View Logs) Web May 6, 2026 at 10:02 pm
frontend-cloud ❌ Build Failed (View Logs) Web May 6, 2026 at 10:01 pm
ladle ❌ Build Failed (View Logs) Web May 6, 2026 at 4:19 am
mcp-hub ✅ Success (View Logs) Web May 6, 2026 at 4:18 am

Copy link
Copy Markdown
Contributor Author

abcxff commented May 6, 2026

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

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented May 6, 2026

PR 4984 Review: remove async drizzle db proxy

Overview

This PR removes the async Proxy-based lazy initializer from ActorContextHandleAdapter.get db and replaces it with a synchronous accessor. The old design wrapped the Drizzle client in a Proxy that called ensureDatabaseClient() asynchronously on every property access. The new design requires the client to be pre-warmed during the onMigrate lifecycle phase (runDatabaseMigrations() -> ensureDatabaseClient()) and then reads it synchronously from runtimeState.databaseClient.

What is Good

  • Simpler, more correct implementation. The old Proxy required a then: undefined guard to stop Promise.resolve from treating the object as a thenable. That is a subtle footgun this PR eliminates.
  • Removes per-call async overhead. Every Drizzle method call previously awaited ensureDatabaseClient() unconditionally. The client is now resolved once and reused.
  • Follows the Fail-By-Default principle. The new databaseClientNotReadyError fails loudly with actionable context instead of silently deferring via lazy init.
  • Correct multi-adapter semantics. Each makeActorCtx(ctx) call creates a fresh ActorContextHandleAdapter with #db = undefined, but the runtimeState.databaseClient lookup correctly restores the cached client across adapter instances.
  • Good lifecycle test coverage. The existing actor-db-init-order.test.ts validates ctx.db availability from onCreate, createState, createVars, onWake, onSleep, and onDestroy.

Issues

Dead code: prepare() method

ActorContextHandleAdapter.prepare() (line 2694) is defined but has no call sites anywhere in the codebase. runDatabaseMigrations() is the actual pre-warm path used by the native lifecycle, making prepare() unreachable. It should be removed, or if it is an intentional public API hook, documented and wired into the lifecycle.

Missing test for the new error code

native-runtime-errors.test.ts has a test for database_not_configured (when no databaseProvider is set at all) but nothing for database_client_not_ready (when a provider is configured but the client was never pre-warmed). A unit test for that path in the same file would complete the error-path coverage.

PR description is empty

All checklist items are unchecked and there is no summary of motivation. A sentence explaining why the proxy was problematic would help future reviewers.

Correctness

The change is logically sound given the established lifecycle ordering:

  1. onMigrate fires first, calling runDatabaseMigrations() -> ensureDatabaseClient(), which sets runtimeState.databaseClient.
  2. All user lifecycle hooks (onCreate, createState, createVars, onWake, etc.) fire after onMigrate, so ctx.db is always ready when user code runs.
  3. On sleep, cleanupNativeSleepRuntimeState() calls closeNativeDatabaseClient(), clearing runtimeState.databaseClient.
  4. On wake, onMigrate runs again (with isNew = false) and re-initializes the client before onWake fires.

The actor-db-init-order.test.ts tests validate this ordering end-to-end.

Summary

Solid improvement overall. Two minor items to address before merging: remove the dead prepare() method, and add a unit test for database_client_not_ready in native-runtime-errors.test.ts.

@abcxff abcxff marked this pull request as ready for review May 6, 2026 15:06
@abcxff abcxff changed the base branch from 05-06-fix_rivetkit-napi_demote_bridge_error_decode_log_from_warn_to_debug to graphite-base/4984 May 6, 2026 21:59
@abcxff abcxff force-pushed the graphite-base/4984 branch from 2bdaa73 to 0499832 Compare May 6, 2026 21:59
@abcxff abcxff force-pushed the 05-06-_slop_fix_rivetkit_remove_async_drizzle_db_proxy branch from 1134c24 to abb6ff1 Compare May 6, 2026 21:59
@abcxff abcxff changed the base branch from graphite-base/4984 to 05-05-fix_rivetkit_use_keepawake_for_websocket_callback_tracking_to_prevent_c.vars_crash_after_grace_deadline May 6, 2026 21:59
@abcxff abcxff changed the base branch from 05-05-fix_rivetkit_use_keepawake_for_websocket_callback_tracking_to_prevent_c.vars_crash_after_grace_deadline to graphite-base/4984 May 7, 2026 01:26
@abcxff abcxff force-pushed the 05-06-_slop_fix_rivetkit_remove_async_drizzle_db_proxy branch from abb6ff1 to 38d756b Compare May 7, 2026 01:27
@abcxff abcxff changed the base branch from graphite-base/4984 to 05-06-fix_rivetkit-napi_demote_bridge_error_decode_log_from_warn_to_debug May 7, 2026 01:27
@abcxff abcxff mentioned this pull request May 7, 2026
11 tasks
@abcxff abcxff changed the base branch from 05-06-fix_rivetkit-napi_demote_bridge_error_decode_log_from_warn_to_debug to graphite-base/4984 May 7, 2026 17:07
@abcxff abcxff force-pushed the 05-06-_slop_fix_rivetkit_remove_async_drizzle_db_proxy branch from 38d756b to d12b4c4 Compare May 7, 2026 17:07
@abcxff abcxff changed the base branch from graphite-base/4984 to main May 7, 2026 17:07
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