fix: eliminate ~3.9s blocking latency on SDK cold init#2980
Open
majiayu000 wants to merge 3 commits intoComposioHQ:nextfrom
Open
fix: eliminate ~3.9s blocking latency on SDK cold init#2980majiayu000 wants to merge 3 commits intoComposioHQ:nextfrom
majiayu000 wants to merge 3 commits intoComposioHQ:nextfrom
Conversation
Three targeted changes to avoid synchronous network I/O during constructor execution: 1. version.ts: Add file-based cache (24h TTL) for npm version check and AbortSignal.timeout(5s) to prevent hanging fetches 2. Telemetry.ts: Route SDK_INITIALIZED event through batchProcessor instead of immediate sendMetric(), leveraging existing 200ms batch window 3. composio.ts: Defer checkForLatestVersionFromNPM to next event loop tick via setTimeout(0) Signed-off-by: majiayu000 <1835304752@qq.com>
- Add 7 test cases for checkForLatestVersionFromNPM covering cache hits, stale cache, missing cache, malformed JSON, write errors, and invalid npm responses - Validate latestVersion is a string and valid semver before writing cache - Fix misleading comment about setTimeout deferral in constructor Signed-off-by: majiayu000 <1835304752@qq.com>
|
@majiayu000 is attempting to deploy a commit to the Composio Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
…sion cache Replace direct Node.js imports (os, path, fs) with the existing #platform conditional import abstraction so version.ts does not break workerd/edge runtimes. Cache location moved from os.tmpdir() to ~/.composio/ using platform.homedir(), guarded by platform.supportsFileSystem. Addresses review feedback on PR ComposioHQ#2980. Signed-off-by: majiayu000 <1835304752@qq.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Fixes #2970
Three targeted changes to eliminate ~3.9s cold-init blocking caused by synchronous npm registry check and telemetry POST during constructor execution.
Changes
os.tmpdir()/composio-version-cache.json) andAbortSignal.timeout(5000)to prevent hanging. On cache hit, skip the network request entirely.batchProcessor.pushItem()instead of immediatesendMetric(), deferring the HTTP POST via the 200ms batch window.checkForLatestVersionFromNPM()insetTimeout(0)to defer to next event loop tick, ensuring zero init-time network I/O.Type of change
How Has This Been Tested?
ts/packages/core/test/core/version-check.test.tswith 7 Vitest tests covering cache write, cache hit, cache stale, fetch timeout, corrupt cache, write error, and npm response validation.ts/packages/core/test/telemetry/TelemetryService.test.tsto verify SDK_INITIALIZED routes through batchProcessor.@composio/json-schema-to-zoddependency, unrelated to this change.Checklist
Additional context
Both the npm version check and telemetry POST were already fire-and-forget (not awaited), but they initiated DNS resolution + TCP connections immediately on cold start, adding ~3.9s blocking latency. The fix uses three complementary strategies: file-based caching (eliminates repeated fetches), batch processing (defers telemetry), and event loop deferral (ensures zero synchronous network I/O during construction).