Skip to content

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

Kshitij Jhunjhunwala03d03cc33373
diff --git a/.gitignore b/.gitignore
index e1572b91e..8fb9aa178 100644
--- a/.gitignore
+++ b/.gitignore
@@ -73,3 +73,4 @@ docs/.workflow-data/*
# Local agent / tooling state (regenerated per machine)
.pi/
.playwright-mcp/
+.claude/plans/
diff --git a/ts/packages/cli/src/analytics/dispatch.ts b/ts/packages/cli/src/analytics/dispatch.ts
index c060e9f0e..73fbeb310 100644
--- a/ts/packages/cli/src/analytics/dispatch.ts
+++ b/ts/packages/cli/src/analytics/dispatch.ts
@@ -351,8 +351,8 @@ const spawnWorker = (command: string, args: ReadonlyArray<string>) =>
);
});
-// Shapes an envelope into a PostHog capture body. The public project key
-// authenticates the ingest in-band — no user API key, so pre-login events send.
+// Shapes an envelope into a PostHog capture body; the public project key
+// authenticates the ingest in-band (no user API key attached).
const buildPostHogBody = (envelope: AnalyticsEnvelope, projectKey: string) => ({
api_key: projectKey,
event: envelope.event,
@@ -493,8 +493,19 @@ const captureToComposioCodactFailures = (failure: CliCodactFailure) =>
});
// Hands an envelope to the detached best-effort worker for PostHog delivery.
+// Short-circuits when no project key is configured (the default for OSS forks /
+// local builds) so we never spawn a worker that would only no-op.
const enqueuePostHogEnvelope = (envelope: AnalyticsEnvelope) =>
Effect.gen(function* () {
+ const { projectKey } = yield* getPostHogConfig;
+ if (projectKey.length === 0) {
+ yield* telemetryDebugLog('enqueue_skipped', {
+ reason: 'missing_project_key',
+ eventName: envelope.event,
+ });
+ return;
+ }
+
yield* telemetryDebugLog('enqueue', { envelope });
const serializedEnvelope = yield* encodeJson(envelope);
const encodedPayload = Encoding.encodeBase64Url(serializedEnvelope);
diff --git a/ts/packages/cli/src/commands/login.cmd.ts b/ts/packages/cli/src/commands/login.cmd.ts
index 8fdab0483..fc4789634 100644
--- a/ts/packages/cli/src/commands/login.cmd.ts
+++ b/ts/packages/cli/src/commands/login.cmd.ts
@@ -324,7 +324,6 @@ const directLogin = (params: { userApiKey: string; org?: string }) =>
userApiKey: params.userApiKey,
});
- // Stitch the anonymous pre-login install into the Apollo person (non-fatal).
yield* linkApolloIdentityForAnalytics(sessionInfo.org_member.id);
const selectedOrg = yield* resolveDirectLoginOrganization({
@@ -510,7 +509,6 @@ const loginWithKey = (params: {
userApiKey: uakApiKey,
});
- // Stitch the anonymous pre-login install into the Apollo person (non-fatal).
yield* linkApolloIdentityForAnalytics(uakSessionInfo.org_member.id);
const organizations = params.defaultToFirstOrg
@@ -719,7 +717,6 @@ export const browserLogin = (params: {
userApiKey: uakApiKey,
});
- // Stitch the anonymous pre-login install into the Apollo person (non-fatal).
yield* linkApolloIdentityForAnalytics(uakSessionInfo.org_member.id);
// e.g., "pr_xlSR6oN5jIlk"
diff --git a/ts/packages/cli/test/src/analytics.dispatch.test.ts b/ts/packages/cli/test/src/analytics.dispatch.test.ts
index 527bb9dc6..4d78ce915 100644
--- a/ts/packages/cli/test/src/analytics.dispatch.test.ts
+++ b/ts/packages/cli/test/src/analytics.dispatch.test.ts
@@ -56,6 +56,9 @@ const enableTelemetry = (apiKey = 'uak_test') => {
vi.stubEnv('COMPOSIO_CLI_TELEMETRY_DISABLED', 'false');
vi.stubEnv('TELEMETRY_DISABLED', 'false');
vi.stubEnv('COMPOSIO_DISABLE_TELEMETRY', 'false');
+ // A configured project key is what gates delivery/worker spawning; enabled
+ // telemetry implies a target. The no-key path is covered explicitly below.
+ vi.stubEnv('COMPOSIO_POSTHOG_KEY', 'phc_test_key');
};
const decodeWorkerPayload = <A>(encodedPayload: string): A => {
@@ -225,8 +228,9 @@ describe('CLI analytics dispatch', () => {
.replace(/\//gu, '_')
.replace(/=+$/u, '');
enableTelemetry();
- // No COMPOSIO_POSTHOG_KEY override -> falls back to the empty embedded
- // placeholder, so delivery is a safe no-op until the real key is filled in.
+ // No project key -> the empty embedded placeholder, so the worker's delivery
+ // is a safe no-op until the real key is baked in.
+ vi.stubEnv('COMPOSIO_POSTHOG_KEY', '');
const fetchSpy = vi
.spyOn(globalThis, 'fetch')
.mockResolvedValue(new Response(null, { status: 200 }));
@@ -243,6 +247,24 @@ describe('CLI analytics dispatch', () => {
});
});
+ it.effect('does not spawn a worker when no project key is configured', () => {
+ const home = tempy.temporaryDirectory();
+ const scriptPath = `${home}/composio.ts`;
+ enableTelemetry();
+ // Empty key: forks / local builds without a baked key must not spawn a
+ // detached worker on every command just to have it no-op.
+ vi.stubEnv('COMPOSIO_POSTHOG_KEY', '');
+ process.argv[1] = scriptPath;
+
+ return Effect.gen(function* () {
+ const fs = yield* FileSystem.FileSystem;
+ yield* fs.writeFileString(scriptPath, '');
+ yield* trackCliEventEffect({ name: 'producer_event', properties: { sample: 'value' } });
+
+ expect(childProcessMocks.spawn).not.toHaveBeenCalled();
+ }).pipe(Effect.provide(makePlatformLayer(home)));
+ });
+
it.effect('spawns a detached analytics worker with a decodable envelope', () => {
const home = tempy.temporaryDirectory();
const scriptPath = `${home}/composio.ts`;