Skip to content

fix: await async getService in all dispatcher handlers#814

Merged
hotlong merged 3 commits into
mainfrom
copilot/fix-async-issues-in-dispatcher
Feb 25, 2026
Merged

fix: await async getService in all dispatcher handlers#814
hotlong merged 3 commits into
mainfrom
copilot/fix-async-issues-in-dispatcher

Conversation

Copilot AI commented Feb 25, 2026

Copy link
Copy Markdown
Contributor

getService() can return a Promise when services are registered via async factories, but no call site awaited it — causing runtime errors like Service 'analytics' is async - use await.

Changes

  • getService() / getObjectQLService()async with await on kernel.getService() and kernel.context.getService()
  • All 11 call sites across 7 handlers now await: handleAnalytics, handleAuth, handleStorage, handleAutomation, handlePackages, handleMetadata (5 sites), handleUi
  • 20 new tests covering Promise-based injection, sync backward compat, missing services, and method rejection

Before:

const analyticsService = this.getService(CoreServiceName.enum.analytics);
// analyticsService is a Promise, not the service — .query() fails

After:

const analyticsService = await this.getService(CoreServiceName.enum.analytics);

Runtime: 49/49 tests pass. Spec: 6507/6507 unchanged.

Original prompt

This section details on the original issue you should resolve

<issue_title>全面排查 getService / handleAnalytics 的异步问题并增强测试用例</issue_title>
<issue_description>### 问题现象
系统在调用 /api/v1/analytics/query 等接口时,出现错误:Service 'analytics' is async - use await。根源是 dispatcher 通过 getService 获取的 service 可能是异步的 Promise,没有正确地 await,导致实际调用时失败。

影响范围

  • handleAnalytics 相关接口(query/meta/sql)
  • 其他 dispatcher 内部所有调用 getService 的 handler,如 handleAuth, handleAutomation, handleStorage
  • 插件加载、服务注册异步工厂场景

修复建议

  1. 全面排查 dispatcher 和其他核心模块 getService 的所有调用点,确保对异步 service 正确 await。
  2. 复查 service-register/consumer 工厂模式文档,确保全员共识。
  3. dispatcher 层所有 handler 内部(如 handleAnalytics)需修正为 await this.getService(...) 后再调用。
  4. 针对所有核心 handler 增加或加强测试用例(Vitest),能够覆盖同步和异步 service 的场景,包括异常、未注册、Promise 注入等。
  5. 对异步工厂模式注册的服务补充测试。
  6. PR 合并前务必运行所有相关 test。

测试增强建议

  • 覆盖 dispatcher 层 handleAnalytics、handleAuth、handleAutomation、handleStorage、handleData 等,用 mock kernel 注入 Promise/同步/未注册等情况。
  • 必须验证正常/异常场景,包括 service 返回异常、Promise reject、service 不存在等。
  • 测试用例需模拟真实 REST 请求及接口调用,包含断言 status、error message。
  • 提高测试覆盖率,保证将来 refactor 不再出现类似隐患。

关联

  • 合并本次 issue 到 roadmap ObjectStack Roadmap,类型 Bug + Enhancement。
  • 针对类似异步工厂/Promise注入的注册方式,补充技术文档及最佳实践说明。

开发任务完成后请运行所有 test,并及时更新 roadmap。</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@vercel

vercel Bot commented Feb 25, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
objectstack-play Ready Ready Preview, Comment Feb 25, 2026 8:12am
spec Ready Ready Preview, Comment Feb 25, 2026 8:12am

Request Review

Copilot AI and others added 2 commits February 25, 2026 08:04
…rvice tests

- Make getService() and getObjectQLService() async to properly await Promise-based service factories
- Add await to all callers: handleAuth, handleAnalytics, handleStorage, handleAutomation, handlePackages
- Add await to all kernel.context.getService() calls in handleMetadata and handleUi
- Add 20 new tests covering async/sync/missing service scenarios

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix async issues in getService and handleAnalytics fix: await async getService in all dispatcher handlers Feb 25, 2026
Copilot AI requested a review from hotlong February 25, 2026 08:07
@hotlong
hotlong marked this pull request as ready for review February 25, 2026 08:15
Copilot AI review requested due to automatic review settings February 25, 2026 08:15
@hotlong
hotlong merged commit 849eebd into main Feb 25, 2026
4 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a critical bug where HttpDispatcher handlers were calling getService() synchronously when it could return a Promise from async factory-based service registration, causing runtime errors like "Service 'analytics' is async - use await".

Changes:

  • Made getService() and getObjectQLService() async methods in HttpDispatcher
  • Updated all 13 call sites across 7 handlers to properly await service resolution: handleAnalytics, handleAuth, handleStorage, handleAutomation, handleMetadata (5 call sites), handleUi, and handlePackages
  • Added 20 comprehensive tests covering Promise-based service injection, synchronous backward compatibility, missing services, and error propagation scenarios
  • Updated ROADMAP.md to document the fix

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
packages/runtime/src/http-dispatcher.ts Made getService() and getObjectQLService() async; updated all 13 call sites to await these methods across handleAnalytics, handleAuth, handleMetadata (5 sites), handleStorage, handleUi, and handleAutomation handlers
packages/runtime/src/http-dispatcher.test.ts Added 20 new tests organized in 3 test suites: async service resolution (Promise-based injection), synchronous backward compatibility, and service method error handling
ROADMAP.md Added entry documenting the dispatcher async getService bug fix with coverage details

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.

全面排查 getService / handleAnalytics 的异步问题并增强测试用例

3 participants