Skip to content

Conversation

@odilitime
Copy link
Collaborator

@odilitime odilitime commented Nov 13, 2025

Note

Adds conditional MySQL/SQL plugin loading (with URL validation and RLS-aware behavior), decouples server from DB plugins, and finalizes runtime initPromise/adapter registration flow with comprehensive tests.

  • Server:
    • Decouples DB plugin from @elizaos/server; accepts databasePlugin, createDatabaseAdapter, DatabaseMigrationService via ServerConfig and auto-detects if absent.
    • Adds MySQL support: validates MYSQL_URL, uses no-op migration service, skips RLS, and switches upsert syntax when creating message_servers.
    • Ensures only one DB plugin is used; persists selected plugin when starting agents.
  • CLI:
    • start: dynamically loads @elizaos/plugin-mysql or @elizaos/plugin-sql based on env and passes to server.
  • Scenario runner:
    • Chooses MySQL vs SQL from scenario plugins/MYSQL_URL; avoids loading both; isolates PGLite dir only when using SQL.
  • Core Runtime:
    • Registers all plugins before checking DB adapter; resolves initPromise after migrations/world/room setup; merges DB settings back into character; updates types to expose initPromise.
  • DB adapters:
    • plugin-sql: pagination condition fixes; tag filter SQL construction tightened; minor return-shape cleanups.
  • Tests & Mocks:
    • New tests for MySQL server compatibility, scenario plugin selection, adapter registration order, and initPromise (core and test-utils); updated mocks to support initPromise and Bun mock API.

Written by Cursor Bugbot for commit f4e1d41. This will update automatically on new commits. Configure here.

Summary by CodeRabbit

  • New Features

    • Added support for flexible database provider selection, allowing configuration with either MySQL or PostgreSQL through environment variables.
  • Improvements

    • Updated security features to conditionally enable based on your database provider.
    • Enhanced Content Security Policy configuration and database initialization flow.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/server/src/index.ts (1)

196-204: Restore the runtime’s database plugin reference.

sqlPlugin no longer exists after the dynamic import refactor, so this line now fails to compile (see TS2552) and we never add the selected database plugin to agent configs. Persist the chosen plugin during initialization (e.g., store it on the instance) and reference that instead.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9abdd87 and 6237f0f.

📒 Files selected for processing (3)
  • packages/core/src/types/runtime.ts (1 hunks)
  • packages/server/src/index.ts (13 hunks)
  • packages/test-utils/src/mocks/runtime.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursorrules)

**/*.{ts,tsx}: TypeScript for all code
Never use any, never, or unknown types - always opt for specific types that accurately represent the data
Ensure code is free of TypeScript errors or warnings - code must compile without issues

**/*.{ts,tsx}: Use TypeScript with ESM; prefer Bun APIs and avoid Node-only modules when Bun equivalents exist
Formatting must follow Prettier settings: 2 spaces, semicolons, single quotes, trailing comma es5, print width 100
Naming: use camelCase for variables and functions
Naming: use PascalCase for types and React components

Files:

  • packages/core/src/types/runtime.ts
  • packages/server/src/index.ts
  • packages/test-utils/src/mocks/runtime.ts
packages/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

packages/**/*.{ts,tsx}: Never use execa or Node child_process (execSync, spawnSync, exec, spawn); use Bun.spawn() or the bun-exec utilities instead
Prefer the existing bun-exec utility (packages/cli/src/utils/bun-exec.ts) for process execution
Do not use Node.js EventEmitter; always use Bun's EventTarget API
TypeScript only: provide proper specific types; never use any, never, or unknown in new code
Ensure code compiles without TypeScript errors or warnings
Use camelCase for variables and functions
Props interfaces use PascalCase and end with 'Props' (e.g., DashboardMenuProps)
File names should match the main export (e.g., DashboardMenu.tsx matches DashboardMenu)
Actions must return Promise and use callback() for user messages while returning ActionResult for chaining

Files:

  • packages/core/src/types/runtime.ts
  • packages/server/src/index.ts
  • packages/test-utils/src/mocks/runtime.ts
packages/**

📄 CodeRabbit inference engine (AGENTS.md)

Place all source code under packages/* in the monorepo

Files:

  • packages/core/src/types/runtime.ts
  • packages/server/src/index.ts
  • packages/test-utils/src/mocks/runtime.ts
packages/core/**

📄 CodeRabbit inference engine (AGENTS.md)

packages/core contains runtime and shared types; keep core-specific code confined to this package

Files:

  • packages/core/src/types/runtime.ts
packages/!(core)/**/src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

In package code outside core, import @elizaos/core (not 'packages/core')

Files:

  • packages/server/src/index.ts
  • packages/test-utils/src/mocks/runtime.ts
packages/server/**

📄 CodeRabbit inference engine (AGENTS.md)

packages/server implements the Express API; server-specific code should live here

Files:

  • packages/server/src/index.ts
🧠 Learnings (13)
📚 Learning: 2025-07-28T23:42:39.951Z
Learnt from: CR
Repo: elizaOS/eliza PR: 0
File: packages/plugin-starter/CLAUDE.md:0-0
Timestamp: 2025-07-28T23:42:39.951Z
Learning: Applies to packages/plugin-starter/src/services/*.ts : Service classes must implement proper initialization logic in an async initialize(runtime: IAgentRuntime) method

Applied to files:

  • packages/core/src/types/runtime.ts
  • packages/test-utils/src/mocks/runtime.ts
📚 Learning: 2025-08-08T14:26:42.742Z
Learnt from: CR
Repo: elizaOS/eliza PR: 0
File: .cursorrules:0-0
Timestamp: 2025-08-08T14:26:42.742Z
Learning: Applies to packages/core/src/runtime.ts : Main runtime implementation must be in packages/core/src/runtime.ts

Applied to files:

  • packages/core/src/types/runtime.ts
📚 Learning: 2025-07-28T23:42:53.140Z
Learnt from: CR
Repo: elizaOS/eliza PR: 0
File: packages/project-starter/CLAUDE.md:0-0
Timestamp: 2025-07-28T23:42:53.140Z
Learning: Applies to packages/project-starter/src/plugin.ts : Define project-specific custom plugins in `src/plugin.ts` using the `Plugin` interface from `elizaos/core`

Applied to files:

  • packages/core/src/types/runtime.ts
  • packages/server/src/index.ts
📚 Learning: 2025-01-17T15:18:59.962Z
Learnt from: wtfsayo
Repo: elizaOS/eliza PR: 0
File: :0-0
Timestamp: 2025-01-17T15:18:59.962Z
Learning: Always use elizaLogger from elizaos/core instead of console.log for logging in Eliza plugins. elizaLogger provides different log levels: log, error, warn, success, info, and debug.

Applied to files:

  • packages/core/src/types/runtime.ts
📚 Learning: 2025-07-28T23:42:53.140Z
Learnt from: CR
Repo: elizaOS/eliza PR: 0
File: packages/project-starter/CLAUDE.md:0-0
Timestamp: 2025-07-28T23:42:53.140Z
Learning: Applies to packages/project-starter/src/character.ts : Include required plugins `elizaos/plugin-bootstrap` and `elizaos/plugin-sql` in the agent's plugin configuration

Applied to files:

  • packages/server/src/index.ts
📚 Learning: 2025-07-28T23:42:53.140Z
Learnt from: CR
Repo: elizaOS/eliza PR: 0
File: packages/project-starter/CLAUDE.md:0-0
Timestamp: 2025-07-28T23:42:53.140Z
Learning: Applies to packages/project-starter/src/character.ts : Choose at least one model provider plugin (e.g., `elizaos/plugin-openai`, `elizaos/plugin-anthropic`, `elizaos/plugin-groq`, `elizaos/plugin-llama`) in the plugin configuration

Applied to files:

  • packages/server/src/index.ts
📚 Learning: 2025-07-28T23:42:53.140Z
Learnt from: CR
Repo: elizaOS/eliza PR: 0
File: packages/project-starter/CLAUDE.md:0-0
Timestamp: 2025-07-28T23:42:53.140Z
Learning: Applies to packages/project-starter/src/character.ts : Integrate custom plugins by importing them into `src/character.ts` and adding them to the `plugins` array

Applied to files:

  • packages/server/src/index.ts
📚 Learning: 2025-08-28T20:11:19.074Z
Learnt from: CR
Repo: elizaOS/eliza PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-08-28T20:11:19.074Z
Learning: Applies to **/package.json : Use Drizzle ORM; do not add other ORMs (e.g., prisma, typeorm, sequelize)

Applied to files:

  • packages/server/src/index.ts
📚 Learning: 2025-01-21T10:42:58.166Z
Learnt from: wtfsayo
Repo: elizaOS/eliza PR: 0
File: :0-0
Timestamp: 2025-01-21T10:42:58.166Z
Learning: New plugins must be imported in both `agent/package.json` (as a dependency) and `agent/src/index.ts` (for initialization) to be properly integrated into the system.

Applied to files:

  • packages/server/src/index.ts
📚 Learning: 2025-09-17T22:22:35.096Z
Learnt from: CR
Repo: elizaOS/eliza PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-09-17T22:22:35.096Z
Learning: Applies to packages/server/** : packages/server implements the Express API; server-specific code should live here

Applied to files:

  • packages/server/src/index.ts
📚 Learning: 2025-06-18T13:07:47.983Z
Learnt from: 0xbbjoker
Repo: elizaOS/eliza PR: 5171
File: packages/plugin-sql/src/__tests__/integration/agent.test.ts:821-829
Timestamp: 2025-06-18T13:07:47.983Z
Learning: In the SQL plugin's createTask method, the agentId is automatically injected by the adapter using this.agentId, even though the Task interface from elizaos/core doesn't include an agentId field. The database schema has agentId as NOT NULL with CASCADE DELETE, but the adapter handles this internally.

Applied to files:

  • packages/server/src/index.ts
📚 Learning: 2025-07-28T23:42:53.140Z
Learnt from: CR
Repo: elizaOS/eliza PR: 0
File: packages/project-starter/CLAUDE.md:0-0
Timestamp: 2025-07-28T23:42:53.140Z
Learning: Applies to packages/project-starter/**/.env : Use `DATABASE_URL` in `.env` to configure the database connection (SQLite for development, PostgreSQL for production)

Applied to files:

  • packages/server/src/index.ts
📚 Learning: 2025-07-28T23:42:39.951Z
Learnt from: CR
Repo: elizaOS/eliza PR: 0
File: packages/plugin-starter/CLAUDE.md:0-0
Timestamp: 2025-07-28T23:42:39.951Z
Learning: Applies to packages/plugin-starter/src/index.ts : All services must be registered in the plugin's services array in src/index.ts

Applied to files:

  • packages/server/src/index.ts
🪛 GitHub Actions: Core Package Tests
packages/server/src/index.ts

[error] 197-197: src/index.ts(197,89): error TS2552: Cannot find name 'sqlPlugin'. Did you mean 'Plugin'?

🪛 GitHub Actions: Plugin SQL Integration Tests
packages/server/src/index.ts

[error] 197-197: bun run build.ts failed with TypeScript error TS2552: Cannot find name 'sqlPlugin'. Did you mean 'Plugin'?

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: test (ubuntu-latest)
  • GitHub Check: test (windows-latest)
  • GitHub Check: test (macos-latest)
  • GitHub Check: cypress-component
  • GitHub Check: cypress-e2e (1)

odilitime and others added 3 commits November 14, 2025 04:27
Resolved conflicts:
- packages/server/src/__tests__/test-utils/mocks.ts: Use mock() instead of jest.fn(), fixed method name getEntitiesByIds
- packages/server/src/index.ts: Merged MySQL support with updated data isolation (RLS), kept both MySQL and PostgreSQL compatibility
- packages/test-utils/src/mocks/runtime.ts: Added isRoomParticipant mock

Key changes merged from develop:
- Updated RLS implementation with data isolation support
- Renamed serverId to messageServerId for clarity
- Added missing imports from @elizaos/plugin-sql
- Improved test utilities and fixtures
- Enhanced server configuration and initialization
Database type detection now relies on the plugin name rather than the MYSQL_URL environment variable, ensuring correct behavior based on the actual database plugin provided. Added logging for detected database type and improved RLS cleanup logging.
Resolved conflicts in:
- packages/server/src/api/index.ts (restored plugin route logging)
- packages/server/src/index.ts (kept MySQL support while adopting structured logging)

Key changes from develop:
- Structured logging format with {src: 'db'} pattern
- Simplified RLS cleanup logic
- Various dependency and linter config updates

Key changes preserved from spartan-prod:
- MySQL plugin support and conditional syntax handling
- Database plugin injection fixes (initPromise)
- MySQL URL validation
- NoOp migration service for MySQL compatibility
Renamed 'serverId' to 'messageServerId' in ensureWorldExists to match expected property. Also corrected indentation and formatting in several object literals for improved readability.
@elizaOS elizaOS deleted a comment from coderabbitai bot Nov 30, 2025
@elizaOS elizaOS deleted a comment from graphite-app bot Nov 30, 2025
@elizaOS elizaOS deleted a comment from odilitime Nov 30, 2025
@elizaOS elizaOS deleted a comment from coderabbitai bot Nov 30, 2025
@elizaOS elizaOS deleted a comment from claude bot Nov 30, 2025
@elizaOS elizaOS deleted a comment from claude bot Nov 30, 2025
@elizaOS elizaOS deleted a comment from claude bot Nov 30, 2025
@elizaOS elizaOS deleted a comment from claude bot Nov 30, 2025
@elizaOS elizaOS deleted a comment from claude bot Nov 30, 2025
@elizaOS elizaOS deleted a comment from claude bot Nov 30, 2025
@elizaOS elizaOS deleted a comment from claude bot Nov 30, 2025
@elizaOS elizaOS deleted a comment from claude bot Nov 30, 2025
@elizaOS elizaOS deleted a comment from claude bot Nov 30, 2025
@elizaOS elizaOS deleted a comment from claude bot Nov 30, 2025
@elizaOS elizaOS deleted a comment from claude bot Nov 30, 2025
@elizaOS elizaOS deleted a comment from claude bot Nov 30, 2025
wtfsayo and others added 2 commits November 30, 2025 18:50
Plugin registration in AgentRuntime is now started before adapter initialization and awaited after, preventing deadlocks for plugins waiting on initPromise. Test mocks in ensure-agent-exists and runtime-initpromise have been updated for completeness and plugin migration coverage. SQL adapter pagination and query logic have been refined for correctness, and formatting has been improved for consistency. Minor ESLint config formatting changes applied.
The initPromise was being resolved prematurely after adapter initialization
but before world and room entities were created. This caused plugins waiting
on initPromise to access database operations that could fail due to missing
foreign key references.

Changes:
- Move initResolver() call to after all initialization steps complete
- Ensure world entity creation (lines 504-515) happens before promise resolves
- Ensure room entity creation (lines 517-537) happens before promise resolves
- Add comprehensive documentation about proper plugin initialization patterns

Plugins should NOT await initPromise in their init() function (causes deadlock).
Instead, spawn background tasks that wait on initPromise:

  // ✅ CORRECT
  init: async (_, runtime) => {
    runtime.initPromise.then(async () => {
      // Safe to access world/room entities
    });
  }

  // ❌ WRONG - causes deadlock
  init: async (_, runtime) => {
    await runtime.initPromise;
  }

Test results:
- All 748 core tests pass
- All 8 initPromise-specific tests pass
- No regressions introduced
@elizaOS elizaOS deleted a comment from coderabbitai bot Dec 1, 2025
@elizaOS elizaOS deleted a comment from claude bot Dec 1, 2025
@elizaOS elizaOS deleted a comment from claude bot Dec 1, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 1, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch spartan-prod

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Resolved conflicts in packages/server/src/index.ts:
- Merged type imports from types/server
- Preserved MySQL plugin support and utilities
- Added database plugin configuration to ServerConfig type
- Cleaned up duplicate type definitions
- Updated imports to use reorganized file structure
@claude
Copy link
Contributor

claude bot commented Dec 1, 2025

Claude finished @odilitime's task —— View job


PR Review Completed

Todo List:

  • Read key changed files and understand implementation
  • Check for critical security issues
  • Verify TypeScript compilation and type safety
  • Review test coverage and approaches
  • Check adherence to project conventions
  • Format findings in requested format
  • Post final review

Critical Issues Found

CRITICAL: TypeScript compilation errors prevent build → Fix: Line 197 in packages/server/src/index.ts references undefined sqlPlugin variable

CRITICAL: Excessive use of any type violates repo standards → Fix: Replace any casts with proper TypeScript types in database adapter pattern and server configuration

CRITICAL: Database plugin not automatically added to agents → Fix: Replace missing sqlPlugin reference with this.databasePlugin in startAgents() method

Important Issues

⚠️ IMPORTANT: initPromise resolved prematurely in runtime → Fix: Move initManager.resolve() call after world/room creation completes (line 546+ in runtime.ts)

⚠️ IMPORTANT: RLS cleanup logic uses wrong environment variable → Fix: Change RLS_OWNER_ID check to ELIZA_SERVER_ID for proper cleanup detection

⚠️ IMPORTANT: MySQL detection relies on env var instead of plugin type → Fix: Determine database type from actual plugin name/properties rather than MYSQL_URL presence

Suggestions

💡 SUGGESTION: Mock runtime initPromise doesn't match real behavior → Consider: Update test mocks to properly simulate async initialization timing

💡 SUGGESTION: Plugin deduplication may fail with different name formats → Consider: Normalize plugin names before deduplication in scenario runner

💡 SUGGESTION: Log message appears after RLS cleanup completes → Consider: Move logging before uninstallRLS() call for better debugging


Analysis Summary

This PR introduces MySQL support and fixes runtime initialization, but has several blocking compilation errors and architectural issues that need resolution before merge. The extensive use of any types violates the repository's TypeScript standards. While test coverage is comprehensive, the core functionality has critical bugs that would prevent proper operation.

Recommendation: Address compilation errors and type safety issues before proceeding.


Introduces tests to verify that database adapters provided by plugins are registered before adapter availability is checked in AgentRuntime. Refactors runtime initialization to await plugin registration before adapter validation, ensuring plugins can supply adapters during their init phase. Adds test utilities for creating mock adapters.
@claude
Copy link
Contributor

claude bot commented Dec 1, 2025

Claude encountered an error —— View job


I'll analyze this and get back to you.

@claude
Copy link
Contributor

claude bot commented Dec 1, 2025

Claude finished @odilitime's task —— View job


PR Review Completed

Todo List:

  • Read key changed files and understand implementation
  • Check for critical security issues
  • Verify TypeScript compilation and type safety
  • Review test coverage and approaches
  • Check adherence to project conventions
  • Format findings in requested format
  • Post final review

Critical Issues Found

CRITICAL: TypeScript compilation errors prevent build → Fix: Line 197 in packages/server/src/index.ts references undefined sqlPlugin variable

CRITICAL: Excessive use of any type violates repo standards → Fix: Replace any casts with proper TypeScript types in database adapter pattern and server configuration

CRITICAL: Database plugin not automatically added to agents → Fix: Replace missing sqlPlugin reference with this.databasePlugin in startAgents() method

Important Issues

⚠️ IMPORTANT: initPromise resolved prematurely in runtime → Fix: Move initManager.resolve() call after world/room creation completes (line 546+ in runtime.ts)

⚠️ IMPORTANT: RLS cleanup logic uses wrong environment variable → Fix: Change RLS_OWNER_ID check to ELIZA_SERVER_ID for proper cleanup detection

⚠️ IMPORTANT: MySQL detection relies on env var instead of plugin type → Fix: Determine database type from actual plugin name/properties rather than MYSQL_URL presence

Suggestions

💡 SUGGESTION: Mock runtime initPromise doesn't match real behavior → Consider: Update test mocks to properly simulate async initialization timing

💡 SUGGESTION: Plugin deduplication may fail with different name formats → Consider: Normalize plugin names before deduplication in scenario runner

💡 SUGGESTION: Log message appears after RLS cleanup completes → Consider: Move logging before uninstallRLS() call for better debugging


Analysis Summary

This PR introduces MySQL support and fixes runtime initialization, but has several blocking compilation errors and architectural issues that need resolution before merge. The extensive use of any types violates the repository's TypeScript standards. While test coverage is comprehensive, the core functionality has critical bugs that would prevent proper operation.

Recommendation: Address compilation errors and type safety issues before proceeding.


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.

4 participants