Skip to content

Conversation

@tintinthong
Copy link
Contributor

@tintinthong tintinthong commented Jan 20, 2026

Introduce bot-runner

  • bot runner is to enable for users to register a custom bot that handles specific events where the bot-runner is invited to
  • a Node process that follows the AI bot pattern. Runner connects to the realm server database
  • Filter and handle room events based on per-user bot registrations. user can register more than one bot
  • introduce bot registration endpoint which stores bot registration per-user Create bot registration endpoint #3881

@github-actions
Copy link

Preview deployments

@tintinthong tintinthong marked this pull request as draft January 20, 2026 13:59
@github-actions
Copy link

github-actions bot commented Jan 20, 2026

Host Test Results

    1 files  ±0      1 suites  ±0   1h 42m 54s ⏱️ -3s
1 920 tests +8  1 903 ✅ +8  17 💤 ±0  0 ❌ ±0 
1 935 runs  +8  1 918 ✅ +8  17 💤 ±0  0 ❌ ±0 

Results for commit d21e3ed. ± Comparison against base commit 1083776.

♻️ This comment has been updated with latest results.

@tintinthong tintinthong force-pushed the create-bot-runner-package branch from 2ad413f to 2654e2a Compare January 22, 2026 14:52
@tintinthong tintinthong force-pushed the create-bot-runner-package branch from 2654e2a to 442f82c Compare January 22, 2026 16:38
* add bot registration endpoint

* add script to register bot

* add register bot commands

* update generic bot runner

* fix copilot recommendations

* fix handling of bot runner with registrations.

* fix tests + fix copilot recommendations

* include accept header and content type for test

* cleanup code

* get type of full row

* add method to fetchRequestFromContext

* fix schema

* lint

* fix lint types and add test for runner

* fix type

* simplify usage of username rather than matrix_user_id

* fix more lint

* fix lint

* more defensive programming

* fix lint
@tintinthong tintinthong marked this pull request as ready for review January 27, 2026 08:53
@tintinthong tintinthong requested a review from Copilot January 27, 2026 08:53
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request introduces a new bot-runner package that enables users to register bots that can listen to Matrix room events and enqueue work via the realm server queue. The PR is marked as "WIP" in the description.

Changes:

  • Created new @cardstack/bot-runner package with Matrix event handlers and database integration
  • Added bot registration REST API endpoints to realm-server (/_bot-registration, /_bot-registrations)
  • Created database migration and schema for bot_registrations table
  • Added register-bot and unregister-bot commands in the host package
  • Integrated bot-runner user into AI assistant room creation flow

Reviewed changes

Copilot reviewed 28 out of 30 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
packages/bot-runner/* New package with main entry point, event handlers, tests, configuration, and documentation
packages/postgres/migrations/1769200000000_create-bot-registrations.js Database migration creating bot_registrations table
packages/realm-server/handlers/handle-bot-registration.ts Handlers for bot registration, listing, and unregistration endpoints
packages/realm-server/routes.ts Route definitions for bot registration endpoints
packages/realm-server/middleware/index.ts Added DELETE method to request body parsing
packages/realm-server/tests/server-endpoints/bot-registration-test.ts Comprehensive test coverage for bot registration endpoints
packages/realm-server/scripts/register-bot.sh Shell script for registering bots via API
packages/host/app/commands/register-bot.ts Command for registering bots from host application
packages/host/app/commands/unregister-bot.ts Command for unregistering bots from host application
packages/host/app/services/realm-server.ts Service methods for bot registration API calls
packages/host/app/services/matrix-service.ts Added botRunnerUserId getter
packages/host/app/commands/create-ai-assistant-room.ts Temporarily invites bot-runner to AI assistant rooms (marked with TODO)
packages/host/tests/integration/commands/bot-registration-test.gts Integration tests for bot registration commands
packages/runtime-common/constants.ts Added botRunnerUsername constant
packages/matrix/package.json Added script to register bot-runner Matrix user
packages/base/command.gts Added RegisterBotInput, RegisterBotResult, and UnregisterBotInput card definitions
pnpm-lock.yaml Dependency updates for new bot-runner package
.github/workflows/ci.yaml Added bot-registration-test to CI workflow
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 6 to 9
});
};

exports.down = (pgm) => {
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

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

The bot_registrations table is queried by username in the timeline handler (packages/bot-runner/lib/timeline-handler.ts:64-69), but there's no index on the username column. For better query performance, especially as the number of registrations grows, consider adding an index on the username column. Example: pgm.createIndex('bot_registrations', 'username');

Suggested change
});
};
exports.down = (pgm) => {
});
pgm.createIndex('bot_registrations', 'username');
};
exports.down = (pgm) => {
pgm.dropIndex('bot_registrations', 'username');

Copilot uses AI. Check for mistakes.
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c525189cbf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@tintinthong tintinthong requested a review from a team January 27, 2026 12:38
@tintinthong tintinthong merged commit 94a0901 into main Jan 28, 2026
105 of 106 checks passed
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.

3 participants