Skip to content

fix(workflows): variable-scan metric cardinality, timing, and bytecode skip - #71500

Merged
mayteio merged 1 commit into
masterfrom
posthog-code/workflows-variable-scan-followups
Jul 16, 2026
Merged

fix(workflows): variable-scan metric cardinality, timing, and bytecode skip#71500
mayteio merged 1 commit into
masterfrom
posthog-code/workflows-variable-scan-followups

Conversation

@mayteio

@mayteio mayteio commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Problem

Review follow-ups on #71060 (variable-miss tracing), raised in the team Slack thread after it auto-merged:

  1. The miss counter is labelled hog_flow_id - one Prometheus series per workflow UUID that ever misses a variable, unbounded cardinality for a metric whose job is fleet-wide ("are misses common enough to justify the publish-time lint?").
  2. The regex scan runs on every fresh entry into a function step with no timing instrumentation, so its cost is assumed rather than observed.
  3. The scan traverses compiled bytecode arrays. The in-code comment claimed that's safe because compiled references store variables and the key as separate constants - true for compiled references, but a template string embedded verbatim as a bytecode constant (or the transpiled JS form) does match the regex while the executor never renders from it: wasted work on the bulkiest part of the config, plus a latent false-positive warning.

Changes

  • cdp_hogflow_missing_variable_reference is now unlabelled. The per-flow drill-down lives in the structured warn log, which already carries team, flow, action, and the missing names - strictly richer than the label was. The metric is a day old, so nothing charts by the old label yet.
  • New cdp_hogflow_variable_scan_duration_seconds histogram around the scan (fixed buckets, 0.5ms-500ms). If it flatlines sub-millisecond we can delete it later with evidence in hand.
  • The traversal skips bytecode and transpiled keys, with the comment corrected to explain the false-positive case rather than asserting safety.

How did you test this code?

Extended the existing parameterized suite with a row where a matching-looking template string sits inside a bytecode constant and a transpiled string - it must not be reported (catches anyone removing the skip and reintroducing the false positive; the pre-existing bytecode row only covered the compiled-reference shape that can't match). Full hogflow-variable-usage + hog_function suites pass (28 tests), lint and tsc clean.

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Docs update

Not needed - internal observability only.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Authored with PostHog Code (Claude), addressing colleague review feedback relayed from Slack. Skills invoked: /writing-tests. The bytecode-skip finding turned out to be a correctness fix, not just perf - the original safety comment held for compiled references but not for template strings carried verbatim as constants.


Created with PostHog Code

…e skip

Review follow-ups on the variable-miss tracing:

- Drop the hog_flow_id label from the miss counter: one series per
  workflow UUID is unbounded cardinality for a metric whose job is the
  fleet-wide rate (it sizes the publish-time lint work). The per-flow
  drill-down lives in the structured warn log, which already carries
  team, flow, action, and the missing names.
- Time the scan with a histogram: it runs on every fresh entry into a
  function step, so its cost has to be observable rather than assumed.
- Stop traversing bytecode/transpiled keys. They are the bulkiest part
  of a config and, contrary to the previous comment, not match-proof: a
  template string embedded verbatim as a bytecode constant matches the
  regex while the executor never renders from it - a latent false
  positive, covered by a new test row.

Generated-By: PostHog Code
Task-Id: 7f5083cf-5d17-4f37-8bee-8c43db70cb79
@mayteio mayteio self-assigned this Jul 16, 2026
@mayteio
mayteio marked this pull request as ready for review July 16, 2026 11:56
@pr-assigner-resolver-posthog
pr-assigner-resolver-posthog Bot requested a review from a team July 16, 2026 11:57
@greptile-apps

greptile-apps Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "fix(workflows): variable-scan metric car..." | Re-trigger Greptile

Comment thread nodejs/src/cdp/services/hogflows/hogflow-variable-usage.ts
@trunk-io

trunk-io Bot commented Jul 16, 2026

Copy link
Copy Markdown

Static BadgeStatic BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

@mayteio
mayteio merged commit d6a925c into master Jul 16, 2026
275 checks passed
@mayteio
mayteio deleted the posthog-code/workflows-variable-scan-followups branch July 16, 2026 12:19
@deployment-status-posthog

deployment-status-posthog Bot commented Jul 16, 2026

Copy link
Copy Markdown

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-07-16 12:48 UTC Run
prod-us ✅ Deployed 2026-07-16 13:08 UTC Run
prod-eu ✅ Deployed 2026-07-16 13:10 UTC Run

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