Skip to content

fix(ivm): platform-error alert misses the first error burst on a fresh isolate - #5373

Merged
shekhar-rudder merged 4 commits into
developfrom
fix/int-6832-ivm-platform-error-counter-zero-init
Jul 21, 2026
Merged

shekhar-rudder merged 4 commits into
developfrom
fix/int-6832-ivm-platform-error-counter-zero-init

Conversation

@shekhar-rudder

@shekhar-rudder shekhar-rudder commented Jul 17, 2026 •

Copy link
Copy Markdown
Member

What

The ivm-platform-errors alert can silently miss the first burst of isolated-vm platform errors on a workspace/isolate that hasn't errored before — the exact failure mode we hit in a recent enterprise-eu incident, where a burst of ~2.7k errors on a freshly-seen isolate never showed up and only a later, smaller burst tripped the alert.

Why it happens

transformer_ivm_platform_error is created lazily on its first increment, so its series springs into existence already at a non-zero value. rate()/increase() anchor on the first sample within their window and cannot measure the jump that creates a series — there is no earlier sample to diff against. As a result:

  • the alert (sum by (cluster, namespace, functionName) (increase(transformer_ivm_platform_error[1m])) > 0) only trips on the second increment of an already-established series;
  • a single burst that then goes quiet is never alerted;
  • increase()-based dashboard panels undercount the same bursts.

Replaying the alert expression over the incident confirmed it: the first burst's window evaluated to 0 throughout, and only the second increment produced a non-zero value.

Fix

Materialise the counter at 0 for a label set when its isolate is first built (the cache-miss path of IvmScriptRunner.execute), using the same labels the error path increments. Because a workspace's first call is always a cache miss, the 0 baseline exists before any error can occur, so increase() sees a clean 0 → N edge and catches the very first burst.

Seeding on isolate build (rather than on every call) keeps the warm-isolate hot path off the metrics registry entirely — the 0 is written once per isolate lifecycle, not per event. This is the same zero-initialisation approach already used elsewhere in the transformer for counters that feed alerts.

Tradeoffs & scope

  • Cardinality: the counter now gets a (zero-valued) series for every actively-processing (workspaceId, functionName, cache), not only erroring ones. It is bounded by the active workspaces per pod. workspaceId was already a label on this metric, so no new label dimension is introduced.
  • Residual gap: if a workspace's very first call errors within a single scrape interval (before the 0 is ever scraped), that one burst can still be missed. This is far narrower than the previous behaviour (every freshly-seen series was blind) and is inherent to lazily-created counters.
  • No change to the alert definition is required — the existing expression becomes correct once the baseline exists.

Testing

New scriptRunner.test.ts covers:

  • happy path seeds 0 and records no error;
  • a platform failure seeds 0 and increments with a matching label set;
  • an isolate build-time failure is covered (seed runs before the isolate exists);
  • warm-isolate calls do not re-seed — only one registry write per isolate.

The existing sandboxClient integration suite exercises the seeded build path.

…h isolate

transformer_ivm_platform_error is created lazily on its first increment, so a
series appears already at a non-zero value. rate()/increase() anchor on the
first sample in their window and cannot measure the jump that *creates* a
series — so an error burst on a workspace/isolate seen for the first time is
invisible to the ivm-platform-errors alert, which only trips on the second
increment of an already-established series. A single burst that then goes quiet
is never alerted, and increase-based panels undercount it.

Seed the counter at 0 on the happy path of IvmScriptRunner.execute, using the
same label set the error path increments. Any workspace actively processing now
has its error series present at 0 before it can fail, giving increase() the
0 -> N edge it needs to catch the very first burst.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@shekhar-rudder
shekhar-rudder requested review from a team as code owners July 17, 2026 11:24
@coderabbitai

coderabbitai Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@shekhar-rudder, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 45 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 06b12c28-4241-4e88-adce-32bb52e9fcbe

📥 Commits

Reviewing files that changed from the base of the PR and between 9c285e1 and 37e7732.

📒 Files selected for processing (1)
  • src/v0/destinations/custom_audience/template/ivmScriptRunner.test.ts

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

⚠️ Parsing warnings (1)
Validation error: Unrecognized key: "auto_resolve_threads"
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Walkthrough

IvmScriptRunner now seeds ivm_platform_error when creating isolates, reuses metric labels for failures, and avoids reseeding cached isolates. Tests cover success, execution and creation failures, concurrent creation, eviction, cache reuse, and Prometheus counter behavior.

Changes

IVM platform metrics

Layer / File(s) Summary
Metric seeding and isolate creation
src/util/ivm/scriptRunner.ts
execute passes shared metric tags and a creation callback to getOrCreate; new isolate creation seeds the counter, while failures increment it.
Metric behavior validation
src/util/ivm/scriptRunner.test.ts, src/util/prometheus.test.js
Mocked tests cover successful execution, failures, cache reuse, concurrent creation, eviction, matching labels, and non-resetting zero seeds.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant IvmScriptRunner
  participant getOrCreate
  participant IVMCache
  participant stats
  IvmScriptRunner->>getOrCreate: request isolate with cache key
  getOrCreate->>stats: seed ivm_platform_error at 0
  getOrCreate->>IVMCache: create or reuse isolate
  IvmScriptRunner->>stats: increment metric on failure
Loading

Possibly related PRs

Suggested reviewers: maheshkutty

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main fix: seeding platform-error metrics so the first burst on a fresh isolate is alertable.
Description check ✅ Passed The description is strong and covers the required change context, but it omits the required Linear task reference.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/int-6832-ivm-platform-error-counter-zero-init

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

shekhar-rudder and others added 3 commits July 17, 2026 17:04
… per call

Move the 0-seed from every execute() into the cache-miss (isolate build) path so
warm-isolate calls never touch the metrics registry. A workspace's first call is
always a cache miss, so the 0 baseline is still materialised before any error can
occur — increase() still gets its 0 -> N edge — while the hot path does no
per-call metrics work.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…eset

Address review feedback on the platform-error 0-seed tests:

- scriptRunner.test.ts: add a concurrent first-callers test (two calls for
  the same key coalesce to one 0-seed and one isolate build) and a
  re-seed-after-eviction test (an error evicts the isolate; the next call
  rebuilds and re-seeds 0). These are the branches most likely to regress
  under refactor.
- scriptRunner.test.ts: document that the mocked `stats.counter`/`increment`
  are independent, whereas in prod `increment` delegates to `counter(name, 1)`
  — so total `counter` call counts must not be asserted across error paths.
- prometheus.test.js: new, proves against the real registry that
  `counter(name, 0)` materialises a series at 0 and that re-seeding with 0
  after an increment does not reset the accumulated count (inc(0) is add-only).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The platform-error 0-seed added in this PR makes IvmScriptRunner.execute
call stats.counter('ivm_platform_error', 0, ...) on every isolate build.
The custom_audience ivmScriptRunner suite mocks stats without a counter
field, so onCreate() threw 'stats.counter is not a function' on the first
call of every test, breaking the whole suite. Add counter: jest.fn() to
the mock so it matches the real stats surface the runner now uses.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.88%. Comparing base (15ed184) to head (37e7732).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #5373      +/-   ##
===========================================
+ Coverage    92.87%   92.88%   +0.01%     
===========================================
  Files          706      708       +2     
  Lines        38372    38431      +59     
  Branches      9005     8970      -35     
===========================================
+ Hits         35638    35697      +59     
- Misses        2508     2524      +16     
+ Partials       226      210      -16     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sonarqubecloud

Copy link
Copy Markdown

@shekhar-rudder
shekhar-rudder merged commit ddb344c into develop Jul 21, 2026
34 checks passed
@shekhar-rudder
shekhar-rudder deleted the fix/int-6832-ivm-platform-error-counter-zero-init branch July 21, 2026 08:02
shekhar-rudder added a commit that referenced this pull request Jul 22, 2026
The branch had drifted 13 commits behind develop and was CONFLICTING, which
meant GitHub could not compute a merge ref and silently skipped every
pull_request-triggered workflow — DT Tests, Verify and Tests have never run
on this PR. Only commitlint (push-triggered) and CodeQL reported, so the PR
appeared green while its unit tests had never executed once.

Conflicts were confined to the two files this branch touches, against #5373
("platform-error alert misses the first error burst on a fresh isolate"),
which landed on develop and rewrote the same execute()/getOrCreate() methods.
The two changes are complementary:

- scriptRunner.ts: keep both. `platformErrorTags` and the 0-seed callback from
  develop, plus this branch's acquireSlot()/releaseSlot() gate around them. The
  tags object is a side-effect-free literal, so hoisting it above the slot
  acquisition is safe, and seeding still happens once per isolate build — now
  inside the gated path, after a slot is held.

- scriptRunner.test.ts: add/add. The suites need incompatible module mocks —
  develop's stubs `fs` and `DisposableCache`, while the gate tests exercise the
  real cache so gate teardown can be observed against real eviction. Merging
  them into one file would break both, so develop's file is kept as-is and the
  gate suite moves to scriptRunner.gate.test.ts. Its `stats` mock gains
  `counter`, which execute() now calls via develop's 0-seed callback.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
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