fix(mcp): await PostHog flush for local tool-call telemetry - #8733
fix(mcp): await PostHog flush for local tool-call telemetry#8733joaovictor91123 wants to merge 1 commit into
Conversation
Mirror the remote MCP telemetry path so stdio tool events are not dropped when the process exits shortly after a call. Closes JSONbored#8690 Co-authored-by: Cursor <cursoragent@cursor.com>
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8733 +/- ##
===========================================
- Coverage 93.80% 82.30% -11.51%
===========================================
Files 797 98 -699
Lines 79480 24764 -54716
Branches 24080 4747 -19333
===========================================
- Hits 74554 20381 -54173
- Misses 3555 4205 +650
+ Partials 1371 178 -1193
Flags with carried forward coverage won't be shown. Click here to find out more.
|
|
Caution 🛑 LoopOver review result - fixes requiredReview updated: 2026-07-26 01:34:36 UTC
Review summary Nits — 5 non-blocking
CI checks failing
Decision drivers
Context & advisory signals — never blocks the verdict
Linked issue satisfactionAddressed Review context
Contributor next steps
Signal definitions
🧪 Chat with LoopOverAsk LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.
Full command reference: https://loopover.ai/docs/loopover-commands 🧪 Experimental — new and may change. 🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed 💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →. Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.
|
|
LoopOver is closing this pull request on the maintainer's behalf (CI is failing (codecov/patch)). This is an automated maintenance action — to pursue this change, please open a new pull request with the issues resolved. Closed PRs may be analyzed later to improve review accuracy, but they are not automatically reopened or re-reviewed. |
Summary
recordMcpToolCallasync andawait client.flush()before returning, mirroring the remote MCP telemetry fix (MCP tool-call telemetry fires without waitUntil, unlike this repo's own scheduleAfterResponse pattern #7233) so stdio tool events are not silently dropped when the process exits shortly after a call.recordStdioToolTelemetry/registerStdioToolso every stdio tool path holds until flush completes (or definitively fails).test/unit/mcp-local-telemetry.test.tswith flush spies, a delayed-flush await assertion, and a never-throw flush-failure case. Opted-out / unconfigured paths remain no-ops.Client lifetime: still constructs a fresh PostHog client per call (same as the remote wrapper) rather than reusing one across the process - each call's flush is self-contained and does not depend on process-exit hooks.
Closes #8690
Scope
type(scope): short summaryConventional Commit format, for examplefix(api): restore profile access checks.CONTRIBUTING.mdand does not reintroduce GitHub Pages, VitePress,site/, orCNAME.Closes #123) - a linked open issue is required for every contributor PR.Validation
git diff --checknpm run actionlintnpm run typechecknpm run test:coveragelocally;codecov/patchrequires ?99% coverage of the lines AND branches you changed (aim for 100% on your diff so CI variance does not fail near the threshold). Global coverage is a non-blocking trend with a loose 90% backstop, not the gate.npm run test:workersnpm run build:mcpnpm run test:mcp-packnpm run ui:openapi:checknpm run ui:lintnpm run ui:typechecknpm run ui:buildnpm audit --audit-level=moderateIf any required check was skipped, explain why:
test/unit/mcp-local-telemetry.test.tsand will run under CI's pinned Node. Remaining scripts are unchanged MCP lib/bin paths only (no UI/OpenAPI/workers surface).Safety
UI Evidencesection below with JPG/JPEG or PNG screenshots arranged as organized, captioned, clickable thumbnails. SVG screenshots are not used as review evidence. Review-only screenshots or recordings are not committed to the repository.UI Evidence
N/A - no visible UI changes.
Notes
codecov/patchsees the new async branch.