-
Notifications
You must be signed in to change notification settings - Fork 5.4k
fix: plugin-mysql support, initPromise and other minor fixes #6143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
sqlPluginno 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
📒 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.tspackages/server/src/index.tspackages/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.tspackages/server/src/index.tspackages/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.tspackages/server/src/index.tspackages/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.tspackages/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.tspackages/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.tspackages/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)
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.
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
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Note Other AI code review bot(s) detectedCodeRabbit 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)
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. Comment |
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 finished @odilitime's task —— View job PR Review CompletedTodo List:
Critical Issues Found❌ CRITICAL: TypeScript compilation errors prevent build → Fix: Line 197 in ❌ CRITICAL: Excessive use of ❌ CRITICAL: Database plugin not automatically added to agents → Fix: Replace missing Important Issues
Suggestions💡 SUGGESTION: Mock runtime 💡 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 Analysis SummaryThis 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 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 encountered an error —— View job I'll analyze this and get back to you. |
|
Claude finished @odilitime's task —— View job PR Review CompletedTodo List:
Critical Issues Found❌ CRITICAL: TypeScript compilation errors prevent build → Fix: Line 197 in ❌ CRITICAL: Excessive use of ❌ CRITICAL: Database plugin not automatically added to agents → Fix: Replace missing Important Issues
Suggestions💡 SUGGESTION: Mock runtime 💡 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 Analysis SummaryThis 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 Recommendation: Address compilation errors and type safety issues before proceeding. |
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.
@elizaos/server; acceptsdatabasePlugin,createDatabaseAdapter,DatabaseMigrationServiceviaServerConfigand auto-detects if absent.MYSQL_URL, uses no-op migration service, skips RLS, and switches upsert syntax when creatingmessage_servers.start: dynamically loads@elizaos/plugin-mysqlor@elizaos/plugin-sqlbased on env and passes to server.MYSQL_URL; avoids loading both; isolates PGLite dir only when using SQL.initPromiseafter migrations/world/room setup; merges DB settings back into character; updates types to exposeinitPromise.plugin-sql: pagination condition fixes; tag filter SQL construction tightened; minor return-shape cleanups.initPromise(core and test-utils); updated mocks to supportinitPromiseand BunmockAPI.Written by Cursor Bugbot for commit f4e1d41. This will update automatically on new commits. Configure here.
Summary by CodeRabbit
New Features
Improvements