Skip to content

feat(telemetry): track SDK version traits and upgrade posthog-node to v6 - #1616

Merged
gewenyu99 merged 5 commits into
mainfrom
feat/sdk-version-telemetry
Nov 27, 2026
Merged

gewenyu99 merged 5 commits into
mainfrom
feat/sdk-version-telemetry

Conversation

@gewenyu99

@gewenyu99 gewenyu99 commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Telemetry doesn't track which PostHog SDK versions, pin styles, or versioned skills runs hit, and the repo is still on posthog-node v5.

Changes

  • Summarize detected SDK versions and pin styles in src/services/project-discovery/traits/sdks.ts (summarizePosthogSdks()) without leaking local paths, patch versions, or raw specs, and emit one posthog sdks detected event plus run tags (has_existing_sdk, detected_sdk_count, sdk_version_found, sdk_version_pin) per session in src/services/project-discovery/report.ts (reportDiscovery()) behind mayReportDiscovery and !noTelemetry.
  • Replace per-skill sdk trait skill resolved events with one sdk skills resolved summary event and sdk_skills / sdk_non_default_major run tags in src/agent/runner/shared/trait-skills.ts.
  • Upgrade posthog-node from ^5.45.2 to ^6.0.5 (latest release past pnpm's 7-day minimumReleaseAge), update src/shared/utils/analytics.ts for v6 and route 'error' events to logToFile() so warnings don't break TUI or headless output, and attach an 'error' listener before shutdown() in src/tui/tools/mcp/services/seed-events.ts so seedDemoEvents() still rejects on failed sends.

Test plan

  • npx tsc -b --force passes.
  • Full Vitest suite passes after the v6 upgrade (304/304 files, 4843 passed, 1 skipped), including updated posthog-sdks.test.ts, report.test.ts, and trait-skills.test.ts.
  • pnpm build (includes test:smoke and test:warlock) passes.
  • eslint and prettier --check pass on all changed files.

@gewenyu99
gewenyu99 requested a review from a team as a code owner November 26, 2026 18:43
@github-actions

Copy link
Copy Markdown

🧙 Wizard CI

Run the Wizard CI and test your changes against wizard-workbench example apps by replying with a GitHub comment using one of the following commands:

Test all apps:

  • /wizard-ci all

Test all apps in a directory:

  • /wizard-ci ai-observability
  • /wizard-ci basic-integration
  • /wizard-ci feature-flags
  • /wizard-ci mcp-analytics
  • /wizard-ci replay-vision
  • /wizard-ci revenue
  • /wizard-ci self-driving
  • /wizard-ci warehouse
  • /wizard-ci warehouse-seeded

Test an individual app:

  • /wizard-ci ai-observability/anthropic
  • /wizard-ci ai-observability/google-adk
  • /wizard-ci ai-observability/groq
Show more apps
  • /wizard-ci ai-observability/manual-capture
  • /wizard-ci ai-observability/openai
  • /wizard-ci ai-observability/openai-agents
  • /wizard-ci ai-observability/opentelemetry
  • /wizard-ci ai-observability/vercel-ai
  • /wizard-ci basic-integration/android
  • /wizard-ci basic-integration/angular
  • /wizard-ci basic-integration/astro
  • /wizard-ci basic-integration/django
  • /wizard-ci basic-integration/fastapi
  • /wizard-ci basic-integration/flask
  • /wizard-ci basic-integration/flutter
  • /wizard-ci basic-integration/javascript-node
  • /wizard-ci basic-integration/javascript-web
  • /wizard-ci basic-integration/laravel
  • /wizard-ci basic-integration/next-js
  • /wizard-ci basic-integration/nuxt
  • /wizard-ci basic-integration/python
  • /wizard-ci basic-integration/rails
  • /wizard-ci basic-integration/react-native
  • /wizard-ci basic-integration/react-router
  • /wizard-ci basic-integration/sveltekit
  • /wizard-ci basic-integration/swift
  • /wizard-ci basic-integration/tanstack-router
  • /wizard-ci basic-integration/tanstack-start
  • /wizard-ci basic-integration/vue
  • /wizard-ci feature-flags/django
  • /wizard-ci feature-flags/next-js
  • /wizard-ci mcp-analytics/custom-dispatcher
  • /wizard-ci mcp-analytics/go-sdk
  • /wizard-ci mcp-analytics/python-sdk
  • /wizard-ci mcp-analytics/ruby-sdk
  • /wizard-ci mcp-analytics/rust-sdk
  • /wizard-ci mcp-analytics/typescript-sdk
  • /wizard-ci replay-vision/javascript-node
  • /wizard-ci replay-vision/next-js
  • /wizard-ci replay-vision/react-vite
  • /wizard-ci revenue/stripe
  • /wizard-ci self-driving/astro
  • /wizard-ci self-driving/fastapi
  • /wizard-ci self-driving/nuxt
  • /wizard-ci self-driving/react-router
  • /wizard-ci self-driving/sveltekit
  • /wizard-ci warehouse/monorepo-env
  • /wizard-ci warehouse/multi-source-next
  • /wizard-ci warehouse/stripe-node
  • /wizard-ci warehouse/zero-source
  • /wizard-ci warehouse-seeded/next-stripe
  • /wizard-ci warehouse-seeded/next-stripe-declined

Test against a Context Mill branch:

  • /wizard-ci all context-mill:my-branch

Add context-mill:<branch> to any command above to pin the Context Mill branch. It defaults to main.

Results will be posted here when complete.

@veria-ai

veria-ai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

PR overview

All previously flagged issues have been addressed. No open security concerns remain on this pull request.

Fixed/addressed: 1 · PR risk: 0/10

Reviews

@posthog-security-review-bot posthog-security-review-bot Bot added the security-review Request a security review label Nov 26, 2026
@posthog-security-review-bot

posthog-security-review-bot Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

✅ Security review complete — abb0e64f12af

3 findings could not be placed on this diff and were posted as a comment below, in 8 min.

Add the security-review label to run again on the latest commit.

@gewenyu99
gewenyu99 marked this pull request as draft November 26, 2026 18:45
Comment thread src/agent/runner/shared/trait-skills.ts Resolved
@gewenyu99
gewenyu99 force-pushed the feat/sdk-version-telemetry branch from abb0e64 to 34c4a16 Compare November 26, 2026 18:48

@posthog-security-review-bot posthog-security-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Agent-driven security review - findings inline.

@posthog-security-review-bot

Copy link
Copy Markdown

Findings on a commit this pull request no longer contains

This branch was force-pushed while the review ran, so commit abb0e64f12af is no longer part of this pull request. GitHub only accepts inline comments on the pull request's own commits, so these findings are reproduced in full here instead.

Each location below refers to abb0e64f12af. The code may have moved or changed since then. Add the security-review label to review the latest commit.

Model-claimed location: src/agent/runner/shared/trait-skills.ts:89

The new sdk skills resolved event and the sdk_skills / sdk_non_default_major tags send manifest-derived SDK data without the discovery-sharing consent gate

low privacy-consent (not a security hole) (confidence 5/5)

Details

installTraitSkills now always runs analytics.setTag('sdk_skills', …), analytics.setTag('sdk_non_default_major', …) and analytics.wizardCapture('sdk skills resolved', { …, unmatched_sdks }) (trait-skills.ts:85-94). unmatched_sdks holds the raw posthogSdks trait values (<ecosystem>:<pkg>@<major>, built from the user's dependency files at traits/registry.ts:199-205). The resolved skill ids are selected by those same values. None of this is behind maySendDiscovery / mayReportDiscovery, and --no-telemetry does not suppress product analytics (analytics.ts never reads it).

The repo's own rule says these must be gated. project-discovery/tags.ts:1-4: "Analytics tags a program derives from discovery … are discovery results, so they leave the machine under the same consent as the discovery report". run-state.ts:55 gates even the boolean posthogSdkDetected on consent. The privacy panel (PrivacyPanel.tsx:81-86) tells the user that what is read from dependency files is shared unless they choose "Don't share tools". The report.ts half of this PR gets the gate right (report.ts:57,63). This half skips it. Tags also stick: sdk_skills is merged into every later event in the run. The existing sdk trait skill resolved event (trait-skills.ts:57) already sends skill_id without the gate. unmatched_sdks and the persistent tags are new.

Impact — A user picks "Don't share tools" (or passes --no-telemetry) on a project where wizard-versioned-sdk-skills is on. Their declared PostHog SDK packages and majors (for example npm:posthog-js@1) are still sent to PostHog in sdk skills resolved and stamped onto every later event. The data is low-sensitivity, but sending it contradicts the opt-out the product shows.

Fix — Pass the session's consent in (or an allowDiscoveryTelemetry boolean computed with maySendDiscovery(session)), and skip the setTag calls and the unmatched_sdks / skill-id lists when it is false. Alternatively, route these tags through tagDiscovery so they wait for consent like the other discovery tags.

Agent-driven security review. Confidence is 4/5 because whether product treats resolved-skill telemetry as a 'discovery result' under the opt-out is inferred from tags.ts and run-state.ts, not stated for this event.


Model-claimed location: src/services/project-discovery/traits/sdks.ts:181

EXACT_PIN_SPEC is tested against the raw, untrimmed manifest version string and backtracks quadratically, so a crafted package.json hangs the wizard's synchronous discovery report

low availability (confidence 5/5)

Details

summarizePosthogSdks runs EXACT_PIN_SPEC.test(spec) (regex at sdks.ts:154-155) on spec = manifest.versions[pkg], the raw value from the user's manifest. The only gate before that is declaredRange(spec) (src/shared/utils/semver.ts:58), and semver's Range trims and collapses whitespace itself before parsing, so a spec with a huge whitespace run still passes as valid. The regex opens with ^\s*(?:==|=)?\s*. With no = present, the two adjacent \s* can split a run of N spaces N ways, and the match then fails later, which costs O(N²) backtracking. safeReadFile lets a manifest be up to 2 MB (MAX_PROJECT_FILE_BYTES, bounded-fs.ts:106), and nothing caps the length of an individual spec.

I copied the regex and declaredRange/declaredFloor into a probe running on Node with semver 7.8.5, the same 7.8.x the lockfile pins. Spec = ' '.repeat(N) + '1.0.0 || 2', timing the regex alone:

N spaces validRange EXACT_PIN_SPEC.test
20 000 5 ms 0.6 s
40 000 5 ms 2.5 s
80 000 5 ms 9.8 s

Scaled to a 1.9 MB spec, that is about 1.5 h of CPU on the main thread. semver handles the same input in 5 ms.

How it gets there: reportDiscovery (report.ts:73) → reportPosthogSdks → summarizePosthogSdks. This runs synchronously by design (report.ts:58) from WizardStore.completeSetup (src/tui/store.ts:554, where it freezes the Ink UI, and Ctrl-C in raw mode needs the event loop) and from run-program.ts:403 in CI/headless runs. Sharing is granted by default there.

Impact — Someone who controls a repository (a cloned template or OSS project, or a PR to a repo where CI runs the wizard) adds "posthog-node": "<~1M spaces>1.0.0 || 2" to dependencies. npm still accepts it because semver trims it, but every wizard run on that checkout spins at 100% CPU until it is killed. This is denial of service against a local tool, with no data exposure. The repo's own bounded-fs limits are there to stop exactly this kind of unbounded work on repo content.

Fix — Trim the spec and cap its length before running the regex, and drop the duplicated whitespace quantifiers:

const EXACT_PIN_SPEC = /^(?:==?)?\s?v?\d+(?:\.\d+){1,2}(?:[-+][0-9A-Za-z.-]+)?$/;
…
const trimmed = spec.trim();
if (trimmed.length <= 64 && EXACT_PIN_SPEC.test(trimmed)) {

You could also skip the regex and decide 'pinned' from the normalized range semver already returned (for example valid(range) !== null).


Model-claimed location: src/services/project-discovery/traits/sdks.ts:183

intersects(range, >=${majorNum + 1}.0.0) throws for a declared floor major of Number.MAX_SAFE_INTEGER, and the throw escapes reportDiscovery and fails the whole wizard run

low non-security-availability (confidence 5/5)

Details

summarizePosthogSdks builds the comparator >=${majorNum + 1}.0.0 from the floor's major and passes it to semver intersects without a guard. When the declared floor major is 9007199254740991 (Number.MAX_SAFE_INTEGER, which semver accepts), majorNum + 1 goes past the safe range. semver's Comparator → SemVer then throws TypeError: Invalid major version. I reproduced this with semver 7.8.5: spec >=9007199254740991.0.0 (or 9007199254740991.0.0 - 9007199254740991.0.5) passes declaredRange/declaredFloor and then throws at this line.

Nothing catches it. reportPosthogSdks runs before store.shareDiscovery (report.ts:73-74), so the discovery report is lost and the latch is never set. In run-program.ts:403 the call is inside the pre-agent try, whose catch returns fail(error.message), so the run ends with "Invalid major version". In the TUI it throws out of WizardStore.completeSetup (src/tui/store.ts:554) before setupConfirmed is written. Before this PR, nothing in this path did arithmetic on a manifest-derived major: sdk-features.ts:30 calls intersects only with constant minimums.

Impact — A package.json declaring "posthog-node": ">=9007199254740991.0.0" makes every wizard run on that project fail at the pre-agent step, all because of a telemetry helper. This is a reliability problem, not a security hole, and only a deliberately odd manifest triggers it. Telemetry should fail open.

Fix — Guard the arithmetic, and isolate the telemetry so it can never fail the run or block shareDiscovery:

} else if (Number.isSafeInteger(majorNum + 1) && intersects(range, `>=${majorNum + 1}.0.0`)) {
// report.ts
try { reportPosthogSdks(discovery); } catch (e) { logToFile('[discovery] sdk summary failed', e); }

@posthog-security-review-bot posthog-security-review-bot Bot removed the security-review Request a security review label Nov 26, 2026
@gewenyu99 gewenyu99 changed the title feat(telemetry): add SDK version and skill resolution telemetry feat(telemetry): track SDK version traits and upgrade posthog-node to v6 Nov 26, 2026
@gewenyu99
gewenyu99 marked this pull request as ready for review November 26, 2026 23:03
@posthog-security-review-bot posthog-security-review-bot Bot added the security-review Request a security review label Nov 26, 2026
@posthog-security-review-bot

posthog-security-review-bot Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

✅ Security review complete — 96c492f57259

2 findings posted as a review, in 7 min.

Add the security-review label to run again on the latest commit.

@posthog-security-review-bot posthog-security-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Agent-driven security review - findings inline.

analytics.setTag('sdk_skills', resolvedIds.join(','));
}
analytics.setTag('sdk_non_default_major', nonDefaultIds.length > 0);
analytics.wizardCapture('sdk skills resolved', {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The new sdk skills resolved event and the sdk_skills / sdk_non_default_major run tags send manifest-derived SDK data without checking discovery consent or --no-telemetry, unlike the same PR's report.ts path.

low privacy-consent (not a security vulnerability) (confidence 5/5)

Details

installTraitSkills (called from linear.ts:101 and orchestrator-runner.ts:942) now does three things whatever the run's sharing consent. It emits wizard: sdk skills resolved with unmatched_sdks. It sets the run tag sdk_skills. It sets the run tag sdk_non_default_major. unmatched_sdks is the posthogSdks match key (traits/registry.ts posthogSdks.detect), which lists each PostHog SDK the project's manifests declare, as <ecosystem>:<pkg>@<major>. That is a local discovery result. setTag puts both tags into this.tags, so they ride on every later capture, every exception and the setup wizard finished event.

Nothing in this path checks consent. matchKeys comes from toMatchKeys(getTraits(...)) (run-program.ts:672), and declaredSdks is gated only by the wizard-versioned-sdk-skills flag. The repo treats this class of data as consent-gated everywhere else. tags.ts says discovery-derived tags "leave the machine under the same consent as the discovery report". reportableDetections withholds posthog_sdk_detected unless sharing is granted. This same PR puts the matching has_existing_sdk / sdk_version_found / posthog sdks detected data behind noTelemetry and mayReportDiscovery in report.ts:57,63. program-session.ts documents --no-telemetry as "nothing about the run leaves the machine, whatever the consent".

This is not a security hole. The values are closed-schema: package names from an allowlist plus a major version, sent to PostHog's own analytics project. The old per-skill sdk trait skill resolved event already sent matched skill ids without a consent check. This diff widens that to declared SDKs that match no skill, and to run-wide tags on every later event.

Impact — A user picks "Don't share tools" on the intro (declineSharing sets DiscoveryConsent.Declined), or passes --no-telemetry, with wizard-versioned-sdk-skills on. The run still sends, for example, unmatched_sdks: ["pypi:posthog@2"], and stamps sdk_skills / sdk_non_default_major onto every later event. The user explicitly opted out of sharing this discovery data.

Fix — Gate the event and the tags on maySendDiscovery(session). For example, callers pass a reportDiscovery: boolean (or a tagDiscovery-style deferred setter) into installTraitSkills:

if (reportDiscovery && (declaredSdks.length > 0 || matched.length > 0)) {
  // setTag + wizardCapture as now
}

Or route the tags through tagDiscovery(session, setFrameworkContext, {...}), so they apply only once sharing is granted, as the report.ts half of this PR does.

Agent-driven security review. Not visible from the repo: whether wizard-versioned-sdk-skills is rolled out to interactive users who decline sharing. The code path is traced end to end.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Already fixed in e4fcfb07. installTraitSkills now defaults reportTelemetry to false and guards setTag and wizardCapture behind it, while linear.ts and orchestrator-runner.ts pass maySendDiscovery(session()).

versions.add(`${sdkId}@${majorPart}.${minorPart}`);
if (EXACT_PIN_SPEC.test(spec)) {
pinKinds.add('exact');
} else if (intersects(range, `>=${majorNum + 1}.0.0`)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

An SDK version range can make discovery telemetry abort the wizard

low non-security-availability (confidence 4/5)

Details

summarizePosthogSdks constructs a new range by adding one to the parsed major without guarding overflow or catching parser exceptions. For >=9007199254740991.0.0, declaredRange and declaredFloor (utils/semver.ts:58-83) return a valid range and floor, but this line constructs >=9007199254740992.0.0; intersects throws TypeError: Invalid major version. A concrete source is gem 'posthog-ruby', '>= 9007199254740991.0.0' in Gemfile, accepted by manifests/rubygems.ts:2-10 and retained by walk.ts:251-264.

Impact — a repository author can make a normal sharing-enabled wizard run fail through best-effort telemetry. reportDiscovery calls this synchronously at report.ts:65, before its credential/report guards, without isolating a summarization failure; its callers include the intro's Continue action (tui/store.ts:550-556) and program setup (run-program.ts:403). This is a local reliability issue, limited to runs on that repository; no credential theft or shared-service denial of service is demonstrated.

Fix — handle the maximum major before constructing the next-major comparator, and make version summarization fail softly per entry when any semver operation throws. Treat an unsupported spec as unversioned rather than failing setup, and add this boundary case as a regression test.

Agent-driven security review. The exception was reproduced using the actual changed functions with installed semver 7.8.5; the lockfile's semver 7.7.1 is not installed in this checkout.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Already fixed in e4fcfb07. summarizePosthogSdks now checks Number.isSafeInteger(nextMajor) and catches per-entry semver failures as unversioned, reportDiscovery isolates summary errors, and posthog-sdks.test.ts covers Number.MAX_SAFE_INTEGER.

@posthog-security-review-bot posthog-security-review-bot Bot removed the security-review Request a security review label Nov 26, 2026

@johncwaters johncwaters 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.

Verdict: APPROVE WITH NITS

See inline comments.

Automated review by Glimmervoid. Not written by a human

};

const EXACT_PIN_SPEC =
/^(?:(?:==|=)\s?v?\d+(?:\.\d+){1,2}|v?\d+\.\d+\.\d+)(?:[-+.a-zA-Z0-9]+)?$/;

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.

[code/logic] MEDIUM

EXACT_PIN_SPEC counts any bare x.y.z as exact, and summarizePosthogSdks() applies it without checking manifest.ecosystem. Cargo reads a bare version as caret, so posthog-rs = "0.3.5" means ^0.3.5 and should land as major_range. Right now every Rust project reports sdk_version_pin: exact, which skews the pin-style numbers this PR exists to collect.

Suggest skipping the bare-version branch when the ecosystem is cargo (only =0.3.5 is exact there) and adding a Cargo "0.3.5" case to posthog-sdks.test.ts. The current exact cases are all npm or PyPI.

Automated review by Glimmervoid. Not written by a human

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 99ecdfd2. isExactPin skips bare x.y.z matching when manifest.ecosystem === 'cargo', so Cargo bare versions classify as major_range while =x.y.z stays exact. Added both cases to posthog-sdks.test.ts.

const versions = new Set<string>();
const pinKinds = new Set<Exclude<SdkVersionPin, 'mixed'>>();

for (const manifest of manifests) {

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.

[architecture/twin-logic] MEDIUM

Open question more than a bug. summarizePosthogSdks() repeats the package filter, the declaredRange/declaredFloor parse and the major split from posthogSdkVersions(), and the two already disagree: line 88 filters to VERSIONED_ECOSYSTEMS (Hex left out, per the comment at line 71) while this loop takes every manifest. The scope differs too: summarizeRunSdks in report.ts reads every manifest under runProject/, and the registry reads manifestsOf(session, projectPath).

So a Hex posthog dep shows up in sdk_version_found and detected_sdk_count but never in sdk_skills or unmatched_sdks. If the plan is to join the discovery tags against the skill tags in insights, they won't line up. If the split is intended, ignore this. If not, one parser that returns every detected SDK with a versioned flag and its pin kind could feed both, or sdk_version_found could come from the same DeclaredSdk[] that registry.ts builds.

Automated review by Glimmervoid. Not written by a human

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The split is intentional, so leaving the code as is. summarizePosthogSdks captures discovery telemetry across all ecosystems (including RubyGems, Composer, Hex, and unversioned specs) and sub-manifests under runProject (matching toolsUnder), whereas posthogSdkVersions is scoped to VERSIONED_ECOSYSTEMS and the single project directory for skill resolution.

@gewenyu99
gewenyu99 merged commit d78c285 into main Nov 27, 2026
24 of 25 checks passed
@gewenyu99
gewenyu99 deleted the feat/sdk-version-telemetry branch November 27, 2026 19:24
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.

2 participants