@devries-cameron20 / composio-1 / commits / 03d03cc33
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

chore(cli): review fixes — gate worker spawn on key; drop redundant comments

- Short-circuit enqueuePostHogEnvelope when no PostHog project key is configured, so we never spawn a detached worker that would only no-op. The pre-rewrite code guarded on the endpoint before spawning; the direct transport lost it, so every command on a keyless build (the default until the key is baked, and all OSS forks / local builds) spawned a throwaway process. Added a parent-side test asserting no spawn without a key. - Remove three duplicated inline comments at the login call sites (the function name + its definition comment already document it). - Ignore .claude/plans/ (handoff artifacts, never committed). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Kshitij Jhunjhunwala committed Jul 23, 2026 at 12:14 UTC 03d03cc33373c840a453175f75cc27f6f393b0fb
4 files changed +38 -7
.gitignore
+1
@@ -73,3 +73,4 @@ docs/.workflow-data/*
73 # Local agent / tooling state (regenerated per machine)
74 .pi/
75 .playwright-mcp/
76 +.claude/plans/
ts/packages/cli/src/analytics/dispatch.ts
+13 -2
@@ -351,8 +351,8 @@ const spawnWorker = (command: string, args: ReadonlyArray<string>) =>
351 );
352 });
353
354 -// Shapes an envelope into a PostHog capture body. The public project key
355 -// authenticates the ingest in-band — no user API key, so pre-login events send.
354 +// Shapes an envelope into a PostHog capture body; the public project key
355 +// authenticates the ingest in-band (no user API key attached).
356 const buildPostHogBody = (envelope: AnalyticsEnvelope, projectKey: string) => ({
357 api_key: projectKey,
358 event: envelope.event,
@@ -493,8 +493,19 @@ const captureToComposioCodactFailures = (failure: CliCodactFailure) =>
493 });
494
495 // Hands an envelope to the detached best-effort worker for PostHog delivery.
496 +// Short-circuits when no project key is configured (the default for OSS forks /
497 +// local builds) so we never spawn a worker that would only no-op.
498 const enqueuePostHogEnvelope = (envelope: AnalyticsEnvelope) =>
499 Effect.gen(function* () {
500 + const { projectKey } = yield* getPostHogConfig;
501 + if (projectKey.length === 0) {
502 + yield* telemetryDebugLog('enqueue_skipped', {
503 + reason: 'missing_project_key',
504 + eventName: envelope.event,
505 + });
506 + return;
507 + }
508 +
509 yield* telemetryDebugLog('enqueue', { envelope });
510 const serializedEnvelope = yield* encodeJson(envelope);
511 const encodedPayload = Encoding.encodeBase64Url(serializedEnvelope);
ts/packages/cli/src/commands/login.cmd.ts
-3
@@ -324,7 +324,6 @@ const directLogin = (params: { userApiKey: string; org?: string }) =>
324 userApiKey: params.userApiKey,
325 });
326
327 - // Stitch the anonymous pre-login install into the Apollo person (non-fatal).
327 yield* linkApolloIdentityForAnalytics(sessionInfo.org_member.id);
328
329 const selectedOrg = yield* resolveDirectLoginOrganization({
@@ -510,7 +509,6 @@ const loginWithKey = (params: {
509 userApiKey: uakApiKey,
510 });
511
513 - // Stitch the anonymous pre-login install into the Apollo person (non-fatal).
512 yield* linkApolloIdentityForAnalytics(uakSessionInfo.org_member.id);
513
514 const organizations = params.defaultToFirstOrg
@@ -719,7 +717,6 @@ export const browserLogin = (params: {
717 userApiKey: uakApiKey,
718 });
719
722 - // Stitch the anonymous pre-login install into the Apollo person (non-fatal).
720 yield* linkApolloIdentityForAnalytics(uakSessionInfo.org_member.id);
721
722 // e.g., "pr_xlSR6oN5jIlk"
ts/packages/cli/test/src/analytics.dispatch.test.ts
+24 -2
@@ -56,6 +56,9 @@ const enableTelemetry = (apiKey = 'uak_test') => {
56 vi.stubEnv('COMPOSIO_CLI_TELEMETRY_DISABLED', 'false');
57 vi.stubEnv('TELEMETRY_DISABLED', 'false');
58 vi.stubEnv('COMPOSIO_DISABLE_TELEMETRY', 'false');
59 + // A configured project key is what gates delivery/worker spawning; enabled
60 + // telemetry implies a target. The no-key path is covered explicitly below.
61 + vi.stubEnv('COMPOSIO_POSTHOG_KEY', 'phc_test_key');
62 };
63
64 const decodeWorkerPayload = <A>(encodedPayload: string): A => {
@@ -225,8 +228,9 @@ describe('CLI analytics dispatch', () => {
228 .replace(/\//gu, '_')
229 .replace(/=+$/u, '');
230 enableTelemetry();
228 - // No COMPOSIO_POSTHOG_KEY override -> falls back to the empty embedded
229 - // placeholder, so delivery is a safe no-op until the real key is filled in.
231 + // No project key -> the empty embedded placeholder, so the worker's delivery
232 + // is a safe no-op until the real key is baked in.
233 + vi.stubEnv('COMPOSIO_POSTHOG_KEY', '');
234 const fetchSpy = vi
235 .spyOn(globalThis, 'fetch')
236 .mockResolvedValue(new Response(null, { status: 200 }));
@@ -243,6 +247,24 @@ describe('CLI analytics dispatch', () => {
247 });
248 });
249
250 + it.effect('does not spawn a worker when no project key is configured', () => {
251 + const home = tempy.temporaryDirectory();
252 + const scriptPath = `${home}/composio.ts`;
253 + enableTelemetry();
254 + // Empty key: forks / local builds without a baked key must not spawn a
255 + // detached worker on every command just to have it no-op.
256 + vi.stubEnv('COMPOSIO_POSTHOG_KEY', '');
257 + process.argv[1] = scriptPath;
258 +
259 + return Effect.gen(function* () {
260 + const fs = yield* FileSystem.FileSystem;
261 + yield* fs.writeFileString(scriptPath, '');
262 + yield* trackCliEventEffect({ name: 'producer_event', properties: { sample: 'value' } });
263 +
264 + expect(childProcessMocks.spawn).not.toHaveBeenCalled();
265 + }).pipe(Effect.provide(makePlatformLayer(home)));
266 + });
267 +
268 it.effect('spawns a detached analytics worker with a decodable envelope', () => {
269 const home = tempy.temporaryDirectory();
270 const scriptPath = `${home}/composio.ts`;